]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal_io.c
Update bcachefs sources to 5d0a6c2b32f1 bcachefs: check_directory_structure() can...
[bcachefs-tools-debian] / libbcachefs / journal_io.c
index 4ec5d5d38abca8d85d8bc023f3f5eea1dc751415..65e58edb975a0259de3c6918dde1c9501c2c2da4 100644 (file)
@@ -548,6 +548,7 @@ static int journal_entry_data_usage_validate(struct bch_fs *c,
        struct jset_entry_data_usage *u =
                container_of(entry, struct jset_entry_data_usage, entry);
        unsigned bytes = jset_u64s(le16_to_cpu(entry->u64s)) * sizeof(u64);
+       struct printbuf err = PRINTBUF;
        int ret = 0;
 
        if (journal_entry_err_on(bytes < sizeof(*u) ||
@@ -556,10 +557,19 @@ static int journal_entry_data_usage_validate(struct bch_fs *c,
                                 journal_entry_data_usage_bad_size,
                                 "invalid journal entry usage: bad size")) {
                journal_entry_null_range(entry, vstruct_next(entry));
-               return ret;
+               goto out;
        }
 
+       if (journal_entry_err_on(bch2_replicas_entry_validate(&u->r, c->disk_sb.sb, &err),
+                                c, version, jset, entry,
+                                journal_entry_data_usage_bad_size,
+                                "invalid journal entry usage: %s", err.buf)) {
+               journal_entry_null_range(entry, vstruct_next(entry));
+               goto out;
+       }
+out:
 fsck_err:
+       printbuf_exit(&err);
        return ret;
 }
 
@@ -676,8 +686,6 @@ static void journal_entry_dev_usage_to_text(struct printbuf *out, struct bch_fs
                       le64_to_cpu(u->d[i].sectors),
                       le64_to_cpu(u->d[i].fragmented));
        }
-
-       prt_printf(out, " buckets_ec: %llu", le64_to_cpu(u->buckets_ec));
 }
 
 static int journal_entry_log_validate(struct bch_fs *c,
@@ -773,7 +781,6 @@ void bch2_journal_entry_to_text(struct printbuf *out, struct bch_fs *c,
 static int jset_validate_entries(struct bch_fs *c, struct jset *jset,
                                 enum bkey_invalid_flags flags)
 {
-       struct jset_entry *entry;
        unsigned version = le32_to_cpu(jset->version);
        int ret = 0;
 
@@ -1161,8 +1168,6 @@ int bch2_journal_read(struct bch_fs *c,
        struct journal_list jlist;
        struct journal_replay *i, **_i, *prev = NULL;
        struct genradix_iter radix_iter;
-       struct bch_dev *ca;
-       unsigned iter;
        struct printbuf buf = PRINTBUF;
        bool degraded = false, last_write_torn = false;
        u64 seq;
@@ -1173,7 +1178,7 @@ int bch2_journal_read(struct bch_fs *c,
        jlist.last_seq = 0;
        jlist.ret = 0;
 
-       for_each_member_device(ca, c, iter) {
+       for_each_member_device(c, ca) {
                if (!c->opts.fsck &&
                    !(bch2_dev_has_data(c, ca) & (1 << BCH_DATA_journal)))
                        continue;
@@ -1339,7 +1344,7 @@ int bch2_journal_read(struct bch_fs *c,
                        continue;
 
                for (ptr = 0; ptr < i->nr_ptrs; ptr++) {
-                       ca = bch_dev_bkey_exists(c, i->ptrs[ptr].dev);
+                       struct bch_dev *ca = bch_dev_bkey_exists(c, i->ptrs[ptr].dev);
 
                        if (!i->ptrs[ptr].csum_good)
                                bch_err_dev_offset(ca, i->ptrs[ptr].sector,
@@ -1715,7 +1720,7 @@ static CLOSURE_CALLBACK(do_journal_write)
 static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
 {
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
-       struct jset_entry *start, *end, *i, *next, *prev = NULL;
+       struct jset_entry *start, *end;
        struct jset *jset = w->data;
        struct journal_keys_to_wb wb = { NULL };
        unsigned sectors, bytes, u64s;
@@ -1732,7 +1737,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
         * If we wanted to be really fancy here, we could sort all the keys in
         * the jset and drop keys that were overwritten - probably not worth it:
         */
-       vstruct_for_each_safe(jset, i, next) {
+       vstruct_for_each(jset, i) {
                unsigned u64s = le16_to_cpu(i->u64s);
 
                /* Empty entry: */
@@ -1772,34 +1777,12 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
                        i->type = BCH_JSET_ENTRY_btree_keys;
                        break;
                }
-
-               /* Can we merge with previous entry? */
-               if (prev &&
-                   i->btree_id == prev->btree_id &&
-                   i->level    == prev->level &&
-                   i->type     == prev->type &&
-                   i->type     == BCH_JSET_ENTRY_btree_keys &&
-                   le16_to_cpu(prev->u64s) + u64s <= U16_MAX) {
-                       memmove_u64s_down(vstruct_next(prev),
-                                         i->_data,
-                                         u64s);
-                       le16_add_cpu(&prev->u64s, u64s);
-                       continue;
-               }
-
-               /* Couldn't merge, move i into new position (after prev): */
-               prev = prev ? vstruct_next(prev) : jset->start;
-               if (i != prev)
-                       memmove_u64s_down(prev, i, jset_u64s(u64s));
        }
 
        if (wb.wb)
                bch2_journal_keys_to_write_buffer_end(c, &wb);
        w->need_flush_to_write_buffer = false;
 
-       prev = prev ? vstruct_next(prev) : jset->start;
-       jset->u64s = cpu_to_le32((u64 *) prev - jset->_data);
-
        start = end = vstruct_last(jset);
 
        end     = bch2_btree_roots_to_journal_entries(c, end, btree_roots_have);
@@ -1905,12 +1888,11 @@ CLOSURE_CALLBACK(bch2_journal_write)
 {
        closure_type(j, struct journal, io);
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
-       struct bch_dev *ca;
        struct journal_buf *w = journal_last_unwritten_buf(j);
        struct bch_replicas_padded replicas;
        struct bio *bio;
        struct printbuf journal_debug_buf = PRINTBUF;
-       unsigned i, nr_rw_members = 0;
+       unsigned nr_rw_members = 0;
        int ret;
 
        BUG_ON(BCH_SB_CLEAN(c->disk_sb.sb));
@@ -1970,7 +1952,7 @@ CLOSURE_CALLBACK(bch2_journal_write)
        if (c->opts.nochanges)
                goto no_io;
 
-       for_each_rw_member(ca, c, i)
+       for_each_rw_member(c, ca)
                nr_rw_members++;
 
        if (nr_rw_members > 1)
@@ -1987,7 +1969,7 @@ CLOSURE_CALLBACK(bch2_journal_write)
                goto err;
 
        if (!JSET_NO_FLUSH(w->data) && w->separate_flush) {
-               for_each_rw_member(ca, c, i) {
+               for_each_rw_member(c, ca) {
                        percpu_ref_get(&ca->io_ref);
 
                        bio = ca->journal.bio;