]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/quota.c
Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into...
[bcachefs-tools-debian] / libbcachefs / quota.c
index 331f22835d1859574cd073784242d557e130d7cd..7e1f1828ab2074d503f3ce9b3d464e4e710d3c88 100644 (file)
@@ -2,6 +2,7 @@
 #include "bcachefs.h"
 #include "btree_update.h"
 #include "errcode.h"
+#include "error.h"
 #include "inode.h"
 #include "quota.h"
 #include "subvolume.h"
@@ -67,12 +68,6 @@ int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k,
                return -BCH_ERR_invalid_bkey;
        }
 
-       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 -BCH_ERR_invalid_bkey;
-       }
-
        return 0;
 }
 
@@ -562,23 +557,32 @@ static int bch2_fs_quota_read_inode(struct btree_trans *trans,
 {
        struct bch_fs *c = trans->c;
        struct bch_inode_unpacked u;
-       struct bch_subvolume subvolume;
+       struct bch_snapshot_tree s_t;
        int ret;
 
-       ret = bch2_snapshot_get_subvol(trans, k.k->p.snapshot, &subvolume);
+       ret = bch2_snapshot_tree_lookup(trans,
+                       snapshot_t(c, k.k->p.snapshot)->tree, &s_t);
+       bch2_fs_inconsistent_on(bch2_err_matches(ret, ENOENT), c,
+                       "%s: snapshot tree %u not found", __func__,
+                       snapshot_t(c, k.k->p.snapshot)->tree);
        if (ret)
                return ret;
 
-       /*
-        * We don't do quota accounting in snapshots:
-        */
-       if (BCH_SUBVOLUME_SNAP(&subvolume))
+       if (!s_t.master_subvol)
                goto advance;
 
-       if (!bkey_is_inode(k.k))
+       ret = bch2_inode_find_by_inum_trans(trans,
+                               (subvol_inum) {
+                                       le32_to_cpu(s_t.master_subvol),
+                                       k.k->p.offset,
+                               }, &u);
+       /*
+        * Inode might be deleted in this snapshot - the easiest way to handle
+        * that is to just skip it here:
+        */
+       if (bch2_err_matches(ret, ENOENT))
                goto advance;
 
-       ret = bch2_inode_unpack(k, &u);
        if (ret)
                return ret;
 
@@ -587,7 +591,7 @@ static int bch2_fs_quota_read_inode(struct btree_trans *trans,
        bch2_quota_acct(c, bch_qid(&u), Q_INO, 1,
                        KEY_TYPE_QUOTA_NOCHECK);
 advance:
-       bch2_btree_iter_set_pos(iter, POS(iter->pos.inode, iter->pos.offset + 1));
+       bch2_btree_iter_set_pos(iter, bpos_nosnap_successor(iter->pos));
        return 0;
 }
 
@@ -617,10 +621,11 @@ int bch2_fs_quota_read(struct bch_fs *c)
              for_each_btree_key2(&trans, iter, BTREE_ID_inodes,
                        POS_MIN, BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k,
                bch2_fs_quota_read_inode(&trans, &iter, k));
-       if (ret)
-               bch_err(c, "err in quota_read: %s", bch2_err_str(ret));
 
        bch2_trans_exit(&trans);
+
+       if (ret)
+               bch_err_fn(c, ret);
        return ret;
 }
 
@@ -896,7 +901,7 @@ static int bch2_get_next_quota(struct super_block *sb, struct kqid *kqid,
        ret = -ENOENT;
 found:
        mutex_unlock(&q->lock);
-       return ret;
+       return bch2_err_class(ret);
 }
 
 static int bch2_set_quota_trans(struct btree_trans *trans,
@@ -907,10 +912,8 @@ static int bch2_set_quota_trans(struct btree_trans *trans,
        struct bkey_s_c k;
        int ret;
 
-       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);
-
+       k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_quotas, new_quota->k.p,
+                              BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
        ret = bkey_err(k);
        if (unlikely(ret))
                return ret;
@@ -958,7 +961,7 @@ static int bch2_set_quota(struct super_block *sb, struct kqid qid,
                            bch2_set_quota_trans(&trans, &new_quota, qdq)) ?:
                __bch2_quota_set(c, bkey_i_to_s_c(&new_quota.k_i), qdq);
 
-       return ret;
+       return bch2_err_class(ret);
 }
 
 const struct quotactl_ops bch2_quotactl_operations = {