Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zdb -r to understand object ids as well #16307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9372,7 +9372,11 @@ main(int argc, char **argv)
if (argc != 3)
usage();
dump_opt['v'] = verbose;
error = dump_path(argv[0], argv[1], &object);
if (zdb_numeric(argv[1])) {
object = strtoull(argv[1], NULL, 0);
Comment on lines +9375 to +9376
Copy link
Member

@robn robn Jul 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a couple of problems here. zdb_numeric() and strtoull(base=0) permit different things, for example, zdb_numeric allows abc, but strtoull() does not, and will return 0.

The other more obvious problem is that this prevents a file name that zdb_numeric() returns true for, eg, there's no way to actually dump a file called abc.

Probably it needs a switch or magic value to say "interpret as number, not name". Maybe it's -N to match the "dataset is an objset id" case? Or maybe it can be a leading / on the filename, since that can't appear relative to the dataset? This seems to work reasonably well:

diff --git cmd/zdb/zdb.c cmd/zdb/zdb.c
index 3b8b67bce..9018eea58 100644
--- cmd/zdb/zdb.c
+++ cmd/zdb/zdb.c
@@ -9372,8 +9372,12 @@ main(int argc, char **argv)
 		if (argc != 3)
 			usage();
 		dump_opt['v'] = verbose;
-		if (zdb_numeric(argv[1])) {
-			object = strtoull(argv[1], NULL, 0);
+		if (argv[1][0] == '/') {
+			errno = 0;
+			object = strtoull(&(argv[1])[1], NULL, 0);
+			error = errno;
+			if (error == 0 && object == 0)
+				error = EINVAL;
 		} else {
 			error = dump_path(argv[0], argv[1], &object);
 		}

Absent that, maybe trying a number if dump_path() returns ENOENT? It has the reverse problem in that you can't dump by object number if you have a file named that, so maybe it's not useful.

} else {
error = dump_path(argv[0], argv[1], &object);
}
if (error != 0)
fatal("internal error: %s", strerror(error));
}
Expand Down
Loading