]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/quota.c
Update bcachefs sources to 3f3f969859 bcachefs: Fix some compiler warnings
[bcachefs-tools-debian] / libbcachefs / quota.c
index e7787c5063ce3d7932fe5295702cae12b52ded9f..9b0f4d3f176d5fcbd7c0e0e189679c40416abefd 100644 (file)
@@ -357,13 +357,13 @@ static int __bch2_quota_set(struct bch_fs *c, struct bkey_s_c k)
 static int bch2_quota_init_type(struct bch_fs *c, enum quota_types type)
 {
        struct btree_trans trans;
-       struct btree_iter *iter;
+       struct btree_iter iter;
        struct bkey_s_c k;
        int ret = 0;
 
        bch2_trans_init(&trans, c, 0, 0);
 
-       for_each_btree_key(&trans, iter, BTREE_ID_QUOTAS, POS(type, 0),
+       for_each_btree_key(&trans, iter, BTREE_ID_quotas, POS(type, 0),
                           BTREE_ITER_PREFETCH, k, ret) {
                if (k.k->p.inode != type)
                        break;
@@ -372,6 +372,7 @@ static int bch2_quota_init_type(struct bch_fs *c, enum quota_types type)
                if (ret)
                        break;
        }
+       bch2_trans_iter_exit(&trans, &iter);
 
        return bch2_trans_exit(&trans) ?: ret;
 }
@@ -418,7 +419,7 @@ int bch2_fs_quota_read(struct bch_fs *c)
        unsigned i, qtypes = enabled_qtypes(c);
        struct bch_memquota_type *q;
        struct btree_trans trans;
-       struct btree_iter *iter;
+       struct btree_iter iter;
        struct bch_inode_unpacked u;
        struct bkey_s_c k;
        int ret;
@@ -435,7 +436,7 @@ int bch2_fs_quota_read(struct bch_fs *c)
 
        bch2_trans_init(&trans, c, 0, 0);
 
-       for_each_btree_key(&trans, iter, BTREE_ID_INODES, POS_MIN,
+       for_each_btree_key(&trans, iter, BTREE_ID_inodes, POS_MIN,
                           BTREE_ITER_PREFETCH, k, ret) {
                switch (k.k->type) {
                case KEY_TYPE_inode:
@@ -449,6 +450,8 @@ int bch2_fs_quota_read(struct bch_fs *c)
                                        KEY_TYPE_QUOTA_NOCHECK);
                }
        }
+       bch2_trans_iter_exit(&trans, &iter);
+
        return bch2_trans_exit(&trans) ?: ret;
 }
 
@@ -526,7 +529,7 @@ static int bch2_quota_remove(struct super_block *sb, unsigned uflags)
                if (c->opts.usrquota)
                        return -EINVAL;
 
-               ret = bch2_btree_delete_range(c, BTREE_ID_QUOTAS,
+               ret = bch2_btree_delete_range(c, BTREE_ID_quotas,
                                              POS(QTYP_USR, 0),
                                              POS(QTYP_USR + 1, 0),
                                              NULL);
@@ -538,7 +541,7 @@ static int bch2_quota_remove(struct super_block *sb, unsigned uflags)
                if (c->opts.grpquota)
                        return -EINVAL;
 
-               ret = bch2_btree_delete_range(c, BTREE_ID_QUOTAS,
+               ret = bch2_btree_delete_range(c, BTREE_ID_quotas,
                                              POS(QTYP_GRP, 0),
                                              POS(QTYP_GRP + 1, 0),
                                              NULL);
@@ -550,7 +553,7 @@ static int bch2_quota_remove(struct super_block *sb, unsigned uflags)
                if (c->opts.prjquota)
                        return -EINVAL;
 
-               ret = bch2_btree_delete_range(c, BTREE_ID_QUOTAS,
+               ret = bch2_btree_delete_range(c, BTREE_ID_quotas,
                                              POS(QTYP_PRJ, 0),
                                              POS(QTYP_PRJ + 1, 0),
                                              NULL);
@@ -710,58 +713,56 @@ 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 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,
-                                  BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
-       k = bch2_btree_iter_peek_slot(iter);
+       bch2_trans_iter_init(trans, &iter, 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);
 
-       bch2_trans_update(&trans, iter, &new_quota.k_i, 0);
+       ret = bch2_trans_update(trans, &iter, &new_quota->k_i, 0);
+       bch2_trans_iter_exit(trans, &iter);
+       return ret;
+}
 
-       ret = bch2_trans_commit(&trans, NULL, NULL, 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 bkey_i_quota new_quota;
+       int ret;
 
-       bch2_trans_exit(&trans);
+       if (sb->s_flags & SB_RDONLY)
+               return -EROFS;
 
-       if (ret)
-               return ret;
+       bkey_quota_init(&new_quota.k_i);
+       new_quota.k.p = POS(qid.type, from_kqid(&init_user_ns, qid));
 
-       ret = __bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i));
+       ret = bch2_trans_do(c, NULL, NULL, 0,
+                           bch2_set_quota_trans(&trans, &new_quota, qdq)) ?:
+               __bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i));
 
        return ret;
 }