Debian Codegraph @

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

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