From patchwork Thu Jan 29 01:27:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5733391 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 0CC92BF440 for ; Thu, 29 Jan 2015 01:30:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F30B2013A for ; Thu, 29 Jan 2015 01:30:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63BE720123 for ; Thu, 29 Jan 2015 01:30:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754191AbbA2B3t (ORCPT ); Wed, 28 Jan 2015 20:29:49 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:21262 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755338AbbA2B3H (ORCPT ); Wed, 28 Jan 2015 20:29:07 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="56788775" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 29 Jan 2015 09:25:36 +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 t0T1SQHK021003; Thu, 29 Jan 2015 09:28:26 +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 09:29:06 +0800 From: Qu Wenruo To: CC: , linux-fsdevel Subject: [PATCH v4 6/8] vfs: Add get_vfsmount_sb() function to get vfsmount from a given sb. Date: Thu, 29 Jan 2015 09:27:41 +0800 Message-ID: <1422494863-15077-11-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422494863-15077-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1422494863-15077-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=unavailable 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;