public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Donald Douwsma <ddouwsma@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: Donald Douwsma <ddouwsma@redhat.com>
Subject: [PATCH 5/5] xfsrestore: assert suppression workaround
Date: Tue, 24 Feb 2026 18:17:12 +1100	[thread overview]
Message-ID: <20260224071712.1014075-6-ddouwsma@redhat.com> (raw)
In-Reply-To: <20260224071712.1014075-1-ddouwsma@redhat.com>

Allow users to workaround assertions encountered during a restore by
suppressing them using 'xfsrestore -z ...`.

This is not the right approach for ongoing upstream development, but it
may be useful as a workaround for downstream maintenance releases built
without NDEBUG, even then I'm hesitant.

Signed-off-by: Donald Douwsma <ddouwsma@redhat.com>
---
 include/config.h.in      |  4 ++++
 man/man8/xfsrestore.8    |  4 ++++
 restore/Makefile         |  6 ++++--
 restore/content.c        |  5 ++++-
 restore/getopt.h         |  4 ++--
 restore/restore_assert.c | 39 +++++++++++++++++++++++++++++++++++++++
 restore/restore_assert.h | 18 ++++++++++++++++++
 7 files changed, 75 insertions(+), 5 deletions(-)
 create mode 100644 restore/restore_assert.c
 create mode 100644 restore/restore_assert.h

diff --git a/include/config.h.in b/include/config.h.in
index 3b35d83..9cc6628 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -50,4 +50,8 @@ typedef unsigned short umode_t;
 #define NBBY 8
 #endif
 
+#if !defined(NDEBUG) && defined(RESTORE)
+#include "../restore/restore_assert.h"
+#endif
+
 #endif	/* __CONFIG_H__ */
diff --git a/man/man8/xfsrestore.8 b/man/man8/xfsrestore.8
index df7dde0..84e1b12 100644
--- a/man/man8/xfsrestore.8
+++ b/man/man8/xfsrestore.8
@@ -254,6 +254,10 @@ the dump without this option.
 In the cumulative mode, this option is required only for a base (level 0)
 dump. You no longer need this option for level 1+ dumps.
 .TP 5
+.B \-z
+If xfsrestore fails due to an assertion this option can be used to ignore it for
+the purpose of debugging or to recover data from a problematic archive.
+.TP 5
 \f3\-v\f1 \f2verbosity\f1
 .\" set inter-paragraph distance to 0
 .PD 0
diff --git a/restore/Makefile b/restore/Makefile
index ac3f8c8..5a5ee62 100644
--- a/restore/Makefile
+++ b/restore/Makefile
@@ -76,7 +76,8 @@ LOCALS = \
 	namreg.c \
 	node.c \
 	tree.c \
-	win.c
+	win.c \
+	restore_assert.c
 
 LOCALINCL = \
 	bag.h \
@@ -87,7 +88,8 @@ LOCALINCL = \
 	namreg.h \
 	node.h \
 	tree.h \
-	win.h
+	win.h \
+	restore_assert.h
 
 LTCOMMAND = xfsrestore
 
diff --git a/restore/content.c b/restore/content.c
index b91e5f0..71de87a 100644
--- a/restore/content.c
+++ b/restore/content.c
@@ -864,7 +864,7 @@ bool_t restore_rootdir_permissions;
 bool_t need_fixrootdir;
 char *media_change_alert_program = NULL;
 size_t perssz;
-
+int workaround_assert;
 
 /* definition of locally defined static variables *****************************/
 
@@ -1191,6 +1191,9 @@ content_init(int argc, char *argv[], size64_t vmsz)
 		case GETOPT_FIXROOTDIR:
 			need_fixrootdir = BOOL_TRUE;
 			break;
+		case GETOPT_WORKAROUND:
+			workaround_assert = 1;
+			break;
 		}
 	}
 
diff --git a/restore/getopt.h b/restore/getopt.h
index b0c0c7d..4c4c2b2 100644
--- a/restore/getopt.h
+++ b/restore/getopt.h
@@ -26,7 +26,7 @@
  * purpose is to contain that command string.
  */
 
