From: Kent Overstreet Date: Sat, 18 Jun 2022 23:55:32 +0000 (-0400) Subject: bcachefs: Always use percpu_ref_tryget_live() on c->writes X-Git-Tag: v6.7-rc1~201^2~927 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a3d7afa5c1b62140168982747fd15c1999d991f4;p=thirdparty%2Fkernel%2Flinux.git bcachefs: Always use percpu_ref_tryget_live() on c->writes If we're trying to get a ref and the refcount has been killed, it means we're doing an emergency shutdown - we always want tryget_live(). Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index 012607cefb6f6..3084081966b64 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -1072,7 +1072,7 @@ static void bch2_do_discards_work(struct work_struct *work) void bch2_do_discards(struct bch_fs *c) { - if (percpu_ref_tryget(&c->writes) && + if (percpu_ref_tryget_live(&c->writes) && !queue_work(system_long_wq, &c->discard_work)) percpu_ref_put(&c->writes); } @@ -1192,7 +1192,7 @@ static void bch2_do_invalidates_work(struct work_struct *work) void bch2_do_invalidates(struct bch_fs *c) { - if (percpu_ref_tryget(&c->writes)) + if (percpu_ref_tryget_live(&c->writes)) queue_work(system_long_wq, &c->invalidate_work); } diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c index a4f66e7cbb457..eeaea292bd802 100644 --- a/fs/bcachefs/btree_update_interior.c +++ b/fs/bcachefs/btree_update_interior.c @@ -1897,7 +1897,7 @@ void bch2_btree_node_rewrite_async(struct bch_fs *c, struct btree *b) { struct async_btree_rewrite *a; - if (!percpu_ref_tryget(&c->writes)) + if (!percpu_ref_tryget_live(&c->writes)) return; a = kmalloc(sizeof(*a), GFP_NOFS); diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index 3425e3c007dd6..c6fe24f424ded 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -1108,7 +1108,7 @@ int __bch2_trans_commit(struct btree_trans *trans) } if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) && - unlikely(!percpu_ref_tryget(&c->writes))) { + unlikely(!percpu_ref_tryget_live(&c->writes))) { ret = bch2_trans_commit_get_rw_cold(trans); if (ret) goto out_reset; diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index faabaa64dcdb5..6ce352c526f01 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -939,7 +939,7 @@ static void ec_stripe_create(struct ec_stripe_new *s) BUG_ON(!s->allocated); - if (!percpu_ref_tryget(&c->writes)) + if (!percpu_ref_tryget_live(&c->writes)) goto err; ec_generate_ec(&s->new_stripe); diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index ad51483ad764a..c0dda29dabb46 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -3105,7 +3105,7 @@ long bch2_fallocate_dispatch(struct file *file, int mode, struct bch_fs *c = inode->v.i_sb->s_fs_info; long ret; - if (!percpu_ref_tryget(&c->writes)) + if (!percpu_ref_tryget_live(&c->writes)) return -EROFS; inode_lock(&inode->v); diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 91789185c78ef..ca72a31da5025 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -1397,7 +1397,7 @@ void bch2_write(struct closure *cl) } if (c->opts.nochanges || - !percpu_ref_tryget(&c->writes)) { + !percpu_ref_tryget_live(&c->writes)) { op->error = -EROFS; goto err; } @@ -1527,7 +1527,7 @@ static struct promote_op *__promote_alloc(struct bch_fs *c, unsigned pages = DIV_ROUND_UP(sectors, PAGE_SECTORS); int ret; - if (!percpu_ref_tryget(&c->writes)) + if (!percpu_ref_tryget_live(&c->writes)) return NULL; op = kzalloc(sizeof(*op) + sizeof(struct bio_vec) * pages, GFP_NOIO); diff --git a/fs/bcachefs/reflink.c b/fs/bcachefs/reflink.c index 4e589c02a93bd..2038e3502d8c1 100644 --- a/fs/bcachefs/reflink.c +++ b/fs/bcachefs/reflink.c @@ -282,7 +282,7 @@ s64 bch2_remap_range(struct bch_fs *c, u32 dst_snapshot, src_snapshot; int ret = 0, ret2 = 0; - if (!percpu_ref_tryget(&c->writes)) + if (!percpu_ref_tryget_live(&c->writes)) return -EROFS; bch2_check_set_feature(c, BCH_FEATURE_reflink); diff --git a/fs/bcachefs/subvolume.c b/fs/bcachefs/subvolume.c index 8f41a06c3e112..60b60de83f3e5 100644 --- a/fs/bcachefs/subvolume.c +++ b/fs/bcachefs/subvolume.c @@ -729,7 +729,7 @@ err: static void bch2_delete_dead_snapshots(struct bch_fs *c) { - if (unlikely(!percpu_ref_tryget(&c->writes))) + if (unlikely(!percpu_ref_tryget_live(&c->writes))) return; if (!queue_work(system_long_wq, &c->snapshot_delete_work)) @@ -931,7 +931,7 @@ int bch2_subvolume_wait_for_pagecache_and_delete_hook(struct btree_trans *trans, if (ret) return ret; - if (unlikely(!percpu_ref_tryget(&c->writes))) + if (unlikely(!percpu_ref_tryget_live(&c->writes))) return -EROFS; if (!queue_work(system_long_wq, &c->snapshot_wait_for_pagecache_and_delete_work)) diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index 173289c34de0f..4e2b6285cf3ad 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -676,7 +676,7 @@ STORE(bch2_fs_opts_dir) * We don't need to take c->writes for correctness, but it eliminates an * unsightly error message in the dmesg log when we're RO: */ - if (unlikely(!percpu_ref_tryget(&c->writes))) + if (unlikely(!percpu_ref_tryget_live(&c->writes))) return -EROFS; tmp = kstrdup(buf, GFP_KERNEL);