autofs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] autofs - convert to to use mount api
@ 2023-09-21  7:03 Ian Kent
  2023-09-21  7:03 ` [PATCH 1/8] autofs: refactor autofs_prepare_pipe() Ian Kent
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21  7:03 UTC (permalink / raw)
  To: Al Viro, Christian Brauner
  Cc: autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

There was a patch from David Howells to convert autofs to use the mount
api but it was never merged.

I have taken David's patch and refactored it to make the change easier
to review in the hope of having it merged.

Signed-off-by: Ian Kent <raven@themaw.net>
---

Ian Kent (8):
      autofs: refactor autofs_prepare_pipe()
      autofs: add autofs_parse_fd()
      autofs - refactor super block info init
      autofs: reformat 0pt enum declaration
      autofs: refactor parse_options()
      autofs: validate protocol version
      autofs: convert autofs to use the new mount api
      autofs: fix protocol sub version setting


 fs/autofs/autofs_i.h |  15 +-
 fs/autofs/init.c     |   9 +-
 fs/autofs/inode.c    | 423 +++++++++++++++++++++++++------------------
 3 files changed, 266 insertions(+), 181 deletions(-)

--
Ian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/8] autofs: refactor autofs_prepare_pipe()
  2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
@ 2023-09-21  7:03 ` Ian Kent
  2023-09-21  7:03 ` [PATCH 2/8] autofs: add autofs_parse_fd() Ian Kent
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21  7:03 UTC (permalink / raw)
  To: Al Viro, Christian Brauner
  Cc: autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

Refactor autofs_prepare_pipe() by seperating out a check function
to be used later.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 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 */



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/8] autofs: add autofs_parse_fd()
  2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
  2023-09-21  7:03 ` [PATCH 1/8] autofs: refactor autofs_prepare_pipe() Ian Kent
@ 2023-09-21  7:03 ` Ian Kent
  2023-09-21  7:03 ` [PATCH 3/8] autofs - refactor super block info init Ian Kent
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21  7:03 UTC (permalink / raw)
  To: Al Viro, Christian Brauner
  Cc: autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

Factor out the fd mount option handling.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 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;



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/8] autofs - refactor super block info init
  2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
  2023-09-21  7:03 ` [PATCH 1/8] autofs: refactor autofs_prepare_pipe() Ian Kent
  2023-09-21  7:03 ` [PATCH 2/8] autofs: add autofs_parse_fd() Ian Kent
@ 2023-09-21  7:03 ` Ian Kent
  2023-09-21  7:03 ` [PATCH 4/8] autofs: reformat 0pt enum declaration Ian Kent
  2023-09-21  9:13 ` [PATCH 0/8] autofs - convert to to use mount api Christian Brauner
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21  7:03 UTC (permalink / raw)
  To: Al Viro, Christian Brauner
  Cc: autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

Move the allocation and initialisation of the super block
info struct to its own function.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 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;



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/8] autofs: reformat 0pt enum declaration
  2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
                   ` (2 preceding siblings ...)
  2023-09-21  7:03 ` [PATCH 3/8] autofs - refactor super block info init Ian Kent
@ 2023-09-21  7:03 ` Ian Kent
  2023-09-21  9:13 ` [PATCH 0/8] autofs - convert to to use mount api Christian Brauner
  4 siblings, 0 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21  7:03 UTC (permalink / raw)
  To: Al Viro, Christian Brauner
  Cc: autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

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 <raven@themaw.net>
---
 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"},



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/8] autofs - convert to to use mount api
  2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
                   ` (3 preceding siblings ...)
  2023-09-21  7:03 ` [PATCH 4/8] autofs: reformat 0pt enum declaration Ian Kent
@ 2023-09-21  9:13 ` Christian Brauner
  2023-09-21 12:35   ` Ian Kent
  4 siblings, 1 reply; 7+ messages in thread
From: Christian Brauner @ 2023-09-21  9:13 UTC (permalink / raw)
  To: Ian Kent
  Cc: Al Viro, autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells

On Thu, Sep 21, 2023 at 03:03:26PM +0800, Ian Kent wrote:
> There was a patch from David Howells to convert autofs to use the mount
> api but it was never merged.
> 
> I have taken David's patch and refactored it to make the change easier
> to review in the hope of having it merged.
> 
> Signed-off-by: Ian Kent <raven@themaw.net>
> ---
> 
> Ian Kent (8):
>       autofs: refactor autofs_prepare_pipe()
>       autofs: add autofs_parse_fd()
>       autofs - refactor super block info init
>       autofs: reformat 0pt enum declaration
>       autofs: refactor parse_options()
>       autofs: validate protocol version
>       autofs: convert autofs to use the new mount api
>       autofs: fix protocol sub version setting
> 

Yeah sure, but I only see 4 patches on the list? Is my setup broken or
did you accidently forget to send some patches?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/8] autofs - convert to to use mount api
  2023-09-21  9:13 ` [PATCH 0/8] autofs - convert to to use mount api Christian Brauner
@ 2023-09-21 12:35   ` Ian Kent
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Kent @ 2023-09-21 12:35 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Al Viro, autofs mailing list, linux-fsdevel, Kernel Mailing List,
	Bill O'Donnell, Miklos Szeredi, David Howells


On 21/9/23 17:13, Christian Brauner wrote:
> On Thu, Sep 21, 2023 at 03:03:26PM +0800, Ian Kent wrote:
>> There was a patch from David Howells to convert autofs to use the mount
>> api but it was never merged.
>>
>> I have taken David's patch and refactored it to make the change easier
>> to review in the hope of having it merged.
>>
>> Signed-off-by: Ian Kent <raven@themaw.net>
>> ---
>>
>> Ian Kent (8):
>>        autofs: refactor autofs_prepare_pipe()
>>        autofs: add autofs_parse_fd()
>>        autofs - refactor super block info init
>>        autofs: reformat 0pt enum declaration
>>        autofs: refactor parse_options()
>>        autofs: validate protocol version
>>        autofs: convert autofs to use the new mount api
>>        autofs: fix protocol sub version setting
>>
> Yeah sure, but I only see 4 patches on the list? Is my setup broken or
> did you accidently forget to send some patches?

Sorry, but no, my email has gone very pair shaped.


The above send failed part way through and I haven't been able to send

anything via the command line since. I'm guessing the email app I'm

using to send this will work and the other email accounts I use will

probably work from an app too but the command line is broken for some

unknown reason.


Please ignore these, I'll send them when I can get my problem fixed ...

*sigh*!


Ian


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-21 12:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21  7:03 [PATCH 0/8] autofs - convert to to use mount api Ian Kent
2023-09-21  7:03 ` [PATCH 1/8] autofs: refactor autofs_prepare_pipe() Ian Kent
2023-09-21  7:03 ` [PATCH 2/8] autofs: add autofs_parse_fd() Ian Kent
2023-09-21  7:03 ` [PATCH 3/8] autofs - refactor super block info init Ian Kent
2023-09-21  7:03 ` [PATCH 4/8] autofs: reformat 0pt enum declaration Ian Kent
2023-09-21  9:13 ` [PATCH 0/8] autofs - convert to to use mount api Christian Brauner
2023-09-21 12:35   ` Ian Kent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).