Commit a3d7afa5 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 23189da9
...@@ -1072,7 +1072,7 @@ static void bch2_do_discards_work(struct work_struct *work) ...@@ -1072,7 +1072,7 @@ static void bch2_do_discards_work(struct work_struct *work)
void bch2_do_discards(struct bch_fs *c) 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)) !queue_work(system_long_wq, &c->discard_work))
percpu_ref_put(&c->writes); percpu_ref_put(&c->writes);
} }
...@@ -1192,7 +1192,7 @@ static void bch2_do_invalidates_work(struct work_struct *work) ...@@ -1192,7 +1192,7 @@ static void bch2_do_invalidates_work(struct work_struct *work)
void bch2_do_invalidates(struct bch_fs *c) 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); queue_work(system_long_wq, &c->invalidate_work);
} }
......
...@@ -1897,7 +1897,7 @@ void bch2_btree_node_rewrite_async(struct bch_fs *c, struct btree *b) ...@@ -1897,7 +1897,7 @@ void bch2_btree_node_rewrite_async(struct bch_fs *c, struct btree *b)
{ {
struct async_btree_rewrite *a; struct async_btree_rewrite *a;
if (!percpu_ref_tryget(&c->writes)) if (!percpu_ref_tryget_live(&c->writes))
return; return;
a = kmalloc(sizeof(*a), GFP_NOFS); a = kmalloc(sizeof(*a), GFP_NOFS);
......
...@@ -1108,7 +1108,7 @@ int __bch2_trans_commit(struct btree_trans *trans) ...@@ -1108,7 +1108,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
} }
if (!(trans->flags & BTREE_INSERT_NOCHECK_RW) && 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); ret = bch2_trans_commit_get_rw_cold(trans);
if (ret) if (ret)
goto out_reset; goto out_reset;
......
...@@ -939,7 +939,7 @@ static void ec_stripe_create(struct ec_stripe_new *s) ...@@ -939,7 +939,7 @@ static void ec_stripe_create(struct ec_stripe_new *s)
BUG_ON(!s->allocated); BUG_ON(!s->allocated);
if (!percpu_ref_tryget(&c->writes)) if (!percpu_ref_tryget_live(&c->writes))
goto err; goto err;
ec_generate_ec(&s->new_stripe); ec_generate_ec(&s->new_stripe);
......
...@@ -3105,7 +3105,7 @@ long bch2_fallocate_dispatch(struct file *file, int mode, ...@@ -3105,7 +3105,7 @@ long bch2_fallocate_dispatch(struct file *file, int mode,
struct bch_fs *c = inode->v.i_sb->s_fs_info; struct bch_fs *c = inode->v.i_sb->s_fs_info;
long ret; long ret;
if (!percpu_ref_tryget(&c->writes)) if (!percpu_ref_tryget_live(&c->writes))
return -EROFS; return -EROFS;
inode_lock(&inode->v); inode_lock(&inode->v);
......
...@@ -1397,7 +1397,7 @@ void bch2_write(struct closure *cl) ...@@ -1397,7 +1397,7 @@ void bch2_write(struct closure *cl)
} }
if (c->opts.nochanges || if (c->opts.nochanges ||
!percpu_ref_tryget(&c->writes)) { !percpu_ref_tryget_live(&c->writes)) {
op->error = -EROFS; op->error = -EROFS;
goto err; goto err;
} }
...@@ -1527,7 +1527,7 @@ static struct promote_op *__promote_alloc(struct bch_fs *c, ...@@ -1527,7 +1527,7 @@ static struct promote_op *__promote_alloc(struct bch_fs *c,
unsigned pages = DIV_ROUND_UP(sectors, PAGE_SECTORS); unsigned pages = DIV_ROUND_UP(sectors, PAGE_SECTORS);
int ret; int ret;
if (!percpu_ref_tryget(&c->writes)) if (!percpu_ref_tryget_live(&c->writes))
return NULL; return NULL;
op = kzalloc(sizeof(*op) + sizeof(struct bio_vec) * pages, GFP_NOIO); op = kzalloc(sizeof(*op) + sizeof(struct bio_vec) * pages, GFP_NOIO);
......
...@@ -282,7 +282,7 @@ s64 bch2_remap_range(struct bch_fs *c, ...@@ -282,7 +282,7 @@ s64 bch2_remap_range(struct bch_fs *c,
u32 dst_snapshot, src_snapshot; u32 dst_snapshot, src_snapshot;
int ret = 0, ret2 = 0; int ret = 0, ret2 = 0;
if (!percpu_ref_tryget(&c->writes)) if (!percpu_ref_tryget_live(&c->writes))
return -EROFS; return -EROFS;
bch2_check_set_feature(c, BCH_FEATURE_reflink); bch2_check_set_feature(c, BCH_FEATURE_reflink);
......
...@@ -729,7 +729,7 @@ static void bch2_delete_dead_snapshots_work(struct work_struct *work) ...@@ -729,7 +729,7 @@ static void bch2_delete_dead_snapshots_work(struct work_struct *work)
static void bch2_delete_dead_snapshots(struct bch_fs *c) 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; return;
if (!queue_work(system_long_wq, &c->snapshot_delete_work)) 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, ...@@ -931,7 +931,7 @@ int bch2_subvolume_wait_for_pagecache_and_delete_hook(struct btree_trans *trans,
if (ret) if (ret)
return ret; return ret;
if (unlikely(!percpu_ref_tryget(&c->writes))) if (unlikely(!percpu_ref_tryget_live(&c->writes)))
return -EROFS; return -EROFS;
if (!queue_work(system_long_wq, &c->snapshot_wait_for_pagecache_and_delete_work)) if (!queue_work(system_long_wq, &c->snapshot_wait_for_pagecache_and_delete_work))
......
...@@ -676,7 +676,7 @@ STORE(bch2_fs_opts_dir) ...@@ -676,7 +676,7 @@ STORE(bch2_fs_opts_dir)
* We don't need to take c->writes for correctness, but it eliminates an * 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: * 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; return -EROFS;
tmp = kstrdup(buf, GFP_KERNEL); tmp = kstrdup(buf, GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment