cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [RFC PATCH] fsck.gfs2: Fail on LVM PV detection
Date: Tue,  6 Jun 2023 11:52:14 +0100	[thread overview]
Message-ID: <20230606105214.50569-1-anprice@redhat.com> (raw)

If fsck.gfs2 is run against an LVM PV it will try its best to repair it
as a gfs2 fs. This is unlikely the best course of action as it's more
likely that the user executed fsck.gfs2 against the PV after stopping
the cluster (including the LVM activation resources).

In this situation other fscks try to look up backup superblocks before
failing but gfs2 does not keep backup superblocks so the safest thing to
do is fail with an operational error code when an LVM PV is detected.

A test is included that restores a PV signature to the test volume
before attempting to run fsck.gfs2 on it.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/fsck/Makefile.am  |  5 ++++-
 gfs2/fsck/initialize.c | 30 ++++++++++++++++++++++++++++++
 tests/Makefile.am      |  3 ++-
 tests/atlocal.in       |  1 +
 tests/fsck.at          |  7 +++++++
 tests/pv_sig.xxd       | 12 ++++++++++++
 6 files changed, 56 insertions(+), 2 deletions(-)
 create mode 100644 tests/pv_sig.xxd

diff --git a/gfs2/fsck/Makefile.am b/gfs2/fsck/Makefile.am
index 405aabe1..543057b1 100644
--- a/gfs2/fsck/Makefile.am
+++ b/gfs2/fsck/Makefile.am
@@ -32,10 +32,13 @@ fsck_gfs2_SOURCES = \
 	util.c
 
 fsck_gfs2_CPPFLAGS = $(AM_CPPFLAGS)
-fsck_gfs2_CFLAGS = $(AM_CFLAGS)
+fsck_gfs2_CFLAGS = \
+	$(AM_CFLAGS) \
+	$(blkid_CFLAGS)
 fsck_gfs2_LDADD = \
 	$(top_builddir)/gfs2/libgfs2/libgfs2.la \
 	$(LTLIBINTL) \
+	$(blkid_LIBS) \
 	$(uuid_LIBS)
 
 if HAVE_CHECK
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 62fb6107..8679dee9 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -12,6 +12,7 @@
 #include <libintl.h>
 #include <errno.h>
 #include <time.h>
+#include <blkid.h>
 
 #define _(String) gettext(String)
 
@@ -1555,6 +1556,33 @@ static int init_rindex(struct fsck_cx *cx)
 	return 0;
 }
 
+static int is_lvm_member(struct fsck_cx *cx)
+{
+	char lvm_member[] = "LVM2_member";
+	char *filter[] = {lvm_member, NULL};
+	int fd = cx->sdp->device_fd;
+	int ret;
+
+	blkid_probe pr = blkid_new_probe();
+	if (pr == NULL || blkid_probe_set_device(pr, fd, 0, 0) != 0
+	               || blkid_probe_filter_superblocks_type(pr,
+	                               BLKID_FLTR_ONLYIN, filter)) {
+		log_err(_("Failed to create probe for %s\n"), cx->opts->device);
+		return -1;
+	}
+	ret = blkid_do_fullprobe(pr);
+	blkid_free_probe(pr);
+	if (ret == -1) {
+		log_err(_("Failed to probe device %s\n"), cx->opts->device);
+		return -1;
+	}
+	if (ret == 1)
+		return 0;
+	log_err(_("%s looks like an LVM physical volume.\n"), cx->opts->device);
+	log_err(_("fsck.gfs2 cannot check this device.\n"));
+	return 1;
+}
+
 /**
  * initialize - initialize superblock pointer
  *
@@ -1602,6 +1630,8 @@ int initialize(struct fsck_cx *cx, int *all_clean)
 		   from themselves. */
 		was_mounted_ro = 1;
 	}
+	if (is_lvm_member(cx)) /* True or error */
+		return FSCK_ERROR;
 
 	if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo)) {
 		perror(cx->opts->device);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 27a643a2..f8538942 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,8 @@ EXTRA_DIST = \
 	$(TESTSCRIPTS) \
 	package.m4 \
 	gfs2-utils.spec.in \
-	atlocal.in
+	atlocal.in \
+	pv_sig.xxd
 
 DISTCLEANFILES = \
 	atlocal \
diff --git a/tests/atlocal.in b/tests/atlocal.in
index eed58b10..769b43cb 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -1,3 +1,4 @@
+GFS_TESTS_DIR="${abs_top_builddir}/tests"
 GFS_TGT="@testvol@"
 GFS_TGT_SZ=20
 GFS_MKFS="mkfs.gfs2 -O -D"
diff --git a/tests/fsck.at b/tests/fsck.at
index 538d41ad..bc8a6d1c 100644
--- a/tests/fsck.at
+++ b/tests/fsck.at
@@ -89,3 +89,10 @@ AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CHECK([mkfs.gfs2 -O -p lock_nolock -o format=1802 ${GFS_TGT}], 0, [ignore], [ignore])
 AT_CHECK([fsck.gfs2 -n $GFS_TGT], 0, [ignore], [ignore])
 AT_CLEANUP
+
+AT_SETUP([Detect LVM PV])
+AT_KEYWORDS(fsck.gfs2 fsck)
+GFS_TGT_REGEN
+AT_CHECK([xxd -r ${GFS_TESTS_DIR}/pv_sig.xxd ${GFS_TGT}], 0, [ignore], [ignore])
+AT_CHECK([fsck.gfs2 -y ${GFS_TGT}], 8, [ignore], [ignore])
+AT_CLEANUP
diff --git a/tests/pv_sig.xxd b/tests/pv_sig.xxd
new file mode 100644
index 00000000..dc00faed
--- /dev/null
+++ b/tests/pv_sig.xxd
@@ -0,0 +1,12 @@
+00000200: 4c41 4245 4c4f 4e45 0100 0000 0000 0000  LABELONE........
+00000210: 22fb 8643 2000 0000 4c56 4d32 2030 3031  "..C ...LVM2 001
+00000220: 5061 6e73 586a 5632 6847 3641 7679 3854  PansXjV2hG6Avy8T
+00000230: 5739 3236 786e 516a 5956 4154 5258 734d  W926xnQjYVATRXsM
+00000240: 0000 0040 0100 0000 0000 1000 0000 0000  ... at ............
+00000250: 0000 0000 0000 0000 0000 0000 0000 0000  ................
+00000260: 0000 0000 0000 0000 0010 0000 0000 0000  ................
+00000270: 00f0 0f00 0000 0000 0000 0000 0000 0000  ................
+00000280: 0000 0000 0000 0000 0200 0000 0000 0000  ................
+00000290: 0000 0000 0000 0000 0000 0000 0000 0000  ................
+*
+000003f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-- 
2.40.1


                 reply	other threads:[~2023-06-06 10:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230606105214.50569-1-anprice@redhat.com \
    --to=anprice@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).