Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp957866imm; Thu, 31 May 2018 12:27:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJvvxn6ndep8+HF8ncFzfg0OQjZR2gnYzte+PRem4eSZHWD8n1cOINJ8cVI9Crz99KMlaOa X-Received: by 2002:a63:770f:: with SMTP id s15-v6mr6656203pgc.30.1527794833426; Thu, 31 May 2018 12:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527794833; cv=none; d=google.com; s=arc-20160816; b=Hv1HAF6oQ7jKFWiVASZy/V8VYqgyFy1lwyCIeBIHqvGFaj/ki2N23bsQe5JOFdCYfA w7zrik1jIsu77LCZix7YcD3eceoML2UuOSo3Wce5jB/wfyqe2wzka+V6l3Sqwxo0GLSi EmJPws2alHRukY74PqH18J4IlZKMCEyUvxDg84zYHdpd7lcZbTzr+fhL1u1L099en5dG OLCEfah6g8lWjwMnWvbmmLy3RlngzLvSvjRc3LnOXRdIic6RfBcQ6yXf2bgTzRV3sWyJ XmgzivSvQf+gAgolChI5ih/43nFGfpEwwYeZb96TSGwF48ChhVBHTw6F6htdIhFj5XfH aSWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=i4KpggUEB3HCRTs18uRypSIOvRUuzXdkfNOTru/Zhgs=; b=k2JyyfL/VcuFQ+ZWpqXP9cUMB2FTCv/+lUYehL0mFE7HZL7ik2214vpEkBSRFT5TDX 5+B1is25UqfiOYOCu6rwJCmnBiefELYTwniLC8ydQV8Xw75BA5HLh2ejFjfeMsSJWGca cDHxpBe9N5Z5CXoyzHC/devwq1moXYEE7zWLPhrZKiGDoXy+kF9OqHeT5KtZ8DrQG0vC Zet/Jg2G0sKGiC0dGQGKcEng4htMMiaTK1tUJSuWxiUDLuHZce3sEFkVCJHhakyPucbO xp0Niwn6usC89FUhYxgrjYz16MnaSiMHrFf72ldoXAYc95ykjxIyy58W62GNaIuxfds+ v5ZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3-v6si25671736pgc.300.2018.05.31.12.26.58; Thu, 31 May 2018 12:27:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754159AbeEaT0M (ORCPT + 99 others); Thu, 31 May 2018 15:26:12 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:48646 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754089AbeEaT0J (ORCPT ); Thu, 31 May 2018 15:26:09 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fOTD6-0005QW-Hz; Thu, 31 May 2018 19:26:08 +0000 Date: Thu, 31 May 2018 20:26:08 +0100 From: Al Viro To: David Howells Cc: linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 20/32] vfs: Make close() unmount the attached mount if so flagged [ver #8] Message-ID: <20180531192608.GH30522@ZenIV.linux.org.uk> References: <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> <152720685405.9073.17445116582570028610.stgit@warthog.procyon.org.uk> <20180531191955.GG30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180531191955.GG30522@ZenIV.linux.org.uk> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 31, 2018 at 08:19:55PM +0100, Al Viro wrote: > On Fri, May 25, 2018 at 01:07:34AM +0100, David Howells wrote: > > + if (unlikely(file->f_mode & FMODE_NEED_UNMOUNT)) > > + __detach_mounts(dentry); > > + > > This is completely wrong. First of all, you want to dissolve the mount tree > on file->f_path.mount, not every tree rooted at dentry equal to file->f_path.dentry. > This is easily done - it would be a simple call of drop_collected_mounts(mnt) > if not for one detail. You want it to happen only if the sucker isn't attached > anywhere by that point. IOW, > namespace_lock(); > lock_mount_hash(); > if (!real_mount(mnt)->mnt_ns) > umount_tree(real_mount(mnt), UMOUNT_SYNC); > unlock_mount_hash(); > namespace_unlock(); > and that's it. You don't need that magical mystery turd in move_mount() later > in the series and all the infrastructure you grow for it. > > FWIW, I would've suggested this > void drop_collected_mounts(struct vfsmount *mnt) > { > namespace_lock(); > lock_mount_hash(); > + if (!real_mount(mnt)->mnt_ns) > + umount_tree(real_mount(mnt), UMOUNT_SYNC); > - umount_tree(real_mount(mnt), UMOUNT_SYNC); > unlock_mount_hash(); > namespace_unlock(); > } > > and in __fput() > if (unlikely(file->f_mode & FMODE_NEED_UNMOUNT)) > drop_collected_mounts(mnt); > > All there is to it, AFAICS... ... and that eliminates #27 and #28 entirely, with #31 becoming simpler - no move_mount_lookup(), no dfd_ref, the check in do_move_mount() becomes + if (!mnt_has_parent(old) && old->mnt_ns) { + /* We need to allow open(O_PATH|O_CLONE_MOUNT) or fsmount() + * followed by move_mount(), but mustn't allow "/" to be moved. + */ + goto out1; + } and I wouldn't be surprised if move_mount_old()/move_mount() split turns out to be not needed at all, seeing that the whole "clear FMODE_NEED_UNMOUNT on success" part goes away.