Skip to content

Commit 42dfc54

Browse files
committed
Use memmove wrapper instead of bcopy for platform compatibillity
Signed-off-by: Paul Dagnelie <[email protected]>
1 parent ade2936 commit 42dfc54

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

module/zfs/btree.c

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ kmem_cache_t *zfs_btree_leaf_cache;
5555
*/
5656
int zfs_btree_verify_intensity = 0;
5757

58+
/*
59+
* A convenience function to silence warnings from memmove's return value and
60+
* change argument order to src, dest.
61+
*/
62+
void
63+
bmov(const void *src, const void *dest, size_t size)
64+
{
65+
(void) memmove(dest, src, size);
66+
}
67+
5868
#ifdef _ILP32
5969
#define BTREE_POISON 0xabadb10c
6070
#else
@@ -367,14 +377,14 @@ bt_shift_core(zfs_btree_t *tree, zfs_btree_core_t *node, uint64_t idx,
367377
int sign = (dir == BSD_LEFT ? -1 : +1);
368378
uint8_t *e_out = e_start + sign * off * size;
369379
uint64_t e_count = count;
370-
bcopy(e_start, e_out, e_count * size);
380+
bmov(e_start, e_out, e_count * size);
371381

372382
zfs_btree_hdr_t **c_start = node->btc_children + idx +
373383
(shape == BSS_TRAPEZOID ? 0 : 1);
374384
zfs_btree_hdr_t **c_out = (dir == BSD_LEFT ? c_start - off :
375385
c_start + off);
376386
uint64_t c_count = count + (shape == BSS_TRAPEZOID ? 1 : 0);
377-
bcopy(c_start, c_out, c_count * sizeof (*c_start));
387+
bmov(c_start, c_out, c_count * sizeof (*c_start));
378388
}
379389

380390
/*
@@ -416,7 +426,7 @@ bt_shift_leaf(zfs_btree_t *tree, zfs_btree_leaf_t *node, uint64_t idx,
416426
uint8_t *start = node->btl_elems + idx * size;
417427
int sign = (dir == BSD_LEFT ? -1 : +1);
418428
uint8_t *out = start + sign * off * size;
419-
bcopy(start, out, count * size);
429+
bmov(start, out, count * size);
420430
}
421431

422432
static inline void
@@ -446,11 +456,11 @@ bt_transfer_core(zfs_btree_t *tree, zfs_btree_core_t *source, uint64_t sidx,
446456
ASSERT(source->btc_hdr.bth_core);
447457
ASSERT(dest->btc_hdr.bth_core);
448458

449-
bcopy(source->btc_elems + sidx * size, dest->btc_elems + didx * size,
459+
bmov(source->btc_elems + sidx * size, dest->btc_elems + didx * size,
450460
count * size);
451461

452462
uint64_t c_count = count + (shape == BSS_TRAPEZOID ? 1 : 0);
453-
bcopy(source->btc_children + sidx + (shape == BSS_TRAPEZOID ? 0 : 1),
463+
bmov(source->btc_children + sidx + (shape == BSS_TRAPEZOID ? 0 : 1),
454464
dest->btc_children + didx + (shape == BSS_TRAPEZOID ? 0 : 1),
455465
c_count * sizeof (*source->btc_children));
456466
}
@@ -463,7 +473,7 @@ bt_transfer_leaf(zfs_btree_t *tree, zfs_btree_leaf_t *source, uint64_t sidx,
463473
ASSERT(!source->btl_hdr.bth_core);
464474
ASSERT(!dest->btl_hdr.bth_core);
465475

466-
bcopy(source->btl_elems + sidx * size, dest->btl_elems + didx * size,
476+
bmov(source->btl_elems + sidx * size, dest->btl_elems + didx * size,
467477
count * size);
468478
}
469479

@@ -511,7 +521,7 @@ zfs_btree_insert_core_impl(zfs_btree_t *tree, zfs_btree_core_t *parent,
511521

512522
/* Insert new values */
513523
parent->btc_children[offset + 1] = new_node;
514-
bcopy(buf, parent->btc_elems + offset * size, size);
524+
bmov(buf, parent->btc_elems + offset * size, size);
515525
par_hdr->bth_count++;
516526
}
517527

