From patchwork Thu Jan 29 02:24:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5734901 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 66916BF440 for ; Thu, 29 Jan 2015 02:26:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98A13201F2 for ; Thu, 29 Jan 2015 02:26:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5E6520160 for ; Thu, 29 Jan 2015 02:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933811AbbA2C0O (ORCPT ); Wed, 28 Jan 2015 21:26:14 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:61879 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1761823AbbA2CZ7 (ORCPT ); Wed, 28 Jan 2015 21:25:59 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="56792905" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Jan 2015 10:22:27 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t0T2PH7f026245; Thu, 29 Jan 2015 10:25:17 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 29 Jan 2015 10:25:57 +0800 From: Qu Wenruo To: CC: linux-fsdevel Subject: [PATCH RESEND v4 6/8] vfs: Add get_vfsmount_sb() function to get vfsmount from a given sb. Date: Thu, 29 Jan 2015 10:24:39 +0800 Message-ID: <1422498281-20493-7-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422498281-20493-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1422498281-20493-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are sysfs interfaces in some fs, only btrfs yet, which will modify on-disk data. Unlike normal file operation routine we can use mnt_want_write_file() to protect the operation, change through sysfs won't to be binded to any file in the filesystem. So we can only extract the first vfsmount of a superblock and pass it to mnt_want_write() to do the protection. Cc: linux-fsdevel Signed-off-by: Qu Wenruo --- fs/namespace.c | 25 +++++++++++++++++++++++++ include/linux/mount.h | 1 + 2 files changed, 26 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index cd1e968..5a16a62 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1105,6 +1105,31 @@ struct vfsmount *mntget(struct vfsmount *mnt) } EXPORT_SYMBOL(mntget); +/* + * get a vfsmount from a given sb + * + * This is especially used for case where change fs' sysfs interface + * will lead to a write, e.g. Change label through sysfs in btrfs. + * So vfs can get a vfsmount and then use mnt_want_write() to protect. + */ +struct vfsmount *get_vfsmount_sb(struct super_block *sb) +{ + struct vfsmount *ret_vfs = NULL; + struct mount *mnt; + int ret = 0; + + lock_mount_hash(); + if (list_empty(&sb->s_mounts)) + goto out; + mnt = list_entry(sb->s_mounts.next, struct mount, mnt_instance); + ret_vfs = &mnt->mnt; + ret_vfs = mntget(ret_vfs); +out: + unlock_mount_hash(); + return ret_vfs; +} +EXPORT_SYMBOL(get_vfsmount_sb); + struct vfsmount *mnt_clone_internal(struct path *path) { struct mount *p; diff --git a/include/linux/mount.h b/include/linux/mount.h index c2c561d..cf1b0f5 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -79,6 +79,7 @@ extern void mnt_drop_write_file(struct file *file); extern void mntput(struct vfsmount *mnt); extern struct vfsmount *mntget(struct vfsmount *mnt); extern struct vfsmount *mnt_clone_internal(struct path *path); +extern struct vfsmount *get_vfsmount_sb(struct super_block *sb); extern int __mnt_is_readonly(struct vfsmount *mnt); struct path;