summaryrefslogtreecommitdiff
path: root/fs/bcachefs/quota.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-05-14 00:53:33 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:08:39 +0300
commitd3baf289dce56f78700ca9dc64153263652c9a0a (patch)
treeb0fc5216ef3d11b1ea394427b5f1ff3b3e0d81ca /fs/bcachefs/quota.c
parent4167b4cdba30fb8db190a3439324f413dc08a0c0 (diff)
downloadlinux-d3baf289dce56f78700ca9dc64153263652c9a0a.tar.xz
bcachefs: Fix setquota
We were returning -EINTR because we were failing to retry the btree transaction. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/quota.c')
-rw-r--r--fs/bcachefs/quota.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c
index e7787c5063ce..d3032a46e7f3 100644
--- a/fs/bcachefs/quota.c
+++ b/fs/bcachefs/quota.c
@@ -710,25 +710,15 @@ found:
return ret;
}
-static int bch2_set_quota(struct super_block *sb, struct kqid qid,
- struct qc_dqblk *qdq)
+static int bch2_set_quota_trans(struct btree_trans *trans,
+ struct bkey_i_quota *new_quota,
+ struct qc_dqblk *qdq)
{
- struct bch_fs *c = sb->s_fs_info;
- struct btree_trans trans;
struct btree_iter *iter;
struct bkey_s_c k;
- struct bkey_i_quota new_quota;
int ret;
- if (sb->s_flags & SB_RDONLY)
- return -EROFS;
-
- bkey_quota_init(&new_quota.k_i);
- new_quota.k.p = POS(qid.type, from_kqid(&init_user_ns, qid));
-
- bch2_trans_init(&trans, c, 0, 0);
-
- iter = bch2_trans_get_iter(&trans, BTREE_ID_QUOTAS, new_quota.k.p,
+ iter = bch2_trans_get_iter(trans, BTREE_ID_QUOTAS, new_quota->k.p,
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
k = bch2_btree_iter_peek_slot(iter);
@@ -736,32 +726,43 @@ static int bch2_set_quota(struct super_block *sb, struct kqid qid,
if (unlikely(ret))
return ret;
- switch (k.k->type) {
- case KEY_TYPE_quota:
- new_quota.v = *bkey_s_c_to_quota(k).v;
- break;
- }
+ if (k.k->type == KEY_TYPE_quota)
+ new_quota->v = *bkey_s_c_to_quota(k).v;
if (qdq->d_fieldmask & QC_SPC_SOFT)
- new_quota.v.c[Q_SPC].softlimit = cpu_to_le64(qdq->d_spc_softlimit >> 9);
+ new_quota->v.c[Q_SPC].softlimit = cpu_to_le64(qdq->d_spc_softlimit >> 9);
if (qdq->d_fieldmask & QC_SPC_HARD)
- new_quota.v.c[Q_SPC].hardlimit = cpu_to_le64(qdq->d_spc_hardlimit >> 9);
+ new_quota->v.c[Q_SPC].hardlimit = cpu_to_le64(qdq->d_spc_hardlimit >> 9);
if (qdq->d_fieldmask & QC_INO_SOFT)
- new_quota.v.c[Q_INO].softlimit = cpu_to_le64(qdq->d_ino_softlimit);
+ new_quota->v.c[Q_INO].softlimit = cpu_to_le64(qdq->d_ino_softlimit);
if (qdq->d_fieldmask & QC_INO_HARD)
- new_quota.v.c[Q_INO].hardlimit = cpu_to_le64(qdq->d_ino_hardlimit);
+ new_quota->v.c[Q_INO].hardlimit = cpu_to_le64(qdq->d_ino_hardlimit);
+
+ return bch2_trans_update(trans, iter, &new_quota->k_i, 0);
+}
- bch2_trans_update(&trans, iter, &new_quota.k_i, 0);
+static int bch2_set_quota(struct super_block *sb, struct kqid qid,
+ struct qc_dqblk *qdq)
+{
+ struct bch_fs *c = sb->s_fs_info;
+ struct btree_trans trans;
+ struct bkey_i_quota new_quota;
+ int ret;
- ret = bch2_trans_commit(&trans, NULL, NULL, 0);
+ if (sb->s_flags & SB_RDONLY)
+ return -EROFS;
- bch2_trans_exit(&trans);
+ bkey_quota_init(&new_quota.k_i);
+ new_quota.k.p = POS(qid.type, from_kqid(&init_user_ns, qid));
- if (ret)
- return ret;
+ bch2_trans_init(&trans, c, 0, 0);
- ret = __bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i));
+ ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_NOUNLOCK,
+ bch2_set_quota_trans(&trans, &new_quota, qdq)) ?:
+ __bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i));
+
+ bch2_trans_exit(&trans);
return ret;
}