| 1 |
--- linux-2.6.27.orig/fs/autofs4/autofs_i.h |
| 2 |
+++ linux-2.6.27/fs/autofs4/autofs_i.h |
| 3 |
@@ -14,6 +14,7 @@ |
| 4 |
/* Internal header file for autofs */ |
| 5 |
|
| 6 |
#include <linux/auto_fs4.h> |
| 7 |
+#include <linux/auto_dev-ioctl.h> |
| 8 |
#include <linux/mutex.h> |
| 9 |
#include <linux/list.h> |
| 10 |
|
| 11 |
@@ -21,6 +22,9 @@ |
| 12 |
#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY |
| 13 |
#define AUTOFS_IOC_COUNT 32 |
| 14 |
|
| 15 |
+#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION) |
| 16 |
+#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11) |
| 17 |
+ |
| 18 |
#include <linux/kernel.h> |
| 19 |
#include <linux/slab.h> |
| 20 |
#include <linux/time.h> |
| 21 |
@@ -35,11 +39,27 @@ |
| 22 |
/* #define DEBUG */ |
| 23 |
|
| 24 |
#ifdef DEBUG |
| 25 |
-#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __func__ , ##args); } while(0) |
| 26 |
+#define DPRINTK(fmt, args...) \ |
| 27 |
+do { \ |
| 28 |
+ printk(KERN_DEBUG "pid %d: %s: " fmt "\n", \ |
| 29 |
+ current->pid, __func__, ##args); \ |
| 30 |
+} while (0) |
| 31 |
#else |
| 32 |
-#define DPRINTK(fmt,args...) do {} while(0) |
| 33 |
+#define DPRINTK(fmt, args...) do {} while (0) |
| 34 |
#endif |
| 35 |
|
| 36 |
+#define AUTOFS_WARN(fmt, args...) \ |
| 37 |
+do { \ |
| 38 |
+ printk(KERN_WARNING "pid %d: %s: " fmt "\n", \ |
| 39 |
+ current->pid, __func__, ##args); \ |
| 40 |
+} while (0) |
| 41 |
+ |
| 42 |
+#define AUTOFS_ERROR(fmt, args...) \ |
| 43 |
+do { \ |
| 44 |
+ printk(KERN_ERR "pid %d: %s: " fmt "\n", \ |
| 45 |
+ current->pid, __func__, ##args); \ |
| 46 |
+} while (0) |
| 47 |
+ |
| 48 |
/* Unified info structure. This is pointed to by both the dentry and |
| 49 |
inode structures. Each file in the filesystem has an instance of this |
| 50 |
structure. It holds a reference to the dentry, so dentries are never |
| 51 |
@@ -61,6 +81,9 @@ struct autofs_info { |
| 52 |
unsigned long last_used; |
| 53 |
atomic_t count; |
| 54 |
|
| 55 |
+ uid_t uid; |
| 56 |
+ gid_t gid; |
| 57 |
+ |
| 58 |
mode_t mode; |
| 59 |
size_t size; |
| 60 |
|
| 61 |
@@ -92,10 +115,6 @@ struct autofs_wait_queue { |
| 62 |
|
| 63 |
#define AUTOFS_SBI_MAGIC 0x6d4a556d |
| 64 |
|
| 65 |
-#define AUTOFS_TYPE_INDIRECT 0x0001 |
| 66 |
-#define AUTOFS_TYPE_DIRECT 0x0002 |
| 67 |
-#define AUTOFS_TYPE_OFFSET 0x0004 |
| 68 |
- |
| 69 |
struct autofs_sb_info { |
| 70 |
u32 magic; |
| 71 |
int pipefd; |
| 72 |
@@ -167,8 +186,21 @@ int autofs4_expire_wait(struct dentry *d |
| 73 |
int autofs4_expire_run(struct super_block *, struct vfsmount *, |
| 74 |
struct autofs_sb_info *, |
| 75 |
struct autofs_packet_expire __user *); |
| 76 |
+int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt, |
| 77 |
+ struct autofs_sb_info *sbi, int when); |
| 78 |
int autofs4_expire_multi(struct super_block *, struct vfsmount *, |
| 79 |
struct autofs_sb_info *, int __user *); |
| 80 |
+struct dentry *autofs4_expire_direct(struct super_block *sb, |
| 81 |
+ struct vfsmount *mnt, |
| 82 |
+ struct autofs_sb_info *sbi, int how); |
| 83 |
+struct dentry *autofs4_expire_indirect(struct super_block *sb, |
| 84 |
+ struct vfsmount *mnt, |
| 85 |
+ struct autofs_sb_info *sbi, int how); |
| 86 |
+ |
| 87 |
+/* Device node initialization */ |
| 88 |
+ |
| 89 |
+int autofs_dev_ioctl_init(void); |
| 90 |
+void autofs_dev_ioctl_exit(void); |
| 91 |
|
| 92 |
/* Operations structures */ |
| 93 |
|
| 94 |
--- linux-2.6.27.orig/fs/autofs4/expire.c |
| 95 |
+++ linux-2.6.27/fs/autofs4/expire.c |
| 96 |
@@ -56,12 +56,25 @@ static int autofs4_mount_busy(struct vfs |
| 97 |
mntget(mnt); |
| 98 |
dget(dentry); |
| 99 |
|
| 100 |
- if (!autofs4_follow_mount(&mnt, &dentry)) |
| 101 |
+ if (!follow_down(&mnt, &dentry)) |
| 102 |
goto done; |
| 103 |
|
| 104 |
- /* This is an autofs submount, we can't expire it */ |
| 105 |
- if (is_autofs4_dentry(dentry)) |
| 106 |
- goto done; |
| 107 |
+ if (is_autofs4_dentry(dentry)) { |
| 108 |
+ struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 109 |
+ |
| 110 |
+ /* This is an autofs submount, we can't expire it */ |
| 111 |
+ if (autofs_type_indirect(sbi->type)) |
| 112 |
+ goto done; |
| 113 |
+ |
| 114 |
+ /* |
| 115 |
+ * Otherwise it's an offset mount and we need to check |
| 116 |
+ * if we can umount its mount, if there is one. |
| 117 |
+ */ |
| 118 |
+ if (!d_mountpoint(dentry)) { |
| 119 |
+ status = 0; |
| 120 |
+ goto done; |
| 121 |
+ } |
| 122 |
+ } |
| 123 |
|
| 124 |
/* Update the expiry counter if fs is busy */ |
| 125 |
if (!may_umount_tree(mnt)) { |
| 126 |
@@ -244,10 +257,10 @@ cont: |
| 127 |
} |
| 128 |
|
| 129 |
/* Check if we can expire a direct mount (possibly a tree) */ |
| 130 |
-static struct dentry *autofs4_expire_direct(struct super_block *sb, |
| 131 |
- struct vfsmount *mnt, |
| 132 |
- struct autofs_sb_info *sbi, |
| 133 |
- int how) |
| 134 |
+struct dentry *autofs4_expire_direct(struct super_block *sb, |
| 135 |
+ struct vfsmount *mnt, |
| 136 |
+ struct autofs_sb_info *sbi, |
| 137 |
+ int how) |
| 138 |
{ |
| 139 |
unsigned long timeout; |
| 140 |
struct dentry *root = dget(sb->s_root); |
| 141 |
@@ -283,10 +296,10 @@ static struct dentry *autofs4_expire_dir |
| 142 |
* - it is unused by any user process |
| 143 |
* - it has been unused for exp_timeout time |
| 144 |
*/ |
| 145 |
-static struct dentry *autofs4_expire_indirect(struct super_block *sb, |
| 146 |
- struct vfsmount *mnt, |
| 147 |
- struct autofs_sb_info *sbi, |
| 148 |
- int how) |
| 149 |
+struct dentry *autofs4_expire_indirect(struct super_block *sb, |
| 150 |
+ struct vfsmount *mnt, |
| 151 |
+ struct autofs_sb_info *sbi, |
| 152 |
+ int how) |
| 153 |
{ |
| 154 |
unsigned long timeout; |
| 155 |
struct dentry *root = sb->s_root; |
| 156 |
@@ -467,22 +480,16 @@ int autofs4_expire_run(struct super_bloc |
| 157 |
return ret; |
| 158 |
} |
| 159 |
|
| 160 |
-/* Call repeatedly until it returns -EAGAIN, meaning there's nothing |
| 161 |
- more to be done */ |
| 162 |
-int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt, |
| 163 |
- struct autofs_sb_info *sbi, int __user *arg) |
| 164 |
+int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt, |
| 165 |
+ struct autofs_sb_info *sbi, int when) |
| 166 |
{ |
| 167 |
struct dentry *dentry; |
| 168 |
int ret = -EAGAIN; |
| 169 |
- int do_now = 0; |
| 170 |
|
| 171 |
- if (arg && get_user(do_now, arg)) |
| 172 |
- return -EFAULT; |
| 173 |
- |
| 174 |
- if (sbi->type & AUTOFS_TYPE_DIRECT) |
| 175 |
- dentry = autofs4_expire_direct(sb, mnt, sbi, do_now); |
| 176 |
+ if (autofs_type_trigger(sbi->type)) |
| 177 |
+ dentry = autofs4_expire_direct(sb, mnt, sbi, when); |
| 178 |
else |
| 179 |
- dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now); |
| 180 |
+ dentry = autofs4_expire_indirect(sb, mnt, sbi, when); |
| 181 |
|
| 182 |
if (dentry) { |
| 183 |
struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 184 |
@@ -505,3 +512,16 @@ int autofs4_expire_multi(struct super_bl |
| 185 |
return ret; |
| 186 |
} |
| 187 |
|
| 188 |
+/* Call repeatedly until it returns -EAGAIN, meaning there's nothing |
| 189 |
+ more to be done */ |
| 190 |
+int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt, |
| 191 |
+ struct autofs_sb_info *sbi, int __user *arg) |
| 192 |
+{ |
| 193 |
+ int do_now = 0; |
| 194 |
+ |
| 195 |
+ if (arg && get_user(do_now, arg)) |
| 196 |
+ return -EFAULT; |
| 197 |
+ |
| 198 |
+ return autofs4_do_expire_multi(sb, mnt, sbi, do_now); |
| 199 |
+} |
| 200 |
+ |
| 201 |
--- linux-2.6.27.orig/fs/autofs4/inode.c |
| 202 |
+++ linux-2.6.27/fs/autofs4/inode.c |
| 203 |
@@ -53,6 +53,8 @@ struct autofs_info *autofs4_init_ino(str |
| 204 |
atomic_set(&ino->count, 0); |
| 205 |
} |
| 206 |
|
| 207 |
+ ino->uid = 0; |
| 208 |
+ ino->gid = 0; |
| 209 |
ino->mode = mode; |
| 210 |
ino->last_used = jiffies; |
| 211 |
|
| 212 |
@@ -195,9 +197,9 @@ static int autofs4_show_options(struct s |
| 213 |
seq_printf(m, ",minproto=%d", sbi->min_proto); |
| 214 |
seq_printf(m, ",maxproto=%d", sbi->max_proto); |
| 215 |
|
| 216 |
- if (sbi->type & AUTOFS_TYPE_OFFSET) |
| 217 |
+ if (autofs_type_offset(sbi->type)) |
| 218 |
seq_printf(m, ",offset"); |
| 219 |
- else if (sbi->type & AUTOFS_TYPE_DIRECT) |
| 220 |
+ else if (autofs_type_direct(sbi->type)) |
| 221 |
seq_printf(m, ",direct"); |
| 222 |
else |
| 223 |
seq_printf(m, ",indirect"); |
| 224 |
@@ -282,13 +284,13 @@ static int parse_options(char *options, |
| 225 |
*maxproto = option; |
| 226 |
break; |
| 227 |
case Opt_indirect: |
| 228 |
- *type = AUTOFS_TYPE_INDIRECT; |
| 229 |
+ set_autofs_type_indirect(type); |
| 230 |
break; |
| 231 |
case Opt_direct: |
| 232 |
- *type = AUTOFS_TYPE_DIRECT; |
| 233 |
+ set_autofs_type_direct(type); |
| 234 |
break; |
| 235 |
case Opt_offset: |
| 236 |
- *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET; |
| 237 |
+ set_autofs_type_offset(type); |
| 238 |
break; |
| 239 |
default: |
| 240 |
return 1; |
| 241 |
@@ -336,7 +338,7 @@ int autofs4_fill_super(struct super_bloc |
| 242 |
sbi->sb = s; |
| 243 |
sbi->version = 0; |
| 244 |
sbi->sub_version = 0; |
| 245 |
- sbi->type = 0; |
| 246 |
+ set_autofs_type_indirect(&sbi->type); |
| 247 |
sbi->min_proto = 0; |
| 248 |
sbi->max_proto = 0; |
| 249 |
mutex_init(&sbi->wq_mutex); |
| 250 |
@@ -378,7 +380,7 @@ int autofs4_fill_super(struct super_bloc |
| 251 |
} |
| 252 |
|
| 253 |
root_inode->i_fop = &autofs4_root_operations; |
| 254 |
- root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ? |
| 255 |
+ root_inode->i_op = autofs_type_trigger(sbi->type) ? |
| 256 |
&autofs4_direct_root_inode_operations : |
| 257 |
&autofs4_indirect_root_inode_operations; |
| 258 |
|
| 259 |
--- linux-2.6.27.orig/fs/autofs4/waitq.c |
| 260 |
+++ linux-2.6.27/fs/autofs4/waitq.c |
| 261 |
@@ -297,20 +297,14 @@ static int validate_request(struct autof |
| 262 |
*/ |
| 263 |
if (notify == NFY_MOUNT) { |
| 264 |
/* |
| 265 |
- * If the dentry isn't hashed just go ahead and try the |
| 266 |
- * mount again with a new wait (not much else we can do). |
| 267 |
- */ |
| 268 |
- if (!d_unhashed(dentry)) { |
| 269 |
- /* |
| 270 |
- * But if the dentry is hashed, that means that we |
| 271 |
- * got here through the revalidate path. Thus, we |
| 272 |
- * need to check if the dentry has been mounted |
| 273 |
- * while we waited on the wq_mutex. If it has, |
| 274 |
- * simply return success. |
| 275 |
- */ |
| 276 |
- if (d_mountpoint(dentry)) |
| 277 |
- return 0; |
| 278 |
- } |
| 279 |
+ * If the dentry was successfully mounted while we slept |
| 280 |
+ * on the wait queue mutex we can return success. If it |
| 281 |
+ * isn't mounted (doesn't have submounts for the case of |
| 282 |
+ * a multi-mount with no mount at it's base) we can |
| 283 |
+ * continue on and create a new request. |
| 284 |
+ */ |
| 285 |
+ if (have_submounts(dentry)) |
| 286 |
+ return 0; |
| 287 |
} |
| 288 |
|
| 289 |
return 1; |
| 290 |
@@ -337,7 +331,7 @@ int autofs4_wait(struct autofs_sb_info * |
| 291 |
* is very similar for indirect mounts except only dentrys |
| 292 |
* in the root of the autofs file system may be negative. |
| 293 |
*/ |
| 294 |
- if (sbi->type & (AUTOFS_TYPE_DIRECT|AUTOFS_TYPE_OFFSET)) |
| 295 |
+ if (autofs_type_trigger(sbi->type)) |
| 296 |
return -ENOENT; |
| 297 |
else if (!IS_ROOT(dentry->d_parent)) |
| 298 |
return -ENOENT; |
| 299 |
@@ -348,7 +342,7 @@ int autofs4_wait(struct autofs_sb_info * |
| 300 |
return -ENOMEM; |
| 301 |
|
| 302 |
/* If this is a direct mount request create a dummy name */ |
| 303 |
- if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT)) |
| 304 |
+ if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type)) |
| 305 |
qstr.len = sprintf(name, "%p", dentry); |
| 306 |
else { |
| 307 |
qstr.len = autofs4_getpath(sbi, dentry, &name); |
| 308 |
@@ -406,11 +400,11 @@ int autofs4_wait(struct autofs_sb_info * |
| 309 |
type = autofs_ptype_expire_multi; |
| 310 |
} else { |
| 311 |
if (notify == NFY_MOUNT) |
| 312 |
- type = (sbi->type & AUTOFS_TYPE_DIRECT) ? |
| 313 |
+ type = autofs_type_trigger(sbi->type) ? |
| 314 |
autofs_ptype_missing_direct : |
| 315 |
autofs_ptype_missing_indirect; |
| 316 |
else |
| 317 |
- type = (sbi->type & AUTOFS_TYPE_DIRECT) ? |
| 318 |
+ type = autofs_type_trigger(sbi->type) ? |
| 319 |
autofs_ptype_expire_direct : |
| 320 |
autofs_ptype_expire_indirect; |
| 321 |
} |
| 322 |
@@ -457,6 +451,40 @@ int autofs4_wait(struct autofs_sb_info * |
| 323 |
|
| 324 |
status = wq->status; |
| 325 |
|
| 326 |
+ /* |
| 327 |
+ * For direct and offset mounts we need to track the requester's |
| 328 |
+ * uid and gid in the dentry info struct. This is so it can be |
| 329 |
+ * supplied, on request, by the misc device ioctl interface. |
| 330 |
+ * This is needed during daemon resatart when reconnecting |
| 331 |
+ * to existing, active, autofs mounts. The uid and gid (and |
| 332 |
+ * related string values) may be used for macro substitution |
| 333 |
+ * in autofs mount maps. |
| 334 |
+ */ |
| 335 |
+ if (!status) { |
| 336 |
+ struct autofs_info *ino; |
| 337 |
+ struct dentry *de = NULL; |
| 338 |
+ |
| 339 |
+ /* direct mount or browsable map */ |
| 340 |
+ ino = autofs4_dentry_ino(dentry); |
| 341 |
+ if (!ino) { |
| 342 |
+ /* If not lookup actual dentry used */ |
| 343 |
+ de = d_lookup(dentry->d_parent, &dentry->d_name); |
| 344 |
+ if (de) |
| 345 |
+ ino = autofs4_dentry_ino(de); |
| 346 |
+ } |
| 347 |
+ |
| 348 |
+ /* Set mount requester */ |
| 349 |
+ if (ino) { |
| 350 |
+ spin_lock(&sbi->fs_lock); |
| 351 |
+ ino->uid = wq->uid; |
| 352 |
+ ino->gid = wq->gid; |
| 353 |
+ spin_unlock(&sbi->fs_lock); |
| 354 |
+ } |
| 355 |
+ |
| 356 |
+ if (de) |
| 357 |
+ dput(de); |
| 358 |
+ } |
| 359 |
+ |
| 360 |
/* Are we the last process to need status? */ |
| 361 |
mutex_lock(&sbi->wq_mutex); |
| 362 |
if (!--wq->wait_ctr) |
| 363 |
--- linux-2.6.27.orig/include/linux/auto_fs4.h |
| 364 |
+++ linux-2.6.27/include/linux/auto_fs4.h |
| 365 |
@@ -23,12 +23,71 @@ |
| 366 |
#define AUTOFS_MIN_PROTO_VERSION 3 |
| 367 |
#define AUTOFS_MAX_PROTO_VERSION 5 |
| 368 |
|
| 369 |
-#define AUTOFS_PROTO_SUBVERSION 0 |
| 370 |
+#define AUTOFS_PROTO_SUBVERSION 1 |
| 371 |
|
| 372 |
/* Mask for expire behaviour */ |
| 373 |
#define AUTOFS_EXP_IMMEDIATE 1 |
| 374 |
#define AUTOFS_EXP_LEAVES 2 |
| 375 |
|
| 376 |
+#define AUTOFS_TYPE_ANY 0U |
| 377 |
+#define AUTOFS_TYPE_INDIRECT 1U |
| 378 |
+#define AUTOFS_TYPE_DIRECT 2U |
| 379 |
+#define AUTOFS_TYPE_OFFSET 4U |
| 380 |
+ |
| 381 |
+static inline void set_autofs_type_indirect(unsigned int *type) |
| 382 |
+{ |
| 383 |
+ *type = AUTOFS_TYPE_INDIRECT; |
| 384 |
+ return; |
| 385 |
+} |
| 386 |
+ |
| 387 |
+static inline unsigned int autofs_type_indirect(unsigned int type) |
| 388 |
+{ |
| 389 |
+ return (type == AUTOFS_TYPE_INDIRECT); |
| 390 |
+} |
| 391 |
+ |
| 392 |
+static inline void set_autofs_type_direct(unsigned int *type) |
| 393 |
+{ |
| 394 |
+ *type = AUTOFS_TYPE_DIRECT; |
| 395 |
+ return; |
| 396 |
+} |
| 397 |
+ |
| 398 |
+static inline unsigned int autofs_type_direct(unsigned int type) |
| 399 |
+{ |
| 400 |
+ return (type == AUTOFS_TYPE_DIRECT); |
| 401 |
+} |
| 402 |
+ |
| 403 |
+static inline void set_autofs_type_offset(unsigned int *type) |
| 404 |
+{ |
| 405 |
+ *type = AUTOFS_TYPE_OFFSET; |
| 406 |
+ return; |
| 407 |
+} |
| 408 |
+ |
| 409 |
+static inline unsigned int autofs_type_offset(unsigned int type) |
| 410 |
+{ |
| 411 |
+ return (type == AUTOFS_TYPE_OFFSET); |
| 412 |
+} |
| 413 |
+ |
| 414 |
+static inline unsigned int autofs_type_trigger(unsigned int type) |
| 415 |
+{ |
| 416 |
+ return (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET); |
| 417 |
+} |
| 418 |
+ |
| 419 |
+/* |
| 420 |
+ * This isn't really a type as we use it to say "no type set" to |
| 421 |
+ * indicate we want to search for "any" mount in the |
| 422 |
+ * autofs_dev_ioctl_ismountpoint() device ioctl function. |
| 423 |
+ */ |
| 424 |
+static inline void set_autofs_type_any(unsigned int *type) |
| 425 |
+{ |
| 426 |
+ *type = AUTOFS_TYPE_ANY; |
| 427 |
+ return; |
| 428 |
+} |
| 429 |
+ |
| 430 |
+static inline unsigned int autofs_type_any(unsigned int type) |
| 431 |
+{ |
| 432 |
+ return (type == AUTOFS_TYPE_ANY); |
| 433 |
+} |
| 434 |
+ |
| 435 |
/* Daemon notification packet types */ |
| 436 |
enum autofs_notify { |
| 437 |
NFY_NONE, |
| 438 |
--- /dev/null |
| 439 |
+++ linux-2.6.27/Documentation/filesystems/autofs4-mount-control.txt |
| 440 |
@@ -0,0 +1,414 @@ |
| 441 |
+ |
| 442 |
+Miscellaneous Device control operations for the autofs4 kernel module |
| 443 |
+==================================================================== |
| 444 |
+ |
| 445 |
+The problem |
| 446 |
+=========== |
| 447 |
+ |
| 448 |
+There is a problem with active restarts in autofs (that is to say |
| 449 |
+restarting autofs when there are busy mounts). |
| 450 |
+ |
| 451 |
+During normal operation autofs uses a file descriptor opened on the |
| 452 |
+directory that is being managed in order to be able to issue control |
| 453 |
+operations. Using a file descriptor gives ioctl operations access to |
| 454 |
+autofs specific information stored in the super block. The operations |
| 455 |
+are things such as setting an autofs mount catatonic, setting the |
| 456 |
+expire timeout and requesting expire checks. As is explained below, |
| 457 |
+certain types of autofs triggered mounts can end up covering an autofs |
| 458 |
+mount itself which prevents us being able to use open(2) to obtain a |
| 459 |
+file descriptor for these operations if we don't already have one open. |
| 460 |
+ |
| 461 |
+Currently autofs uses "umount -l" (lazy umount) to clear active mounts |
| 462 |
+at restart. While using lazy umount works for most cases, anything that |
| 463 |
+needs to walk back up the mount tree to construct a path, such as |
| 464 |
+getcwd(2) and the proc file system /proc/<pid>/cwd, no longer works |
| 465 |
+because the point from which the path is constructed has been detached |
| 466 |
+from the mount tree. |
| 467 |
+ |
| 468 |
+The actual problem with autofs is that it can't reconnect to existing |
| 469 |
+mounts. Immediately one thinks of just adding the ability to remount |
| 470 |
+autofs file systems would solve it, but alas, that can't work. This is |
| 471 |
+because autofs direct mounts and the implementation of "on demand mount |
| 472 |
+and expire" of nested mount trees have the file system mounted directly |
| 473 |
+on top of the mount trigger directory dentry. |
| 474 |
+ |
| 475 |
+For example, there are two types of automount maps, direct (in the kernel |
| 476 |
+module source you will see a third type called an offset, which is just |
| 477 |
+a direct mount in disguise) and indirect. |
| 478 |
+ |
| 479 |
+Here is a master map with direct and indirect map entries: |
| 480 |
+ |
| 481 |
+/- /etc/auto.direct |
| 482 |
+/test /etc/auto.indirect |
| 483 |
+ |
| 484 |
+and the corresponding map files: |
| 485 |
+ |
| 486 |
+/etc/auto.direct: |
| 487 |
+ |
| 488 |
+/automount/dparse/g6 budgie:/autofs/export1 |
| 489 |
+/automount/dparse/g1 shark:/autofs/export1 |
| 490 |
+and so on. |
| 491 |
+ |
| 492 |
+/etc/auto.indirect: |
| 493 |
+ |
| 494 |
+g1 shark:/autofs/export1 |
| 495 |
+g6 budgie:/autofs/export1 |
| 496 |
+and so on. |
| 497 |
+ |
| 498 |
+For the above indirect map an autofs file system is mounted on /test and |
| 499 |
+mounts are triggered for each sub-directory key by the inode lookup |
| 500 |
+operation. So we see a mount of shark:/autofs/export1 on /test/g1, for |
| 501 |
+example. |
| 502 |
+ |
| 503 |
+The way that direct mounts are handled is by making an autofs mount on |
| 504 |
+each full path, such as /automount/dparse/g1, and using it as a mount |
| 505 |
+trigger. So when we walk on the path we mount shark:/autofs/export1 "on |
| 506 |
+top of this mount point". Since these are always directories we can |
| 507 |
+use the follow_link inode operation to trigger the mount. |
| 508 |
+ |
| 509 |
+But, each entry in direct and indirect maps can have offsets (making |
| 510 |
+them multi-mount map entries). |
| 511 |
+ |
| 512 |
+For example, an indirect mount map entry could also be: |
| 513 |
+ |
| 514 |
+g1 \ |
| 515 |
+ / shark:/autofs/export5/testing/test \ |
| 516 |
+ /s1 shark:/autofs/export/testing/test/s1 \ |
| 517 |
+ /s2 shark:/autofs/export5/testing/test/s2 \ |
| 518 |
+ /s1/ss1 shark:/autofs/export1 \ |
| 519 |
+ /s2/ss2 shark:/autofs/export2 |
| 520 |
+ |
| 521 |
+and a similarly a direct mount map entry could also be: |
| 522 |
+ |
| 523 |
+/automount/dparse/g1 \ |
| 524 |
+ / shark:/autofs/export5/testing/test \ |
| 525 |
+ /s1 shark:/autofs/export/testing/test/s1 \ |
| 526 |
+ /s2 shark:/autofs/export5/testing/test/s2 \ |
| 527 |
+ /s1/ss1 shark:/autofs/export2 \ |
| 528 |
+ /s2/ss2 shark:/autofs/export2 |
| 529 |
+ |
| 530 |
+One of the issues with version 4 of autofs was that, when mounting an |
| 531 |
+entry with a large number of offsets, possibly with nesting, we needed |
| 532 |
+to mount and umount all of the offsets as a single unit. Not really a |
| 533 |
+problem, except for people with a large number of offsets in map entries. |
| 534 |
+This mechanism is used for the well known "hosts" map and we have seen |
| 535 |
+cases (in 2.4) where the available number of mounts are exhausted or |
| 536 |
+where the number of privileged ports available is exhausted. |
| 537 |
+ |
| 538 |
+In version 5 we mount only as we go down the tree of offsets and |
| 539 |
+similarly for expiring them which resolves the above problem. There is |
| 540 |
+somewhat more detail to the implementation but it isn't needed for the |
| 541 |
+sake of the problem explanation. The one important detail is that these |
| 542 |
+offsets are implemented using the same mechanism as the direct mounts |
| 543 |
+above and so the mount points can be covered by a mount. |
| 544 |
+ |
| 545 |
+The current autofs implementation uses an ioctl file descriptor opened |
| 546 |
+on the mount point for control operations. The references held by the |
| 547 |
+descriptor are accounted for in checks made to determine if a mount is |
| 548 |
+in use and is also used to access autofs file system information held |
| 549 |
+in the mount super block. So the use of a file handle needs to be |
| 550 |
+retained. |
| 551 |
+ |
| 552 |
+ |
| 553 |
+The Solution |
| 554 |
+============ |
| 555 |
+ |
| 556 |
+To be able to restart autofs leaving existing direct, indirect and |
| 557 |
+offset mounts in place we need to be able to obtain a file handle |
| 558 |
+for these potentially covered autofs mount points. Rather than just |
| 559 |
+implement an isolated operation it was decided to re-implement the |
| 560 |
+existing ioctl interface and add new operations to provide this |
| 561 |
+functionality. |
| 562 |
+ |
| 563 |
+In addition, to be able to reconstruct a mount tree that has busy mounts, |
| 564 |
+the uid and gid of the last user that triggered the mount needs to be |
| 565 |
+available because these can be used as macro substitution variables in |
| 566 |
+autofs maps. They are recorded at mount request time and an operation |
| 567 |
+has been added to retrieve them. |
| 568 |
+ |
| 569 |
+Since we're re-implementing the control interface, a couple of other |
| 570 |
+problems with the existing interface have been addressed. First, when |
| 571 |
+a mount or expire operation completes a status is returned to the |
| 572 |
+kernel by either a "send ready" or a "send fail" operation. The |
| 573 |
+"send fail" operation of the ioctl interface could only ever send |
| 574 |
+ENOENT so the re-implementation allows user space to send an actual |
| 575 |
+status. Another expensive operation in user space, for those using |
| 576 |
+very large maps, is discovering if a mount is present. Usually this |
| 577 |
+involves scanning /proc/mounts and since it needs to be done quite |
| 578 |
+often it can introduce significant overhead when there are many entries |
| 579 |
+in the mount table. An operation to lookup the mount status of a mount |
| 580 |
+point dentry (covered or not) has also been added. |
| 581 |
+ |
| 582 |
+Current kernel development policy recommends avoiding the use of the |
| 583 |
+ioctl mechanism in favor of systems such as Netlink. An implementation |
| 584 |
+using this system was attempted to evaluate its suitability and it was |
| 585 |
+found to be inadequate, in this case. The Generic Netlink system was |
| 586 |
+used for this as raw Netlink would lead to a significant increase in |
| 587 |
+complexity. There's no question that the Generic Netlink system is an |
| 588 |
+elegant solution for common case ioctl functions but it's not a complete |
| 589 |
+replacement probably because it's primary purpose in life is to be a |
| 590 |
+message bus implementation rather than specifically an ioctl replacement. |
| 591 |
+While it would be possible to work around this there is one concern |
| 592 |
+that lead to the decision to not use it. This is that the autofs |
| 593 |
+expire in the daemon has become far to complex because umount |
| 594 |
+candidates are enumerated, almost for no other reason than to "count" |
| 595 |
+the number of times to call the expire ioctl. This involves scanning |
| 596 |
+the mount table which has proved to be a big overhead for users with |
| 597 |
+large maps. The best way to improve this is try and get back to the |
| 598 |
+way the expire was done long ago. That is, when an expire request is |
| 599 |
+issued for a mount (file handle) we should continually call back to |
| 600 |
+the daemon until we can't umount any more mounts, then return the |
| 601 |
+appropriate status to the daemon. At the moment we just expire one |
| 602 |
+mount at a time. A Generic Netlink implementation would exclude this |
| 603 |
+possibility for future development due to the requirements of the |
| 604 |
+message bus architecture. |
| 605 |
+ |
| 606 |
+ |
| 607 |
+autofs4 Miscellaneous Device mount control interface |
| 608 |
+==================================================== |
| 609 |
+ |
| 610 |
+The control interface is opening a device node, typically /dev/autofs. |
| 611 |
+ |
| 612 |
+All the ioctls use a common structure to pass the needed parameter |
| 613 |
+information and return operation results: |
| 614 |
+ |
| 615 |
+struct autofs_dev_ioctl { |
| 616 |
+ __u32 ver_major; |
| 617 |
+ __u32 ver_minor; |
| 618 |
+ __u32 size; /* total size of data passed in |
| 619 |
+ * including this struct */ |
| 620 |
+ __s32 ioctlfd; /* automount command fd */ |
| 621 |
+ |
| 622 |
+ /* Command parameters */ |
| 623 |
+ |
| 624 |
+ union { |
| 625 |
+ struct args_protover protover; |
| 626 |
+ struct args_protosubver protosubver; |
| 627 |
+ struct args_openmount openmount; |
| 628 |
+ struct args_ready ready; |
| 629 |
+ struct args_fail fail; |
| 630 |
+ struct args_setpipefd setpipefd; |
| 631 |
+ struct args_timeout timeout; |
| 632 |
+ struct args_requester requester; |
| 633 |
+ struct args_expire expire; |
| 634 |
+ struct args_askumount askumount; |
| 635 |
+ struct args_ismountpoint ismountpoint; |
| 636 |
+ }; |
| 637 |
+ |
| 638 |
+ char path[0]; |
| 639 |
+}; |
| 640 |
+ |
| 641 |
+The ioctlfd field is a mount point file descriptor of an autofs mount |
| 642 |
+point. It is returned by the open call and is used by all calls except |
| 643 |
+the check for whether a given path is a mount point, where it may |
| 644 |
+optionally be used to check a specific mount corresponding to a given |
| 645 |
+mount point file descriptor, and when requesting the uid and gid of the |
| 646 |
+last successful mount on a directory within the autofs file system. |
| 647 |
+ |
| 648 |
+The anonymous union is used to communicate parameters and results of calls |
| 649 |
+made as described below. |
| 650 |
+ |
| 651 |
+The path field is used to pass a path where it is needed and the size field |
| 652 |
+is used account for the increased structure length when translating the |
| 653 |
+structure sent from user space. |
| 654 |
+ |
| 655 |
+This structure can be initialized before setting specific fields by using |
| 656 |
+the void function call init_autofs_dev_ioctl(struct autofs_dev_ioctl *). |
| 657 |
+ |
| 658 |
+All of the ioctls perform a copy of this structure from user space to |
| 659 |
+kernel space and return -EINVAL if the size parameter is smaller than |
| 660 |
+the structure size itself, -ENOMEM if the kernel memory allocation fails |
| 661 |
+or -EFAULT if the copy itself fails. Other checks include a version check |
| 662 |
+of the compiled in user space version against the module version and a |
| 663 |
+mismatch results in a -EINVAL return. If the size field is greater than |
| 664 |
+the structure size then a path is assumed to be present and is checked to |
| 665 |
+ensure it begins with a "/" and is NULL terminated, otherwise -EINVAL is |
| 666 |
+returned. Following these checks, for all ioctl commands except |
| 667 |
+AUTOFS_DEV_IOCTL_VERSION_CMD, AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and |
| 668 |
+AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD the ioctlfd is validated and if it is |
| 669 |
+not a valid descriptor or doesn't correspond to an autofs mount point |
| 670 |
+an error of -EBADF, -ENOTTY or -EINVAL (not an autofs descriptor) is |
| 671 |
+returned. |
| 672 |
+ |
| 673 |
+ |
| 674 |
+The ioctls |
| 675 |
+========== |
| 676 |
+ |
| 677 |
+An example of an implementation which uses this interface can be seen |
| 678 |
+in autofs version 5.0.4 and later in file lib/dev-ioctl-lib.c of the |
| 679 |
+distribution tar available for download from kernel.org in directory |
| 680 |
+/pub/linux/daemons/autofs/v5. |
| 681 |
+ |
| 682 |
+The device node ioctl operations implemented by this interface are: |
| 683 |
+ |
| 684 |
+ |
| 685 |
+AUTOFS_DEV_IOCTL_VERSION |
| 686 |
+------------------------ |
| 687 |
+ |
| 688 |
+Get the major and minor version of the autofs4 device ioctl kernel module |
| 689 |
+implementation. It requires an initialized struct autofs_dev_ioctl as an |
| 690 |
+input parameter and sets the version information in the passed in structure. |
| 691 |
+It returns 0 on success or the error -EINVAL if a version mismatch is |
| 692 |
+detected. |
| 693 |
+ |
| 694 |
+ |
| 695 |
+AUTOFS_DEV_IOCTL_PROTOVER_CMD and AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD |
| 696 |
+------------------------------------------------------------------ |
| 697 |
+ |
| 698 |
+Get the major and minor version of the autofs4 protocol version understood |
| 699 |
+by loaded module. This call requires an initialized struct autofs_dev_ioctl |
| 700 |
+with the ioctlfd field set to a valid autofs mount point descriptor |
| 701 |
+and sets the requested version number in structure field protover.version |
| 702 |
+and ptotosubver.sub_version respectively. These commands return 0 on |
| 703 |
+success or one of the negative error codes if validation fails. |
| 704 |
+ |
| 705 |
+ |
| 706 |
+AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD |
| 707 |
+------------------------------------------------------------------ |
| 708 |
+ |
| 709 |
+Obtain and release a file descriptor for an autofs managed mount point |
| 710 |
+path. The open call requires an initialized struct autofs_dev_ioctl with |
| 711 |
+the the path field set and the size field adjusted appropriately as well |
| 712 |
+as the openmount.devid field set to the device number of the autofs mount. |
| 713 |
+The device number of an autofs mounted filesystem can be obtained by using |
| 714 |
+the AUTOFS_DEV_IOCTL_ISMOUNTPOINT ioctl function by providing the path |
| 715 |
+and autofs mount type, as described below. The close call requires an |
| 716 |
+initialized struct autofs_dev_ioct with the ioctlfd field set to the |
| 717 |
+descriptor obtained from the open call. The release of the file descriptor |
| 718 |
+can also be done with close(2) so any open descriptors will also be |
| 719 |
+closed at process exit. The close call is included in the implemented |
| 720 |
+operations largely for completeness and to provide for a consistent |
| 721 |
+user space implementation. |
| 722 |
+ |
| 723 |
+ |
| 724 |
+AUTOFS_DEV_IOCTL_READY_CMD and AUTOFS_DEV_IOCTL_FAIL_CMD |
| 725 |
+-------------------------------------------------------- |
| 726 |
+ |
| 727 |
+Return mount and expire result status from user space to the kernel. |
| 728 |
+Both of these calls require an initialized struct autofs_dev_ioctl |
| 729 |
+with the ioctlfd field set to the descriptor obtained from the open |
| 730 |
+call and the ready.token or fail.token field set to the wait queue |
| 731 |
+token number, received by user space in the foregoing mount or expire |
| 732 |
+request. The fail.status field is set to the status to be returned when |
| 733 |
+sending a failure notification with AUTOFS_DEV_IOCTL_FAIL_CMD. |
| 734 |
+ |
| 735 |
+ |
| 736 |
+AUTOFS_DEV_IOCTL_SETPIPEFD_CMD |
| 737 |
+------------------------------ |
| 738 |
+ |
| 739 |
+Set the pipe file descriptor used for kernel communication to the daemon. |
| 740 |
+Normally this is set at mount time using an option but when reconnecting |
| 741 |
+to a existing mount we need to use this to tell the autofs mount about |
| 742 |
+the new kernel pipe descriptor. In order to protect mounts against |
| 743 |
+incorrectly setting the pipe descriptor we also require that the autofs |
| 744 |
+mount be catatonic (see next call). |
| 745 |
+ |
| 746 |
+The call requires an initialized struct autofs_dev_ioctl with the |
| 747 |
+ioctlfd field set to the descriptor obtained from the open call and |
| 748 |
+the setpipefd.pipefd field set to descriptor of the pipe. On success |
| 749 |
+the call also sets the process group id used to identify the controlling |
| 750 |
+process (eg. the owning automount(8) daemon) to the process group of |
| 751 |
+the caller. |
| 752 |
+ |
| 753 |
+ |
| 754 |
+AUTOFS_DEV_IOCTL_CATATONIC_CMD |
| 755 |
+------------------------------ |
| 756 |
+ |
| 757 |
+Make the autofs mount point catatonic. The autofs mount will no longer |
| 758 |
+issue mount requests, the kernel communication pipe descriptor is released |
| 759 |
+and any remaining waits in the queue released. |
| 760 |
+ |
| 761 |
+The call requires an initialized struct autofs_dev_ioctl with the |
| 762 |
+ioctlfd field set to the descriptor obtained from the open call. |
| 763 |
+ |
| 764 |
+ |
| 765 |
+AUTOFS_DEV_IOCTL_TIMEOUT_CMD |
| 766 |
+---------------------------- |
| 767 |
+ |
| 768 |
+Set the expire timeout for mounts withing an autofs mount point. |
| 769 |
+ |
| 770 |
+The call requires an initialized struct autofs_dev_ioctl with the |
| 771 |
+ioctlfd field set to the descriptor obtained from the open call. |
| 772 |
+The timeout.timeout field is set to the desired timeout and this |
| 773 |
+field is set to the value of the value of the current timeout of |
| 774 |
+the mount upon successful completion. |
| 775 |
+ |
| 776 |
+ |
| 777 |
+AUTOFS_DEV_IOCTL_REQUESTER_CMD |
| 778 |
+------------------------------ |
| 779 |
+ |
| 780 |
+Return the uid and gid of the last process to successfully trigger a the |
| 781 |
+mount on the given path dentry. |
| 782 |
+ |
| 783 |
+The call requires an initialized struct autofs_dev_ioctl with the path |
| 784 |
+field set to the mount point in question and the size field adjusted |
| 785 |
+appropriately as well as the ioctlfd field set to the descriptor obtained |
| 786 |
+from the open call. Upon return the struct fields requester.uid and |
| 787 |
+requester.gid contain the uid and gid respectively. |
| 788 |
+ |
| 789 |
+When reconstructing an autofs mount tree with active mounts we need to |
| 790 |
+re-connect to mounts that may have used the original process uid and |
| 791 |
+gid (or string variations of them) for mount lookups within the map entry. |
| 792 |
+This call provides the ability to obtain this uid and gid so they may be |
| 793 |
+used by user space for the mount map lookups. |
| 794 |
+ |
| 795 |
+ |
| 796 |
+AUTOFS_DEV_IOCTL_EXPIRE_CMD |
| 797 |
+--------------------------- |
| 798 |
+ |
| 799 |
+Issue an expire request to the kernel for an autofs mount. Typically |
| 800 |
+this ioctl is called until no further expire candidates are found. |
| 801 |
+ |
| 802 |
+The call requires an initialized struct autofs_dev_ioctl with the |
| 803 |
+ioctlfd field set to the descriptor obtained from the open call. In |
| 804 |
+addition an immediate expire, independent of the mount timeout, can be |
| 805 |
+requested by setting the expire.how field to 1. If no expire candidates |
| 806 |
+can be found the ioctl returns -1 with errno set to EAGAIN. |
| 807 |
+ |
| 808 |
+This call causes the kernel module to check the mount corresponding |
| 809 |
+to the given ioctlfd for mounts that can be expired, issues an expire |
| 810 |
+request back to the daemon and waits for completion. |
| 811 |
+ |
| 812 |
+AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD |
| 813 |
+------------------------------ |
| 814 |
+ |
| 815 |
+Checks if an autofs mount point is in use. |
| 816 |
+ |
| 817 |
+The call requires an initialized struct autofs_dev_ioctl with the |
| 818 |
+ioctlfd field set to the descriptor obtained from the open call and |
| 819 |
+it returns the result in the askumount.may_umount field, 1 for busy |
| 820 |
+and 0 otherwise. |
| 821 |
+ |
| 822 |
+ |
| 823 |
+AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD |
| 824 |
+--------------------------------- |
| 825 |
+ |
| 826 |
+Check if the given path is a mountpoint. |
| 827 |
+ |
| 828 |
+The call requires an initialized struct autofs_dev_ioctl. There are two |
| 829 |
+possible variations. Both use the path field set to the path of the mount |
| 830 |
+point to check and the size field must be adjusted appropriately. One uses |
| 831 |
+the ioctlfd field to identify a specific mount point to check while the |
| 832 |
+other variation uses the path and optionaly the ismountpoint.in.type |
| 833 |
+field set to an autofs mount type. The call returns 1 if this is a mount |
| 834 |
+point and sets the ismountpoint.out.devid field to the device number of |
| 835 |
+the mount and the ismountpoint.out.magic field to the relevant super |
| 836 |
+block magic number (described below) or 0 if it isn't a mountpoint. In |
| 837 |
+both cases the the device number (as returned by new_encode_dev()) is |
| 838 |
+returned in the ismountpoint.out.devid field. |
| 839 |
+ |
| 840 |
+If supplied with a file descriptor we're looking for a specific mount, |
| 841 |
+not necessarily at the top of the mounted stack. In this case the path |
| 842 |
+the descriptor corresponds to is considered a mountpoint if it is itself |
| 843 |
+a mountpoint or contains a mount, such as a multi-mount without a root |
| 844 |
+mount. In this case we return 1 if the descriptor corresponds to a mount |
| 845 |
+point and and also returns the super magic of the covering mount if there |
| 846 |
+is one or 0 if it isn't a mountpoint. |
| 847 |
+ |
| 848 |
+If a path is supplied (and the ioctlfd field is set to -1) then the path |
| 849 |
+is looked up and is checked to see if it is the root of a mount. If a |
| 850 |
+type is also given we are looking for a particular autofs mount and if |
| 851 |
+a match isn't found a fail is returned. If the the located path is the |
| 852 |
+root of a mount 1 is returned along with the super magic of the mount |
| 853 |
+or 0 otherwise. |
| 854 |
+ |
| 855 |
--- linux-2.6.27.orig/fs/autofs4/Makefile |
| 856 |
+++ linux-2.6.27/fs/autofs4/Makefile |
| 857 |
@@ -4,4 +4,4 @@ |
| 858 |
|
| 859 |
obj-$(CONFIG_AUTOFS4_FS) += autofs4.o |
| 860 |
|
| 861 |
-autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o |
| 862 |
+autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o dev-ioctl.o |
| 863 |
--- /dev/null |
| 864 |
+++ linux-2.6.27/fs/autofs4/dev-ioctl.c |
| 865 |
@@ -0,0 +1,841 @@ |
| 866 |
+/* |
| 867 |
+ * Copyright 2008 Red Hat, Inc. All rights reserved. |
| 868 |
+ * Copyright 2008 Ian Kent <[email protected]> |
| 869 |
+ * |
| 870 |
+ * This file is part of the Linux kernel and is made available under |
| 871 |
+ * the terms of the GNU General Public License, version 2, or at your |
| 872 |
+ * option, any later version, incorporated herein by reference. |
| 873 |
+ */ |
| 874 |
+ |
| 875 |
+#include <linux/module.h> |
| 876 |
+#include <linux/vmalloc.h> |
| 877 |
+#include <linux/miscdevice.h> |
| 878 |
+#include <linux/init.h> |
| 879 |
+#include <linux/wait.h> |
| 880 |
+#include <linux/namei.h> |
| 881 |
+#include <linux/fcntl.h> |
| 882 |
+#include <linux/file.h> |
| 883 |
+#include <linux/fdtable.h> |
| 884 |
+#include <linux/sched.h> |
| 885 |
+#include <linux/compat.h> |
| 886 |
+#include <linux/syscalls.h> |
| 887 |
+#include <linux/smp_lock.h> |
| 888 |
+#include <linux/magic.h> |
| 889 |
+#include <linux/dcache.h> |
| 890 |
+#include <linux/uaccess.h> |
| 891 |
+ |
| 892 |
+#include "autofs_i.h" |
| 893 |
+ |
| 894 |
+/* |
| 895 |
+ * This module implements an interface for routing autofs ioctl control |
| 896 |
+ * commands via a miscellaneous device file. |
| 897 |
+ * |
| 898 |
+ * The alternate interface is needed because we need to be able open |
| 899 |
+ * an ioctl file descriptor on an autofs mount that may be covered by |
| 900 |
+ * another mount. This situation arises when starting automount(8) |
| 901 |
+ * or other user space daemon which uses direct mounts or offset |
| 902 |
+ * mounts (used for autofs lazy mount/umount of nested mount trees), |
| 903 |
+ * which have been left busy at at service shutdown. |
| 904 |
+ */ |
| 905 |
+ |
| 906 |
+#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl) |
| 907 |
+ |
| 908 |
+typedef int (*ioctl_fn)(struct file *, |
| 909 |
+struct autofs_sb_info *, struct autofs_dev_ioctl *); |
| 910 |
+ |
| 911 |
+static int check_name(const char *name) |
| 912 |
+{ |
| 913 |
+ if (!strchr(name, '/')) |
| 914 |
+ return -EINVAL; |
| 915 |
+ return 0; |
| 916 |
+} |
| 917 |
+ |
| 918 |
+/* |
| 919 |
+ * Check a string doesn't overrun the chunk of |
| 920 |
+ * memory we copied from user land. |
| 921 |
+ */ |
| 922 |
+static int invalid_str(char *str, void *end) |
| 923 |
+{ |
| 924 |
+ while ((void *) str <= end) |
| 925 |
+ if (!*str++) |
| 926 |
+ return 0; |
| 927 |
+ return -EINVAL; |
| 928 |
+} |
| 929 |
+ |
| 930 |
+/* |
| 931 |
+ * Check that the user compiled against correct version of autofs |
| 932 |
+ * misc device code. |
| 933 |
+ * |
| 934 |
+ * As well as checking the version compatibility this always copies |
| 935 |
+ * the kernel interface version out. |
| 936 |
+ */ |
| 937 |
+static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param) |
| 938 |
+{ |
| 939 |
+ int err = 0; |
| 940 |
+ |
| 941 |
+ if ((AUTOFS_DEV_IOCTL_VERSION_MAJOR != param->ver_major) || |
| 942 |
+ (AUTOFS_DEV_IOCTL_VERSION_MINOR < param->ver_minor)) { |
| 943 |
+ AUTOFS_WARN("ioctl control interface version mismatch: " |
| 944 |
+ "kernel(%u.%u), user(%u.%u), cmd(%d)", |
| 945 |
+ AUTOFS_DEV_IOCTL_VERSION_MAJOR, |
| 946 |
+ AUTOFS_DEV_IOCTL_VERSION_MINOR, |
| 947 |
+ param->ver_major, param->ver_minor, cmd); |
| 948 |
+ err = -EINVAL; |
| 949 |
+ } |
| 950 |
+ |
| 951 |
+ /* Fill in the kernel version. */ |
| 952 |
+ param->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR; |
| 953 |
+ param->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR; |
| 954 |
+ |
| 955 |
+ return err; |
| 956 |
+} |
| 957 |
+ |
| 958 |
+/* |
| 959 |
+ * Copy parameter control struct, including a possible path allocated |
| 960 |
+ * at the end of the struct. |
| 961 |
+ */ |
| 962 |
+static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in) |
| 963 |
+{ |
| 964 |
+ struct autofs_dev_ioctl tmp, *ads; |
| 965 |
+ |
| 966 |
+ if (copy_from_user(&tmp, in, sizeof(tmp))) |
| 967 |
+ return ERR_PTR(-EFAULT); |
| 968 |
+ |
| 969 |
+ if (tmp.size < sizeof(tmp)) |
| 970 |
+ return ERR_PTR(-EINVAL); |
| 971 |
+ |
| 972 |
+ ads = kmalloc(tmp.size, GFP_KERNEL); |
| 973 |
+ if (!ads) |
| 974 |
+ return ERR_PTR(-ENOMEM); |
| 975 |
+ |
| 976 |
+ if (copy_from_user(ads, in, tmp.size)) { |
| 977 |
+ kfree(ads); |
| 978 |
+ return ERR_PTR(-EFAULT); |
| 979 |
+ } |
| 980 |
+ |
| 981 |
+ return ads; |
| 982 |
+} |
| 983 |
+ |
| 984 |
+static inline void free_dev_ioctl(struct autofs_dev_ioctl *param) |
| 985 |
+{ |
| 986 |
+ kfree(param); |
| 987 |
+ return; |
| 988 |
+} |
| 989 |
+ |
| 990 |
+/* |
| 991 |
+ * Check sanity of parameter control fields and if a path is present |
| 992 |
+ * check that it is terminated and contains at least one "/". |
| 993 |
+ */ |
| 994 |
+static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) |
| 995 |
+{ |
| 996 |
+ int err; |
| 997 |
+ |
| 998 |
+ if ((err = check_dev_ioctl_version(cmd, param))) { |
| 999 |
+ AUTOFS_WARN("invalid device control module version " |
| 1000 |
+ "supplied for cmd(0x%08x)", cmd); |
| 1001 |
+ goto out; |
| 1002 |
+ } |
| 1003 |
+ |
| 1004 |
+ if (param->size > sizeof(*param)) { |
| 1005 |
+ err = invalid_str(param->path, |
| 1006 |
+ (void *) ((size_t) param + param->size)); |
| 1007 |
+ if (err) { |
| 1008 |
+ AUTOFS_WARN( |
| 1009 |
+ "path string terminator missing for cmd(0x%08x)", |
| 1010 |
+ cmd); |
| 1011 |
+ goto out; |
| 1012 |
+ } |
| 1013 |
+ |
| 1014 |
+ err = check_name(param->path); |
| 1015 |
+ if (err) { |
| 1016 |
+ AUTOFS_WARN("invalid path supplied for cmd(0x%08x)", |
| 1017 |
+ cmd); |
| 1018 |
+ goto out; |
| 1019 |
+ } |
| 1020 |
+ } |
| 1021 |
+ |
| 1022 |
+ err = 0; |
| 1023 |
+out: |
| 1024 |
+ return err; |
| 1025 |
+} |
| 1026 |
+ |
| 1027 |
+/* |
| 1028 |
+ * Get the autofs super block info struct from the file opened on |
| 1029 |
+ * the autofs mount point. |
| 1030 |
+ */ |
| 1031 |
+static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f) |
| 1032 |
+{ |
| 1033 |
+ struct autofs_sb_info *sbi = NULL; |
| 1034 |
+ struct inode *inode; |
| 1035 |
+ |
| 1036 |
+ if (f) { |
| 1037 |
+ inode = f->f_path.dentry->d_inode; |
| 1038 |
+ sbi = autofs4_sbi(inode->i_sb); |
| 1039 |
+ } |
| 1040 |
+ return sbi; |
| 1041 |
+} |
| 1042 |
+ |
| 1043 |
+/* Return autofs module protocol version */ |
| 1044 |
+static int autofs_dev_ioctl_protover(struct file *fp, |
| 1045 |
+ struct autofs_sb_info *sbi, |
| 1046 |
+ struct autofs_dev_ioctl *param) |
| 1047 |
+{ |
| 1048 |
+ param->protover.version = sbi->version; |
| 1049 |
+ return 0; |
| 1050 |
+} |
| 1051 |
+ |
| 1052 |
+/* Return autofs module protocol sub version */ |
| 1053 |
+static int autofs_dev_ioctl_protosubver(struct file *fp, |
| 1054 |
+ struct autofs_sb_info *sbi, |
| 1055 |
+ struct autofs_dev_ioctl *param) |
| 1056 |
+{ |
| 1057 |
+ param->protosubver.sub_version = sbi->sub_version; |
| 1058 |
+ return 0; |
| 1059 |
+} |
| 1060 |
+ |
| 1061 |
+/* |
| 1062 |
+ * Walk down the mount stack looking for an autofs mount that |
| 1063 |
+ * has the requested device number (aka. new_encode_dev(sb->s_dev). |
| 1064 |
+ */ |
| 1065 |
+static int autofs_dev_ioctl_find_super(struct nameidata *nd, dev_t devno) |
| 1066 |
+{ |
| 1067 |
+ struct dentry *dentry; |
| 1068 |
+ struct inode *inode; |
| 1069 |
+ struct super_block *sb; |
| 1070 |
+ dev_t s_dev; |
| 1071 |
+ unsigned int err; |
| 1072 |
+ |
| 1073 |
+ err = -ENOENT; |
| 1074 |
+ |
| 1075 |
+ /* Lookup the dentry name at the base of our mount point */ |
| 1076 |
+ dentry = d_lookup(nd->path.dentry, &nd->last); |
| 1077 |
+ if (!dentry) |
| 1078 |
+ goto out; |
| 1079 |
+ |
| 1080 |
+ dput(nd->path.dentry); |
| 1081 |
+ nd->path.dentry = dentry; |
| 1082 |
+ |
| 1083 |
+ /* And follow the mount stack looking for our autofs mount */ |
| 1084 |
+ while (follow_down(&nd->path.mnt, &nd->path.dentry)) { |
| 1085 |
+ inode = nd->path.dentry->d_inode; |
| 1086 |
+ if (!inode) |
| 1087 |
+ break; |
| 1088 |
+ |
| 1089 |
+ sb = inode->i_sb; |
| 1090 |
+ s_dev = new_encode_dev(sb->s_dev); |
| 1091 |
+ if (devno == s_dev) { |
| 1092 |
+ if (sb->s_magic == AUTOFS_SUPER_MAGIC) { |
| 1093 |
+ err = 0; |
| 1094 |
+ break; |
| 1095 |
+ } |
| 1096 |
+ } |
| 1097 |
+ } |
| 1098 |
+out: |
| 1099 |
+ return err; |
| 1100 |
+} |
| 1101 |
+ |
| 1102 |
+/* |
| 1103 |
+ * Walk down the mount stack looking for an autofs mount that |
| 1104 |
+ * has the requested mount type (ie. indirect, direct or offset). |
| 1105 |
+ */ |
| 1106 |
+static int autofs_dev_ioctl_find_sbi_type(struct nameidata *nd, unsigned int type) |
| 1107 |
+{ |
| 1108 |
+ struct dentry *dentry; |
| 1109 |
+ struct autofs_info *ino; |
| 1110 |
+ unsigned int err; |
| 1111 |
+ |
| 1112 |
+ err = -ENOENT; |
| 1113 |
+ |
| 1114 |
+ /* Lookup the dentry name at the base of our mount point */ |
| 1115 |
+ dentry = d_lookup(nd->path.dentry, &nd->last); |
| 1116 |
+ if (!dentry) |
| 1117 |
+ goto out; |
| 1118 |
+ |
| 1119 |
+ dput(nd->path.dentry); |
| 1120 |
+ nd->path.dentry = dentry; |
| 1121 |
+ |
| 1122 |
+ /* And follow the mount stack looking for our autofs mount */ |
| 1123 |
+ while (follow_down(&nd->path.mnt, &nd->path.dentry)) { |
| 1124 |
+ ino = autofs4_dentry_ino(nd->path.dentry); |
| 1125 |
+ if (ino && ino->sbi->type & type) { |
| 1126 |
+ err = 0; |
| 1127 |
+ break; |
| 1128 |
+ } |
| 1129 |
+ } |
| 1130 |
+out: |
| 1131 |
+ return err; |
| 1132 |
+} |
| 1133 |
+ |
| 1134 |
+static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file) |
| 1135 |
+{ |
| 1136 |
+ struct files_struct *files = current->files; |
| 1137 |
+ struct fdtable *fdt; |
| 1138 |
+ |
| 1139 |
+ spin_lock(&files->file_lock); |
| 1140 |
+ fdt = files_fdtable(files); |
| 1141 |
+ BUG_ON(fdt->fd[fd] != NULL); |
| 1142 |
+ rcu_assign_pointer(fdt->fd[fd], file); |
| 1143 |
+ FD_SET(fd, fdt->close_on_exec); |
| 1144 |
+ spin_unlock(&files->file_lock); |
| 1145 |
+} |
| 1146 |
+ |
| 1147 |
+ |
| 1148 |
+/* |
| 1149 |
+ * Open a file descriptor on the autofs mount point corresponding |
| 1150 |
+ * to the given path and device number (aka. new_encode_dev(sb->s_dev)). |
| 1151 |
+ */ |
| 1152 |
+static int autofs_dev_ioctl_open_mountpoint(const char *path, dev_t devid) |
| 1153 |
+{ |
| 1154 |
+ struct file *filp; |
| 1155 |
+ struct nameidata nd; |
| 1156 |
+ int err, fd; |
| 1157 |
+ |
| 1158 |
+ fd = get_unused_fd(); |
| 1159 |
+ if (likely(fd >= 0)) { |
| 1160 |
+ /* Get nameidata of the parent directory */ |
| 1161 |
+ err = path_lookup(path, LOOKUP_PARENT, &nd); |
| 1162 |
+ if (err) |
| 1163 |
+ goto out; |
| 1164 |
+ |
| 1165 |
+ /* |
| 1166 |
+ * Search down, within the parent, looking for an |
| 1167 |
+ * autofs super block that has the device number |
| 1168 |
+ * corresponding to the autofs fs we want to open. |
| 1169 |
+ */ |
| 1170 |
+ err = autofs_dev_ioctl_find_super(&nd, devid); |
| 1171 |
+ if (err) { |
| 1172 |
+ path_put(&nd.path); |
| 1173 |
+ goto out; |
| 1174 |
+ } |
| 1175 |
+ |
| 1176 |
+ filp = dentry_open(nd.path.dentry, nd.path.mnt, O_RDONLY); |
| 1177 |
+ if (IS_ERR(filp)) { |
| 1178 |
+ err = PTR_ERR(filp); |
| 1179 |
+ goto out; |
| 1180 |
+ } |
| 1181 |
+ |
| 1182 |
+ autofs_dev_ioctl_fd_install(fd, filp); |
| 1183 |
+ } |
| 1184 |
+ |
| 1185 |
+ return fd; |
| 1186 |
+ |
| 1187 |
+out: |
| 1188 |
+ put_unused_fd(fd); |
| 1189 |
+ return err; |
| 1190 |
+} |
| 1191 |
+ |
| 1192 |
+/* Open a file descriptor on an autofs mount point */ |
| 1193 |
+static int autofs_dev_ioctl_openmount(struct file *fp, |
| 1194 |
+ struct autofs_sb_info *sbi, |
| 1195 |
+ struct autofs_dev_ioctl *param) |
| 1196 |
+{ |
| 1197 |
+ const char *path; |
| 1198 |
+ dev_t devid; |
| 1199 |
+ int err, fd; |
| 1200 |
+ |
| 1201 |
+ /* param->path has already been checked */ |
| 1202 |
+ if (!param->openmount.devid) |
| 1203 |
+ return -EINVAL; |
| 1204 |
+ |
| 1205 |
+ param->ioctlfd = -1; |
| 1206 |
+ |
| 1207 |
+ path = param->path; |
| 1208 |
+ devid = param->openmount.devid; |
| 1209 |
+ |
| 1210 |
+ err = 0; |
| 1211 |
+ fd = autofs_dev_ioctl_open_mountpoint(path, devid); |
| 1212 |
+ if (unlikely(fd < 0)) { |
| 1213 |
+ err = fd; |
| 1214 |
+ goto out; |
| 1215 |
+ } |
| 1216 |
+ |
| 1217 |
+ param->ioctlfd = fd; |
| 1218 |
+out: |
| 1219 |
+ return err; |
| 1220 |
+} |
| 1221 |
+ |
| 1222 |
+/* Close file descriptor allocated above (user can also use close(2)). */ |
| 1223 |
+static int autofs_dev_ioctl_closemount(struct file *fp, |
| 1224 |
+ struct autofs_sb_info *sbi, |
| 1225 |
+ struct autofs_dev_ioctl *param) |
| 1226 |
+{ |
| 1227 |
+ return sys_close(param->ioctlfd); |
| 1228 |
+} |
| 1229 |
+ |
| 1230 |
+/* |
| 1231 |
+ * Send "ready" status for an existing wait (either a mount or an expire |
| 1232 |
+ * request). |
| 1233 |
+ */ |
| 1234 |
+static int autofs_dev_ioctl_ready(struct file *fp, |
| 1235 |
+ struct autofs_sb_info *sbi, |
| 1236 |
+ struct autofs_dev_ioctl *param) |
| 1237 |
+{ |
| 1238 |
+ autofs_wqt_t token; |
| 1239 |
+ |
| 1240 |
+ token = (autofs_wqt_t) param->ready.token; |
| 1241 |
+ return autofs4_wait_release(sbi, token, 0); |
| 1242 |
+} |
| 1243 |
+ |
| 1244 |
+/* |
| 1245 |
+ * Send "fail" status for an existing wait (either a mount or an expire |
| 1246 |
+ * request). |
| 1247 |
+ */ |
| 1248 |
+static int autofs_dev_ioctl_fail(struct file *fp, |
| 1249 |
+ struct autofs_sb_info *sbi, |
| 1250 |
+ struct autofs_dev_ioctl *param) |
| 1251 |
+{ |
| 1252 |
+ autofs_wqt_t token; |
| 1253 |
+ int status; |
| 1254 |
+ |
| 1255 |
+ token = (autofs_wqt_t) param->fail.token; |
| 1256 |
+ status = param->fail.status ? param->fail.status : -ENOENT; |
| 1257 |
+ return autofs4_wait_release(sbi, token, status); |
| 1258 |
+} |
| 1259 |
+ |
| 1260 |
+/* |
| 1261 |
+ * Set the pipe fd for kernel communication to the daemon. |
| 1262 |
+ * |
| 1263 |
+ * Normally this is set at mount using an option but if we |
| 1264 |
+ * are reconnecting to a busy mount then we need to use this |
| 1265 |
+ * to tell the autofs mount about the new kernel pipe fd. In |
| 1266 |
+ * order to protect mounts against incorrectly setting the |
| 1267 |
+ * pipefd we also require that the autofs mount be catatonic. |
| 1268 |
+ * |
| 1269 |
+ * This also sets the process group id used to identify the |
| 1270 |
+ * controlling process (eg. the owning automount(8) daemon). |
| 1271 |
+ */ |
| 1272 |
+static int autofs_dev_ioctl_setpipefd(struct file *fp, |
| 1273 |
+ struct autofs_sb_info *sbi, |
| 1274 |
+ struct autofs_dev_ioctl *param) |
| 1275 |
+{ |
| 1276 |
+ int pipefd; |
| 1277 |
+ int err = 0; |
| 1278 |
+ |
| 1279 |
+ if (param->setpipefd.pipefd == -1) |
| 1280 |
+ return -EINVAL; |
| 1281 |
+ |
| 1282 |
+ pipefd = param->setpipefd.pipefd; |
| 1283 |
+ |
| 1284 |
+ mutex_lock(&sbi->wq_mutex); |
| 1285 |
+ if (!sbi->catatonic) { |
| 1286 |
+ mutex_unlock(&sbi->wq_mutex); |
| 1287 |
+ return -EBUSY; |
| 1288 |
+ } else { |
| 1289 |
+ struct file *pipe = fget(pipefd); |
| 1290 |
+ if (!pipe->f_op || !pipe->f_op->write) { |
| 1291 |
+ err = -EPIPE; |
| 1292 |
+ fput(pipe); |
| 1293 |
+ goto out; |
| 1294 |
+ } |
| 1295 |
+ sbi->oz_pgrp = task_pgrp_nr(current); |
| 1296 |
+ sbi->pipefd = pipefd; |
| 1297 |
+ sbi->pipe = pipe; |
| 1298 |
+ sbi->catatonic = 0; |
| 1299 |
+ } |
| 1300 |
+out: |
| 1301 |
+ mutex_unlock(&sbi->wq_mutex); |
| 1302 |
+ return err; |
| 1303 |
+} |
| 1304 |
+ |
| 1305 |
+/* |
| 1306 |
+ * Make the autofs mount point catatonic, no longer responsive to |
| 1307 |
+ * mount requests. Also closes the kernel pipe file descriptor. |
| 1308 |
+ */ |
| 1309 |
+static int autofs_dev_ioctl_catatonic(struct file *fp, |
| 1310 |
+ struct autofs_sb_info *sbi, |
| 1311 |
+ struct autofs_dev_ioctl *param) |
| 1312 |
+{ |
| 1313 |
+ autofs4_catatonic_mode(sbi); |
| 1314 |
+ return 0; |
| 1315 |
+} |
| 1316 |
+ |
| 1317 |
+/* Set the autofs mount timeout */ |
| 1318 |
+static int autofs_dev_ioctl_timeout(struct file *fp, |
| 1319 |
+ struct autofs_sb_info *sbi, |
| 1320 |
+ struct autofs_dev_ioctl *param) |
| 1321 |
+{ |
| 1322 |
+ unsigned long timeout; |
| 1323 |
+ |
| 1324 |
+ timeout = param->timeout.timeout; |
| 1325 |
+ param->timeout.timeout = sbi->exp_timeout / HZ; |
| 1326 |
+ sbi->exp_timeout = timeout * HZ; |
| 1327 |
+ return 0; |
| 1328 |
+} |
| 1329 |
+ |
| 1330 |
+/* |
| 1331 |
+ * Return the uid and gid of the last request for the mount |
| 1332 |
+ * |
| 1333 |
+ * When reconstructing an autofs mount tree with active mounts |
| 1334 |
+ * we need to re-connect to mounts that may have used the original |
| 1335 |
+ * process uid and gid (or string variations of them) for mount |
| 1336 |
+ * lookups within the map entry. |
| 1337 |
+ */ |
| 1338 |
+static int autofs_dev_ioctl_requester(struct file *fp, |
| 1339 |
+ struct autofs_sb_info *sbi, |
| 1340 |
+ struct autofs_dev_ioctl *param) |
| 1341 |
+{ |
| 1342 |
+ struct autofs_info *ino; |
| 1343 |
+ struct nameidata nd; |
| 1344 |
+ const char *path; |
| 1345 |
+ dev_t devid; |
| 1346 |
+ int err = -ENOENT; |
| 1347 |
+ |
| 1348 |
+ if (param->size <= sizeof(*param)) { |
| 1349 |
+ err = -EINVAL; |
| 1350 |
+ goto out; |
| 1351 |
+ } |
| 1352 |
+ |
| 1353 |
+ path = param->path; |
| 1354 |
+ devid = sbi->sb->s_dev; |
| 1355 |
+ |
| 1356 |
+ param->requester.uid = param->requester.gid = -1; |
| 1357 |
+ |
| 1358 |
+ /* Get nameidata of the parent directory */ |
| 1359 |
+ err = path_lookup(path, LOOKUP_PARENT, &nd); |
| 1360 |
+ if (err) |
| 1361 |
+ goto out; |
| 1362 |
+ |
| 1363 |
+ err = autofs_dev_ioctl_find_super(&nd, devid); |
| 1364 |
+ if (err) |
| 1365 |
+ goto out_release; |
| 1366 |
+ |
| 1367 |
+ ino = autofs4_dentry_ino(nd.path.dentry); |
| 1368 |
+ if (ino) { |
| 1369 |
+ err = 0; |
| 1370 |
+ autofs4_expire_wait(nd.path.dentry); |
| 1371 |
+ spin_lock(&sbi->fs_lock); |
| 1372 |
+ param->requester.uid = ino->uid; |
| 1373 |
+ param->requester.gid = ino->gid; |
| 1374 |
+ spin_unlock(&sbi->fs_lock); |
| 1375 |
+ } |
| 1376 |
+ |
| 1377 |
+out_release: |
| 1378 |
+ path_put(&nd.path); |
| 1379 |
+out: |
| 1380 |
+ return err; |
| 1381 |
+} |
| 1382 |
+ |
| 1383 |
+/* |
| 1384 |
+ * Call repeatedly until it returns -EAGAIN, meaning there's nothing |
| 1385 |
+ * more that can be done. |
| 1386 |
+ */ |
| 1387 |
+static int autofs_dev_ioctl_expire(struct file *fp, |
| 1388 |
+ struct autofs_sb_info *sbi, |
| 1389 |
+ struct autofs_dev_ioctl *param) |
| 1390 |
+{ |
| 1391 |
+ struct vfsmount *mnt; |
| 1392 |
+ int how; |
| 1393 |
+ |
| 1394 |
+ how = param->expire.how; |
| 1395 |
+ mnt = fp->f_path.mnt; |
| 1396 |
+ |
| 1397 |
+ return autofs4_do_expire_multi(sbi->sb, mnt, sbi, how); |
| 1398 |
+} |
| 1399 |
+ |
| 1400 |
+/* Check if autofs mount point is in use */ |
| 1401 |
+static int autofs_dev_ioctl_askumount(struct file *fp, |
| 1402 |
+ struct autofs_sb_info *sbi, |
| 1403 |
+ struct autofs_dev_ioctl *param) |
| 1404 |
+{ |
| 1405 |
+ param->askumount.may_umount = 0; |
| 1406 |
+ if (may_umount(fp->f_path.mnt)) |
| 1407 |
+ param->askumount.may_umount = 1; |
| 1408 |
+ return 0; |
| 1409 |
+} |
| 1410 |
+ |
| 1411 |
+/* |
| 1412 |
+ * Check if the given path is a mountpoint. |
| 1413 |
+ * |
| 1414 |
+ * If we are supplied with the file descriptor of an autofs |
| 1415 |
+ * mount we're looking for a specific mount. In this case |
| 1416 |
+ * the path is considered a mountpoint if it is itself a |
| 1417 |
+ * mountpoint or contains a mount, such as a multi-mount |
| 1418 |
+ * without a root mount. In this case we return 1 if the |
| 1419 |
+ * path is a mount point and the super magic of the covering |
| 1420 |
+ * mount if there is one or 0 if it isn't a mountpoint. |
| 1421 |
+ * |
| 1422 |
+ * If we aren't supplied with a file descriptor then we |
| 1423 |
+ * lookup the nameidata of the path and check if it is the |
| 1424 |
+ * root of a mount. If a type is given we are looking for |
| 1425 |
+ * a particular autofs mount and if we don't find a match |
| 1426 |
+ * we return fail. If the located nameidata path is the |
| 1427 |
+ * root of a mount we return 1 along with the super magic |
| 1428 |
+ * of the mount or 0 otherwise. |
| 1429 |
+ * |
| 1430 |
+ * In both cases the the device number (as returned by |
| 1431 |
+ * new_encode_dev()) is also returned. |
| 1432 |
+ */ |
| 1433 |
+static int autofs_dev_ioctl_ismountpoint(struct file *fp, |
| 1434 |
+ struct autofs_sb_info *sbi, |
| 1435 |
+ struct autofs_dev_ioctl *param) |
| 1436 |
+{ |
| 1437 |
+ struct nameidata nd; |
| 1438 |
+ const char *path; |
| 1439 |
+ unsigned int type; |
| 1440 |
+ unsigned int devid, magic; |
| 1441 |
+ int err = -ENOENT; |
| 1442 |
+ |
| 1443 |
+ if (param->size <= sizeof(*param)) { |
| 1444 |
+ err = -EINVAL; |
| 1445 |
+ goto out; |
| 1446 |
+ } |
| 1447 |
+ |
| 1448 |
+ path = param->path; |
| 1449 |
+ type = param->ismountpoint.in.type; |
| 1450 |
+ |
| 1451 |
+ param->ismountpoint.out.devid = devid = 0; |
| 1452 |
+ param->ismountpoint.out.magic = magic = 0; |
| 1453 |
+ |
| 1454 |
+ if (!fp || param->ioctlfd == -1) { |
| 1455 |
+ if (autofs_type_any(type)) { |
| 1456 |
+ struct super_block *sb; |
| 1457 |
+ |
| 1458 |
+ err = path_lookup(path, LOOKUP_FOLLOW, &nd); |
| 1459 |
+ if (err) |
| 1460 |
+ goto out; |
| 1461 |
+ |
| 1462 |
+ sb = nd.path.dentry->d_sb; |
| 1463 |
+ devid = new_encode_dev(sb->s_dev); |
| 1464 |
+ } else { |
| 1465 |
+ struct autofs_info *ino; |
| 1466 |
+ |
| 1467 |
+ err = path_lookup(path, LOOKUP_PARENT, &nd); |
| 1468 |
+ if (err) |
| 1469 |
+ goto out; |
| 1470 |
+ |
| 1471 |
+ err = autofs_dev_ioctl_find_sbi_type(&nd, type); |
| 1472 |
+ if (err) |
| 1473 |
+ goto out_release; |
| 1474 |
+ |
| 1475 |
+ ino = autofs4_dentry_ino(nd.path.dentry); |
| 1476 |
+ devid = autofs4_get_dev(ino->sbi); |
| 1477 |
+ } |
| 1478 |
+ |
| 1479 |
+ err = 0; |
| 1480 |
+ if (nd.path.dentry->d_inode && |
| 1481 |
+ nd.path.mnt->mnt_root == nd.path.dentry) { |
| 1482 |
+ err = 1; |
| 1483 |
+ magic = nd.path.dentry->d_inode->i_sb->s_magic; |
| 1484 |
+ } |
| 1485 |
+ } else { |
| 1486 |
+ dev_t dev = autofs4_get_dev(sbi); |
| 1487 |
+ |
| 1488 |
+ err = path_lookup(path, LOOKUP_PARENT, &nd); |
| 1489 |
+ if (err) |
| 1490 |
+ goto out; |
| 1491 |
+ |
| 1492 |
+ err = autofs_dev_ioctl_find_super(&nd, dev); |
| 1493 |
+ if (err) |
| 1494 |
+ goto out_release; |
| 1495 |
+ |
| 1496 |
+ devid = dev; |
| 1497 |
+ |
| 1498 |
+ err = have_submounts(nd.path.dentry); |
| 1499 |
+ |
| 1500 |
+ if (nd.path.mnt->mnt_mountpoint != nd.path.mnt->mnt_root) { |
| 1501 |
+ if (follow_down(&nd.path.mnt, &nd.path.dentry)) { |
| 1502 |
+ struct inode *inode = nd.path.dentry->d_inode; |
| 1503 |
+ magic = inode->i_sb->s_magic; |
| 1504 |
+ } |
| 1505 |
+ } |
| 1506 |
+ } |
| 1507 |
+ |
| 1508 |
+ param->ismountpoint.out.devid = devid; |
| 1509 |
+ param->ismountpoint.out.magic = magic; |
| 1510 |
+ |
| 1511 |
+out_release: |
| 1512 |
+ path_put(&nd.path); |
| 1513 |
+out: |
| 1514 |
+ return err; |
| 1515 |
+} |
| 1516 |
+ |
| 1517 |
+/* |
| 1518 |
+ * Our range of ioctl numbers isn't 0 based so we need to shift |
| 1519 |
+ * the array index by _IOC_NR(AUTOFS_CTL_IOC_FIRST) for the table |
| 1520 |
+ * lookup. |
| 1521 |
+ */ |
| 1522 |
+#define cmd_idx(cmd) (cmd - _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST)) |
| 1523 |
+ |
| 1524 |
+static ioctl_fn lookup_dev_ioctl(unsigned int cmd) |
| 1525 |
+{ |
| 1526 |
+ static struct { |
| 1527 |
+ int cmd; |
| 1528 |
+ ioctl_fn fn; |
| 1529 |
+ } _ioctls[] = { |
| 1530 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD), NULL}, |
| 1531 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_PROTOVER_CMD), |
| 1532 |
+ autofs_dev_ioctl_protover}, |
| 1533 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD), |
| 1534 |
+ autofs_dev_ioctl_protosubver}, |
| 1535 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_OPENMOUNT_CMD), |
| 1536 |
+ autofs_dev_ioctl_openmount}, |
| 1537 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD), |
| 1538 |
+ autofs_dev_ioctl_closemount}, |
| 1539 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_READY_CMD), |
| 1540 |
+ autofs_dev_ioctl_ready}, |
| 1541 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_FAIL_CMD), |
| 1542 |
+ autofs_dev_ioctl_fail}, |
| 1543 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_SETPIPEFD_CMD), |
| 1544 |
+ autofs_dev_ioctl_setpipefd}, |
| 1545 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_CATATONIC_CMD), |
| 1546 |
+ autofs_dev_ioctl_catatonic}, |
| 1547 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_TIMEOUT_CMD), |
| 1548 |
+ autofs_dev_ioctl_timeout}, |
| 1549 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_REQUESTER_CMD), |
| 1550 |
+ autofs_dev_ioctl_requester}, |
| 1551 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_EXPIRE_CMD), |
| 1552 |
+ autofs_dev_ioctl_expire}, |
| 1553 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD), |
| 1554 |
+ autofs_dev_ioctl_askumount}, |
| 1555 |
+ {cmd_idx(AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD), |
| 1556 |
+ autofs_dev_ioctl_ismountpoint} |
| 1557 |
+ }; |
| 1558 |
+ unsigned int idx = cmd_idx(cmd); |
| 1559 |
+ |
| 1560 |
+ return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx].fn; |
| 1561 |
+} |
| 1562 |
+ |
| 1563 |
+/* ioctl dispatcher */ |
| 1564 |
+static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __user *user) |
| 1565 |
+{ |
| 1566 |
+ struct autofs_dev_ioctl *param; |
| 1567 |
+ struct file *fp; |
| 1568 |
+ struct autofs_sb_info *sbi; |
| 1569 |
+ unsigned int cmd_first, cmd; |
| 1570 |
+ ioctl_fn fn = NULL; |
| 1571 |
+ int err = 0; |
| 1572 |
+ |
| 1573 |
+ /* only root can play with this */ |
| 1574 |
+ if (!capable(CAP_SYS_ADMIN)) |
| 1575 |
+ return -EPERM; |
| 1576 |
+ |
| 1577 |
+ cmd_first = _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST); |
| 1578 |
+ cmd = _IOC_NR(command); |
| 1579 |
+ |
| 1580 |
+ if (_IOC_TYPE(command) != _IOC_TYPE(AUTOFS_DEV_IOCTL_IOC_FIRST) || |
| 1581 |
+ cmd - cmd_first >= AUTOFS_DEV_IOCTL_IOC_COUNT) { |
| 1582 |
+ return -ENOTTY; |
| 1583 |
+ } |
| 1584 |
+ |
| 1585 |
+ /* Copy the parameters into kernel space. */ |
| 1586 |
+ param = copy_dev_ioctl(user); |
| 1587 |
+ if (IS_ERR(param)) |
| 1588 |
+ return PTR_ERR(param); |
| 1589 |
+ |
| 1590 |
+ err = validate_dev_ioctl(command, param); |
| 1591 |
+ if (err) |
| 1592 |
+ goto out; |
| 1593 |
+ |
| 1594 |
+ /* The validate routine above always sets the version */ |
| 1595 |
+ if (cmd == AUTOFS_DEV_IOCTL_VERSION_CMD) |
| 1596 |
+ goto done; |
| 1597 |
+ |
| 1598 |
+ fn = lookup_dev_ioctl(cmd); |
| 1599 |
+ if (!fn) { |
| 1600 |
+ AUTOFS_WARN("unknown command 0x%08x", command); |
| 1601 |
+ return -ENOTTY; |
| 1602 |
+ } |
| 1603 |
+ |
| 1604 |
+ fp = NULL; |
| 1605 |
+ sbi = NULL; |
| 1606 |
+ |
| 1607 |
+ /* |
| 1608 |
+ * For obvious reasons the openmount can't have a file |
| 1609 |
+ * descriptor yet. We don't take a reference to the |
| 1610 |
+ * file during close to allow for immediate release. |
| 1611 |
+ */ |
| 1612 |
+ if (cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD && |
| 1613 |
+ cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) { |
| 1614 |
+ fp = fget(param->ioctlfd); |
| 1615 |
+ if (!fp) { |
| 1616 |
+ if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD) |
| 1617 |
+ goto cont; |
| 1618 |
+ err = -EBADF; |
| 1619 |
+ goto out; |
| 1620 |
+ } |
| 1621 |
+ |
| 1622 |
+ if (!fp->f_op) { |
| 1623 |
+ err = -ENOTTY; |
| 1624 |
+ fput(fp); |
| 1625 |
+ goto out; |
| 1626 |
+ } |
| 1627 |
+ |
| 1628 |
+ sbi = autofs_dev_ioctl_sbi(fp); |
| 1629 |
+ if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) { |
| 1630 |
+ err = -EINVAL; |
| 1631 |
+ fput(fp); |
| 1632 |
+ goto out; |
| 1633 |
+ } |
| 1634 |
+ |
| 1635 |
+ /* |
| 1636 |
+ * Admin needs to be able to set the mount catatonic in |
| 1637 |
+ * order to be able to perform the re-open. |
| 1638 |
+ */ |
| 1639 |
+ if (!autofs4_oz_mode(sbi) && |
| 1640 |
+ cmd != AUTOFS_DEV_IOCTL_CATATONIC_CMD) { |
| 1641 |
+ err = -EACCES; |
| 1642 |
+ fput(fp); |
| 1643 |
+ goto out; |
| 1644 |
+ } |
| 1645 |
+ } |
| 1646 |
+cont: |
| 1647 |
+ err = fn(fp, sbi, param); |
| 1648 |
+ |
| 1649 |
+ if (fp) |
| 1650 |
+ fput(fp); |
| 1651 |
+done: |
| 1652 |
+ if (err >= 0 && copy_to_user(user, param, AUTOFS_DEV_IOCTL_SIZE)) |
| 1653 |
+ err = -EFAULT; |
| 1654 |
+out: |
| 1655 |
+ free_dev_ioctl(param); |
| 1656 |
+ return err; |
| 1657 |
+} |
| 1658 |
+ |
| 1659 |
+static long autofs_dev_ioctl(struct file *file, uint command, ulong u) |
| 1660 |
+{ |
| 1661 |
+ int err; |
| 1662 |
+ err = _autofs_dev_ioctl(command, (struct autofs_dev_ioctl __user *) u); |
| 1663 |
+ return (long) err; |
| 1664 |
+} |
| 1665 |
+ |
| 1666 |
+#ifdef CONFIG_COMPAT |
| 1667 |
+static long autofs_dev_ioctl_compat(struct file *file, uint command, ulong u) |
| 1668 |
+{ |
| 1669 |
+ return (long) autofs_dev_ioctl(file, command, (ulong) compat_ptr(u)); |
| 1670 |
+} |
| 1671 |
+#else |
| 1672 |
+#define autofs_dev_ioctl_compat NULL |
| 1673 |
+#endif |
| 1674 |
+ |
| 1675 |
+static const struct file_operations _dev_ioctl_fops = { |
| 1676 |
+ .unlocked_ioctl = autofs_dev_ioctl, |
| 1677 |
+ .compat_ioctl = autofs_dev_ioctl_compat, |
| 1678 |
+ .owner = THIS_MODULE, |
| 1679 |
+}; |
| 1680 |
+ |
| 1681 |
+static struct miscdevice _autofs_dev_ioctl_misc = { |
| 1682 |
+ .minor = MISC_DYNAMIC_MINOR, |
| 1683 |
+ .name = AUTOFS_DEVICE_NAME, |
| 1684 |
+ .fops = &_dev_ioctl_fops |
| 1685 |
+}; |
| 1686 |
+ |
| 1687 |
+/* Register/deregister misc character device */ |
| 1688 |
+int autofs_dev_ioctl_init(void) |
| 1689 |
+{ |
| 1690 |
+ int r; |
| 1691 |
+ |
| 1692 |
+ r = misc_register(&_autofs_dev_ioctl_misc); |
| 1693 |
+ if (r) { |
| 1694 |
+ AUTOFS_ERROR("misc_register failed for control device"); |
| 1695 |
+ return r; |
| 1696 |
+ } |
| 1697 |
+ |
| 1698 |
+ return 0; |
| 1699 |
+} |
| 1700 |
+ |
| 1701 |
+void autofs_dev_ioctl_exit(void) |
| 1702 |
+{ |
| 1703 |
+ misc_deregister(&_autofs_dev_ioctl_misc); |
| 1704 |
+ return; |
| 1705 |
+} |
| 1706 |
+ |
| 1707 |
--- linux-2.6.27.orig/fs/autofs4/init.c |
| 1708 |
+++ linux-2.6.27/fs/autofs4/init.c |
| 1709 |
@@ -29,11 +29,20 @@ static struct file_system_type autofs_fs |
| 1710 |
|
| 1711 |
static int __init init_autofs4_fs(void) |
| 1712 |
{ |
| 1713 |
- return register_filesystem(&autofs_fs_type); |
| 1714 |
+ int err; |
| 1715 |
+ |
| 1716 |
+ err = register_filesystem(&autofs_fs_type); |
| 1717 |
+ if (err) |
| 1718 |
+ return err; |
| 1719 |
+ |
| 1720 |
+ autofs_dev_ioctl_init(); |
| 1721 |
+ |
| 1722 |
+ return err; |
| 1723 |
} |
| 1724 |
|
| 1725 |
static void __exit exit_autofs4_fs(void) |
| 1726 |
{ |
| 1727 |
+ autofs_dev_ioctl_exit(); |
| 1728 |
unregister_filesystem(&autofs_fs_type); |
| 1729 |
} |
| 1730 |
|
| 1731 |
--- /dev/null |
| 1732 |
+++ linux-2.6.27/include/linux/auto_dev-ioctl.h |
| 1733 |
@@ -0,0 +1,229 @@ |
| 1734 |
+/* |
| 1735 |
+ * Copyright 2008 Red Hat, Inc. All rights reserved. |
| 1736 |
+ * Copyright 2008 Ian Kent <[email protected]> |
| 1737 |
+ * |
| 1738 |
+ * This file is part of the Linux kernel and is made available under |
| 1739 |
+ * the terms of the GNU General Public License, version 2, or at your |
| 1740 |
+ * option, any later version, incorporated herein by reference. |
| 1741 |
+ */ |
| 1742 |
+ |
| 1743 |
+#ifndef _LINUX_AUTO_DEV_IOCTL_H |
| 1744 |
+#define _LINUX_AUTO_DEV_IOCTL_H |
| 1745 |
+ |
| 1746 |
+#include <linux/auto_fs.h> |
| 1747 |
+ |
| 1748 |
+#ifdef __KERNEL__ |
| 1749 |
+#include <linux/string.h> |
| 1750 |
+#else |
| 1751 |
+#include <string.h> |
| 1752 |
+#endif /* __KERNEL__ */ |
| 1753 |
+ |
| 1754 |
+#define AUTOFS_DEVICE_NAME "autofs" |
| 1755 |
+ |
| 1756 |
+#define AUTOFS_DEV_IOCTL_VERSION_MAJOR 1 |
| 1757 |
+#define AUTOFS_DEV_IOCTL_VERSION_MINOR 0 |
| 1758 |
+ |
| 1759 |
+#define AUTOFS_DEVID_LEN 16 |
| 1760 |
+ |
| 1761 |
+#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl) |
| 1762 |
+ |
| 1763 |
+/* |
| 1764 |
+ * An ioctl interface for autofs mount point control. |
| 1765 |
+ */ |
| 1766 |
+ |
| 1767 |
+struct args_protover { |
| 1768 |
+ __u32 version; |
| 1769 |
+}; |
| 1770 |
+ |
| 1771 |
+struct args_protosubver { |
| 1772 |
+ __u32 sub_version; |
| 1773 |
+}; |
| 1774 |
+ |
| 1775 |
+struct args_openmount { |
| 1776 |
+ __u32 devid; |
| 1777 |
+}; |
| 1778 |
+ |
| 1779 |
+struct args_ready { |
| 1780 |
+ __u32 token; |
| 1781 |
+}; |
| 1782 |
+ |
| 1783 |
+struct args_fail { |
| 1784 |
+ __u32 token; |
| 1785 |
+ __s32 status; |
| 1786 |
+}; |
| 1787 |
+ |
| 1788 |
+struct args_setpipefd { |
| 1789 |
+ __s32 pipefd; |
| 1790 |
+}; |
| 1791 |
+ |
| 1792 |
+struct args_timeout { |
| 1793 |
+ __u64 timeout; |
| 1794 |
+}; |
| 1795 |
+ |
| 1796 |
+struct args_requester { |
| 1797 |
+ __u32 uid; |
| 1798 |
+ __u32 gid; |
| 1799 |
+}; |
| 1800 |
+ |
| 1801 |
+struct args_expire { |
| 1802 |
+ __u32 how; |
| 1803 |
+}; |
| 1804 |
+ |
| 1805 |
+struct args_askumount { |
| 1806 |
+ __u32 may_umount; |
| 1807 |
+}; |
| 1808 |
+ |
| 1809 |
+struct args_ismountpoint { |
| 1810 |
+ union { |
| 1811 |
+ struct args_in { |
| 1812 |
+ __u32 type; |
| 1813 |
+ } in; |
| 1814 |
+ struct args_out { |
| 1815 |
+ __u32 devid; |
| 1816 |
+ __u32 magic; |
| 1817 |
+ } out; |
| 1818 |
+ }; |
| 1819 |
+}; |
| 1820 |
+ |
| 1821 |
+/* |
| 1822 |
+ * All the ioctls use this structure. |
| 1823 |
+ * When sending a path size must account for the total length |
| 1824 |
+ * of the chunk of memory otherwise is is the size of the |
| 1825 |
+ * structure. |
| 1826 |
+ */ |
| 1827 |
+ |
| 1828 |
+struct autofs_dev_ioctl { |
| 1829 |
+ __u32 ver_major; |
| 1830 |
+ __u32 ver_minor; |
| 1831 |
+ __u32 size; /* total size of data passed in |
| 1832 |
+ * including this struct */ |
| 1833 |
+ __s32 ioctlfd; /* automount command fd */ |
| 1834 |
+ |
| 1835 |
+ /* Command parameters */ |
| 1836 |
+ |
| 1837 |
+ union { |
| 1838 |
+ struct args_protover protover; |
| 1839 |
+ struct args_protosubver protosubver; |
| 1840 |
+ struct args_openmount openmount; |
| 1841 |
+ struct args_ready ready; |
| 1842 |
+ struct args_fail fail; |
| 1843 |
+ struct args_setpipefd setpipefd; |
| 1844 |
+ struct args_timeout timeout; |
| 1845 |
+ struct args_requester requester; |
| 1846 |
+ struct args_expire expire; |
| 1847 |
+ struct args_askumount askumount; |
| 1848 |
+ struct args_ismountpoint ismountpoint; |
| 1849 |
+ }; |
| 1850 |
+ |
| 1851 |
+ char path[0]; |
| 1852 |
+}; |
| 1853 |
+ |
| 1854 |
+static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in) |
| 1855 |
+{ |
| 1856 |
+ memset(in, 0, sizeof(struct autofs_dev_ioctl)); |
| 1857 |
+ in->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR; |
| 1858 |
+ in->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR; |
| 1859 |
+ in->size = sizeof(struct autofs_dev_ioctl); |
| 1860 |
+ in->ioctlfd = -1; |
| 1861 |
+ return; |
| 1862 |
+} |
| 1863 |
+ |
| 1864 |
+/* |
| 1865 |
+ * If you change this make sure you make the corresponding change |
| 1866 |
+ * to autofs-dev-ioctl.c:lookup_ioctl() |
| 1867 |
+ */ |
| 1868 |
+enum { |
| 1869 |
+ /* Get various version info */ |
| 1870 |
+ AUTOFS_DEV_IOCTL_VERSION_CMD = 0x71, |
| 1871 |
+ AUTOFS_DEV_IOCTL_PROTOVER_CMD, |
| 1872 |
+ AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD, |
| 1873 |
+ |
| 1874 |
+ /* Open mount ioctl fd */ |
| 1875 |
+ AUTOFS_DEV_IOCTL_OPENMOUNT_CMD, |
| 1876 |
+ |
| 1877 |
+ /* Close mount ioctl fd */ |
| 1878 |
+ AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD, |
| 1879 |
+ |
| 1880 |
+ /* Mount/expire status returns */ |
| 1881 |
+ AUTOFS_DEV_IOCTL_READY_CMD, |
| 1882 |
+ AUTOFS_DEV_IOCTL_FAIL_CMD, |
| 1883 |
+ |
| 1884 |
+ /* Activate/deactivate autofs mount */ |
| 1885 |
+ AUTOFS_DEV_IOCTL_SETPIPEFD_CMD, |
| 1886 |
+ AUTOFS_DEV_IOCTL_CATATONIC_CMD, |
| 1887 |
+ |
| 1888 |
+ /* Expiry timeout */ |
| 1889 |
+ AUTOFS_DEV_IOCTL_TIMEOUT_CMD, |
| 1890 |
+ |
| 1891 |
+ /* Get mount last requesting uid and gid */ |
| 1892 |
+ AUTOFS_DEV_IOCTL_REQUESTER_CMD, |
| 1893 |
+ |
| 1894 |
+ /* Check for eligible expire candidates */ |
| 1895 |
+ AUTOFS_DEV_IOCTL_EXPIRE_CMD, |
| 1896 |
+ |
| 1897 |
+ /* Request busy status */ |
| 1898 |
+ AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD, |
| 1899 |
+ |
| 1900 |
+ /* Check if path is a mountpoint */ |
| 1901 |
+ AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD, |
| 1902 |
+}; |
| 1903 |
+ |
| 1904 |
+#define AUTOFS_IOCTL 0x93 |
| 1905 |
+ |
| 1906 |
+#define AUTOFS_DEV_IOCTL_VERSION \ |
| 1907 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1908 |
+ AUTOFS_DEV_IOCTL_VERSION_CMD, struct autofs_dev_ioctl) |
| 1909 |
+ |
| 1910 |
+#define AUTOFS_DEV_IOCTL_PROTOVER \ |
| 1911 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1912 |
+ AUTOFS_DEV_IOCTL_PROTOVER_CMD, struct autofs_dev_ioctl) |
| 1913 |
+ |
| 1914 |
+#define AUTOFS_DEV_IOCTL_PROTOSUBVER \ |
| 1915 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1916 |
+ AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD, struct autofs_dev_ioctl) |
| 1917 |
+ |
| 1918 |
+#define AUTOFS_DEV_IOCTL_OPENMOUNT \ |
| 1919 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1920 |
+ AUTOFS_DEV_IOCTL_OPENMOUNT_CMD, struct autofs_dev_ioctl) |
| 1921 |
+ |
| 1922 |
+#define AUTOFS_DEV_IOCTL_CLOSEMOUNT \ |
| 1923 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1924 |
+ AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD, struct autofs_dev_ioctl) |
| 1925 |
+ |
| 1926 |
+#define AUTOFS_DEV_IOCTL_READY \ |
| 1927 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1928 |
+ AUTOFS_DEV_IOCTL_READY_CMD, struct autofs_dev_ioctl) |
| 1929 |
+ |
| 1930 |
+#define AUTOFS_DEV_IOCTL_FAIL \ |
| 1931 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1932 |
+ AUTOFS_DEV_IOCTL_FAIL_CMD, struct autofs_dev_ioctl) |
| 1933 |
+ |
| 1934 |
+#define AUTOFS_DEV_IOCTL_SETPIPEFD \ |
| 1935 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1936 |
+ AUTOFS_DEV_IOCTL_SETPIPEFD_CMD, struct autofs_dev_ioctl) |
| 1937 |
+ |
| 1938 |
+#define AUTOFS_DEV_IOCTL_CATATONIC \ |
| 1939 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1940 |
+ AUTOFS_DEV_IOCTL_CATATONIC_CMD, struct autofs_dev_ioctl) |
| 1941 |
+ |
| 1942 |
+#define AUTOFS_DEV_IOCTL_TIMEOUT \ |
| 1943 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1944 |
+ AUTOFS_DEV_IOCTL_TIMEOUT_CMD, struct autofs_dev_ioctl) |
| 1945 |
+ |
| 1946 |
+#define AUTOFS_DEV_IOCTL_REQUESTER \ |
| 1947 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1948 |
+ AUTOFS_DEV_IOCTL_REQUESTER_CMD, struct autofs_dev_ioctl) |
| 1949 |
+ |
| 1950 |
+#define AUTOFS_DEV_IOCTL_EXPIRE \ |
| 1951 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1952 |
+ AUTOFS_DEV_IOCTL_EXPIRE_CMD, struct autofs_dev_ioctl) |
| 1953 |
+ |
| 1954 |
+#define AUTOFS_DEV_IOCTL_ASKUMOUNT \ |
| 1955 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1956 |
+ AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD, struct autofs_dev_ioctl) |
| 1957 |
+ |
| 1958 |
+#define AUTOFS_DEV_IOCTL_ISMOUNTPOINT \ |
| 1959 |
+ _IOWR(AUTOFS_IOCTL, \ |
| 1960 |
+ AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD, struct autofs_dev_ioctl) |
| 1961 |
+ |
| 1962 |
+#endif /* _LINUX_AUTO_DEV_IOCTL_H */ |
| 1963 |
--- linux-2.6.27.orig/fs/autofs4/root.c |
| 1964 |
+++ linux-2.6.27/fs/autofs4/root.c |
| 1965 |
@@ -485,22 +485,6 @@ static struct dentry *autofs4_lookup(str |
| 1966 |
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", |
| 1967 |
current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); |
| 1968 |
|
| 1969 |
- expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name); |
| 1970 |
- if (expiring) { |
| 1971 |
- /* |
| 1972 |
- * If we are racing with expire the request might not |
| 1973 |
- * be quite complete but the directory has been removed |
| 1974 |
- * so it must have been successful, so just wait for it. |
| 1975 |
- */ |
| 1976 |
- ino = autofs4_dentry_ino(expiring); |
| 1977 |
- autofs4_expire_wait(expiring); |
| 1978 |
- spin_lock(&sbi->lookup_lock); |
| 1979 |
- if (!list_empty(&ino->expiring)) |
| 1980 |
- list_del_init(&ino->expiring); |
| 1981 |
- spin_unlock(&sbi->lookup_lock); |
| 1982 |
- dput(expiring); |
| 1983 |
- } |
| 1984 |
- |
| 1985 |
unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name); |
| 1986 |
if (unhashed) |
| 1987 |
dentry = unhashed; |
| 1988 |
@@ -538,14 +522,31 @@ static struct dentry *autofs4_lookup(str |
| 1989 |
} |
| 1990 |
|
| 1991 |
if (!oz_mode) { |
| 1992 |
+ mutex_unlock(&dir->i_mutex); |
| 1993 |
+ expiring = autofs4_lookup_expiring(sbi, |
| 1994 |
+ dentry->d_parent, |
| 1995 |
+ &dentry->d_name); |
| 1996 |
+ if (expiring) { |
| 1997 |
+ /* |
| 1998 |
+ * If we are racing with expire the request might not |
| 1999 |
+ * be quite complete but the directory has been removed |
| 2000 |
+ * so it must have been successful, so just wait for it. |
| 2001 |
+ */ |
| 2002 |
+ ino = autofs4_dentry_ino(expiring); |
| 2003 |
+ autofs4_expire_wait(expiring); |
| 2004 |
+ spin_lock(&sbi->lookup_lock); |
| 2005 |
+ if (!list_empty(&ino->expiring)) |
| 2006 |
+ list_del_init(&ino->expiring); |
| 2007 |
+ spin_unlock(&sbi->lookup_lock); |
| 2008 |
+ dput(expiring); |
| 2009 |
+ } |
| 2010 |
+ |
| 2011 |
spin_lock(&dentry->d_lock); |
| 2012 |
dentry->d_flags |= DCACHE_AUTOFS_PENDING; |
| 2013 |
spin_unlock(&dentry->d_lock); |
| 2014 |
- if (dentry->d_op && dentry->d_op->d_revalidate) { |
| 2015 |
- mutex_unlock(&dir->i_mutex); |
| 2016 |
+ if (dentry->d_op && dentry->d_op->d_revalidate) |
| 2017 |
(dentry->d_op->d_revalidate)(dentry, nd); |
| 2018 |
- mutex_lock(&dir->i_mutex); |
| 2019 |
- } |
| 2020 |
+ mutex_lock(&dir->i_mutex); |
| 2021 |
} |
| 2022 |
|
| 2023 |
/* |
| 2024 |
--- linux-2.6.27.orig/include/linux/auto_fs.h |
| 2025 |
+++ linux-2.6.27/include/linux/auto_fs.h |
| 2026 |
@@ -17,11 +17,13 @@ |
| 2027 |
#ifdef __KERNEL__ |
| 2028 |
#include <linux/fs.h> |
| 2029 |
#include <linux/limits.h> |
| 2030 |
+#include <linux/types.h> |
| 2031 |
+#include <linux/ioctl.h> |
| 2032 |
+#else |
| 2033 |
#include <asm/types.h> |
| 2034 |
+#include <sys/ioctl.h> |
| 2035 |
#endif /* __KERNEL__ */ |
| 2036 |
|
| 2037 |
-#include <linux/ioctl.h> |
| 2038 |
- |
| 2039 |
/* This file describes autofs v3 */ |
| 2040 |
#define AUTOFS_PROTO_VERSION 3 |
| 2041 |
|