Debian Codegraph @

patches/autofs4-2.6.18-v5-update-20090903.patch

raw
1 --- linux-2.6.18.orig/fs/autofs4/root.c
2 +++ linux-2.6.18/fs/autofs4/root.c
3 @@ -26,25 +26,25 @@ static int autofs4_dir_rmdir(struct inod
4 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
5 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
6 static int autofs4_dir_open(struct inode *inode, struct file *file);
7 -static int autofs4_dir_close(struct inode *inode, struct file *file);
8 -static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
9 -static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
10 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
11 static void *autofs4_follow_link(struct dentry *, struct nameidata *);
12
13 +#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
14 +#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
15 +
16 const struct file_operations autofs4_root_operations = {
17 .open = dcache_dir_open,
18 .release = dcache_dir_close,
19 .read = generic_read_dir,
20 - .readdir = autofs4_root_readdir,
21 + .readdir = dcache_readdir,
22 .ioctl = autofs4_root_ioctl,
23 };
24
25 const struct file_operations autofs4_dir_operations = {
26 .open = autofs4_dir_open,
27 - .release = autofs4_dir_close,
28 + .release = dcache_dir_close,
29 .read = generic_read_dir,
30 - .readdir = autofs4_dir_readdir,
31 + .readdir = dcache_readdir,
32 };
33
34 struct inode_operations autofs4_indirect_root_inode_operations = {
35 @@ -71,42 +71,10 @@ struct inode_operations autofs4_dir_inod
36 .rmdir = autofs4_dir_rmdir,
37 };
38
39 -static int autofs4_root_readdir(struct file *file, void *dirent,
40 - filldir_t filldir)
41 -{
42 - struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
43 - int oz_mode = autofs4_oz_mode(sbi);
44 -
45 - DPRINTK("called, filp->f_pos = %lld", file->f_pos);
46 -
47 - /*
48 - * Don't set reghost flag if:
49 - * 1) f_pos is larger than zero -- we've already been here.
50 - * 2) we haven't even enabled reghosting in the 1st place.
51 - * 3) this is the daemon doing a readdir
52 - */
53 - if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
54 - sbi->needs_reghost = 1;
55 -
56 - DPRINTK("needs_reghost = %d", sbi->needs_reghost);
57 -
58 - return dcache_readdir(file, dirent, filldir);
59 -}
60 -
61 static int autofs4_dir_open(struct inode *inode, struct file *file)
62 {
63 struct dentry *dentry = file->f_dentry;
64 - struct vfsmount *mnt = file->f_vfsmnt;
65 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
66 - struct dentry *cursor;
67 - int status;
68 -
69 - status = dcache_dir_open(inode, file);
70 - if (status)
71 - goto out;
72 -
73 - cursor = file->private_data;
74 - cursor->d_fsdata = NULL;
75
76 DPRINTK("file=%p dentry=%p %.*s",
77 file, dentry, dentry->d_name.len, dentry->d_name.name);
78 @@ -114,155 +82,30 @@ static int autofs4_dir_open(struct inode
79 if (autofs4_oz_mode(sbi))
80 goto out;
81
82 - if (autofs4_ispending(dentry)) {
83 - DPRINTK("dentry busy");
84 - dcache_dir_close(inode, file);
85 - status = -EBUSY;
86 - goto out;
87 - }
88 -
89 - status = -ENOENT;
90 - if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
91 - struct nameidata nd;
92 - int empty, ret;
93 -
94 - /* In case there are stale directory dentrys from a failed mount */
95 - spin_lock(&dcache_lock);
96 - empty = list_empty(&dentry->d_subdirs);
97 + /*
98 + * An empty directory in an autofs file system is always a
99 + * mount point. The daemon must have failed to mount this
100 + * during lookup so it doesn't exist. This can happen, for
101 + * example, if user space returns an incorrect status for a
102 + * mount request. Otherwise we're doing a readdir on the
103 + * autofs file system so just let the libfs routines handle
104 + * it.
105 + */
106 + if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
107 spin_unlock(&dcache_lock);
108 -
109 - if (!empty)
110 - d_invalidate(dentry);
111 -
112 - nd.flags = LOOKUP_DIRECTORY;
113 - ret = (dentry->d_op->d_revalidate)(dentry, &nd);
114 -
115 - if (!ret) {
116 - dcache_dir_close(inode, file);
117 - goto out;
118 - }
119 - }
120 -
121 - if (d_mountpoint(dentry)) {
122 - struct file *fp = NULL;
123 - struct vfsmount *fp_mnt = mntget(mnt);
124 - struct dentry *fp_dentry = dget(dentry);
125 -
126 - if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
127 - dput(fp_dentry);
128 - mntput(fp_mnt);
129 - dcache_dir_close(inode, file);
130 - goto out;
131 - }
132 -
133 - fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
134 - status = PTR_ERR(fp);
135 - if (IS_ERR(fp)) {
136 - dcache_dir_close(inode, file);
137 - goto out;
138 - }
139 - cursor->d_fsdata = fp;
140 - }
141 - return 0;
142 -out:
143 - return status;
144 -}
145 -
146 -static int autofs4_dir_close(struct inode *inode, struct file *file)
147 -{
148 - struct dentry *dentry = file->f_dentry;
149 - struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
150 - struct dentry *cursor = file->private_data;
151 - int status = 0;
152 -
153 - DPRINTK("file=%p dentry=%p %.*s",
154 - file, dentry, dentry->d_name.len, dentry->d_name.name);
155 -
156 - if (autofs4_oz_mode(sbi))
157 - goto out;
158 -
159 - if (autofs4_ispending(dentry)) {
160 - DPRINTK("dentry busy");
161 - status = -EBUSY;
162 - goto out;
163 - }
164 -
165 - if (d_mountpoint(dentry)) {
166 - struct file *fp = cursor->d_fsdata;
167 - if (!fp) {
168 - status = -ENOENT;
169 - goto out;
170 - }
171 - filp_close(fp, current->files);
172 - }
173 -out:
174 - dcache_dir_close(inode, file);
175 - return status;
176 -}
177 -
178 -static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
179 -{
180 - struct dentry *dentry = file->f_dentry;
181 - struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
182 - struct dentry *cursor = file->private_data;
183 - int status;
184 -
185 - DPRINTK("file=%p dentry=%p %.*s",
186 - file, dentry, dentry->d_name.len, dentry->d_name.name);
187 -
188 - if (autofs4_oz_mode(sbi))
189 - goto out;
190 -
191 - if (autofs4_ispending(dentry)) {
192 - DPRINTK("dentry busy");
193 - return -EBUSY;
194 + return -ENOENT;
195 }
196 + spin_unlock(&dcache_lock);
197
198 - if (d_mountpoint(dentry)) {
199 - struct file *fp = cursor->d_fsdata;
200 -
201 - if (!fp)
202 - return -ENOENT;
203 -
204 - if (!fp->f_op || !fp->f_op->readdir)
205 - goto out;
206 -
207 - status = vfs_readdir(fp, filldir, dirent);
208 - file->f_pos = fp->f_pos;
209 - if (status)
210 - autofs4_copy_atime(file, fp);
211 - return status;
212 - }
213 out:
214 - return dcache_readdir(file, dirent, filldir);
215 + return dcache_dir_open(inode, file);
216 }
217
218 static int try_to_fill_dentry(struct dentry *dentry, int flags)
219 {
220 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
221 struct autofs_info *ino = autofs4_dentry_ino(dentry);
222 - int status = 0;
223 -
224 - /* Block on any pending expiry here; invalidate the dentry
225 - when expiration is done to trigger mount request with a new
226 - dentry */
227 - if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
228 - DPRINTK("waiting for expire %p name=%.*s",
229 - dentry, dentry->d_name.len, dentry->d_name.name);
230 -
231 - status = autofs4_wait(sbi, dentry, NFY_NONE);
232 -
233 - DPRINTK("expire done status=%d", status);
234 -
235 - /*
236 - * If the directory still exists the mount request must
237 - * continue otherwise it can't be followed at the right
238 - * time during the walk.
239 - */
240 - status = d_invalidate(dentry);
241 - if (status != -EBUSY)
242 - return -ENOENT;
243 - }
244 + int status;
245
246 DPRINTK("dentry=%p %.*s ino=%p",
247 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
248 @@ -279,9 +122,6 @@ static int try_to_fill_dentry(struct den
249
250 DPRINTK("mount done status=%d", status);
251
252 - if (status && dentry->d_inode)
253 - return status; /* Try to get the kernel to invalidate this dentry */
254 -
255 /* Turn this into a real negative dentry? */
256 if (status == -ENOENT) {
257 spin_lock(&dentry->d_lock);
258 @@ -293,7 +133,8 @@ static int try_to_fill_dentry(struct den
259 return status;
260 }
261 /* Trigger mount for path component or follow link */
262 - } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
263 + } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
264 + flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
265 current->link_count) {
266 DPRINTK("waiting for mount name=%.*s",
267 dentry->d_name.len, dentry->d_name.name);
268 @@ -320,7 +161,8 @@ static int try_to_fill_dentry(struct den
269 spin_lock(&dentry->d_lock);
270 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
271 spin_unlock(&dentry->d_lock);
272 - return status;
273 +
274 + return 0;
275 }
276
277 /* For autofs direct mounts the follow link triggers the mount */
278 @@ -335,50 +177,62 @@ static void *autofs4_follow_link(struct
279 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
280 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
281 nd->flags);
282 -
283 - /* If it's our master or we shouldn't trigger a mount we're done */
284 - lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY);
285 - if (oz_mode || !lookup_type)
286 + /*
287 + * For an expire of a covered direct or offset mount we need
288 + * to beeak out of follow_down() at the autofs mount trigger
289 + * (d_mounted--), so we can see the expiring flag, and manage
290 + * the blocking and following here until the expire is completed.
291 + */
292 + if (oz_mode) {
293 + spin_lock(&sbi->fs_lock);
294 + if (ino->flags & AUTOFS_INF_EXPIRING) {
295 + spin_unlock(&sbi->fs_lock);
296 + /* Follow down to our covering mount. */
297 + if (!follow_down(&nd->mnt, &nd->dentry))
298 + goto done;
299 + goto follow;
300 + }
301 + spin_unlock(&sbi->fs_lock);
302 goto done;
303 + }
304
305 - /* If an expire request is pending wait for it. */
306 - if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
307 - DPRINTK("waiting for active request %p name=%.*s",
308 - dentry, dentry->d_name.len, dentry->d_name.name);
309 -
310 - status = autofs4_wait(sbi, dentry, NFY_NONE);
311 + /* If an expire request is pending everyone must wait. */
312 + autofs4_expire_wait(dentry);
313
314 - DPRINTK("request done status=%d", status);
315 - }
316 + /* We trigger a mount for almost all flags */
317 + lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
318 + if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
319 + goto follow;
320
321 /*
322 - * If the dentry contains directories then it is an
323 - * autofs multi-mount with no root mount offset. So
324 - * don't try to mount it again.
325 + * If the dentry contains directories then it is an autofs
326 + * multi-mount with no root mount offset. So don't try to
327 + * mount it again.
328 */
329 spin_lock(&dcache_lock);
330 - if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {
331 + if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
332 + (!d_mountpoint(dentry) && __simple_empty(dentry))) {
333 spin_unlock(&dcache_lock);
334
335 status = try_to_fill_dentry(dentry, 0);
336 if (status)
337 goto out_error;
338
339 - /*
340 - * The mount succeeded but if there is no root mount
341 - * it must be an autofs multi-mount with no root offset
342 - * so we don't need to follow the mount.
343 - */
344 - if (d_mountpoint(dentry)) {
345 - if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
346 - status = -ENOENT;
347 - goto out_error;
348 - }
349 - }
350 -
351 - goto done;
352 + goto follow;
353 }
354 spin_unlock(&dcache_lock);
355 +follow:
356 + /*
357 + * If there is no root mount it must be an autofs
358 + * multi-mount with no root offset so we don't need
359 + * to follow it.
360 + */
361 + if (d_mountpoint(dentry)) {
362 + if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) {
363 + status = -ENOENT;
364 + goto out_error;
365 + }
366 + }
367
368 done:
369 return NULL;
370 @@ -400,14 +254,36 @@ static int autofs4_revalidate(struct den
371 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
372 int oz_mode = autofs4_oz_mode(sbi);
373 int flags = nd ? nd->flags : 0;
374 - int status = 0;
375 + int status;
376
377 /* Pending dentry */
378 + spin_lock(&sbi->fs_lock);
379 if (autofs4_ispending(dentry)) {
380 - if (!oz_mode)
381 - status = try_to_fill_dentry(dentry, flags);
382 - return !status;
383 + /* The daemon never causes a mount to trigger */
384 + spin_unlock(&sbi->fs_lock);
385 +
386 + if (oz_mode)
387 + return 1;
388 +
389 + /*
390 + * If the directory has gone away due to an expire
391 + * we have been called as ->d_revalidate() and so
392 + * we need to return false and proceed to ->lookup().
393 + */
394 + if (autofs4_expire_wait(dentry) == -EAGAIN)
395 + return 0;
396 +
397 + /*
398 + * A zero status is success otherwise we have a
399 + * negative error code.
400 + */
401 + status = try_to_fill_dentry(dentry, flags);
402 + if (status == 0)
403 + return 1;
404 +
405 + return status;
406 }
407 + spin_unlock(&sbi->fs_lock);
408
409 /* Negative dentry.. invalidate if "old" */
410 if (dentry->d_inode == NULL)
411 @@ -421,9 +297,20 @@ static int autofs4_revalidate(struct den
412 DPRINTK("dentry=%p %.*s, emptydir",
413 dentry, dentry->d_name.len, dentry->d_name.name);
414 spin_unlock(&dcache_lock);
415 - if (!oz_mode)
416 - status = try_to_fill_dentry(dentry, flags);
417 - return !status;
418 +
419 + /* The daemon never causes a mount to trigger */
420 + if (oz_mode)
421 + return 1;
422 +
423 + /*
424 + * A zero status is success otherwise we have a
425 + * negative error code.
426 + */
427 + status = try_to_fill_dentry(dentry, flags);
428 + if (status == 0)
429 + return 1;
430 +
431 + return status;
432 }
433 spin_unlock(&dcache_lock);
434
435 @@ -440,6 +327,17 @@ void autofs4_dentry_release(struct dentr
436 de->d_fsdata = NULL;
437
438 if (inf) {
439 + struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
440 +
441 + if (sbi) {
442 + spin_lock(&sbi->lookup_lock);
443 + if (!list_empty(&inf->active))
444 + list_del(&inf->active);
445 + if (!list_empty(&inf->expiring))
446 + list_del(&inf->expiring);
447 + spin_unlock(&sbi->lookup_lock);
448 + }
449 +
450 inf->dentry = NULL;
451 inf->inode = NULL;
452
453 @@ -459,10 +357,116 @@ static struct dentry_operations autofs4_
454 .d_release = autofs4_dentry_release,
455 };
456
457 +static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
458 +{
459 + unsigned int len = name->len;
460 + unsigned int hash = name->hash;
461 + const unsigned char *str = name->name;
462 + struct list_head *p, *head;
463 +
464 + spin_lock(&dcache_lock);
465 + spin_lock(&sbi->lookup_lock);
466 + head = &sbi->active_list;
467 + list_for_each(p, head) {
468 + struct autofs_info *ino;
469 + struct dentry *dentry;
470 + struct qstr *qstr;
471 +
472 + ino = list_entry(p, struct autofs_info, active);
473 + dentry = ino->dentry;
474 +
475 + spin_lock(&dentry->d_lock);
476 +
477 + /* Already gone? */
478 + if (atomic_read(&dentry->d_count) == 0)
479 + goto next;
480 +
481 + qstr = &dentry->d_name;
482 +
483 + if (dentry->d_name.hash != hash)
484 + goto next;
485 + if (dentry->d_parent != parent)
486 + goto next;
487 +
488 + if (qstr->len != len)
489 + goto next;
490 + if (memcmp(qstr->name, str, len))
491 + goto next;
492 +
493 + if (d_unhashed(dentry)) {
494 + dget(dentry);
495 + spin_unlock(&dentry->d_lock);
496 + spin_unlock(&sbi->lookup_lock);
497 + spin_unlock(&dcache_lock);
498 + return dentry;
499 + }
500 +next:
501 + spin_unlock(&dentry->d_lock);
502 + }
503 + spin_unlock(&sbi->lookup_lock);
504 + spin_unlock(&dcache_lock);
505 +
506 + return NULL;
507 +}
508 +
509 +static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
510 +{
511 + unsigned int len = name->len;
512 + unsigned int hash = name->hash;
513 + const unsigned char *str = name->name;
514 + struct list_head *p, *head;
515 +
516 + spin_lock(&dcache_lock);
517 + spin_lock(&sbi->lookup_lock);
518 + head = &sbi->expiring_list;
519 + list_for_each(p, head) {
520 + struct autofs_info *ino;
521 + struct dentry *dentry;
522 + struct qstr *qstr;
523 +
524 + ino = list_entry(p, struct autofs_info, expiring);
525 + dentry = ino->dentry;
526 +
527 + spin_lock(&dentry->d_lock);
528 +
529 + /* Bad luck, we've already been dentry_iput */
530 + if (!dentry->d_inode)
531 + goto next;
532 +
533 + qstr = &dentry->d_name;
534 +
535 + if (dentry->d_name.hash != hash)
536 + goto next;
537 + if (dentry->d_parent != parent)
538 + goto next;
539 +
540 + if (qstr->len != len)
541 + goto next;
542 + if (memcmp(qstr->name, str, len))
543 + goto next;
544 +
545 + if (d_unhashed(dentry)) {
546 + dget(dentry);
547 + spin_unlock(&dentry->d_lock);
548 + spin_unlock(&sbi->lookup_lock);
549 + spin_unlock(&dcache_lock);
550 + return dentry;
551 + }
552 +next:
553 + spin_unlock(&dentry->d_lock);
554 + }
555 + spin_unlock(&sbi->lookup_lock);
556 + spin_unlock(&dcache_lock);
557 +
558 + return NULL;
559 +}
560 +
561 /* Lookups in the root directory */
562 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
563 {
564 struct autofs_sb_info *sbi;
565 + struct autofs_info *ino;
566 + struct dentry *expiring, *unhashed;
567 int oz_mode;
568
569 DPRINTK("name = %.*s",
570 @@ -478,29 +482,67 @@ static struct dentry *autofs4_lookup(str
571 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
572 current->pid, process_group(current), sbi->catatonic, oz_mode);
573
574 - /*
575 - * Mark the dentry incomplete, but add it. This is needed so
576 - * that the VFS layer knows about the dentry, and we can count
577 - * on catching any lookups through the revalidate.
578 - *
579 - * Let all the hard work be done by the revalidate function that
580 - * needs to be able to do this anyway..
581 - *
582 - * We need to do this before we release the directory semaphore.
583 - */
584 - dentry->d_op = &autofs4_root_dentry_operations;
585 + unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
586 + if (unhashed)
587 + dentry = unhashed;
588 + else {
589 + /*
590 + * Mark the dentry incomplete but don't hash it. We do this
591 + * to serialize our inode creation operations (symlink and
592 + * mkdir) which prevents deadlock during the callback to
593 + * the daemon. Subsequent user space lookups for the same
594 + * dentry are placed on the wait queue while the daemon
595 + * itself is allowed passage unresticted so the create
596 + * operation itself can then hash the dentry. Finally,
597 + * we check for the hashed dentry and return the newly
598 + * hashed dentry.
599 + */
600 + dentry->d_op = &autofs4_root_dentry_operations;
601 +
602 + /*
603 + * And we need to ensure that the same dentry is used for
604 + * all following lookup calls until it is hashed so that
605 + * the dentry flags are persistent throughout the request.
606 + */
607 + ino = autofs4_init_ino(NULL, sbi, 0555);
608 + if (!ino)
609 + return ERR_PTR(-ENOMEM);
610 +
611 + dentry->d_fsdata = ino;
612 + ino->dentry = dentry;
613 +
614 + spin_lock(&sbi->lookup_lock);
615 + list_add(&ino->active, &sbi->active_list);
616 + spin_unlock(&sbi->lookup_lock);
617 +
618 + d_instantiate(dentry, NULL);
619 + }
620
621 if (!oz_mode) {
622 + mutex_unlock(&dir->i_mutex);
623 + expiring = autofs4_lookup_expiring(sbi,
624 + dentry->d_parent,
625 + &dentry->d_name);
626 + if (expiring) {
627 + /*
628 + * If we are racing with expire the request might not
629 + * be quite complete but the directory has been removed
630 + * so it must have been successful, so just wait for it.
631 + */
632 + ino = autofs4_dentry_ino(expiring);
633 + autofs4_expire_wait(expiring);
634 + spin_lock(&sbi->lookup_lock);
635 + if (!list_empty(&ino->expiring))
636 + list_del_init(&ino->expiring);
637 + spin_unlock(&sbi->lookup_lock);
638 + dput(expiring);
639 + }
640 +
641 spin_lock(&dentry->d_lock);
642 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
643 spin_unlock(&dentry->d_lock);
644 - }
645 - dentry->d_fsdata = NULL;
646 - d_add(dentry, NULL);
647 -
648 - if (dentry->d_op && dentry->d_op->d_revalidate) {
649 - mutex_unlock(&dir->i_mutex);
650 - (dentry->d_op->d_revalidate)(dentry, nd);
651 + if (dentry->d_op && dentry->d_op->d_revalidate)
652 + (dentry->d_op->d_revalidate)(dentry, nd);
653 mutex_lock(&dir->i_mutex);
654 }
655
656 @@ -515,19 +557,47 @@ static struct dentry *autofs4_lookup(str
657 if (sigismember (sigset, SIGKILL) ||
658 sigismember (sigset, SIGQUIT) ||
659 sigismember (sigset, SIGINT)) {
660 + if (unhashed)
661 + dput(unhashed);
662 return ERR_PTR(-ERESTARTNOINTR);
663 }
664 }
665 + if (!oz_mode) {
666 + spin_lock(&dentry->d_lock);
667 + dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
668 + spin_unlock(&dentry->d_lock);
669 + }
670 }
671
672 /*
673 * If this dentry is unhashed, then we shouldn't honour this
674 - * lookup even if the dentry is positive. Returning ENOENT here
675 - * doesn't do the right thing for all system calls, but it should
676 - * be OK for the operations we permit from an autofs.
677 + * lookup. Returning ENOENT here doesn't do the right thing
678 + * for all system calls, but it should be OK for the operations
679 + * we permit from an autofs.
680 */
681 - if (dentry->d_inode && d_unhashed(dentry))
682 - return ERR_PTR(-ENOENT);
683 + if (!oz_mode && d_unhashed(dentry)) {
684 + /*
685 + * A user space application can (and has done in the past)
686 + * remove and re-create this directory during the callback.
687 + * This can leave us with an unhashed dentry, but a
688 + * successful mount! So we need to perform another
689 + * cached lookup in case the dentry now exists.
690 + */
691 + struct dentry *parent = dentry->d_parent;
692 + struct dentry *new = d_lookup(parent, &dentry->d_name);
693 + if (new != NULL)
694 + dentry = new;
695 + else
696 + dentry = ERR_PTR(-ENOENT);
697 +
698 + if (unhashed)
699 + dput(unhashed);
700 +
701 + return dentry;
702 + }
703 +
704 + if (unhashed)
705 + return unhashed;
706
707 return NULL;
708 }
709 @@ -549,21 +619,32 @@ static int autofs4_dir_symlink(struct in
710 return -EACCES;
711
712 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
713 - if (ino == NULL)
714 - return -ENOSPC;
715 + if (!ino)
716 + return -ENOMEM;
717
718 - ino->size = strlen(symname);
719 - ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
720 + spin_lock(&sbi->lookup_lock);
721 + if (!list_empty(&ino->active))
722 + list_del_init(&ino->active);
723 + spin_unlock(&sbi->lookup_lock);
724
725 - if (cp == NULL) {
726 - kfree(ino);
727 - return -ENOSPC;
728 + ino->size = strlen(symname);
729 + cp = kmalloc(ino->size + 1, GFP_KERNEL);
730 + if (!cp) {
731 + if (!dentry->d_fsdata)
732 + kfree(ino);
733 + return -ENOMEM;
734 }
735
736 strcpy(cp, symname);
737
738 inode = autofs4_get_inode(dir->i_sb, ino);
739 - d_instantiate(dentry, inode);
740 + if (!inode) {
741 + kfree(cp);
742 + if (!dentry->d_fsdata)
743 + kfree(ino);
744 + return -ENOMEM;
745 + }
746 + d_add(dentry, inode);
747
748 if (dir == dir->i_sb->s_root->d_inode)
749 dentry->d_op = &autofs4_root_dentry_operations;
750 @@ -578,6 +659,7 @@ static int autofs4_dir_symlink(struct in
751 atomic_inc(&p_ino->count);
752 ino->inode = inode;
753
754 + ino->u.symlink = cp;
755 dir->i_mtime = CURRENT_TIME;
756
757 return 0;
758 @@ -589,9 +671,9 @@ static int autofs4_dir_symlink(struct in
759 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
760 * that the file no longer exists. However, doing that means that the
761 * VFS layer can turn the dentry into a negative dentry. We don't want
762 - * this, because since the unlink is probably the result of an expire.
763 - * We simply d_drop it, which allows the dentry lookup to remount it
764 - * if necessary.
765 + * this, because the unlink is probably the result of an expire.
766 + * We simply d_drop it and add it to a expiring list in the super block,
767 + * which allows the dentry lookup to check for an incomplete expire.
768 *
769 * If a process is blocked on the dentry waiting for the expire to finish,
770 * it will invalidate the dentry and try to mount with a new one.
771 @@ -620,7 +702,15 @@ static int autofs4_dir_unlink(struct ino
772
773 dir->i_mtime = CURRENT_TIME;
774
775 - d_drop(dentry);
776 + spin_lock(&dcache_lock);
777 + spin_lock(&sbi->lookup_lock);
778 + if (list_empty(&ino->expiring))
779 + list_add(&ino->expiring, &sbi->expiring_list);
780 + spin_unlock(&sbi->lookup_lock);
781 + spin_lock(&dentry->d_lock);
782 + __d_drop(dentry);
783 + spin_unlock(&dentry->d_lock);
784 + spin_unlock(&dcache_lock);
785
786 return 0;
787 }
788 @@ -631,6 +721,9 @@ static int autofs4_dir_rmdir(struct inod
789 struct autofs_info *ino = autofs4_dentry_ino(dentry);
790 struct autofs_info *p_ino;
791
792 + DPRINTK("dentry %p, removing %.*s",
793 + dentry, dentry->d_name.len, dentry->d_name.name);
794 +
795 if (!autofs4_oz_mode(sbi))
796 return -EACCES;
797
798 @@ -639,6 +732,10 @@ static int autofs4_dir_rmdir(struct inod
799 spin_unlock(&dcache_lock);
800 return -ENOTEMPTY;
801 }
802 + spin_lock(&sbi->lookup_lock);
803 + if (list_empty(&ino->expiring))
804 + list_add(&ino->expiring, &sbi->expiring_list);
805 + spin_unlock(&sbi->lookup_lock);
806 spin_lock(&dentry->d_lock);
807 __d_drop(dentry);
808 spin_unlock(&dentry->d_lock);
809 @@ -673,11 +770,21 @@ static int autofs4_dir_mkdir(struct inod
810 dentry, dentry->d_name.len, dentry->d_name.name);
811
812 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
813 - if (ino == NULL)
814 - return -ENOSPC;
815 + if (!ino)
816 + return -ENOMEM;
817 +
818 + spin_lock(&sbi->lookup_lock);
819 + if (!list_empty(&ino->active))
820 + list_del_init(&ino->active);
821 + spin_unlock(&sbi->lookup_lock);
822
823 inode = autofs4_get_inode(dir->i_sb, ino);
824 - d_instantiate(dentry, inode);
825 + if (!inode) {
826 + if (!dentry->d_fsdata)
827 + kfree(ino);
828 + return -ENOMEM;
829 + }
830 + d_add(dentry, inode);
831
832 if (dir == dir->i_sb->s_root->d_inode)
833 dentry->d_op = &autofs4_root_dentry_operations;
834 @@ -729,44 +836,6 @@ static inline int autofs4_get_protosubve
835 }
836
837 /*
838 - * Tells the daemon whether we need to reghost or not. Also, clears
839 - * the reghost_needed flag.
840 - */
841 -static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
842 -{
843 - int status;
844 -
845 - DPRINTK("returning %d", sbi->needs_reghost);
846 -
847 - status = put_user(sbi->needs_reghost, p);
848 - if ( status )
849 - return status;
850 -
851 - sbi->needs_reghost = 0;
852 - return 0;
853 -}
854 -
855 -/*
856 - * Enable / Disable reghosting ioctl() operation
857 - */
858 -static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
859 -{
860 - int status;
861 - int val;
862 -
863 - status = get_user(val, p);
864 -
865 - DPRINTK("reghost = %d", val);
866 -
867 - if (status)
868 - return status;
869 -
870 - /* turn on/off reghosting, with the val */
871 - sbi->reghost_enabled = val;
872 - return 0;
873 -}
874 -
875 -/*
876 * Tells the daemon whether it can umount the autofs mount.
877 */
878 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
879 @@ -830,11 +899,6 @@ static int autofs4_root_ioctl(struct ino
880 case AUTOFS_IOC_SETTIMEOUT:
881 return autofs4_get_set_timeout(sbi, p);
882
883 - case AUTOFS_IOC_TOGGLEREGHOST:
884 - return autofs4_toggle_reghost(sbi, p);
885 - case AUTOFS_IOC_ASKREGHOST:
886 - return autofs4_ask_reghost(sbi, p);
887 -
888 case AUTOFS_IOC_ASKUMOUNT:
889 return autofs4_ask_umount(filp->f_vfsmnt, p);
890
891 --- linux-2.6.18.orig/fs/namei.c
892 +++ linux-2.6.18/fs/namei.c
893 @@ -372,6 +372,29 @@ void release_open_intent(struct nameidat
894 fput(nd->intent.open.file);
895 }
896
897 +static inline struct dentry *do_revalidate(struct dentry *dentry, struct nameidata *nd)
898 +{
899 + int status = dentry->d_op->d_revalidate(dentry, nd);
900 + if (unlikely(status <= 0)) {
901 + /*
902 + * The dentry failed validation.
903 + * If d_revalidate returned 0 attempt to invalidate
904 + * the dentry otherwise d_revalidate is asking us
905 + * to return a fail status.
906 + */
907 + if (!status) {
908 + if (!d_invalidate(dentry)) {
909 + dput(dentry);
910 + dentry = NULL;
911 + }
912 + } else {
913 + dput(dentry);
914 + dentry = ERR_PTR(status);
915 + }
916 + }
917 + return dentry;
918 +}
919 +
920 /*
921 * Internal lookup() using the new generic dcache.
922 * SMP-safe
923 @@ -386,12 +409,9 @@ static struct dentry * cached_lookup(str
924 if (!dentry)
925 dentry = d_lookup(parent, name);
926
927 - if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
928 - if (!dentry->d_op->d_revalidate(dentry, nd) && !d_invalidate(dentry)) {
929 - dput(dentry);
930 - dentry = NULL;
931 - }
932 - }
933 + if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
934 + dentry = do_revalidate(dentry, nd);
935 +
936 return dentry;
937 }
938
939 @@ -484,10 +504,9 @@ static struct dentry * real_lookup(struc
940 */
941 mutex_unlock(&dir->i_mutex);
942 if (result->d_op && result->d_op->d_revalidate) {
943 - if (!result->d_op->d_revalidate(result, nd) && !d_invalidate(result)) {
944 - dput(result);
945 + result = do_revalidate(result, nd);
946 + if (!result)
947 result = ERR_PTR(-ENOENT);
948 - }
949 }
950 return result;
951 }
952 @@ -767,12 +786,12 @@ need_lookup:
953 goto done;
954
955 need_revalidate:
956 - if (dentry->d_op->d_revalidate(dentry, nd))
957 - goto done;
958 - if (d_invalidate(dentry))
959 - goto done;
960 - dput(dentry);
961 - goto need_lookup;
962 + dentry = do_revalidate(dentry, nd);
963 + if (!dentry)
964 + goto need_lookup;
965 + if (IS_ERR(dentry))
966 + goto fail;
967 + goto done;
968
969 fail:
970 return PTR_ERR(dentry);
971 --- linux-2.6.18.orig/fs/autofs/init.c
972 +++ linux-2.6.18/fs/autofs/init.c
973 @@ -24,7 +24,7 @@ static struct file_system_type autofs_fs
974 .owner = THIS_MODULE,
975 .name = "autofs",
976 .get_sb = autofs_get_sb,
977 - .kill_sb = kill_anon_super,
978 + .kill_sb = autofs_kill_sb,
979 };
980
981 static int __init init_autofs_fs(void)
982 --- linux-2.6.18.orig/fs/autofs/inode.c
983 +++ linux-2.6.18/fs/autofs/inode.c
984 @@ -19,11 +19,20 @@
985 #include "autofs_i.h"
986 #include <linux/module.h>
987
988 -static void autofs_put_super(struct super_block *sb)
989 +void autofs4_kill_sb(struct super_block *sb)
990 {
991 struct autofs_sb_info *sbi = autofs_sbi(sb);
992 unsigned int n;
993
994 + /*
995 + * In the event of a failure in get_sb_nodev the superblock
996 + * info is not present so nothing else has been setup, so
997 + * just call kill_anon_super when we are called from
998 + * deactivate_super.
999 + */
1000 + if (!sbi)
1001 + goto out_kill_sb;
1002 +
1003 if ( !sbi->catatonic )
1004 autofs_catatonic_mode(sbi); /* Free wait queues, close pipe */
1005
1006 @@ -35,14 +44,15 @@ static void autofs_put_super(struct supe
1007
1008 kfree(sb->s_fs_info);
1009
1010 +out_kill_sb:
1011 DPRINTK(("autofs: shutting down\n"));
1012 + kill_anon_super(sb);
1013 }
1014
1015 static void autofs_read_inode(struct inode *inode);
1016
1017 static struct super_operations autofs_sops = {
1018 .read_inode = autofs_read_inode,
1019 - .put_super = autofs_put_super,
1020 .statfs = simple_statfs,
1021 };
1022
1023 @@ -136,7 +146,8 @@ int autofs_fill_super(struct super_block
1024
1025 s->s_fs_info = sbi;
1026 sbi->magic = AUTOFS_SBI_MAGIC;
1027 - sbi->catatonic = 0;
1028 + sbi->pipe = NULL;
1029 + sbi->catatonic = 1;
1030 sbi->exp_timeout = 0;
1031 sbi->oz_pgrp = process_group(current);
1032 autofs_initialize_hash(&sbi->dirhash);
1033 @@ -180,6 +191,7 @@ int autofs_fill_super(struct super_block
1034 if ( !pipe->f_op || !pipe->f_op->write )
1035 goto fail_fput;
1036 sbi->pipe = pipe;
1037 + sbi->catatonic = 0;
1038
1039 /*
1040 * Success! Install the root dentry now to indicate completion.
1041 @@ -198,6 +210,7 @@ fail_iput:
1042 iput(root_inode);
1043 fail_free:
1044 kfree(sbi);
1045 + s->s_fs_info = NULL;
1046 fail_unlock:
1047 return -EINVAL;
1048 }
1049 --- linux-2.6.18.orig/fs/autofs/autofs_i.h
1050 +++ linux-2.6.18/fs/autofs/autofs_i.h
1051 @@ -151,6 +151,7 @@ extern const struct file_operations auto
1052 /* Initializing function */
1053
1054 int autofs_fill_super(struct super_block *, void *, int);
1055 +void autofs_kill_sb(struct super_block *);
1056
1057 /* Queue management functions */
1058
1059 --- linux-2.6.18.orig/fs/autofs4/autofs_i.h
1060 +++ linux-2.6.18/fs/autofs4/autofs_i.h
1061 @@ -14,6 +14,7 @@
1062 /* Internal header file for autofs */
1063
1064 #include <linux/auto_fs4.h>
1065 +#include <linux/auto_dev-ioctl.h>
1066 #include <linux/mutex.h>
1067 #include <linux/list.h>
1068
1069 @@ -21,6 +22,9 @@
1070 #define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
1071 #define AUTOFS_IOC_COUNT 32
1072
1073 +#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)
1074 +#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11)
1075 +
1076 #include <linux/kernel.h>
1077 #include <linux/slab.h>
1078 #include <linux/time.h>
1079 @@ -35,11 +39,27 @@
1080 /* #define DEBUG */
1081
1082 #ifdef DEBUG
1083 -#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __FUNCTION__ , ##args); } while(0)
1084 +#define DPRINTK(fmt, args...) \
1085 +do { \
1086 + printk(KERN_DEBUG "pid %d: %s: " fmt "\n", \
1087 + current->pid, __FUNCTION__, ##args); \
1088 +} while (0)
1089 #else
1090 #define DPRINTK(fmt,args...) do {} while(0)
1091 #endif
1092
1093 +#define AUTOFS_WARN(fmt, args...) \
1094 +do { \
1095 + printk(KERN_WARNING "pid %d: %s: " fmt "\n", \
1096 + current->pid, __FUNCTION__, ##args); \
1097 +} while (0)
1098 +
1099 +#define AUTOFS_ERROR(fmt, args...) \
1100 +do { \
1101 + printk(KERN_ERR "pid %d: %s: " fmt "\n", \
1102 + current->pid, __FUNCTION__, ##args); \
1103 +} while (0)
1104 +
1105 #define AUTOFS_SUPER_MAGIC 0x0187
1106
1107 /* Unified info structure. This is pointed to by both the dentry and
1108 @@ -54,10 +74,18 @@ struct autofs_info {
1109
1110 int flags;
1111
1112 + struct completion expire_complete;
1113 +
1114 + struct list_head active;
1115 + struct list_head expiring;
1116 +
1117 struct autofs_sb_info *sbi;
1118 unsigned long last_used;
1119 atomic_t count;
1120
1121 + uid_t uid;
1122 + gid_t gid;
1123 +
1124 mode_t mode;
1125 size_t size;
1126
1127 @@ -68,15 +96,14 @@ struct autofs_info {
1128 };
1129
1130 #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
1131 +#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
1132
1133 struct autofs_wait_queue {
1134 wait_queue_head_t queue;
1135 struct autofs_wait_queue *next;
1136 autofs_wqt_t wait_queue_token;
1137 /* We use the following to see what we are waiting for */
1138 - unsigned int hash;
1139 - unsigned int len;
1140 - char *name;
1141 + struct qstr name;
1142 u32 dev;
1143 u64 ino;
1144 uid_t uid;
1145 @@ -85,18 +112,13 @@ struct autofs_wait_queue {
1146 pid_t tgid;
1147 /* This is for status reporting upon return */
1148 int status;
1149 - atomic_t wait_ctr;
1150 + unsigned int wait_ctr;
1151 };
1152
1153 #define AUTOFS_SBI_MAGIC 0x6d4a556d
1154
1155 -#define AUTOFS_TYPE_INDIRECT 0x0001
1156 -#define AUTOFS_TYPE_DIRECT 0x0002
1157 -#define AUTOFS_TYPE_OFFSET 0x0004
1158 -
1159 struct autofs_sb_info {
1160 u32 magic;
1161 - struct dentry *root;
1162 int pipefd;
1163 struct file *pipe;
1164 pid_t oz_pgrp;
1165 @@ -113,6 +135,9 @@ struct autofs_sb_info {
1166 struct mutex wq_mutex;
1167 spinlock_t fs_lock;
1168 struct autofs_wait_queue *queues; /* Wait queue pointer */
1169 + spinlock_t lookup_lock;
1170 + struct list_head active_list;
1171 + struct list_head expiring_list;
1172 };
1173
1174 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
1175 @@ -137,18 +162,14 @@ static inline int autofs4_oz_mode(struct
1176 static inline int autofs4_ispending(struct dentry *dentry)
1177 {
1178 struct autofs_info *inf = autofs4_dentry_ino(dentry);
1179 - int pending = 0;
1180
1181 if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
1182 return 1;
1183
1184 - if (inf) {
1185 - spin_lock(&inf->sbi->fs_lock);
1186 - pending = inf->flags & AUTOFS_INF_EXPIRING;
1187 - spin_unlock(&inf->sbi->fs_lock);
1188 - }
1189 + if (inf->flags & AUTOFS_INF_EXPIRING)
1190 + return 1;
1191
1192 - return pending;
1193 + return 0;
1194 }
1195
1196 static inline void autofs4_copy_atime(struct file *src, struct file *dst)
1197 @@ -162,11 +183,23 @@ void autofs4_free_ino(struct autofs_info
1198
1199 /* Expiration */
1200 int is_autofs4_dentry(struct dentry *);
1201 +int autofs4_expire_wait(struct dentry *dentry);
1202 int autofs4_expire_run(struct super_block *, struct vfsmount *,
1203 struct autofs_sb_info *,
1204 struct autofs_packet_expire __user *);
1205 int autofs4_expire_multi(struct super_block *, struct vfsmount *,
1206 struct autofs_sb_info *, int __user *);
1207 +struct dentry *autofs4_expire_direct(struct super_block *sb,
1208 + struct vfsmount *mnt,
1209 + struct autofs_sb_info *sbi, int how);
1210 +struct dentry *autofs4_expire_indirect(struct super_block *sb,
1211 + struct vfsmount *mnt,
1212 + struct autofs_sb_info *sbi, int how);
1213 +
1214 +/* Device node initialization */
1215 +
1216 +int autofs_dev_ioctl_init(void);
1217 +void autofs_dev_ioctl_exit(void);
1218
1219 /* Operations structures */
1220
1221 @@ -231,4 +264,4 @@ out:
1222 }
1223
1224 void autofs4_dentry_release(struct dentry *);
1225 -
1226 +extern void autofs4_kill_sb(struct super_block *);
1227 --- linux-2.6.18.orig/fs/autofs4/init.c
1228 +++ linux-2.6.18/fs/autofs4/init.c
1229 @@ -24,16 +24,25 @@ static struct file_system_type autofs_fs
1230 .owner = THIS_MODULE,
1231 .name = "autofs",
1232 .get_sb = autofs_get_sb,
1233 - .kill_sb = kill_anon_super,
1234 + .kill_sb = autofs4_kill_sb,
1235 };
1236
1237 static int __init init_autofs4_fs(void)
1238 {
1239 - return register_filesystem(&autofs_fs_type);
1240 + int err;
1241 +
1242 + err = register_filesystem(&autofs_fs_type);
1243 + if (err)
1244 + return err;
1245 +
1246 + autofs_dev_ioctl_init();
1247 +
1248 + return err;
1249 }
1250
1251 static void __exit exit_autofs4_fs(void)
1252 {
1253 + autofs_dev_ioctl_exit();
1254 unregister_filesystem(&autofs_fs_type);
1255 }
1256
1257 --- linux-2.6.18.orig/fs/autofs4/inode.c
1258 +++ linux-2.6.18/fs/autofs4/inode.c
1259 @@ -24,8 +24,10 @@
1260
1261 static void ino_lnkfree(struct autofs_info *ino)
1262 {
1263 - kfree(ino->u.symlink);
1264 - ino->u.symlink = NULL;
1265 + if (ino->u.symlink) {
1266 + kfree(ino->u.symlink);
1267 + ino->u.symlink = NULL;
1268 + }
1269 }
1270
1271 struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
1272 @@ -41,14 +43,20 @@ struct autofs_info *autofs4_init_ino(str
1273 if (ino == NULL)
1274 return NULL;
1275
1276 - ino->flags = 0;
1277 - ino->mode = mode;
1278 - ino->inode = NULL;
1279 - ino->dentry = NULL;
1280 - ino->size = 0;
1281 + if (!reinit) {
1282 + ino->flags = 0;
1283 + ino->inode = NULL;
1284 + ino->dentry = NULL;
1285 + ino->size = 0;
1286 + INIT_LIST_HEAD(&ino->active);
1287 + INIT_LIST_HEAD(&ino->expiring);
1288 + atomic_set(&ino->count, 0);
1289 + }
1290
1291 + ino->uid = 0;
1292 + ino->gid = 0;
1293 + ino->mode = mode;
1294 ino->last_used = jiffies;
1295 - atomic_set(&ino->count, 0);
1296
1297 ino->sbi = sbi;
1298
1299 @@ -95,9 +103,12 @@ void autofs4_free_ino(struct autofs_info
1300 */
1301 static void autofs4_force_release(struct autofs_sb_info *sbi)
1302 {
1303 - struct dentry *this_parent = sbi->root;
1304 + struct dentry *this_parent = sbi->sb->s_root;
1305 struct list_head *next;
1306
1307 + if (!sbi->sb->s_root)
1308 + return;
1309 +
1310 spin_lock(&dcache_lock);
1311 repeat:
1312 next = this_parent->d_subdirs.next;
1313 @@ -126,7 +137,7 @@ resume:
1314 spin_lock(&dcache_lock);
1315 }
1316
1317 - if (this_parent != sbi->root) {
1318 + if (this_parent != sbi->sb->s_root) {
1319 struct dentry *dentry = this_parent;
1320
1321 next = this_parent->d_u.d_child.next;
1322 @@ -139,29 +150,34 @@ resume:
1323 goto resume;
1324 }
1325 spin_unlock(&dcache_lock);
1326 -
1327 - dput(sbi->root);
1328 - sbi->root = NULL;
1329 shrink_dcache_sb(sbi->sb);
1330 -
1331 - return;
1332 }
1333
1334 -static void autofs4_put_super(struct super_block *sb)
1335 +void autofs4_kill_sb(struct super_block *sb)
1336 {
1337 struct autofs_sb_info *sbi = autofs4_sbi(sb);
1338
1339 - sb->s_fs_info = NULL;
1340 + /*
1341 + * In the event of a failure in get_sb_nodev the superblock
1342 + * info is not present so nothing else has been setup, so
1343 + * just call kill_anon_super when we are called from
1344 + * deactivate_super.
1345 + */
1346 + if (!sbi)
1347 + goto out_kill_sb;
1348
1349 - if ( !sbi->catatonic )
1350 - autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
1351 + /* Free wait queues, close pipe */
1352 + autofs4_catatonic_mode(sbi);
1353
1354 /* Clean up and release dangling references */
1355 autofs4_force_release(sbi);
1356
1357 + sb->s_fs_info = NULL;
1358 kfree(sbi);
1359
1360 +out_kill_sb:
1361 DPRINTK("shutting down");
1362 + kill_anon_super(sb);
1363 }
1364
1365 static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
1366 @@ -177,9 +193,9 @@ static int autofs4_show_options(struct s
1367 seq_printf(m, ",minproto=%d", sbi->min_proto);
1368 seq_printf(m, ",maxproto=%d", sbi->max_proto);
1369
1370 - if (sbi->type & AUTOFS_TYPE_OFFSET)
1371 + if (autofs_type_offset(sbi->type))
1372 seq_printf(m, ",offset");
1373 - else if (sbi->type & AUTOFS_TYPE_DIRECT)
1374 + else if (autofs_type_direct(sbi->type))
1375 seq_printf(m, ",direct");
1376 else
1377 seq_printf(m, ",indirect");
1378 @@ -188,7 +204,6 @@ static int autofs4_show_options(struct s
1379 }
1380
1381 static struct super_operations autofs4_sops = {
1382 - .put_super = autofs4_put_super,
1383 .statfs = simple_statfs,
1384 .show_options = autofs4_show_options,
1385 };
1386 @@ -266,13 +281,13 @@ static int parse_options(char *options,
1387 *maxproto = option;
1388 break;
1389 case Opt_indirect:
1390 - *type = AUTOFS_TYPE_INDIRECT;
1391 + set_autofs_type_indirect(type);
1392 break;
1393 case Opt_direct:
1394 - *type = AUTOFS_TYPE_DIRECT;
1395 + set_autofs_type_direct(type);
1396 break;
1397 case Opt_offset:
1398 - *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET;
1399 + set_autofs_type_offset(type);
1400 break;
1401 default:
1402 return 1;
1403 @@ -314,20 +329,23 @@ int autofs4_fill_super(struct super_bloc
1404
1405 s->s_fs_info = sbi;
1406 sbi->magic = AUTOFS_SBI_MAGIC;
1407 - sbi->root = NULL;
1408 sbi->pipefd = -1;
1409 - sbi->catatonic = 0;
1410 + sbi->pipe = NULL;
1411 + sbi->catatonic = 1;
1412 sbi->exp_timeout = 0;
1413 sbi->oz_pgrp = process_group(current);
1414 sbi->sb = s;
1415 sbi->version = 0;
1416 sbi->sub_version = 0;
1417 - sbi->type = 0;
1418 + set_autofs_type_indirect(&sbi->type);
1419 sbi->min_proto = 0;
1420 sbi->max_proto = 0;
1421 mutex_init(&sbi->wq_mutex);
1422 spin_lock_init(&sbi->fs_lock);
1423 sbi->queues = NULL;
1424 + spin_lock_init(&sbi->lookup_lock);
1425 + INIT_LIST_HEAD(&sbi->active_list);
1426 + INIT_LIST_HEAD(&sbi->expiring_list);
1427 s->s_blocksize = 1024;
1428 s->s_blocksize_bits = 10;
1429 s->s_magic = AUTOFS_SUPER_MAGIC;
1430 @@ -362,7 +380,7 @@ int autofs4_fill_super(struct super_bloc
1431 }
1432
1433 root_inode->i_fop = &autofs4_root_operations;
1434 - root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ?
1435 + root_inode->i_op = autofs_type_trigger(sbi->type) ?
1436 &autofs4_direct_root_inode_operations :
1437 &autofs4_indirect_root_inode_operations;
1438
1439 @@ -394,13 +412,7 @@ int autofs4_fill_super(struct super_bloc
1440 goto fail_fput;
1441 sbi->pipe = pipe;
1442 sbi->pipefd = pipefd;
1443 -
1444 - /*
1445 - * Take a reference to the root dentry so we get a chance to
1446 - * clean up the dentry tree on umount.
1447 - * See autofs4_force_release.
1448 - */
1449 - sbi->root = dget(root);
1450 + sbi->catatonic = 0;
1451
1452 /*
1453 * Success! Install the root dentry now to indicate completion.
1454 @@ -425,6 +437,7 @@ fail_ino:
1455 kfree(ino);
1456 fail_free:
1457 kfree(sbi);
1458 + s->s_fs_info = NULL;
1459 fail_unlock:
1460 return -EINVAL;
1461 }
1462 --- linux-2.6.18.orig/fs/autofs4/waitq.c
1463 +++ linux-2.6.18/fs/autofs4/waitq.c
1464 @@ -28,6 +28,12 @@ void autofs4_catatonic_mode(struct autof
1465 {
1466 struct autofs_wait_queue *wq, *nwq;
1467
1468 + mutex_lock(&sbi->wq_mutex);
1469 + if (sbi->catatonic) {
1470 + mutex_unlock(&sbi->wq_mutex);
1471 + return;
1472 + }
1473 +
1474 DPRINTK("entering catatonic mode");
1475
1476 sbi->catatonic = 1;
1477 @@ -36,15 +42,17 @@ void autofs4_catatonic_mode(struct autof
1478 while (wq) {
1479 nwq = wq->next;
1480 wq->status = -ENOENT; /* Magic is gone - report failure */
1481 - kfree(wq->name);
1482 - wq->name = NULL;
1483 + if (wq->name.name) {
1484 + kfree(wq->name.name);
1485 + wq->name.name = NULL;
1486 + }
1487 + wq->wait_ctr--;
1488 wake_up_interruptible(&wq->queue);
1489 wq = nwq;
1490 }
1491 - if (sbi->pipe) {
1492 - fput(sbi->pipe); /* Close the pipe */
1493 - sbi->pipe = NULL;
1494 - }
1495 + fput(sbi->pipe); /* Close the pipe */
1496 + sbi->pipe = NULL;
1497 + mutex_unlock(&sbi->wq_mutex);
1498 shrink_dcache_sb(sbi->sb);
1499 }
1500
1501 @@ -87,11 +95,16 @@ static void autofs4_notify_daemon(struct
1502 struct autofs_wait_queue *wq,
1503 int type)
1504 {
1505 - union autofs_packet_union pkt;
1506 + union {
1507 + struct autofs_packet_hdr hdr;
1508 + union autofs_packet_union v4_pkt;
1509 + union autofs_v5_packet_union v5_pkt;
1510 + } pkt;
1511 + struct file *pipe = NULL;
1512 size_t pktsz;
1513
1514 DPRINTK("wait id = 0x%08lx, name = %.*s, type=%d",
1515 - wq->wait_queue_token, wq->len, wq->name, type);
1516 + wq->wait_queue_token, wq->name.len, wq->name.name, type);
1517
1518 memset(&pkt,0,sizeof pkt); /* For security reasons */
1519
1520 @@ -101,26 +114,26 @@ static void autofs4_notify_daemon(struct
1521 /* Kernel protocol v4 missing and expire packets */
1522 case autofs_ptype_missing:
1523 {
1524 - struct autofs_packet_missing *mp = &pkt.missing;
1525 + struct autofs_packet_missing *mp = &pkt.v4_pkt.missing;
1526
1527 pktsz = sizeof(*mp);
1528
1529 mp->wait_queue_token = wq->wait_queue_token;
1530 - mp->len = wq->len;
1531 - memcpy(mp->name, wq->name, wq->len);
1532 - mp->name[wq->len] = '\0';
1533 + mp->len = wq->name.len;
1534 + memcpy(mp->name, wq->name.name, wq->name.len);
1535 + mp->name[wq->name.len] = '\0';
1536 break;
1537 }
1538 case autofs_ptype_expire_multi:
1539 {
1540 - struct autofs_packet_expire_multi *ep = &pkt.expire_multi;
1541 + struct autofs_packet_expire_multi *ep = &pkt.v4_pkt.expire_multi;
1542
1543 pktsz = sizeof(*ep);
1544
1545 ep->wait_queue_token = wq->wait_queue_token;
1546 - ep->len = wq->len;
1547 - memcpy(ep->name, wq->name, wq->len);
1548 - ep->name[wq->len] = '\0';
1549 + ep->len = wq->name.len;
1550 + memcpy(ep->name, wq->name.name, wq->name.len);
1551 + ep->name[wq->name.len] = '\0';
1552 break;
1553 }
1554 /*
1555 @@ -132,14 +145,14 @@ static void autofs4_notify_daemon(struct
1556 case autofs_ptype_missing_direct:
1557 case autofs_ptype_expire_direct:
1558 {
1559 - struct autofs_v5_packet *packet = &pkt.v5_packet;
1560 + struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
1561
1562 pktsz = sizeof(*packet);
1563
1564 packet->wait_queue_token = wq->wait_queue_token;
1565 - packet->len = wq->len;
1566 - memcpy(packet->name, wq->name, wq->len);
1567 - packet->name[wq->len] = '\0';
1568 + packet->len = wq->name.len;
1569 + memcpy(packet->name, wq->name.name, wq->name.len);
1570 + packet->name[wq->name.len] = '\0';
1571 packet->dev = wq->dev;
1572 packet->ino = wq->ino;
1573 packet->uid = wq->uid;
1574 @@ -153,8 +166,19 @@ static void autofs4_notify_daemon(struct
1575 return;
1576 }
1577
1578 - if (autofs4_write(sbi->pipe, &pkt, pktsz))
1579 - autofs4_catatonic_mode(sbi);
1580 + /* Check if we have become catatonic */
1581 + mutex_lock(&sbi->wq_mutex);
1582 + if (!sbi->catatonic) {
1583 + pipe = sbi->pipe;
1584 + get_file(pipe);
1585 + }
1586 + mutex_unlock(&sbi->wq_mutex);
1587 +
1588 + if (pipe) {
1589 + if (autofs4_write(pipe, &pkt, pktsz))
1590 + autofs4_catatonic_mode(sbi);
1591 + fput(pipe);
1592 + }
1593 }
1594
1595 static int autofs4_getpath(struct autofs_sb_info *sbi,
1596 @@ -170,7 +194,7 @@ static int autofs4_getpath(struct autofs
1597 for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
1598 len += tmp->d_name.len + 1;
1599
1600 - if (--len > NAME_MAX) {
1601 + if (!len || --len > NAME_MAX) {
1602 spin_unlock(&dcache_lock);
1603 return 0;
1604 }
1605 @@ -190,58 +214,55 @@ static int autofs4_getpath(struct autofs
1606 }
1607
1608 static struct autofs_wait_queue *
1609 -autofs4_find_wait(struct autofs_sb_info *sbi,
1610 - char *name, unsigned int hash, unsigned int len)
1611 +autofs4_find_wait(struct autofs_sb_info *sbi, struct qstr *qstr)
1612 {
1613 struct autofs_wait_queue *wq;
1614
1615 for (wq = sbi->queues; wq; wq = wq->next) {
1616 - if (wq->hash == hash &&
1617 - wq->len == len &&
1618 - wq->name && !memcmp(wq->name, name, len))
1619 + if (wq->name.hash == qstr->hash &&
1620 + wq->name.len == qstr->len &&
1621 + wq->name.name &&
1622 + !memcmp(wq->name.name, qstr->name, qstr->len))
1623 break;
1624 }
1625 return wq;
1626 }
1627
1628 -int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1629 - enum autofs_notify notify)
1630 +/*
1631 + * Check if we have a valid request.
1632 + * Returns
1633 + * 1 if the request should continue.
1634 + * In this case we can return an autofs_wait_queue entry if one is
1635 + * found or NULL to idicate a new wait needs to be created.
1636 + * 0 or a negative errno if the request shouldn't continue.
1637 + */
1638 +static int validate_request(struct autofs_wait_queue **wait,
1639 + struct autofs_sb_info *sbi,
1640 + struct qstr *qstr,
1641 + struct dentry*dentry, enum autofs_notify notify)
1642 {
1643 - struct autofs_info *ino;
1644 struct autofs_wait_queue *wq;
1645 - char *name;
1646 - unsigned int len = 0;
1647 - unsigned int hash = 0;
1648 - int status, type;
1649 -
1650 - /* In catatonic mode, we don't wait for nobody */
1651 - if (sbi->catatonic)
1652 - return -ENOENT;
1653 -
1654 - name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
1655 - if (!name)
1656 - return -ENOMEM;
1657 + struct autofs_info *ino;
1658
1659 - /* If this is a direct mount request create a dummy name */
1660 - if (IS_ROOT(dentry) && (sbi->type & AUTOFS_TYPE_DIRECT))
1661 - len = sprintf(name, "%p", dentry);
1662 - else {
1663 - len = autofs4_getpath(sbi, dentry, &name);
1664 - if (!len) {
1665 - kfree(name);
1666 - return -ENOENT;
1667 - }
1668 + /* Wait in progress, continue; */
1669 + wq = autofs4_find_wait(sbi, qstr);
1670 + if (wq) {
1671 + *wait = wq;
1672 + return 1;
1673 }
1674 - hash = full_name_hash(name, len);
1675
1676 - if (mutex_lock_interruptible(&sbi->wq_mutex)) {
1677 - kfree(name);
1678 - return -EINTR;
1679 - }
1680 + *wait = NULL;
1681
1682 - wq = autofs4_find_wait(sbi, name, hash, len);
1683 + /* If we don't yet have any info this is a new request */
1684 ino = autofs4_dentry_ino(dentry);
1685 - if (!wq && ino && notify == NFY_NONE) {
1686 + if (!ino)
1687 + return 1;
1688 +
1689 + /*
1690 + * If we've been asked to wait on an existing expire (NFY_NONE)
1691 + * but there is no wait in the queue ...
1692 + */
1693 + if (notify == NFY_NONE) {
1694 /*
1695 * Either we've betean the pending expire to post it's
1696 * wait or it finished while we waited on the mutex.
1697 @@ -252,13 +273,14 @@ int autofs4_wait(struct autofs_sb_info *
1698 while (ino->flags & AUTOFS_INF_EXPIRING) {
1699 mutex_unlock(&sbi->wq_mutex);
1700 schedule_timeout_interruptible(HZ/10);
1701 - if (mutex_lock_interruptible(&sbi->wq_mutex)) {
1702 - kfree(name);
1703 + if (mutex_lock_interruptible(&sbi->wq_mutex))
1704 return -EINTR;
1705 +
1706 + wq = autofs4_find_wait(sbi, qstr);
1707 + if (wq) {
1708 + *wait = wq;
1709 + return 1;
1710 }
1711 - wq = autofs4_find_wait(sbi, name, hash, len);
1712 - if (wq)
1713 - break;
1714 }
1715
1716 /*
1717 @@ -266,18 +288,90 @@ int autofs4_wait(struct autofs_sb_info *
1718 * cases where we wait on NFY_NONE neither depend on the
1719 * return status of the wait.
1720 */
1721 - if (!wq) {
1722 - kfree(name);
1723 - mutex_unlock(&sbi->wq_mutex);
1724 + return 0;
1725 + }
1726 +
1727 + /*
1728 + * If we've been asked to trigger a mount and the request
1729 + * completed while we waited on the mutex ...
1730 + */
1731 + if (notify == NFY_MOUNT) {
1732 + /*
1733 + * If the dentry was successfully mounted while we slept
1734 + * on the wait queue mutex we can return success. If it
1735 + * isn't mounted (doesn't have submounts for the case of
1736 + * a multi-mount with no mount at it's base) we can
1737 + * continue on and create a new request.
1738 + */
1739 + if (have_submounts(dentry))
1740 return 0;
1741 + }
1742 +
1743 + return 1;
1744 +}
1745 +
1746 +int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
1747 + enum autofs_notify notify)
1748 +{
1749 + struct autofs_wait_queue *wq;
1750 + struct qstr qstr;
1751 + char *name;
1752 + int status, ret, type;
1753 +
1754 + /* In catatonic mode, we don't wait for nobody */
1755 + if (sbi->catatonic)
1756 + return -ENOENT;
1757 +
1758 + if (!dentry->d_inode) {
1759 + /*
1760 + * A wait for a negative dentry is invalid for certain
1761 + * cases. A direct or offset mount "always" has its mount
1762 + * point directory created and so the request dentry must
1763 + * be positive or the map key doesn't exist. The situation
1764 + * is very similar for indirect mounts except only dentrys
1765 + * in the root of the autofs file system may be negative.
1766 + */
1767 + if (autofs_type_trigger(sbi->type))
1768 + return -ENOENT;
1769 + else if (!IS_ROOT(dentry->d_parent))
1770 + return -ENOENT;
1771 + }
1772 +
1773 + name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
1774 + if (!name)
1775 + return -ENOMEM;
1776 +
1777 + /* If this is a direct mount request create a dummy name */
1778 + if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
1779 + qstr.len = sprintf(name, "%p", dentry);
1780 + else {
1781 + qstr.len = autofs4_getpath(sbi, dentry, &name);
1782 + if (!qstr.len) {
1783 + kfree(name);
1784 + return -ENOENT;
1785 }
1786 }
1787 + qstr.name = name;
1788 + qstr.hash = full_name_hash(name, qstr.len);
1789 +
1790 + if (mutex_lock_interruptible(&sbi->wq_mutex)) {
1791 + kfree(qstr.name);
1792 + return -EINTR;
1793 + }
1794 +
1795 + ret = validate_request(&wq, sbi, &qstr, dentry, notify);
1796 + if (ret <= 0) {
1797 + if (ret == 0)
1798 + mutex_unlock(&sbi->wq_mutex);
1799 + kfree(qstr.name);
1800 + return ret;
1801 + }
1802
1803 if (!wq) {
1804 /* Create a new wait queue */
1805 wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
1806 if (!wq) {
1807 - kfree(name);
1808 + kfree(qstr.name);
1809 mutex_unlock(&sbi->wq_mutex);
1810 return -ENOMEM;
1811 }
1812 @@ -288,9 +382,7 @@ int autofs4_wait(struct autofs_sb_info *
1813 wq->next = sbi->queues;
1814 sbi->queues = wq;
1815 init_waitqueue_head(&wq->queue);
1816 - wq->hash = hash;
1817 - wq->name = name;
1818 - wq->len = len;
1819 + memcpy(&wq->name, &qstr, sizeof(struct qstr));
1820 wq->dev = autofs4_get_dev(sbi);
1821 wq->ino = autofs4_get_ino(sbi);
1822 wq->uid = current->uid;
1823 @@ -298,7 +390,7 @@ int autofs4_wait(struct autofs_sb_info *
1824 wq->pid = current->pid;
1825 wq->tgid = current->tgid;
1826 wq->status = -EINTR; /* Status return if interrupted */
1827 - atomic_set(&wq->wait_ctr, 2);
1828 + wq->wait_ctr = 2;
1829 mutex_unlock(&sbi->wq_mutex);
1830
1831 if (sbi->version < 5) {
1832 @@ -308,38 +400,35 @@ int autofs4_wait(struct autofs_sb_info *
1833 type = autofs_ptype_expire_multi;
1834 } else {
1835 if (notify == NFY_MOUNT)
1836 - type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
1837 + type = autofs_type_trigger(sbi->type) ?
1838 autofs_ptype_missing_direct :
1839 autofs_ptype_missing_indirect;
1840 else
1841 - type = (sbi->type & AUTOFS_TYPE_DIRECT) ?
1842 + type = autofs_type_trigger(sbi->type) ?
1843 autofs_ptype_expire_direct :
1844 autofs_ptype_expire_indirect;
1845 }
1846
1847 DPRINTK("new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
1848 - (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
1849 + (unsigned long) wq->wait_queue_token, wq->name.len,
1850 + wq->name.name, notify);
1851
1852 /* autofs4_notify_daemon() may block */
1853 autofs4_notify_daemon(sbi, wq, type);
1854 } else {
1855 - atomic_inc(&wq->wait_ctr);
1856 + wq->wait_ctr++;
1857 mutex_unlock(&sbi->wq_mutex);
1858 - kfree(name);
1859 + kfree(qstr.name);
1860 DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
1861 - (unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
1862 + (unsigned long) wq->wait_queue_token, wq->name.len,
1863 + wq->name.name, notify);
1864 }
1865
1866 - /* wq->name is NULL if and only if the lock is already released */
1867 -
1868 - if (sbi->catatonic) {
1869 - /* We might have slept, so check again for catatonic mode */
1870 - wq->status = -ENOENT;
1871 - kfree(wq->name);
1872 - wq->name = NULL;
1873 - }
1874 -
1875 - if (wq->name) {
1876 + /*
1877 + * wq->name.name is NULL iff the lock is already released
1878 + * or the mount has been made catatonic.
1879 + */
1880 + if (wq->name.name) {
1881 /* Block all but "shutdown" signals while waiting */
1882 sigset_t oldset;
1883 unsigned long irqflags;
1884 @@ -350,7 +439,7 @@ int autofs4_wait(struct autofs_sb_info *
1885 recalc_sigpending();
1886 spin_unlock_irqrestore(&current->sighand->siglock, irqflags);
1887
1888 - wait_event_interruptible(wq->queue, wq->name == NULL);
1889 + wait_event_interruptible(wq->queue, wq->name.name == NULL);
1890
1891 spin_lock_irqsave(&current->sighand->siglock, irqflags);
1892 current->blocked = oldset;
1893 @@ -362,9 +451,45 @@ int autofs4_wait(struct autofs_sb_info *
1894
1895 status = wq->status;
1896
1897 + /*
1898 + * For direct and offset mounts we need to track the requester's
1899 + * uid and gid in the dentry info struct. This is so it can be
1900 + * supplied, on request, by the misc device ioctl interface.
1901 + * This is needed during daemon resatart when reconnecting
1902 + * to existing, active, autofs mounts. The uid and gid (and
1903 + * related string values) may be used for macro substitution
1904 + * in autofs mount maps.
1905 + */
1906 + if (!status) {
1907 + struct autofs_info *ino;
1908 + struct dentry *de = NULL;
1909 +
1910 + /* direct mount or browsable map */
1911 + ino = autofs4_dentry_ino(dentry);
1912 + if (!ino) {
1913 + /* If not lookup actual dentry used */
1914 + de = d_lookup(dentry->d_parent, &dentry->d_name);
1915 + if (de)
1916 + ino = autofs4_dentry_ino(de);
1917 + }
1918 +
1919 + /* Set mount requester */
1920 + if (ino) {
1921 + spin_lock(&sbi->fs_lock);
1922 + ino->uid = wq->uid;
1923 + ino->gid = wq->gid;
1924 + spin_unlock(&sbi->fs_lock);
1925 + }
1926 +
1927 + if (de)
1928 + dput(de);
1929 + }
1930 +
1931 /* Are we the last process to need status? */
1932 - if (atomic_dec_and_test(&wq->wait_ctr))
1933 + mutex_lock(&sbi->wq_mutex);
1934 + if (!--wq->wait_ctr)
1935 kfree(wq);
1936 + mutex_unlock(&sbi->wq_mutex);
1937
1938 return status;
1939 }
1940 @@ -386,16 +511,13 @@ int autofs4_wait_release(struct autofs_s
1941 }
1942
1943 *wql = wq->next; /* Unlink from chain */
1944 - mutex_unlock(&sbi->wq_mutex);
1945 - kfree(wq->name);
1946 - wq->name = NULL; /* Do not wait on this queue */
1947 -
1948 + kfree(wq->name.name);
1949 + wq->name.name = NULL; /* Do not wait on this queue */
1950 wq->status = status;
1951 -
1952 - if (atomic_dec_and_test(&wq->wait_ctr)) /* Is anyone still waiting for this guy? */
1953 + wake_up_interruptible(&wq->queue);
1954 + if (!--wq->wait_ctr)
1955 kfree(wq);
1956 - else
1957 - wake_up_interruptible(&wq->queue);
1958 + mutex_unlock(&sbi->wq_mutex);
1959
1960 return 0;
1961 }
1962 --- linux-2.6.18.orig/fs/autofs/waitq.c
1963 +++ linux-2.6.18/fs/autofs/waitq.c
1964 @@ -41,6 +41,7 @@ void autofs_catatonic_mode(struct autofs
1965 wq = nwq;
1966 }
1967 fput(sbi->pipe); /* Close the pipe */
1968 + sbi->pipe = NULL;
1969 autofs_hash_dputall(&sbi->dirhash); /* Remove all dentry pointers */
1970 }
1971
1972 --- linux-2.6.18.orig/include/linux/auto_fs4.h
1973 +++ linux-2.6.18/include/linux/auto_fs4.h
1974 @@ -23,12 +23,71 @@
1975 #define AUTOFS_MIN_PROTO_VERSION 3
1976 #define AUTOFS_MAX_PROTO_VERSION 5
1977
1978 -#define AUTOFS_PROTO_SUBVERSION 0
1979 +#define AUTOFS_PROTO_SUBVERSION 1
1980
1981 /* Mask for expire behaviour */
1982 #define AUTOFS_EXP_IMMEDIATE 1
1983 #define AUTOFS_EXP_LEAVES 2
1984
1985 +#define AUTOFS_TYPE_ANY 0U
1986 +#define AUTOFS_TYPE_INDIRECT 1U
1987 +#define AUTOFS_TYPE_DIRECT 2U
1988 +#define AUTOFS_TYPE_OFFSET 4U
1989 +
1990 +static inline void set_autofs_type_indirect(unsigned int *type)
1991 +{
1992 + *type = AUTOFS_TYPE_INDIRECT;
1993 + return;
1994 +}
1995 +
1996 +static inline unsigned int autofs_type_indirect(unsigned int type)
1997 +{
1998 + return (type == AUTOFS_TYPE_INDIRECT);
1999 +}
2000 +
2001 +static inline void set_autofs_type_direct(unsigned int *type)
2002 +{
2003 + *type = AUTOFS_TYPE_DIRECT;
2004 + return;
2005 +}
2006 +
2007 +static inline unsigned int autofs_type_direct(unsigned int type)
2008 +{
2009 + return (type == AUTOFS_TYPE_DIRECT);
2010 +}
2011 +
2012 +static inline void set_autofs_type_offset(unsigned int *type)
2013 +{
2014 + *type = AUTOFS_TYPE_OFFSET;
2015 + return;
2016 +}
2017 +
2018 +static inline unsigned int autofs_type_offset(unsigned int type)
2019 +{
2020 + return (type == AUTOFS_TYPE_OFFSET);
2021 +}
2022 +
2023 +static inline unsigned int autofs_type_trigger(unsigned int type)
2024 +{
2025 + return (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET);
2026 +}
2027 +
2028 +/*
2029 + * This isn't really a type as we use it to say "no type set" to
2030 + * indicate we want to search for "any" mount in the
2031 + * autofs_dev_ioctl_ismountpoint() device ioctl function.
2032 + */
2033 +static inline void set_autofs_type_any(unsigned int *type)
2034 +{
2035 + *type = AUTOFS_TYPE_ANY;
2036 + return;
2037 +}
2038 +
2039 +static inline unsigned int autofs_type_any(unsigned int type)
2040 +{
2041 + return (type == AUTOFS_TYPE_ANY);
2042 +}
2043 +
2044 /* Daemon notification packet types */
2045 enum autofs_notify {
2046 NFY_NONE,
2047 @@ -59,6 +118,13 @@ struct autofs_packet_expire_multi {
2048 char name[NAME_MAX+1];
2049 };
2050
2051 +union autofs_packet_union {
2052 + struct autofs_packet_hdr hdr;
2053 + struct autofs_packet_missing missing;
2054 + struct autofs_packet_expire expire;
2055 + struct autofs_packet_expire_multi expire_multi;
2056 +};
2057 +
2058 /* autofs v5 common packet struct */
2059 struct autofs_v5_packet {
2060 struct autofs_packet_hdr hdr;
2061 @@ -78,20 +144,19 @@ typedef struct autofs_v5_packet autofs_p
2062 typedef struct autofs_v5_packet autofs_packet_missing_direct_t;
2063 typedef struct autofs_v5_packet autofs_packet_expire_direct_t;
2064
2065 -union autofs_packet_union {
2066 +union autofs_v5_packet_union {
2067 struct autofs_packet_hdr hdr;
2068 - struct autofs_packet_missing missing;
2069 - struct autofs_packet_expire expire;
2070 - struct autofs_packet_expire_multi expire_multi;
2071 struct autofs_v5_packet v5_packet;
2072 + autofs_packet_missing_indirect_t missing_indirect;
2073 + autofs_packet_expire_indirect_t expire_indirect;
2074 + autofs_packet_missing_direct_t missing_direct;
2075 + autofs_packet_expire_direct_t expire_direct;
2076 };
2077
2078 #define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
2079 #define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI
2080 #define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI
2081 #define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
2082 -#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
2083 -#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
2084 #define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
2085
2086
2087 --- linux-2.6.18.orig/fs/autofs4/expire.c
2088 +++ linux-2.6.18/fs/autofs4/expire.c
2089 @@ -56,12 +56,25 @@ static int autofs4_mount_busy(struct vfs
2090 mntget(mnt);
2091 dget(dentry);
2092
2093 - if (!autofs4_follow_mount(&mnt, &dentry))
2094 + if (!follow_down(&mnt, &dentry))
2095 goto done;
2096
2097 - /* This is an autofs submount, we can't expire it */
2098 - if (is_autofs4_dentry(dentry))
2099 - goto done;
2100 + if (is_autofs4_dentry(dentry)) {
2101 + struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
2102 +
2103 + /* This is an autofs submount, we can't expire it */
2104 + if (autofs_type_indirect(sbi->type))
2105 + goto done;
2106 +
2107 + /*
2108 + * Otherwise it's an offset mount and we need to check
2109 + * if we can umount its mount, if there is one.
2110 + */
2111 + if (!d_mountpoint(dentry)) {
2112 + status = 0;
2113 + goto done;
2114 + }
2115 + }
2116
2117 /* Update the expiry counter if fs is busy */
2118 if (!may_umount_tree(mnt)) {
2119 @@ -73,8 +86,8 @@ static int autofs4_mount_busy(struct vfs
2120 status = 0;
2121 done:
2122 DPRINTK("returning = %d", status);
2123 - mntput(mnt);
2124 dput(dentry);
2125 + mntput(mnt);
2126 return status;
2127 }
2128
2129 @@ -244,10 +257,10 @@ cont:
2130 }
2131
2132 /* Check if we can expire a direct mount (possibly a tree) */
2133 -static struct dentry *autofs4_expire_direct(struct super_block *sb,
2134 - struct vfsmount *mnt,
2135 - struct autofs_sb_info *sbi,
2136 - int how)
2137 +struct dentry *autofs4_expire_direct(struct super_block *sb,
2138 + struct vfsmount *mnt,
2139 + struct autofs_sb_info *sbi,
2140 + int how)
2141 {
2142 unsigned long timeout;
2143 struct dentry *root = dget(sb->s_root);
2144 @@ -259,13 +272,15 @@ static struct dentry *autofs4_expire_dir
2145 now = jiffies;
2146 timeout = sbi->exp_timeout;
2147
2148 - /* Lock the tree as we must expire as a whole */
2149 spin_lock(&sbi->fs_lock);
2150 if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
2151 struct autofs_info *ino = autofs4_dentry_ino(root);
2152 -
2153 - /* Set this flag early to catch sys_chdir and the like */
2154 + if (d_mountpoint(root)) {
2155 + ino->flags |= AUTOFS_INF_MOUNTPOINT;
2156 + root->d_mounted--;
2157 + }
2158 ino->flags |= AUTOFS_INF_EXPIRING;
2159 + init_completion(&ino->expire_complete);
2160 spin_unlock(&sbi->fs_lock);
2161 return root;
2162 }
2163 @@ -281,10 +296,10 @@ static struct dentry *autofs4_expire_dir
2164 * - it is unused by any user process
2165 * - it has been unused for exp_timeout time
2166 */
2167 -static struct dentry *autofs4_expire_indirect(struct super_block *sb,
2168 - struct vfsmount *mnt,
2169 - struct autofs_sb_info *sbi,
2170 - int how)
2171 +struct dentry *autofs4_expire_indirect(struct super_block *sb,
2172 + struct vfsmount *mnt,
2173 + struct autofs_sb_info *sbi,
2174 + int how)
2175 {
2176 unsigned long timeout;
2177 struct dentry *root = sb->s_root;
2178 @@ -292,6 +307,8 @@ static struct dentry *autofs4_expire_ind
2179 struct list_head *next;
2180 int do_now = how & AUTOFS_EXP_IMMEDIATE;
2181 int exp_leaves = how & AUTOFS_EXP_LEAVES;
2182 + struct autofs_info *ino;
2183 + unsigned int ino_count;
2184
2185 if ( !sbi->exp_timeout || !root )
2186 return NULL;
2187 @@ -316,6 +333,9 @@ static struct dentry *autofs4_expire_ind
2188 dentry = dget(dentry);
2189 spin_unlock(&dcache_lock);
2190
2191 + spin_lock(&sbi->fs_lock);
2192 + ino = autofs4_dentry_ino(dentry);
2193 +
2194 /*
2195 * Case 1: (i) indirect mount or top level pseudo direct mount
2196 * (autofs-4.1).
2197 @@ -326,6 +346,11 @@ static struct dentry *autofs4_expire_ind
2198 DPRINTK("checking mountpoint %p %.*s",
2199 dentry, (int)dentry->d_name.len, dentry->d_name.name);
2200
2201 + /* Path walk currently on this dentry? */
2202 + ino_count = atomic_read(&ino->count) + 2;
2203 + if (atomic_read(&dentry->d_count) > ino_count)
2204 + goto next;
2205 +
2206 /* Can we umount this guy */
2207 if (autofs4_mount_busy(mnt, dentry))
2208 goto next;
2209 @@ -333,7 +358,7 @@ static struct dentry *autofs4_expire_ind
2210 /* Can we expire this guy */
2211 if (autofs4_can_expire(dentry, timeout, do_now)) {
2212 expired = dentry;
2213 - break;
2214 + goto found;
2215 }
2216 goto next;
2217 }
2218 @@ -343,46 +368,80 @@ static struct dentry *autofs4_expire_ind
2219
2220 /* Case 2: tree mount, expire iff entire tree is not busy */
2221 if (!exp_leaves) {
2222 - /* Lock the tree as we must expire as a whole */
2223 - spin_lock(&sbi->fs_lock);
2224 - if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
2225 - struct autofs_info *inf = autofs4_dentry_ino(dentry);
2226 + /* Path walk currently on this dentry? */
2227 + ino_count = atomic_read(&ino->count) + 1;
2228 + if (atomic_read(&dentry->d_count) > ino_count)
2229 + goto next;
2230
2231 - /* Set this flag early to catch sys_chdir and the like */
2232 - inf->flags |= AUTOFS_INF_EXPIRING;
2233 - spin_unlock(&sbi->fs_lock);
2234 + if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
2235 expired = dentry;
2236 - break;
2237 + goto found;
2238 }
2239 - spin_unlock(&sbi->fs_lock);
2240 /*
2241 * Case 3: pseudo direct mount, expire individual leaves
2242 * (autofs-4.1).
2243 */
2244 } else {
2245 + /* Path walk currently on this dentry? */
2246 + ino_count = atomic_read(&ino->count) + 1;
2247 + if (atomic_read(&dentry->d_count) > ino_count)
2248 + goto next;
2249 +
2250 expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
2251 if (expired) {
2252 dput(dentry);
2253 - break;
2254 + goto found;
2255 }
2256 }
2257 next:
2258 + spin_unlock(&sbi->fs_lock);
2259 dput(dentry);
2260 spin_lock(&dcache_lock);
2261 next = next->next;
2262 }
2263 + spin_unlock(&dcache_lock);
2264 + return NULL;
2265
2266 - if (expired) {
2267 - DPRINTK("returning %p %.*s",
2268 - expired, (int)expired->d_name.len, expired->d_name.name);
2269 - spin_lock(&dcache_lock);
2270 - list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
2271 - spin_unlock(&dcache_lock);
2272 - return expired;
2273 - }
2274 +found:
2275 + DPRINTK("returning %p %.*s",
2276 + expired, (int)expired->d_name.len, expired->d_name.name);
2277 + ino = autofs4_dentry_ino(expired);
2278 + ino->flags |= AUTOFS_INF_EXPIRING;
2279 + init_completion(&ino->expire_complete);
2280 + spin_unlock(&sbi->fs_lock);
2281 + spin_lock(&dcache_lock);
2282 + list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
2283 spin_unlock(&dcache_lock);
2284 + return expired;
2285 +}
2286
2287 - return NULL;
2288 +int autofs4_expire_wait(struct dentry *dentry)
2289 +{
2290 + struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
2291 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
2292 + int status;
2293 +
2294 + /* Block on any pending expire */
2295 + spin_lock(&sbi->fs_lock);
2296 + if (ino->flags & AUTOFS_INF_EXPIRING) {
2297 + spin_unlock(&sbi->fs_lock);
2298 +
2299 + DPRINTK("waiting for expire %p name=%.*s",
2300 + dentry, dentry->d_name.len, dentry->d_name.name);
2301 +
2302 + status = autofs4_wait(sbi, dentry, NFY_NONE);
2303 + wait_for_completion(&ino->expire_complete);
2304 +
2305 + DPRINTK("expire done status=%d", status);
2306 +
2307 + if (d_unhashed(dentry))
2308 + return -EAGAIN;
2309 +
2310 + return status;
2311 + }
2312 + spin_unlock(&sbi->fs_lock);
2313 +
2314 + return 0;
2315 }
2316
2317 /* Perform an expiry operation */
2318 @@ -392,7 +451,9 @@ int autofs4_expire_run(struct super_bloc
2319 struct autofs_packet_expire __user *pkt_p)
2320 {
2321 struct autofs_packet_expire pkt;
2322 + struct autofs_info *ino;
2323 struct dentry *dentry;
2324 + int ret = 0;
2325
2326 memset(&pkt,0,sizeof pkt);
2327
2328 @@ -408,9 +469,15 @@ int autofs4_expire_run(struct super_bloc
2329 dput(dentry);
2330
2331 if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
2332 - return -EFAULT;
2333 + ret = -EFAULT;
2334
2335 - return 0;
2336 + spin_lock(&sbi->fs_lock);
2337 + ino = autofs4_dentry_ino(dentry);
2338 + ino->flags &= ~AUTOFS_INF_EXPIRING;
2339 + complete_all(&ino->expire_complete);
2340 + spin_unlock(&sbi->fs_lock);
2341 +
2342 + return ret;
2343 }
2344
2345 /* Call repeatedly until it returns -EAGAIN, meaning there's nothing
2346 @@ -425,7 +492,7 @@ int autofs4_expire_multi(struct super_bl
2347 if (arg && get_user(do_now, arg))
2348 return -EFAULT;
2349
2350 - if (sbi->type & AUTOFS_TYPE_DIRECT)
2351 + if (autofs_type_trigger(sbi->type))
2352 dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
2353 else
2354 dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
2355 @@ -435,9 +502,16 @@ int autofs4_expire_multi(struct super_bl
2356
2357 /* This is synchronous because it makes the daemon a
2358 little easier */
2359 - ino->flags |= AUTOFS_INF_EXPIRING;
2360 ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
2361 +
2362 + spin_lock(&sbi->fs_lock);
2363 + if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
2364 + sb->s_root->d_mounted++;
2365 + ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
2366 + }
2367 ino->flags &= ~AUTOFS_INF_EXPIRING;
2368 + complete_all(&ino->expire_complete);
2369 + spin_unlock(&sbi->fs_lock);
2370 dput(dentry);
2371 }
2372
2373 --- linux-2.6.18.orig/include/linux/compat_ioctl.h
2374 +++ linux-2.6.18/include/linux/compat_ioctl.h
2375 @@ -565,8 +565,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
2376 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
2377 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
2378 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
2379 -COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
2380 -COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
2381 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
2382 /* Raw devices */
2383 COMPATIBLE_IOCTL(RAW_SETBIND)
2384 --- /dev/null
2385 +++ linux-2.6.18/Documentation/filesystems/autofs4-mount-control.txt
2386 @@ -0,0 +1,414 @@
2387 +
2388 +Miscellaneous Device control operations for the autofs4 kernel module
2389 +====================================================================
2390 +
2391 +The problem
2392 +===========
2393 +
2394 +There is a problem with active restarts in autofs (that is to say
2395 +restarting autofs when there are busy mounts).
2396 +
2397 +During normal operation autofs uses a file descriptor opened on the
2398 +directory that is being managed in order to be able to issue control
2399 +operations. Using a file descriptor gives ioctl operations access to
2400 +autofs specific information stored in the super block. The operations
2401 +are things such as setting an autofs mount catatonic, setting the
2402 +expire timeout and requesting expire checks. As is explained below,
2403 +certain types of autofs triggered mounts can end up covering an autofs
2404 +mount itself which prevents us being able to use open(2) to obtain a
2405 +file descriptor for these operations if we don't already have one open.
2406 +
2407 +Currently autofs uses "umount -l" (lazy umount) to clear active mounts
2408 +at restart. While using lazy umount works for most cases, anything that
2409 +needs to walk back up the mount tree to construct a path, such as
2410 +getcwd(2) and the proc file system /proc/<pid>/cwd, no longer works
2411 +because the point from which the path is constructed has been detached
2412 +from the mount tree.
2413 +
2414 +The actual problem with autofs is that it can't reconnect to existing
2415 +mounts. Immediately one thinks of just adding the ability to remount
2416 +autofs file systems would solve it, but alas, that can't work. This is
2417 +because autofs direct mounts and the implementation of "on demand mount
2418 +and expire" of nested mount trees have the file system mounted directly
2419 +on top of the mount trigger directory dentry.
2420 +
2421 +For example, there are two types of automount maps, direct (in the kernel
2422 +module source you will see a third type called an offset, which is just
2423 +a direct mount in disguise) and indirect.
2424 +
2425 +Here is a master map with direct and indirect map entries:
2426 +
2427 +/- /etc/auto.direct
2428 +/test /etc/auto.indirect
2429 +
2430 +and the corresponding map files:
2431 +
2432 +/etc/auto.direct:
2433 +
2434 +/automount/dparse/g6 budgie:/autofs/export1
2435 +/automount/dparse/g1 shark:/autofs/export1
2436 +and so on.
2437 +
2438 +/etc/auto.indirect:
2439 +
2440 +g1 shark:/autofs/export1
2441 +g6 budgie:/autofs/export1
2442 +and so on.
2443 +
2444 +For the above indirect map an autofs file system is mounted on /test and
2445 +mounts are triggered for each sub-directory key by the inode lookup
2446 +operation. So we see a mount of shark:/autofs/export1 on /test/g1, for
2447 +example.
2448 +
2449 +The way that direct mounts are handled is by making an autofs mount on
2450 +each full path, such as /automount/dparse/g1, and using it as a mount
2451 +trigger. So when we walk on the path we mount shark:/autofs/export1 "on
2452 +top of this mount point". Since these are always directories we can
2453 +use the follow_link inode operation to trigger the mount.
2454 +
2455 +But, each entry in direct and indirect maps can have offsets (making
2456 +them multi-mount map entries).
2457 +
2458 +For example, an indirect mount map entry could also be:
2459 +
2460 +g1 \
2461 + / shark:/autofs/export5/testing/test \
2462 + /s1 shark:/autofs/export/testing/test/s1 \
2463 + /s2 shark:/autofs/export5/testing/test/s2 \
2464 + /s1/ss1 shark:/autofs/export1 \
2465 + /s2/ss2 shark:/autofs/export2
2466 +
2467 +and a similarly a direct mount map entry could also be:
2468 +
2469 +/automount/dparse/g1 \
2470 + / shark:/autofs/export5/testing/test \
2471 + /s1 shark:/autofs/export/testing/test/s1 \
2472 + /s2 shark:/autofs/export5/testing/test/s2 \
2473 + /s1/ss1 shark:/autofs/export2 \
2474 + /s2/ss2 shark:/autofs/export2
2475 +
2476 +One of the issues with version 4 of autofs was that, when mounting an
2477 +entry with a large number of offsets, possibly with nesting, we needed
2478 +to mount and umount all of the offsets as a single unit. Not really a
2479 +problem, except for people with a large number of offsets in map entries.
2480 +This mechanism is used for the well known "hosts" map and we have seen
2481 +cases (in 2.4) where the available number of mounts are exhausted or
2482 +where the number of privileged ports available is exhausted.
2483 +
2484 +In version 5 we mount only as we go down the tree of offsets and
2485 +similarly for expiring them which resolves the above problem. There is
2486 +somewhat more detail to the implementation but it isn't needed for the
2487 +sake of the problem explanation. The one important detail is that these
2488 +offsets are implemented using the same mechanism as the direct mounts
2489 +above and so the mount points can be covered by a mount.
2490 +
2491 +The current autofs implementation uses an ioctl file descriptor opened
2492 +on the mount point for control operations. The references held by the
2493 +descriptor are accounted for in checks made to determine if a mount is
2494 +in use and is also used to access autofs file system information held
2495 +in the mount super block. So the use of a file handle needs to be
2496 +retained.
2497 +
2498 +
2499 +The Solution
2500 +============
2501 +
2502 +To be able to restart autofs leaving existing direct, indirect and
2503 +offset mounts in place we need to be able to obtain a file handle
2504 +for these potentially covered autofs mount points. Rather than just
2505 +implement an isolated operation it was decided to re-implement the
2506 +existing ioctl interface and add new operations to provide this
2507 +functionality.
2508 +
2509 +In addition, to be able to reconstruct a mount tree that has busy mounts,
2510 +the uid and gid of the last user that triggered the mount needs to be
2511 +available because these can be used as macro substitution variables in
2512 +autofs maps. They are recorded at mount request time and an operation
2513 +has been added to retrieve them.
2514 +
2515 +Since we're re-implementing the control interface, a couple of other
2516 +problems with the existing interface have been addressed. First, when
2517 +a mount or expire operation completes a status is returned to the
2518 +kernel by either a "send ready" or a "send fail" operation. The
2519 +"send fail" operation of the ioctl interface could only ever send
2520 +ENOENT so the re-implementation allows user space to send an actual
2521 +status. Another expensive operation in user space, for those using
2522 +very large maps, is discovering if a mount is present. Usually this
2523 +involves scanning /proc/mounts and since it needs to be done quite
2524 +often it can introduce significant overhead when there are many entries
2525 +in the mount table. An operation to lookup the mount status of a mount
2526 +point dentry (covered or not) has also been added.
2527 +
2528 +Current kernel development policy recommends avoiding the use of the
2529 +ioctl mechanism in favor of systems such as Netlink. An implementation
2530 +using this system was attempted to evaluate its suitability and it was
2531 +found to be inadequate, in this case. The Generic Netlink system was
2532 +used for this as raw Netlink would lead to a significant increase in
2533 +complexity. There's no question that the Generic Netlink system is an
2534 +elegant solution for common case ioctl functions but it's not a complete
2535 +replacement probably because it's primary purpose in life is to be a
2536 +message bus implementation rather than specifically an ioctl replacement.
2537 +While it would be possible to work around this there is one concern
2538 +that lead to the decision to not use it. This is that the autofs
2539 +expire in the daemon has become far to complex because umount
2540 +candidates are enumerated, almost for no other reason than to "count"
2541 +the number of times to call the expire ioctl. This involves scanning
2542 +the mount table which has proved to be a big overhead for users with
2543 +large maps. The best way to improve this is try and get back to the
2544 +way the expire was done long ago. That is, when an expire request is
2545 +issued for a mount (file handle) we should continually call back to
2546 +the daemon until we can't umount any more mounts, then return the
2547 +appropriate status to the daemon. At the moment we just expire one
2548 +mount at a time. A Generic Netlink implementation would exclude this
2549 +possibility for future development due to the requirements of the
2550 +message bus architecture.
2551 +
2552 +
2553 +autofs4 Miscellaneous Device mount control interface
2554 +====================================================
2555 +
2556 +The control interface is opening a device node, typically /dev/autofs.
2557 +
2558 +All the ioctls use a common structure to pass the needed parameter
2559 +information and return operation results:
2560 +
2561 +struct autofs_dev_ioctl {
2562 + __u32 ver_major;
2563 + __u32 ver_minor;
2564 + __u32 size; /* total size of data passed in
2565 + * including this struct */
2566 + __s32 ioctlfd; /* automount command fd */
2567 +
2568 + /* Command parameters */
2569 +
2570 + union {
2571 + struct args_protover protover;
2572 + struct args_protosubver protosubver;
2573 + struct args_openmount openmount;
2574 + struct args_ready ready;
2575 + struct args_fail fail;
2576 + struct args_setpipefd setpipefd;
2577 + struct args_timeout timeout;
2578 + struct args_requester requester;
2579 + struct args_expire expire;
2580 + struct args_askumount askumount;
2581 + struct args_ismountpoint ismountpoint;
2582 + };
2583 +
2584 + char path[0];
2585 +};
2586 +
2587 +The ioctlfd field is a mount point file descriptor of an autofs mount
2588 +point. It is returned by the open call and is used by all calls except
2589 +the check for whether a given path is a mount point, where it may
2590 +optionally be used to check a specific mount corresponding to a given
2591 +mount point file descriptor, and when requesting the uid and gid of the
2592 +last successful mount on a directory within the autofs file system.
2593 +
2594 +The anonymous union is used to communicate parameters and results of calls
2595 +made as described below.
2596 +
2597 +The path field is used to pass a path where it is needed and the size field
2598 +is used account for the increased structure length when translating the
2599 +structure sent from user space.
2600 +
2601 +This structure can be initialized before setting specific fields by using
2602 +the void function call init_autofs_dev_ioctl(struct autofs_dev_ioctl *).
2603 +
2604 +All of the ioctls perform a copy of this structure from user space to
2605 +kernel space and return -EINVAL if the size parameter is smaller than
2606 +the structure size itself, -ENOMEM if the kernel memory allocation fails
2607 +or -EFAULT if the copy itself fails. Other checks include a version check
2608 +of the compiled in user space version against the module version and a
2609 +mismatch results in a -EINVAL return. If the size field is greater than
2610 +the structure size then a path is assumed to be present and is checked to
2611 +ensure it begins with a "/" and is NULL terminated, otherwise -EINVAL is
2612 +returned. Following these checks, for all ioctl commands except
2613 +AUTOFS_DEV_IOCTL_VERSION_CMD, AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and
2614 +AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD the ioctlfd is validated and if it is
2615 +not a valid descriptor or doesn't correspond to an autofs mount point
2616 +an error of -EBADF, -ENOTTY or -EINVAL (not an autofs descriptor) is
2617 +returned.
2618 +
2619 +
2620 +The ioctls
2621 +==========
2622 +
2623 +An example of an implementation which uses this interface can be seen
2624 +in autofs version 5.0.4 and later in file lib/dev-ioctl-lib.c of the
2625 +distribution tar available for download from kernel.org in directory
2626 +/pub/linux/daemons/autofs/v5.
2627 +
2628 +The device node ioctl operations implemented by this interface are:
2629 +
2630 +
2631 +AUTOFS_DEV_IOCTL_VERSION
2632 +------------------------
2633 +
2634 +Get the major and minor version of the autofs4 device ioctl kernel module
2635 +implementation. It requires an initialized struct autofs_dev_ioctl as an
2636 +input parameter and sets the version information in the passed in structure.
2637 +It returns 0 on success or the error -EINVAL if a version mismatch is
2638 +detected.
2639 +
2640 +
2641 +AUTOFS_DEV_IOCTL_PROTOVER_CMD and AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD
2642 +------------------------------------------------------------------
2643 +
2644 +Get the major and minor version of the autofs4 protocol version understood
2645 +by loaded module. This call requires an initialized struct autofs_dev_ioctl
2646 +with the ioctlfd field set to a valid autofs mount point descriptor
2647 +and sets the requested version number in structure field protover.version
2648 +and ptotosubver.sub_version respectively. These commands return 0 on
2649 +success or one of the negative error codes if validation fails.
2650 +
2651 +
2652 +AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD
2653 +------------------------------------------------------------------
2654 +
2655 +Obtain and release a file descriptor for an autofs managed mount point
2656 +path. The open call requires an initialized struct autofs_dev_ioctl with
2657 +the the path field set and the size field adjusted appropriately as well
2658 +as the openmount.devid field set to the device number of the autofs mount.
2659 +The device number of an autofs mounted filesystem can be obtained by using
2660 +the AUTOFS_DEV_IOCTL_ISMOUNTPOINT ioctl function by providing the path
2661 +and autofs mount type, as described below. The close call requires an
2662 +initialized struct autofs_dev_ioct with the ioctlfd field set to the
2663 +descriptor obtained from the open call. The release of the file descriptor
2664 +can also be done with close(2) so any open descriptors will also be
2665 +closed at process exit. The close call is included in the implemented
2666 +operations largely for completeness and to provide for a consistent
2667 +user space implementation.
2668 +
2669 +
2670 +AUTOFS_DEV_IOCTL_READY_CMD and AUTOFS_DEV_IOCTL_FAIL_CMD
2671 +--------------------------------------------------------
2672 +
2673 +Return mount and expire result status from user space to the kernel.
2674 +Both of these calls require an initialized struct autofs_dev_ioctl
2675 +with the ioctlfd field set to the descriptor obtained from the open
2676 +call and the ready.token or fail.token field set to the wait queue
2677 +token number, received by user space in the foregoing mount or expire
2678 +request. The fail.status field is set to the status to be returned when
2679 +sending a failure notification with AUTOFS_DEV_IOCTL_FAIL_CMD.
2680 +
2681 +
2682 +AUTOFS_DEV_IOCTL_SETPIPEFD_CMD
2683 +------------------------------
2684 +
2685 +Set the pipe file descriptor used for kernel communication to the daemon.
2686 +Normally this is set at mount time using an option but when reconnecting
2687 +to a existing mount we need to use this to tell the autofs mount about
2688 +the new kernel pipe descriptor. In order to protect mounts against
2689 +incorrectly setting the pipe descriptor we also require that the autofs
2690 +mount be catatonic (see next call).
2691 +
2692 +The call requires an initialized struct autofs_dev_ioctl with the
2693 +ioctlfd field set to the descriptor obtained from the open call and
2694 +the setpipefd.pipefd field set to descriptor of the pipe. On success
2695 +the call also sets the process group id used to identify the controlling
2696 +process (eg. the owning automount(8) daemon) to the process group of
2697 +the caller.
2698 +
2699 +
2700 +AUTOFS_DEV_IOCTL_CATATONIC_CMD
2701 +------------------------------
2702 +
2703 +Make the autofs mount point catatonic. The autofs mount will no longer
2704 +issue mount requests, the kernel communication pipe descriptor is released
2705 +and any remaining waits in the queue released.
2706 +
2707 +The call requires an initialized struct autofs_dev_ioctl with the
2708 +ioctlfd field set to the descriptor obtained from the open call.
2709 +
2710 +
2711 +AUTOFS_DEV_IOCTL_TIMEOUT_CMD
2712 +----------------------------
2713 +
2714 +Set the expire timeout for mounts withing an autofs mount point.
2715 +
2716 +The call requires an initialized struct autofs_dev_ioctl with the
2717 +ioctlfd field set to the descriptor obtained from the open call.
2718 +The timeout.timeout field is set to the desired timeout and this
2719 +field is set to the value of the value of the current timeout of
2720 +the mount upon successful completion.
2721 +
2722 +
2723 +AUTOFS_DEV_IOCTL_REQUESTER_CMD
2724 +------------------------------
2725 +
2726 +Return the uid and gid of the last process to successfully trigger a the
2727 +mount on the given path dentry.
2728 +
2729 +The call requires an initialized struct autofs_dev_ioctl with the path
2730 +field set to the mount point in question and the size field adjusted
2731 +appropriately as well as the ioctlfd field set to the descriptor obtained
2732 +from the open call. Upon return the struct fields requester.uid and
2733 +requester.gid contain the uid and gid respectively.
2734 +
2735 +When reconstructing an autofs mount tree with active mounts we need to
2736 +re-connect to mounts that may have used the original process uid and
2737 +gid (or string variations of them) for mount lookups within the map entry.
2738 +This call provides the ability to obtain this uid and gid so they may be
2739 +used by user space for the mount map lookups.
2740 +
2741 +
2742 +AUTOFS_DEV_IOCTL_EXPIRE_CMD
2743 +---------------------------
2744 +
2745 +Issue an expire request to the kernel for an autofs mount. Typically
2746 +this ioctl is called until no further expire candidates are found.
2747 +
2748 +The call requires an initialized struct autofs_dev_ioctl with the
2749 +ioctlfd field set to the descriptor obtained from the open call. In
2750 +addition an immediate expire, independent of the mount timeout, can be
2751 +requested by setting the expire.how field to 1. If no expire candidates
2752 +can be found the ioctl returns -1 with errno set to EAGAIN.
2753 +
2754 +This call causes the kernel module to check the mount corresponding
2755 +to the given ioctlfd for mounts that can be expired, issues an expire
2756 +request back to the daemon and waits for completion.
2757 +
2758 +AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD
2759 +------------------------------
2760 +
2761 +Checks if an autofs mount point is in use.
2762 +
2763 +The call requires an initialized struct autofs_dev_ioctl with the
2764 +ioctlfd field set to the descriptor obtained from the open call and
2765 +it returns the result in the askumount.may_umount field, 1 for busy
2766 +and 0 otherwise.
2767 +
2768 +
2769 +AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD
2770 +---------------------------------
2771 +
2772 +Check if the given path is a mountpoint.
2773 +
2774 +The call requires an initialized struct autofs_dev_ioctl. There are two
2775 +possible variations. Both use the path field set to the path of the mount
2776 +point to check and the size field must be adjusted appropriately. One uses
2777 +the ioctlfd field to identify a specific mount point to check while the
2778 +other variation uses the path and optionaly the ismountpoint.in.type
2779 +field set to an autofs mount type. The call returns 1 if this is a mount
2780 +point and sets the ismountpoint.out.devid field to the device number of
2781 +the mount and the ismountpoint.out.magic field to the relevant super
2782 +block magic number (described below) or 0 if it isn't a mountpoint. In
2783 +both cases the the device number (as returned by new_encode_dev()) is
2784 +returned in the ismountpoint.out.devid field.
2785 +
2786 +If supplied with a file descriptor we're looking for a specific mount,
2787 +not necessarily at the top of the mounted stack. In this case the path
2788 +the descriptor corresponds to is considered a mountpoint if it is itself
2789 +a mountpoint or contains a mount, such as a multi-mount without a root
2790 +mount. In this case we return 1 if the descriptor corresponds to a mount
2791 +point and and also returns the super magic of the covering mount if there
2792 +is one or 0 if it isn't a mountpoint.
2793 +
2794 +If a path is supplied (and the ioctlfd field is set to -1) then the path
2795 +is looked up and is checked to see if it is the root of a mount. If a
2796 +type is also given we are looking for a particular autofs mount and if
2797 +a match isn't found a fail is returned. If the the located path is the
2798 +root of a mount 1 is returned along with the super magic of the mount
2799 +or 0 otherwise.
2800 +
2801 --- linux-2.6.18.orig/fs/autofs4/Makefile
2802 +++ linux-2.6.18/fs/autofs4/Makefile
2803 @@ -4,4 +4,4 @@
2804
2805 obj-$(CONFIG_AUTOFS4_FS) += autofs4.o
2806
2807 -autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o
2808 +autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o dev-ioctl.o
2809 --- /dev/null
2810 +++ linux-2.6.18/fs/autofs4/dev-ioctl.c
2811 @@ -0,0 +1,867 @@
2812 +/*
2813 + * Copyright 2008 Red Hat, Inc. All rights reserved.
2814 + * Copyright 2008 Ian Kent <[email protected]>
2815 + *
2816 + * This file is part of the Linux kernel and is made available under
2817 + * the terms of the GNU General Public License, version 2, or at your
2818 + * option, any later version, incorporated herein by reference.
2819 + */
2820 +
2821 +#include <linux/module.h>
2822 +#include <linux/vmalloc.h>
2823 +#include <linux/miscdevice.h>
2824 +#include <linux/init.h>
2825 +#include <linux/wait.h>
2826 +#include <linux/namei.h>
2827 +#include <linux/fcntl.h>
2828 +#include <linux/file.h>
2829 +#include <linux/sched.h>
2830 +#include <linux/compat.h>
2831 +#include <linux/syscalls.h>
2832 +#include <linux/smp_lock.h>
2833 +#include <linux/magic.h>
2834 +#include <linux/dcache.h>
2835 +#include <linux/uaccess.h>
2836 +
2837 +#include "autofs_i.h"
2838 +
2839 +/*
2840 + * This module implements an interface for routing autofs ioctl control
2841 + * commands via a miscellaneous device file.
2842 + *
2843 + * The alternate interface is needed because we need to be able open
2844 + * an ioctl file descriptor on an autofs mount that may be covered by
2845 + * another mount. This situation arises when starting automount(8)
2846 + * or other user space daemon which uses direct mounts or offset
2847 + * mounts (used for autofs lazy mount/umount of nested mount trees),
2848 + * which have been left busy at at service shutdown.
2849 + */
2850 +
2851 +#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
2852 +
2853 +typedef int (*ioctl_fn)(struct file *,
2854 +struct autofs_sb_info *, struct autofs_dev_ioctl *);
2855 +
2856 +static int check_name(const char *name)
2857 +{
2858 + if (!strchr(name, '/'))
2859 + return -EINVAL;
2860 + return 0;
2861 +}
2862 +
2863 +/*
2864 + * Check a string doesn't overrun the chunk of
2865 + * memory we copied from user land.
2866 + */
2867 +static int invalid_str(char *str, void *end)
2868 +{
2869 + while ((void *) str <= end)
2870 + if (!*str++)
2871 + return 0;
2872 + return -EINVAL;
2873 +}
2874 +
2875 +/*
2876 + * Check that the user compiled against correct version of autofs
2877 + * misc device code.
2878 + *
2879 + * As well as checking the version compatibility this always copies
2880 + * the kernel interface version out.
2881 + */
2882 +static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
2883 +{
2884 + int err = 0;
2885 +
2886 + if ((AUTOFS_DEV_IOCTL_VERSION_MAJOR != param->ver_major) ||
2887 + (AUTOFS_DEV_IOCTL_VERSION_MINOR < param->ver_minor)) {
2888 + AUTOFS_WARN("ioctl control interface version mismatch: "
2889 + "kernel(%u.%u), user(%u.%u), cmd(%d)",
2890 + AUTOFS_DEV_IOCTL_VERSION_MAJOR,
2891 + AUTOFS_DEV_IOCTL_VERSION_MINOR,
2892 + param->ver_major, param->ver_minor, cmd);
2893 + err = -EINVAL;
2894 + }
2895 +
2896 + /* Fill in the kernel version. */
2897 + param->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
2898 + param->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
2899 +
2900 + return err;
2901 +}
2902 +
2903 +/*
2904 + * Copy parameter control struct, including a possible path allocated
2905 + * at the end of the struct.
2906 + */
2907 +static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in)
2908 +{
2909 + struct autofs_dev_ioctl tmp, *ads;
2910 +
2911 + if (copy_from_user(&tmp, in, sizeof(tmp)))
2912 + return ERR_PTR(-EFAULT);
2913 +
2914 + if (tmp.size < sizeof(tmp))
2915 + return ERR_PTR(-EINVAL);
2916 +
2917 + ads = kmalloc(tmp.size, GFP_KERNEL);
2918 + if (!ads)
2919 + return ERR_PTR(-ENOMEM);
2920 +
2921 + if (copy_from_user(ads, in, tmp.size)) {
2922 + kfree(ads);
2923 + return ERR_PTR(-EFAULT);
2924 + }
2925 +
2926 + return ads;
2927 +}
2928 +
2929 +static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)
2930 +{
2931 + kfree(param);
2932 + return;
2933 +}
2934 +
2935 +/*
2936 + * Check sanity of parameter control fields and if a path is present
2937 + * check that it is terminated and contains at least one "/".
2938 + */
2939 +static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
2940 +{
2941 + int err;
2942 +
2943 + if ((err = check_dev_ioctl_version(cmd, param))) {
2944 + AUTOFS_WARN("invalid device control module version "
2945 + "supplied for cmd(0x%08x)", cmd);
2946 + goto out;
2947 + }
2948 +
2949 + if (param->size > sizeof(*param)) {
2950 + err = invalid_str(param->path,
2951 + (void *) ((size_t) param + param->size));
2952 + if (err) {
2953 + AUTOFS_WARN(
2954 + "path string terminator missing for cmd(0x%08x)",
2955 + cmd);
2956 + goto out;
2957 + }
2958 +
2959 + err = check_name(param->path);
2960 + if (err) {
2961 + AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
2962 + cmd);
2963 + goto out;
2964 + }
2965 + }
2966 +
2967 + err = 0;
2968 +out:
2969 + return err;
2970 +}
2971 +
2972 +/*
2973 + * Get the autofs super block info struct from the file opened on
2974 + * the autofs mount point.
2975 + */
2976 +static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
2977 +{
2978 + struct autofs_sb_info *sbi = NULL;
2979 + struct inode *inode;
2980 +
2981 + if (f) {
2982 + inode = f->f_dentry->d_inode;
2983 + sbi = autofs4_sbi(inode->i_sb);
2984 + }
2985 + return sbi;
2986 +}
2987 +
2988 +/* Return autofs module protocol version */
2989 +static int autofs_dev_ioctl_protover(struct file *fp,
2990 + struct autofs_sb_info *sbi,
2991 + struct autofs_dev_ioctl *param)
2992 +{
2993 + param->protover.version = sbi->version;
2994 + return 0;
2995 +}
2996 +
2997 +/* Return autofs module protocol sub version */
2998 +static int autofs_dev_ioctl_protosubver(struct file *fp,
2999 + struct autofs_sb_info *sbi,
3000 + struct autofs_dev_ioctl *param)
3001 +{
3002 + param->protosubver.sub_version = sbi->sub_version;
3003 + return 0;
3004 +}
3005 +
3006 +/*
3007 + * Walk down the mount stack looking for an autofs mount that
3008 + * has the requested device number (aka. new_encode_dev(sb->s_dev).
3009 + */
3010 +static int autofs_dev_ioctl_find_super(struct nameidata *nd, dev_t devno)
3011 +{
3012 + struct dentry *dentry;
3013 + struct inode *inode;
3014 + struct super_block *sb;
3015 + dev_t s_dev;
3016 + unsigned int err;
3017 +
3018 + err = -ENOENT;
3019 +
3020 + /* Lookup the dentry name at the base of our mount point */
3021 + dentry = d_lookup(nd->dentry, &nd->last);
3022 + if (!dentry)
3023 + goto out;
3024 +
3025 + dput(nd->dentry);
3026 + nd->dentry = dentry;
3027 +
3028 + /* And follow the mount stack looking for our autofs mount */
3029 + while (follow_down(&nd->mnt, &nd->dentry)) {
3030 + inode = nd->dentry->d_inode;
3031 + if (!inode)
3032 + break;
3033 +
3034 + sb = inode->i_sb;
3035 + s_dev = new_encode_dev(sb->s_dev);
3036 + if (devno == s_dev) {
3037 + if (sb->s_magic == AUTOFS_SUPER_MAGIC) {
3038 + err = 0;
3039 + break;
3040 + }
3041 + }
3042 + }
3043 +out:
3044 + return err;
3045 +}
3046 +
3047 +/*
3048 + * Walk down the mount stack looking for an autofs mount that
3049 + * has the requested mount type (ie. indirect, direct or offset).
3050 + */
3051 +static int autofs_dev_ioctl_find_sbi_type(struct nameidata *nd, unsigned int type)
3052 +{
3053 + struct dentry *dentry;
3054 + struct autofs_info *ino;
3055 + unsigned int err;
3056 +
3057 + err = -ENOENT;
3058 +
3059 + /* Lookup the dentry name at the base of our mount point */
3060 + dentry = d_lookup(nd->dentry, &nd->last);
3061 + if (!dentry)
3062 + goto out;
3063 +
3064 + dput(nd->dentry);
3065 + nd->dentry = dentry;
3066 +
3067 + /* And follow the mount stack looking for our autofs mount */
3068 + while (follow_down(&nd->mnt, &nd->dentry)) {
3069 + ino = autofs4_dentry_ino(nd->dentry);
3070 + if (ino && ino->sbi->type & type) {
3071 + err = 0;
3072 + break;
3073 + }
3074 + }
3075 +out:
3076 + return err;
3077 +}
3078 +
3079 +static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file)
3080 +{
3081 + struct files_struct *files = current->files;
3082 + struct fdtable *fdt;
3083 +
3084 + spin_lock(&files->file_lock);
3085 + fdt = files_fdtable(files);
3086 + BUG_ON(fdt->fd[fd] != NULL);
3087 + rcu_assign_pointer(fdt->fd[fd], file);
3088 + FD_SET(fd, fdt->close_on_exec);
3089 + spin_unlock(&files->file_lock);
3090 +}
3091 +
3092 +
3093 +/*
3094 + * Open a file descriptor on the autofs mount point corresponding
3095 + * to the given path and device number (aka. new_encode_dev(sb->s_dev)).
3096 + */
3097 +static int autofs_dev_ioctl_open_mountpoint(const char *path, dev_t devid)
3098 +{
3099 + struct file *filp;
3100 + struct nameidata nd;
3101 + int err, fd;
3102 +
3103 + fd = get_unused_fd();
3104 + if (likely(fd >= 0)) {
3105 + /* Get nameidata of the parent directory */
3106 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3107 + if (err)
3108 + goto out;
3109 +
3110 + /*
3111 + * Search down, within the parent, looking for an
3112 + * autofs super block that has the device number
3113 + * corresponding to the autofs fs we want to open.
3114 + */
3115 + err = autofs_dev_ioctl_find_super(&nd, devid);
3116 + if (err) {
3117 + path_release(&nd);
3118 + goto out;
3119 + }
3120 +
3121 + filp = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
3122 + if (IS_ERR(filp)) {
3123 + err = PTR_ERR(filp);
3124 + goto out;
3125 + }
3126 +
3127 + autofs_dev_ioctl_fd_install(fd, filp);
3128 + }
3129 +
3130 + return fd;
3131 +
3132 +out:
3133 + put_unused_fd(fd);
3134 + return err;
3135 +}
3136 +
3137 +/* Open a file descriptor on an autofs mount point */
3138 +static int autofs_dev_ioctl_openmount(struct file *fp,
3139 + struct autofs_sb_info *sbi,
3140 + struct autofs_dev_ioctl *param)
3141 +{
3142 + const char *path;
3143 + dev_t devid;
3144 + int err, fd;
3145 +
3146 + /* param->path has already been checked */
3147 + if (!param->openmount.devid)
3148 + return -EINVAL;
3149 +
3150 + param->ioctlfd = -1;
3151 +
3152 + path = param->path;
3153 + devid = param->openmount.devid;
3154 +
3155 + err = 0;
3156 + fd = autofs_dev_ioctl_open_mountpoint(path, devid);
3157 + if (unlikely(fd < 0)) {
3158 + err = fd;
3159 + goto out;
3160 + }
3161 +
3162 + param->ioctlfd = fd;
3163 +out:
3164 + return err;
3165 +}
3166 +
3167 +/* Close file descriptor allocated above (user can also use close(2)). */
3168 +static int autofs_dev_ioctl_closemount(struct file *fp,
3169 + struct autofs_sb_info *sbi,
3170 + struct autofs_dev_ioctl *param)
3171 +{
3172 + return sys_close(param->ioctlfd);
3173 +}
3174 +
3175 +/*
3176 + * Send "ready" status for an existing wait (either a mount or an expire
3177 + * request).
3178 + */
3179 +static int autofs_dev_ioctl_ready(struct file *fp,
3180 + struct autofs_sb_info *sbi,
3181 + struct autofs_dev_ioctl *param)
3182 +{
3183 + autofs_wqt_t token;
3184 +
3185 + token = (autofs_wqt_t) param->ready.token;
3186 + return autofs4_wait_release(sbi, token, 0);
3187 +}
3188 +
3189 +/*
3190 + * Send "fail" status for an existing wait (either a mount or an expire
3191 + * request).
3192 + */
3193 +static int autofs_dev_ioctl_fail(struct file *fp,
3194 + struct autofs_sb_info *sbi,
3195 + struct autofs_dev_ioctl *param)
3196 +{
3197 + autofs_wqt_t token;
3198 + int status;
3199 +
3200 + token = (autofs_wqt_t) param->fail.token;
3201 + status = param->fail.status ? param->fail.status : -ENOENT;
3202 + return autofs4_wait_release(sbi, token, status);
3203 +}
3204 +
3205 +/*
3206 + * Set the pipe fd for kernel communication to the daemon.
3207 + *
3208 + * Normally this is set at mount using an option but if we
3209 + * are reconnecting to a busy mount then we need to use this
3210 + * to tell the autofs mount about the new kernel pipe fd. In
3211 + * order to protect mounts against incorrectly setting the
3212 + * pipefd we also require that the autofs mount be catatonic.
3213 + *
3214 + * This also sets the process group id used to identify the
3215 + * controlling process (eg. the owning automount(8) daemon).
3216 + */
3217 +static int autofs_dev_ioctl_setpipefd(struct file *fp,
3218 + struct autofs_sb_info *sbi,
3219 + struct autofs_dev_ioctl *param)
3220 +{
3221 + int pipefd;
3222 + int err = 0;
3223 +
3224 + if (param->setpipefd.pipefd == -1)
3225 + return -EINVAL;
3226 +
3227 + pipefd = param->setpipefd.pipefd;
3228 +
3229 + mutex_lock(&sbi->wq_mutex);
3230 + if (!sbi->catatonic) {
3231 + mutex_unlock(&sbi->wq_mutex);
3232 + return -EBUSY;
3233 + } else {
3234 + struct file *pipe = fget(pipefd);
3235 + if (!pipe->f_op || !pipe->f_op->write) {
3236 + err = -EPIPE;
3237 + fput(pipe);
3238 + goto out;
3239 + }
3240 + sbi->oz_pgrp = process_group(current);
3241 + sbi->pipefd = pipefd;
3242 + sbi->pipe = pipe;
3243 + sbi->catatonic = 0;
3244 + }
3245 +out:
3246 + mutex_unlock(&sbi->wq_mutex);
3247 + return err;
3248 +}
3249 +
3250 +/*
3251 + * Make the autofs mount point catatonic, no longer responsive to
3252 + * mount requests. Also closes the kernel pipe file descriptor.
3253 + */
3254 +static int autofs_dev_ioctl_catatonic(struct file *fp,
3255 + struct autofs_sb_info *sbi,
3256 + struct autofs_dev_ioctl *param)
3257 +{
3258 + autofs4_catatonic_mode(sbi);
3259 + return 0;
3260 +}
3261 +
3262 +/* Set the autofs mount timeout */
3263 +static int autofs_dev_ioctl_timeout(struct file *fp,
3264 + struct autofs_sb_info *sbi,
3265 + struct autofs_dev_ioctl *param)
3266 +{
3267 + unsigned long timeout;
3268 +
3269 + timeout = param->timeout.timeout;
3270 + param->timeout.timeout = sbi->exp_timeout / HZ;
3271 + sbi->exp_timeout = timeout * HZ;
3272 + return 0;
3273 +}
3274 +
3275 +/*
3276 + * Return the uid and gid of the last request for the mount
3277 + *
3278 + * When reconstructing an autofs mount tree with active mounts
3279 + * we need to re-connect to mounts that may have used the original
3280 + * process uid and gid (or string variations of them) for mount
3281 + * lookups within the map entry.
3282 + */
3283 +static int autofs_dev_ioctl_requester(struct file *fp,
3284 + struct autofs_sb_info *sbi,
3285 + struct autofs_dev_ioctl *param)
3286 +{
3287 + struct autofs_info *ino;
3288 + struct nameidata nd;
3289 + const char *path;
3290 + dev_t devid;
3291 + int err = -ENOENT;
3292 +
3293 + if (param->size <= sizeof(*param)) {
3294 + err = -EINVAL;
3295 + goto out;
3296 + }
3297 +
3298 + path = param->path;
3299 + devid = sbi->sb->s_dev;
3300 +
3301 + param->requester.uid = param->requester.gid = -1;
3302 +
3303 + /* Get nameidata of the parent directory */
3304 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3305 + if (err)
3306 + goto out;
3307 +
3308 + err = autofs_dev_ioctl_find_super(&nd, devid);
3309 + if (err)
3310 + goto out_release;
3311 +
3312 + ino = autofs4_dentry_ino(nd.dentry);
3313 + if (ino) {
3314 + err = 0;
3315 + autofs4_expire_wait(nd.dentry);
3316 + spin_lock(&sbi->fs_lock);
3317 + param->requester.uid = ino->uid;
3318 + param->requester.gid = ino->gid;
3319 + spin_unlock(&sbi->fs_lock);
3320 + }
3321 +
3322 +out_release:
3323 + path_release(&nd);
3324 +out:
3325 + return err;
3326 +}
3327 +
3328 +/*
3329 + * Call repeatedly until it returns -EAGAIN, meaning there's nothing
3330 + * more that can be done.
3331 + */
3332 +static int autofs_dev_ioctl_expire(struct file *fp,
3333 + struct autofs_sb_info *sbi,
3334 + struct autofs_dev_ioctl *param)
3335 +{
3336 + struct dentry *dentry;
3337 + struct vfsmount *mnt;
3338 + int err = -EAGAIN;
3339 + int how;
3340 +
3341 + how = param->expire.how;
3342 + mnt = fp->f_vfsmnt;
3343 +
3344 + if (autofs_type_trigger(sbi->type))
3345 + dentry = autofs4_expire_direct(sbi->sb, mnt, sbi, how);
3346 + else
3347 + dentry = autofs4_expire_indirect(sbi->sb, mnt, sbi, how);
3348 +
3349 + if (dentry) {
3350 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
3351 +
3352 + /*
3353 + * This is synchronous because it makes the daemon a
3354 + * little easier
3355 + */
3356 + err = autofs4_wait(sbi, dentry, NFY_EXPIRE);
3357 +
3358 + spin_lock(&sbi->fs_lock);
3359 + if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
3360 + ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
3361 + sbi->sb->s_root->d_mounted++;
3362 + }
3363 + ino->flags &= ~AUTOFS_INF_EXPIRING;
3364 + complete_all(&ino->expire_complete);
3365 + spin_unlock(&sbi->fs_lock);
3366 + dput(dentry);
3367 + }
3368 +
3369 + return err;
3370 +}
3371 +
3372 +/* Check if autofs mount point is in use */
3373 +static int autofs_dev_ioctl_askumount(struct file *fp,
3374 + struct autofs_sb_info *sbi,
3375 + struct autofs_dev_ioctl *param)
3376 +{
3377 + param->askumount.may_umount = 0;
3378 + if (may_umount(fp->f_vfsmnt))
3379 + param->askumount.may_umount = 1;
3380 + return 0;
3381 +}
3382 +
3383 +/*
3384 + * Check if the given path is a mountpoint.
3385 + *
3386 + * If we are supplied with the file descriptor of an autofs
3387 + * mount we're looking for a specific mount. In this case
3388 + * the path is considered a mountpoint if it is itself a
3389 + * mountpoint or contains a mount, such as a multi-mount
3390 + * without a root mount. In this case we return 1 if the
3391 + * path is a mount point and the super magic of the covering
3392 + * mount if there is one or 0 if it isn't a mountpoint.
3393 + *
3394 + * If we aren't supplied with a file descriptor then we
3395 + * lookup the nameidata of the path and check if it is the
3396 + * root of a mount. If a type is given we are looking for
3397 + * a particular autofs mount and if we don't find a match
3398 + * we return fail. If the located nameidata path is the
3399 + * root of a mount we return 1 along with the super magic
3400 + * of the mount or 0 otherwise.
3401 + *
3402 + * In both cases the the device number (as returned by
3403 + * new_encode_dev()) is also returned.
3404 + */
3405 +static int autofs_dev_ioctl_ismountpoint(struct file *fp,
3406 + struct autofs_sb_info *sbi,
3407 + struct autofs_dev_ioctl *param)
3408 +{
3409 + struct nameidata nd;
3410 + const char *path;
3411 + unsigned int type;
3412 + unsigned int devid, magic;
3413 + int err = -ENOENT;
3414 +
3415 + if (param->size <= sizeof(*param)) {
3416 + err = -EINVAL;
3417 + goto out;
3418 + }
3419 +
3420 + path = param->path;
3421 + type = param->ismountpoint.in.type;
3422 +
3423 + param->ismountpoint.out.devid = devid = 0;
3424 + param->ismountpoint.out.magic = magic = 0;
3425 +
3426 + if (!fp || param->ioctlfd == -1) {
3427 + if (autofs_type_any(type)) {
3428 + struct super_block *sb;
3429 +
3430 + err = path_lookup(path, LOOKUP_FOLLOW, &nd);
3431 + if (err)
3432 + goto out;
3433 +
3434 + sb = nd.dentry->d_sb;
3435 + devid = new_encode_dev(sb->s_dev);
3436 + } else {
3437 + struct autofs_info *ino;
3438 +
3439 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3440 + if (err)
3441 + goto out;
3442 +
3443 + err = autofs_dev_ioctl_find_sbi_type(&nd, type);
3444 + if (err)
3445 + goto out_release;
3446 +
3447 + ino = autofs4_dentry_ino(nd.dentry);
3448 + devid = autofs4_get_dev(ino->sbi);
3449 + }
3450 +
3451 + err = 0;
3452 + if (nd.dentry->d_inode &&
3453 + nd.mnt->mnt_root == nd.dentry) {
3454 + err = 1;
3455 + magic = nd.dentry->d_inode->i_sb->s_magic;
3456 + }
3457 + } else {
3458 + dev_t devid = new_encode_dev(sbi->sb->s_dev);
3459 +
3460 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3461 + if (err)
3462 + goto out;
3463 +
3464 + err = autofs_dev_ioctl_find_super(&nd, devid);
3465 + if (err)
3466 + goto out_release;
3467 +
3468 + devid = autofs4_get_dev(sbi);
3469 +
3470 + err = have_submounts(nd.dentry);
3471 +
3472 + if (nd.mnt->mnt_mountpoint != nd.mnt->mnt_root) {
3473 + if (follow_down(&nd.mnt, &nd.dentry)) {
3474 + struct inode *inode = nd.dentry->d_inode;
3475 + magic = inode->i_sb->s_magic;
3476 + }
3477 + }
3478 + }
3479 +
3480 + param->ismountpoint.out.devid = devid;
3481 + param->ismountpoint.out.magic = magic;
3482 +
3483 +out_release:
3484 + path_release(&nd);
3485 +out:
3486 + return err;
3487 +}
3488 +
3489 +/*
3490 + * Our range of ioctl numbers isn't 0 based so we need to shift
3491 + * the array index by _IOC_NR(AUTOFS_CTL_IOC_FIRST) for the table
3492 + * lookup.
3493 + */
3494 +#define cmd_idx(cmd) (cmd - _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST))
3495 +
3496 +static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
3497 +{
3498 + static struct {
3499 + int cmd;
3500 + ioctl_fn fn;
3501 + } _ioctls[] = {
3502 + {cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD), NULL},
3503 + {cmd_idx(AUTOFS_DEV_IOCTL_PROTOVER_CMD),
3504 + autofs_dev_ioctl_protover},
3505 + {cmd_idx(AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD),
3506 + autofs_dev_ioctl_protosubver},
3507 + {cmd_idx(AUTOFS_DEV_IOCTL_OPENMOUNT_CMD),
3508 + autofs_dev_ioctl_openmount},
3509 + {cmd_idx(AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD),
3510 + autofs_dev_ioctl_closemount},
3511 + {cmd_idx(AUTOFS_DEV_IOCTL_READY_CMD),
3512 + autofs_dev_ioctl_ready},
3513 + {cmd_idx(AUTOFS_DEV_IOCTL_FAIL_CMD),
3514 + autofs_dev_ioctl_fail},
3515 + {cmd_idx(AUTOFS_DEV_IOCTL_SETPIPEFD_CMD),
3516 + autofs_dev_ioctl_setpipefd},
3517 + {cmd_idx(AUTOFS_DEV_IOCTL_CATATONIC_CMD),
3518 + autofs_dev_ioctl_catatonic},
3519 + {cmd_idx(AUTOFS_DEV_IOCTL_TIMEOUT_CMD),
3520 + autofs_dev_ioctl_timeout},
3521 + {cmd_idx(AUTOFS_DEV_IOCTL_REQUESTER_CMD),
3522 + autofs_dev_ioctl_requester},
3523 + {cmd_idx(AUTOFS_DEV_IOCTL_EXPIRE_CMD),
3524 + autofs_dev_ioctl_expire},
3525 + {cmd_idx(AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD),
3526 + autofs_dev_ioctl_askumount},
3527 + {cmd_idx(AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD),
3528 + autofs_dev_ioctl_ismountpoint}
3529 + };
3530 + unsigned int idx = cmd_idx(cmd);
3531 +
3532 + return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx].fn;
3533 +}
3534 +
3535 +/* ioctl dispatcher */
3536 +static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __user *user)
3537 +{
3538 + struct autofs_dev_ioctl *param;
3539 + struct file *fp;
3540 + struct autofs_sb_info *sbi;
3541 + unsigned int cmd_first, cmd;
3542 + ioctl_fn fn = NULL;
3543 + int err = 0;
3544 +
3545 + /* only root can play with this */
3546 + if (!capable(CAP_SYS_ADMIN))
3547 + return -EPERM;
3548 +
3549 + cmd_first = _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST);
3550 + cmd = _IOC_NR(command);
3551 +
3552 + if (_IOC_TYPE(command) != _IOC_TYPE(AUTOFS_DEV_IOCTL_IOC_FIRST) ||
3553 + cmd - cmd_first >= AUTOFS_DEV_IOCTL_IOC_COUNT) {
3554 + return -ENOTTY;
3555 + }
3556 +
3557 + /* Copy the parameters into kernel space. */
3558 + param = copy_dev_ioctl(user);
3559 + if (IS_ERR(param))
3560 + return PTR_ERR(param);
3561 +
3562 + err = validate_dev_ioctl(command, param);
3563 + if (err)
3564 + goto out;
3565 +
3566 + /* The validate routine above always sets the version */
3567 + if (cmd == AUTOFS_DEV_IOCTL_VERSION_CMD)
3568 + goto done;
3569 +
3570 + fn = lookup_dev_ioctl(cmd);
3571 + if (!fn) {
3572 + AUTOFS_WARN("unknown command 0x%08x", command);
3573 + return -ENOTTY;
3574 + }
3575 +
3576 + fp = NULL;
3577 + sbi = NULL;
3578 +
3579 + /*
3580 + * For obvious reasons the openmount can't have a file
3581 + * descriptor yet. We don't take a reference to the
3582 + * file during close to allow for immediate release.
3583 + */
3584 + if (cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
3585 + cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
3586 + fp = fget(param->ioctlfd);
3587 + if (!fp) {
3588 + if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
3589 + goto cont;
3590 + err = -EBADF;
3591 + goto out;
3592 + }
3593 +
3594 + if (!fp->f_op) {
3595 + err = -ENOTTY;
3596 + fput(fp);
3597 + goto out;
3598 + }
3599 +
3600 + sbi = autofs_dev_ioctl_sbi(fp);
3601 + if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
3602 + err = -EINVAL;
3603 + fput(fp);
3604 + goto out;
3605 + }
3606 +
3607 + /*
3608 + * Admin needs to be able to set the mount catatonic in
3609 + * order to be able to perform the re-open.
3610 + */
3611 + if (!autofs4_oz_mode(sbi) &&
3612 + cmd != AUTOFS_DEV_IOCTL_CATATONIC_CMD) {
3613 + err = -EACCES;
3614 + fput(fp);
3615 + goto out;
3616 + }
3617 + }
3618 +cont:
3619 + err = fn(fp, sbi, param);
3620 +
3621 + if (fp)
3622 + fput(fp);
3623 +done:
3624 + if (err >= 0 && copy_to_user(user, param, AUTOFS_DEV_IOCTL_SIZE))
3625 + err = -EFAULT;
3626 +out:
3627 + free_dev_ioctl(param);
3628 + return err;
3629 +}
3630 +
3631 +static long autofs_dev_ioctl(struct file *file, uint command, ulong u)
3632 +{
3633 + int err;
3634 + err = _autofs_dev_ioctl(command, (struct autofs_dev_ioctl __user *) u);
3635 + return (long) err;
3636 +}
3637 +
3638 +#ifdef CONFIG_COMPAT
3639 +static long autofs_dev_ioctl_compat(struct file *file, uint command, ulong u)
3640 +{
3641 + return (long) autofs_dev_ioctl(file, command, (ulong) compat_ptr(u));
3642 +}
3643 +#else
3644 +#define autofs_dev_ioctl_compat NULL
3645 +#endif
3646 +
3647 +static const struct file_operations _dev_ioctl_fops = {
3648 + .unlocked_ioctl = autofs_dev_ioctl,
3649 + .compat_ioctl = autofs_dev_ioctl_compat,
3650 + .owner = THIS_MODULE,
3651 +};
3652 +
3653 +static struct miscdevice _autofs_dev_ioctl_misc = {
3654 + .minor = MISC_DYNAMIC_MINOR,
3655 + .name = AUTOFS_DEVICE_NAME,
3656 + .fops = &_dev_ioctl_fops
3657 +};
3658 +
3659 +/* Register/deregister misc character device */
3660 +int autofs_dev_ioctl_init(void)
3661 +{
3662 + int r;
3663 +
3664 + r = misc_register(&_autofs_dev_ioctl_misc);
3665 + if (r) {
3666 + AUTOFS_ERROR("misc_register failed for control device");
3667 + return r;
3668 + }
3669 +
3670 + return 0;
3671 +}
3672 +
3673 +void autofs_dev_ioctl_exit(void)
3674 +{
3675 + misc_deregister(&_autofs_dev_ioctl_misc);
3676 + return;
3677 +}
3678 +
3679 --- /dev/null
3680 +++ linux-2.6.18/include/linux/auto_dev-ioctl.h
3681 @@ -0,0 +1,229 @@
3682 +/*
3683 + * Copyright 2008 Red Hat, Inc. All rights reserved.
3684 + * Copyright 2008 Ian Kent <[email protected]>
3685 + *
3686 + * This file is part of the Linux kernel and is made available under
3687 + * the terms of the GNU General Public License, version 2, or at your
3688 + * option, any later version, incorporated herein by reference.
3689 + */
3690 +
3691 +#ifndef _LINUX_AUTO_DEV_IOCTL_H
3692 +#define _LINUX_AUTO_DEV_IOCTL_H
3693 +
3694 +#include <linux/auto_fs.h>
3695 +
3696 +#ifdef __KERNEL__
3697 +#include <linux/string.h>
3698 +#else
3699 +#include <string.h>
3700 +#endif /* __KERNEL__ */
3701 +
3702 +#define AUTOFS_DEVICE_NAME "autofs"
3703 +
3704 +#define AUTOFS_DEV_IOCTL_VERSION_MAJOR 1
3705 +#define AUTOFS_DEV_IOCTL_VERSION_MINOR 0
3706 +
3707 +#define AUTOFS_DEVID_LEN 16
3708 +
3709 +#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
3710 +
3711 +/*
3712 + * An ioctl interface for autofs mount point control.
3713 + */
3714 +
3715 +struct args_protover {
3716 + __u32 version;
3717 +};
3718 +
3719 +struct args_protosubver {
3720 + __u32 sub_version;
3721 +};
3722 +
3723 +struct args_openmount {
3724 + __u32 devid;
3725 +};
3726 +
3727 +struct args_ready {
3728 + __u32 token;
3729 +};
3730 +
3731 +struct args_fail {
3732 + __u32 token;
3733 + __s32 status;
3734 +};
3735 +
3736 +struct args_setpipefd {
3737 + __s32 pipefd;
3738 +};
3739 +
3740 +struct args_timeout {
3741 + __u64 timeout;
3742 +};
3743 +
3744 +struct args_requester {
3745 + __u32 uid;
3746 + __u32 gid;
3747 +};
3748 +
3749 +struct args_expire {
3750 + __u32 how;
3751 +};
3752 +
3753 +struct args_askumount {
3754 + __u32 may_umount;
3755 +};
3756 +
3757 +struct args_ismountpoint {
3758 + union {
3759 + struct args_in {
3760 + __u32 type;
3761 + } in;
3762 + struct args_out {
3763 + __u32 devid;
3764 + __u32 magic;
3765 + } out;
3766 + };
3767 +};
3768 +
3769 +/*
3770 + * All the ioctls use this structure.
3771 + * When sending a path size must account for the total length
3772 + * of the chunk of memory otherwise is is the size of the
3773 + * structure.
3774 + */
3775 +
3776 +struct autofs_dev_ioctl {
3777 + __u32 ver_major;
3778 + __u32 ver_minor;
3779 + __u32 size; /* total size of data passed in
3780 + * including this struct */
3781 + __s32 ioctlfd; /* automount command fd */
3782 +
3783 + /* Command parameters */
3784 +
3785 + union {
3786 + struct args_protover protover;
3787 + struct args_protosubver protosubver;
3788 + struct args_openmount openmount;
3789 + struct args_ready ready;
3790 + struct args_fail fail;
3791 + struct args_setpipefd setpipefd;
3792 + struct args_timeout timeout;
3793 + struct args_requester requester;
3794 + struct args_expire expire;
3795 + struct args_askumount askumount;
3796 + struct args_ismountpoint ismountpoint;
3797 + };
3798 +
3799 + char path[0];
3800 +};
3801 +
3802 +static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)
3803 +{
3804 + memset(in, 0, sizeof(struct autofs_dev_ioctl));
3805 + in->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
3806 + in->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
3807 + in->size = sizeof(struct autofs_dev_ioctl);
3808 + in->ioctlfd = -1;
3809 + return;
3810 +}
3811 +
3812 +/*
3813 + * If you change this make sure you make the corresponding change
3814 + * to autofs-dev-ioctl.c:lookup_ioctl()
3815 + */
3816 +enum {
3817 + /* Get various version info */
3818 + AUTOFS_DEV_IOCTL_VERSION_CMD = 0x71,
3819 + AUTOFS_DEV_IOCTL_PROTOVER_CMD,
3820 + AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD,
3821 +
3822 + /* Open mount ioctl fd */
3823 + AUTOFS_DEV_IOCTL_OPENMOUNT_CMD,
3824 +
3825 + /* Close mount ioctl fd */
3826 + AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD,
3827 +
3828 + /* Mount/expire status returns */
3829 + AUTOFS_DEV_IOCTL_READY_CMD,
3830 + AUTOFS_DEV_IOCTL_FAIL_CMD,
3831 +
3832 + /* Activate/deactivate autofs mount */
3833 + AUTOFS_DEV_IOCTL_SETPIPEFD_CMD,
3834 + AUTOFS_DEV_IOCTL_CATATONIC_CMD,
3835 +
3836 + /* Expiry timeout */
3837 + AUTOFS_DEV_IOCTL_TIMEOUT_CMD,
3838 +
3839 + /* Get mount last requesting uid and gid */
3840 + AUTOFS_DEV_IOCTL_REQUESTER_CMD,
3841 +
3842 + /* Check for eligible expire candidates */
3843 + AUTOFS_DEV_IOCTL_EXPIRE_CMD,
3844 +
3845 + /* Request busy status */
3846 + AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD,
3847 +
3848 + /* Check if path is a mountpoint */
3849 + AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD,
3850 +};
3851 +
3852 +#define AUTOFS_IOCTL 0x93
3853 +
3854 +#define AUTOFS_DEV_IOCTL_VERSION \
3855 + _IOWR(AUTOFS_IOCTL, \
3856 + AUTOFS_DEV_IOCTL_VERSION_CMD, struct autofs_dev_ioctl)
3857 +
3858 +#define AUTOFS_DEV_IOCTL_PROTOVER \
3859 + _IOWR(AUTOFS_IOCTL, \
3860 + AUTOFS_DEV_IOCTL_PROTOVER_CMD, struct autofs_dev_ioctl)
3861 +
3862 +#define AUTOFS_DEV_IOCTL_PROTOSUBVER \
3863 + _IOWR(AUTOFS_IOCTL, \
3864 + AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD, struct autofs_dev_ioctl)
3865 +
3866 +#define AUTOFS_DEV_IOCTL_OPENMOUNT \
3867 + _IOWR(AUTOFS_IOCTL, \
3868 + AUTOFS_DEV_IOCTL_OPENMOUNT_CMD, struct autofs_dev_ioctl)
3869 +
3870 +#define AUTOFS_DEV_IOCTL_CLOSEMOUNT \
3871 + _IOWR(AUTOFS_IOCTL, \
3872 + AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD, struct autofs_dev_ioctl)
3873 +
3874 +#define AUTOFS_DEV_IOCTL_READY \
3875 + _IOWR(AUTOFS_IOCTL, \
3876 + AUTOFS_DEV_IOCTL_READY_CMD, struct autofs_dev_ioctl)
3877 +
3878 +#define AUTOFS_DEV_IOCTL_FAIL \
3879 + _IOWR(AUTOFS_IOCTL, \
3880 + AUTOFS_DEV_IOCTL_FAIL_CMD, struct autofs_dev_ioctl)
3881 +
3882 +#define AUTOFS_DEV_IOCTL_SETPIPEFD \
3883 + _IOWR(AUTOFS_IOCTL, \
3884 + AUTOFS_DEV_IOCTL_SETPIPEFD_CMD, struct autofs_dev_ioctl)
3885 +
3886 +#define AUTOFS_DEV_IOCTL_CATATONIC \
3887 + _IOWR(AUTOFS_IOCTL, \
3888 + AUTOFS_DEV_IOCTL_CATATONIC_CMD, struct autofs_dev_ioctl)
3889 +
3890 +#define AUTOFS_DEV_IOCTL_TIMEOUT \
3891 + _IOWR(AUTOFS_IOCTL, \
3892 + AUTOFS_DEV_IOCTL_TIMEOUT_CMD, struct autofs_dev_ioctl)
3893 +
3894 +#define AUTOFS_DEV_IOCTL_REQUESTER \
3895 + _IOWR(AUTOFS_IOCTL, \
3896 + AUTOFS_DEV_IOCTL_REQUESTER_CMD, struct autofs_dev_ioctl)
3897 +
3898 +#define AUTOFS_DEV_IOCTL_EXPIRE \
3899 + _IOWR(AUTOFS_IOCTL, \
3900 + AUTOFS_DEV_IOCTL_EXPIRE_CMD, struct autofs_dev_ioctl)
3901 +
3902 +#define AUTOFS_DEV_IOCTL_ASKUMOUNT \
3903 + _IOWR(AUTOFS_IOCTL, \
3904 + AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD, struct autofs_dev_ioctl)
3905 +
3906 +#define AUTOFS_DEV_IOCTL_ISMOUNTPOINT \
3907 + _IOWR(AUTOFS_IOCTL, \
3908 + AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD, struct autofs_dev_ioctl)
3909 +
3910 +#endif /* _LINUX_AUTO_DEV_IOCTL_H */
3911 --- linux-2.6.18.orig/include/linux/auto_fs.h
3912 +++ linux-2.6.18/include/linux/auto_fs.h
3913 @@ -17,11 +17,13 @@
3914 #ifdef __KERNEL__
3915 #include <linux/fs.h>
3916 #include <linux/limits.h>
3917 +#include <linux/types.h>
3918 +#include <linux/ioctl.h>
3919 +#else
3920 #include <asm/types.h>
3921 +#include <sys/ioctl.h>
3922 #endif /* __KERNEL__ */
3923
3924 -#include <linux/ioctl.h>
3925 -
3926 /* This file describes autofs v3 */
3927 #define AUTOFS_PROTO_VERSION 3
3928