]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/btree_io.c
Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang
[bcachefs-tools-debian] / libbcachefs / btree_io.c
index 586e2f96f649af1e98aa3eddd39378f634530ece..c049876ee80be3cc4ca5e7813ddd42e1a9194490 100644 (file)
@@ -18,9 +18,9 @@
 #include "journal_reclaim.h"
 #include "journal_seq_blacklist.h"
 #include "super-io.h"
+#include "trace.h"
 
 #include <linux/sched/mm.h>
-#include <trace/events/bcachefs.h>
 
 void bch2_btree_node_io_unlock(struct btree *b)
 {
@@ -105,8 +105,8 @@ static void btree_bounce_free(struct bch_fs *c, size_t size,
                vpfree(p, size);
 }
 
-static void *_btree_bounce_alloc(struct bch_fs *c, size_t size,
-                                bool *used_mempool)
+static void *btree_bounce_alloc_noprof(struct bch_fs *c, size_t size,
+                                      bool *used_mempool)
 {
        unsigned flags = memalloc_nofs_save();
        void *p;
@@ -114,16 +114,16 @@ static void *_btree_bounce_alloc(struct bch_fs *c, size_t size,
        BUG_ON(size > btree_bytes(c));
 
        *used_mempool = false;
-       p = _vpmalloc(size, __GFP_NOWARN|GFP_NOWAIT);
+       p = vpmalloc_noprof(size, __GFP_NOWARN|GFP_NOWAIT);
        if (!p) {
                *used_mempool = true;
-               p = mempool_alloc(&c->btree_bounce_pool, GFP_NOIO);
+               p = mempool_alloc(&c->btree_bounce_pool, GFP_NOFS);
        }
        memalloc_nofs_restore(flags);
        return p;
 }
 #define btree_bounce_alloc(_c, _size, _used_mempool)           \
-       alloc_hooks(_btree_bounce_alloc(_c, _size, _used_mempool), void *, NULL)
+       alloc_hooks(btree_bounce_alloc_noprof(_c, _size, _used_mempool))
 
 static void sort_bkey_ptrs(const struct btree *bt,
                           struct bkey_packed **ptrs, unsigned nr)
@@ -485,7 +485,7 @@ void bch2_btree_init_next(struct btree_trans *trans, struct btree *b)
        struct btree_node_entry *bne;
        bool reinit_iter = false;
 
-       EBUG_ON(!(b->c.lock.state.seq & 1));
+       EBUG_ON(!six_lock_counts(&b->c.lock).n[SIX_LOCK_write]);
        BUG_ON(bset_written(b, bset(b, &b->set[1])));
        BUG_ON(btree_node_just_written(b));
 
@@ -519,7 +519,7 @@ static void btree_pos_to_text(struct printbuf *out, struct bch_fs *c,
        prt_printf(out, "%s level %u/%u\n  ",
               bch2_btree_ids[b->c.btree_id],
               b->c.level,
-              c->btree_roots[b->c.btree_id].level);
+              bch2_btree_id_root(c, b->c.btree_id)->level);
        bch2_bkey_val_to_text(out, c, bkey_i_to_s_c(&b->key));
 }
 
@@ -612,7 +612,7 @@ static int __btree_err(enum btree_err_type type,
        case BTREE_ERR_BAD_NODE:
                bch2_print_string_as_lines(KERN_ERR, out.buf);
                bch2_topology_error(c);
-               ret = -BCH_ERR_need_topology_repair;
+               ret = bch2_run_explicit_recovery_pass(c, BCH_RECOVERY_PASS_check_topology) ?: -EIO;
                break;
        case BTREE_ERR_INCOMPATIBLE:
                bch2_print_string_as_lines(KERN_ERR, out.buf);
@@ -701,11 +701,11 @@ static int validate_bset(struct bch_fs *c, struct bch_dev *ca,
        struct printbuf buf2 = PRINTBUF;
        int ret = 0;
 
-       btree_err_on((version != BCH_BSET_VERSION_OLD &&
-                     version < bcachefs_metadata_version_min) ||
-                    version >= bcachefs_metadata_version_max,
+       btree_err_on(!bch2_version_compatible(version),
                     BTREE_ERR_INCOMPATIBLE, c, ca, b, i,
-                    "unsupported bset version");
+                    "unsupported bset version %u.%u",
+                    BCH_VERSION_MAJOR(version),
+                    BCH_VERSION_MINOR(version));
 
        if (btree_err_on(version < c->sb.version_min,
                         BTREE_ERR_FIXABLE, c, NULL, b, i,
@@ -717,7 +717,8 @@ static int validate_bset(struct bch_fs *c, struct bch_dev *ca,
                mutex_unlock(&c->sb_lock);
        }
 
-       if (btree_err_on(version > c->sb.version,
+       if (btree_err_on(BCH_VERSION_MAJOR(version) >
+                        BCH_VERSION_MAJOR(c->sb.version),
                         BTREE_ERR_FIXABLE, c, NULL, b, i,
                         "bset version %u newer than superblock version %u",
                         version, c->sb.version)) {
@@ -939,7 +940,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
        /* We might get called multiple times on read retry: */
        b->written = 0;
 
-       iter = mempool_alloc(&c->fill_iter, GFP_NOIO);
+       iter = mempool_alloc(&c->fill_iter, GFP_NOFS);
        sort_iter_init(iter, b);
        iter->size = (btree_blocks(c) + 1) * 2;
 
@@ -1285,7 +1286,7 @@ struct btree_node_read_all {
        unsigned                nr;
        void                    *buf[BCH_REPLICAS_MAX];
        struct bio              *bio[BCH_REPLICAS_MAX];
-       int                     err[BCH_REPLICAS_MAX];
+       blk_status_t            err[BCH_REPLICAS_MAX];
 };
 
 static unsigned btree_node_sectors_written(struct bch_fs *c, void *data)
@@ -1567,7 +1568,8 @@ void bch2_btree_node_read(struct bch_fs *c, struct btree *b,
                btree_pos_to_text(&buf, c, b);
                bch_err(c, "%s", buf.buf);
 
-               if (test_bit(BCH_FS_TOPOLOGY_REPAIR_DONE, &c->flags))
+               if (c->recovery_passes_explicit & BIT_ULL(BCH_RECOVERY_PASS_check_topology) &&
+                   c->curr_recovery_pass > BCH_RECOVERY_PASS_check_topology)
                        bch2_fatal_error(c);
 
                set_btree_node_read_error(b);
@@ -1582,7 +1584,7 @@ void bch2_btree_node_read(struct bch_fs *c, struct btree *b,
        bio = bio_alloc_bioset(NULL,
                               buf_pages(b->data, btree_bytes(c)),
                               REQ_OP_READ|REQ_SYNC|REQ_META,
-                              GFP_NOIO,
+                              GFP_NOFS,
                               &c->btree_bio);
        rb = container_of(bio, struct btree_read_bio, bio);
        rb->c                   = c;
@@ -1748,7 +1750,7 @@ static void btree_node_write_work(struct work_struct *work)
        struct bch_fs *c        = wbio->wbio.c;
        struct btree *b         = wbio->wbio.bio.bi_private;
        struct bch_extent_ptr *ptr;
-       int ret;
+       int ret = 0;
 
        btree_bounce_free(c,
                wbio->data_bytes,
@@ -1768,7 +1770,11 @@ static void btree_node_write_work(struct work_struct *work)
        } else {
                ret = bch2_trans_do(c, NULL, NULL, 0,
                        bch2_btree_node_update_key_get_iter(&trans, b, &wbio->key,
-                                                           !wbio->wbio.failed.nr));
+                                       BCH_WATERMARK_reclaim|
+                                       BTREE_INSERT_JOURNAL_RECLAIM|
+                                       BTREE_INSERT_NOFAIL|
+                                       BTREE_INSERT_NOCHECK_RW,
+                                       !wbio->wbio.failed.nr));
                if (ret)
                        goto err;
        }
@@ -1778,7 +1784,8 @@ out:
        return;
 err:
        set_btree_node_noevict(b);
-       bch2_fs_fatal_error(c, "fatal error writing btree node");
+       if (!bch2_err_matches(ret, EROFS))
+               bch2_fs_fatal_error(c, "fatal error writing btree node: %s", bch2_err_str(ret));
        goto out;
 }
 
@@ -2016,9 +2023,7 @@ do_write:
        BUG_ON(BSET_BIG_ENDIAN(i) != CPU_BIG_ENDIAN);
        BUG_ON(i->seq != b->data->keys.seq);
 
-       i->version = c->sb.version < bcachefs_metadata_version_bkey_renumber
-               ? cpu_to_le16(BCH_BSET_VERSION_OLD)
-               : cpu_to_le16(c->sb.version);
+       i->version = cpu_to_le16(c->sb.version);
        SET_BSET_OFFSET(i, b->written);
        SET_BSET_CSUM_TYPE(i, bch2_meta_checksum_type(c));
 
@@ -2078,7 +2083,7 @@ do_write:
        wbio = container_of(bio_alloc_bioset(NULL,
                                buf_pages(data, sectors_to_write << 9),
                                REQ_OP_WRITE|REQ_META,
-                               GFP_NOIO,
+                               GFP_NOFS,
                                &c->btree_bio),
                            struct btree_write_bio, wbio.bio);
        wbio_init(&wbio->wbio.bio);
@@ -2231,7 +2236,7 @@ bool bch2_btree_flush_all_writes(struct bch_fs *c)
        return __bch2_btree_flush_all(c, BTREE_NODE_write_in_flight);
 }
 
-const char * const bch2_btree_write_types[] = {
+static const char * const bch2_btree_write_types[] = {
 #define x(t, n) [n] = #t,
        BCH_BTREE_WRITE_TYPES()
        NULL