summaryrefslogtreecommitdiff
path: root/fs/bcachefs/quota.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-07-16 03:51:09 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:35 +0300
commita1783320d46e878ddf5d2bb3380c181d515a5ff3 (patch)
tree679a1d7df61a5b8431f3288888f9e01e63eea61b /fs/bcachefs/quota.c
parent0d06b4eca687b3a6a07b62fd4ca83d635103c77f (diff)
downloadlinux-a1783320d46e878ddf5d2bb3380c181d515a5ff3.tar.xz
bcachefs: for_each_btree_key2()
This introduces two new macros for iterating through the btree, with transaction restart handling - for_each_btree_key2() - for_each_btree_key_commit() Every iteration is now in an implicit transaction, and - as with lockrestart_do() and commit_do() - returning -EINTR will cause the transaction to be restarted, at the same key. This patch converts a bunch of code that was open coding this to these new macros, saving a substantial amount of code. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/quota.c')
-rw-r--r--fs/bcachefs/quota.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c
index d764dc7abfe8..e35a6d1f31e9 100644
--- a/fs/bcachefs/quota.c
+++ b/fs/bcachefs/quota.c
@@ -455,22 +455,14 @@ static void bch2_sb_quota_read(struct bch_fs *c)
}
static int bch2_fs_quota_read_inode(struct btree_trans *trans,
- struct btree_iter *iter)
+ struct btree_iter *iter,
+ struct bkey_s_c k)
{
struct bch_fs *c = trans->c;
struct bch_inode_unpacked u;
struct bch_subvolume subvolume;
- struct bkey_s_c k;
int ret;
- k = bch2_btree_iter_peek(iter);
- ret = bkey_err(k);
- if (ret)
- return ret;
-
- if (!k.k)
- return 1;
-
ret = bch2_snapshot_get_subvol(trans, k.k->p.snapshot, &subvolume);
if (ret)
return ret;
@@ -503,6 +495,7 @@ int bch2_fs_quota_read(struct bch_fs *c)
struct bch_memquota_type *q;
struct btree_trans trans;
struct btree_iter iter;
+ struct bkey_s_c k;
int ret;
mutex_lock(&c->sb_lock);
@@ -517,18 +510,18 @@ int bch2_fs_quota_read(struct bch_fs *c)
bch2_trans_init(&trans, c, 0, 0);
- bch2_trans_iter_init(&trans, &iter, BTREE_ID_inodes, POS_MIN,
+ ret = for_each_btree_key2(&trans, iter, BTREE_ID_inodes,
+ POS_MIN,
BTREE_ITER_INTENT|
BTREE_ITER_PREFETCH|
- BTREE_ITER_ALL_SNAPSHOTS);
- do {
- ret = lockrestart_do(&trans,
- bch2_fs_quota_read_inode(&trans, &iter));
- } while (!ret);
- bch2_trans_iter_exit(&trans, &iter);
+ BTREE_ITER_ALL_SNAPSHOTS,
+ k,
+ bch2_fs_quota_read_inode(&trans, &iter, k));
+ if (ret)
+ bch_err(c, "err reading inodes in quota init: %i", ret);
bch2_trans_exit(&trans);
- return ret < 0 ? ret : 0;
+ return ret;
}
/* Enable/disable/delete quotas for an entire filesystem: */