Skip to content

Commit 730c9ee

Browse files
raven-autorvalds
authored andcommitted
autofs4: improve parameter usage
The 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. Signed-off-by: Ian Kent <raven@themaw.net> Signed-off-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f70f582 commit 730c9ee

2 files changed

Lines changed: 100 additions & 29 deletions

File tree

‎fs/autofs4/dev-ioctl.c‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int autofs_dev_ioctl_protover(struct file *fp,
180180
struct autofs_sb_info *sbi,
181181
struct autofs_dev_ioctl *param)
182182
{
183-
param->arg1 = sbi->version;
183+
param->protover.version = sbi->version;
184184
return 0;
185185
}
186186

@@ -189,7 +189,7 @@ static int autofs_dev_ioctl_protosubver(struct file *fp,
189189
struct autofs_sb_info *sbi,
190190
struct autofs_dev_ioctl *param)
191191
{
192-
param->arg1 = sbi->sub_version;
192+
param->protosubver.sub_version = sbi->sub_version;
193193
return 0;
194194
}
195195

@@ -335,13 +335,13 @@ static int autofs_dev_ioctl_openmount(struct file *fp,
335335
int err, fd;
336336

337337
/* param->path has already been checked */
338-
if (!param->arg1)
338+
if (!param->openmount.devid)
339339
return -EINVAL;
340340

341341
param->ioctlfd = -1;
342342

343343
path = param->path;
344-
devid = param->arg1;
344+
devid = param->openmount.devid;
345345

346346
err = 0;
347347
fd = autofs_dev_ioctl_open_mountpoint(path, devid);
@@ -373,7 +373,7 @@ static int autofs_dev_ioctl_ready(struct file *fp,
373373
{
374374
autofs_wqt_t token;
375375

376-
token = (autofs_wqt_t) param->arg1;
376+
token = (autofs_wqt_t) param->ready.token;
377377
return autofs4_wait_release(sbi, token, 0);
378378
}
379379

@@ -388,8 +388,8 @@ static int autofs_dev_ioctl_fail(struct file *fp,
388388
autofs_wqt_t token;
389389
int status;
390390

391-
token = (autofs_wqt_t) param->arg1;
392-
status = param->arg2 ? param->arg2 : -ENOENT;
391+
token = (autofs_wqt_t) param->fail.token;
392+
status = param->fail.status ? param->fail.status : -ENOENT;
393393
return autofs4_wait_release(sbi, token, status);
394394
}
395395

@@ -412,10 +412,10 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
412412
int pipefd;
413413
int err = 0;
414414

415-
if (param->arg1 == -1)
415+
if (param->setpipefd.pipefd == -1)
416416
return -EINVAL;
417417

418-
pipefd = param->arg1;
418+
pipefd = param->setpipefd.pipefd;
419419

420420
mutex_lock(&sbi->wq_mutex);
421421
if (!sbi->catatonic) {
@@ -457,8 +457,8 @@ static int autofs_dev_ioctl_timeout(struct file *fp,
457457
{
458458
unsigned long timeout;
459459

460-
timeout = param->arg1;
461-
param->arg1 = sbi->exp_timeout / HZ;
460+
timeout = param->timeout.timeout;
461+
param->timeout.timeout = sbi->exp_timeout / HZ;
462462
sbi->exp_timeout = timeout * HZ;
463463
return 0;
464464
}
@@ -489,7 +489,7 @@ static int autofs_dev_ioctl_requester(struct file *fp,
489489
path = param->path;
490490
devid = sbi->sb->s_dev;
491491

492-
param->arg1 = param->arg2 = -1;
492+
param->requester.uid = param->requester.gid = -1;
493493

494494
/* Get nameidata of the parent directory */
495495
err = path_lookup(path, LOOKUP_PARENT, &nd);
@@ -505,8 +505,8 @@ static int autofs_dev_ioctl_requester(struct file *fp,
505505
err = 0;
506506
autofs4_expire_wait(nd.path.dentry);
507507
spin_lock(&sbi->fs_lock);
508-
param->arg1 = ino->uid;
509-
param->arg2 = ino->gid;
508+
param->requester.uid = ino->uid;
509+
param->requester.gid = ino->gid;
510510
spin_unlock(&sbi->fs_lock);
511511
}
512512

@@ -529,7 +529,7 @@ static int autofs_dev_ioctl_expire(struct file *fp,
529529
int err = -EAGAIN;
530530
int how;
531531

532-
how = param->arg1;
532+
how = param->expire.how;
533533
mnt = fp->f_path.mnt;
534534

535535
if (sbi->type & AUTOFS_TYPE_TRIGGER)
@@ -565,9 +565,9 @@ static int autofs_dev_ioctl_askumount(struct file *fp,
565565
struct autofs_sb_info *sbi,
566566
struct autofs_dev_ioctl *param)
567567
{
568-
param->arg1 = 0;
568+
param->askumount.may_umount = 0;
569569
if (may_umount(fp->f_path.mnt))
570-
param->arg1 = 1;
570+
param->askumount.may_umount = 1;
571571
return 0;
572572
}
573573

@@ -600,6 +600,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
600600
struct nameidata nd;
601601
const char *path;
602602
unsigned int type;
603+
unsigned int devid, magic;
603604
int err = -ENOENT;
604605

605606
if (param->size <= sizeof(*param)) {
@@ -608,10 +609,10 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
608609
}
609610

610611
path = param->path;
611-
type = param->arg1;
612+
type = param->ismountpoint.in.type;
612613

613-
param->arg1 = 0;
614-
param->arg2 = 0;
614+
param->ismountpoint.out.devid = devid = 0;
615+
param->ismountpoint.out.magic = magic = 0;
615616

616617
if (!fp || param->ioctlfd == -1) {
617618
if (type == AUTOFS_TYPE_ANY) {
@@ -622,7 +623,7 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
622623
goto out;
623624

624625
sb = nd.path.dentry->d_sb;
625-
param->arg1 = new_encode_dev(sb->s_dev);
626+
devid = new_encode_dev(sb->s_dev);
626627
} else {
627628
struct autofs_info *ino;
628629

@@ -635,14 +636,14 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
635636
goto out_release;
636637

637638
ino = autofs4_dentry_ino(nd.path.dentry);
638-
param->arg1 = autofs4_get_dev(ino->sbi);
639+
devid = autofs4_get_dev(ino->sbi);
639640
}
640641

641642
err = 0;
642643
if (nd.path.dentry->d_inode &&
643644
nd.path.mnt->mnt_root == nd.path.dentry) {
644645
err = 1;
645-
param->arg2 = nd.path.dentry->d_inode->i_sb->s_magic;
646+
magic = nd.path.dentry->d_inode->i_sb->s_magic;
646647
}
647648
} else {
648649
dev_t devid = new_encode_dev(sbi->sb->s_dev);
@@ -655,18 +656,21 @@ static int autofs_dev_ioctl_ismountpoint(struct file *fp,
655656
if (err)
656657
goto out_release;
657658

658-
param->arg1 = autofs4_get_dev(sbi);
659+
devid = autofs4_get_dev(sbi);
659660

660661
err = have_submounts(nd.path.dentry);
661662

662663
if (nd.path.mnt->mnt_mountpoint != nd.path.mnt->mnt_root) {
663664
if (follow_down(&nd.path.mnt, &nd.path.dentry)) {
664665
struct inode *inode = nd.path.dentry->d_inode;
665-
param->arg2 = inode->i_sb->s_magic;
666+
magic = inode->i_sb->s_magic;
666667
}
667668
}
668669
}
669670

671+
param->ismountpoint.out.devid = devid;
672+
param->ismountpoint.out.magic = magic;
673+
670674
out_release:
671675
path_put(&nd.path);
672676
out:

‎include/linux/auto_dev-ioctl.h‎

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _LINUX_AUTO_DEV_IOCTL_H
1111
#define _LINUX_AUTO_DEV_IOCTL_H
1212

13+
#include <linux/string.h>
1314
#include <linux/types.h>
1415

1516
#define AUTOFS_DEVICE_NAME "autofs"
@@ -25,6 +26,60 @@
2526
* An ioctl interface for autofs mount point control.
2627
*/
2728

29+
struct args_protover {
30+
__u32 version;
31+
};
32+
33+
struct args_protosubver {
34+
__u32 sub_version;
35+
};
36+
37+
struct args_openmount {
38+
__u32 devid;
39+
};
40+
41+
struct args_ready {
42+
__u32 token;
43+
};
44+
45+
struct args_fail {
46+
__u32 token;
47+
__s32 status;
48+
};
49+
50+
struct args_setpipefd {
51+
__s32 pipefd;
52+
};
53+
54+
struct args_timeout {
55+
__u64 timeout;
56+
};
57+
58+
struct args_requester {
59+
__u32 uid;
60+
__u32 gid;
61+
};
62+
63+
struct args_expire {
64+
__u32 how;
65+
};
66+
67+
struct args_askumount {
68+
__u32 may_umount;
69+
};
70+
71+
struct args_ismountpoint {
72+
union {
73+
struct args_in {
74+
__u32 type;
75+
} in;
76+
struct args_out {
77+
__u32 devid;
78+
__u32 magic;
79+
} out;
80+
};
81+
};
82+
2883
/*
2984
* All the ioctls use this structure.
3085
* When sending a path size must account for the total length
@@ -39,20 +94,32 @@ struct autofs_dev_ioctl {
3994
* including this struct */
4095
__s32 ioctlfd; /* automount command fd */
4196

42-
__u32 arg1; /* Command parameters */
43-
__u32 arg2;
97+
/* Command parameters */
98+
99+
union {
100+
struct args_protover protover;
101+
struct args_protosubver protosubver;
102+
struct args_openmount openmount;
103+
struct args_ready ready;
104+
struct args_fail fail;
105+
struct args_setpipefd setpipefd;
106+
struct args_timeout timeout;
107+
struct args_requester requester;
108+
struct args_expire expire;
109+
struct args_askumount askumount;
110+
struct args_ismountpoint ismountpoint;
111+
};
44112

45113
char path[0];
46114
};
47115

48116
static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)
49117
{
118+
memset(in, 0, sizeof(struct autofs_dev_ioctl));
50119
in->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
51120
in->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
52121
in->size = sizeof(struct autofs_dev_ioctl);
53122
in->ioctlfd = -1;
54-
in->arg1 = 0;
55-
in->arg2 = 0;
56123
return;
57124
}
58125

0 commit comments

Comments
 (0)