From patchwork Mon Jul 27 03:08:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 6867991 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 8257FC05AD for ; Mon, 27 Jul 2015 03:08:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B553120529 for ; Mon, 27 Jul 2015 03:08:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA8F1205FE for ; Mon, 27 Jul 2015 03:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755419AbbG0DIn (ORCPT ); Sun, 26 Jul 2015 23:08:43 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:36858 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755260AbbG0DIm (ORCPT ); Sun, 26 Jul 2015 23:08:42 -0400 Received: by pachj5 with SMTP id hj5so43497863pac.3; Sun, 26 Jul 2015 20:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=PCafwDlvtrWbd2WUjOJAAmMQlXfQi+B4vH5l9/9CNI8=; b=xkarxuCOkq+2yHi26NdFyWYoyYpwblc/gj/wyI7gsy5uFGoZxBgk1Uq3K4CS0tEZ2p SwzOW/vsWYDur7JOmL1HKFtofrwD9XrDQdVQrJ3zPqeQn01GmdpswMZv6n2/CxIQAlIo DZUm+FNCTB71qjG8YJBzBCSOU00NL1BMq9Luqlxh1wTBvaOVeDuZOEJfoajQ3sJlrFTm k2LeZ3uNBMjDrhmT/z0ox5XH1IUlIgPM7dqEuB8LOSkyU+Hh0gPbI04UuALlY2INUrzl w9cYNmRZ/4glnb59JPlfT/UaUOSmNrlXC0fo3IRu5xcIzpq1uJ6i1pOXDr+sWm3W6IZ3 w+Dw== X-Received: by 10.66.65.142 with SMTP id x14mr63121503pas.135.1437966521456; Sun, 26 Jul 2015 20:08:41 -0700 (PDT) Received: from [192.168.99.25] ([104.143.41.79]) by smtp.googlemail.com with ESMTPSA id jg7sm5323522pac.1.2015.07.26.20.08.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 20:08:40 -0700 (PDT) Message-ID: <55B5A0B0.7060604@gmail.com> Date: Mon, 27 Jul 2015 11:08:32 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "J. Bruce Fields" , Al Viro CC: "linux-nfs@vger.kernel.org" , linux-fsdevel@vger.kernel.org, NeilBrown , Trond Myklebust , kinglongmee@gmail.com Subject: [PATCH 4/9 v8] fs: New helper legitimize_mntget() for getting a legitimize mnt References: <55B5A012.1030006@gmail.com> In-Reply-To: <55B5A012.1030006@gmail.com> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 New helper legitimize_mntget for getting a mnt without setting MNT_SYNC_UMOUNT | MNT_UMOUNT | MNT_DOOMED, otherwise return NULL. v8, same as v6 Signed-off-by: Kinglong Mee --- fs/namespace.c | 19 +++++++++++++++++++ include/linux/mount.h | 1 + 2 files changed, 20 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index 2b8aa15..842cf57 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1153,6 +1153,25 @@ struct vfsmount *mntget(struct vfsmount *mnt) } EXPORT_SYMBOL(mntget); +struct vfsmount *legitimize_mntget(struct vfsmount *vfsmnt) +{ + struct mount *mnt; + + if (vfsmnt == NULL) + return NULL; + + read_seqlock_excl(&mount_lock); + mnt = real_mount(vfsmnt); + if (vfsmnt->mnt_flags & (MNT_SYNC_UMOUNT | MNT_UMOUNT | MNT_DOOMED)) + vfsmnt = NULL; + else + mnt_add_count(mnt, 1); + read_sequnlock_excl(&mount_lock); + + return vfsmnt; +} +EXPORT_SYMBOL(legitimize_mntget); + struct vfsmount *mnt_clone_internal(struct path *path) { struct mount *p; diff --git a/include/linux/mount.h b/include/linux/mount.h index f822c3c..8ae9dc0 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -79,6 +79,7 @@ extern void mnt_drop_write(struct vfsmount *mnt); 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 *legitimize_mntget(struct vfsmount *vfsmnt); extern struct vfsmount *mnt_clone_internal(struct path *path); extern int __mnt_is_readonly(struct vfsmount *mnt);