Skip to contentSkip to conversation

xfs_db rdump: papercut fixes

PATCH In review Alexander Monakov 2 participants 8 messages Nov 12, 2025 – Nov 20, 2025

lore
Share & tools
lore
#0 lore raw

cover xfs_db rdump: papercut fixes

Hello,

I've been using the new 'rdump' command of xfs_db for manual recovery of a substantially damaged filesystem. I'd like to propose two patches that would have made that work a bit easier.

I'd also like to suggest to remove the one-argument form of rdump that dumps from root. I'm honestly unsure what it's for, considering that 'rdump / dest' is also supposed to work.

Alexander Monakov (2):
xfs_db rdump: remove sole_path logic
xfs_db: use push_cur_and_set_type more

 db/namei.c        |  2 +-
 db/rdump.c        | 21 +++------------------
 man/man8/xfs_db.8 |  8 +-------
 3 files changed, 5 insertions(+), 26 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/2 xfs_db rdump: remove sole_path logic

Eliminate special handling of the case where rdump'ing one directory does not create the corresponding directory in the destination, but instead modifies the destination's attributes and creates children alongside the pre-existing children.

This can be a trap for the unwary (the effect on attributes can be particularly surprising and non-trivial to undo), and, in general, fewer special cases in such a low-level tool should be desirable.

---
 db/rdump.c        | 19 ++-----------------
 man/man8/xfs_db.8 |  8 +-------
 2 files changed, 3 insertions(+), 24 deletions(-)
