From patchwork Thu Sep 21 07:03:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 13394327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 937EDE7D0A5 for ; Thu, 21 Sep 2023 18:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbjIUS5U (ORCPT ); Thu, 21 Sep 2023 14:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjIUS46 (ORCPT ); Thu, 21 Sep 2023 14:56:58 -0400 X-Greylist: delayed 60 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 21 Sep 2023 11:51:05 PDT Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D006E8D9FB; Thu, 21 Sep 2023 11:51:05 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 1D1AF100572; Thu, 21 Sep 2023 17:03:35 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rnrQDSauchoq; Thu, 21 Sep 2023 17:03:35 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 133D5100544; Thu, 21 Sep 2023 17:03:35 +1000 (AEST) Received: from donald.themaw.net (180-150-90-198.b4965a.per.nbn.aussiebb.net [180.150.90.198]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 7F4CA100223; Thu, 21 Sep 2023 17:03:33 +1000 (AEST) Subject: [PATCH 1/8] autofs: refactor autofs_prepare_pipe() From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Date: Thu, 21 Sep 2023 15:03:33 +0800 Message-ID: <169527981274.27328.17552761781465494402.stgit@donald.themaw.net> In-Reply-To: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> References: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Refactor autofs_prepare_pipe() by seperating out a check function to be used later. Signed-off-by: Ian Kent --- fs/autofs/autofs_i.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/autofs/autofs_i.h b/fs/autofs/autofs_i.h index d5a44fa88acf..c24d32be7937 100644 --- a/fs/autofs/autofs_i.h +++ b/fs/autofs/autofs_i.h @@ -209,12 +209,20 @@ int autofs_fill_super(struct super_block *, void *, int); struct autofs_info *autofs_new_ino(struct autofs_sb_info *); void autofs_clean_ino(struct autofs_info *); -static inline int autofs_prepare_pipe(struct file *pipe) +static inline int autofs_check_pipe(struct file *pipe) { if (!(pipe->f_mode & FMODE_CAN_WRITE)) return -EINVAL; if (!S_ISFIFO(file_inode(pipe)->i_mode)) return -EINVAL; + return 0; +} + +static inline int autofs_prepare_pipe(struct file *pipe) +{ + int ret = autofs_check_pipe(pipe); + if (ret < 0) + return ret; /* We want a packet pipe */ pipe->f_flags |= O_DIRECT; /* We don't expect -EAGAIN */ From patchwork Thu Sep 21 07:03:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 13394328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E03AE7D0A2 for ; Thu, 21 Sep 2023 18:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230376AbjIUS5V (ORCPT ); Thu, 21 Sep 2023 14:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229513AbjIUS5A (ORCPT ); Thu, 21 Sep 2023 14:57:00 -0400 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F1258DEFE; Thu, 21 Sep 2023 11:51:05 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 70527100580; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AAGMtsSZ3NHu; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 67A5C10057F; Thu, 21 Sep 2023 17:03:40 +1000 (AEST) Received: from donald.themaw.net (180-150-90-198.b4965a.per.nbn.aussiebb.net [180.150.90.198]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 8AFA9100265; Thu, 21 Sep 2023 17:03:39 +1000 (AEST) Subject: [PATCH 2/8] autofs: add autofs_parse_fd() From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Date: Thu, 21 Sep 2023 15:03:39 +0800 Message-ID: <169527981914.27328.15182386732807940466.stgit@donald.themaw.net> In-Reply-To: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> References: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Factor out the fd mount option handling. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index 2b49662ed237..e279e275b0a5 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -129,6 +129,33 @@ static const match_table_t tokens = { {Opt_err, NULL} }; +static int autofs_parse_fd(struct autofs_sb_info *sbi, int fd) +{ + struct file *pipe; + int ret; + + pipe = fget(fd); + if (!pipe) { + pr_err("could not open pipe file descriptor\n"); + return -EBADF; + } + + ret = autofs_check_pipe(pipe); + if (ret < 0) { + pr_err("Invalid/unusable pipe\n"); + fput(pipe); + return -EBADF; + } + + if (sbi->pipe) + fput(sbi->pipe); + + sbi->pipefd = fd; + sbi->pipe = pipe; + + return 0; +} + static int parse_options(char *options, struct inode *root, int *pgrp, bool *pgrp_set, struct autofs_sb_info *sbi) @@ -139,6 +166,7 @@ static int parse_options(char *options, int pipefd = -1; kuid_t uid; kgid_t gid; + int ret; root->i_uid = current_uid(); root->i_gid = current_gid(); @@ -162,7 +190,9 @@ static int parse_options(char *options, case Opt_fd: if (match_int(args, &pipefd)) return 1; - sbi->pipefd = pipefd; + ret = autofs_parse_fd(sbi, pipefd); + if (ret) + return 1; break; case Opt_uid: if (match_int(args, &option)) @@ -222,7 +252,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) { struct inode *root_inode; struct dentry *root; - struct file *pipe; struct autofs_sb_info *sbi; struct autofs_info *ino; int pgrp = 0; @@ -275,7 +304,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) ret = -ENOMEM; goto fail_ino; } - pipe = NULL; root->d_fsdata = ino; @@ -321,16 +349,7 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) pr_debug("pipe fd = %d, pgrp = %u\n", sbi->pipefd, pid_nr(sbi->oz_pgrp)); - pipe = fget(sbi->pipefd); - if (!pipe) { - pr_err("could not open pipe file descriptor\n"); - goto fail_put_pid; - } - ret = autofs_prepare_pipe(pipe); - if (ret < 0) - goto fail_fput; - sbi->pipe = pipe; sbi->flags &= ~AUTOFS_SBI_CATATONIC; /* @@ -342,11 +361,6 @@ int autofs_fill_super(struct super_block *s, void *data, int silent) /* * Failure ... clean up. */ -fail_fput: - pr_err("pipe file descriptor does not contain proper ops\n"); - fput(pipe); -fail_put_pid: - put_pid(sbi->oz_pgrp); fail_dput: dput(root); goto fail_free; From patchwork Thu Sep 21 07:03:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 13394329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88751E7D0A6 for ; Thu, 21 Sep 2023 18:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230492AbjIUS5Y (ORCPT ); Thu, 21 Sep 2023 14:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjIUS5A (ORCPT ); Thu, 21 Sep 2023 14:57:00 -0400 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 431708FB3E; Thu, 21 Sep 2023 11:51:05 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 7F837100321; Thu, 21 Sep 2023 17:03:46 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cS9HrQngyQhG; Thu, 21 Sep 2023 17:03:46 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 7620310056B; Thu, 21 Sep 2023 17:03:46 +1000 (AEST) Received: from donald.themaw.net (180-150-90-198.b4965a.per.nbn.aussiebb.net [180.150.90.198]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id A40B81002AE; Thu, 21 Sep 2023 17:03:45 +1000 (AEST) Subject: [PATCH 3/8] autofs - refactor super block info init From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Date: Thu, 21 Sep 2023 15:03:45 +0800 Message-ID: <169527982522.27328.18413711550740966247.stgit@donald.themaw.net> In-Reply-To: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> References: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Move the allocation and initialisation of the super block info struct to its own function. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index e279e275b0a5..992d6cb29707 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -171,11 +171,6 @@ static int parse_options(char *options, root->i_uid = current_uid(); root->i_gid = current_gid(); - sbi->min_proto = AUTOFS_MIN_PROTO_VERSION; - sbi->max_proto = AUTOFS_MAX_PROTO_VERSION; - - sbi->pipefd = -1; - if (!options) return 1; @@ -248,41 +243,49 @@ static int parse_options(char *options, return (sbi->pipefd < 0); } -int autofs_fill_super(struct super_block *s, void *data, int silent) +static struct autofs_sb_info *autofs_alloc_sbi(void) { - struct inode *root_inode; - struct dentry *root; struct autofs_sb_info *sbi; - struct autofs_info *ino; - int pgrp = 0; - bool pgrp_set = false; - int ret = -EINVAL; sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); if (!sbi) - return -ENOMEM; - pr_debug("starting up, sbi = %p\n", sbi); + return NULL; - s->s_fs_info = sbi; sbi->magic = AUTOFS_SBI_MAGIC; - sbi->pipefd = -1; - sbi->pipe = NULL; - sbi->exp_timeout = 0; - sbi->oz_pgrp = NULL; - sbi->sb = s; - sbi->version = 0; - sbi->sub_version = 0; sbi->flags = AUTOFS_SBI_CATATONIC; + sbi->min_proto = AUTOFS_MIN_PROTO_VERSION; + sbi->max_proto = AUTOFS_MAX_PROTO_VERSION; + sbi->pipefd = -1; + set_autofs_type_indirect(&sbi->type); - sbi->min_proto = 0; - sbi->max_proto = 0; mutex_init(&sbi->wq_mutex); mutex_init(&sbi->pipe_mutex); spin_lock_init(&sbi->fs_lock); - sbi->queues = NULL; spin_lock_init(&sbi->lookup_lock); INIT_LIST_HEAD(&sbi->active_list); INIT_LIST_HEAD(&sbi->expiring_list); + + return sbi; +} + +int autofs_fill_super(struct super_block *s, void *data, int silent) +{ + struct inode *root_inode; + struct dentry *root; + struct autofs_sb_info *sbi; + struct autofs_info *ino; + int pgrp = 0; + bool pgrp_set = false; + int ret = -EINVAL; + + sbi = autofs_alloc_sbi(); + if (!sbi) + return -ENOMEM; + + pr_debug("starting up, sbi = %p\n", sbi); + + sbi->sb = s; + s->s_fs_info = sbi; s->s_blocksize = 1024; s->s_blocksize_bits = 10; s->s_magic = AUTOFS_SUPER_MAGIC; From patchwork Thu Sep 21 07:03:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 13394330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B26FE7D0A5 for ; Thu, 21 Sep 2023 18:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbjIUS5W (ORCPT ); Thu, 21 Sep 2023 14:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbjIUS5B (ORCPT ); Thu, 21 Sep 2023 14:57:01 -0400 Received: from smtp01.aussiebb.com.au (smtp01.aussiebb.com.au [IPv6:2403:5800:3:25::1001]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F8938ED43; Thu, 21 Sep 2023 11:51:05 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id 8F65910057C; Thu, 21 Sep 2023 17:03:52 +1000 (AEST) X-Virus-Scanned: Debian amavisd-new at smtp01.aussiebb.com.au Received: from smtp01.aussiebb.com.au ([127.0.0.1]) by localhost (smtp01.aussiebb.com.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eCRW0MMXS3Y8; Thu, 21 Sep 2023 17:03:52 +1000 (AEST) Received: by smtp01.aussiebb.com.au (Postfix, from userid 116) id 8835810057F; Thu, 21 Sep 2023 17:03:52 +1000 (AEST) Received: from donald.themaw.net (180-150-90-198.b4965a.per.nbn.aussiebb.net [180.150.90.198]) by smtp01.aussiebb.com.au (Postfix) with ESMTP id BC87F100265; Thu, 21 Sep 2023 17:03:51 +1000 (AEST) Subject: [PATCH 4/8] autofs: reformat 0pt enum declaration From: Ian Kent To: Al Viro , Christian Brauner Cc: autofs mailing list , linux-fsdevel , Kernel Mailing List , Bill O'Donnell , Miklos Szeredi , David Howells Date: Thu, 21 Sep 2023 15:03:51 +0800 Message-ID: <169527983132.27328.10535655381168506781.stgit@donald.themaw.net> In-Reply-To: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> References: <169527971702.27328.16272807830250040704.stgit@donald.themaw.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The enum of options is only reformated in the patch to convert autofs to use the mount API so do that now to simplify the conversion patch. Signed-off-by: Ian Kent --- fs/autofs/inode.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/autofs/inode.c b/fs/autofs/inode.c index 992d6cb29707..d2b333c0682a 100644 --- a/fs/autofs/inode.c +++ b/fs/autofs/inode.c @@ -110,9 +110,20 @@ static const struct super_operations autofs_sops = { .evict_inode = autofs_evict_inode, }; -enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, - Opt_indirect, Opt_direct, Opt_offset, Opt_strictexpire, - Opt_ignore}; +enum { + Opt_err, + Opt_direct, + Opt_fd, + Opt_gid, + Opt_ignore, + Opt_indirect, + Opt_maxproto, + Opt_minproto, + Opt_offset, + Opt_pgrp, + Opt_strictexpire, + Opt_uid, +}; static const match_table_t tokens = { {Opt_fd, "fd=%u"},