From patchwork Fri Nov 17 17:45:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 10063065 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 91DB96023A for ; Fri, 17 Nov 2017 17:46:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80F932AD16 for ; Fri, 17 Nov 2017 17:46:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 761182AD3A; Fri, 17 Nov 2017 17:46:20 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 1CD9E2AD16 for ; Fri, 17 Nov 2017 17:46:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161134AbdKQRqS (ORCPT ); Fri, 17 Nov 2017 12:46:18 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:36477 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030310AbdKQRqM (ORCPT ); Fri, 17 Nov 2017 12:46:12 -0500 Received: by mail-it0-f67.google.com with SMTP id 187so2789210iti.1 for ; Fri, 17 Nov 2017 09:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QFkK6dY7JwyycwQRPa+vlg6idyyVcTCOD9amlAFVdMI=; b=upKPSD4bFELMWwDOuFjOJjMOXrOB037IYdVCfidQlaVMfgVN2cASkpL4rTIWLBBKQi B7mVH8rjwmNSgh/Z8HSFSvBP34nRVA1nJvX7l8TvRk9VRiMfV4dx5utmaqiLrYZYktjO sE5z6EeD7+Dj9j/9UpBBxqKm2eCWbZN8S/i90iLC5i4oDuC+pFrsrCIVkp+MHFt63u6G JefOYLzzUzt0IL9ORA5xKxuTvwgjbyUBat3rd/mxYI3i2j8uz8H9BaMD84uRTC3aX/ZW 4MNmVksPKo8IzAWEn2kYFc38MhjYDRzikRZuZvykBTGov2J8EM9hvz/H2ySM9lXvTOAy WTrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QFkK6dY7JwyycwQRPa+vlg6idyyVcTCOD9amlAFVdMI=; b=hIkn5GIiLNV3LSGI5caL27f3HrE6cBUPdW6pnlInH0IorcL0sim4mRmn5S6MTTLTTV aev1DX+p65sgXkBiA3HBLFpMt+lw3cmUd+g7gGLpXttk++MNxmimrxsZi7fMZPXIzavx rgx0jCjUhruBvY1TaloN9jU1ykYWHVn6YZiLRuamzW3w+K3O2K5xDGoUp+1vOVHMSMuV QgyzbjkB07wnUux8nWH4cA00QJRla6RBNKUxiLUhDa+xOikniIhh+Kv5RGbzd39lvI9+ nfbBXTjFevgbDIJACIE+oaRNW41fG++C41C5kQTpZRRvZF9HRlmW+LB1GIYYhc2GowdL Lyfg== X-Gm-Message-State: AJaThX5KZgrMGJ0bvvkrnNR2bsPEYwQzG0eDv91mofXtLuwdD1zpvYBc 1EylitV4HdA178xiuf1hROI= X-Google-Smtp-Source: AGs4zMb4viCIeRbD1qAVTRhAeL3VA6/zmN4aOBNrfqFLbzKSt7LFyOtVuj2jTu9SAYgAJ83z3p3afA== X-Received: by 10.36.101.207 with SMTP id u198mr7690872itb.50.1510940771768; Fri, 17 Nov 2017 09:46:11 -0800 (PST) Received: from ola-842mrw1.ad.garmin.com ([204.77.163.55]) by smtp.googlemail.com with ESMTPSA id h21sm1878189iod.59.2017.11.17.09.46.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 17 Nov 2017 09:46:11 -0800 (PST) From: Joshua Watt X-Google-Original-From: Joshua Watt To: NeilBrown , Jeff Layton , Trond Myklebust , "J . Bruce Fields" Cc: linux-nfs@vger.kernel.org, Al Viro , David Howells , Joshua Watt Subject: [RFC v4 4/9] namespace: Add umount_end superblock operation Date: Fri, 17 Nov 2017 11:45:47 -0600 Message-Id: <20171117174552.18722-5-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171117174552.18722-1-JPEWhacker@gmail.com> References: <20171117174552.18722-1-JPEWhacker@gmail.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The umount_end operation allows cleaning of state set by umount_begin in the event the filesystem doesn't actually get unmounted. Signed-off-by: Joshua Watt --- fs/namespace.c | 22 ++++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index d18deb4c410b..d2587be4d08b 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1524,6 +1524,12 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how) } } +static void umount_end(struct super_block *sb, int flags) +{ + if (flags & MNT_FORCE && sb->s_op->umount_end) + sb->s_op->umount_end(sb); +} + static void shrink_submounts(struct mount *mnt); static int do_umount(struct mount *mnt, int flags) @@ -1589,12 +1595,16 @@ static int do_umount(struct mount *mnt, int flags) * Special case for "unmounting" root ... * we just try to remount it readonly. */ - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; + if (!capable(CAP_SYS_ADMIN)) { + retval = -EPERM; + goto out_umount_end; + } down_write(&sb->s_umount); if (!sb_rdonly(sb)) retval = do_remount_sb(sb, SB_RDONLY, NULL, 0); up_write(&sb->s_umount); + /* Still mounted. Always invoke the cleanup */ + umount_end(sb, flags); return retval; } @@ -1617,6 +1627,14 @@ static int do_umount(struct mount *mnt, int flags) } unlock_mount_hash(); namespace_unlock(); + +out_umount_end: + /* If the umount failed and the file system is still mounted, allow the + * driver to cleanup any state it may have setup in umount_begin(). Note + * that this is purposely *not* called when MNT_DETACH is specified. + */ + if (retval) + umount_end(sb, flags); return retval; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 885266aae2d7..5443c22da18f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1816,6 +1816,7 @@ struct super_operations { int (*statfs) (struct dentry *, struct kstatfs *); int (*remount_fs) (struct super_block *, int *, char *); void (*umount_begin) (struct super_block *); + void (*umount_end)(struct super_block *); int (*show_options)(struct seq_file *, struct dentry *); int (*show_devname)(struct seq_file *, struct dentry *);