Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1693282rdh; Mon, 25 Sep 2023 23:58:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgJKiZxQyIIg+dve6Eq64EXdLswVLbcsDg2sm33pbrFt3xT0Dx3rKgLK7xawPoRy1jYvYy X-Received: by 2002:a05:6a21:33a7:b0:13c:ca8b:7e29 with SMTP id yy39-20020a056a2133a700b0013cca8b7e29mr11017821pzb.12.1695711525072; Mon, 25 Sep 2023 23:58:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695711525; cv=none; d=google.com; s=arc-20160816; b=0c5Atsirkf7m6KtudksU5c0WS4WFURC2fza/3m5D8o8SBfmhM91o6LixAYW/CFsbkR 7ucTvEdlL+mmYJ5KuYJDIBE37pW4Kis/AWSjpam7iOqev5sTnWOPhYb8hxVmwOiobun1 jQT7XiXidVV0qDTApoasfkA74X5f8saiyCqlCZEsV6tDpg40zWgiUQBNjPgTB7tmDrxb pocKYVfBrotqHaJZLXeBARoOUbRfLB4ohP1BFLp9iA8q4+b1MBp7bs/yDuKFZ9m/kpWg DHhrL7JACPSoZCNETdIdhPPD0h4Luz10fJF8Vs/04WlFc3jx654J6Vhi2Q64WyQFUztX kFKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:feedback-id:dkim-signature:dkim-signature; bh=w3s0Dgf7ZNU4pBcYrLEoMk5BLPpr5HzYEj0tCtnwHL8=; fh=C6RLPReLeJjeD69eRrV6sF5wV7dyb6PruEHWMnRJUlE=; b=bzUDxAzMwFkhX95SHbf+IIGj1WJHPFfO7H7Ba1GwE2dK1ym15dFpViLaKXvJEpdJl9 X6xpJ9r0e1CIUtKVHCpM8UVvKqRv2Gl3X+F5sdxZT4GmIRHnaVPtru6JG2Mj48qXo99O EAnECLQi1O2cYQVJF48jmmTFKmv2fYpsUezj6nL3H+Ki/OANEmKLbDDmdqA1mCttEr7X 9wtZvzaVbe6WAr+D7d8C6KiEgANF8BdQzBF5QH9TvZCstNOKbaI4pA/NHH1RSsw8KfNq 8a93hoyNMWuaiMIqUZhLc7aZoSp3G/IUK6NAfzxTslU6h03XjukVAjyjQ7Wb3KqM80jb RqKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@themaw.net header.s=fm1 header.b=OrwFaHnR; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="MYJZ/Ih3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d10-20020a170902654a00b001bb993ef74bsi6755983pln.540.2023.09.25.23.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 23:58:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@themaw.net header.s=fm1 header.b=OrwFaHnR; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="MYJZ/Ih3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2A93B8325D18; Mon, 25 Sep 2023 23:53:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231129AbjIZGxg (ORCPT + 99 others); Tue, 26 Sep 2023 02:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjIZGxe (ORCPT ); Tue, 26 Sep 2023 02:53:34 -0400 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61DE1C0; Mon, 25 Sep 2023 23:53:26 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id D70DE3200924; Tue, 26 Sep 2023 02:53:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 26 Sep 2023 02:53:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1695711204; x=1695797604; bh=w3s0Dgf7ZNU4pBcYrLEoMk5BLPpr5HzYEj0 tCtnwHL8=; b=OrwFaHnR2huHzqN5M4cGl/q50k0Gaiux+4hfqK1Cwn6/S2KepeY i1BG4GMVMNKA5S8r5WcDW0qNBqSDyPlOiM8OCnQLLBuWB2taDL/F74y34rVyYmsB DSgKnbYSLY6FbfCXmE6ZD2UMiberXIZ61hIPc7GMKx8ZKfPmbfFyOSMMuQDUHVCC vEOms7YGCq0WVfApCfCmFe0Ls6qiL1odznLjPGxxvQ9JEDL+ROyI9Z7svycV9el/ qL8BPYfdHsdxYVvn0VVEP4gQzi4E6oyRA0Zz2lX9ys2Iqu/sAv2dY0CZ4+SnuNID 46YagPQdbXyZTPMp0JH5SaRAMlKU66hSLDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1695711204; x=1695797604; bh=w3s0Dgf7ZNU4pBcYrLEoMk5BLPpr5HzYEj0 tCtnwHL8=; b=MYJZ/Ih3sT+asgkdHIMNEHof9hdX3Wx2yAiWt362TSlAb4jxsm1 Ls8gESQ4gjQmDo8/I0AGmnB3qQvwKCQw0u4pAnpcgpqcxEWsEOBTiHB4JPHAUhLB 4jso48HXyJCzBqVDdxZfnHQF8suqXQrnfrYK/hrU3nspH+BVaUfaV7UyrNEMIg5O Jit9b54cGQtlxkkPIxqxHyucaZIh5NRL3/c5qHs4O6+Yh9K3csSUoC4R3G20UwnX fEvaa9RkWU6ycnoYGPUTKbq2ulWJechpzIkDnK9xnAUJRNhEPB7P4XQpzb77SLWV pHjGxl/9H5YId9mRLLt7W5C8Y7QDX7AZOmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudelhedgudduvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuhffvvehfjggtgfesthekredttdefjeenucfhrhhomhepkfgr nhcumfgvnhhtuceorhgrvhgvnhesthhhvghmrgifrdhnvghtqeenucggtffrrghtthgvrh hnpeeiveelkefgtdegudefudeftdelteejtedvheeuleevvdeluefhuddtieegveelkeen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrrghvvg hnsehthhgvmhgrfidrnhgvth X-ME-Proxy: Feedback-ID: i31e841b0:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Sep 2023 02:53:21 -0400 (EDT) Message-ID: Date: Tue, 26 Sep 2023 14:53:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 7/8] autofs: convert autofs to use the new mount api Content-Language: en-US From: Ian Kent To: Christian Brauner Cc: Al Viro , autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells References: <20230922041215.13675-1-raven@themaw.net> <20230922041215.13675-8-raven@themaw.net> <20230922-vorbringen-spaghetti-946729122076@brauner> <7121dcf7-23fe-07a5-9df4-9ea7af6f5964@themaw.net> In-Reply-To: <7121dcf7-23fe-07a5-9df4-9ea7af6f5964@themaw.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 23:53:50 -0700 (PDT) On 22/9/23 21:27, Ian Kent wrote: > On 22/9/23 19:59, Christian Brauner wrote: >>> +    fsparam_fd    ("fd", Opt_fd), >>> +/* >>> + * Open the fd.  We do it here rather than in get_tree so that it's >>> done in the >>> + * context of the system call that passed the data and not the one >>> that >>> + * triggered the superblock creation, lest the fd gets reassigned. >>> + */ >>> +static int autofs_parse_fd(struct fs_context *fc, int fd) >>>   { >>> +    struct autofs_sb_info *sbi = fc->s_fs_info; >>>       struct file *pipe; >>>       int ret; >>>         pipe = fget(fd); >>>       if (!pipe) { >>> -        pr_err("could not open pipe file descriptor\n"); >>> +        errorf(fc, "could not open pipe file descriptor"); >>>           return -EBADF; >>>       } >>>         ret = autofs_check_pipe(pipe); >>>       if (ret < 0) { >>> -        pr_err("Invalid/unusable pipe\n"); >>> +        errorf(fc, "Invalid/unusable pipe"); >>>           fput(pipe); >>>           return -EBADF; >>>       } >>> +static int autofs_parse_param(struct fs_context *fc, struct >>> fs_parameter *param) >>>   { >>> +        return autofs_parse_fd(fc, result.int_32); >> Mah, so there's a difference between the new and the old mount api >> that we >> should probably hide on the VFS level for fsparam_fd. Basically, if >> you're >> coming through the new mount api via fsconfig(FSCONFIG_SET_FD, fd) >> then the vfs >> will have done param->file = fget(fd) for you already so there's no >> need to >> call fget() again. We can just take ownership of the reference that >> the vfs >> took for us. >> >> But if we're coming in through the old mount api then we need to call >> fget. >> There's nothing wrong with your code but it doesn't take advantage of >> the new >> mount api which would be unfortunate. So I folded a small extension >> into this >> see [1]. >> >> There's an unrelated bug in fs_param_is_fd() that I'm also fixing see >> [2]. > > Ok, that's interesting, I'll have a look at these developments tomorrow, > > admittedly (obviously) I hadn't looked at the code for some time ... This code pattern is a bit unusual, it looks a bit untidy to have different behavior between the two but I expect there was a reason to include the fd handling and have this small difference anyway ... In [2] that's a good catch, I certainly was caught by it, ;( > > > Ian > >> >> I've tested both changes with the old and new mount api. >> >> [1]: >> diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c >> index 3f2dfed428f9..0477bce7d277 100644 >> --- a/fs/autofs/inode.c >> +++ b/fs/autofs/inode.c >> @@ -150,13 +150,20 @@ struct autofs_fs_context { >>    * context of the system call that passed the data and not the one >> that >>    * triggered the superblock creation, lest the fd gets reassigned. >>    */ >> -static int autofs_parse_fd(struct fs_context *fc, int fd) >> +static int autofs_parse_fd(struct fs_context *fc, struct >> autofs_sb_info *sbi, >> +                          struct fs_parameter *param, >> +                          struct fs_parse_result *result) >>   { >> -       struct autofs_sb_info *sbi = fc->s_fs_info; >>          struct file *pipe; >>          int ret; >> >> -       pipe = fget(fd); >> +       if (param->type == fs_value_is_file) { >> +               /* came through the new api */ >> +               pipe = param->file; >> +               param->file = NULL; >> +       } else { >> +               pipe = fget(result->uint_32); >> +       } >>          if (!pipe) { >>                  errorf(fc, "could not open pipe file descriptor"); >>                  return -EBADF; >> @@ -165,14 +172,15 @@ static int autofs_parse_fd(struct fs_context >> *fc, int fd) >>          ret = autofs_check_pipe(pipe); >>          if (ret < 0) { >>                  errorf(fc, "Invalid/unusable pipe"); >> -               fput(pipe); >> +               if (param->type != fs_value_is_file) >> +                       fput(pipe); >>                  return -EBADF; >>          } >> >>          if (sbi->pipe) >>                  fput(sbi->pipe); >> >> -       sbi->pipefd = fd; >> +       sbi->pipefd = result->uint_32; >>          sbi->pipe = pipe; >> >>          return 0; >> >> [2]: >>  From 2f9171200505c82e744a235c85377e36ed190109 Mon Sep 17 00:00:00 2001 >> From: Christian Brauner >> Date: Fri, 22 Sep 2023 13:49:05 +0200 >> Subject: [PATCH] fsconfig: ensure that dirfd is set to aux >> >> The code in fs_param_is_fd() expects param->dirfd to be set to the fd >> that was used to set param->file to initialize result->uint_32. So make >> sure it's set so users like autofs using FSCONFIG_SET_FD with the new >> mount api can rely on this to be set to the correct value. >> >> Signed-off-by: Christian Brauner >> --- >>   fs/fsopen.c | 1 + >>   1 file changed, 1 insertion(+) >> >> diff --git a/fs/fsopen.c b/fs/fsopen.c >> index ce03f6521c88..6593ae518115 100644 >> --- a/fs/fsopen.c >> +++ b/fs/fsopen.c >> @@ -465,6 +465,7 @@ SYSCALL_DEFINE5(fsconfig, >>           param.file = fget(aux); >>           if (!param.file) >>               goto out_key; >> +        param.dirfd = aux; >>           break; >>       default: >>           break;