]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/fsck.c
Update bcachefs sources to 9b3aa5ec6c bcachefs: Add tabstops to printbufs
[bcachefs-tools-debian] / libbcachefs / fsck.c
index 835ef11496d2c5ede6372d555faa282a01584397..ced4d671eb8d707e49b8600a5bfa607c4711751f 100644 (file)
@@ -564,14 +564,17 @@ static struct inode_walker inode_walker_init(void)
        return (struct inode_walker) { 0, };
 }
 
-static int inode_walker_realloc(struct inode_walker *w)
+static int inode_walker_realloc(struct bch_fs *c, struct inode_walker *w)
 {
        if (w->nr == w->size) {
                size_t new_size = max_t(size_t, 8UL, w->size * 2);
                void *d = krealloc(w->d, new_size * sizeof(w->d[0]),
                                   GFP_KERNEL);
-               if (!d)
+               if (!d) {
+                       bch_err(c, "fsck: error allocating memory for inode_walker, size %zu",
+                               new_size);
                        return -ENOMEM;
+               }
 
                w->d = d;
                w->size = new_size;
@@ -586,7 +589,7 @@ static int add_inode(struct bch_fs *c, struct inode_walker *w,
        struct bch_inode_unpacked u;
        int ret;
 
-       ret = inode_walker_realloc(w);
+       ret = inode_walker_realloc(c, w);
        if (ret)
                return ret;
 
@@ -647,7 +650,7 @@ found:
                while (i && w->d[i - 1].snapshot > pos.snapshot)
                        --i;
 
-               ret = inode_walker_realloc(w);
+               ret = inode_walker_realloc(c, w);
                if (ret)
                        return ret;
 
@@ -1132,9 +1135,9 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w)
                count2 = lockrestart_do(trans,
                        bch2_count_inode_sectors(trans, w->cur_inum, i->snapshot));
 
-               if (fsck_err_on(i->count != count2, c,
-                               "fsck counted i_sectors wrong: got %llu should be %llu",
-                               i->count, count2)) {
+               if (i->count != count2) {
+                       bch_err(c, "fsck counted i_sectors wrong: got %llu should be %llu",
+                               i->count, count2);
                        i->count = count2;
                        if (i->inode.bi_sectors == i->count)
                                continue;
@@ -1313,12 +1316,13 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w)
                if (i->inode.bi_nlink == i->count)
                        continue;
 
-               count2 = lockrestart_do(trans,
-                               bch2_count_subdirs(trans, w->cur_inum, i->snapshot));
+               count2 = bch2_count_subdirs(trans, w->cur_inum, i->snapshot);
+               if (count2 < 0)
+                       return count2;
 
-               if (fsck_err_on(i->count != count2, c,
-                               "directory %llu:%u: fsck counted subdirectories wrong, got %llu should be %llu",
-                               w->cur_inum, i->snapshot, i->count, count2)) {
+               if (i->count != count2) {
+                       bch_err(c, "fsck counted subdirectories wrong: got %llu should be %llu",
+                               i->count, count2);
                        i->count = count2;
                        if (i->inode.bi_nlink == i->count)
                                continue;
@@ -1812,7 +1816,8 @@ static bool path_is_dup(struct pathbuf *p, u64 inum, u32 snapshot)
        return false;
 }
 
-static int path_down(struct pathbuf *p, u64 inum, u32 snapshot)
+static int path_down(struct bch_fs *c, struct pathbuf *p,
+                    u64 inum, u32 snapshot)
 {
        if (p->nr == p->size) {
                size_t new_size = max_t(size_t, 256UL, p->size * 2);
@@ -1820,6 +1825,8 @@ static int path_down(struct pathbuf *p, u64 inum, u32 snapshot)
                                   new_size * sizeof(p->entries[0]),
                                   GFP_KERNEL);
                if (!n) {
+                       bch_err(c, "fsck: error allocating memory for pathbuf, size %zu",
+                               new_size);
                        return -ENOMEM;
                }
 
@@ -1893,7 +1900,7 @@ static int check_path(struct btree_trans *trans,
                if (!S_ISDIR(inode->bi_mode))
                        break;
 
-               ret = path_down(p, inode->bi_inum, snapshot);
+               ret = path_down(c, p, inode->bi_inum, snapshot);
                if (ret) {
                        bch_err(c, "memory allocation failure");
                        return ret;
@@ -1998,12 +2005,15 @@ struct nlink_table {
        }               *d;
 };
 
-static int add_nlink(struct nlink_table *t, u64 inum, u32 snapshot)
+static int add_nlink(struct bch_fs *c, struct nlink_table *t,
+                    u64 inum, u32 snapshot)
 {
        if (t->nr == t->size) {
                size_t new_size = max_t(size_t, 128UL, t->size * 2);
                void *d = kvmalloc(new_size * sizeof(t->d[0]), GFP_KERNEL);
                if (!d) {
+                       bch_err(c, "fsck: error allocating memory for nlink_table, size %zu",
+                               new_size);
                        return -ENOMEM;
                }
 
@@ -2093,7 +2103,7 @@ static int check_nlinks_find_hardlinks(struct bch_fs *c,
                if (!u.bi_nlink)
                        continue;
 
-               ret = add_nlink(t, k.k->p.offset, k.k->p.snapshot);
+               ret = add_nlink(c, t, k.k->p.offset, k.k->p.snapshot);
                if (ret) {
                        *end = k.k->p.offset;
                        ret = 0;