autofs4 - correct offset mount expire check
Subsystems (2)
Ian Kent
maintainerPATCH 1/6 autofs4 - correct offset mount expire check
When checking a directory tree in autofs_tree_busy() we can incorrectly decide that the tree isn't busy. This happens for the case of an active offset mount as autofs4_follow_mount() follows past the active offset mount, which has an open file handle used for expires, causing the file handle not to count toward the busyness check.
---
fs/autofs4/expire.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-)
fs/autofs4/expire.c +15 -4
@@ -56,12 +56,23 @@ static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)mntget (mnt);dget (dentry); -if (!autofs4_follow_mount (&mnt, &dentry)) +if (!follow_down (&mnt, &dentry)) goto done; -/* This is an autofs submount, we can't expire it */ -if (is_autofs4_dentry (dentry)) - goto done; +if (is_autofs4_dentry (dentry)) { +struct autofs_sb_info *sbi =autofs4_sbi (dentry->d_sb); + +/* This is an autofs submount, we can't expire it */ +if (sbi->type ==AUTOFS_TYPE_INDIRECT ) + goto done; + +/* +* Otherwise it's an offset mount and we need to check +* if we can umount its mount, if there is one. +*/ +if (!d_mountpoint (dentry)) + goto done; + }/* Update the expiry counter if fs is busy */ if (!may_umount_tree (mnt)) {
Ian Kent
maintainerPATCH 2/6 autofs4 - remove string terminator check
Remove unnecessary string terminator check.
---
fs/autofs4/dev-ioctl.c | 20 -------------------- 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -20
@@ -51,18 +51,6 @@ static int check_name(const char *name) }/* -* Check a string doesn't overrun the chunk of -* memory we copied from user land. -*/ -static int invalid_str (char *str,void *end) -{ -while ((void *) str <= end) -if (!*str++) -return 0 ; -return -EINVAL ; -} - -/* * Check that the user compiled against correct version of autofs * misc device code. *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) cmd); goto out; } - - err =invalid_str (param->path, - (void *) ((size_t ) param + param->size)); -if (err) { -AUTOFS_WARN ("invalid path supplied for cmd(0x%08x)" , - cmd); - goto out; - } } err =0 ;
Re: [PATCH 2/6] autofs4 - remove string terminator check
Quoted 1 line · On Thu, 23 Oct 2008 10:35:22 +0800 Ian Kent <[email protected]> wrote:
Remove unnecessary string terminator check.
Why is it unnecessary?
Does this change alter behaviour in any way?
Does it fix a bug?
Better changelogs, please....
Quoted 36 lines
fs/autofs4/dev-ioctl.c +0
-20@@ -51,18 +51,6 @@ static int check_name(const char *name) }/* -* Check a string doesn't overrun the chunk of -* memory we copied from user land. -*/ -static int invalid_str (char *str,void *end) -{ -while ((void *) str <= end) -if (!*str++) -return 0 ; -return -EINVAL ; -} - -/* * Check that the user compiled against correct version of autofs * misc device code. * @@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) cmd); goto out; } - - err =invalid_str (param->path, - (void *) ((size_t ) param + param->size)); -if (err) { -AUTOFS_WARN ("invalid path supplied for cmd(0x%08x)" , - cmd); - goto out; - } } err =0 ;
Ian Kent
maintainerRe: [PATCH 2/6] autofs4 - remove string terminator check
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Thu, 23 Oct 2008 10:35:22 +0800 Ian Kent <[email protected]> wrote:
Remove unnecessary string terminator check.
Why is it unnecessary?
Does this change alter behaviour in any way?
Does it fix a bug?
Umm .... it was done in response to your comment, quoted below ...
Review
Quoted 11 lines
(quoted diff) +11
-0+/* + * Check a string doesn't overrun the chunk of + * memory we copied from user land. + */ +static int invalid_str(char *str, void *end) +{ + while ((void *) str <= end) + if (!*str++) + return 0; + return -EINVAL; +}
What is this? We copy strings in from userspace in 10000 different places without needing checks such as this?
Quoted 39 lines
Better changelogs, please....
Quoted 36 lines
fs/autofs4/dev-ioctl.c +0
-20@@ -51,18 +51,6 @@ static int check_name(const char *name) }/* -* Check a string doesn't overrun the chunk of -* memory we copied from user land. -*/ -static int invalid_str (char *str,void *end) -{ -while ((void *) str <= end) -if (!*str++) -return 0 ; -return -EINVAL ; -} - -/* * Check that the user compiled against correct version of autofs * misc device code. * @@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) cmd); goto out; } - - err =invalid_str (param->path, - (void *) ((size_t ) param + param->size)); -if (err) { -AUTOFS_WARN ("invalid path supplied for cmd(0x%08x)" , - cmd); - goto out; - } } err =0 ;
Re: [PATCH 2/6] autofs4 - remove string terminator check
Quoted 6 lines · On Tue, 28 Oct 2008 09:27:02 +0900 Ian Kent <[email protected]> wrote:
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Thu, 23 Oct 2008 10:35:22 +0800 Ian Kent <[email protected]> wrote:
Remove unnecessary string terminator check.
Quoted 7 lines
Quoted 5 lines
Why is it unnecessary?
Does this change alter behaviour in any way?
Does it fix a bug?
Umm .... it was done in response to your comment, quoted below ...
umm, the number of patches I've handled recently overflowed a u16. Please don't rely on my memory! Plus "read akpm's mind" isn't a very useful changelog.
Please send a new and complete changelog for this patch?
Ian Kent
maintainerRe: [PATCH 2/6] autofs4 - remove string terminator check
Quoted 15 lines · Andrew Morton
Quoted 12 lines · On Tue, 28 Oct 2008 09:27:02 +0900 Ian Kent <[email protected]> wrote:
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Thu, 23 Oct 2008 10:35:22 +0800 Ian Kent <[email protected]> wrote:
Remove unnecessary string terminator check.
Why is it unnecessary?
Does this change alter behaviour in any way?
Does it fix a bug?
Quoted 7 lines
Quoted 1 line
Umm .... it was done in response to your comment, quoted below ...
umm, the number of patches I've handled recently overflowed a u16. Please don't rely on my memory! Plus "read akpm's mind" isn't a very useful changelog.
Please send a new and complete changelog for this patch?
OK, a resend will be done.
Ian
Ian Kent
maintainerRe: [PATCH 2/6] autofs4 - remove string terminator check
In reply to Ian KentThis response is a bit confusing, let me try to fix that.
Quoted 6 lines · Ian Kent
Quoted 5 lines · Andrew Morton
Quoted 1 line · On Thu, 23 Oct 2008 10:35:22 +0800 Ian Kent <[email protected]> wrote:
Remove unnecessary string terminator check.
Quoted 8 lines
Quoted 5 lines
Why is it unnecessary?
Does this change alter behaviour in any way?
Does it fix a bug?
Umm .... it was done in response to your comment, quoted below ...
<quote>
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+/* + * Check a string doesn't overrun the chunk of + * memory we copied from user land. + */ +static int invalid_str(char *str, void *end) +{
Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ while ((void *) str <= end) + if (!*str++) + return 0; + return -EINVAL; +}What is this? We copy strings in from userspace in 10000 different places without needing checks such as this?
</quote>
Ian Kent
maintainerPATCH 3/6 autofs4 - collect version check return
In reply to Ian KentThe function check_dev_ioctl_version() returns an error code upon fail but it isn't captured and returned in validate_dev_ioctl() as it should be.
---
fs/autofs4/dev-ioctl.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/autofs4/dev-ioctl.c +2 -2
@@ -116,9 +116,9 @@ static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)*/ static int validate_dev_ioctl (int cmd,struct autofs_dev_ioctl *param) { -int err = -EINVAL ; +int err; -if (check_dev_ioctl_version (cmd, param)) { +if ((err =check_dev_ioctl_version (cmd, param))) {AUTOFS_WARN ("invalid device control module version " "supplied for cmd(0x%08x)" , cmd); goto out;
Ian Kent
maintainerPATCH 4/6 autofs4 - make autofs type usage explicit
In reply to Ian KentThis patch further improves autofs mount type usage and provides supplementry explanation of the changes made in the previous patch "autofs4 - cleanup autofs mount type usage".
Changes introduced in "autofs4 - cleanup autofs mount type usage":
- the type assigned at mount when no type is given is changed from 0 to AUTOFS_TYPE_INDIRECT. This was done because 0 and AUTOFS_TYPE_INDIRECT were being treated implicitly as the same type.
- previously, an offset mount had it's type set to AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET but the mount control re-implementation needs to be able distinguish all three types. So this was changed to make the type setting explicit.
- a type AUTOFS_TYPE_ANY was added for use by the re-implementation when checking if a given path is a mountpoint. It's not really a type as we use this to ask if a given path is a mountpoint in the autofs_dev_ioctl_ismountpoint() function.
Changes introduced in this patch:
- macros to set and test the autofs mount types have been added to improve readability and make the type usage explicit.
- the mount type is used from user space for the mount control re-implementtion so, for consistency, all the definitions have been moved to the user space include file include/linux/auto_fs4.h.
---
fs/autofs4/autofs_i.h | 2 -- fs/autofs4/dev-ioctl.c | 4 ++-- fs/autofs4/expire.c | 4 ++-- fs/autofs4/inode.c | 14 +++++++------- fs/autofs4/waitq.c | 8 ++++---- include/linux/auto_fs4.h | 28 ++++++++++++++++++++++++---- 6 files changed, 39 insertions(+), 21 deletions(-)
fs/autofs4/autofs_i.h +0 -2
@@ -25,8 +25,6 @@#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11) -#define AUTOFS_TYPE_TRIGGER (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET) -#include <linux/kernel.h> #include <linux/slab.h> #include <linux/time.h>
fs/autofs4/dev-ioctl.c +2 -2
@@ -510,7 +510,7 @@ static int autofs_dev_ioctl_expire(struct file *fp, how = param->arg1; mnt = fp->f_path.mnt; -if (sbi->type &AUTOFS_TYPE_TRIGGER ) +if (autofs_type_trigger (sbi->type)) dentry =autofs4_expire_direct (sbi->sb, mnt, sbi, how);else dentry =autofs4_expire_indirect (sbi->sb, mnt, sbi, how);
@@ -592,7 +592,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, param->arg2 =0 ;if (!fp || param->ioctlfd ==-1 ) { -if (type ==AUTOFS_TYPE_ANY ) { +if (autofs_type_any (type)) {struct super_block *sb; err =path_lookup (path,LOOKUP_FOLLOW , &nd);
fs/autofs4/expire.c +2 -2
@@ -63,7 +63,7 @@ static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)struct autofs_sb_info *sbi =autofs4_sbi (dentry->d_sb);/* This is an autofs submount, we can't expire it */ -if (sbi->type ==AUTOFS_TYPE_INDIRECT ) +if (autofs_type_indirect (sbi->type)) goto done;/*
@@ -490,7 +490,7 @@ int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,if (arg &&get_user (do_now, arg))return -EFAULT ; -if (sbi->type &AUTOFS_TYPE_TRIGGER ) +if (autofs_type_trigger (sbi->type)) dentry =autofs4_expire_direct (sb, mnt, sbi, do_now);else dentry =autofs4_expire_indirect (sb, mnt, sbi, do_now);
fs/autofs4/inode.c +7 -7
@@ -197,9 +197,9 @@ static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)seq_printf (m,",minproto=%d" , sbi->min_proto);seq_printf (m,",maxproto=%d" , sbi->max_proto); -if (sbi->type &AUTOFS_TYPE_OFFSET ) +if (autofs_type_offset (sbi->type))seq_printf (m,",offset" ); -else if (sbi->type &AUTOFS_TYPE_DIRECT ) +else if (autofs_type_direct (sbi->type))seq_printf (m,",direct" );else seq_printf (m,",indirect" );
@@ -284,13 +284,13 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, *maxproto = option;break ;case Opt_indirect: - *type =AUTOFS_TYPE_INDIRECT ; +set_autofs_type_indirect (*type);break ;case Opt_direct: - *type =AUTOFS_TYPE_DIRECT ; +set_autofs_type_direct (*type);break ;case Opt_offset: - *type =AUTOFS_TYPE_OFFSET ; +set_autofs_type_offset (*type);break ;default :return 1 ;
@@ -338,7 +338,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) sbi->sb = s; sbi->version =0 ; sbi->sub_version =0 ; - sbi->type =AUTOFS_TYPE_INDIRECT ; +set_autofs_type_indirect (sbi->type); sbi->min_proto =0 ; sbi->max_proto =0 ;mutex_init (&sbi->wq_mutex);
@@ -380,7 +380,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) } root_inode->i_fop = &autofs4_root_operations; - root_inode->i_op = sbi->type &AUTOFS_TYPE_TRIGGER ? + root_inode->i_op =autofs_type_trigger (sbi->type) ? &autofs4_direct_root_inode_operations : &autofs4_indirect_root_inode_operations;
fs/autofs4/waitq.c +4 -4
@@ -337,7 +337,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,* is very similar for indirect mounts except only dentrys * in the root of the autofs file system may be negative. */ -if (sbi->type &AUTOFS_TYPE_TRIGGER ) +if (autofs_type_trigger (sbi->type))return -ENOENT ;else if (!IS_ROOT (dentry->d_parent))return -ENOENT ;
@@ -348,7 +348,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,return -ENOMEM ;/* If this is a direct mount request create a dummy name */ -if (IS_ROOT (dentry) && sbi->type &AUTOFS_TYPE_TRIGGER ) +if (IS_ROOT (dentry) &&autofs_type_trigger (sbi->type)) qstr.len =sprintf (name,"%p" , dentry);else { qstr.len =autofs4_getpath (sbi, dentry, &name);
@@ -406,11 +406,11 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, type = autofs_ptype_expire_multi; }else {if (notify ==NFY_MOUNT ) - type = (sbi->type &AUTOFS_TYPE_TRIGGER ) ? + type =autofs_type_trigger (sbi->type) ? autofs_ptype_missing_direct : autofs_ptype_missing_indirect;else - type = (sbi->type &AUTOFS_TYPE_TRIGGER ) ? + type =autofs_type_trigger (sbi->type) ? autofs_ptype_expire_direct : autofs_ptype_expire_indirect; }
include/linux/auto_fs4.h +24 -4
@@ -29,10 +29,30 @@#define AUTOFS_EXP_IMMEDIATE 1#define AUTOFS_EXP_LEAVES 2 -#define AUTOFS_TYPE_ANY 0x0000 -#define AUTOFS_TYPE_INDIRECT 0x0001 -#define AUTOFS_TYPE_DIRECT 0x0002 -#define AUTOFS_TYPE_OFFSET 0x0004 +#define AUTOFS_TYPE_ANY 0U +#define AUTOFS_TYPE_INDIRECT 1U +#define AUTOFS_TYPE_DIRECT 2U +#define AUTOFS_TYPE_OFFSET 4U + +#define set_autofs_type_indirect (type) (type = AUTOFS_TYPE_INDIRECT) +#define autofs_type_indirect (type) (type == AUTOFS_TYPE_INDIRECT) + +#define set_autofs_type_direct (type) (type = AUTOFS_TYPE_DIRECT) +#define autofs_type_direct (type) (type == AUTOFS_TYPE_DIRECT) + +#define set_autofs_type_offset (type) (type = AUTOFS_TYPE_OFFSET) +#define autofs_type_offset (type) (type == AUTOFS_TYPE_OFFSET) + +#define autofs_type_trigger (type) \ + (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET) + +/* +* This isn't really a type as we use it to say "no type set" to +* indicate we want to search for "any" mount in the +* autofs_dev_ioctl_ismountpoint() device ioctl function. +*/ +#define set_autofs_type_any (type) (type = AUTOFS_TYPE_ANY) +#define autofs_type_any (type) (type == AUTOFS_TYPE_ANY)/* Daemon notification packet types */ enum autofs_notify {
Re: [PATCH 4/6] autofs4 - make autofs type usage explicit
Quoted 21 lines · On Thu, 23 Oct 2008 10:35:32 +0800 Ian Kent <[email protected]> wrote:
This patch further improves autofs mount type usage and provides supplementry explanation of the changes made in the previous patch "autofs4 - cleanup autofs mount type usage".
Changes introduced in "autofs4 - cleanup autofs mount type usage":
- the type assigned at mount when no type is given is changed from 0 to
AUTOFS_TYPE_INDIRECT. This was done because 0 andAUTOFS_TYPE_INDIRECTwere being treated implicitly as the same type.- previously, an offset mount had it's type set to AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET but the mount control re-implementation needs to be able distinguish all three types. So this was changed to make the type setting explicit.
- a type
AUTOFS_TYPE_ANYwas added for use by the re-implementation when checking if a given path is a mountpoint. It's not really a type as we use this to ask if a given path is a mountpoint in theautofs_dev_ioctl_ismountpoint()function.
Quoted 4 lines
Changes introduced in this patch:
- macros to set and test the autofs mount types have been added to improve readability and make the type usage explicit.
^^^^^^^^^^^^^^^^^^^ <<-- ??
fs/autofs4/expire.c static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry) · line 66
Quoted 8 lines
- the mount type is used from user space for the mount control re-implementtion so, for consistency, all the definitions have been moved to the user space include file
include/linux/auto_fs4.h....
fs/autofs4/expire.c +1
-1-if (sbi->type ==AUTOFS_TYPE_INDIRECT ) +if (autofs_type_indirect (sbi->type))
spose so.
fs/autofs4/inode.c static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, · line 287
Quoted 2 lines
fs/autofs4/inode.c +1
-1- *type =AUTOFS_TYPE_INDIRECT ; +set_autofs_type_indirect (*type);
That's pretty nasty. One doesn't expect a "function" to modify a variable which was passed by value.
This interface _requires_ that set_autofs_type_indirect() be implemented as a macro.
This didn't improve readability.
Quoted 4 lines
...
+#define
set_autofs_type_indirect(type)(type =AUTOFS_TYPE_INDIRECT)
You'll find very few places in the kernel pull tricks like this, for good reasons. The obnoxious exceptions include local_irq_save() and friends.
Quoted 1 line
+#define
autofs_type_indirect(type)(type ==AUTOFS_TYPE_INDIRECT)
I guess that's OK.
But why was it implemented as a macro? It didn't _need_ to be implemented in cpp - it could have been implemented in C.
include/linux/auto_fs4.h line 47
Quoted 9 lines
include/linux/auto_fs4.h +9
-0+ +#define set_autofs_type_direct (type) (type = AUTOFS_TYPE_DIRECT) +#define autofs_type_direct (type) (type == AUTOFS_TYPE_DIRECT) + +#define set_autofs_type_offset (type) (type = AUTOFS_TYPE_OFFSET) +#define autofs_type_offset (type) (type == AUTOFS_TYPE_OFFSET) + +#define autofs_type_trigger (type) \ + (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET)
And this one is dangerous. If passed an expression-with-side-effects it will evaluate that expression either once or twice. Bad. Should be implemented in C.
Ian Kent
maintainerRe: [PATCH 4/6] autofs4 - make autofs type usage explicit
Quoted 69 lines · Andrew Morton
Quoted 21 lines · On Thu, 23 Oct 2008 10:35:32 +0800 Ian Kent <[email protected]> wrote:
This patch further improves autofs mount type usage and provides supplementry explanation of the changes made in the previous patch "autofs4 - cleanup autofs mount type usage".
Changes introduced in "autofs4 - cleanup autofs mount type usage":
- the type assigned at mount when no type is given is changed from 0 to
AUTOFS_TYPE_INDIRECT. This was done because 0 andAUTOFS_TYPE_INDIRECTwere being treated implicitly as the same type.- previously, an offset mount had it's type set to AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET but the mount control re-implementation needs to be able distinguish all three types. So this was changed to make the type setting explicit.
- a type
AUTOFS_TYPE_ANYwas added for use by the re-implementation when checking if a given path is a mountpoint. It's not really a type as we use this to ask if a given path is a mountpoint in theautofs_dev_ioctl_ismountpoint()function.Quoted 4 lines
Changes introduced in this patch:
- macros to set and test the autofs mount types have been added to improve readability and make the type usage explicit.
^^^^^^^^^^^^^^^^^^^ <<-- ??fs/autofs4/expire.c static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry) · line 66
Quoted 8 lines
- the mount type is used from user space for the mount control re-implementtion so, for consistency, all the definitions have been moved to the user space include file
include/linux/auto_fs4.h....
fs/autofs4/expire.c +1
-1-if (sbi->type ==AUTOFS_TYPE_INDIRECT ) +if (autofs_type_indirect (sbi->type))spose so.
fs/autofs4/inode.c static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, · line 287
Quoted 2 lines
fs/autofs4/inode.c +1
-1- *type =AUTOFS_TYPE_INDIRECT ; +set_autofs_type_indirect (*type);That's pretty nasty. One doesn't expect a "function" to modify a variable which was passed by value.
This interface _requires_ that
set_autofs_type_indirect()be implemented as a macro.This didn't improve readability.
Quoted 4 lines
...
+#define
set_autofs_type_indirect(type)(type =AUTOFS_TYPE_INDIRECT)You'll find very few places in the kernel pull tricks like this, for good reasons. The obnoxious exceptions include
local_irq_save()and friends.Quoted 1 line
+#define
autofs_type_indirect(type)(type ==AUTOFS_TYPE_INDIRECT)I guess that's OK.
But why was it implemented as a macro? It didn't _need_ to be implemented in cpp - it could have been implemented in C.
Quoted 14 lines
include/linux/auto_fs4.h line 47
Quoted 9 lines
include/linux/auto_fs4.h +9
-0+ +#define set_autofs_type_direct (type) (type = AUTOFS_TYPE_DIRECT) +#define autofs_type_direct (type) (type == AUTOFS_TYPE_DIRECT) + +#define set_autofs_type_offset (type) (type = AUTOFS_TYPE_OFFSET) +#define autofs_type_offset (type) (type == AUTOFS_TYPE_OFFSET) + +#define autofs_type_trigger (type) \ + (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET)And this one is dangerous. If passed an expression-with-side-effects it will evaluate that expression either once or twice. Bad. Should be implemented in C.
OK, more work needed then.
Ian
Re: [PATCH 4/6] autofs4 - make autofs type usage explicit
In reply to Andrew MortonQuoted 24 lines · Andrew Morton
Quoted 21 lines · On Thu, 23 Oct 2008 10:35:32 +0800 Ian Kent <[email protected]> wrote:
This patch further improves autofs mount type usage and provides supplementry explanation of the changes made in the previous patch "autofs4 - cleanup autofs mount type usage".
Changes introduced in "autofs4 - cleanup autofs mount type usage":
- the type assigned at mount when no type is given is changed from 0 to
AUTOFS_TYPE_INDIRECT. This was done because 0 andAUTOFS_TYPE_INDIRECTwere being treated implicitly as the same type.- previously, an offset mount had it's type set to AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET but the mount control re-implementation needs to be able distinguish all three types. So this was changed to make the type setting explicit.
- a type
AUTOFS_TYPE_ANYwas added for use by the re-implementation when checking if a given path is a mountpoint. It's not really a type as we use this to ask if a given path is a mountpoint in theautofs_dev_ioctl_ismountpoint()function.
Quoted 6 lines
Quoted 4 lines
Changes introduced in this patch:
- macros to set and test the autofs mount types have been added to improve readability and make the type usage explicit.
^^^^^^^^^^^^^^^^^^^ <<-- ??
Just for some background, I requested a change here. The reason is that I ran into problems in the user space daemon where there was this notion of a bitfield that wasn't always treated as a bitfield. So AUTOFS_TYPE_ANY should be all bits set, right? Nope. Some places in the code tested with binary operators, others with ==. It was confusing and error-prone. The accessor functions at least normalize the interface.
Cheers,
Jeff
Ian Kent
maintainerPATCH 5/6 autofs4 - improve parameter usage
In reply to Ian KentThe parameter usage in the device node ioctl code uses arg1 and arg2 as parameter names. This patch redefines the parameter names to reflect what they actually are in an effort to make the code more readable.
---
fs/autofs4/dev-ioctl.c | 54 +++++++++++++++-------------- include/linux/auto_dev-ioctl.h | 75 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 29 deletions(-)
fs/autofs4/dev-ioctl.c +29 -25
@@ -159,7 +159,7 @@ static int autofs_dev_ioctl_protover(struct file *fp,struct autofs_sb_info *sbi, struct autofs_dev_ioctl *param) { - param->arg1 = sbi->version; + param->protover.version = sbi->version;return 0 ; }
@@ -168,7 +168,7 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,struct autofs_sb_info *sbi, struct autofs_dev_ioctl *param) { - param->arg1 = sbi->sub_version; + param->protosubver.sub_version = sbi->sub_version;return 0 ; }
@@ -313,13 +313,13 @@ static int autofs_dev_ioctl_openmount(struct file *fp,int err, fd;/* param->path has already been checked */ -if (!param->arg1) +if (!param->openmount.devid)return -EINVAL ; param->ioctlfd =-1 ; path = param->path; - devid = param->arg1; + devid = param->openmount.devid; err =0 ; fd =autofs_dev_ioctl_open_mountpoint (path, devid);
@@ -351,7 +351,7 @@ static int autofs_dev_ioctl_ready(struct file *fp, {autofs_wqt_t token; - token = (autofs_wqt_t ) param->arg1; + token = (autofs_wqt_t ) param->ready.token;return autofs4_wait_release (sbi, token,0 ); }
@@ -366,8 +366,8 @@ static int autofs_dev_ioctl_fail(struct file *fp,autofs_wqt_t token;int status; - token = (autofs_wqt_t ) param->arg1; - status = param->arg2 ? param->arg2 : -ENOENT ; + token = (autofs_wqt_t ) param->fail.token; + status = param->fail.status ? param->fail.status : -ENOENT ;return autofs4_wait_release (sbi, token, status); }
@@ -390,10 +390,10 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,int pipefd;int err =0 ; -if (param->arg1 ==-1 ) +if (param->setpipefd.pipefd ==-1 )return -EINVAL ; - pipefd = param->arg1; + pipefd = param->setpipefd.pipefd;mutex_lock (&sbi->wq_mutex);if (!sbi->catatonic) {
@@ -435,8 +435,8 @@ static int autofs_dev_ioctl_timeout(struct file *fp, {unsigned long timeout; - timeout = param->arg1; - param->arg1 = sbi->exp_timeout /HZ ; + timeout = param->timeout.timeout; + param->timeout.timeout = sbi->exp_timeout /HZ ; sbi->exp_timeout = timeout *HZ ;return 0 ; }
@@ -467,7 +467,7 @@ static int autofs_dev_ioctl_requester(struct file *fp, path = param->path; devid = sbi->sb->s_dev; - param->arg1 = param->arg2 =-1 ; + param->requester.uid = param->requester.gid =-1 ;/* Get nameidata of the parent directory */ err =path_lookup (path,LOOKUP_PARENT , &nd);
@@ -483,8 +483,8 @@ static int autofs_dev_ioctl_requester(struct file *fp, err =0 ;autofs4_expire_wait (nd.path.dentry);spin_lock (&sbi->fs_lock); - param->arg1 = ino->uid; - param->arg2 = ino->gid; + param->requester.uid = ino->uid; + param->requester.gid = ino->gid;spin_unlock (&sbi->fs_lock); }
@@ -507,7 +507,7 @@ static int autofs_dev_ioctl_expire(struct file *fp,int err = -EAGAIN ;int how; - how = param->arg1; + how = param->expire.how; mnt = fp->f_path.mnt;if (autofs_type_trigger (sbi->type))
@@ -543,9 +543,9 @@ static int autofs_dev_ioctl_askumount(struct file *fp,struct autofs_sb_info *sbi, struct autofs_dev_ioctl *param) { - param->arg1 = 0; + param->askumount.may_umount = 0;if (may_umount (fp->f_path.mnt)) - param->arg1 =1 ; + param->askumount.may_umount =1 ;return 0 ; }
@@ -578,6 +578,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,struct nameidata nd;const char *path;unsigned int type; +unsigned int devid, magic;int err = -ENOENT ;if (param->size <=sizeof (*param)) {
@@ -586,10 +587,10 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, } path = param->path; - type = param->arg1; + type = param->ismountpoint.in.type; - param->arg1 =0 ; - param->arg2 =0 ; + param->ismountpoint.out.devid = devid =0 ; + param->ismountpoint.out.magic = magic =0 ;if (!fp || param->ioctlfd ==-1 ) {if (autofs_type_any (type)) {
@@ -600,7 +601,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, goto out; sb = nd.path.dentry->d_sb; - param->arg1 =new_encode_dev (sb->s_dev); + devid =new_encode_dev (sb->s_dev); }else {struct autofs_info *ino;
@@ -613,14 +614,14 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp, goto out_release; ino =autofs4_dentry_ino (nd.path.dentry); - param->arg1 =autofs4_get_dev (ino->sbi); + devid =autofs4_get_dev (ino->sbi); } err =0 ;if (nd.path.dentry->d_inode && nd.path.mnt->mnt_root == nd.path.dentry) { err =1 ; - param->arg2 = nd.path.dentry->d_inode->i_sb->s_magic; + magic = nd.path.dentry->d_inode->i_sb->s_magic; } }else {dev_t devid =new_encode_dev (sbi->sb->s_dev);
@@ -633,18 +634,21 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,if (err) goto out_release; - param->arg1 =autofs4_get_dev (sbi); + devid =autofs4_get_dev (sbi); err =have_submounts (nd.path.dentry);if (nd.path.mnt->mnt_mountpoint != nd.path.mnt->mnt_root) {if (follow_down (&nd.path.mnt, &nd.path.dentry)) {struct inode *inode = nd.path.dentry->d_inode; - param->arg2 = inode->i_sb->s_magic; + magic = inode->i_sb->s_magic; } } } + param->ismountpoint.out.devid = devid; + param->ismountpoint.out.magic = magic; + out_release:path_put (&nd.path); out:
include/linux/auto_dev-ioctl.h +71 -4
103 lines not on this page · raw message
Ian Kent
maintainerPATCH 6/6 autofs4 - cleanup expire code duplication
In reply to Ian KentA significant portion of the autofs_dev_ioctl_expire() and autofs4_expire_multi() functions is duplicated code. This patch cleans that up.
---
fs/autofs4/autofs_i.h | 2 ++ fs/autofs4/dev-ioctl.c | 29 +---------------------------- fs/autofs4/expire.c | 27 +++++++++++++++++---------- 3 files changed, 20 insertions(+), 38 deletions(-)
fs/autofs4/autofs_i.h +2 -0
@@ -186,6 +186,8 @@ int autofs4_expire_wait(struct dentry *dentry);int autofs4_expire_run (struct super_block *,struct vfsmount *,struct autofs_sb_info *,struct autofs_packet_expire __user *); +int autofs4_do_expire_multi (struct super_block *sb,struct vfsmount *mnt, +struct autofs_sb_info *sbi,int when);int autofs4_expire_multi (struct super_block *,struct vfsmount *,struct autofs_sb_info *,int __user *); struct dentry *autofs4_expire_direct(struct super_block *sb,
fs/autofs4/dev-ioctl.c +1 -28
@@ -502,40 +502,13 @@ static int autofs_dev_ioctl_expire(struct file *fp,struct autofs_sb_info *sbi, struct autofs_dev_ioctl *param) { - struct dentry *dentry; struct vfsmount *mnt; -int err = -EAGAIN ;int how; how = param->expire.how; mnt = fp->f_path.mnt; -if (autofs_type_trigger (sbi->type)) - dentry =autofs4_expire_direct (sbi->sb, mnt, sbi, how); -else - dentry =autofs4_expire_indirect (sbi->sb, mnt, sbi, how); - -if (dentry) { -struct autofs_info *ino =autofs4_dentry_ino (dentry); - -/* -* This is synchronous because it makes the daemon a -* little easier -*/ - err =autofs4_wait (sbi, dentry,NFY_EXPIRE ); - -spin_lock (&sbi->fs_lock); -if (ino->flags &AUTOFS_INF_MOUNTPOINT ) { - ino->flags &= ~AUTOFS_INF_MOUNTPOINT ; - sbi->sb->s_root->d_mounted++; - } - ino->flags &= ~AUTOFS_INF_EXPIRING ; -complete_all (&ino->expire_complete); -spin_unlock (&sbi->fs_lock); -dput (dentry); - } - -return err; +return autofs4_do_expire_multi (sbi->sb, mnt, sbi, how); }/* Check if autofs mount point is in use */
fs/autofs4/expire.c +17 -10
@@ -478,22 +478,16 @@ int autofs4_expire_run(struct super_block *sb,return ret; } -/* Call repeatedly until it returns -EAGAIN, meaning there's nothing -more to be done */ -int autofs4_expire_multi (struct super_block *sb,struct vfsmount *mnt, -struct autofs_sb_info *sbi,int __user *arg) +int autofs4_do_expire_multi (struct super_block *sb,struct vfsmount *mnt, +struct autofs_sb_info *sbi,int when) {struct dentry *dentry;int ret = -EAGAIN ; -int do_now =0 ; - -if (arg &&get_user (do_now, arg)) -return -EFAULT ;if (autofs_type_trigger (sbi->type)) - dentry =autofs4_expire_direct (sb, mnt, sbi, do_now); + dentry =autofs4_expire_direct (sb, mnt, sbi, when);else - dentry =autofs4_expire_indirect (sb, mnt, sbi, do_now); + dentry =autofs4_expire_indirect (sb, mnt, sbi, when);if (dentry) {struct autofs_info *ino =autofs4_dentry_ino (dentry);
@@ -516,3 +510,16 @@ int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,return ret; } +/* Call repeatedly until it returns -EAGAIN, meaning there's nothing +more to be done */ +int autofs4_expire_multi (struct super_block *sb,struct vfsmount *mnt, +struct autofs_sb_info *sbi,int __user *arg) +{ +int do_now =0 ; + +if (arg &&get_user (do_now, arg)) +return -EFAULT ; + +return autofs4_do_expire_multi (sb, mnt, sbi, do_now); +} +