]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/quota.c
Update bcachefs sources to d82da7126f fixup! bcachefs: for_each_btree_key2()
[bcachefs-tools-debian] / libbcachefs / quota.c
index ca029a00e7b8044c5815b783a3437628942ecdda..e35a6d1f31e907a5d9d706201ba6cc9428761cd8 100644 (file)
@@ -23,7 +23,7 @@ static int bch2_sb_quota_validate(struct bch_sb *sb, struct bch_sb_field *f,
        struct bch_sb_field_quota *q = field_to_type(f, quota);
 
        if (vstruct_bytes(&q->field) < sizeof(*q)) {
-               pr_buf(err, "wrong size (got %zu should be %zu)",
+               prt_printf(err, "wrong size (got %zu should be %zu)",
                       vstruct_bytes(&q->field), sizeof(*q));
                return -EINVAL;
        }
@@ -38,17 +38,17 @@ static void bch2_sb_quota_to_text(struct printbuf *out, struct bch_sb *sb,
        unsigned qtyp, counter;
 
        for (qtyp = 0; qtyp < ARRAY_SIZE(q->q); qtyp++) {
-               pr_buf(out, "%s: flags %llx",
+               prt_printf(out, "%s: flags %llx",
                       bch2_quota_types[qtyp],
                       le64_to_cpu(q->q[qtyp].flags));
 
                for (counter = 0; counter < Q_COUNTERS; counter++)
-                       pr_buf(out, " %s timelimit %u warnlimit %u",
+                       prt_printf(out, " %s timelimit %u warnlimit %u",
                               bch2_quota_counters[counter],
                               le32_to_cpu(q->q[qtyp].c[counter].timelimit),
                               le32_to_cpu(q->q[qtyp].c[counter].warnlimit));
 
-               pr_newline(out);
+               prt_newline(out);
        }
 }
 
@@ -57,15 +57,22 @@ const struct bch_sb_field_ops bch_sb_field_ops_quota = {
        .to_text        = bch2_sb_quota_to_text,
 };
 
-const char *bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k)
+int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k,
+                      int rw, struct printbuf *err)
 {
-       if (k.k->p.inode >= QTYP_NR)
-               return "invalid quota type";
+       if (k.k->p.inode >= QTYP_NR) {
+               prt_printf(err, "invalid quota type (%llu >= %u)",
+                      k.k->p.inode, QTYP_NR);
+               return -EINVAL;
+       }
 
-       if (bkey_val_bytes(k.k) != sizeof(struct bch_quota))
-               return "incorrect value size";
+       if (bkey_val_bytes(k.k) != sizeof(struct bch_quota)) {
+               prt_printf(err, "incorrect value size (%zu != %zu)",
+                      bkey_val_bytes(k.k), sizeof(struct bch_quota));
+               return -EINVAL;
+       }
 
-       return NULL;
+       return 0;
 }
 
 void bch2_quota_to_text(struct printbuf *out, struct bch_fs *c,
@@ -75,7 +82,7 @@ void bch2_quota_to_text(struct printbuf *out, struct bch_fs *c,
        unsigned i;
 
        for (i = 0; i < Q_COUNTERS; i++)
-               pr_buf(out, "%s hardlimit %llu softlimit %llu",
+               prt_printf(out, "%s hardlimit %llu softlimit %llu",
                       bch2_quota_counters[i],
                       le64_to_cpu(dq.v->c[i].hardlimit),
                       le64_to_cpu(dq.v->c[i].softlimit));
@@ -448,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;
@@ -496,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);
@@ -510,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: */