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 <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-06-18 19:55:32 -04:00 committed by Kent Overstreet
parent 23189da9eb
commit a3d7afa5c1
9 changed files with 12 additions and 12 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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)
{
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))

View file

@ -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);