]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/quota.c
Update bcachefs sources to 25de2b00dc bcachefs: Change check for invalid key types
[bcachefs-tools-debian] / libbcachefs / quota.c
index cc0db72ce1df8163aa01f3f317051e9248eccaab..d90db3fb823ed42fc89c9a47b8b0dc6179721b6a 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"
@@ -59,7 +60,8 @@ const struct bch_sb_field_ops bch_sb_field_ops_quota = {
 };
 
 int bch2_quota_invalid(const struct bch_fs *c, struct bkey_s_c k,
-                      unsigned flags, struct printbuf *err)
+                      enum bkey_invalid_flags flags,
+                      struct printbuf *err)
 {
        if (k.k->p.inode >= QTYP_NR) {
                prt_printf(err, "invalid quota type (%llu >= %u)",
@@ -479,13 +481,13 @@ static int __bch2_quota_set(struct bch_fs *c, struct bkey_s_c k,
                }
 
                if (qdq && qdq->d_fieldmask & QC_SPC_TIMER)
-                       mq->c[Q_SPC].timer      = cpu_to_le64(qdq->d_spc_timer);
+                       mq->c[Q_SPC].timer      = qdq->d_spc_timer;
                if (qdq && qdq->d_fieldmask & QC_SPC_WARNS)
-                       mq->c[Q_SPC].warns      = cpu_to_le64(qdq->d_spc_warns);
+                       mq->c[Q_SPC].warns      = qdq->d_spc_warns;
                if (qdq && qdq->d_fieldmask & QC_INO_TIMER)
-                       mq->c[Q_INO].timer      = cpu_to_le64(qdq->d_ino_timer);
+                       mq->c[Q_INO].timer      = qdq->d_ino_timer;
                if (qdq && qdq->d_fieldmask & QC_INO_WARNS)
-                       mq->c[Q_INO].warns      = cpu_to_le64(qdq->d_ino_warns);
+                       mq->c[Q_INO].warns      = qdq->d_ino_warns;
 
                mutex_unlock(&q->lock);
        }
@@ -561,6 +563,9 @@ static int bch2_fs_quota_read_inode(struct btree_trans *trans,
 
        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;
 
@@ -572,6 +577,13 @@ static int bch2_fs_quota_read_inode(struct btree_trans *trans,
                                        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;
+
        if (ret)
                return ret;
 
@@ -610,10 +622,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;
 }
 
@@ -889,7 +902,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,
@@ -949,7 +962,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 = {