Skip to contentSkip to conversation

xfsrestore: suggest -x rather than assert for false roots

PATCH Superseded Donald Douwsma 3 participants 3 messages Jun 23, 2023 – Jun 29, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsrestore: suggest -x rather than assert for false roots

If we're going to have a fix for false root problems its a good idea to let people know that there's a way to recover, error out with a useful message that mentions the -x option rather than just assert.

Before

xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: tree.c:757: tree_begindir: Assertion `ino != persp->p_rootino || hardh == persp->p_rooth' failed. Aborted

After

xfsrestore: ERROR: tree.c:791: tree_begindir: Assertion ino != persp->p_rootino || hardh == persp->p_rooth failed.
xfsrestore: ERROR: False root detected. Recovery may be possible using the -x option
Aborted

Fixes d7cba74 ("xfsrestore: fix rootdir due to xfsdump bulkstat misuse")
---
 restore/tree.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
restore/tree.c +11 -2
index bfa07fe..0b65d0f 100644
@@ -783,8 +783,17 @@ tree_begindir(filehdr_t *fhdrp, dah_t *dahp)
 	/* lookup head of hardlink list
 	 */
 	hardh = link_hardh(ino, gen);
-	if (need_fixrootdir == BOOL_FALSE)
-		assert(ino != persp->p_rootino || hardh == persp->p_rooth);
+	if (need_fixrootdir == BOOL_FALSE
+		&& !(ino != persp->p_rootino || hardh == persp->p_rooth)) {
+		mlog(MLOG_ERROR | MLOG_TREE, 
+			"%s:%d: %s: Assertion "
+			"`ino != persp->p_rootino || hardh == persp->p_rooth` failed.\n",
+			__FILE__, __LINE__, __FUNCTION__);
+		mlog(MLOG_ERROR | MLOG_TREE, _(
+			"False root detected. "
+			"Recovery may be possible using the `-x` option\n"));
+		return NH_NULL;
+	};
 
 	/* already present
 	 */
Signature · 1 line
2.39.3
#1 lore raw
Quoted 28 lines · Donald Douwsma

If we're going to have a fix for false root problems its a good idea to let people know that there's a way to recover, error out with a useful message that mentions the -x option rather than just assert.

Before

xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: tree.c:757: tree_begindir: Assertion `ino != persp->p_rootino || hardh == persp->p_rooth' failed. Aborted

After

xfsrestore: ERROR: tree.c:791: tree_begindir: Assertion ino != persp->p_rootino || hardh == persp->p_rooth failed.
xfsrestore: ERROR: False root detected. Recovery may be possible using the -x option
Aborted

Fixes d7cba74 ("xfsrestore: fix rootdir due to xfsdump bulkstat misuse")
---
  restore/tree.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
restore/tree.c +0 -0
index bfa07fe..0b65d0f 100644

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 788

Quoted 8 lines
restore/tree.c +3 -2
@@ -783,8 +783,17 @@ tree_begindir(filehdr_t *fhdrp, dah_t *dahp)
  	/* lookup head of hardlink list
  	 */
  	hardh = link_hardh(ino, gen);
-	if (need_fixrootdir == BOOL_FALSE)
-		assert(ino != persp->p_rootino || hardh == persp->p_rooth);
+	if (need_fixrootdir == BOOL_FALSE
+		&& !(ino != persp->p_rootino || hardh == persp->p_rooth)) {
+		mlog(MLOG_ERROR | MLOG_TREE,

Trailing white space

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 796

Quoted 8 lines
restore/tree.c +8 -0
+			"%s:%d: %s: Assertion "
+			"`ino != persp->p_rootino || hardh == persp->p_rooth` failed.\n",
+			__FILE__, __LINE__, __FUNCTION__);
+		mlog(MLOG_ERROR | MLOG_TREE, _(
+			"False root detected. "
+			"Recovery may be possible using the `-x` option\n"));
+		return NH_NULL;
+	};

Extra semicolon

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 799

Quoted 2 lines
restore/tree.c +0 -0
  	/* already present
  	 */

Otherwise looks good to me, applies and builds.

#2 lore raw
In reply to Donald Douwsma
Quoted 28 lines · Donald Douwsma

If we're going to have a fix for false root problems its a good idea to let people know that there's a way to recover, error out with a useful message that mentions the -x option rather than just assert.

Before

xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: tree.c:757: tree_begindir: Assertion `ino != persp->p_rootino || hardh == persp->p_rooth' failed. Aborted

After

xfsrestore: ERROR: tree.c:791: tree_begindir: Assertion ino != persp->p_rootino || hardh == persp->p_rooth failed.
xfsrestore: ERROR: False root detected. Recovery may be possible using the -x option
Aborted

Fixes d7cba74 ("xfsrestore: fix rootdir due to xfsdump bulkstat misuse")
---
 restore/tree.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
restore/tree.c +0 -0
index bfa07fe..0b65d0f 100644

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 787

Quoted 7 lines
restore/tree.c +2 -2
@@ -783,8 +783,17 @@ tree_begindir(filehdr_t *fhdrp, dah_t *dahp)
 	/* lookup head of hardlink list
 	 */
 	hardh = link_hardh(ino, gen);
-	if (need_fixrootdir == BOOL_FALSE)
-		assert(ino != persp->p_rootino || hardh == persp->p_rooth);
+	if (need_fixrootdir == BOOL_FALSE
+		&& !(ino != persp->p_rootino || hardh == persp->p_rooth)) {

Usually we put the && operator on the line above. But ignore that comment if that's actually the predominant style in xfsrestore.

	if (need_fixrootdir == BOOL_FALSE &&
	    !(ino != persp->p_rootino || hardh == persp->p_rooth)) {

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 788

Quoted 1 line
restore/tree.c +1 -0
+		mlog(MLOG_ERROR | MLOG_TREE, 

Trailing space.

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 790

Quoted 2 lines
restore/tree.c +2 -0
+			"%s:%d: %s: Assertion "
+			"`ino != persp->p_rootino || hardh == persp->p_rooth` failed.\n",

Might be nice to put the entire string on one line for greppability?

mlog(MLOG_ERROR | MLOG_TREE,
"%s:%d: %s: Assertion ino != persp->p_rootino || hardh == persp->p_rooth failed.\n",

restore/tree.c tree_begindir(filehdr_t *fhdrp, dah_t *dahp) · line 794

Quoted 4 lines
restore/tree.c +4 -0
+			__FILE__, __LINE__, __FUNCTION__);
+		mlog(MLOG_ERROR | MLOG_TREE, _(
+			"False root detected. "
+			"Recovery may be possible using the `-x` option\n"));

Same here.

Otherwise this looks like a good improvement.

--D

Quoted 8 lines
restore/tree.c +2 -0
+		return NH_NULL;
+	};
 
 	/* already present
 	 */
Signature · 1 line
2.39.3