diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-02-24 19:07:21 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:54 -0400 |
commit | 33669e0cc94e9554cf162cbe2e63155887a10231 (patch) | |
tree | 2c39afb2b393d1d0b131af86456123573320ad00 | |
parent | 1a14e255100cb17cface9ca179ca7ddba87fd8b9 (diff) | |
download | lwn-33669e0cc94e9554cf162cbe2e63155887a10231.tar.gz lwn-33669e0cc94e9554cf162cbe2e63155887a10231.zip |
bcachefs: Add option for completely disabling nocow
This adds an option for completely disabling nocow mode, including the
locking in the data move path.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/data_update.c | 38 | ||||
-rw-r--r-- | fs/bcachefs/io.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/opts.h | 6 |
3 files changed, 28 insertions, 18 deletions
diff --git a/fs/bcachefs/data_update.c b/fs/bcachefs/data_update.c index c98a393f4916..dacea5e04000 100644 --- a/fs/bcachefs/data_update.c +++ b/fs/bcachefs/data_update.c @@ -327,8 +327,9 @@ void bch2_data_update_exit(struct data_update *update) const struct bch_extent_ptr *ptr; bkey_for_each_ptr(ptrs, ptr) { - bch2_bucket_nocow_unlock(&c->nocow_locks, - PTR_BUCKET_POS(c, ptr), 0); + if (c->opts.nocow_enabled) + bch2_bucket_nocow_unlock(&c->nocow_locks, + PTR_BUCKET_POS(c, ptr), 0); percpu_ref_put(&bch_dev_bkey_exists(c, ptr->dev)->ref); } @@ -488,23 +489,26 @@ int bch2_data_update_init(struct btree_trans *trans, if (p.crc.compression_type == BCH_COMPRESSION_TYPE_incompressible) m->op.incompressible = true; - if (ctxt) { - move_ctxt_wait_event(ctxt, trans, - (locked = bch2_bucket_nocow_trylock(&c->nocow_locks, - PTR_BUCKET_POS(c, &p.ptr), 0)) || - !atomic_read(&ctxt->read_sectors)); - - if (!locked) - bch2_bucket_nocow_lock(&c->nocow_locks, - PTR_BUCKET_POS(c, &p.ptr), 0); - } else { - if (!bch2_bucket_nocow_trylock(&c->nocow_locks, - PTR_BUCKET_POS(c, &p.ptr), 0)) { - ret = -BCH_ERR_nocow_lock_blocked; - goto err; + if (c->opts.nocow_enabled) { + if (ctxt) { + move_ctxt_wait_event(ctxt, trans, + (locked = bch2_bucket_nocow_trylock(&c->nocow_locks, + PTR_BUCKET_POS(c, &p.ptr), 0)) || + !atomic_read(&ctxt->read_sectors)); + + if (!locked) + bch2_bucket_nocow_lock(&c->nocow_locks, + PTR_BUCKET_POS(c, &p.ptr), 0); + } else { + if (!bch2_bucket_nocow_trylock(&c->nocow_locks, + PTR_BUCKET_POS(c, &p.ptr), 0)) { + ret = -BCH_ERR_nocow_lock_blocked; + goto err; + } } + ptrs_locked |= (1U << i); } - ptrs_locked |= (1U << i); + i++; } diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 6f7e4dac4268..ede2f3116935 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -1649,7 +1649,7 @@ static void __bch2_write(struct bch_write_op *op) nofs_flags = memalloc_nofs_save(); - if (unlikely(op->opts.nocow)) { + if (unlikely(op->opts.nocow && c->opts.nocow_enabled)) { bch2_nocow_write(op); if (op->flags & BCH_WRITE_DONE) goto out_nofs_restore; diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h index fc444c68025c..afbf82d62977 100644 --- a/fs/bcachefs/opts.h +++ b/fs/bcachefs/opts.h @@ -404,6 +404,12 @@ enum opt_type { NULL, "Nocow mode: Writes will be done in place when possible.\n"\ "Snapshots and reflink will still caused writes to be COW\n"\ "Implicitly disables data checksumming, compression and encryption")\ + x(nocow_enabled, u8, \ + OPT_FS|OPT_MOUNT, \ + OPT_BOOL(), \ + BCH2_NO_SB_OPT, true, \ + NULL, "Enable nocow mode: enables runtime locking in\n"\ + "data move path needed if nocow will ever be in use\n")\ x(no_data_io, u8, \ OPT_MOUNT, \ OPT_BOOL(), \ |