Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp438425ybg; Tue, 28 Jul 2020 09:38:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMcL7EKwE6dOutEk/rVe8B2AMxwolT55C2EWuStl0ynxGOM1LqCpX7AqwaYaw7AJaiDsEx X-Received: by 2002:a17:907:385:: with SMTP id ss5mr24745094ejb.496.1595954285302; Tue, 28 Jul 2020 09:38:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595954285; cv=none; d=google.com; s=arc-20160816; b=ymbs+yU3lkZ0+QAJkAAlrssWUL30lVWwL5LbUMkiOjy2btgKEPvdaHu9mcS4Zf8+OG 8vNjHGr4kB2BaQOK28lg9iX2QuA1aoc49i2wUoYSbbThkRRGIiXKpddcYgKl970VK4xl IwsXaR/oLhhQdvE06REKWMC01uJce9s4Nb/Bbj5qQLziVVF8bw/h28AsAgt9HlfecN+q 8l9SDLIhEVt+SjdVXVD9p8fET0lzZyVeY4j0QiINYGWLyQfIuyCVT2o/rrV66Og2ftPF OkRo4twWCAuU8KEg32tkmiI24T9coTZfA5zxBv36pBsp9IoFUR//9K0ngRBj3cst/ri6 St+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ePYrotlytJXvI0CdCW3tl0P3sQHCqpS3OjHeAMmpEaE=; b=ZN2Ff3WEj2dAnRcTnZPQcoeMRZ8lnxz9EQsBQ8K+z13L8z1Y7FVWZm4JnyfCphsr16 moLf2F7w5DFPZtiARFb2eIPqMm032NxcSEHAscZLxM77zvrCFdowqEmJbZ3slf6yz2I6 voOcoxU9p1DZ//UgV48NJ5IoHxZRbdyShb5baFXfq5BK744Klg16XJ/c1dqf8oORIvta KSFBoNIJwtcWnxjfznMI078ejugcB7ONDv4wxXAdwszygzyQNUrQ4+r8WCwZ4u42B9S9 wLUpskIABkBCxRe4X2lJRZkwayMqaaV64HgnOQE95/msdbyCpXgKwBUdyDkM45dEtGMs OBUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=sfXNdNHS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s3si692352edy.554.2020.07.28.09.37.43; Tue, 28 Jul 2020 09:38:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=sfXNdNHS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731575AbgG1Qe0 (ORCPT + 99 others); Tue, 28 Jul 2020 12:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731422AbgG1QeZ (ORCPT ); Tue, 28 Jul 2020 12:34:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657C4C0619D2; Tue, 28 Jul 2020 09:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ePYrotlytJXvI0CdCW3tl0P3sQHCqpS3OjHeAMmpEaE=; b=sfXNdNHSuFEovpB8yATS1Pqah4 x2Kk41ftYlNLkrHzw7PiWtbrGa+zcWImnOvwWyXxUMSWcA/Zb4/rNH/9pTzll/I3W03bndgiwaUze FveyJlPXap1sAoKiPpFlCQNXRX5To6jbfYKDOi2tRn6PCvHjLyEy/nOiUVDmW2vKFhp7kr9cLrsG0 /ZGFqwgwprfvCtZHtY1r/dSt7gQxOxiJ8zYDlGLExKx20oDdAg8QurXK9mjgv/BMozSANc05IaeIA ROoyXC38ydo1+nrU070jHdjYH4u1t2OuVVHh8voYYe2cavufBgERY/9a9b9ZuqgrrJ3uKEEFVPfeQ FMhmOoUg==; Received: from [2001:4bb8:180:6102:fd04:50d8:4827:5508] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0SYY-0006wz-6q; Tue, 28 Jul 2020 16:34:22 +0000 From: Christoph Hellwig To: Al Viro , Linus Torvalds Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH 02/23] fs: refactor ksys_umount Date: Tue, 28 Jul 2020 18:33:55 +0200 Message-Id: <20200728163416.556521-3-hch@lst.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728163416.556521-1-hch@lst.de> References: <20200728163416.556521-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out a path_umount helper that takes a struct path * instead of the actual file name. This will allow to convert the init and devtmpfs code to properly mount based on a kernel pointer instead of relying on the implicit set_fs(KERNEL_DS) during early init. Signed-off-by: Christoph Hellwig --- fs/namespace.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 6f8234f74bed90..43834b59eff6c3 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1706,36 +1706,19 @@ static inline bool may_mandlock(void) } #endif -/* - * Now umount can handle mount points as well as block devices. - * This is important for filesystems which use unnamed block devices. - * - * We now support a flag for forced unmount like the other 'big iron' - * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD - */ - -int ksys_umount(char __user *name, int flags) +static int path_umount(struct path *path, int flags) { - struct path path; struct mount *mnt; int retval; - int lookup_flags = LOOKUP_MOUNTPOINT; if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW)) return -EINVAL; - if (!may_mount()) return -EPERM; - if (!(flags & UMOUNT_NOFOLLOW)) - lookup_flags |= LOOKUP_FOLLOW; - - retval = user_path_at(AT_FDCWD, name, lookup_flags, &path); - if (retval) - goto out; - mnt = real_mount(path.mnt); + mnt = real_mount(path->mnt); retval = -EINVAL; - if (path.dentry != path.mnt->mnt_root) + if (path->dentry != path->mnt->mnt_root) goto dput_and_out; if (!check_mnt(mnt)) goto dput_and_out; @@ -1748,12 +1731,25 @@ int ksys_umount(char __user *name, int flags) retval = do_umount(mnt, flags); dput_and_out: /* we mustn't call path_put() as that would clear mnt_expiry_mark */ - dput(path.dentry); + dput(path->dentry); mntput_no_expire(mnt); -out: return retval; } +int ksys_umount(char __user *name, int flags) +{ + int lookup_flags = LOOKUP_MOUNTPOINT; + struct path path; + int ret; + + if (!(flags & UMOUNT_NOFOLLOW)) + lookup_flags |= LOOKUP_FOLLOW; + ret = user_path_at(AT_FDCWD, name, lookup_flags, &path); + if (ret) + return ret; + return path_umount(&path, flags); +} + SYSCALL_DEFINE2(umount, char __user *, name, int, flags) { return ksys_umount(name, flags); -- 2.27.0