Debian Codegraph @

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