Commit a3aefb39 authored by Joe Thornber's avatar Joe Thornber Committed by Alasdair G Kergon

dm persistent data: remove redundant value_size arg from value_ptr

Now that the value_size is held within every node of the btrees we can
remove this argument from value_ptr().

For the last few months a BUG_ON has been checking this argument is
the same as that held in the node.  No issues were reported.  So this
is a safe change.
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 466891f9
...@@ -108,12 +108,9 @@ static inline void *value_base(struct node *n) ...@@ -108,12 +108,9 @@ static inline void *value_base(struct node *n)
return &n->keys[le32_to_cpu(n->header.max_entries)]; return &n->keys[le32_to_cpu(n->header.max_entries)];
} }
/* static inline void *value_ptr(struct node *n, uint32_t index)
* FIXME: Now that value size is stored in node we don't need the third parm.
*/
static inline void *value_ptr(struct node *n, uint32_t index, size_t value_size)
{ {
BUG_ON(value_size != le32_to_cpu(n->header.value_size)); uint32_t value_size = le32_to_cpu(n->header.value_size);
return value_base(n) + (value_size * index); return value_base(n) + (value_size * index);
} }
......
...@@ -61,20 +61,20 @@ static void node_shift(struct node *n, int shift) ...@@ -61,20 +61,20 @@ static void node_shift(struct node *n, int shift)
if (shift < 0) { if (shift < 0) {
shift = -shift; shift = -shift;
BUG_ON(shift > nr_entries); BUG_ON(shift > nr_entries);
BUG_ON((void *) key_ptr(n, shift) >= value_ptr(n, shift, value_size)); BUG_ON((void *) key_ptr(n, shift) >= value_ptr(n, shift));
memmove(key_ptr(n, 0), memmove(key_ptr(n, 0),
key_ptr(n, shift), key_ptr(n, shift),
(nr_entries - shift) * sizeof(__le64)); (nr_entries - shift) * sizeof(__le64));
memmove(value_ptr(n, 0, value_size), memmove(value_ptr(n, 0),
value_ptr(n, shift, value_size), value_ptr(n, shift),
(nr_entries - shift) * value_size); (nr_entries - shift) * value_size);
} else { } else {
BUG_ON(nr_entries + shift > le32_to_cpu(n->header.max_entries)); BUG_ON(nr_entries + shift > le32_to_cpu(n->header.max_entries));
memmove(key_ptr(n, shift), memmove(key_ptr(n, shift),
key_ptr(n, 0), key_ptr(n, 0),
nr_entries * sizeof(__le64)); nr_entries * sizeof(__le64));
memmove(value_ptr(n, shift, value_size), memmove(value_ptr(n, shift),
value_ptr(n, 0, value_size), value_ptr(n, 0),
nr_entries * value_size); nr_entries * value_size);
} }
} }
...@@ -91,16 +91,16 @@ static void node_copy(struct node *left, struct node *right, int shift) ...@@ -91,16 +91,16 @@ static void node_copy(struct node *left, struct node *right, int shift)
memcpy(key_ptr(left, nr_left), memcpy(key_ptr(left, nr_left),
key_ptr(right, 0), key_ptr(right, 0),
shift * sizeof(__le64)); shift * sizeof(__le64));
memcpy(value_ptr(left, nr_left, value_size), memcpy(value_ptr(left, nr_left),
value_ptr(right, 0, value_size), value_ptr(right, 0),
shift * value_size); shift * value_size);
} else { } else {
BUG_ON(shift > le32_to_cpu(right->header.max_entries)); BUG_ON(shift > le32_to_cpu(right->header.max_entries));
memcpy(key_ptr(right, 0), memcpy(key_ptr(right, 0),
key_ptr(left, nr_left - shift), key_ptr(left, nr_left - shift),
shift * sizeof(__le64)); shift * sizeof(__le64));
memcpy(value_ptr(right, 0, value_size), memcpy(value_ptr(right, 0),
value_ptr(left, nr_left - shift, value_size), value_ptr(left, nr_left - shift),
shift * value_size); shift * value_size);
} }
} }
...@@ -120,8 +120,8 @@ static void delete_at(struct node *n, unsigned index) ...@@ -120,8 +120,8 @@ static void delete_at(struct node *n, unsigned index)
key_ptr(n, index + 1), key_ptr(n, index + 1),
nr_to_copy * sizeof(__le64)); nr_to_copy * sizeof(__le64));
memmove(value_ptr(n, index, value_size), memmove(value_ptr(n, index),
value_ptr(n, index + 1, value_size), value_ptr(n, index + 1),
nr_to_copy * value_size); nr_to_copy * value_size);
} }
...@@ -166,7 +166,7 @@ static int init_child(struct dm_btree_info *info, struct node *parent, ...@@ -166,7 +166,7 @@ static int init_child(struct dm_btree_info *info, struct node *parent,
if (inc) if (inc)
inc_children(info->tm, result->n, &le64_type); inc_children(info->tm, result->n, &le64_type);
*((__le64 *) value_ptr(parent, index, sizeof(__le64))) = *((__le64 *) value_ptr(parent, index)) =
cpu_to_le64(dm_block_location(result->block)); cpu_to_le64(dm_block_location(result->block));
return 0; return 0;
...@@ -520,7 +520,7 @@ static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info, ...@@ -520,7 +520,7 @@ static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info,
*/ */
if (shadow_has_parent(s)) { if (shadow_has_parent(s)) {
__le64 location = cpu_to_le64(dm_block_location(shadow_current(s))); __le64 location = cpu_to_le64(dm_block_location(shadow_current(s)));
memcpy(value_ptr(dm_block_data(shadow_parent(s)), i, sizeof(__le64)), memcpy(value_ptr(dm_block_data(shadow_parent(s)), i),
&location, sizeof(__le64)); &location, sizeof(__le64));
} }
...@@ -577,7 +577,7 @@ int dm_btree_remove(struct dm_btree_info *info, dm_block_t root, ...@@ -577,7 +577,7 @@ int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
if (info->value_type.dec) if (info->value_type.dec)
info->value_type.dec(info->value_type.context, info->value_type.dec(info->value_type.context,
value_ptr(n, index, info->value_type.size)); value_ptr(n, index));
delete_at(n, index); delete_at(n, index);
} }
......
...@@ -74,8 +74,7 @@ void inc_children(struct dm_transaction_manager *tm, struct node *n, ...@@ -74,8 +74,7 @@ void inc_children(struct dm_transaction_manager *tm, struct node *n,
dm_tm_inc(tm, value64(n, i)); dm_tm_inc(tm, value64(n, i));
else if (vt->inc) else if (vt->inc)
for (i = 0; i < nr_entries; i++) for (i = 0; i < nr_entries; i++)
vt->inc(vt->context, vt->inc(vt->context, value_ptr(n, i));
value_ptr(n, i, vt->size));
} }
static int insert_at(size_t value_size, struct node *node, unsigned index, static int insert_at(size_t value_size, struct node *node, unsigned index,
...@@ -281,7 +280,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root) ...@@ -281,7 +280,7 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
for (i = 0; i < f->nr_children; i++) for (i = 0; i < f->nr_children; i++)
info->value_type.dec(info->value_type.context, info->value_type.dec(info->value_type.context,
value_ptr(f->n, i, info->value_type.size)); value_ptr(f->n, i));
} }
f->current_child = f->nr_children; f->current_child = f->nr_children;
} }
...@@ -320,7 +319,7 @@ static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key, ...@@ -320,7 +319,7 @@ static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
} while (!(flags & LEAF_NODE)); } while (!(flags & LEAF_NODE));
*result_key = le64_to_cpu(ro_node(s)->keys[i]); *result_key = le64_to_cpu(ro_node(s)->keys[i]);
memcpy(v, value_ptr(ro_node(s), i, value_size), value_size); memcpy(v, value_ptr(ro_node(s), i), value_size);
return 0; return 0;
} }
...@@ -432,7 +431,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root, ...@@ -432,7 +431,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root,
size = le32_to_cpu(ln->header.flags) & INTERNAL_NODE ? size = le32_to_cpu(ln->header.flags) & INTERNAL_NODE ?
sizeof(uint64_t) : s->info->value_type.size; sizeof(uint64_t) : s->info->value_type.size;
memcpy(value_ptr(rn, 0, size), value_ptr(ln, nr_left, size), memcpy(value_ptr(rn, 0), value_ptr(ln, nr_left),
size * nr_right); size * nr_right);
/* /*
...@@ -443,7 +442,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root, ...@@ -443,7 +442,7 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root,
pn = dm_block_data(parent); pn = dm_block_data(parent);
location = cpu_to_le64(dm_block_location(left)); location = cpu_to_le64(dm_block_location(left));
__dm_bless_for_disk(&location); __dm_bless_for_disk(&location);
memcpy_disk(value_ptr(pn, parent_index, sizeof(__le64)), memcpy_disk(value_ptr(pn, parent_index),
&location, sizeof(__le64)); &location, sizeof(__le64));
location = cpu_to_le64(dm_block_location(right)); location = cpu_to_le64(dm_block_location(right));
...@@ -529,8 +528,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key) ...@@ -529,8 +528,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
size = le32_to_cpu(pn->header.flags) & INTERNAL_NODE ? size = le32_to_cpu(pn->header.flags) & INTERNAL_NODE ?
sizeof(__le64) : s->info->value_type.size; sizeof(__le64) : s->info->value_type.size;
memcpy(value_ptr(ln, 0, size), value_ptr(pn, 0, size), nr_left * size); memcpy(value_ptr(ln, 0), value_ptr(pn, 0), nr_left * size);
memcpy(value_ptr(rn, 0, size), value_ptr(pn, nr_left, size), memcpy(value_ptr(rn, 0), value_ptr(pn, nr_left),
nr_right * size); nr_right * size);
/* new_parent should just point to l and r now */ /* new_parent should just point to l and r now */
...@@ -545,12 +544,12 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key) ...@@ -545,12 +544,12 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
val = cpu_to_le64(dm_block_location(left)); val = cpu_to_le64(dm_block_location(left));
__dm_bless_for_disk(&val); __dm_bless_for_disk(&val);
pn->keys[0] = ln->keys[0]; pn->keys[0] = ln->keys[0];
memcpy_disk(value_ptr(pn, 0, sizeof(__le64)), &val, sizeof(__le64)); memcpy_disk(value_ptr(pn, 0), &val, sizeof(__le64));
val = cpu_to_le64(dm_block_location(right)); val = cpu_to_le64(dm_block_location(right));
__dm_bless_for_disk(&val); __dm_bless_for_disk(&val);
pn->keys[1] = rn->keys[0]; pn->keys[1] = rn->keys[0];
memcpy_disk(value_ptr(pn, 1, sizeof(__le64)), &val, sizeof(__le64)); memcpy_disk(value_ptr(pn, 1), &val, sizeof(__le64));
/* /*
* rejig the spine. This is ugly, since it knows too * rejig the spine. This is ugly, since it knows too
...@@ -595,7 +594,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root, ...@@ -595,7 +594,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root,
__le64 location = cpu_to_le64(dm_block_location(shadow_current(s))); __le64 location = cpu_to_le64(dm_block_location(shadow_current(s)));
__dm_bless_for_disk(&location); __dm_bless_for_disk(&location);
memcpy_disk(value_ptr(dm_block_data(shadow_parent(s)), i, sizeof(uint64_t)), memcpy_disk(value_ptr(dm_block_data(shadow_parent(s)), i),
&location, sizeof(__le64)); &location, sizeof(__le64));
} }
...@@ -710,12 +709,12 @@ static int insert(struct dm_btree_info *info, dm_block_t root, ...@@ -710,12 +709,12 @@ static int insert(struct dm_btree_info *info, dm_block_t root,
(!info->value_type.equal || (!info->value_type.equal ||
!info->value_type.equal( !info->value_type.equal(
info->value_type.context, info->value_type.context,
value_ptr(n, index, info->value_type.size), value_ptr(n, index),
value))) { value))) {
info->value_type.dec(info->value_type.context, info->value_type.dec(info->value_type.context,
value_ptr(n, index, info->value_type.size)); value_ptr(n, index));
} }
memcpy_disk(value_ptr(n, index, info->value_type.size), memcpy_disk(value_ptr(n, index),
value, info->value_type.size); value, info->value_type.size);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment