]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to d464ec667b2b bcachefs: Add missing printk newlines
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 3 Nov 2023 16:09:59 +0000 (12:09 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 3 Nov 2023 16:09:59 +0000 (12:09 -0400)
16 files changed:
.bcachefs_revision
libbcachefs/alloc_background.c
libbcachefs/backpointers.c
libbcachefs/backpointers.h
libbcachefs/bkey.h
libbcachefs/bkey_sort.c
libbcachefs/btree_io.c
libbcachefs/btree_update_interior.h
libbcachefs/errcode.h
libbcachefs/fs-io-buffered.c
libbcachefs/fs.c
libbcachefs/inode.c
libbcachefs/inode.h
libbcachefs/opts.c
libbcachefs/recovery.c
libbcachefs/super-io.c

index f778625352ece04d84b70b8c74c42a5d0a3de909..8abb4eddb0934fbd1b8bc0a51e006a4c7275cf1e 100644 (file)
@@ -1 +1 @@
-b9bd69421f7364ca4ff11c827fd0e171a8b826ea
+d464ec667b2b9de097e39d1505b45aafd87a9552
index bcfae91667af10e98d94c96f590c66c6ddc269ad..1fec0e67891f120efefed775c8010bc1b6675a86 100644 (file)
@@ -297,15 +297,6 @@ fsck_err:
        return ret;
 }
 
-static inline u64 swab40(u64 x)
-{
-       return (((x & 0x00000000ffULL) << 32)|
-               ((x & 0x000000ff00ULL) << 16)|
-               ((x & 0x0000ff0000ULL) >>  0)|
-               ((x & 0x00ff000000ULL) >> 16)|
-               ((x & 0xff00000000ULL) >> 32));
-}
-
 void bch2_alloc_v4_swab(struct bkey_s k)
 {
        struct bch_alloc_v4 *a = bkey_s_to_alloc_v4(k).v;
@@ -319,6 +310,7 @@ void bch2_alloc_v4_swab(struct bkey_s k)
        a->io_time[1]           = swab64(a->io_time[1]);
        a->stripe               = swab32(a->stripe);
        a->nr_external_backpointers = swab32(a->nr_external_backpointers);
+       a->fragmentation_lru    = swab64(a->fragmentation_lru);
 
        bps = alloc_v4_backpointers(a);
        for (bp = bps; bp < bps + BCH_ALLOC_V4_NR_BACKPOINTERS(a); bp++) {
index 3b79bde1ce2f2abdda4827274b127c8a22e03e7a..5ed96dddae08fee8c579919cf6db2061546a5b20 100644 (file)
@@ -77,7 +77,7 @@ void bch2_backpointer_swab(struct bkey_s k)
 {
        struct bkey_s_backpointer bp = bkey_s_to_backpointer(k);
 
-       bp.v->bucket_offset     = swab32(bp.v->bucket_offset);
+       bp.v->bucket_offset     = swab40(bp.v->bucket_offset);
        bp.v->bucket_len        = swab32(bp.v->bucket_len);
        bch2_bpos_swab(&bp.v->pos);
 }
index 4ab9f3562912de16a3e41f3baefa8645e9b2323c..ab866feeaf660f497cc58ddf73a2692ab32865ac 100644 (file)
@@ -7,6 +7,15 @@
 #include "buckets.h"
 #include "super.h"
 
+static inline u64 swab40(u64 x)
+{
+       return (((x & 0x00000000ffULL) << 32)|
+               ((x & 0x000000ff00ULL) << 16)|
+               ((x & 0x0000ff0000ULL) >>  0)|
+               ((x & 0x00ff000000ULL) >> 16)|
+               ((x & 0xff00000000ULL) >> 32));
+}
+
 int bch2_backpointer_invalid(struct bch_fs *, struct bkey_s_c k,
                             enum bkey_invalid_flags, struct printbuf *);
 void bch2_backpointer_to_text(struct printbuf *, const struct bch_backpointer *);
index 5184502092369d963f076383ee9bf3ca5a358f6c..831be01809f2c9271d4db159377decd1b8686bb6 100644 (file)
@@ -92,19 +92,15 @@ enum bkey_lr_packed {
 #define bkey_lr_packed(_l, _r)                                         \
        ((_l)->format + ((_r)->format << 1))
 
-#define bkey_copy(_dst, _src)                                  \
-do {                                                           \
-       BUILD_BUG_ON(!type_is(_dst, struct bkey_i *) &&         \
-                    !type_is(_dst, struct bkey_packed *));     \
-       BUILD_BUG_ON(!type_is(_src, struct bkey_i *) &&         \
-                    !type_is(_src, struct bkey_packed *));     \
-       EBUG_ON((u64 *) (_dst) > (u64 *) (_src) &&              \
-               (u64 *) (_dst) < (u64 *) (_src) +               \
-               ((struct bkey *) (_src))->u64s);                \
-                                                               \
-       memcpy_u64s_small((_dst), (_src),                       \
-                         ((struct bkey *) (_src))->u64s);      \
-} while (0)
+static inline void bkey_p_copy(struct bkey_packed *dst, const struct bkey_packed *src)
+{
+       memcpy_u64s_small(dst, src, src->u64s);
+}
+
+static inline void bkey_copy(struct bkey_i *dst, const struct bkey_i *src)
+{
+       memcpy_u64s_small(dst, src, src->k.u64s);
+}
 
 struct btree;
 
index b9aa027c881b14458394ae8fdad6d93f53e1cbbf..bcca9e76a0b4bf40f20903c856e7559e60b87da1 100644 (file)
@@ -106,7 +106,7 @@ bch2_key_sort_fix_overlapping(struct bch_fs *c, struct bset *dst,
        while ((k = sort_iter_peek(iter))) {
                if (!bkey_deleted(k) &&
                    !should_drop_next_key(iter)) {
-                       bkey_copy(out, k);
+                       bkey_p_copy(out, k);
                        btree_keys_account_key_add(&nr, 0, out);
                        out = bkey_p_next(out);
                }
@@ -137,7 +137,7 @@ bch2_sort_repack(struct bset *dst, struct btree *src,
                        continue;
 
                if (!transform)
-                       bkey_copy(out, in);
+                       bkey_p_copy(out, in);
                else if (bch2_bkey_transform(out_f, out, bkey_packed(in)
                                             ? in_f : &bch2_bkey_format_current, in))
                        out->format = KEY_FORMAT_LOCAL_BTREE;
@@ -191,7 +191,7 @@ unsigned bch2_sort_keys(struct bkey_packed *dst,
                        memcpy_u64s_small(out, in, bkeyp_key_u64s(f, in));
                        set_bkeyp_val_u64s(f, out, 0);
                } else {
-                       bkey_copy(out, in);
+                       bkey_p_copy(out, in);
                }
                out->needs_whiteout |= needs_whiteout;
                out = bkey_p_next(out);
index 4d2d6f93500d22008a1ce031b134494c52812212..37d896edb06e0475cc7146e31a2790321f842394 100644 (file)
@@ -184,7 +184,7 @@ static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b)
        k = new_whiteouts;
 
        while (ptrs != ptrs_end) {
-               bkey_copy(k, *ptrs);
+               bkey_p_copy(k, *ptrs);
                k = bkey_p_next(k);
                ptrs++;
        }
@@ -260,7 +260,7 @@ static bool bch2_drop_whiteouts(struct btree *b, enum compact_mode mode)
                        n = bkey_p_next(k);
 
                        if (!bkey_deleted(k)) {
-                               bkey_copy(out, k);
+                               bkey_p_copy(out, k);
                                out = bkey_p_next(out);
                        } else {
                                BUG_ON(k->needs_whiteout);
index d92b3cf5f5e0f26b823d32a8719bf0f879cf994b..c2ffeb30884d795ebbdcdc08f7804c1803779352 100644 (file)
@@ -303,7 +303,7 @@ static inline void push_whiteout(struct bch_fs *c, struct btree *b,
        k.needs_whiteout = true;
 
        b->whiteout_u64s += k.u64s;
-       bkey_copy(unwritten_whiteouts_start(c, b), &k);
+       bkey_p_copy(unwritten_whiteouts_start(c, b), &k);
 }
 
 /*
index 2a11f32cf30a24050f6237ddaf506f9bb87f31de..68a1a96bb7caf526a148a988c12913151c57b6d5 100644 (file)
@@ -3,6 +3,8 @@
 #define _BCACHEFS_ERRCODE_H
 
 #define BCH_ERRCODES()                                                         \
+       x(ERANGE,                       ERANGE_option_too_small)                \
+       x(ERANGE,                       ERANGE_option_too_big)                  \
        x(ENOMEM,                       ENOMEM_stripe_buf)                      \
        x(ENOMEM,                       ENOMEM_replicas_table)                  \
        x(ENOMEM,                       ENOMEM_cpu_replicas)                    \
index 58ccc7b91ac79c7343828205e37edfdca56c0fab..52f0e7acda3d81ce043672b428db4432cdcebeb2 100644 (file)
@@ -389,6 +389,21 @@ static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs
        return ret;
 }
 
+/*
+ * Determine when a writepage io is full. We have to limit writepage bios to a
+ * single page per bvec (i.e. 1MB with 4k pages) because that is the limit to
+ * what the bounce path in bch2_write_extent() can handle. In theory we could
+ * loosen this restriction for non-bounce I/O, but we don't have that context
+ * here. Ideally, we can up this limit and make it configurable in the future
+ * when the bounce path can be enhanced to accommodate larger source bios.
+ */
+static inline bool bch_io_full(struct bch_writepage_io *io, unsigned len)
+{
+       struct bio *bio = &io->op.wbio.bio;
+       return bio_full(bio, len) ||
+               (bio->bi_iter.bi_size + len > BIO_MAX_VECS * PAGE_SIZE);
+}
+
 static void bch2_writepage_io_done(struct bch_write_op *op)
 {
        struct bch_writepage_io *io =
@@ -606,9 +621,7 @@ do_io:
 
                if (w->io &&
                    (w->io->op.res.nr_replicas != nr_replicas_this_write ||
-                    bio_full(&w->io->op.wbio.bio, sectors << 9) ||
-                    w->io->op.wbio.bio.bi_iter.bi_size + (sectors << 9) >=
-                    (BIO_MAX_VECS * PAGE_SIZE) ||
+                    bch_io_full(w->io, sectors << 9) ||
                     bio_end_sector(&w->io->op.wbio.bio) != sector))
                        bch2_writepage_do_io(w);
 
index 693f34747841181b75f673780dd27f6d2a647ad0..8dbc848f25b878d065d2b74949c46ad13b6dda27 100644 (file)
@@ -1213,9 +1213,6 @@ static struct dentry *bch2_get_parent(struct dentry *child)
                .inum = inode->ei_inode.bi_dir,
        };
 
-       if (!parent_inum.inum)
-               return NULL;
-
        return d_obtain_alias(bch2_vfs_inode_get(c, parent_inum));
 }
 
index 8b3c675eb2957183adeda0bdb9dcb629acca0028..ef58e2927aecb58f1263f2e9ec83902bde6b7d99 100644 (file)
@@ -367,9 +367,10 @@ int bch2_inode_peek(struct btree_trans *trans,
        return ret;
 }
 
-int bch2_inode_write(struct btree_trans *trans,
+int bch2_inode_write_flags(struct btree_trans *trans,
                     struct btree_iter *iter,
-                    struct bch_inode_unpacked *inode)
+                    struct bch_inode_unpacked *inode,
+                    enum btree_update_flags flags)
 {
        struct bkey_inode_buf *inode_p;
 
@@ -379,7 +380,7 @@ int bch2_inode_write(struct btree_trans *trans,
 
        bch2_inode_pack_inlined(inode_p, inode);
        inode_p->inode.k.p.snapshot = iter->snapshot;
-       return bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0);
+       return bch2_trans_update(trans, iter, &inode_p->inode.k_i, flags);
 }
 
 struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k)
@@ -1065,24 +1066,18 @@ err:
        return ret ?: -BCH_ERR_transaction_restart_nested;
 }
 
-static int may_delete_deleted_inode(struct btree_trans *trans, struct bpos pos)
+static int may_delete_deleted_inode(struct btree_trans *trans,
+                                   struct btree_iter *iter,
+                                   struct bpos pos,
+                                   bool *need_another_pass)
 {
        struct bch_fs *c = trans->c;
-       struct btree_iter iter;
+       struct btree_iter inode_iter;
        struct bkey_s_c k;
        struct bch_inode_unpacked inode;
        int ret;
 
-       if (bch2_snapshot_is_internal_node(c, pos.snapshot))
-               return 0;
-
-       if (!fsck_err_on(c->sb.clean, c,
-                        deleted_inode_but_clean,
-                        "filesystem marked as clean but have deleted inode %llu:%u",
-                        pos.offset, pos.snapshot))
-               return 0;
-
-       k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes, pos, BTREE_ITER_CACHED);
+       k = bch2_bkey_get_iter(trans, &inode_iter, BTREE_ID_inodes, pos, BTREE_ITER_CACHED);
        ret = bkey_err(k);
        if (ret)
                return ret;
@@ -1110,6 +1105,36 @@ static int may_delete_deleted_inode(struct btree_trans *trans, struct bpos pos)
                        pos.offset, pos.snapshot))
                goto delete;
 
+       if (c->sb.clean &&
+           !fsck_err(c,
+                     deleted_inode_but_clean,
+                     "filesystem marked as clean but have deleted inode %llu:%u",
+                     pos.offset, pos.snapshot))
+               return 0;
+
+       if (bch2_snapshot_is_internal_node(c, pos.snapshot)) {
+               struct bpos new_min_pos;
+
+               ret = bch2_propagate_key_to_snapshot_leaves(trans, inode_iter.btree_id, k, &new_min_pos);
+               if (ret)
+                       goto err;
+
+               inode.bi_flags &= ~BCH_INODE_unlinked;
+
+               ret = bch2_inode_write_flags(trans, &inode_iter, &inode,
+                                            BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
+               bch_err_msg(c, ret, "clearing inode unlinked flag");
+               if (ret)
+                       return ret;
+
+               /*
+                * We'll need another write buffer flush to pick up the new
+                * unlinked inodes in the snapshot leaves:
+                */
+               *need_another_pass = true;
+               return 0;
+       }
+
        return 1;
 err:
 fsck_err:
@@ -1123,7 +1148,10 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
        struct btree_trans *trans = bch2_trans_get(c);
        struct btree_iter iter;
        struct bkey_s_c k;
+       bool need_another_pass;
        int ret;
+again:
+       need_another_pass = false;
 
        ret = bch2_btree_write_buffer_flush_sync(trans);
        if (ret)
@@ -1137,7 +1165,8 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
         */
        for_each_btree_key(trans, iter, BTREE_ID_deleted_inodes, POS_MIN,
                           BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
-               ret = lockrestart_do(trans, may_delete_deleted_inode(trans, k.k->p));
+               ret = lockrestart_do(trans, may_delete_deleted_inode(trans, &iter, k.k->p,
+                                                                    &need_another_pass));
                if (ret < 0)
                        break;
 
@@ -1147,12 +1176,17 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
                                bch2_fs_lazy_rw(c);
                        }
 
+                       bch_verbose(c, "deleting unlinked inode %llu:%u", k.k->p.offset, k.k->p.snapshot);
+
                        ret = bch2_inode_rm_snapshot(trans, k.k->p.offset, k.k->p.snapshot);
                        if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
                                break;
                }
        }
        bch2_trans_iter_exit(trans, &iter);
+
+       if (!ret && need_another_pass)
+               goto again;
 err:
        bch2_trans_put(trans);
 
index 5068ba9ca8ba2e549e1131649dd6e559397c4b3f..88818a332b1e5fcaa5fd9b350d958ef582c05161 100644 (file)
@@ -3,6 +3,7 @@
 #define _BCACHEFS_INODE_H
 
 #include "bkey.h"
+#include "bkey_methods.h"
 #include "opts.h"
 
 enum bkey_invalid_flags;
@@ -101,8 +102,16 @@ void bch2_inode_unpacked_to_text(struct printbuf *, struct bch_inode_unpacked *)
 
 int bch2_inode_peek(struct btree_trans *, struct btree_iter *,
                    struct bch_inode_unpacked *, subvol_inum, unsigned);
-int bch2_inode_write(struct btree_trans *, struct btree_iter *,
-                    struct bch_inode_unpacked *);
+
+int bch2_inode_write_flags(struct btree_trans *, struct btree_iter *,
+                    struct bch_inode_unpacked *, enum btree_update_flags);
+
+static inline int bch2_inode_write(struct btree_trans *trans,
+                    struct btree_iter *iter,
+                    struct bch_inode_unpacked *inode)
+{
+       return bch2_inode_write_flags(trans, iter, inode, 0);
+}
 
 void bch2_inode_init_early(struct bch_fs *,
                           struct bch_inode_unpacked *);
index 4ad5880664b0fbf8105ae4b175ede930cae43e14..8dd4046cca41ef23b061f4aeac1892f82a504d65 100644 (file)
@@ -265,14 +265,14 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
                if (err)
                        prt_printf(err, "%s: too small (min %llu)",
                               opt->attr.name, opt->min);
-               return -ERANGE;
+               return -BCH_ERR_ERANGE_option_too_small;
        }
 
        if (opt->max && v >= opt->max) {
                if (err)
                        prt_printf(err, "%s: too big (max %llu)",
                               opt->attr.name, opt->max);
-               return -ERANGE;
+               return -BCH_ERR_ERANGE_option_too_big;
        }
 
        if ((opt->flags & OPT_SB_FIELD_SECTORS) && (v & 511)) {
index 9600b808317534b317e5836802f483c67299c46a..9c30500ce9200af8be8f71a50f5fa02c356e4400 100644 (file)
@@ -735,6 +735,13 @@ int bch2_fs_recovery(struct bch_fs *c)
                                if (*i) {
                                        last_journal_entry = &(*i)->j;
                                        (*i)->ignore = false;
+                                       /*
+                                        * This was probably a NO_FLUSH entry,
+                                        * so last_seq was garbage - but we know
+                                        * we're only using a single journal
+                                        * entry, set it here:
+                                        */
+                                       (*i)->j.last_seq = (*i)->j.seq;
                                        break;
                                }
                }
index a93e53d0b37ef623582beb8731f8c0b86bc51b2c..9b9f36af6bd31d47aa84404a6f85e3d323c0a1d9 100644 (file)
@@ -721,7 +721,7 @@ retry:
        if (opt_defined(*opts, sb))
                goto err;
 
-       printk(KERN_ERR "bcachefs (%s): error reading default superblock: %s",
+       printk(KERN_ERR "bcachefs (%s): error reading default superblock: %s\n",
               path, err.buf);
        printbuf_reset(&err);
 
@@ -783,7 +783,7 @@ got_super:
 
        ret = bch2_sb_validate(sb, &err, READ);
        if (ret) {
-               printk(KERN_ERR "bcachefs (%s): error validating superblock: %s",
+               printk(KERN_ERR "bcachefs (%s): error validating superblock: %s\n",
                       path, err.buf);
                goto err_no_print;
        }
@@ -791,7 +791,7 @@ out:
        printbuf_exit(&err);
        return ret;
 err:
-       printk(KERN_ERR "bcachefs (%s): error reading superblock: %s",
+       printk(KERN_ERR "bcachefs (%s): error reading superblock: %s\n",
               path, err.buf);
 err_no_print:
        bch2_free_super(sb);