From patchwork Fri Apr 3 01:56:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6153191 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 367CEBF4A6 for ; Fri, 3 Apr 2015 02:00:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4421920379 for ; Fri, 3 Apr 2015 02:00:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CE832035E for ; Fri, 3 Apr 2015 02:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753337AbbDCCAl (ORCPT ); Thu, 2 Apr 2015 22:00:41 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:45032 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753264AbbDCCAk (ORCPT ); Thu, 2 Apr 2015 22:00:40 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1YdquV-0002tW-Or; Thu, 02 Apr 2015 20:00:39 -0600 Received: from 70-59-163-10.omah.qwest.net ([70.59.163.10] helo=x220.int.ebiederm.org) by in01.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1YdquV-0003Lp-3f; Thu, 02 Apr 2015 20:00:39 -0600 From: "Eric W. Biederman" To: Linux Containers Cc: , "Serge E. Hallyn" , Andy Lutomirski , Richard Weinberger , Andrey Vagin , Al Viro , Jann Horn , Willy Tarreau , Omar Sandoval Date: Thu, 2 Apr 2015 20:56:12 -0500 Message-Id: <1428026183-14879-8-git-send-email-ebiederm@xmission.com> X-Mailer: git-send-email 2.2.1 In-Reply-To: <87a8yqou41.fsf_-_@x220.int.ebiederm.org> References: <87a8yqou41.fsf_-_@x220.int.ebiederm.org> X-XM-AID: U2FsdGVkX19xT05Jq5TzNr6zaoOK1yAPb571UbvANx4= X-SA-Exim-Connect-IP: 70.59.163.10 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: 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-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 316 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 4.1 (1.3%), b_tie_ro: 2.8 (0.9%), parse: 2.1 (0.7%), extract_message_metadata: 17 (5.3%), get_uri_detail_list: 2.9 (0.9%), tests_pri_-1000: 7 (2.1%), tests_pri_-950: 1.45 (0.5%), tests_pri_-900: 1.18 (0.4%), tests_pri_-400: 26 (8.2%), check_bayes: 25 (7.8%), b_tokenize: 8 (2.5%), b_tok_get_all: 7 (2.2%), b_comp_prob: 2.3 (0.7%), b_tok_touch_all: 3.0 (1.0%), b_finish: 0.96 (0.3%), tests_pri_0: 245 (77.7%), tests_pri_500: 7 (2.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH review 08/19] mnt: Don't propagate unmounts to locked mounts X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the first mount in shared subtree is locked don't unmount the shared subtree. This is ensured by walking through the mounts parents before children and marking a mount as unmountable if it is not locked or it is locked but it's parent is marked. This allows recursive mount detach to propagate through a set of mounts when unmounting them would not reveal what is under any locked mount. Cc: stable@vger.kernel.org Signed-off-by: "Eric W. Biederman" --- fs/pnode.c | 32 +++++++++++++++++++++++++++++--- fs/pnode.h | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/pnode.c b/fs/pnode.c index 89890293dd0a..6367e1e435c6 100644 --- a/fs/pnode.c +++ b/fs/pnode.c @@ -382,6 +382,26 @@ void propagate_mount_unlock(struct mount *mnt) } /* + * Mark all mounts that the MNT_LOCKED logic will allow to be unmounted. + */ +static void mark_umount_candidates(struct mount *mnt) +{ + struct mount *parent = mnt->mnt_parent; + struct mount *m; + + BUG_ON(parent == mnt); + + for (m = propagation_next(parent, parent); m; + m = propagation_next(m, parent)) { + struct mount *child = __lookup_mnt_last(&m->mnt, + mnt->mnt_mountpoint); + if (child && (!IS_MNT_LOCKED(child) || IS_MNT_MARKED(m))) { + SET_MNT_MARK(child); + } + } +} + +/* * NOTE: unmounting 'mnt' naturally propagates to all other mounts its * parent propagates to. */ @@ -398,10 +418,13 @@ static void __propagate_umount(struct mount *mnt) struct mount *child = __lookup_mnt_last(&m->mnt, mnt->mnt_mountpoint); /* - * umount the child only if the child has no - * other children + * umount the child only if the child has no children + * and the child is marked safe to unmount. */ - if (child && list_empty(&child->mnt_mounts)) { + if (!child || !IS_MNT_MARKED(child)) + continue; + CLEAR_MNT_MARK(child); + if (list_empty(&child->mnt_mounts)) { list_del_init(&child->mnt_child); child->mnt.mnt_flags |= MNT_UMOUNT; list_move_tail(&child->mnt_list, &mnt->mnt_list); @@ -420,6 +443,9 @@ int propagate_umount(struct list_head *list) { struct mount *mnt; + list_for_each_entry_reverse(mnt, list, mnt_list) + mark_umount_candidates(mnt); + list_for_each_entry(mnt, list, mnt_list) __propagate_umount(mnt); return 0; diff --git a/fs/pnode.h b/fs/pnode.h index af47d4bd7b31..0fcdbe7ca648 100644 --- a/fs/pnode.h +++ b/fs/pnode.h @@ -19,6 +19,7 @@ #define IS_MNT_MARKED(m) ((m)->mnt.mnt_flags & MNT_MARKED) #define SET_MNT_MARK(m) ((m)->mnt.mnt_flags |= MNT_MARKED) #define CLEAR_MNT_MARK(m) ((m)->mnt.mnt_flags &= ~MNT_MARKED) +#define IS_MNT_LOCKED(m) ((m)->mnt.mnt_flags & MNT_LOCKED) #define CL_EXPIRE 0x01 #define CL_SLAVE 0x02