From patchwork Mon Sep 4 06:50:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 9936741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A9E36601EB for ; Mon, 4 Sep 2017 06:52:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B12B28737 for ; Mon, 4 Sep 2017 06:52:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F4182873D; Mon, 4 Sep 2017 06:52:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF62B28737 for ; Mon, 4 Sep 2017 06:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752609AbdIDGwt (ORCPT ); Mon, 4 Sep 2017 02:52:49 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5516 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751620AbdIDGwr (ORCPT ); Mon, 4 Sep 2017 02:52:47 -0400 Received: from 172.30.72.59 (EHLO DGGEMS401-HUB.china.huawei.com) ([172.30.72.59]) by dggrg04-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DGM14902; Mon, 04 Sep 2017 14:46:06 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.301.0; Mon, 4 Sep 2017 14:46:02 +0800 From: Hou Tao To: CC: , Subject: [PATCH v3] xfs: add online uevent for mount operation Date: Mon, 4 Sep 2017 14:50:59 +0800 Message-ID: <1504507859-39323-1-git-send-email-houtao1@huawei.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090201.59ACF6AE.00AA, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f1fc8b923220782e57cf18a37b30b1e9 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Hou Tao --- 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: