diff options
-rw-r--r-- | fs/bcachefs/io.c | 11 | ||||
-rw-r--r-- | fs/bcachefs/io.h | 49 | ||||
-rw-r--r-- | fs/bcachefs/io_types.h | 2 | ||||
-rw-r--r-- | fs/bcachefs/move.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/move.h | 1 |
5 files changed, 42 insertions, 27 deletions
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index bf59875db546..1b457e90a172 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -432,7 +432,7 @@ int bch2_fpunch(struct bch_fs *c, u64 inum, u64 start, u64 end, return ret; } -int bch2_write_index_default(struct bch_write_op *op) +static int bch2_write_index_default(struct bch_write_op *op) { struct bch_fs *c = op->c; struct bkey_buf sk; @@ -577,7 +577,7 @@ static void __bch2_write_index(struct bch_write_op *op) struct bch_extent_ptr *ptr; struct bkey_i *src, *dst = keys->keys, *n, *k; unsigned dev; - int ret; + int ret = 0; for (src = keys->keys; src != keys->top; src = n) { n = bkey_next(src); @@ -614,7 +614,10 @@ static void __bch2_write_index(struct bch_write_op *op) if (!bch2_keylist_empty(keys)) { u64 sectors_start = keylist_sectors(keys); - int ret = op->index_update_fn(op); + + ret = !(op->flags & BCH_WRITE_MOVE) + ? bch2_write_index_default(op) + : bch2_migrate_index_update(op); BUG_ON(ret == -EINTR); BUG_ON(keylist_sectors(keys) && !ret); @@ -624,7 +627,7 @@ static void __bch2_write_index(struct bch_write_op *op) if (ret) { bch_err_inum_ratelimited(c, op->pos.inode, "write error %i from btree update", ret); - op->error = ret; + goto err; } } out: diff --git a/fs/bcachefs/io.h b/fs/bcachefs/io.h index 5d692a2228a6..f21ffb53c1e4 100644 --- a/fs/bcachefs/io.h +++ b/fs/bcachefs/io.h @@ -29,23 +29,39 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *, const char *bch2_blk_status_to_str(blk_status_t); enum bch_write_flags { - BCH_WRITE_ALLOC_NOWAIT = (1 << 0), - BCH_WRITE_CACHED = (1 << 1), - BCH_WRITE_FLUSH = (1 << 2), - BCH_WRITE_DATA_ENCODED = (1 << 3), - BCH_WRITE_PAGES_STABLE = (1 << 4), - BCH_WRITE_PAGES_OWNED = (1 << 5), - BCH_WRITE_ONLY_SPECIFIED_DEVS = (1 << 6), - BCH_WRITE_WROTE_DATA_INLINE = (1 << 7), - BCH_WRITE_FROM_INTERNAL = (1 << 8), - BCH_WRITE_CHECK_ENOSPC = (1 << 9), - - /* Internal: */ - BCH_WRITE_JOURNAL_SEQ_PTR = (1 << 10), - BCH_WRITE_SKIP_CLOSURE_PUT = (1 << 11), - BCH_WRITE_DONE = (1 << 12), + __BCH_WRITE_ALLOC_NOWAIT, + __BCH_WRITE_CACHED, + __BCH_WRITE_FLUSH, + __BCH_WRITE_DATA_ENCODED, + __BCH_WRITE_PAGES_STABLE, + __BCH_WRITE_PAGES_OWNED, + __BCH_WRITE_ONLY_SPECIFIED_DEVS, + __BCH_WRITE_WROTE_DATA_INLINE, + __BCH_WRITE_FROM_INTERNAL, + __BCH_WRITE_CHECK_ENOSPC, + __BCH_WRITE_MOVE, + __BCH_WRITE_JOURNAL_SEQ_PTR, + __BCH_WRITE_SKIP_CLOSURE_PUT, + __BCH_WRITE_DONE, }; +#define BCH_WRITE_ALLOC_NOWAIT (1U << __BCH_WRITE_ALLOC_NOWAIT) +#define BCH_WRITE_CACHED (1U << __BCH_WRITE_CACHED) +#define BCH_WRITE_FLUSH (1U << __BCH_WRITE_FLUSH) +#define BCH_WRITE_DATA_ENCODED (1U << __BCH_WRITE_DATA_ENCODED) +#define BCH_WRITE_PAGES_STABLE (1U << __BCH_WRITE_PAGES_STABLE) +#define BCH_WRITE_PAGES_OWNED (1U << __BCH_WRITE_PAGES_OWNED) +#define BCH_WRITE_ONLY_SPECIFIED_DEVS (1U << __BCH_WRITE_ONLY_SPECIFIED_DEVS) +#define BCH_WRITE_WROTE_DATA_INLINE (1U << __BCH_WRITE_WROTE_DATA_INLINE) +#define BCH_WRITE_FROM_INTERNAL (1U << __BCH_WRITE_FROM_INTERNAL) +#define BCH_WRITE_CHECK_ENOSPC (1U << __BCH_WRITE_CHECK_ENOSPC) +#define BCH_WRITE_MOVE (1U << __BCH_WRITE_MOVE) + +/* Internal: */ +#define BCH_WRITE_JOURNAL_SEQ_PTR (1U << __BCH_WRITE_JOURNAL_SEQ_PTR) +#define BCH_WRITE_SKIP_CLOSURE_PUT (1U << __BCH_WRITE_SKIP_CLOSURE_PUT) +#define BCH_WRITE_DONE (1U << __BCH_WRITE_DONE) + static inline u64 *op_journal_seq(struct bch_write_op *op) { return (op->flags & BCH_WRITE_JOURNAL_SEQ_PTR) @@ -74,8 +90,6 @@ int bch2_fpunch_at(struct btree_trans *, struct btree_iter *, struct bpos, u64 *, s64 *); int bch2_fpunch(struct bch_fs *c, u64, u64, u64, u64 *, s64 *); -int bch2_write_index_default(struct bch_write_op *); - static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c, struct bch_io_opts opts) { @@ -101,7 +115,6 @@ static inline void bch2_write_op_init(struct bch_write_op *op, struct bch_fs *c, op->journal_seq = 0; op->new_i_size = U64_MAX; op->i_sectors_delta = 0; - op->index_update_fn = bch2_write_index_default; } void bch2_write(struct closure *); diff --git a/fs/bcachefs/io_types.h b/fs/bcachefs/io_types.h index 99b4b4c4a53b..148808bdea50 100644 --- a/fs/bcachefs/io_types.h +++ b/fs/bcachefs/io_types.h @@ -146,8 +146,6 @@ struct bch_write_op { u64 new_i_size; s64 i_sectors_delta; - int (*index_update_fn)(struct bch_write_op *); - struct bch_devs_mask failed; struct keylist insert_keys; diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index 8807b18ddc43..61c9be4acd5f 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -52,7 +52,7 @@ struct moving_context { wait_queue_head_t wait; }; -static int bch2_migrate_index_update(struct bch_write_op *op) +int bch2_migrate_index_update(struct bch_write_op *op) { struct bch_fs *c = op->c; struct btree_trans trans; @@ -266,11 +266,11 @@ int bch2_migrate_write_init(struct bch_fs *c, struct migrate_write *m, m->op.flags |= BCH_WRITE_PAGES_STABLE| BCH_WRITE_PAGES_OWNED| BCH_WRITE_DATA_ENCODED| - BCH_WRITE_FROM_INTERNAL; + BCH_WRITE_FROM_INTERNAL| + BCH_WRITE_MOVE; m->op.nr_replicas = data_opts.nr_replicas; m->op.nr_replicas_required = data_opts.nr_replicas; - m->op.index_update_fn = bch2_migrate_index_update; switch (data_cmd) { case DATA_ADD_REPLICAS: { diff --git a/fs/bcachefs/move.h b/fs/bcachefs/move.h index 5076153689d1..99d6acb10880 100644 --- a/fs/bcachefs/move.h +++ b/fs/bcachefs/move.h @@ -41,6 +41,7 @@ struct migrate_write { struct bch_write_op op; }; +int bch2_migrate_index_update(struct bch_write_op *); void bch2_migrate_read_done(struct migrate_write *, struct bch_read_bio *); int bch2_migrate_write_init(struct bch_fs *, struct migrate_write *, struct write_point_specifier, |