cmd_debug: Add -j for dumping entire journal

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-03-20 02:38:55 -04:00
parent 3765483ff0
commit e76dbf1abd

View File

@ -29,11 +29,13 @@ static void dump_usage(void)
"Options:\n"
" -o output Output qcow2 image(s)\n"
" -f Force; overwrite when needed\n"
" -j Dump entire journal, not just dirty entries\n"
" -h Display this help and exit\n"
"Report bugs to <linux-bcache@vger.kernel.org>");
}
static void dump_one_device(struct bch_fs *c, struct bch_dev *ca, int fd)
static void dump_one_device(struct bch_fs *c, struct bch_dev *ca, int fd,
bool entire_journal)
{
struct bch_sb *sb = ca->disk_sb.sb;
ranges data;
@ -53,7 +55,8 @@ static void dump_one_device(struct bch_fs *c, struct bch_dev *ca, int fd)
/* Journal: */
for (i = 0; i < ca->journal.nr; i++)
if (ca->journal.bucket_seq[i] >= c->journal.last_seq_ondisk) {
if (entire_journal ||
ca->journal.bucket_seq[i] >= c->journal.last_seq_ondisk) {
u64 bucket = ca->journal.buckets[i];
range_add(&data,
@ -116,7 +119,7 @@ int cmd_dump(int argc, char *argv[])
struct bch_dev *ca;
char *out = NULL;
unsigned i, nr_devices = 0;
bool force = false;
bool force = false, entire_journal = false;
int fd, opt;
opt_set(opts, nochanges, true);
@ -125,7 +128,7 @@ int cmd_dump(int argc, char *argv[])
opt_set(opts, errors, BCH_ON_ERROR_continue);
opt_set(opts, fix_errors, FSCK_OPT_NO);
while ((opt = getopt(argc, argv, "o:fvh")) != -1)
while ((opt = getopt(argc, argv, "o:fjvh")) != -1)
switch (opt) {
case 'o':
out = optarg;
@ -133,6 +136,9 @@ int cmd_dump(int argc, char *argv[])
case 'f':
force = true;
break;
case 'j':
entire_journal = true;
break;
case 'v':
opt_set(opts, verbose, true);
break;
@ -174,7 +180,7 @@ int cmd_dump(int argc, char *argv[])
fd = xopen(path, flags, 0600);
free(path);
dump_one_device(c, ca, fd);
dump_one_device(c, ca, fd, entire_journal);
close(fd);
}