@@ -546,7 +556,7 @@ zfs_btree_insert_into_parent(zfs_btree_t *tree, zfs_btree_hdr_t *old_node,
546556
old_node->bth_parent = new_node->bth_parent = new_root;
547557
new_root->btc_children[0] = old_node;
548558
new_root->btc_children[1] = new_node;
549-
bcopy(buf, new_root->btc_elems, size);
559+
bmov(buf, new_root->btc_elems, size);
550560

551561
tree->bt_height++;
552562
tree->bt_root = new_root_hdr;
@@ -614,7 +624,7 @@ zfs_btree_insert_into_parent(zfs_btree_t *tree, zfs_btree_hdr_t *old_node,
614624

615625
/* Store the new separator in a buffer. */
616626
uint8_t *tmp_buf = kmem_alloc(size, KM_SLEEP);
617-
bcopy(parent->btc_elems + keep_count * size, tmp_buf,
627+
bmov(parent->btc_elems + keep_count * size, tmp_buf,
618628
size);
619629
zfs_btree_poison_node(tree, par_hdr);
620630

@@ -626,7 +636,7 @@ zfs_btree_insert_into_parent(zfs_btree_t *tree, zfs_btree_hdr_t *old_node,
626636
/*
627637
* Move the new separator to the existing buffer.
628638
*/
629-
bcopy(tmp_buf, buf, size);
639+
bmov(tmp_buf, buf, size);
630640
} else if (offset > keep_count) {
631641
/* Insert the new node into the right half */
632642
new_node->bth_parent = new_parent;
@@ -636,7 +646,7 @@ zfs_btree_insert_into_parent(zfs_btree_t *tree, zfs_btree_hdr_t *old_node,
636646
/*
637647
* Move the new separator to the existing buffer.
638648
*/
639-
bcopy(tmp_buf, buf, size);
649+
bmov(tmp_buf, buf, size);
640650
} else {
641651
/*
642652
* Move the new separator into the right half, and replace it
@@ -646,7 +656,7 @@ zfs_btree_insert_into_parent(zfs_btree_t *tree, zfs_btree_hdr_t *old_node,
646656
bt_shift_core_right(tree, new_parent, 0, move_count,
647657
BSS_TRAPEZOID);
648658
new_parent->btc_children[0] = new_node;
649-
bcopy(tmp_buf, new_parent->btc_elems, size);
659+
bmov(tmp_buf, new_parent->btc_elems, size);
650660
new_par_hdr->bth_count++;
651661
}
652662
kmem_free(tmp_buf, size);
@@ -685,7 +695,7 @@ zfs_btree_insert_leaf_impl(zfs_btree_t *tree, zfs_btree_leaf_t *leaf,
685695
}
686696

687697
bt_shift_leaf_right(tree, leaf, idx, count);
688-
bcopy(value, start, size);
698+
bmov(value, start, size);
689699
hdr->bth_count++;
690700
}
691701

@@ -745,7 +755,7 @@ zfs_btree_insert_into_leaf(zfs_btree_t *tree, zfs_btree_leaf_t *leaf,
745755

746756
/* We store the new separator in a buffer we control for simplicity. */
747757
uint8_t *buf = kmem_alloc(size, KM_SLEEP);
748-
bcopy(leaf->btl_elems + (keep_count * size), buf, size);
758+
bmov(leaf->btl_elems + (keep_count * size), buf, size);
749759
zfs_btree_poison_node(tree, &leaf->btl_hdr);
750760

751761
if (idx < keep_count) {
@@ -761,8 +771,8 @@ zfs_btree_insert_into_leaf(zfs_btree_t *tree, zfs_btree_leaf_t *leaf,
761771
* separator, and use the new value as the new separator.
762772
*/
763773
bt_shift_leaf_right(tree, new_leaf, 0, move_count);
764-
bcopy(buf, new_leaf->btl_elems, size);
765-
bcopy(value, buf, size);
774+
bmov(buf, new_leaf->btl_elems, size);
775+
bmov(value, buf, size);
766776
new_hdr->bth_count++;
767777
}
768778

@@ -864,7 +874,7 @@ zfs_btree_bulk_finish(zfs_btree_t *tree)
864874
/* Next, move the separator from the common ancestor to leaf. */
865875
uint8_t *separator = common->btc_elems + (common_idx * size);
866876
uint8_t *out = leaf->btl_elems + ((move_count - 1) * size);
867-
bcopy(separator, out, size);
877+
bmov(separator, out, size);
868878
move_count--;
869879

870880
/*
@@ -878,7 +888,7 @@ zfs_btree_bulk_finish(zfs_btree_t *tree)
878888
* Finally, move the new last element in the left neighbor to
879889
* the separator.
880890
*/
881-
bcopy(l_neighbor->btl_elems + (l_hdr->bth_count -
891+
bmov(l_neighbor->btl_elems + (l_hdr->bth_count -
882892
move_count - 1) * size, separator, size);
883893

884894
/* Adjust the node's counts, and we're done. */
@@ -933,7 +943,7 @@ zfs_btree_bulk_finish(zfs_btree_t *tree)
933943
uint8_t *separator = parent->btc_elems + ((parent_idx - 1) *
934944
size);
935945
uint8_t *e_out = cur->btc_elems + ((move_count - 1) * size);
936-
bcopy(separator, e_out, size);
946+
bmov(separator, e_out, size);
937947

938948
/*
939949
* Now, move elements and children from the left node to the
@@ -949,7 +959,7 @@ zfs_btree_bulk_finish(zfs_btree_t *tree)
949959
* separator's position.
950960
*/
951961
move_idx--;
952-
bcopy(l_neighbor->btc_elems + move_idx * size, separator, size);
962+
bmov(l_neighbor->btc_elems + move_idx * size, separator, size);
953963

954964
l_neighbor->btc_hdr.bth_count -= move_count + 1;
955965
hdr->bth_count += move_count + 1;
@@ -1036,8 +1046,8 @@ zfs_btree_insert(zfs_btree_t *tree, const void *value,
10361046
zfs_btree_hdr_t *subtree = node->btc_children[off + 1];
10371047
size_t size = tree->bt_elem_size;
10381048
uint8_t *buf = kmem_alloc(size, KM_SLEEP);
1039-
bcopy(node->btc_elems + off * size, buf, size);
1040-
bcopy(value, node->btc_elems + off * size, size);
1049+
bmov(node->btc_elems + off * size, buf, size);
1050+
bmov(value, node->btc_elems + off * size, size);
10411051

10421052
/*
10431053
* Find the first slot in the subtree to the right, insert
@@ -1389,18 +1399,18 @@ zfs_btree_remove_from_node(zfs_btree_t *tree, zfs_btree_core_t *node,
13891399
*/
13901400
uint8_t *separator = parent->btc_elems + (parent_idx - 1) *
13911401
size;
1392-
bcopy(separator, node->btc_elems, size);
1402+
bmov(separator, node->btc_elems, size);
13931403

13941404
/* Move the last child of neighbor to our first child slot. */
13951405
zfs_btree_hdr_t **take_child = neighbor->btc_children +
13961406
l_hdr->bth_count;
1397-
bcopy(take_child, node->btc_children, sizeof (*take_child));
1407+
bmov(take_child, node->btc_children, sizeof (*take_child));
13981408
node->btc_children[0]->bth_parent = node;
13991409

14001410
/* Move the last element of neighbor to the separator spot. */
14011411
uint8_t *take_elem = neighbor->btc_elems +
14021412
(l_hdr->bth_count - 1) * size;
1403-
bcopy(take_elem, separator, size);
1413+
bmov(take_elem, separator, size);
14041414
l_hdr->bth_count--;
14051415
zfs_btree_poison_node_at(tree, l_hdr, l_hdr->bth_count);
14061416
return;
@@ -1425,21 +1435,21 @@ zfs_btree_remove_from_node(zfs_btree_t *tree, zfs_btree_core_t *node,
14251435
* element spot in node.
14261436
*/
14271437
uint8_t *separator = parent->btc_elems + parent_idx * size;
1428-
bcopy(separator, node->btc_elems + (hdr->bth_count - 1) * size,
1438+
bmov(separator, node->btc_elems + (hdr->bth_count - 1) * size,
14291439
size);
14301440

14311441
/*
14321442
* Move the first child of neighbor to the last child spot in
14331443
* node.
14341444
*/
14351445
zfs_btree_hdr_t **take_child = neighbor->btc_children;
1436-
bcopy(take_child, node->btc_children + hdr->bth_count,
1446+
bmov(take_child, node->btc_children + hdr->bth_count,
14371447
sizeof (*take_child));
14381448
node->btc_children[hdr->bth_count]->bth_parent = node;
14391449

14401450
/* Move the first element of neighbor to the separator spot. */
14411451
uint8_t *take_elem = neighbor->btc_elems;
1442-
bcopy(take_elem, separator, size);
1452+
bmov(take_elem, separator, size);
14431453
r_hdr->bth_count--;
14441454

14451455
/*
@@ -1492,7 +1502,7 @@ zfs_btree_remove_from_node(zfs_btree_t *tree, zfs_btree_core_t *node,
14921502
uint8_t *e_out = keep->btc_elems + keep_hdr->bth_count * size;
14931503
uint8_t *separator = parent->btc_elems + (parent_idx - 1) *
14941504
size;
1495-
bcopy(separator, e_out, size);
1505+
bmov(separator, e_out, size);
14961506
keep_hdr->bth_count++;
14971507

14981508
/* Move all our elements and children into the left node. */
@@ -1550,7 +1560,7 @@ zfs_btree_remove_from(zfs_btree_t *tree, zfs_btree_index_t *where)
15501560
*/
15511561
uint8_t *value = zfs_btree_get(tree, where);
15521562
uint8_t *tmp = kmem_alloc(size, KM_SLEEP);
1553-
bcopy(value, tmp, size);
1563+
bmov(value, tmp, size);
15541564
zfs_btree_bulk_finish(tree);
15551565
VERIFY3P(zfs_btree_find(tree, tmp, where), !=, NULL);
15561566
kmem_free(tmp, size);
@@ -1572,7 +1582,7 @@ zfs_btree_remove_from(zfs_btree_t *tree, zfs_btree_index_t *where)
15721582
where);
15731583
ASSERT3P(new_value, !=, NULL);
15741584

1575-
bcopy(new_value, node->btc_elems + idx * size, size);
1585+
bmov(new_value, node->btc_elems + idx * size, size);
15761586

15771587
hdr = where->bti_node;
15781588
idx = where->bti_offset;
@@ -1644,10 +1654,10 @@ zfs_btree_remove_from(zfs_btree_t *tree, zfs_btree_index_t *where)
16441654
uint8_t *take_elem = ((zfs_btree_leaf_t *)l_hdr)->btl_elems +
16451655
(l_hdr->bth_count - 1) * size;
16461656
/* Move the separator to our first spot. */
1647-
bcopy(separator, leaf->btl_elems, size);
1657+
bmov(separator, leaf->btl_elems, size);
16481658

16491659
/* Move our neighbor's last element to the separator. */
1650-
bcopy(take_elem, separator, size);
1660+
bmov(take_elem, separator, size);
16511661

16521662
/* Update the bookkeeping. */
16531663
l_hdr->bth_count--;
@@ -1675,11 +1685,11 @@ zfs_btree_remove_from(zfs_btree_t *tree, zfs_btree_index_t *where)
16751685
uint8_t *separator = parent->btc_elems + parent_idx * size;
16761686
uint8_t *take_elem = ((zfs_btree_leaf_t *)r_hdr)->btl_elems;
16771687
/* Move the separator between us to our last spot. */
1678-
bcopy(separator, leaf->btl_elems + (hdr->bth_count - 1) * size,
1688+
bmov(separator, leaf->btl_elems + (hdr->bth_count - 1) * size,
16791689
size);
16801690

16811691
/* Move our neighbor's first element to the separator. */
1682-
bcopy(take_elem, separator, size);
1692+
bmov(take_elem, separator, size);
16831693

16841694
/* Update the bookkeeping. */
16851695
r_hdr->bth_count--;
@@ -1738,7 +1748,7 @@ zfs_btree_remove_from(zfs_btree_t *tree, zfs_btree_index_t *where)
17381748
uint8_t *out = keep->btl_elems + keep_hdr->bth_count * size;
17391749
uint8_t *separator = parent->btc_elems + (parent_idx - 1) *
17401750
size;
1741-
bcopy(separator, out, size);
1751+
bmov(separator, out, size);
17421752
keep_hdr->bth_count++;
17431753

17441754
/* Move our elements to the left neighbor. */

0 commit comments

Comments
 (0)