summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-06-09 16:56:16 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:23 -0400
commit436c656d468fe04cd8e313a4a55151aa946de102 (patch)
treeed1a1523fce5d476afe105b609d9e18da4171b64
parent1ae973345626fcd9cdb81fe856cabf7808a33140 (diff)
bcachefs: bkey_merge() now takes bkey_s
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/bkey_methods.c12
-rw-r--r--fs/bcachefs/bkey_methods.h4
-rw-r--r--fs/bcachefs/bkey_sort.c6
-rw-r--r--fs/bcachefs/extents.c54
-rw-r--r--fs/bcachefs/extents.h4
5 files changed, 42 insertions, 38 deletions
diff --git a/fs/bcachefs/bkey_methods.c b/fs/bcachefs/bkey_methods.c
index 571013a0d1a0..547f5b301ad4 100644
--- a/fs/bcachefs/bkey_methods.c
+++ b/fs/bcachefs/bkey_methods.c
@@ -199,22 +199,22 @@ bool bch2_bkey_normalize(struct bch_fs *c, struct bkey_s k)
}
enum merge_result bch2_bkey_merge(struct bch_fs *c,
- struct bkey_i *l, struct bkey_i *r)
+ struct bkey_s l, struct bkey_s r)
{
- const struct bkey_ops *ops = &bch2_bkey_ops[l->k.type];
+ const struct bkey_ops *ops = &bch2_bkey_ops[l.k->type];
enum merge_result ret;
if (key_merging_disabled(c) ||
!ops->key_merge ||
- l->k.type != r->k.type ||
- bversion_cmp(l->k.version, r->k.version) ||
- bkey_cmp(l->k.p, bkey_start_pos(&r->k)))
+ l.k->type != r.k->type ||
+ bversion_cmp(l.k->version, r.k->version) ||
+ bkey_cmp(l.k->p, bkey_start_pos(r.k)))
return BCH_MERGE_NOMERGE;
ret = ops->key_merge(c, l, r);
if (ret != BCH_MERGE_NOMERGE)
- l->k.needs_whiteout |= r->k.needs_whiteout;
+ l.k->needs_whiteout |= r.k->needs_whiteout;
return ret;
}
diff --git a/fs/bcachefs/bkey_methods.h b/fs/bcachefs/bkey_methods.h
index a4bfd2aef5bf..08b976633360 100644
--- a/fs/bcachefs/bkey_methods.h
+++ b/fs/bcachefs/bkey_methods.h
@@ -33,7 +33,7 @@ struct bkey_ops {
void (*swab)(const struct bkey_format *, struct bkey_packed *);
bool (*key_normalize)(struct bch_fs *, struct bkey_s);
enum merge_result (*key_merge)(struct bch_fs *,
- struct bkey_i *, struct bkey_i *);
+ struct bkey_s, struct bkey_s);
};
const char *bch2_bkey_val_invalid(struct bch_fs *, struct bkey_s_c);
@@ -57,7 +57,7 @@ void bch2_bkey_swab(const struct bkey_format *, struct bkey_packed *);
bool bch2_bkey_normalize(struct bch_fs *, struct bkey_s);
enum merge_result bch2_bkey_merge(struct bch_fs *,
- struct bkey_i *, struct bkey_i *);
+ struct bkey_s, struct bkey_s);
void bch2_bkey_renumber(enum btree_node_type, struct bkey_packed *, int);
diff --git a/fs/bcachefs/bkey_sort.c b/fs/bcachefs/bkey_sort.c
index 12825c1b292f..d4fbb694ee52 100644
--- a/fs/bcachefs/bkey_sort.c
+++ b/fs/bcachefs/bkey_sort.c
@@ -257,7 +257,7 @@ static void extent_sort_append(struct bch_fs *c,
bch2_bkey_unpack(b, &tmp.k, k);
if (*prev &&
- bch2_bkey_merge(c, (void *) *prev, &tmp.k))
+ bch2_bkey_merge(c, bkey_i_to_s((void *) *prev), bkey_i_to_s(&tmp.k)))
return;
if (*prev) {
@@ -436,7 +436,9 @@ bch2_sort_repack_merge(struct bch_fs *c,
/* prev is always unpacked, for key merging: */
if (prev &&
- bch2_bkey_merge(c, (void *) prev, &tmp.k) ==
+ bch2_bkey_merge(c,
+ bkey_i_to_s((void *) prev),
+ bkey_i_to_s(&tmp.k)) ==
BCH_MERGE_MERGE)
continue;
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index a5582a6f6ef6..b55d52ec43a0 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1521,21 +1521,21 @@ void bch2_extent_mark_replicas_cached(struct bch_fs *c,
}
enum merge_result bch2_extent_merge(struct bch_fs *c,
- struct bkey_i *l, struct bkey_i *r)
+ struct bkey_s _l, struct bkey_s _r)
{
- struct bkey_s_extent el = bkey_i_to_s_extent(l);
- struct bkey_s_extent er = bkey_i_to_s_extent(r);
- union bch_extent_entry *en_l = el.v->start;
- union bch_extent_entry *en_r = er.v->start;
+ struct bkey_s_extent l = bkey_s_to_extent(_l);
+ struct bkey_s_extent r = bkey_s_to_extent(_r);
+ union bch_extent_entry *en_l = l.v->start;
+ union bch_extent_entry *en_r = r.v->start;
struct bch_extent_crc_unpacked crc_l, crc_r;
- if (bkey_val_u64s(&l->k) != bkey_val_u64s(&r->k))
+ if (bkey_val_u64s(l.k) != bkey_val_u64s(r.k))
return BCH_MERGE_NOMERGE;
- crc_l = bch2_extent_crc_unpack(el.k, NULL);
+ crc_l = bch2_extent_crc_unpack(l.k, NULL);
- extent_for_each_entry(el, en_l) {
- en_r = vstruct_idx(er.v, (u64 *) en_l - el.v->_data);
+ extent_for_each_entry(l, en_l) {
+ en_r = vstruct_idx(r.v, (u64 *) en_l - l.v->_data);
if (extent_entry_type(en_l) != extent_entry_type(en_r))
return BCH_MERGE_NOMERGE;
@@ -1567,8 +1567,8 @@ enum merge_result bch2_extent_merge(struct bch_fs *c,
case BCH_EXTENT_ENTRY_crc32:
case BCH_EXTENT_ENTRY_crc64:
case BCH_EXTENT_ENTRY_crc128:
- crc_l = bch2_extent_crc_unpack(el.k, entry_to_crc(en_l));
- crc_r = bch2_extent_crc_unpack(er.k, entry_to_crc(en_r));
+ crc_l = bch2_extent_crc_unpack(l.k, entry_to_crc(en_l));
+ crc_r = bch2_extent_crc_unpack(r.k, entry_to_crc(en_r));
if (crc_l.csum_type != crc_r.csum_type ||
crc_l.compression_type != crc_r.compression_type ||
@@ -1600,16 +1600,16 @@ enum merge_result bch2_extent_merge(struct bch_fs *c,
}
}
- extent_for_each_entry(el, en_l) {
+ extent_for_each_entry(l, en_l) {
struct bch_extent_crc_unpacked crc_l, crc_r;
- en_r = vstruct_idx(er.v, (u64 *) en_l - el.v->_data);
+ en_r = vstruct_idx(r.v, (u64 *) en_l - l.v->_data);
if (!extent_entry_is_crc(en_l))
continue;
- crc_l = bch2_extent_crc_unpack(el.k, entry_to_crc(en_l));
- crc_r = bch2_extent_crc_unpack(er.k, entry_to_crc(en_r));
+ crc_l = bch2_extent_crc_unpack(l.k, entry_to_crc(en_l));
+ crc_r = bch2_extent_crc_unpack(r.k, entry_to_crc(en_r));
crc_l.csum = bch2_checksum_merge(crc_l.csum_type,
crc_l.csum,
@@ -1622,7 +1622,7 @@ enum merge_result bch2_extent_merge(struct bch_fs *c,
bch2_extent_crc_pack(entry_to_crc(en_l), crc_l);
}
- bch2_key_resize(&l->k, l->k.size + r->k.size);
+ bch2_key_resize(l.k, l.k->size + r.k->size);
return BCH_MERGE_MERGE;
}
@@ -1662,7 +1662,9 @@ static bool bch2_extent_merge_inline(struct bch_fs *c,
bch2_bkey_unpack(b, &li.k, l);
bch2_bkey_unpack(b, &ri.k, r);
- ret = bch2_bkey_merge(c, &li.k, &ri.k);
+ ret = bch2_bkey_merge(c,
+ bkey_i_to_s(&li.k),
+ bkey_i_to_s(&ri.k));
if (ret == BCH_MERGE_NOMERGE)
return false;
@@ -1785,22 +1787,22 @@ void bch2_reservation_to_text(struct printbuf *out, struct bch_fs *c,
}
enum merge_result bch2_reservation_merge(struct bch_fs *c,
- struct bkey_i *l, struct bkey_i *r)
+ struct bkey_s _l, struct bkey_s _r)
{
- struct bkey_i_reservation *li = bkey_i_to_reservation(l);
- struct bkey_i_reservation *ri = bkey_i_to_reservation(r);
+ struct bkey_s_reservation l = bkey_s_to_reservation(_l);
+ struct bkey_s_reservation r = bkey_s_to_reservation(_r);
- if (li->v.generation != ri->v.generation ||
- li->v.nr_replicas != ri->v.nr_replicas)
+ if (l.v->generation != r.v->generation ||
+ l.v->nr_replicas != r.v->nr_replicas)
return BCH_MERGE_NOMERGE;
- if ((u64) l->k.size + r->k.size > KEY_SIZE_MAX) {
- bch2_key_resize(&l->k, KEY_SIZE_MAX);
- bch2_cut_front(l->k.p, r);
+ if ((u64) l.k->size + r.k->size > KEY_SIZE_MAX) {
+ bch2_key_resize(l.k, KEY_SIZE_MAX);
+ __bch2_cut_front(l.k->p, r.s);
return BCH_MERGE_PARTIAL;
}
- bch2_key_resize(&l->k, l->k.size + r->k.size);
+ bch2_key_resize(l.k, l.k->size + r.k->size);
return BCH_MERGE_MERGE;
}
diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h
index 4cd16e8a2af6..fe92737354bd 100644
--- a/fs/bcachefs/extents.h
+++ b/fs/bcachefs/extents.h
@@ -386,7 +386,7 @@ void bch2_extent_debugcheck(struct bch_fs *, struct btree *, struct bkey_s_c);
void bch2_extent_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
bool bch2_extent_normalize(struct bch_fs *, struct bkey_s);
enum merge_result bch2_extent_merge(struct bch_fs *,
- struct bkey_i *, struct bkey_i *);
+ struct bkey_s, struct bkey_s);
#define bch2_bkey_ops_extent (struct bkey_ops) { \
.key_invalid = bch2_extent_invalid, \
@@ -402,7 +402,7 @@ enum merge_result bch2_extent_merge(struct bch_fs *,
const char *bch2_reservation_invalid(const struct bch_fs *, struct bkey_s_c);
void bch2_reservation_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
enum merge_result bch2_reservation_merge(struct bch_fs *,
- struct bkey_i *, struct bkey_i *);
+ struct bkey_s, struct bkey_s);
#define bch2_bkey_ops_reservation (struct bkey_ops) { \
.key_invalid = bch2_reservation_invalid, \