db/rdump.c +2 -17
index 9ff83355..73295dbe 100644
@@ -852,7 +852,6 @@ rdump_file(
 static int
 rdump_path(
 	struct xfs_mount	*mp,
-	bool			sole_path,
 	const char		*path,
 	const struct destdir	*destdir)
 {
@@ -890,20 +889,6 @@ rdump_path(
 			dbprintf(_("%s: %s\n"), path, strerror(ret));
 			return 1;
 		}
-
-		if (sole_path) {
-			struct xfs_dinode	*dip = iocur_top->data;
-
-			/*
-			 * If this is the only path to copy out and it's a dir,
-			 * then we can copy the children directly into the
-			 * target.
-			 */
-			if (S_ISDIR(be16_to_cpu(dip->di_mode))) {
-				pbuf->len = 0;
-				pbuf->path[0] = 0;
-			}
-		}
 	} else {
 		set_cur_inode(mp->m_sb.sb_rootino);
 	}
@@ -980,7 +965,7 @@ rdump_f(
 	if (optind == argc - 1) {
 		/* no dirs given, just do the whole fs */
 		push_cur();
-		ret = rdump_path(mp, false, "", &destdir);
+		ret = rdump_path(mp, "", &destdir);
 		pop_cur();
 		if (ret)
 			exitcode = 1;
@@ -996,7 +981,7 @@ rdump_f(
 		argv[i][len] = 0;
 
 		push_cur();
-		ret = rdump_path(mp, argc == optind + 2, argv[i], &destdir);
+		ret = rdump_path(mp, argv[i], &destdir);
 		pop_cur();
 
 		if (ret) {
man/man8/xfs_db.8 +1 -7
index 1e85aebb..920b2b3e 100644
@@ -1147,13 +1147,7 @@ the filesystem as possible.
 If zero
 .B paths
 are specified, the entire filesystem is dumped.
-If only one
-.B path
-is specified and it is a directory, the children of that directory will be
-copied directly to the destination.
-If multiple
-.B paths
-are specified, each file is copied into the directory as a new child.
+Otherwise, each entry is copied into the destination as a new child.
 
 If possible, sparse holes, xfs file attributes, and extended attributes will be
 preserved.
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH 1/2] xfs_db rdump: remove sole_path logic

Quoted 4 lines · Alexander Monakov

Eliminate special handling of the case where rdump'ing one directory does not create the corresponding directory in the destination, but instead modifies the destination's attributes and creates children alongside the pre-existing children.

It sounds like what happened is that you ran rdump with a non-empty destdir, only to have rdump mutate the existing children in that directory. Is that correct?

If so, then I think what you really wanted was for rdump to check for that and error out, unless explicit --overwrite permission had been granted. Because...

Quoted 3 lines

This can be a trap for the unwary (the effect on attributes can be particularly surprising and non-trivial to undo), and, in general, fewer special cases in such a low-level tool should be desirable.

...I use this "special case" and don't understand why you decided that removing functionality was the solution here. This is a filesystem debugger, there are weird functions and sharp edges everywhere.

--D

Quoted 80 lines
---
 db/rdump.c        | 19 ++-----------------
 man/man8/xfs_db.8 |  8 +-------
 2 files changed, 3 insertions(+), 24 deletions(-)
db/rdump.c +2 -17
index 9ff83355..73295dbe 100644
@@ -852,7 +852,6 @@ rdump_file(
 static int
 rdump_path(
 	struct xfs_mount	*mp,
-	bool			sole_path,
 	const char		*path,
 	const struct destdir	*destdir)
 {
@@ -890,20 +889,6 @@ rdump_path(
 			dbprintf(_("%s: %s\n"), path, strerror(ret));
 			return 1;
 		}
-
-		if (sole_path) {
-			struct xfs_dinode	*dip = iocur_top->data;
-
-			/*
-			 * If this is the only path to copy out and it's a dir,
-			 * then we can copy the children directly into the
-			 * target.
-			 */
-			if (S_ISDIR(be16_to_cpu(dip->di_mode))) {
-				pbuf->len = 0;
-				pbuf->path[0] = 0;
-			}
-		}
 	} else {
 		set_cur_inode(mp->m_sb.sb_rootino);
 	}
@@ -980,7 +965,7 @@ rdump_f(
 	if (optind == argc - 1) {
 		/* no dirs given, just do the whole fs */
 		push_cur();
-		ret = rdump_path(mp, false, "", &destdir);
+		ret = rdump_path(mp, "", &destdir);
 		pop_cur();
 		if (ret)
 			exitcode = 1;
@@ -996,7 +981,7 @@ rdump_f(
 		argv[i][len] = 0;
 
 		push_cur();
-		ret = rdump_path(mp, argc == optind + 2, argv[i], &destdir);
+		ret = rdump_path(mp, argv[i], &destdir);
 		pop_cur();
 
 		if (ret) {
man/man8/xfs_db.8 +1 -7
index 1e85aebb..920b2b3e 100644
@@ -1147,13 +1147,7 @@ the filesystem as possible.
 If zero
 .B paths
 are specified, the entire filesystem is dumped.
-If only one
-.B path
-is specified and it is a directory, the children of that directory will be
-copied directly to the destination.
-If multiple
-.B paths
-are specified, each file is copied into the directory as a new child.
+Otherwise, each entry is copied into the destination as a new child.
 
 If possible, sparse holes, xfs file attributes, and extended attributes will be
 preserved.
Signature · 1 line
2.51.0
#3 lore raw

Re: [PATCH 1/2] xfs_db rdump: remove sole_path logic

Quoted 9 lines · Darrick J. Wong
Quoted 4 lines · Alexander Monakov

Eliminate special handling of the case where rdump'ing one directory does not create the corresponding directory in the destination, but instead modifies the destination's attributes and creates children alongside the pre-existing children.

It sounds like what happened is that you ran rdump with a non-empty destdir, only to have rdump mutate the existing children in that directory. Is that correct?

Not really (what you describe would have been even worse).

In my case, I was rdump'ing into a directory that had rtinherit set, and rdump undid that (generally speaking, all attributes of the destdir were overwritten, not just rtinherit).

Quoted 3 lines

If so, then I think what you really wanted was for rdump to check for that and error out, unless explicit --overwrite permission had been granted. Because...

(I would still hit the above issue with attributes)

Quoted 7 lines
Quoted 3 lines

This can be a trap for the unwary (the effect on attributes can be particularly surprising and non-trivial to undo), and, in general, fewer special cases in such a low-level tool should be desirable.

...I use this "special case" and don't understand why you decided that removing functionality was the solution here. This is a filesystem debugger, there are weird functions and sharp edges everywhere.

Shouldn't we strive to have fewer surprises? For instance, if there was an explicit flag for that, there wouldn't be an issue.

Out of curiosity, what is your use-case for this?

Thank you.
Alexander

#4 lore raw

Re: [PATCH 1/2] xfs_db rdump: remove sole_path logic

Quoted 29 lines · Alexander Monakov
Quoted 9 lines · Darrick J. Wong
Quoted 4 lines · Alexander Monakov

Eliminate special handling of the case where rdump'ing one directory does not create the corresponding directory in the destination, but instead modifies the destination's attributes and creates children alongside the pre-existing children.

It sounds like what happened is that you ran rdump with a non-empty destdir, only to have rdump mutate the existing children in that directory. Is that correct?

Not really (what you describe would have been even worse).

In my case, I was rdump'ing into a directory that had rtinherit set, and rdump undid that (generally speaking, all attributes of the destdir were overwritten, not just rtinherit).

Quoted 3 lines

If so, then I think what you really wanted was for rdump to check for that and error out, unless explicit --overwrite permission had been granted. Because...

(I would still hit the above issue with attributes)

Quoted 4 lines
Quoted 3 lines

This can be a trap for the unwary (the effect on attributes can be particularly surprising and non-trivial to undo), and, in general, fewer special cases in such a low-level tool should be desirable.

Quoted 8 lines
Quoted 3 lines

...I use this "special case" and don't understand why you decided that removing functionality was the solution here. This is a filesystem debugger, there are weird functions and sharp edges everywhere.

Shouldn't we strive to have fewer surprises? For instance, if there was an explicit flag for that, there wouldn't be an issue.

Out of curiosity, what is your use-case for this?

Copying build artifacts out of a directory on an xfs filesystem into some other directory, e.g.

# xfs_db -c 'rdump /rootfs /srv/containers/whatever' /dev/sda1

Without then having to do:

# mv /srv/containers/whatever/rootfs/* /srv/containers/whatever/
# rmdir /srv/containers/whatever/rootfs

I'd be willing to accept more rsync-like behavior where a trailing slash means "copy children directly into the target dir" and no trailing slash means "create new child subdir in target dir and copy stuff into that".

IOWs,

xfs_db> rdump /rootfs /srv/containers/whatever

Would always create /srv/containers/whatever/rootfs and copy the children of /rootfs into that path, but

xfs_db> rdump /rootfs/ /srv/containers/whatever/boot

Would copy the children of /rootfs directly into
/srv/containers/whatever/boot.

--D

Quoted 3 lines

Thank you.
Alexander

#5 lore raw

PATCH 2/2 xfs_db: use push_cur_and_set_type more

In reply to Alexander Monakov

Since push_cur unsets cur_typ, 'ls' and 'rdump' with paths relative to current address do not work with a mysterious diagnostic (claiming that the supplied name is not a directory). Use push_cur_and_set_type instead.

---
 db/namei.c | 2 +-
 db/rdump.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
db/namei.c +1 -1
index 1d9581c3..4149503c 100644
@@ -629,7 +629,7 @@ ls_f(
 	}
 
 	for (c = optind; c < argc; c++) {
-		push_cur();
+		push_cur_and_set_type();
 
 		error = path_walk(rootino, argv[c]);
 		if (error)
db/rdump.c +1 -1
index 73295dbe..146f829b 100644
@@ -980,7 +980,7 @@ rdump_f(
 			len--;
 		argv[i][len] = 0;
 
-		push_cur();
+		push_cur_and_set_type();
 		ret = rdump_path(mp, argv[i], &destdir);
 		pop_cur();
 
Signature · 1 line
2.51.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] xfs_db: use push_cur_and_set_type more

Quoted 4 lines · Alexander Monakov

Since push_cur unsets cur_typ, 'ls' and 'rdump' with paths relative to current address do not work with a mysterious diagnostic (claiming that the supplied name is not a directory). Use push_cur_and_set_type instead.

IOWs, you're trying to fix this, correct?

# xfs_db /dev/sdf
xfs_db> ls /
/:
8          128                directory      0x0000002e   1 . (good)
10         128                directory      0x0000172e   2 .. (good)
314        50337826           directory      0x0a152956   5 PPTRS (good)
xfs_db> ls ./PPTRS
./PPTRS: Not a directory

If so, then

--D

Quoted 36 lines
---
 db/namei.c | 2 +-
 db/rdump.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
db/namei.c +1 -1
index 1d9581c3..4149503c 100644
@@ -629,7 +629,7 @@ ls_f(
 	}
 
 	for (c = optind; c < argc; c++) {
-		push_cur();
+		push_cur_and_set_type();
 
 		error = path_walk(rootino, argv[c]);
 		if (error)
db/rdump.c +1 -1
index 73295dbe..146f829b 100644
@@ -980,7 +980,7 @@ rdump_f(
 			len--;
 		argv[i][len] = 0;
 
-		push_cur();
+		push_cur_and_set_type();
 		ret = rdump_path(mp, argv[i], &destdir);
 		pop_cur();
 
Signature · 1 line
2.51.0
#7 lore raw

Re: [PATCH 2/2] xfs_db: use push_cur_and_set_type more

Quoted 7 lines · Darrick J. Wong
Quoted 4 lines · Alexander Monakov

Since push_cur unsets cur_typ, 'ls' and 'rdump' with paths relative to current address do not work with a mysterious diagnostic (claiming that the supplied name is not a directory). Use push_cur_and_set_type instead.

IOWs, you're trying to fix this, correct?

Mostly correct, but with 'path /' in place of initial 'ls /' so that current address is set to the root inode.

Quoted 11 lines
# xfs_db /dev/sdf
xfs_db> ls /
/:
8          128                directory      0x0000002e   1 . (good)
10         128                directory      0x0000172e   2 .. (good)
314        50337826           directory      0x0a152956   5 PPTRS (good)
xfs_db> ls ./PPTRS
./PPTRS: Not a directory

If so, then

Thanks.
Alexander