Skip to content

Commit

Permalink
bcachefs: Fix setquota
Browse files Browse the repository at this point in the history
We were returning -EINTR because we were failing to retry the btree
transaction.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
  • Loading branch information
koverstreet committed May 13, 2020
1 parent 0fb6532 commit 91fedfc
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions fs/bcachefs/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,58 +710,59 @@ static int bch2_get_next_quota(struct super_block *sb, struct kqid *kqid,
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);

ret = bkey_err(k);
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;
}
Expand Down

0 comments on commit 91fedfc

Please sign in to comment.