]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - c_src/cmd_list_journal.c
Update upstream source from tag 'v1.6.3'
[bcachefs-tools-debian] / c_src / cmd_list_journal.c
similarity index 88%
rename from cmd_list_journal.c
rename to c_src/cmd_list_journal.c
index 70f7e669207ef9d3f7600f75586e7fb983479089..5884842ce130e1d0fa1e9bffbd6bc7c8d95c5169 100644 (file)
@@ -28,6 +28,7 @@ static void list_journal_usage(void)
             "  -a                                Read entire journal, not just dirty entries\n"
             "  -n, --nr-entries=nr               Number of journal entries to print, starting from the most recent\n"
             "  -t, --transaction-filter=bbpos    Filter transactions not updating <bbpos>\n"
+            "                                    Or entries not matching the range <bbpos-bbpos>\n"
             "  -k, --key-filter=btree            Filter keys not updating btree\n"
             "  -v, --verbose                     Verbose mode\n"
             "  -h, --help                        Display this help and exit\n"
@@ -50,30 +51,24 @@ static inline bool entry_is_transaction_start(struct jset_entry *entry)
        return entry->type == BCH_JSET_ENTRY_log && !entry->level;
 }
 
-typedef DARRAY(struct bbpos) d_bbpos;
+typedef DARRAY(struct bbpos_range) d_bbpos_range;
 typedef DARRAY(enum btree_id) d_btree_id;
 
-static bool bkey_matches_filter(d_bbpos filter, struct jset_entry *entry, struct bkey_i *k)
+static bool bkey_matches_filter(d_bbpos_range filter, struct jset_entry *entry, struct bkey_i *k)
 {
-       struct bbpos *i;
-
        darray_for_each(filter, i) {
-               if (i->btree != entry->btree_id)
-                       continue;
+               struct bbpos k_start    = BBPOS(entry->btree_id, bkey_start_pos(&k->k));
+               struct bbpos k_end      = BBPOS(entry->btree_id, k->k.p);
 
-               if (bkey_eq(i->pos, k->k.p))
-                       return true;
-
-               if (btree_node_type_is_extents(i->btree) &&
-                   bkey_ge(i->pos, bkey_start_pos(&k->k)) &&
-                   bkey_lt(i->pos, k->k.p))
+               if (bbpos_cmp(k_start, i->end) < 0 &&
+                   bbpos_cmp(k_end, i->start) > 0)
                        return true;
        }
        return false;
 }
 
 static bool entry_matches_transaction_filter(struct jset_entry *entry,
-                                            d_bbpos filter)
+                                            d_bbpos_range filter)
 {
        if (entry->type == BCH_JSET_ENTRY_btree_root ||
            entry->type == BCH_JSET_ENTRY_btree_keys ||
@@ -89,7 +84,7 @@ static bool entry_matches_transaction_filter(struct jset_entry *entry,
 }
 
 static bool should_print_transaction(struct jset_entry *entry, struct jset_entry *end,
-                                    d_bbpos filter)
+                                    d_bbpos_range filter)
 {
        if (!filter.nr)
                return true;
@@ -106,7 +101,6 @@ static bool should_print_transaction(struct jset_entry *entry, struct jset_entry
 static bool should_print_entry(struct jset_entry *entry, d_btree_id filter)
 {
        struct bkey_i *k;
-       enum btree_id *id;
 
        if (!filter.nr)
                return true;
@@ -125,7 +119,7 @@ static bool should_print_entry(struct jset_entry *entry, d_btree_id filter)
 }
 
 static void journal_entries_print(struct bch_fs *c, unsigned nr_entries,
-                                 d_bbpos transaction_filter,
+                                 d_bbpos_range transaction_filter,
                                  d_btree_id key_filter)
 {
        struct journal_replay *p, **_p;
@@ -140,7 +134,7 @@ static void journal_entries_print(struct bch_fs *c, unsigned nr_entries,
                if (le64_to_cpu(p->j.seq) + nr_entries < atomic64_read(&c->journal.seq))
                        continue;
 
-               bool blacklisted =
+               bool blacklisted = p->ignore ||
                        bch2_journal_seq_is_blacklisted(c,
                                        le64_to_cpu(p->j.seq), false);
 
@@ -225,12 +219,13 @@ int cmd_list_journal(int argc, char *argv[])
        };
        struct bch_opts opts = bch2_opts_empty();
        u32 nr_entries = U32_MAX;
-       d_bbpos         transaction_filter = { 0 };
+       d_bbpos_range   transaction_filter = { 0 };
        d_btree_id      key_filter = { 0 };
        int opt;
 
        opt_set(opts, nochanges,        true);
        opt_set(opts, norecovery,       true);
+       opt_set(opts, read_only,        true);
        opt_set(opts, degraded,         true);
        opt_set(opts, errors,           BCH_ON_ERROR_continue);
        opt_set(opts, fix_errors,       FSCK_FIX_yes);
@@ -249,7 +244,7 @@ int cmd_list_journal(int argc, char *argv[])
                        opt_set(opts, read_entire_journal, true);
                        break;
                case 't':
-                       darray_push(&transaction_filter, bbpos_parse(optarg));
+                       darray_push(&transaction_filter, bbpos_range_parse(optarg));
                        break;
                case 'k':
                        darray_push(&key_filter, read_string_list_or_die(optarg, __bch2_btree_ids, "btree id"));
@@ -266,7 +261,9 @@ int cmd_list_journal(int argc, char *argv[])
        if (!argc)
                die("Please supply device(s) to open");
 
-       struct bch_fs *c = bch2_fs_open(argv, argc, opts);
+       darray_str devs = get_or_split_cmdline_devs(argc, argv);
+
+       struct bch_fs *c = bch2_fs_open(devs.data, devs.nr, opts);
        if (IS_ERR(c))
                die("error opening %s: %s", argv[0], bch2_err_str(PTR_ERR(c)));