-#define GETOPT_CMDSTRING	"a:b:c:def:himn:op:qrs:tv:wxABCDEFG:H:I:JKL:M:NO:PQRS:TUVWX:Y:"
+#define GETOPT_CMDSTRING	"a:b:c:def:himn:op:qrs:tv:wxzABCDEFG:H:I:JKL:M:NO:PQRS:TUVWX:Y:"
 
 #define GETOPT_WORKSPACE	'a'	/* workspace dir (content.c) */
 #define GETOPT_BLOCKSIZE        'b'     /* blocksize for rmt */
@@ -53,7 +53,7 @@
 #define	GETOPT_SMALLWINDOW	'w'	/* use a small window for dir entries */
 #define GETOPT_FIXROOTDIR	'x'	/* try to fix rootdir due to bulkstat misuse */
 /*				'y' */
-/*				'z' */
+#define GETOPT_WORKAROUND	'z'	/* enable workaroundz */
 #define	GETOPT_NOEXTATTR	'A'	/* do not restore ext. file attr. */
 #define GETOPT_ROOTPERM		'B'	/* restore ownership and permissions for root directory */
 #define GETOPT_RECCHKSUM	'C'	/* use record checksums */
diff --git a/restore/restore_assert.c b/restore/restore_assert.c
new file mode 100644
index 0000000..e2f3054
--- /dev/null
+++ b/restore/restore_assert.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+
+#include "config.h"
+
+#include "mlog.h"
+
+/*
+ * Override glibc __assert_fail to allow users to optionally ignore assertions.
+ *
+ * We could optionally require a number of assertions to skip, allowing the user
+ * to consider each problem and continue only if a specified number is not
+ * exceeded
+ */
+
+extern int workaround_assert;
+
+void __xfsrestore_assert_fail(const char *__assertion, const char *__file,
+			      unsigned int __line, const char *__function)
+{
+	static int assert_count;
+	assert_count++;
+
+	mlog(MLOG_ERROR|MLOG_NOLOCK, _("%s:%d: %s: Assertion %s failed\n"),
+			__file, __line, __function, __assertion);
+
+	if(!workaround_assert) {
+		mlog(MLOG_ERROR|MLOG_NOLOCK, _("Recovery may be possible using the `-z` option\n"));
+		abort();
+	}
+}
+
+
+
diff --git a/restore/restore_assert.h b/restore/restore_assert.h
new file mode 100644
index 0000000..8eb22e6
--- /dev/null
+++ b/restore/restore_assert.h
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2024 Red Hat, Inc. All Rights Reserved.
+ */
+
+#ifndef _XFS_RESTORE_ASSERT_H_
+#define _XFS_RESTORE_ASSERT_H_
+
+#if defined(assert)
+#undef assert
+extern void __xfsrestore_assert_fail(const char *__assertion, const char *__file,
+				     unsigned int __line, const char *__function);
+#define assert(expr) \
+	((expr) ? (void)0 : \
+	__xfsrestore_assert_fail(#expr, __FILE__, __LINE__, __func__))
+#endif
+
+#endif /* _XFS_RESTORE_ASSERT_H_ */
-- 
2.47.3


  parent reply	other threads:[~2026-02-24  7:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-24  7:17 [PATCH 0/5] xfsdump, xfsprogs distro builds and DEBUG= Donald Douwsma
2026-02-24  7:17 ` [PATCH 1/5] xfsrestore: remove unused variable strctxp Donald Douwsma
2026-02-24  7:17 ` [PATCH 2/5] annotate variables only used for assert Donald Douwsma
2026-02-24  7:17 ` [PATCH 3/5] xfsrestore: include TREE_DEBUG all builds Donald Douwsma
2026-02-24  7:17 ` [PATCH 4/5] xfsrestore: remove failing assert from noref_elim_recurse Donald Douwsma
2026-03-23  3:01   ` Donald Douwsma
2026-02-24  7:17 ` Donald Douwsma [this message]
2026-03-13 13:12 ` [PATCH 0/5] xfsdump, xfsprogs distro builds and DEBUG= Andrey Albershteyn
2026-03-23  1:48   ` Donald Douwsma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260224071712.1014075-6-ddouwsma@redhat.com \
    --to=ddouwsma@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox