Skip to contentSkip to conversation

xfs_healer: fail earlier on non-xfs filesystems

PATCH In review Darrick J. Wong 3 participants 9 messages Oct 1 – Oct 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_healer: fail earlier on non-xfs filesystems

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults. However, the actual service failure here is a result of the ExecCondition program exiting with 255 instead of EXIT_FAILURE. EXIT_FAILURE is what we're supposed to return to mean "do not run service".

Note that xfs_healer@- is always started by systemd (and not xfs_healer_start) because the root filesystem is usually mounted before systemd starts.

stracing this program a litle further reveals this:

 # strace -e ioctl /usr/libexec/xfsprogs/xfs_healer --supported /
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7e, 0x100), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7c, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x64, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 /: Inappropriate ioctl for device

All three ioctls are XFS_IOC_FSGEOMETRY calls, and they all fail with ENOTTY because this is an ext4 filesystem. The fsgeometry call occurs under xfd_open(), so fix this error by special-casing the error return handling.

Cc <[email protected]> # v7.0.0
Fixes ea178059ff72c3 ("xfs_healer: don't start service if kernel support unavailable")
---
 healer/xfs_healer.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
healer/xfs_healer.c +10 -0
index ec402a78d5d2bf..b71695db05876f 100644
@@ -317,6 +317,16 @@ setup_monitor(
 
 	ret = xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);
 	if (ret) {
+		if (ret == -ENOTTY) {
+			/*
+			 * If this isn't even an XFS filesystem, the fsgeometry
+			 * call will return ENOTTY.
+			 */
+			fprintf(stderr, "%s: %s\n", ctx->mntpoint,
+ _("XFS health monitoring not supported."));
+			return MON_UNSUPPORTED;
+		}
+
 		perror(ctx->mntpoint);
 		return outcome;
 	}
#1 lore raw

Re: Bug#1149571: [PATCH] xfs_healer: fail earlier on non-xfs filesystems

Quoted 48 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults. However, the actual service failure here is a result of the ExecCondition program exiting with 255 instead of EXIT_FAILURE. EXIT_FAILURE is what we're supposed to return to mean "do not run service".

Note that xfs_healer@- is always started by systemd (and not xfs_healer_start) because the root filesystem is usually mounted before systemd starts.

stracing this program a litle further reveals this:

 # strace -e ioctl /usr/libexec/xfsprogs/xfs_healer --supported /
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7e, 0x100), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7c, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x64, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 /: Inappropriate ioctl for device

All three ioctls are XFS_IOC_FSGEOMETRY calls, and they all fail with ENOTTY because this is an ext4 filesystem. The fsgeometry call occurs under xfd_open(), so fix this error by special-casing the error return handling.

Cc <[email protected]> # v7.0.0
Fixes ea178059ff72c3 ("xfs_healer: don't start service if kernel support unavailable")
---
 healer/xfs_healer.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
healer/xfs_healer.c +0 -0
index ec402a78d5d2bf..b71695db05876f 100644

healer/xfs_healer.c setup_monitor( · line 318

Quoted 2 lines
healer/xfs_healer.c +0 -0
@@ -317,6 +317,16 @@ setup_monitor(
 
 	ret = xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);

This probably should be ret = -xfd_open(...)? (not sure why xfd_open converts errno to negative but all other users convert it back)

healer/xfs_healer.c setup_monitor( · line 320

Quoted 2 lines
healer/xfs_healer.c +1 -0
 	if (ret) {
+		if (ret == -ENOTTY) {

Then, ret == ENOTTY

Signature · 1 line
- Andrey
#2 lore raw

Re: Bug#1149571: [PATCH] xfs_healer: fail earlier on non-xfs filesystems

Quoted 50 lines · Andrey Albershteyn
Quoted 49 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults. However, the actual service failure here is a result of the ExecCondition program exiting with 255 instead of EXIT_FAILURE. EXIT_FAILURE is what we're supposed to return to mean "do not run service".

Note that xfs_healer@- is always started by systemd (and not xfs_healer_start) because the root filesystem is usually mounted before systemd starts.

stracing this program a litle further reveals this:

 # strace -e ioctl /usr/libexec/xfsprogs/xfs_healer --supported /
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7e, 0x100), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7c, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x64, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 /: Inappropriate ioctl for device

All three ioctls are XFS_IOC_FSGEOMETRY calls, and they all fail with ENOTTY because this is an ext4 filesystem. The fsgeometry call occurs under xfd_open(), so fix this error by special-casing the error return handling.

Cc <[email protected]> # v7.0.0
Fixes ea178059ff72c3 ("xfs_healer: don't start service if kernel support unavailable")
---
 healer/xfs_healer.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
healer/xfs_healer.c +0 -0
index ec402a78d5d2bf..b71695db05876f 100644
@@ -317,6 +317,16 @@ setup_monitor(
 
Quoted 4 lines

healer/xfs_healer.c setup_monitor( · line 318

Quoted 1 line
healer/xfs_healer.c +0 -0
 	ret = xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);

This probably should be ret = -xfd_open(...)? (not sure why xfd_open converts errno to negative but all other users convert it back)

Yeah, and the perror() call is incorrect too. I'll post a second patch to convert the callsite.

--D

Quoted 8 lines

healer/xfs_healer.c setup_monitor( · line 320

Quoted 2 lines
healer/xfs_healer.c +1 -0
 	if (ret) {
+		if (ret == -ENOTTY) {

Then, ret == ENOTTY

Signature · 1 line
- Andrey
#3 lore raw
In reply to Darrick J. Wong

Am 01.10.26 um 08:23 schrieb Darrick J. Wong:

Quoted 4 lines

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

Quoted 8 lines

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults.

Fwiw, this assumption is correct. My / is using ext4.

Regards,
Michael

#4 lore raw

PATCH v2 1/1 xfs_healer: fix a user-reported bug

Hi all,

This bugfix series corrects a couple of problems in xfs_healer that were found by a Debian user.

v2: fix xfd_open callsite's use of error return values in addition to
fixing the reported problem, per maintainer

If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.

With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=healer-fixes
---
Commits in this patchset:
* xfs_healer: correct xfd_ API usage
* xfs_healer: fail earlier on non-xfs filesystems

---
 healer/xfs_healer.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
#5 lore raw

PATCH 1/2 xfs_healer: correct xfd_ API usage

From: Darrick J. Wong <[email protected]>

This callsite is wrong -- the xfd_* functions return 0 on success or negative errno on failure, so we should be using strerror on the value provided, and not perror, which uses errno. Fix this to be consistent with the other xfsprogs utilities.

Cc <[email protected]> # v7.0.0
Fixes b9b03770197d19 ("xfs_healer: create daemon to listen for health events")
---
 healer/xfs_healer.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
healer/xfs_healer.c +2 -2
index ec402a78d5d2bf..8fa58b742aea49 100644
@@ -315,9 +315,9 @@ setup_monitor(
 	int			mon_fd;
 	int			ret;
 
-	ret = xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);
+	ret = -xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);
 	if (ret) {
-		perror(ctx->mntpoint);
+		fprintf(stderr, "%s: %s\n", ctx->mntpoint, strerror(ret));
 		return outcome;
 	}
 
Reviewed-by on v1 1/2
#6 lore raw

Re: [PATCH 1/2] xfs_healer: correct xfd_ API usage

Quoted 10 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

This callsite is wrong -- the xfd_* functions return 0 on success or negative errno on failure, so we should be using strerror on the value provided, and not perror, which uses errno. Fix this to be consistent with the other xfsprogs utilities.

Cc <[email protected]> # v7.0.0
Fixes b9b03770197d19 ("xfs_healer: create daemon to listen for health events")

Looks good to me

Signature · 1 line
- Andrey
#7 lore raw

PATCH 2/2 xfs_healer: fail earlier on non-xfs filesystems

In reply to Darrick J. Wong

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults. However, the actual service failure here is a result of the ExecCondition program exiting with 255 instead of EXIT_FAILURE. EXIT_FAILURE is what we're supposed to return to mean "do not run service".

Note that xfs_healer@- is always started by systemd (and not xfs_healer_start) because the root filesystem is usually mounted before systemd starts.

stracing this program a litle further reveals this:

 # strace -e ioctl /usr/libexec/xfsprogs/xfs_healer --supported /
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7e, 0x100), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7c, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x64, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 /: Inappropriate ioctl for device

All three ioctls are XFS_IOC_FSGEOMETRY calls, and they all fail with ENOTTY because this is an ext4 filesystem. The fsgeometry call occurs under xfd_open(), so fix this error by special-casing the error return handling.

Cc <[email protected]> # v7.0.0
Fixes bf8b99270c6be1 ("xfs_healer: use the autofsck fsproperty to select mode")
---
 healer/xfs_healer.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
healer/xfs_healer.c +10 -0
index 8fa58b742aea49..0a55e3b5755056 100644
@@ -317,6 +317,16 @@ setup_monitor(
 
 	ret = -xfd_open(&ctx->mnt, ctx->mntpoint, O_RDONLY);
 	if (ret) {
+		if (ret == ENOTTY) {
+			/*
+			 * If the fsgeometry call returns ENOTTY, this isn't
+			 * even an XFS filesystem.
+			 */
+			fprintf(stderr, "%s: %s\n", ctx->mntpoint,
+ _("XFS health monitoring not supported."));
+			return MON_UNSUPPORTED;
+		}
+
 		fprintf(stderr, "%s: %s\n", ctx->mntpoint, strerror(ret));
 		return outcome;
 	}
Reviewed-by on v1 2/2
#8 lore raw

Re: Bug#1149571: [PATCH 2/2] xfs_healer: fail earlier on non-xfs filesystems

Quoted 33 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

A Debian user reported that the root filesystem service fails with:

systemd[1]: Starting [email protected] - Self Healing of XFS Metadata for /... xfs_healer@-[976]: /: Inappropriate ioctl for device
systemd[1]: [email protected]: Condition check process exited, code=exited, status=255/EXCEPTION systemd[1]: [email protected]: Failed with result 'exit-code'.
systemd[1]: Failed to start [email protected] - Self Healing of XFS Metadata for /.

when the root filesystem is not XFS. It's most likely ext4 given Debian's defaults. However, the actual service failure here is a result of the ExecCondition program exiting with 255 instead of EXIT_FAILURE. EXIT_FAILURE is what we're supposed to return to mean "do not run service".

Note that xfs_healer@- is always started by systemd (and not xfs_healer_start) because the root filesystem is usually mounted before systemd starts.

stracing this program a litle further reveals this:

 # strace -e ioctl /usr/libexec/xfsprogs/xfs_healer --supported /
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7e, 0x100), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x7c, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 ioctl(3, _IOC(_IOC_READ, 0x58, 0x64, 0x70), 0x7fffb2c5e6a8) = -1 ENOTTY (Inappropriate ioctl for device)
 /: Inappropriate ioctl for device

All three ioctls are XFS_IOC_FSGEOMETRY calls, and they all fail with ENOTTY because this is an ext4 filesystem. The fsgeometry call occurs under xfd_open(), so fix this error by special-casing the error return handling.

Quoted 6 lines
Cc <[email protected]> # v7.0.0
Fixes bf8b99270c6be1 ("xfs_healer: use the autofsck fsproperty to select mode")

Looks good to me

Signature · 1 line
- Andrey