public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] xfs: add online uevent for mount operation
@ 2017-08-31 14:17 Hou Tao
  2017-08-31 15:03 ` Darrick J. Wong
  0 siblings, 1 reply; 10+ messages in thread
From: Hou Tao @ 2017-08-31 14:17 UTC (permalink / raw)
  To: linux-xfs; +Cc: darrick.wong, david

It will be useful if there is a corresponding online uevent after
a XFS filesystem has been mounted. A typical usage of the uevent
is setting the error configuration for a specific XFS filesystem
or all XFS filesystems by using udevd.

The following is an example of udevd rule which will shutdown
any XFS filesystem after the filesystem gets any IO error:

    ACTION=="online", SUBSYSTEM=="xfs", DEVPATH=="/fs/xfs/*", \
    RUN+="/bin/sh -c 'echo 0 > /sys%p/error/metadata/default/max_retries; \
	    echo 0 > /sys%p/error/metadata/EIO/max_retries; \
	    echo 0 > /sys%p/error/metadata/ENOSPC/max_retries; \
	    echo 0 > /sys%p/error/metadata/ENODEV/max_retries'"

You also could apply an udevd rule to a specific XFS filesystem by
UUID filtering:

    ACTION=="online", SUBSYSTEM=="xfs", \
    ENV{UUID}=="8f789c27-391f-4bd7-b17d-9bcf2443dc9c", \
    RUN+="/bin/sh -c 'echo 5 > /sys%p/error/metadata/EIO/max_retries'"

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
v2:
    * add UUID property for mount uevent
    * add an udev example for UUID filtering
v1:
    * http://www.spinics.net/lists/linux-xfs/msg09484.html
---
 fs/xfs/xfs_super.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 3a3812b4..6f8351c 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -70,6 +70,11 @@ static struct kset *xfs_kset;		/* top-level xfs sysfs dir */
 static struct xfs_kobj xfs_dbg_kobj;	/* global debug sysfs attrs */
 #endif
 
+enum {
+	XFS_UEVENT_ENV_CNT = 2,
+	XFS_UEVENT_UUID_LEN = UUID_STRING_LEN + 6,
+};
+
 /*
  * Table driven mount option parser.
  */
@@ -1530,6 +1535,28 @@ xfs_destroy_percpu_counters(
 	percpu_counter_destroy(&mp->m_fdblocks);
 }
 
+static void
+xfs_fs_uevent(
+	struct xfs_mount	*mp,
+	enum kobject_action	action)
+{
+	int err;
+	char *envp[XFS_UEVENT_ENV_CNT];
+	int i = 0;
+
+	if (!uuid_is_null(&mp->m_super->s_uuid)) {
+		char uuid[XFS_UEVENT_UUID_LEN];
+
+		snprintf(uuid, sizeof(uuid), "UUID=%pUb", &mp->m_super->s_uuid);
+		envp[i++] = uuid;
+	}
+	envp[i] = NULL;
+	err = kobject_uevent_env(&mp->m_kobj.kobject, action, envp);
+	if (err)
+		xfs_notice(mp, "Sending XFS uevent %d got error %d",
+				action, err);
+}
+
 STATIC int
 xfs_fs_fill_super(
 	struct super_block	*sb,
@@ -1667,6 +1694,8 @@ xfs_fs_fill_super(
 		goto out_unmount;
 	}
 
+	xfs_fs_uevent(mp, KOBJ_ONLINE);
+
 	return 0;
 
  out_filestream_unmount:
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-09-04  4:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 14:17 [PATCH v2] xfs: add online uevent for mount operation Hou Tao
2017-08-31 15:03 ` Darrick J. Wong
2017-08-31 23:34   ` Dave Chinner
2017-09-01  1:26     ` Hou Tao
2017-09-01  2:06       ` Dave Chinner
2017-09-01  5:11         ` Hou Tao
2017-09-01 15:20           ` Darrick J. Wong
2017-09-01 21:52             ` Dave Chinner
2017-09-04  0:03               ` Darrick J. Wong
2017-09-04  4:01                 ` Hou Tao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox