Update bcachefs sources to c6d45169c6 bcachefs: Convert split_devs() to darray

This commit is contained in:
Kent Overstreet 2023-12-22 21:21:14 -05:00
parent e962ffb769
commit 5134a64ceb
21 changed files with 137 additions and 109 deletions

View File

@ -1 +1 @@
df6415fefb2790c3b95fa87ead779e7d2c654379 c6d45169c6e3b4e42a189c9e87d1d14070033f01

View File

@ -2147,6 +2147,19 @@ enum {
BCH_JSET_ENTRY_NR BCH_JSET_ENTRY_NR
}; };
static inline bool jset_entry_is_key(struct jset_entry *e)
{
switch (e->type) {
case BCH_JSET_ENTRY_btree_keys:
case BCH_JSET_ENTRY_btree_root:
case BCH_JSET_ENTRY_overwrite:
case BCH_JSET_ENTRY_write_buffer_keys:
return true;
}
return false;
}
/* /*
* Journal sequence numbers can be blacklisted: bsets record the max sequence * Journal sequence numbers can be blacklisted: bsets record the max sequence
* number of all the journal entries they contain updates for, so that on * number of all the journal entries they contain updates for, so that on

View File

@ -1844,7 +1844,6 @@ static int gc_btree_gens_key(struct btree_trans *trans,
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
struct bkey_i *u; struct bkey_i *u;
int ret; int ret;

View File

@ -934,7 +934,6 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
struct sort_iter *iter; struct sort_iter *iter;
struct btree_node *sorted; struct btree_node *sorted;
struct bkey_packed *k; struct bkey_packed *k;
struct bch_extent_ptr *ptr;
struct bset *i; struct bset *i;
bool used_mempool, blacklisted; bool used_mempool, blacklisted;
bool updated_range = b->key.k.type == KEY_TYPE_btree_ptr_v2 && bool updated_range = b->key.k.type == KEY_TYPE_btree_ptr_v2 &&
@ -1894,7 +1893,6 @@ static int validate_bset_for_write(struct bch_fs *c, struct btree *b,
static void btree_write_submit(struct work_struct *work) static void btree_write_submit(struct work_struct *work)
{ {
struct btree_write_bio *wbio = container_of(work, struct btree_write_bio, work); struct btree_write_bio *wbio = container_of(work, struct btree_write_bio, work);
struct bch_extent_ptr *ptr;
BKEY_PADDED_ONSTACK(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp; BKEY_PADDED_ONSTACK(k, BKEY_BTREE_PTR_VAL_U64s_MAX) tmp;
bkey_copy(&tmp.k, &wbio->key); bkey_copy(&tmp.k, &wbio->key);

View File

@ -12,6 +12,7 @@
#include "errcode.h" #include "errcode.h"
#include "error.h" #include "error.h"
#include "journal.h" #include "journal.h"
#include "journal_io.h"
#include "journal_reclaim.h" #include "journal_reclaim.h"
#include "replicas.h" #include "replicas.h"
#include "snapshot.h" #include "snapshot.h"
@ -798,6 +799,27 @@ static noinline int bch2_trans_commit_bkey_invalid(struct btree_trans *trans,
return -EINVAL; return -EINVAL;
} }
static noinline int bch2_trans_commit_journal_entry_invalid(struct btree_trans *trans,
struct jset_entry *i)
{
struct bch_fs *c = trans->c;
struct printbuf buf = PRINTBUF;
prt_printf(&buf, "invalid bkey on insert from %s", trans->fn);
prt_newline(&buf);
printbuf_indent_add(&buf, 2);
bch2_journal_entry_to_text(&buf, c, i);
prt_newline(&buf);
bch2_print_string_as_lines(KERN_ERR, buf.buf);
bch2_inconsistent_error(c);
bch2_dump_trans_updates(trans);
return -EINVAL;
}
static int bch2_trans_commit_journal_pin_flush(struct journal *j, static int bch2_trans_commit_journal_pin_flush(struct journal *j,
struct journal_entry_pin *_pin, u64 seq) struct journal_entry_pin *_pin, u64 seq)
{ {
@ -998,6 +1020,26 @@ int __bch2_trans_commit(struct btree_trans *trans, unsigned flags)
return ret; return ret;
} }
for (struct jset_entry *i = trans->journal_entries;
i != (void *) ((u64 *) trans->journal_entries + trans->journal_entries_u64s);
i = vstruct_next(i)) {
if (!jset_entry_is_key(i))
continue;
enum bkey_invalid_flags invalid_flags = 0;
if (!(flags & BCH_TRANS_COMMIT_no_journal_res))
invalid_flags |= BKEY_INVALID_WRITE|BKEY_INVALID_COMMIT;
if (unlikely(bch2_journal_entry_validate(c, NULL, i,
bcachefs_metadata_version_current,
CPU_BIG_ENDIAN, invalid_flags)))
ret = bch2_trans_commit_journal_entry_invalid(trans, i);
if (ret)
return ret;
}
if (unlikely(!test_bit(BCH_FS_may_go_rw, &c->flags))) { if (unlikely(!test_bit(BCH_FS_may_go_rw, &c->flags))) {
ret = do_bch2_trans_commit_to_journal_replay(trans); ret = do_bch2_trans_commit_to_journal_replay(trans);
goto out_reset; goto out_reset;

View File

@ -186,8 +186,11 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
enum btree_id btree_id = iter->btree_id; enum btree_id btree_id = iter->btree_id;
struct bkey_i *update; struct bkey_i *update;
struct bpos new_start = bkey_start_pos(new.k); struct bpos new_start = bkey_start_pos(new.k);
bool front_split = bkey_lt(bkey_start_pos(old.k), new_start); unsigned front_split = bkey_lt(bkey_start_pos(old.k), new_start);
bool back_split = bkey_gt(old.k->p, new.k->p); unsigned back_split = bkey_gt(old.k->p, new.k->p);
unsigned middle_split = (front_split || back_split) &&
old.k->p.snapshot != new.k->p.snapshot;
unsigned nr_splits = front_split + back_split + middle_split;
int ret = 0, compressed_sectors; int ret = 0, compressed_sectors;
/* /*
@ -195,10 +198,9 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
* so that __bch2_trans_commit() can increase our disk * so that __bch2_trans_commit() can increase our disk
* reservation: * reservation:
*/ */
if (((front_split && back_split) || if (nr_splits > 1 &&
((front_split || back_split) && old.k->p.snapshot != new.k->p.snapshot)) &&
(compressed_sectors = bch2_bkey_sectors_compressed(old))) (compressed_sectors = bch2_bkey_sectors_compressed(old)))
trans->extra_disk_res += compressed_sectors; trans->extra_disk_res += compressed_sectors * (nr_splits - 1);
if (front_split) { if (front_split) {
update = bch2_bkey_make_mut_noupdate(trans, old); update = bch2_bkey_make_mut_noupdate(trans, old);
@ -216,8 +218,7 @@ int bch2_trans_update_extent_overwrite(struct btree_trans *trans,
} }
/* If we're overwriting in a different snapshot - middle split: */ /* If we're overwriting in a different snapshot - middle split: */
if (old.k->p.snapshot != new.k->p.snapshot && if (middle_split) {
(front_split || back_split)) {
update = bch2_bkey_make_mut_noupdate(trans, old); update = bch2_bkey_make_mut_noupdate(trans, old);
if ((ret = PTR_ERR_OR_ZERO(update))) if ((ret = PTR_ERR_OR_ZERO(update)))
return ret; return ret;

View File

@ -556,8 +556,6 @@ static void btree_update_add_key(struct btree_update *as,
static int btree_update_nodes_written_trans(struct btree_trans *trans, static int btree_update_nodes_written_trans(struct btree_trans *trans,
struct btree_update *as) struct btree_update *as)
{ {
struct bkey_i *k;
struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, as->journal_u64s); struct jset_entry *e = bch2_trans_jset_entry_alloc(trans, as->journal_u64s);
int ret = PTR_ERR_OR_ZERO(e); int ret = PTR_ERR_OR_ZERO(e);
if (ret) if (ret)

View File

@ -17,6 +17,7 @@ struct { \
} }
typedef DARRAY(void) darray_void; typedef DARRAY(void) darray_void;
typedef DARRAY(char *) darray_str;
int __bch2_darray_resize(darray_void *, size_t, size_t, gfp_t); int __bch2_darray_resize(darray_void *, size_t, size_t, gfp_t);

View File

@ -356,7 +356,6 @@ void bch2_data_update_exit(struct data_update *update)
struct bch_fs *c = update->op.c; struct bch_fs *c = update->op.c;
struct bkey_ptrs_c ptrs = struct bkey_ptrs_c ptrs =
bch2_bkey_ptrs_c(bkey_i_to_s_c(update->k.k)); bch2_bkey_ptrs_c(bkey_i_to_s_c(update->k.k));
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {
if (c->opts.nocow_enabled) if (c->opts.nocow_enabled)
@ -377,7 +376,6 @@ static void bch2_update_unwritten_extent(struct btree_trans *trans,
struct bio *bio = &update->op.wbio.bio; struct bio *bio = &update->op.wbio.bio;
struct bkey_i_extent *e; struct bkey_i_extent *e;
struct write_point *wp; struct write_point *wp;
struct bch_extent_ptr *ptr;
struct closure cl; struct closure cl;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
@ -509,7 +507,6 @@ int bch2_data_update_init(struct btree_trans *trans,
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const union bch_extent_entry *entry; const union bch_extent_entry *entry;
struct extent_ptr_decoded p; struct extent_ptr_decoded p;
const struct bch_extent_ptr *ptr;
unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas; unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas;
unsigned ptrs_locked = 0; unsigned ptrs_locked = 0;
int ret = 0; int ret = 0;
@ -654,7 +651,6 @@ done:
void bch2_data_update_opts_normalize(struct bkey_s_c k, struct data_update_opts *opts) void bch2_data_update_opts_normalize(struct bkey_s_c k, struct data_update_opts *opts)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
unsigned i = 0; unsigned i = 0;
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {

View File

@ -161,7 +161,6 @@ static const struct bch_extent_ptr *bkey_matches_stripe(struct bch_stripe *s,
struct bkey_s_c k, unsigned *block) struct bkey_s_c k, unsigned *block)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
unsigned i, nr_data = s->nr_blocks - s->nr_redundant; unsigned i, nr_data = s->nr_blocks - s->nr_redundant;
bkey_for_each_ptr(ptrs, ptr) bkey_for_each_ptr(ptrs, ptr)

View File

@ -843,7 +843,6 @@ void bch2_bkey_drop_device_noerror(struct bkey_s k, unsigned dev)
const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev) const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(ptrs, ptr) bkey_for_each_ptr(ptrs, ptr)
if (ptr->dev == dev) if (ptr->dev == dev)
@ -855,7 +854,6 @@ const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned
bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target) bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(ptrs, ptr) bkey_for_each_ptr(ptrs, ptr)
if (bch2_dev_in_target(c, ptr->dev, target) && if (bch2_dev_in_target(c, ptr->dev, target) &&
@ -1065,7 +1063,6 @@ static int extent_ptr_invalid(struct bch_fs *c,
struct printbuf *err) struct printbuf *err)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr2;
u64 bucket; u64 bucket;
u32 bucket_offset; u32 bucket_offset;
struct bch_dev *ca; struct bch_dev *ca;
@ -1307,7 +1304,6 @@ unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k,
} }
incompressible: incompressible:
if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) { if (target && bch2_target_accepts_data(c, BCH_DATA_user, target)) {
const struct bch_extent_ptr *ptr;
unsigned i = 0; unsigned i = 0;
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {

View File

@ -300,7 +300,7 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
bkey_extent_entry_for_each_from(_p, _entry, _p.start) bkey_extent_entry_for_each_from(_p, _entry, _p.start)
#define __bkey_for_each_ptr(_start, _end, _ptr) \ #define __bkey_for_each_ptr(_start, _end, _ptr) \
for ((_ptr) = (_start); \ for (typeof(_start) (_ptr) = (_start); \
((_ptr) = __bkey_ptr_next(_ptr, _end)); \ ((_ptr) = __bkey_ptr_next(_ptr, _end)); \
(_ptr)++) (_ptr)++)
@ -547,7 +547,6 @@ static inline bool bkey_extent_is_allocation(const struct bkey *k)
static inline bool bkey_extent_is_unwritten(struct bkey_s_c k) static inline bool bkey_extent_is_unwritten(struct bkey_s_c k)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(ptrs, ptr) bkey_for_each_ptr(ptrs, ptr)
if (ptr->unwritten) if (ptr->unwritten)
@ -565,7 +564,6 @@ static inline struct bch_devs_list bch2_bkey_devs(struct bkey_s_c k)
{ {
struct bch_devs_list ret = (struct bch_devs_list) { 0 }; struct bch_devs_list ret = (struct bch_devs_list) { 0 };
struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
ret.devs[ret.nr++] = ptr->dev; ret.devs[ret.nr++] = ptr->dev;
@ -577,7 +575,6 @@ static inline struct bch_devs_list bch2_bkey_dirty_devs(struct bkey_s_c k)
{ {
struct bch_devs_list ret = (struct bch_devs_list) { 0 }; struct bch_devs_list ret = (struct bch_devs_list) { 0 };
struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
if (!ptr->cached) if (!ptr->cached)
@ -590,7 +587,6 @@ static inline struct bch_devs_list bch2_bkey_cached_devs(struct bkey_s_c k)
{ {
struct bch_devs_list ret = (struct bch_devs_list) { 0 }; struct bch_devs_list ret = (struct bch_devs_list) { 0 };
struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c p = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
if (ptr->cached) if (ptr->cached)

View File

@ -1596,31 +1596,6 @@ static struct bch_fs *bch2_path_to_fs(const char *path)
return c ?: ERR_PTR(-ENOENT); return c ?: ERR_PTR(-ENOENT);
} }
static char **split_devs(const char *_dev_name, unsigned *nr)
{
char *dev_name = NULL, **devs = NULL, *s;
size_t i = 0, nr_devs = 0;
dev_name = kstrdup(_dev_name, GFP_KERNEL);
if (!dev_name)
return NULL;
for (s = dev_name; s; s = strchr(s + 1, ':'))
nr_devs++;
devs = kcalloc(nr_devs + 1, sizeof(const char *), GFP_KERNEL);
if (!devs) {
kfree(dev_name);
return NULL;
}
while ((s = strsep(&dev_name, ":")))
devs[i++] = s;
*nr = nr_devs;
return devs;
}
static int bch2_remount(struct super_block *sb, int *flags, char *data) static int bch2_remount(struct super_block *sb, int *flags, char *data)
{ {
struct bch_fs *c = sb->s_fs_info; struct bch_fs *c = sb->s_fs_info;
@ -1773,17 +1748,18 @@ static int bch2_noset_super(struct super_block *s, void *data)
return -EBUSY; return -EBUSY;
} }
typedef DARRAY(struct bch_fs *) darray_fs;
static int bch2_test_super(struct super_block *s, void *data) static int bch2_test_super(struct super_block *s, void *data)
{ {
struct bch_fs *c = s->s_fs_info; struct bch_fs *c = s->s_fs_info;
struct bch_fs **devs = data; darray_fs *d = data;
unsigned i;
if (!c) if (!c)
return false; return false;
for (i = 0; devs[i]; i++) darray_for_each(*d, i)
if (c != devs[i]) if (c != *i)
return false; return false;
return true; return true;
} }
@ -1795,9 +1771,6 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
struct super_block *sb; struct super_block *sb;
struct inode *vinode; struct inode *vinode;
struct bch_opts opts = bch2_opts_empty(); struct bch_opts opts = bch2_opts_empty();
char **devs;
struct bch_fs **devs_to_fs = NULL;
unsigned nr_devs;
int ret; int ret;
opt_set(opts, read_only, (flags & SB_RDONLY) != 0); opt_set(opts, read_only, (flags & SB_RDONLY) != 0);
@ -1809,25 +1782,25 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
if (!dev_name || strlen(dev_name) == 0) if (!dev_name || strlen(dev_name) == 0)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
devs = split_devs(dev_name, &nr_devs); darray_str devs;
if (!devs) ret = bch2_split_devs(dev_name, &devs);
return ERR_PTR(-ENOMEM); if (ret)
return ERR_PTR(ret);
devs_to_fs = kcalloc(nr_devs + 1, sizeof(void *), GFP_KERNEL); darray_fs devs_to_fs = {};
if (!devs_to_fs) { darray_for_each(devs, i) {
sb = ERR_PTR(-ENOMEM); ret = darray_push(&devs_to_fs, bch2_path_to_fs(*i));
if (ret) {
sb = ERR_PTR(ret);
goto got_sb; goto got_sb;
} }
}
for (unsigned i = 0; i < nr_devs; i++) sb = sget(fs_type, bch2_test_super, bch2_noset_super, flags|SB_NOSEC, &devs_to_fs);
devs_to_fs[i] = bch2_path_to_fs(devs[i]);
sb = sget(fs_type, bch2_test_super, bch2_noset_super,
flags|SB_NOSEC, devs_to_fs);
if (!IS_ERR(sb)) if (!IS_ERR(sb))
goto got_sb; goto got_sb;
c = bch2_fs_open(devs, nr_devs, opts); c = bch2_fs_open(devs.data, devs.nr, opts);
if (IS_ERR(c)) { if (IS_ERR(c)) {
sb = ERR_CAST(c); sb = ERR_CAST(c);
goto got_sb; goto got_sb;
@ -1847,9 +1820,8 @@ static struct dentry *bch2_mount(struct file_system_type *fs_type,
if (IS_ERR(sb)) if (IS_ERR(sb))
bch2_fs_stop(c); bch2_fs_stop(c);
got_sb: got_sb:
kfree(devs_to_fs); darray_exit(&devs_to_fs);
kfree(devs[0]); bch2_darray_str_exit(&devs);
kfree(devs);
if (IS_ERR(sb)) { if (IS_ERR(sb)) {
ret = PTR_ERR(sb); ret = PTR_ERR(sb);

View File

@ -74,7 +74,6 @@ int bch2_extent_fallocate(struct btree_trans *trans,
struct bkey_i_extent *e; struct bkey_i_extent *e;
struct bch_devs_list devs_have; struct bch_devs_list devs_have;
struct write_point *wp; struct write_point *wp;
struct bch_extent_ptr *ptr;
devs_have.nr = 0; devs_have.nr = 0;

View File

@ -396,16 +396,14 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *wbio, struct bch_fs *c,
bool nocow) bool nocow)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k)); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k));
const struct bch_extent_ptr *ptr;
struct bch_write_bio *n; struct bch_write_bio *n;
struct bch_dev *ca;
BUG_ON(c->opts.nochanges); BUG_ON(c->opts.nochanges);
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {
BUG_ON(!bch2_dev_exists2(c, ptr->dev)); BUG_ON(!bch2_dev_exists2(c, ptr->dev));
ca = bch_dev_bkey_exists(c, ptr->dev); struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev);
if (to_entry(ptr + 1) < ptrs.end) { if (to_entry(ptr + 1) < ptrs.end) {
n = to_wbio(bio_alloc_clone(NULL, &wbio->bio, n = to_wbio(bio_alloc_clone(NULL, &wbio->bio,
@ -1108,8 +1106,6 @@ static bool bch2_extent_is_writeable(struct bch_write_op *op,
static inline void bch2_nocow_write_unlock(struct bch_write_op *op) static inline void bch2_nocow_write_unlock(struct bch_write_op *op)
{ {
struct bch_fs *c = op->c; struct bch_fs *c = op->c;
const struct bch_extent_ptr *ptr;
struct bkey_i *k;
for_each_keylist_key(&op->insert_keys, k) { for_each_keylist_key(&op->insert_keys, k) {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k)); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(k));
@ -1127,25 +1123,20 @@ static int bch2_nocow_write_convert_one_unwritten(struct btree_trans *trans,
struct bkey_s_c k, struct bkey_s_c k,
u64 new_i_size) u64 new_i_size)
{ {
struct bkey_i *new;
struct bkey_ptrs ptrs;
struct bch_extent_ptr *ptr;
int ret;
if (!bch2_extents_match(bkey_i_to_s_c(orig), k)) { if (!bch2_extents_match(bkey_i_to_s_c(orig), k)) {
/* trace this */ /* trace this */
return 0; return 0;
} }
new = bch2_bkey_make_mut_noupdate(trans, k); struct bkey_i *new = bch2_bkey_make_mut_noupdate(trans, k);
ret = PTR_ERR_OR_ZERO(new); int ret = PTR_ERR_OR_ZERO(new);
if (ret) if (ret)
return ret; return ret;
bch2_cut_front(bkey_start_pos(&orig->k), new); bch2_cut_front(bkey_start_pos(&orig->k), new);
bch2_cut_back(orig->k.p, new); bch2_cut_back(orig->k.p, new);
ptrs = bch2_bkey_ptrs(bkey_i_to_s(new)); struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(new));
bkey_for_each_ptr(ptrs, ptr) bkey_for_each_ptr(ptrs, ptr)
ptr->unwritten = 0; ptr->unwritten = 0;
@ -1166,11 +1157,9 @@ static void bch2_nocow_write_convert_unwritten(struct bch_write_op *op)
{ {
struct bch_fs *c = op->c; struct bch_fs *c = op->c;
struct btree_trans *trans = bch2_trans_get(c); struct btree_trans *trans = bch2_trans_get(c);
struct bkey_i *orig;
int ret;
for_each_keylist_key(&op->insert_keys, orig) { for_each_keylist_key(&op->insert_keys, orig) {
ret = for_each_btree_key_upto_commit(trans, iter, BTREE_ID_extents, int ret = for_each_btree_key_upto_commit(trans, iter, BTREE_ID_extents,
bkey_start_pos(&orig->k), orig->k.p, bkey_start_pos(&orig->k), orig->k.p,
BTREE_ITER_INTENT, k, BTREE_ITER_INTENT, k,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({ NULL, NULL, BCH_TRANS_COMMIT_no_enospc, ({
@ -1219,8 +1208,6 @@ static void bch2_nocow_write(struct bch_write_op *op)
struct btree_trans *trans; struct btree_trans *trans;
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_ptrs_c ptrs;
const struct bch_extent_ptr *ptr;
struct { struct {
struct bpos b; struct bpos b;
unsigned gen; unsigned gen;
@ -1266,7 +1253,7 @@ retry:
break; break;
/* Get iorefs before dropping btree locks: */ /* Get iorefs before dropping btree locks: */
ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
bkey_for_each_ptr(ptrs, ptr) { bkey_for_each_ptr(ptrs, ptr) {
buckets[nr_buckets].b = PTR_BUCKET_POS(c, ptr); buckets[nr_buckets].b = PTR_BUCKET_POS(c, ptr);
buckets[nr_buckets].gen = ptr->gen; buckets[nr_buckets].gen = ptr->gen;

View File

@ -409,8 +409,10 @@ static int journal_entry_btree_root_validate(struct bch_fs *c,
return 0; return 0;
} }
return journal_validate_key(c, jset, entry, 1, entry->btree_id, k, ret = journal_validate_key(c, jset, entry, 1, entry->btree_id, k,
version, big_endian, flags); version, big_endian, flags);
if (ret == FSCK_DELETED_KEY)
ret = 0;
fsck_err: fsck_err:
return ret; return ret;
} }
@ -1676,7 +1678,6 @@ static CLOSURE_CALLBACK(do_journal_write)
struct bch_fs *c = container_of(j, struct bch_fs, journal); struct bch_fs *c = container_of(j, struct bch_fs, journal);
struct bch_dev *ca; struct bch_dev *ca;
struct journal_buf *w = journal_last_unwritten_buf(j); struct journal_buf *w = journal_last_unwritten_buf(j);
struct bch_extent_ptr *ptr;
struct bio *bio; struct bio *bio;
unsigned sectors = vstruct_sectors(w->data, c->block_bits); unsigned sectors = vstruct_sectors(w->data, c->block_bits);

View File

@ -43,8 +43,6 @@ void bch2_keylist_pop_front(struct keylist *l)
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef CONFIG_BCACHEFS_DEBUG
void bch2_verify_keylist_sorted(struct keylist *l) void bch2_verify_keylist_sorted(struct keylist *l)
{ {
struct bkey_i *k;
for_each_keylist_key(l, k) for_each_keylist_key(l, k)
BUG_ON(bkey_next(k) != l->top && BUG_ON(bkey_next(k) != l->top &&
bpos_ge(k->k.p, bkey_next(k)->k.p)); bpos_ge(k->k.p, bkey_next(k)->k.p));

View File

@ -50,18 +50,16 @@ static inline struct bkey_i *bch2_keylist_front(struct keylist *l)
} }
#define for_each_keylist_key(_keylist, _k) \ #define for_each_keylist_key(_keylist, _k) \
for (_k = (_keylist)->keys; \ for (struct bkey_i *_k = (_keylist)->keys; \
_k != (_keylist)->top; \ _k != (_keylist)->top; \
_k = bkey_next(_k)) _k = bkey_next(_k))
static inline u64 keylist_sectors(struct keylist *keys) static inline u64 keylist_sectors(struct keylist *keys)
{ {
struct bkey_i *k;
u64 ret = 0; u64 ret = 0;
for_each_keylist_key(keys, k) for_each_keylist_key(keys, k)
ret += k->k.size; ret += k->k.size;
return ret; return ret;
} }

View File

@ -695,9 +695,6 @@ int bch2_evacuate_bucket(struct moving_context *ctxt,
break; break;
if (!bp.level) { if (!bp.level) {
const struct bch_extent_ptr *ptr;
unsigned i = 0;
k = bch2_backpointer_get_key(trans, &iter, bp_pos, bp, 0); k = bch2_backpointer_get_key(trans, &iter, bp_pos, bp, 0);
ret = bkey_err(k); ret = bkey_err(k);
if (bch2_err_matches(ret, BCH_ERR_transaction_restart)) if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
@ -720,6 +717,7 @@ int bch2_evacuate_bucket(struct moving_context *ctxt,
data_opts.target = io_opts.background_target; data_opts.target = io_opts.background_target;
data_opts.rewrite_ptrs = 0; data_opts.rewrite_ptrs = 0;
unsigned i = 0;
bkey_for_each_ptr(bch2_bkey_ptrs_c(k), ptr) { bkey_for_each_ptr(bch2_bkey_ptrs_c(k), ptr) {
if (ptr->dev == bucket.inode) { if (ptr->dev == bucket.inode) {
data_opts.rewrite_ptrs |= 1U << i; data_opts.rewrite_ptrs |= 1U << i;
@ -890,7 +888,6 @@ static bool migrate_pred(struct bch_fs *c, void *arg,
struct data_update_opts *data_opts) struct data_update_opts *data_opts)
{ {
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
const struct bch_extent_ptr *ptr;
struct bch_ioctl_data *op = arg; struct bch_ioctl_data *op = arg;
unsigned i = 0; unsigned i = 0;

View File

@ -1174,3 +1174,37 @@ u64 *bch2_acc_percpu_u64s(u64 __percpu *p, unsigned nr)
return ret; return ret;
} }
void bch2_darray_str_exit(darray_str *d)
{
darray_for_each(*d, i)
kfree(*i);
darray_exit(d);
}
int bch2_split_devs(const char *_dev_name, darray_str *ret)
{
darray_init(ret);
char *dev_name = kstrdup(_dev_name, GFP_KERNEL), *s = dev_name;
if (!dev_name)
return -ENOMEM;
while ((s = strsep(&dev_name, ":"))) {
char *p = kstrdup(s, GFP_KERNEL);
if (!p)
goto err;
if (darray_push(ret, p)) {
kfree(p);
goto err;
}
}
kfree(dev_name);
return 0;
err:
bch2_darray_str_exit(ret);
kfree(dev_name);
return -ENOMEM;
}

View File

@ -862,4 +862,7 @@ static inline bool qstr_eq(const struct qstr l, const struct qstr r)
return l.len == r.len && !memcmp(l.name, r.name, l.len); return l.len == r.len && !memcmp(l.name, r.name, l.len);
} }
void bch2_darray_str_exit(darray_str *);
int bch2_split_devs(const char *, darray_str *);
#endif /* _BCACHEFS_UTIL_H */ #endif /* _BCACHEFS_UTIL_H */