All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hou Tao <houtao1@huawei.com>
To: linux-xfs@vger.kernel.org
Cc: darrick.wong@oracle.com, david@fromorbit.com
Subject: [PATCH v3] xfs: add online uevent for mount operation
Date: Mon, 4 Sep 2017 14:50:59 +0800	[thread overview]
Message-ID: <1504507859-39323-1-git-send-email-houtao1@huawei.com> (raw)

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 (except the one with the matched UUID) after
the filesystem gets any IO error and the filesystem with the matched
UUID will retry 5 times before its shutdown:

    ACTION=="online", SUBSYSTEM=="xfs", \
    ENV{ID_FS_UUID}=="6c1eebfd-d1af-4b69-a0f1-c9b4663df44d", \
    RUN+="/bin/sh -c 'echo 5 > /sys%p/error/metadata/EIO/max_retries'", \
    GOTO="end"

    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'"

    LABEL="end"

Suggested-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
v3:
    * code style fixes
    * use "ID_FS_UUID" instead of "UUID" as the name of uuid environment
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 | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 3a3812b4..1f0d895 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -1530,6 +1530,28 @@ xfs_destroy_percpu_counters(
 	percpu_counter_destroy(&mp->m_fdblocks);
 }
 
+static void
+xfs_fs_uevent(
+	struct xfs_mount	*mp,
+	enum kobject_action	action)
+{
+#define XFS_UEVENT_MAX_ENV_COUNT 1
+	/* "+ 1" for the trailing NULL pointer */
+	char			*envp[XFS_UEVENT_MAX_ENV_COUNT + 1];
+	const char		*prefix = "ID_FS_UUID=";
+	char			buf[strlen(prefix) + UUID_STRING_LEN + 1];
+	int			i = 0;
+	int			err;
+
+	snprintf(buf, sizeof(buf), "%s%pUb", prefix, &mp->m_super->s_uuid);
+	envp[i++] = buf;
+	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 +1689,8 @@ xfs_fs_fill_super(
 		goto out_unmount;
 	}
 
+	xfs_fs_uevent(mp, KOBJ_ONLINE);
+
 	return 0;
 
  out_filestream_unmount:
-- 
2.5.0


             reply	other threads:[~2017-09-04  6:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04  6:50 Hou Tao [this message]
2017-09-06  0:52 ` [PATCH v3] xfs: add online uevent for mount operation Luis R. Rodriguez
2017-09-07  8:56   ` Hou Tao
2017-09-08  0:49     ` Dave Chinner
2017-09-18 18:00       ` Darrick J. Wong

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=1504507859-39323-1-git-send-email-houtao1@huawei.com \
    --to=houtao1@huawei.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.