aboutsummaryrefslogtreecommitdiffstats
path: root/tools-util.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-02-12 21:44:33 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-12 21:44:33 -0500
commit4697efb7a01affe650dbc9a4e81a8203d0316d96 (patch)
tree9f3c397dcf29fa2903f787609c3897568a9a52eb /tools-util.c
parente160e9b97986d908bce40ab40ee5d930453a3bf1 (diff)
downloadbcachefs-tools-4697efb7a01affe650dbc9a4e81a8203d0316d96.tar.gz
cmd_list_journal: Add filter options
Instead of having to use grep, this adds the ability to print out only transactions that update a particular key, or to filter out entirely keys except those updating certain btrees. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'tools-util.c')
-rw-r--r--tools-util.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/tools-util.c b/tools-util.c
index f29d2026..65835edf 100644
--- a/tools-util.c
+++ b/tools-util.c
@@ -607,19 +607,41 @@ int dev_mounted(char *dev)
struct bpos bpos_parse(char *buf)
{
- char *s = buf, *field;
+ char *orig = strdup(buf);
+ char *s = buf;
+
+ char *inode_s = strsep(&s, ":");
+ char *offset_s = strsep(&s, ":");
+ char *snapshot_s = strsep(&s, ":");
+
+ if (!inode_s || !offset_s || s)
+ die("invalid bpos %s", orig);
+ free(orig);
+
u64 inode_v = 0, offset_v = 0;
+ u32 snapshot_v = 0;
+ if (kstrtoull(inode_s, 10, &inode_v))
+ die("invalid bpos.inode %s", inode_s);
+
+ if (kstrtoull(offset_s, 10, &offset_v))
+ die("invalid bpos.offset %s", offset_s);
- if (!(field = strsep(&s, ":")) ||
- kstrtoull(field, 10, &inode_v))
- die("invalid bpos %s", buf);
+ if (snapshot_s &&
+ kstrtouint(snapshot_s, 10, &snapshot_v))
+ die("invalid bpos.snapshot %s", snapshot_s);
- if ((field = strsep(&s, ":")) &&
- kstrtoull(field, 10, &offset_v))
- die("invalid bpos %s", buf);
+ return (struct bpos) { .inode = inode_v, .offset = offset_v, .snapshot = snapshot_v };
+}
- if (s)
- die("invalid bpos %s", buf);
+struct bbpos bbpos_parse(char *buf)
+{
+ char *s = buf, *field;
+ struct bbpos ret;
- return (struct bpos) { .inode = inode_v, .offset = offset_v };
+ if (!(field = strsep(&s, ":")))
+ die("invalid bbpos %s", buf);
+
+ ret.btree = read_string_list_or_die(field, bch2_btree_ids, "btree id");
+ ret.pos = bpos_parse(s);
+ return ret;
}