Debian Codegraph @

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

raw
1 --- linux-2.6.25.orig/fs/autofs4/waitq.c
2 +++ linux-2.6.25/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.25.orig/fs/autofs4/expire.c
478 +++ linux-2.6.25/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.25.orig/fs/autofs4/root.c
793 +++ linux-2.6.25/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,51 +177,63 @@ 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->path.mnt, &nd->path.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->path.mnt,
1130 - &nd->path.dentry)) {
1131 - status = -ENOENT;
1132 - goto out_error;
1133 - }
1134 - }
1135 -
1136 - goto done;
1137 + goto follow;
1138 }
1139 spin_unlock(&dcache_lock);
1140 +follow:
1141 + /*
1142 + * If there is no root mount it must be an autofs
1143 + * multi-mount with no root offset so we don't need
1144 + * to follow it.
1145 + */
1146 + if (d_mountpoint(dentry)) {
1147 + if (!autofs4_follow_mount(&nd->path.mnt,
1148 + &nd->path.dentry)) {
1149 + status = -ENOENT;
1150 + goto out_error;
1151 + }
1152 + }
1153
1154 done:
1155 return NULL;
1156 @@ -402,12 +258,23 @@ static int autofs4_revalidate(struct den
1157 int status = 1;
1158
1159 /* Pending dentry */
1160 + spin_lock(&sbi->fs_lock);
1161 if (autofs4_ispending(dentry)) {
1162 /* The daemon never causes a mount to trigger */
1163 + spin_unlock(&sbi->fs_lock);
1164 +
1165 if (oz_mode)
1166 return 1;
1167
1168 /*
1169 + * If the directory has gone away due to an expire
1170 + * we have been called as ->d_revalidate() and so
1171 + * we need to return false and proceed to ->lookup().
1172 + */
1173 + if (autofs4_expire_wait(dentry) == -EAGAIN)
1174 + return 0;
1175 +
1176 + /*
1177 * A zero status is success otherwise we have a
1178 * negative error code.
1179 */
1180 @@ -415,17 +282,9 @@ static int autofs4_revalidate(struct den
1181 if (status == 0)
1182 return 1;
1183
1184 - /*
1185 - * A status of EAGAIN here means that the dentry has gone
1186 - * away while waiting for an expire to complete. If we are
1187 - * racing with expire lookup will wait for it so this must
1188 - * be a revalidate and we need to send it to lookup.
1189 - */
1190 - if (status == -EAGAIN)
1191 - return 0;
1192 -
1193 return status;
1194 }
1195 + spin_unlock(&sbi->fs_lock);
1196
1197 /* Negative dentry.. invalidate if "old" */
1198 if (dentry->d_inode == NULL)
1199 @@ -439,6 +298,7 @@ static int autofs4_revalidate(struct den
1200 DPRINTK("dentry=%p %.*s, emptydir",
1201 dentry, dentry->d_name.len, dentry->d_name.name);
1202 spin_unlock(&dcache_lock);
1203 +
1204 /* The daemon never causes a mount to trigger */
1205 if (oz_mode)
1206 return 1;
1207 @@ -471,10 +331,12 @@ void autofs4_dentry_release(struct dentr
1208 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
1209
1210 if (sbi) {
1211 - spin_lock(&sbi->rehash_lock);
1212 - if (!list_empty(&inf->rehash))
1213 - list_del(&inf->rehash);
1214 - spin_unlock(&sbi->rehash_lock);
1215 + spin_lock(&sbi->lookup_lock);
1216 + if (!list_empty(&inf->active))
1217 + list_del(&inf->active);
1218 + if (!list_empty(&inf->expiring))
1219 + list_del(&inf->expiring);
1220 + spin_unlock(&sbi->lookup_lock);
1221 }
1222
1223 inf->dentry = NULL;
1224 @@ -496,7 +358,7 @@ static struct dentry_operations autofs4_
1225 .d_release = autofs4_dentry_release,
1226 };
1227
1228 -static struct dentry *autofs4_lookup_unhashed(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1229 +static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1230 {
1231 unsigned int len = name->len;
1232 unsigned int hash = name->hash;
1233 @@ -504,14 +366,66 @@ static struct dentry *autofs4_lookup_unh
1234 struct list_head *p, *head;
1235
1236 spin_lock(&dcache_lock);
1237 - spin_lock(&sbi->rehash_lock);
1238 - head = &sbi->rehash_list;
1239 + spin_lock(&sbi->lookup_lock);
1240 + head = &sbi->active_list;
1241 list_for_each(p, head) {
1242 struct autofs_info *ino;
1243 struct dentry *dentry;
1244 struct qstr *qstr;
1245
1246 - ino = list_entry(p, struct autofs_info, rehash);
1247 + ino = list_entry(p, struct autofs_info, active);
1248 + dentry = ino->dentry;
1249 +
1250 + spin_lock(&dentry->d_lock);
1251 +
1252 + /* Already gone? */
1253 + if (atomic_read(&dentry->d_count) == 0)
1254 + goto next;
1255 +
1256 + qstr = &dentry->d_name;
1257 +
1258 + if (dentry->d_name.hash != hash)
1259 + goto next;
1260 + if (dentry->d_parent != parent)
1261 + goto next;
1262 +
1263 + if (qstr->len != len)
1264 + goto next;
1265 + if (memcmp(qstr->name, str, len))
1266 + goto next;
1267 +
1268 + if (d_unhashed(dentry)) {
1269 + dget(dentry);
1270 + spin_unlock(&dentry->d_lock);
1271 + spin_unlock(&sbi->lookup_lock);
1272 + spin_unlock(&dcache_lock);
1273 + return dentry;
1274 + }
1275 +next:
1276 + spin_unlock(&dentry->d_lock);
1277 + }
1278 + spin_unlock(&sbi->lookup_lock);
1279 + spin_unlock(&dcache_lock);
1280 +
1281 + return NULL;
1282 +}
1283 +
1284 +static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
1285 +{
1286 + unsigned int len = name->len;
1287 + unsigned int hash = name->hash;
1288 + const unsigned char *str = name->name;
1289 + struct list_head *p, *head;
1290 +
1291 + spin_lock(&dcache_lock);
1292 + spin_lock(&sbi->lookup_lock);
1293 + head = &sbi->expiring_list;
1294 + list_for_each(p, head) {
1295 + struct autofs_info *ino;
1296 + struct dentry *dentry;
1297 + struct qstr *qstr;
1298 +
1299 + ino = list_entry(p, struct autofs_info, expiring);
1300 dentry = ino->dentry;
1301
1302 spin_lock(&dentry->d_lock);
1303 @@ -533,33 +447,16 @@ static struct dentry *autofs4_lookup_unh
1304 goto next;
1305
1306 if (d_unhashed(dentry)) {
1307 - struct autofs_info *ino = autofs4_dentry_ino(dentry);
1308 - struct inode *inode = dentry->d_inode;
1309 -
1310 - list_del_init(&ino->rehash);
1311 dget(dentry);
1312 - /*
1313 - * Make the rehashed dentry negative so the VFS
1314 - * behaves as it should.
1315 - */
1316 - if (inode) {
1317 - dentry->d_inode = NULL;
1318 - list_del_init(&dentry->d_alias);
1319 - spin_unlock(&dentry->d_lock);
1320 - spin_unlock(&sbi->rehash_lock);
1321 - spin_unlock(&dcache_lock);
1322 - iput(inode);
1323 - return dentry;
1324 - }
1325 spin_unlock(&dentry->d_lock);
1326 - spin_unlock(&sbi->rehash_lock);
1327 + spin_unlock(&sbi->lookup_lock);
1328 spin_unlock(&dcache_lock);
1329 return dentry;
1330 }
1331 next:
1332 spin_unlock(&dentry->d_lock);
1333 }
1334 - spin_unlock(&sbi->rehash_lock);
1335 + spin_unlock(&sbi->lookup_lock);
1336 spin_unlock(&dcache_lock);
1337
1338 return NULL;
1339 @@ -569,7 +466,8 @@ next:
1340 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1341 {
1342 struct autofs_sb_info *sbi;
1343 - struct dentry *unhashed;
1344 + struct autofs_info *ino;
1345 + struct dentry *expiring, *unhashed;
1346 int oz_mode;
1347
1348 DPRINTK("name = %.*s",
1349 @@ -585,8 +483,10 @@ static struct dentry *autofs4_lookup(str
1350 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
1351 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
1352
1353 - unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name);
1354 - if (!unhashed) {
1355 + unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
1356 + if (unhashed)
1357 + dentry = unhashed;
1358 + else {
1359 /*
1360 * Mark the dentry incomplete but don't hash it. We do this
1361 * to serialize our inode creation operations (symlink and
1362 @@ -600,38 +500,50 @@ static struct dentry *autofs4_lookup(str
1363 */
1364 dentry->d_op = &autofs4_root_dentry_operations;
1365
1366 - dentry->d_fsdata = NULL;
1367 - d_instantiate(dentry, NULL);
1368 - } else {
1369 - struct autofs_info *ino = autofs4_dentry_ino(unhashed);
1370 - DPRINTK("rehash %p with %p", dentry, unhashed);
1371 /*
1372 - * If we are racing with expire the request might not
1373 - * be quite complete but the directory has been removed
1374 - * so it must have been successful, so just wait for it.
1375 - * We need to ensure the AUTOFS_INF_EXPIRING flag is clear
1376 - * before continuing as revalidate may fail when calling
1377 - * try_to_fill_dentry (returning EAGAIN) if we don't.
1378 + * And we need to ensure that the same dentry is used for
1379 + * all following lookup calls until it is hashed so that
1380 + * the dentry flags are persistent throughout the request.
1381 */
1382 - while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
1383 - DPRINTK("wait for incomplete expire %p name=%.*s",
1384 - unhashed, unhashed->d_name.len,
1385 - unhashed->d_name.name);
1386 - autofs4_wait(sbi, unhashed, NFY_NONE);
1387 - DPRINTK("request completed");
1388 - }
1389 - dentry = unhashed;
1390 + ino = autofs4_init_ino(NULL, sbi, 0555);
1391 + if (!ino)
1392 + return ERR_PTR(-ENOMEM);
1393 +
1394 + dentry->d_fsdata = ino;
1395 + ino->dentry = dentry;
1396 +
1397 + spin_lock(&sbi->lookup_lock);
1398 + list_add(&ino->active, &sbi->active_list);
1399 + spin_unlock(&sbi->lookup_lock);
1400 +
1401 + d_instantiate(dentry, NULL);
1402 }
1403
1404 if (!oz_mode) {
1405 + mutex_unlock(&dir->i_mutex);
1406 + expiring = autofs4_lookup_expiring(sbi,
1407 + dentry->d_parent,
1408 + &dentry->d_name);
1409 + if (expiring) {
1410 + /*
1411 + * If we are racing with expire the request might not
1412 + * be quite complete but the directory has been removed
1413 + * so it must have been successful, so just wait for it.
1414 + */
1415 + ino = autofs4_dentry_ino(expiring);
1416 + autofs4_expire_wait(expiring);
1417 + spin_lock(&sbi->lookup_lock);
1418 + if (!list_empty(&ino->expiring))
1419 + list_del_init(&ino->expiring);
1420 + spin_unlock(&sbi->lookup_lock);
1421 + dput(expiring);
1422 + }
1423 +
1424 spin_lock(&dentry->d_lock);
1425 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
1426 spin_unlock(&dentry->d_lock);
1427 - }
1428 -
1429 - if (dentry->d_op && dentry->d_op->d_revalidate) {
1430 - mutex_unlock(&dir->i_mutex);
1431 - (dentry->d_op->d_revalidate)(dentry, nd);
1432 + if (dentry->d_op && dentry->d_op->d_revalidate)
1433 + (dentry->d_op->d_revalidate)(dentry, nd);
1434 mutex_lock(&dir->i_mutex);
1435 }
1436
1437 @@ -651,9 +563,11 @@ static struct dentry *autofs4_lookup(str
1438 return ERR_PTR(-ERESTARTNOINTR);
1439 }
1440 }
1441 - spin_lock(&dentry->d_lock);
1442 - dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1443 - spin_unlock(&dentry->d_lock);
1444 + if (!oz_mode) {
1445 + spin_lock(&dentry->d_lock);
1446 + dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
1447 + spin_unlock(&dentry->d_lock);
1448 + }
1449 }
1450
1451 /*
1452 @@ -684,7 +598,7 @@ static struct dentry *autofs4_lookup(str
1453 }
1454
1455 if (unhashed)
1456 - return dentry;
1457 + return unhashed;
1458
1459 return NULL;
1460 }
1461 @@ -706,20 +620,31 @@ static int autofs4_dir_symlink(struct in
1462 return -EACCES;
1463
1464 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
1465 - if (ino == NULL)
1466 - return -ENOSPC;
1467 + if (!ino)
1468 + return -ENOMEM;
1469
1470 - ino->size = strlen(symname);
1471 - ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
1472 + spin_lock(&sbi->lookup_lock);
1473 + if (!list_empty(&ino->active))
1474 + list_del_init(&ino->active);
1475 + spin_unlock(&sbi->lookup_lock);
1476
1477 - if (cp == NULL) {
1478 - kfree(ino);
1479 - return -ENOSPC;
1480 + ino->size = strlen(symname);
1481 + cp = kmalloc(ino->size + 1, GFP_KERNEL);
1482 + if (!cp) {
1483 + if (!dentry->d_fsdata)
1484 + kfree(ino);
1485 + return -ENOMEM;
1486 }
1487
1488 strcpy(cp, symname);
1489
1490 inode = autofs4_get_inode(dir->i_sb, ino);
1491 + if (!inode) {
1492 + kfree(cp);
1493 + if (!dentry->d_fsdata)
1494 + kfree(ino);
1495 + return -ENOMEM;
1496 + }
1497 d_add(dentry, inode);
1498
1499 if (dir == dir->i_sb->s_root->d_inode)
1500 @@ -735,6 +660,7 @@ static int autofs4_dir_symlink(struct in
1501 atomic_inc(&p_ino->count);
1502 ino->inode = inode;
1503
1504 + ino->u.symlink = cp;
1505 dir->i_mtime = CURRENT_TIME;
1506
1507 return 0;
1508 @@ -747,9 +673,8 @@ static int autofs4_dir_symlink(struct in
1509 * that the file no longer exists. However, doing that means that the
1510 * VFS layer can turn the dentry into a negative dentry. We don't want
1511 * this, because the unlink is probably the result of an expire.
1512 - * We simply d_drop it and add it to a rehash candidates list in the
1513 - * super block, which allows the dentry lookup to reuse it retaining
1514 - * the flags, such as expire in progress, in case we're racing with expire.
1515 + * We simply d_drop it and add it to a expiring list in the super block,
1516 + * which allows the dentry lookup to check for an incomplete expire.
1517 *
1518 * If a process is blocked on the dentry waiting for the expire to finish,
1519 * it will invalidate the dentry and try to mount with a new one.
1520 @@ -779,9 +704,10 @@ static int autofs4_dir_unlink(struct ino
1521 dir->i_mtime = CURRENT_TIME;
1522
1523 spin_lock(&dcache_lock);
1524 - spin_lock(&sbi->rehash_lock);
1525 - list_add(&ino->rehash, &sbi->rehash_list);
1526 - spin_unlock(&sbi->rehash_lock);
1527 + spin_lock(&sbi->lookup_lock);
1528 + if (list_empty(&ino->expiring))
1529 + list_add(&ino->expiring, &sbi->expiring_list);
1530 + spin_unlock(&sbi->lookup_lock);
1531 spin_lock(&dentry->d_lock);
1532 __d_drop(dentry);
1533 spin_unlock(&dentry->d_lock);
1534 @@ -807,9 +733,10 @@ static int autofs4_dir_rmdir(struct inod
1535 spin_unlock(&dcache_lock);
1536 return -ENOTEMPTY;
1537 }
1538 - spin_lock(&sbi->rehash_lock);
1539 - list_add(&ino->rehash, &sbi->rehash_list);
1540 - spin_unlock(&sbi->rehash_lock);
1541 + spin_lock(&sbi->lookup_lock);
1542 + if (list_empty(&ino->expiring))
1543 + list_add(&ino->expiring, &sbi->expiring_list);
1544 + spin_unlock(&sbi->lookup_lock);
1545 spin_lock(&dentry->d_lock);
1546 __d_drop(dentry);
1547 spin_unlock(&dentry->d_lock);
1548 @@ -844,10 +771,20 @@ static int autofs4_dir_mkdir(struct inod
1549 dentry, dentry->d_name.len, dentry->d_name.name);
1550
1551 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
1552 - if (ino == NULL)
1553 - return -ENOSPC;
1554 + if (!ino)
1555 + return -ENOMEM;
1556 +
1557 + spin_lock(&sbi->lookup_lock);
1558 + if (!list_empty(&ino->active))
1559 + list_del_init(&ino->active);
1560 + spin_unlock(&sbi->lookup_lock);
1561
1562 inode = autofs4_get_inode(dir->i_sb, ino);
1563 + if (!inode) {
1564 + if (!dentry->d_fsdata)
1565 + kfree(ino);
1566 + return -ENOMEM;
1567 + }
1568 d_add(dentry, inode);
1569
1570 if (dir == dir->i_sb->s_root->d_inode)
1571 @@ -900,44 +837,6 @@ static inline int autofs4_get_protosubve
1572 }
1573
1574 /*
1575 - * Tells the daemon whether we need to reghost or not. Also, clears
1576 - * the reghost_needed flag.
1577 - */
1578 -static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
1579 -{
1580 - int status;
1581 -
1582 - DPRINTK("returning %d", sbi->needs_reghost);
1583 -
1584 - status = put_user(sbi->needs_reghost, p);
1585 - if (status)
1586 - return status;
1587 -
1588 - sbi->needs_reghost = 0;
1589 - return 0;
1590 -}
1591 -
1592 -/*
1593 - * Enable / Disable reghosting ioctl() operation
1594 - */
1595 -static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
1596 -{
1597 - int status;
1598 - int val;
1599 -
1600 - status = get_user(val, p);
1601 -
1602 - DPRINTK("reghost = %d", val);
1603 -
1604 - if (status)
1605 - return status;
1606 -
1607 - /* turn on/off reghosting, with the val */
1608 - sbi->reghost_enabled = val;
1609 - return 0;
1610 -}
1611 -
1612 -/*
1613 * Tells the daemon whether it can umount the autofs mount.
1614 */
1615 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
1616 @@ -1001,11 +900,6 @@ static int autofs4_root_ioctl(struct ino
1617 case AUTOFS_IOC_SETTIMEOUT:
1618 return autofs4_get_set_timeout(sbi, p);
1619
1620 - case AUTOFS_IOC_TOGGLEREGHOST:
1621 - return autofs4_toggle_reghost(sbi, p);
1622 - case AUTOFS_IOC_ASKREGHOST:
1623 - return autofs4_ask_reghost(sbi, p);
1624 -
1625 case AUTOFS_IOC_ASKUMOUNT:
1626 return autofs4_ask_umount(filp->f_path.mnt, p);
1627
1628 --- linux-2.6.25.orig/fs/autofs4/autofs_i.h
1629 +++ linux-2.6.25/fs/autofs4/autofs_i.h
1630 @@ -14,6 +14,7 @@
1631 /* Internal header file for autofs */
1632
1633 #include <linux/auto_fs4.h>
1634 +#include <linux/auto_dev-ioctl.h>
1635 #include <linux/mutex.h>
1636 #include <linux/list.h>
1637
1638 @@ -21,6 +22,9 @@
1639 #define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
1640 #define AUTOFS_IOC_COUNT 32
1641
1642 +#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)
1643 +#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11)
1644 +
1645 #include <linux/kernel.h>
1646 #include <linux/slab.h>
1647 #include <linux/time.h>
1648 @@ -35,11 +39,27 @@
1649 /* #define DEBUG */
1650
1651 #ifdef DEBUG
1652 -#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __FUNCTION__ , ##args); } while(0)
1653 +#define DPRINTK(fmt, args...) \
1654 +do { \
1655 + printk(KERN_DEBUG "pid %d: %s: " fmt "\n", \
1656 + current->pid, __FUNCTION__, ##args); \
1657 +} while (0)
1658 #else
1659 -#define DPRINTK(fmt,args...) do {} while(0)
1660 +#define DPRINTK(fmt, args...) do {} while (0)
1661 #endif
1662
1663 +#define AUTOFS_WARN(fmt, args...) \
1664 +do { \
1665 + printk(KERN_WARNING "pid %d: %s: " fmt "\n", \
1666 + current->pid, __FUNCTION__, ##args); \
1667 +} while (0)
1668 +
1669 +#define AUTOFS_ERROR(fmt, args...) \
1670 +do { \
1671 + printk(KERN_ERR "pid %d: %s: " fmt "\n", \
1672 + current->pid, __FUNCTION__, ##args); \
1673 +} while (0)
1674 +
1675 /* Unified info structure. This is pointed to by both the dentry and
1676 inode structures. Each file in the filesystem has an instance of this
1677 structure. It holds a reference to the dentry, so dentries are never
1678 @@ -52,12 +72,18 @@ struct autofs_info {
1679
1680 int flags;
1681
1682 - struct list_head rehash;
1683 + struct completion expire_complete;
1684 +
1685 + struct list_head active;
1686 + struct list_head expiring;
1687
1688 struct autofs_sb_info *sbi;
1689 unsigned long last_used;
1690 atomic_t count;
1691
1692 + uid_t uid;
1693 + gid_t gid;
1694 +
1695 mode_t mode;
1696 size_t size;
1697
1698 @@ -68,15 +94,14 @@ struct autofs_info {
1699 };
1700
1701 #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
1702 +#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
1703
1704 struct autofs_wait_queue {
1705 wait_queue_head_t queue;
1706 struct autofs_wait_queue *next;
1707 autofs_wqt_t wait_queue_token;
1708 /* We use the following to see what we are waiting for */
1709 - unsigned int hash;
1710 - unsigned int len;
1711 - char *name;
1712 + struct qstr name;
1713 u32 dev;
1714 u64 ino;
1715 uid_t uid;
1716 @@ -85,15 +110,11 @@ struct autofs_wait_queue {
1717 pid_t tgid;
1718 /* This is for status reporting upon return */
1719 int status;
1720 - atomic_t wait_ctr;
1721 + unsigned int wait_ctr;
1722 };
1723
1724 #define AUTOFS_SBI_MAGIC 0x6d4a556d
1725
1726 -#define AUTOFS_TYPE_INDIRECT 0x0001
1727 -#define AUTOFS_TYPE_DIRECT 0x0002
1728 -#define AUTOFS_TYPE_OFFSET 0x0004
1729 -
1730 struct autofs_sb_info {
1731 u32 magic;
1732 int pipefd;
1733 @@ -112,8 +133,9 @@ struct autofs_sb_info {
1734 struct mutex wq_mutex;
1735 spinlock_t fs_lock;
1736 struct autofs_wait_queue *queues; /* Wait queue pointer */
1737 - spinlock_t rehash_lock;
1738 - struct list_head rehash_list;
1739 + spinlock_t lookup_lock;
1740 + struct list_head active_list;
1741 + struct list_head expiring_list;
1742 };
1743
1744 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
1745 @@ -138,18 +160,14 @@ static inline int autofs4_oz_mode(struct
1746 static inline int autofs4_ispending(struct dentry *dentry)
1747 {
1748 struct autofs_info *inf = autofs4_dentry_ino(dentry);
1749 - int pending = 0;
1750
1751 if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
1752 return 1;
1753
1754 - if (inf) {
1755 - spin_lock(&inf->sbi->fs_lock);
1756 - pending = inf->flags & AUTOFS_INF_EXPIRING;
1757 - spin_unlock(&inf->sbi->fs_lock);
1758 - }
1759 + if (inf->flags & AUTOFS_INF_EXPIRING)
1760 + return 1;
1761
1762 - return pending;
1763 + return 0;
1764 }
1765
1766 static inline void autofs4_copy_atime(struct file *src, struct file *dst)
1767 @@ -164,11 +182,25 @@ void autofs4_free_ino(struct autofs_info
1768
1769 /* Expiration */
1770 int is_autofs4_dentry(struct dentry *);
1771 +int autofs4_expire_wait(struct dentry *dentry);
1772 int autofs4_expire_run(struct super_block *, struct vfsmount *,
1773 struct autofs_sb_info *,
1774 struct autofs_packet_expire __user *);
1775 +int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt,
1776 + struct autofs_sb_info *sbi, int when);
1777 int autofs4_expire_multi(struct super_block *, struct vfsmount *,
1778 struct autofs_sb_info *, int __user *);
1779 +struct dentry *autofs4_expire_direct(struct super_block *sb,
1780 + struct vfsmount *mnt,
1781 + struct autofs_sb_info *sbi, int how);
1782 +struct dentry *autofs4_expire_indirect(struct super_block *sb,
1783 + struct vfsmount *mnt,
1784 + struct autofs_sb_info *sbi, int how);
1785 +
1786 +/* Device node initialization */
1787 +
1788 +int autofs_dev_ioctl_init(void);
1789 +void autofs_dev_ioctl_exit(void);
1790
1791 /* Operations structures */
1792
1793 --- linux-2.6.25.orig/fs/autofs4/inode.c
1794 +++ linux-2.6.25/fs/autofs4/inode.c
1795 @@ -24,8 +24,10 @@
1796
1797 static void ino_lnkfree(struct autofs_info *ino)
1798 {
1799 - kfree(ino->u.symlink);
1800 - ino->u.symlink = NULL;
1801 + if (ino->u.symlink) {
1802 + kfree(ino->u.symlink);
1803 + ino->u.symlink = NULL;
1804 + }
1805 }
1806
1807 struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
1808 @@ -41,16 +43,20 @@ struct autofs_info *autofs4_init_ino(str
1809 if (ino == NULL)
1810 return NULL;
1811
1812 - ino->flags = 0;
1813 - ino->mode = mode;
1814 - ino->inode = NULL;
1815 - ino->dentry = NULL;
1816 - ino->size = 0;
1817 -
1818 - INIT_LIST_HEAD(&ino->rehash);
1819 + if (!reinit) {
1820 + ino->flags = 0;
1821 + ino->inode = NULL;
1822 + ino->dentry = NULL;
1823 + ino->size = 0;
1824 + INIT_LIST_HEAD(&ino->active);
1825 + INIT_LIST_HEAD(&ino->expiring);
1826 + atomic_set(&ino->count, 0);
1827 + }
1828
1829 + ino->uid = 0;
1830 + ino->gid = 0;
1831 + ino->mode = mode;
1832 ino->last_used = jiffies;
1833 - atomic_set(&ino->count, 0);
1834
1835 ino->sbi = sbi;
1836
1837 @@ -159,8 +165,8 @@ void autofs4_kill_sb(struct super_block
1838 if (!sbi)
1839 goto out_kill_sb;
1840
1841 - if (!sbi->catatonic)
1842 - autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
1843 + /* Free wait queues, close pipe */
1844 + autofs4_catatonic_mode(sbi);
1845
1846 /* Clean up and release dangling references */
1847 autofs4_force_release(sbi);
1848 @@ -191,9 +197,9 @@ static int autofs4_show_options(struct s
1849 seq_printf(m, ",minproto=%d", sbi->min_proto);
1850 seq_printf(m, ",maxproto=%d", sbi->max_proto);
1851
1852 - if (sbi->type & AUTOFS_TYPE_OFFSET)
1853 + if (autofs_type_offset(sbi->type))
1854 seq_printf(m, ",offset");
1855 - else if (sbi->type & AUTOFS_TYPE_DIRECT)
1856 + else if (autofs_type_direct(sbi->type))
1857 seq_printf(m, ",direct");
1858 else
1859 seq_printf(m, ",indirect");
1860 @@ -278,13 +284,13 @@ static int parse_options(char *options,
1861 *maxproto = option;
1862 break;
1863 case Opt_indirect:
1864 - *type = AUTOFS_TYPE_INDIRECT;
1865 + set_autofs_type_indirect(type);
1866 break;
1867 case Opt_direct:
1868 - *type = AUTOFS_TYPE_DIRECT;
1869 + set_autofs_type_direct(type);
1870 break;
1871 case Opt_offset:
1872 - *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET;
1873 + set_autofs_type_offset(type);
1874 break;
1875 default:
1876 return 1;
1877 @@ -332,14 +338,15 @@ int autofs4_fill_super(struct super_bloc
1878 sbi->sb = s;
1879 sbi->version = 0;
1880 sbi->sub_version = 0;
1881 - sbi->type = 0;
1882 + set_autofs_type_indirect(&sbi->type);
1883 sbi->min_proto = 0;
1884 sbi->max_proto = 0;
1885 mutex_init(&sbi->wq_mutex);
1886 spin_lock_init(&sbi->fs_lock);
1887 sbi->queues = NULL;
1888 - spin_lock_init(&sbi->rehash_lock);
1889 - INIT_LIST_HEAD(&sbi->rehash_list);
1890 + spin_lock_init(&sbi->lookup_lock);
1891 + INIT_LIST_HEAD(&sbi->active_list);
1892 + INIT_LIST_HEAD(&sbi->expiring_list);
1893 s->s_blocksize = 1024;
1894 s->s_blocksize_bits = 10;
1895 s->s_magic = AUTOFS_SUPER_MAGIC;
1896 @@ -373,7 +380,7 @@ int autofs4_fill_super(struct super_bloc
1897 }
1898
1899 root_inode->i_fop = &autofs4_root_operations;
1900 - root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ?
1901 + root_inode->i_op = autofs_type_trigger(sbi->type) ?
1902 &autofs4_direct_root_inode_operations :
1903 &autofs4_indirect_root_inode_operations;
1904
1905 --- linux-2.6.25.orig/fs/compat_ioctl.c
1906 +++ linux-2.6.25/fs/compat_ioctl.c
1907 @@ -2350,8 +2350,6 @@ COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOVER)
1908 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE)
1909 COMPATIBLE_IOCTL(AUTOFS_IOC_EXPIRE_MULTI)
1910 COMPATIBLE_IOCTL(AUTOFS_IOC_PROTOSUBVER)
1911 -COMPATIBLE_IOCTL(AUTOFS_IOC_ASKREGHOST)
1912 -COMPATIBLE_IOCTL(AUTOFS_IOC_TOGGLEREGHOST)
1913 COMPATIBLE_IOCTL(AUTOFS_IOC_ASKUMOUNT)
1914 /* Raw devices */
1915 COMPATIBLE_IOCTL(RAW_SETBIND)
1916 --- linux-2.6.25.orig/include/linux/auto_fs4.h
1917 +++ linux-2.6.25/include/linux/auto_fs4.h
1918 @@ -23,12 +23,71 @@
1919 #define AUTOFS_MIN_PROTO_VERSION 3
1920 #define AUTOFS_MAX_PROTO_VERSION 5
1921
1922 -#define AUTOFS_PROTO_SUBVERSION 0
1923 +#define AUTOFS_PROTO_SUBVERSION 1
1924
1925 /* Mask for expire behaviour */
1926 #define AUTOFS_EXP_IMMEDIATE 1
1927 #define AUTOFS_EXP_LEAVES 2
1928
1929 +#define AUTOFS_TYPE_ANY 0U
1930 +#define AUTOFS_TYPE_INDIRECT 1U
1931 +#define AUTOFS_TYPE_DIRECT 2U
1932 +#define AUTOFS_TYPE_OFFSET 4U
1933 +
1934 +static inline void set_autofs_type_indirect(unsigned int *type)
1935 +{
1936 + *type = AUTOFS_TYPE_INDIRECT;
1937 + return;
1938 +}
1939 +
1940 +static inline unsigned int autofs_type_indirect(unsigned int type)
1941 +{
1942 + return (type == AUTOFS_TYPE_INDIRECT);
1943 +}
1944 +
1945 +static inline void set_autofs_type_direct(unsigned int *type)
1946 +{
1947 + *type = AUTOFS_TYPE_DIRECT;
1948 + return;
1949 +}
1950 +
1951 +static inline unsigned int autofs_type_direct(unsigned int type)
1952 +{
1953 + return (type == AUTOFS_TYPE_DIRECT);
1954 +}
1955 +
1956 +static inline void set_autofs_type_offset(unsigned int *type)
1957 +{
1958 + *type = AUTOFS_TYPE_OFFSET;
1959 + return;
1960 +}
1961 +
1962 +static inline unsigned int autofs_type_offset(unsigned int type)
1963 +{
1964 + return (type == AUTOFS_TYPE_OFFSET);
1965 +}
1966 +
1967 +static inline unsigned int autofs_type_trigger(unsigned int type)
1968 +{
1969 + return (type == AUTOFS_TYPE_DIRECT || type == AUTOFS_TYPE_OFFSET);
1970 +}
1971 +
1972 +/*
1973 + * This isn't really a type as we use it to say "no type set" to
1974 + * indicate we want to search for "any" mount in the
1975 + * autofs_dev_ioctl_ismountpoint() device ioctl function.
1976 + */
1977 +static inline void set_autofs_type_any(unsigned int *type)
1978 +{
1979 + *type = AUTOFS_TYPE_ANY;
1980 + return;
1981 +}
1982 +
1983 +static inline unsigned int autofs_type_any(unsigned int type)
1984 +{
1985 + return (type == AUTOFS_TYPE_ANY);
1986 +}
1987 +
1988 /* Daemon notification packet types */
1989 enum autofs_notify {
1990 NFY_NONE,
1991 @@ -98,8 +157,6 @@ union autofs_v5_packet_union {
1992 #define AUTOFS_IOC_EXPIRE_INDIRECT AUTOFS_IOC_EXPIRE_MULTI
1993 #define AUTOFS_IOC_EXPIRE_DIRECT AUTOFS_IOC_EXPIRE_MULTI
1994 #define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
1995 -#define AUTOFS_IOC_ASKREGHOST _IOR(0x93,0x68,int)
1996 -#define AUTOFS_IOC_TOGGLEREGHOST _IOR(0x93,0x69,int)
1997 #define AUTOFS_IOC_ASKUMOUNT _IOR(0x93,0x70,int)
1998
1999
2000 --- /dev/null
2001 +++ linux-2.6.25/Documentation/filesystems/autofs4-mount-control.txt
2002 @@ -0,0 +1,414 @@
2003 +
2004 +Miscellaneous Device control operations for the autofs4 kernel module
2005 +====================================================================
2006 +
2007 +The problem
2008 +===========
2009 +
2010 +There is a problem with active restarts in autofs (that is to say
2011 +restarting autofs when there are busy mounts).
2012 +
2013 +During normal operation autofs uses a file descriptor opened on the
2014 +directory that is being managed in order to be able to issue control
2015 +operations. Using a file descriptor gives ioctl operations access to
2016 +autofs specific information stored in the super block. The operations
2017 +are things such as setting an autofs mount catatonic, setting the
2018 +expire timeout and requesting expire checks. As is explained below,
2019 +certain types of autofs triggered mounts can end up covering an autofs
2020 +mount itself which prevents us being able to use open(2) to obtain a
2021 +file descriptor for these operations if we don't already have one open.
2022 +
2023 +Currently autofs uses "umount -l" (lazy umount) to clear active mounts
2024 +at restart. While using lazy umount works for most cases, anything that
2025 +needs to walk back up the mount tree to construct a path, such as
2026 +getcwd(2) and the proc file system /proc/<pid>/cwd, no longer works
2027 +because the point from which the path is constructed has been detached
2028 +from the mount tree.
2029 +
2030 +The actual problem with autofs is that it can't reconnect to existing
2031 +mounts. Immediately one thinks of just adding the ability to remount
2032 +autofs file systems would solve it, but alas, that can't work. This is
2033 +because autofs direct mounts and the implementation of "on demand mount
2034 +and expire" of nested mount trees have the file system mounted directly
2035 +on top of the mount trigger directory dentry.
2036 +
2037 +For example, there are two types of automount maps, direct (in the kernel
2038 +module source you will see a third type called an offset, which is just
2039 +a direct mount in disguise) and indirect.
2040 +
2041 +Here is a master map with direct and indirect map entries:
2042 +
2043 +/- /etc/auto.direct
2044 +/test /etc/auto.indirect
2045 +
2046 +and the corresponding map files:
2047 +
2048 +/etc/auto.direct:
2049 +
2050 +/automount/dparse/g6 budgie:/autofs/export1
2051 +/automount/dparse/g1 shark:/autofs/export1
2052 +and so on.
2053 +
2054 +/etc/auto.indirect:
2055 +
2056 +g1 shark:/autofs/export1
2057 +g6 budgie:/autofs/export1
2058 +and so on.
2059 +
2060 +For the above indirect map an autofs file system is mounted on /test and
2061 +mounts are triggered for each sub-directory key by the inode lookup
2062 +operation. So we see a mount of shark:/autofs/export1 on /test/g1, for
2063 +example.
2064 +
2065 +The way that direct mounts are handled is by making an autofs mount on
2066 +each full path, such as /automount/dparse/g1, and using it as a mount
2067 +trigger. So when we walk on the path we mount shark:/autofs/export1 "on
2068 +top of this mount point". Since these are always directories we can
2069 +use the follow_link inode operation to trigger the mount.
2070 +
2071 +But, each entry in direct and indirect maps can have offsets (making
2072 +them multi-mount map entries).
2073 +
2074 +For example, an indirect mount map entry could also be:
2075 +
2076 +g1 \
2077 + / shark:/autofs/export5/testing/test \
2078 + /s1 shark:/autofs/export/testing/test/s1 \
2079 + /s2 shark:/autofs/export5/testing/test/s2 \
2080 + /s1/ss1 shark:/autofs/export1 \
2081 + /s2/ss2 shark:/autofs/export2
2082 +
2083 +and a similarly a direct mount map entry could also be:
2084 +
2085 +/automount/dparse/g1 \
2086 + / shark:/autofs/export5/testing/test \
2087 + /s1 shark:/autofs/export/testing/test/s1 \
2088 + /s2 shark:/autofs/export5/testing/test/s2 \
2089 + /s1/ss1 shark:/autofs/export2 \
2090 + /s2/ss2 shark:/autofs/export2
2091 +
2092 +One of the issues with version 4 of autofs was that, when mounting an
2093 +entry with a large number of offsets, possibly with nesting, we needed
2094 +to mount and umount all of the offsets as a single unit. Not really a
2095 +problem, except for people with a large number of offsets in map entries.
2096 +This mechanism is used for the well known "hosts" map and we have seen
2097 +cases (in 2.4) where the available number of mounts are exhausted or
2098 +where the number of privileged ports available is exhausted.
2099 +
2100 +In version 5 we mount only as we go down the tree of offsets and
2101 +similarly for expiring them which resolves the above problem. There is
2102 +somewhat more detail to the implementation but it isn't needed for the
2103 +sake of the problem explanation. The one important detail is that these
2104 +offsets are implemented using the same mechanism as the direct mounts
2105 +above and so the mount points can be covered by a mount.
2106 +
2107 +The current autofs implementation uses an ioctl file descriptor opened
2108 +on the mount point for control operations. The references held by the
2109 +descriptor are accounted for in checks made to determine if a mount is
2110 +in use and is also used to access autofs file system information held
2111 +in the mount super block. So the use of a file handle needs to be
2112 +retained.
2113 +
2114 +
2115 +The Solution
2116 +============
2117 +
2118 +To be able to restart autofs leaving existing direct, indirect and
2119 +offset mounts in place we need to be able to obtain a file handle
2120 +for these potentially covered autofs mount points. Rather than just
2121 +implement an isolated operation it was decided to re-implement the
2122 +existing ioctl interface and add new operations to provide this
2123 +functionality.
2124 +
2125 +In addition, to be able to reconstruct a mount tree that has busy mounts,
2126 +the uid and gid of the last user that triggered the mount needs to be
2127 +available because these can be used as macro substitution variables in
2128 +autofs maps. They are recorded at mount request time and an operation
2129 +has been added to retrieve them.
2130 +
2131 +Since we're re-implementing the control interface, a couple of other
2132 +problems with the existing interface have been addressed. First, when
2133 +a mount or expire operation completes a status is returned to the
2134 +kernel by either a "send ready" or a "send fail" operation. The
2135 +"send fail" operation of the ioctl interface could only ever send
2136 +ENOENT so the re-implementation allows user space to send an actual
2137 +status. Another expensive operation in user space, for those using
2138 +very large maps, is discovering if a mount is present. Usually this
2139 +involves scanning /proc/mounts and since it needs to be done quite
2140 +often it can introduce significant overhead when there are many entries
2141 +in the mount table. An operation to lookup the mount status of a mount
2142 +point dentry (covered or not) has also been added.
2143 +
2144 +Current kernel development policy recommends avoiding the use of the
2145 +ioctl mechanism in favor of systems such as Netlink. An implementation
2146 +using this system was attempted to evaluate its suitability and it was
2147 +found to be inadequate, in this case. The Generic Netlink system was
2148 +used for this as raw Netlink would lead to a significant increase in
2149 +complexity. There's no question that the Generic Netlink system is an
2150 +elegant solution for common case ioctl functions but it's not a complete
2151 +replacement probably because it's primary purpose in life is to be a
2152 +message bus implementation rather than specifically an ioctl replacement.
2153 +While it would be possible to work around this there is one concern
2154 +that lead to the decision to not use it. This is that the autofs
2155 +expire in the daemon has become far to complex because umount
2156 +candidates are enumerated, almost for no other reason than to "count"
2157 +the number of times to call the expire ioctl. This involves scanning
2158 +the mount table which has proved to be a big overhead for users with
2159 +large maps. The best way to improve this is try and get back to the
2160 +way the expire was done long ago. That is, when an expire request is
2161 +issued for a mount (file handle) we should continually call back to
2162 +the daemon until we can't umount any more mounts, then return the
2163 +appropriate status to the daemon. At the moment we just expire one
2164 +mount at a time. A Generic Netlink implementation would exclude this
2165 +possibility for future development due to the requirements of the
2166 +message bus architecture.
2167 +
2168 +
2169 +autofs4 Miscellaneous Device mount control interface
2170 +====================================================
2171 +
2172 +The control interface is opening a device node, typically /dev/autofs.
2173 +
2174 +All the ioctls use a common structure to pass the needed parameter
2175 +information and return operation results:
2176 +
2177 +struct autofs_dev_ioctl {
2178 + __u32 ver_major;
2179 + __u32 ver_minor;
2180 + __u32 size; /* total size of data passed in
2181 + * including this struct */
2182 + __s32 ioctlfd; /* automount command fd */
2183 +
2184 + /* Command parameters */
2185 +
2186 + union {
2187 + struct args_protover protover;
2188 + struct args_protosubver protosubver;
2189 + struct args_openmount openmount;
2190 + struct args_ready ready;
2191 + struct args_fail fail;
2192 + struct args_setpipefd setpipefd;
2193 + struct args_timeout timeout;
2194 + struct args_requester requester;
2195 + struct args_expire expire;
2196 + struct args_askumount askumount;
2197 + struct args_ismountpoint ismountpoint;
2198 + };
2199 +
2200 + char path[0];
2201 +};
2202 +
2203 +The ioctlfd field is a mount point file descriptor of an autofs mount
2204 +point. It is returned by the open call and is used by all calls except
2205 +the check for whether a given path is a mount point, where it may
2206 +optionally be used to check a specific mount corresponding to a given
2207 +mount point file descriptor, and when requesting the uid and gid of the
2208 +last successful mount on a directory within the autofs file system.
2209 +
2210 +The anonymous union is used to communicate parameters and results of calls
2211 +made as described below.
2212 +
2213 +The path field is used to pass a path where it is needed and the size field
2214 +is used account for the increased structure length when translating the
2215 +structure sent from user space.
2216 +
2217 +This structure can be initialized before setting specific fields by using
2218 +the void function call init_autofs_dev_ioctl(struct autofs_dev_ioctl *).
2219 +
2220 +All of the ioctls perform a copy of this structure from user space to
2221 +kernel space and return -EINVAL if the size parameter is smaller than
2222 +the structure size itself, -ENOMEM if the kernel memory allocation fails
2223 +or -EFAULT if the copy itself fails. Other checks include a version check
2224 +of the compiled in user space version against the module version and a
2225 +mismatch results in a -EINVAL return. If the size field is greater than
2226 +the structure size then a path is assumed to be present and is checked to
2227 +ensure it begins with a "/" and is NULL terminated, otherwise -EINVAL is
2228 +returned. Following these checks, for all ioctl commands except
2229 +AUTOFS_DEV_IOCTL_VERSION_CMD, AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and
2230 +AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD the ioctlfd is validated and if it is
2231 +not a valid descriptor or doesn't correspond to an autofs mount point
2232 +an error of -EBADF, -ENOTTY or -EINVAL (not an autofs descriptor) is
2233 +returned.
2234 +
2235 +
2236 +The ioctls
2237 +==========
2238 +
2239 +An example of an implementation which uses this interface can be seen
2240 +in autofs version 5.0.4 and later in file lib/dev-ioctl-lib.c of the
2241 +distribution tar available for download from kernel.org in directory
2242 +/pub/linux/daemons/autofs/v5.
2243 +
2244 +The device node ioctl operations implemented by this interface are:
2245 +
2246 +
2247 +AUTOFS_DEV_IOCTL_VERSION
2248 +------------------------
2249 +
2250 +Get the major and minor version of the autofs4 device ioctl kernel module
2251 +implementation. It requires an initialized struct autofs_dev_ioctl as an
2252 +input parameter and sets the version information in the passed in structure.
2253 +It returns 0 on success or the error -EINVAL if a version mismatch is
2254 +detected.
2255 +
2256 +
2257 +AUTOFS_DEV_IOCTL_PROTOVER_CMD and AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD
2258 +------------------------------------------------------------------
2259 +
2260 +Get the major and minor version of the autofs4 protocol version understood
2261 +by loaded module. This call requires an initialized struct autofs_dev_ioctl
2262 +with the ioctlfd field set to a valid autofs mount point descriptor
2263 +and sets the requested version number in structure field protover.version
2264 +and ptotosubver.sub_version respectively. These commands return 0 on
2265 +success or one of the negative error codes if validation fails.
2266 +
2267 +
2268 +AUTOFS_DEV_IOCTL_OPENMOUNT_CMD and AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD
2269 +------------------------------------------------------------------
2270 +
2271 +Obtain and release a file descriptor for an autofs managed mount point
2272 +path. The open call requires an initialized struct autofs_dev_ioctl with
2273 +the the path field set and the size field adjusted appropriately as well
2274 +as the openmount.devid field set to the device number of the autofs mount.
2275 +The device number of an autofs mounted filesystem can be obtained by using
2276 +the AUTOFS_DEV_IOCTL_ISMOUNTPOINT ioctl function by providing the path
2277 +and autofs mount type, as described below. The close call requires an
2278 +initialized struct autofs_dev_ioct with the ioctlfd field set to the
2279 +descriptor obtained from the open call. The release of the file descriptor
2280 +can also be done with close(2) so any open descriptors will also be
2281 +closed at process exit. The close call is included in the implemented
2282 +operations largely for completeness and to provide for a consistent
2283 +user space implementation.
2284 +
2285 +
2286 +AUTOFS_DEV_IOCTL_READY_CMD and AUTOFS_DEV_IOCTL_FAIL_CMD
2287 +--------------------------------------------------------
2288 +
2289 +Return mount and expire result status from user space to the kernel.
2290 +Both of these calls require an initialized struct autofs_dev_ioctl
2291 +with the ioctlfd field set to the descriptor obtained from the open
2292 +call and the ready.token or fail.token field set to the wait queue
2293 +token number, received by user space in the foregoing mount or expire
2294 +request. The fail.status field is set to the status to be returned when
2295 +sending a failure notification with AUTOFS_DEV_IOCTL_FAIL_CMD.
2296 +
2297 +
2298 +AUTOFS_DEV_IOCTL_SETPIPEFD_CMD
2299 +------------------------------
2300 +
2301 +Set the pipe file descriptor used for kernel communication to the daemon.
2302 +Normally this is set at mount time using an option but when reconnecting
2303 +to a existing mount we need to use this to tell the autofs mount about
2304 +the new kernel pipe descriptor. In order to protect mounts against
2305 +incorrectly setting the pipe descriptor we also require that the autofs
2306 +mount be catatonic (see next call).
2307 +
2308 +The call requires an initialized struct autofs_dev_ioctl with the
2309 +ioctlfd field set to the descriptor obtained from the open call and
2310 +the setpipefd.pipefd field set to descriptor of the pipe. On success
2311 +the call also sets the process group id used to identify the controlling
2312 +process (eg. the owning automount(8) daemon) to the process group of
2313 +the caller.
2314 +
2315 +
2316 +AUTOFS_DEV_IOCTL_CATATONIC_CMD
2317 +------------------------------
2318 +
2319 +Make the autofs mount point catatonic. The autofs mount will no longer
2320 +issue mount requests, the kernel communication pipe descriptor is released
2321 +and any remaining waits in the queue released.
2322 +
2323 +The call requires an initialized struct autofs_dev_ioctl with the
2324 +ioctlfd field set to the descriptor obtained from the open call.
2325 +
2326 +
2327 +AUTOFS_DEV_IOCTL_TIMEOUT_CMD
2328 +----------------------------
2329 +
2330 +Set the expire timeout for mounts withing an autofs mount point.
2331 +
2332 +The call requires an initialized struct autofs_dev_ioctl with the
2333 +ioctlfd field set to the descriptor obtained from the open call.
2334 +The timeout.timeout field is set to the desired timeout and this
2335 +field is set to the value of the value of the current timeout of
2336 +the mount upon successful completion.
2337 +
2338 +
2339 +AUTOFS_DEV_IOCTL_REQUESTER_CMD
2340 +------------------------------
2341 +
2342 +Return the uid and gid of the last process to successfully trigger a the
2343 +mount on the given path dentry.
2344 +
2345 +The call requires an initialized struct autofs_dev_ioctl with the path
2346 +field set to the mount point in question and the size field adjusted
2347 +appropriately as well as the ioctlfd field set to the descriptor obtained
2348 +from the open call. Upon return the struct fields requester.uid and
2349 +requester.gid contain the uid and gid respectively.
2350 +
2351 +When reconstructing an autofs mount tree with active mounts we need to
2352 +re-connect to mounts that may have used the original process uid and
2353 +gid (or string variations of them) for mount lookups within the map entry.
2354 +This call provides the ability to obtain this uid and gid so they may be
2355 +used by user space for the mount map lookups.
2356 +
2357 +
2358 +AUTOFS_DEV_IOCTL_EXPIRE_CMD
2359 +---------------------------
2360 +
2361 +Issue an expire request to the kernel for an autofs mount. Typically
2362 +this ioctl is called until no further expire candidates are found.
2363 +
2364 +The call requires an initialized struct autofs_dev_ioctl with the
2365 +ioctlfd field set to the descriptor obtained from the open call. In
2366 +addition an immediate expire, independent of the mount timeout, can be
2367 +requested by setting the expire.how field to 1. If no expire candidates
2368 +can be found the ioctl returns -1 with errno set to EAGAIN.
2369 +
2370 +This call causes the kernel module to check the mount corresponding
2371 +to the given ioctlfd for mounts that can be expired, issues an expire
2372 +request back to the daemon and waits for completion.
2373 +
2374 +AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD
2375 +------------------------------
2376 +
2377 +Checks if an autofs mount point is in use.
2378 +
2379 +The call requires an initialized struct autofs_dev_ioctl with the
2380 +ioctlfd field set to the descriptor obtained from the open call and
2381 +it returns the result in the askumount.may_umount field, 1 for busy
2382 +and 0 otherwise.
2383 +
2384 +
2385 +AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD
2386 +---------------------------------
2387 +
2388 +Check if the given path is a mountpoint.
2389 +
2390 +The call requires an initialized struct autofs_dev_ioctl. There are two
2391 +possible variations. Both use the path field set to the path of the mount
2392 +point to check and the size field must be adjusted appropriately. One uses
2393 +the ioctlfd field to identify a specific mount point to check while the
2394 +other variation uses the path and optionaly the ismountpoint.in.type
2395 +field set to an autofs mount type. The call returns 1 if this is a mount
2396 +point and sets the ismountpoint.out.devid field to the device number of
2397 +the mount and the ismountpoint.out.magic field to the relevant super
2398 +block magic number (described below) or 0 if it isn't a mountpoint. In
2399 +both cases the the device number (as returned by new_encode_dev()) is
2400 +returned in the ismountpoint.out.devid field.
2401 +
2402 +If supplied with a file descriptor we're looking for a specific mount,
2403 +not necessarily at the top of the mounted stack. In this case the path
2404 +the descriptor corresponds to is considered a mountpoint if it is itself
2405 +a mountpoint or contains a mount, such as a multi-mount without a root
2406 +mount. In this case we return 1 if the descriptor corresponds to a mount
2407 +point and and also returns the super magic of the covering mount if there
2408 +is one or 0 if it isn't a mountpoint.
2409 +
2410 +If a path is supplied (and the ioctlfd field is set to -1) then the path
2411 +is looked up and is checked to see if it is the root of a mount. If a
2412 +type is also given we are looking for a particular autofs mount and if
2413 +a match isn't found a fail is returned. If the the located path is the
2414 +root of a mount 1 is returned along with the super magic of the mount
2415 +or 0 otherwise.
2416 +
2417 --- linux-2.6.25.orig/fs/autofs4/Makefile
2418 +++ linux-2.6.25/fs/autofs4/Makefile
2419 @@ -4,4 +4,4 @@
2420
2421 obj-$(CONFIG_AUTOFS4_FS) += autofs4.o
2422
2423 -autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o
2424 +autofs4-objs := init.o inode.o root.o symlink.o waitq.o expire.o dev-ioctl.o
2425 --- /dev/null
2426 +++ linux-2.6.25/fs/autofs4/dev-ioctl.c
2427 @@ -0,0 +1,840 @@
2428 +/*
2429 + * Copyright 2008 Red Hat, Inc. All rights reserved.
2430 + * Copyright 2008 Ian Kent <[email protected]>
2431 + *
2432 + * This file is part of the Linux kernel and is made available under
2433 + * the terms of the GNU General Public License, version 2, or at your
2434 + * option, any later version, incorporated herein by reference.
2435 + */
2436 +
2437 +#include <linux/module.h>
2438 +#include <linux/vmalloc.h>
2439 +#include <linux/miscdevice.h>
2440 +#include <linux/init.h>
2441 +#include <linux/wait.h>
2442 +#include <linux/namei.h>
2443 +#include <linux/fcntl.h>
2444 +#include <linux/file.h>
2445 +#include <linux/sched.h>
2446 +#include <linux/compat.h>
2447 +#include <linux/syscalls.h>
2448 +#include <linux/smp_lock.h>
2449 +#include <linux/magic.h>
2450 +#include <linux/dcache.h>
2451 +#include <linux/uaccess.h>
2452 +
2453 +#include "autofs_i.h"
2454 +
2455 +/*
2456 + * This module implements an interface for routing autofs ioctl control
2457 + * commands via a miscellaneous device file.
2458 + *
2459 + * The alternate interface is needed because we need to be able open
2460 + * an ioctl file descriptor on an autofs mount that may be covered by
2461 + * another mount. This situation arises when starting automount(8)
2462 + * or other user space daemon which uses direct mounts or offset
2463 + * mounts (used for autofs lazy mount/umount of nested mount trees),
2464 + * which have been left busy at at service shutdown.
2465 + */
2466 +
2467 +#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
2468 +
2469 +typedef int (*ioctl_fn)(struct file *,
2470 +struct autofs_sb_info *, struct autofs_dev_ioctl *);
2471 +
2472 +static int check_name(const char *name)
2473 +{
2474 + if (!strchr(name, '/'))
2475 + return -EINVAL;
2476 + return 0;
2477 +}
2478 +
2479 +/*
2480 + * Check a string doesn't overrun the chunk of
2481 + * memory we copied from user land.
2482 + */
2483 +static int invalid_str(char *str, void *end)
2484 +{
2485 + while ((void *) str <= end)
2486 + if (!*str++)
2487 + return 0;
2488 + return -EINVAL;
2489 +}
2490 +
2491 +/*
2492 + * Check that the user compiled against correct version of autofs
2493 + * misc device code.
2494 + *
2495 + * As well as checking the version compatibility this always copies
2496 + * the kernel interface version out.
2497 + */
2498 +static int check_dev_ioctl_version(int cmd, struct autofs_dev_ioctl *param)
2499 +{
2500 + int err = 0;
2501 +
2502 + if ((AUTOFS_DEV_IOCTL_VERSION_MAJOR != param->ver_major) ||
2503 + (AUTOFS_DEV_IOCTL_VERSION_MINOR < param->ver_minor)) {
2504 + AUTOFS_WARN("ioctl control interface version mismatch: "
2505 + "kernel(%u.%u), user(%u.%u), cmd(%d)",
2506 + AUTOFS_DEV_IOCTL_VERSION_MAJOR,
2507 + AUTOFS_DEV_IOCTL_VERSION_MINOR,
2508 + param->ver_major, param->ver_minor, cmd);
2509 + err = -EINVAL;
2510 + }
2511 +
2512 + /* Fill in the kernel version. */
2513 + param->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
2514 + param->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
2515 +
2516 + return err;
2517 +}
2518 +
2519 +/*
2520 + * Copy parameter control struct, including a possible path allocated
2521 + * at the end of the struct.
2522 + */
2523 +static struct autofs_dev_ioctl *copy_dev_ioctl(struct autofs_dev_ioctl __user *in)
2524 +{
2525 + struct autofs_dev_ioctl tmp, *ads;
2526 +
2527 + if (copy_from_user(&tmp, in, sizeof(tmp)))
2528 + return ERR_PTR(-EFAULT);
2529 +
2530 + if (tmp.size < sizeof(tmp))
2531 + return ERR_PTR(-EINVAL);
2532 +
2533 + ads = kmalloc(tmp.size, GFP_KERNEL);
2534 + if (!ads)
2535 + return ERR_PTR(-ENOMEM);
2536 +
2537 + if (copy_from_user(ads, in, tmp.size)) {
2538 + kfree(ads);
2539 + return ERR_PTR(-EFAULT);
2540 + }
2541 +
2542 + return ads;
2543 +}
2544 +
2545 +static inline void free_dev_ioctl(struct autofs_dev_ioctl *param)
2546 +{
2547 + kfree(param);
2548 + return;
2549 +}
2550 +
2551 +/*
2552 + * Check sanity of parameter control fields and if a path is present
2553 + * check that it is terminated and contains at least one "/".
2554 + */
2555 +static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
2556 +{
2557 + int err;
2558 +
2559 + if ((err = check_dev_ioctl_version(cmd, param))) {
2560 + AUTOFS_WARN("invalid device control module version "
2561 + "supplied for cmd(0x%08x)", cmd);
2562 + goto out;
2563 + }
2564 +
2565 + if (param->size > sizeof(*param)) {
2566 + err = invalid_str(param->path,
2567 + (void *) ((size_t) param + param->size));
2568 + if (err) {
2569 + AUTOFS_WARN(
2570 + "path string terminator missing for cmd(0x%08x)",
2571 + cmd);
2572 + goto out;
2573 + }
2574 +
2575 + err = check_name(param->path);
2576 + if (err) {
2577 + AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
2578 + cmd);
2579 + goto out;
2580 + }
2581 + }
2582 +
2583 + err = 0;
2584 +out:
2585 + return err;
2586 +}
2587 +
2588 +/*
2589 + * Get the autofs super block info struct from the file opened on
2590 + * the autofs mount point.
2591 + */
2592 +static struct autofs_sb_info *autofs_dev_ioctl_sbi(struct file *f)
2593 +{
2594 + struct autofs_sb_info *sbi = NULL;
2595 + struct inode *inode;
2596 +
2597 + if (f) {
2598 + inode = f->f_path.dentry->d_inode;
2599 + sbi = autofs4_sbi(inode->i_sb);
2600 + }
2601 + return sbi;
2602 +}
2603 +
2604 +/* Return autofs module protocol version */
2605 +static int autofs_dev_ioctl_protover(struct file *fp,
2606 + struct autofs_sb_info *sbi,
2607 + struct autofs_dev_ioctl *param)
2608 +{
2609 + param->protover.version = sbi->version;
2610 + return 0;
2611 +}
2612 +
2613 +/* Return autofs module protocol sub version */
2614 +static int autofs_dev_ioctl_protosubver(struct file *fp,
2615 + struct autofs_sb_info *sbi,
2616 + struct autofs_dev_ioctl *param)
2617 +{
2618 + param->protosubver.sub_version = sbi->sub_version;
2619 + return 0;
2620 +}
2621 +
2622 +/*
2623 + * Walk down the mount stack looking for an autofs mount that
2624 + * has the requested device number (aka. new_encode_dev(sb->s_dev).
2625 + */
2626 +static int autofs_dev_ioctl_find_super(struct nameidata *nd, dev_t devno)
2627 +{
2628 + struct dentry *dentry;
2629 + struct inode *inode;
2630 + struct super_block *sb;
2631 + dev_t s_dev;
2632 + unsigned int err;
2633 +
2634 + err = -ENOENT;
2635 +
2636 + /* Lookup the dentry name at the base of our mount point */
2637 + dentry = d_lookup(nd->path.dentry, &nd->last);
2638 + if (!dentry)
2639 + goto out;
2640 +
2641 + dput(nd->path.dentry);
2642 + nd->path.dentry = dentry;
2643 +
2644 + /* And follow the mount stack looking for our autofs mount */
2645 + while (follow_down(&nd->path.mnt, &nd->path.dentry)) {
2646 + inode = nd->path.dentry->d_inode;
2647 + if (!inode)
2648 + break;
2649 +
2650 + sb = inode->i_sb;
2651 + s_dev = new_encode_dev(sb->s_dev);
2652 + if (devno == s_dev) {
2653 + if (sb->s_magic == AUTOFS_SUPER_MAGIC) {
2654 + err = 0;
2655 + break;
2656 + }
2657 + }
2658 + }
2659 +out:
2660 + return err;
2661 +}
2662 +
2663 +/*
2664 + * Walk down the mount stack looking for an autofs mount that
2665 + * has the requested mount type (ie. indirect, direct or offset).
2666 + */
2667 +static int autofs_dev_ioctl_find_sbi_type(struct nameidata *nd, unsigned int type)
2668 +{
2669 + struct dentry *dentry;
2670 + struct autofs_info *ino;
2671 + unsigned int err;
2672 +
2673 + err = -ENOENT;
2674 +
2675 + /* Lookup the dentry name at the base of our mount point */
2676 + dentry = d_lookup(nd->path.dentry, &nd->last);
2677 + if (!dentry)
2678 + goto out;
2679 +
2680 + dput(nd->path.dentry);
2681 + nd->path.dentry = dentry;
2682 +
2683 + /* And follow the mount stack looking for our autofs mount */
2684 + while (follow_down(&nd->path.mnt, &nd->path.dentry)) {
2685 + ino = autofs4_dentry_ino(nd->path.dentry);
2686 + if (ino && ino->sbi->type & type) {
2687 + err = 0;
2688 + break;
2689 + }
2690 + }
2691 +out:
2692 + return err;
2693 +}
2694 +
2695 +static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file)
2696 +{
2697 + struct files_struct *files = current->files;
2698 + struct fdtable *fdt;
2699 +
2700 + spin_lock(&files->file_lock);
2701 + fdt = files_fdtable(files);
2702 + BUG_ON(fdt->fd[fd] != NULL);
2703 + rcu_assign_pointer(fdt->fd[fd], file);
2704 + FD_SET(fd, fdt->close_on_exec);
2705 + spin_unlock(&files->file_lock);
2706 +}
2707 +
2708 +
2709 +/*
2710 + * Open a file descriptor on the autofs mount point corresponding
2711 + * to the given path and device number (aka. new_encode_dev(sb->s_dev)).
2712 + */
2713 +static int autofs_dev_ioctl_open_mountpoint(const char *path, dev_t devid)
2714 +{
2715 + struct file *filp;
2716 + struct nameidata nd;
2717 + int err, fd;
2718 +
2719 + fd = get_unused_fd();
2720 + if (likely(fd >= 0)) {
2721 + /* Get nameidata of the parent directory */
2722 + err = path_lookup(path, LOOKUP_PARENT, &nd);
2723 + if (err)
2724 + goto out;
2725 +
2726 + /*
2727 + * Search down, within the parent, looking for an
2728 + * autofs super block that has the device number
2729 + * corresponding to the autofs fs we want to open.
2730 + */
2731 + err = autofs_dev_ioctl_find_super(&nd, devid);
2732 + if (err) {
2733 + path_put(&nd.path);
2734 + goto out;
2735 + }
2736 +
2737 + filp = dentry_open(nd.path.dentry, nd.path.mnt, O_RDONLY);
2738 + if (IS_ERR(filp)) {
2739 + err = PTR_ERR(filp);
2740 + goto out;
2741 + }
2742 +
2743 + autofs_dev_ioctl_fd_install(fd, filp);
2744 + }
2745 +
2746 + return fd;
2747 +
2748 +out:
2749 + put_unused_fd(fd);
2750 + return err;
2751 +}
2752 +
2753 +/* Open a file descriptor on an autofs mount point */
2754 +static int autofs_dev_ioctl_openmount(struct file *fp,
2755 + struct autofs_sb_info *sbi,
2756 + struct autofs_dev_ioctl *param)
2757 +{
2758 + const char *path;
2759 + dev_t devid;
2760 + int err, fd;
2761 +
2762 + /* param->path has already been checked */
2763 + if (!param->openmount.devid)
2764 + return -EINVAL;
2765 +
2766 + param->ioctlfd = -1;
2767 +
2768 + path = param->path;
2769 + devid = param->openmount.devid;
2770 +
2771 + err = 0;
2772 + fd = autofs_dev_ioctl_open_mountpoint(path, devid);
2773 + if (unlikely(fd < 0)) {
2774 + err = fd;
2775 + goto out;
2776 + }
2777 +
2778 + param->ioctlfd = fd;
2779 +out:
2780 + return err;
2781 +}
2782 +
2783 +/* Close file descriptor allocated above (user can also use close(2)). */
2784 +static int autofs_dev_ioctl_closemount(struct file *fp,
2785 + struct autofs_sb_info *sbi,
2786 + struct autofs_dev_ioctl *param)
2787 +{
2788 + return sys_close(param->ioctlfd);
2789 +}
2790 +
2791 +/*
2792 + * Send "ready" status for an existing wait (either a mount or an expire
2793 + * request).
2794 + */
2795 +static int autofs_dev_ioctl_ready(struct file *fp,
2796 + struct autofs_sb_info *sbi,
2797 + struct autofs_dev_ioctl *param)
2798 +{
2799 + autofs_wqt_t token;
2800 +
2801 + token = (autofs_wqt_t) param->ready.token;
2802 + return autofs4_wait_release(sbi, token, 0);
2803 +}
2804 +
2805 +/*
2806 + * Send "fail" status for an existing wait (either a mount or an expire
2807 + * request).
2808 + */
2809 +static int autofs_dev_ioctl_fail(struct file *fp,
2810 + struct autofs_sb_info *sbi,
2811 + struct autofs_dev_ioctl *param)
2812 +{
2813 + autofs_wqt_t token;
2814 + int status;
2815 +
2816 + token = (autofs_wqt_t) param->fail.token;
2817 + status = param->fail.status ? param->fail.status : -ENOENT;
2818 + return autofs4_wait_release(sbi, token, status);
2819 +}
2820 +
2821 +/*
2822 + * Set the pipe fd for kernel communication to the daemon.
2823 + *
2824 + * Normally this is set at mount using an option but if we
2825 + * are reconnecting to a busy mount then we need to use this
2826 + * to tell the autofs mount about the new kernel pipe fd. In
2827 + * order to protect mounts against incorrectly setting the
2828 + * pipefd we also require that the autofs mount be catatonic.
2829 + *
2830 + * This also sets the process group id used to identify the
2831 + * controlling process (eg. the owning automount(8) daemon).
2832 + */
2833 +static int autofs_dev_ioctl_setpipefd(struct file *fp,
2834 + struct autofs_sb_info *sbi,
2835 + struct autofs_dev_ioctl *param)
2836 +{
2837 + int pipefd;
2838 + int err = 0;
2839 +
2840 + if (param->setpipefd.pipefd == -1)
2841 + return -EINVAL;
2842 +
2843 + pipefd = param->setpipefd.pipefd;
2844 +
2845 + mutex_lock(&sbi->wq_mutex);
2846 + if (!sbi->catatonic) {
2847 + mutex_unlock(&sbi->wq_mutex);
2848 + return -EBUSY;
2849 + } else {
2850 + struct file *pipe = fget(pipefd);
2851 + if (!pipe->f_op || !pipe->f_op->write) {
2852 + err = -EPIPE;
2853 + fput(pipe);
2854 + goto out;
2855 + }
2856 + sbi->oz_pgrp = task_pgrp_nr(current);
2857 + sbi->pipefd = pipefd;
2858 + sbi->pipe = pipe;
2859 + sbi->catatonic = 0;
2860 + }
2861 +out:
2862 + mutex_unlock(&sbi->wq_mutex);
2863 + return err;
2864 +}
2865 +
2866 +/*
2867 + * Make the autofs mount point catatonic, no longer responsive to
2868 + * mount requests. Also closes the kernel pipe file descriptor.
2869 + */
2870 +static int autofs_dev_ioctl_catatonic(struct file *fp,
2871 + struct autofs_sb_info *sbi,
2872 + struct autofs_dev_ioctl *param)
2873 +{
2874 + autofs4_catatonic_mode(sbi);
2875 + return 0;
2876 +}
2877 +
2878 +/* Set the autofs mount timeout */
2879 +static int autofs_dev_ioctl_timeout(struct file *fp,
2880 + struct autofs_sb_info *sbi,
2881 + struct autofs_dev_ioctl *param)
2882 +{
2883 + unsigned long timeout;
2884 +
2885 + timeout = param->timeout.timeout;
2886 + param->timeout.timeout = sbi->exp_timeout / HZ;
2887 + sbi->exp_timeout = timeout * HZ;
2888 + return 0;
2889 +}
2890 +
2891 +/*
2892 + * Return the uid and gid of the last request for the mount
2893 + *
2894 + * When reconstructing an autofs mount tree with active mounts
2895 + * we need to re-connect to mounts that may have used the original
2896 + * process uid and gid (or string variations of them) for mount
2897 + * lookups within the map entry.
2898 + */
2899 +static int autofs_dev_ioctl_requester(struct file *fp,
2900 + struct autofs_sb_info *sbi,
2901 + struct autofs_dev_ioctl *param)
2902 +{
2903 + struct autofs_info *ino;
2904 + struct nameidata nd;
2905 + const char *path;
2906 + dev_t devid;
2907 + int err = -ENOENT;
2908 +
2909 + if (param->size <= sizeof(*param)) {
2910 + err = -EINVAL;
2911 + goto out;
2912 + }
2913 +
2914 + path = param->path;
2915 + devid = sbi->sb->s_dev;
2916 +
2917 + param->requester.uid = param->requester.gid = -1;
2918 +
2919 + /* Get nameidata of the parent directory */
2920 + err = path_lookup(path, LOOKUP_PARENT, &nd);
2921 + if (err)
2922 + goto out;
2923 +
2924 + err = autofs_dev_ioctl_find_super(&nd, devid);
2925 + if (err)
2926 + goto out_release;
2927 +
2928 + ino = autofs4_dentry_ino(nd.path.dentry);
2929 + if (ino) {
2930 + err = 0;
2931 + autofs4_expire_wait(nd.path.dentry);
2932 + spin_lock(&sbi->fs_lock);
2933 + param->requester.uid = ino->uid;
2934 + param->requester.gid = ino->gid;
2935 + spin_unlock(&sbi->fs_lock);
2936 + }
2937 +
2938 +out_release:
2939 + path_put(&nd.path);
2940 +out:
2941 + return err;
2942 +}
2943 +
2944 +/*
2945 + * Call repeatedly until it returns -EAGAIN, meaning there's nothing
2946 + * more that can be done.
2947 + */
2948 +static int autofs_dev_ioctl_expire(struct file *fp,
2949 + struct autofs_sb_info *sbi,
2950 + struct autofs_dev_ioctl *param)
2951 +{
2952 + struct vfsmount *mnt;
2953 + int how;
2954 +
2955 + how = param->expire.how;
2956 + mnt = fp->f_path.mnt;
2957 +
2958 + return autofs4_do_expire_multi(sbi->sb, mnt, sbi, how);
2959 +}
2960 +
2961 +/* Check if autofs mount point is in use */
2962 +static int autofs_dev_ioctl_askumount(struct file *fp,
2963 + struct autofs_sb_info *sbi,
2964 + struct autofs_dev_ioctl *param)
2965 +{
2966 + param->askumount.may_umount = 0;
2967 + if (may_umount(fp->f_path.mnt))
2968 + param->askumount.may_umount = 1;
2969 + return 0;
2970 +}
2971 +
2972 +/*
2973 + * Check if the given path is a mountpoint.
2974 + *
2975 + * If we are supplied with the file descriptor of an autofs
2976 + * mount we're looking for a specific mount. In this case
2977 + * the path is considered a mountpoint if it is itself a
2978 + * mountpoint or contains a mount, such as a multi-mount
2979 + * without a root mount. In this case we return 1 if the
2980 + * path is a mount point and the super magic of the covering
2981 + * mount if there is one or 0 if it isn't a mountpoint.
2982 + *
2983 + * If we aren't supplied with a file descriptor then we
2984 + * lookup the nameidata of the path and check if it is the
2985 + * root of a mount. If a type is given we are looking for
2986 + * a particular autofs mount and if we don't find a match
2987 + * we return fail. If the located nameidata path is the
2988 + * root of a mount we return 1 along with the super magic
2989 + * of the mount or 0 otherwise.
2990 + *
2991 + * In both cases the the device number (as returned by
2992 + * new_encode_dev()) is also returned.
2993 + */
2994 +static int autofs_dev_ioctl_ismountpoint(struct file *fp,
2995 + struct autofs_sb_info *sbi,
2996 + struct autofs_dev_ioctl *param)
2997 +{
2998 + struct nameidata nd;
2999 + const char *path;
3000 + unsigned int type;
3001 + unsigned int devid, magic;
3002 + int err = -ENOENT;
3003 +
3004 + if (param->size <= sizeof(*param)) {
3005 + err = -EINVAL;
3006 + goto out;
3007 + }
3008 +
3009 + path = param->path;
3010 + type = param->ismountpoint.in.type;
3011 +
3012 + param->ismountpoint.out.devid = devid = 0;
3013 + param->ismountpoint.out.magic = magic = 0;
3014 +
3015 + if (!fp || param->ioctlfd == -1) {
3016 + if (autofs_type_any(type)) {
3017 + struct super_block *sb;
3018 +
3019 + err = path_lookup(path, LOOKUP_FOLLOW, &nd);
3020 + if (err)
3021 + goto out;
3022 +
3023 + sb = nd.path.dentry->d_sb;
3024 + devid = new_encode_dev(sb->s_dev);
3025 + } else {
3026 + struct autofs_info *ino;
3027 +
3028 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3029 + if (err)
3030 + goto out;
3031 +
3032 + err = autofs_dev_ioctl_find_sbi_type(&nd, type);
3033 + if (err)
3034 + goto out_release;
3035 +
3036 + ino = autofs4_dentry_ino(nd.path.dentry);
3037 + devid = autofs4_get_dev(ino->sbi);
3038 + }
3039 +
3040 + err = 0;
3041 + if (nd.path.dentry->d_inode &&
3042 + nd.path.mnt->mnt_root == nd.path.dentry) {
3043 + err = 1;
3044 + magic = nd.path.dentry->d_inode->i_sb->s_magic;
3045 + }
3046 + } else {
3047 + dev_t dev = autofs4_get_dev(sbi);
3048 +
3049 + err = path_lookup(path, LOOKUP_PARENT, &nd);
3050 + if (err)
3051 + goto out;
3052 +
3053 + err = autofs_dev_ioctl_find_super(&nd, dev);
3054 + if (err)
3055 + goto out_release;
3056 +
3057 + devid = dev;
3058 +
3059 + err = have_submounts(nd.path.dentry);
3060 +
3061 + if (nd.path.mnt->mnt_mountpoint != nd.path.mnt->mnt_root) {
3062 + if (follow_down(&nd.path.mnt, &nd.path.dentry)) {
3063 + struct inode *inode = nd.path.dentry->d_inode;
3064 + magic = inode->i_sb->s_magic;
3065 + }
3066 + }
3067 + }
3068 +
3069 + param->ismountpoint.out.devid = devid;
3070 + param->ismountpoint.out.magic = magic;
3071 +
3072 +out_release:
3073 + path_put(&nd.path);
3074 +out:
3075 + return err;
3076 +}
3077 +
3078 +/*
3079 + * Our range of ioctl numbers isn't 0 based so we need to shift
3080 + * the array index by _IOC_NR(AUTOFS_CTL_IOC_FIRST) for the table
3081 + * lookup.
3082 + */
3083 +#define cmd_idx(cmd) (cmd - _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST))
3084 +
3085 +static ioctl_fn lookup_dev_ioctl(unsigned int cmd)
3086 +{
3087 + static struct {
3088 + int cmd;
3089 + ioctl_fn fn;
3090 + } _ioctls[] = {
3091 + {cmd_idx(AUTOFS_DEV_IOCTL_VERSION_CMD), NULL},
3092 + {cmd_idx(AUTOFS_DEV_IOCTL_PROTOVER_CMD),
3093 + autofs_dev_ioctl_protover},
3094 + {cmd_idx(AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD),
3095 + autofs_dev_ioctl_protosubver},
3096 + {cmd_idx(AUTOFS_DEV_IOCTL_OPENMOUNT_CMD),
3097 + autofs_dev_ioctl_openmount},
3098 + {cmd_idx(AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD),
3099 + autofs_dev_ioctl_closemount},
3100 + {cmd_idx(AUTOFS_DEV_IOCTL_READY_CMD),
3101 + autofs_dev_ioctl_ready},
3102 + {cmd_idx(AUTOFS_DEV_IOCTL_FAIL_CMD),
3103 + autofs_dev_ioctl_fail},
3104 + {cmd_idx(AUTOFS_DEV_IOCTL_SETPIPEFD_CMD),
3105 + autofs_dev_ioctl_setpipefd},
3106 + {cmd_idx(AUTOFS_DEV_IOCTL_CATATONIC_CMD),
3107 + autofs_dev_ioctl_catatonic},
3108 + {cmd_idx(AUTOFS_DEV_IOCTL_TIMEOUT_CMD),
3109 + autofs_dev_ioctl_timeout},
3110 + {cmd_idx(AUTOFS_DEV_IOCTL_REQUESTER_CMD),
3111 + autofs_dev_ioctl_requester},
3112 + {cmd_idx(AUTOFS_DEV_IOCTL_EXPIRE_CMD),
3113 + autofs_dev_ioctl_expire},
3114 + {cmd_idx(AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD),
3115 + autofs_dev_ioctl_askumount},
3116 + {cmd_idx(AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD),
3117 + autofs_dev_ioctl_ismountpoint}
3118 + };
3119 + unsigned int idx = cmd_idx(cmd);
3120 +
3121 + return (idx >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[idx].fn;
3122 +}
3123 +
3124 +/* ioctl dispatcher */
3125 +static int _autofs_dev_ioctl(unsigned int command, struct autofs_dev_ioctl __user *user)
3126 +{
3127 + struct autofs_dev_ioctl *param;
3128 + struct file *fp;
3129 + struct autofs_sb_info *sbi;
3130 + unsigned int cmd_first, cmd;
3131 + ioctl_fn fn = NULL;
3132 + int err = 0;
3133 +
3134 + /* only root can play with this */
3135 + if (!capable(CAP_SYS_ADMIN))
3136 + return -EPERM;
3137 +
3138 + cmd_first = _IOC_NR(AUTOFS_DEV_IOCTL_IOC_FIRST);
3139 + cmd = _IOC_NR(command);
3140 +
3141 + if (_IOC_TYPE(command) != _IOC_TYPE(AUTOFS_DEV_IOCTL_IOC_FIRST) ||
3142 + cmd - cmd_first >= AUTOFS_DEV_IOCTL_IOC_COUNT) {
3143 + return -ENOTTY;
3144 + }
3145 +
3146 + /* Copy the parameters into kernel space. */
3147 + param = copy_dev_ioctl(user);
3148 + if (IS_ERR(param))
3149 + return PTR_ERR(param);
3150 +
3151 + err = validate_dev_ioctl(command, param);
3152 + if (err)
3153 + goto out;
3154 +
3155 + /* The validate routine above always sets the version */
3156 + if (cmd == AUTOFS_DEV_IOCTL_VERSION_CMD)
3157 + goto done;
3158 +
3159 + fn = lookup_dev_ioctl(cmd);
3160 + if (!fn) {
3161 + AUTOFS_WARN("unknown command 0x%08x", command);
3162 + return -ENOTTY;
3163 + }
3164 +
3165 + fp = NULL;
3166 + sbi = NULL;
3167 +
3168 + /*
3169 + * For obvious reasons the openmount can't have a file
3170 + * descriptor yet. We don't take a reference to the
3171 + * file during close to allow for immediate release.
3172 + */
3173 + if (cmd != AUTOFS_DEV_IOCTL_OPENMOUNT_CMD &&
3174 + cmd != AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD) {
3175 + fp = fget(param->ioctlfd);
3176 + if (!fp) {
3177 + if (cmd == AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD)
3178 + goto cont;
3179 + err = -EBADF;
3180 + goto out;
3181 + }
3182 +
3183 + if (!fp->f_op) {
3184 + err = -ENOTTY;
3185 + fput(fp);
3186 + goto out;
3187 + }
3188 +
3189 + sbi = autofs_dev_ioctl_sbi(fp);
3190 + if (!sbi || sbi->magic != AUTOFS_SBI_MAGIC) {
3191 + err = -EINVAL;
3192 + fput(fp);
3193 + goto out;
3194 + }
3195 +
3196 + /*
3197 + * Admin needs to be able to set the mount catatonic in
3198 + * order to be able to perform the re-open.
3199 + */
3200 + if (!autofs4_oz_mode(sbi) &&
3201 + cmd != AUTOFS_DEV_IOCTL_CATATONIC_CMD) {
3202 + err = -EACCES;
3203 + fput(fp);
3204 + goto out;
3205 + }
3206 + }
3207 +cont:
3208 + err = fn(fp, sbi, param);
3209 +
3210 + if (fp)
3211 + fput(fp);
3212 +done:
3213 + if (err >= 0 && copy_to_user(user, param, AUTOFS_DEV_IOCTL_SIZE))
3214 + err = -EFAULT;
3215 +out:
3216 + free_dev_ioctl(param);
3217 + return err;
3218 +}
3219 +
3220 +static long autofs_dev_ioctl(struct file *file, uint command, ulong u)
3221 +{
3222 + int err;
3223 + err = _autofs_dev_ioctl(command, (struct autofs_dev_ioctl __user *) u);
3224 + return (long) err;
3225 +}
3226 +
3227 +#ifdef CONFIG_COMPAT
3228 +static long autofs_dev_ioctl_compat(struct file *file, uint command, ulong u)
3229 +{
3230 + return (long) autofs_dev_ioctl(file, command, (ulong) compat_ptr(u));
3231 +}
3232 +#else
3233 +#define autofs_dev_ioctl_compat NULL
3234 +#endif
3235 +
3236 +static const struct file_operations _dev_ioctl_fops = {
3237 + .unlocked_ioctl = autofs_dev_ioctl,
3238 + .compat_ioctl = autofs_dev_ioctl_compat,
3239 + .owner = THIS_MODULE,
3240 +};
3241 +
3242 +static struct miscdevice _autofs_dev_ioctl_misc = {
3243 + .minor = MISC_DYNAMIC_MINOR,
3244 + .name = AUTOFS_DEVICE_NAME,
3245 + .fops = &_dev_ioctl_fops
3246 +};
3247 +
3248 +/* Register/deregister misc character device */
3249 +int autofs_dev_ioctl_init(void)
3250 +{
3251 + int r;
3252 +
3253 + r = misc_register(&_autofs_dev_ioctl_misc);
3254 + if (r) {
3255 + AUTOFS_ERROR("misc_register failed for control device");
3256 + return r;
3257 + }
3258 +
3259 + return 0;
3260 +}
3261 +
3262 +void autofs_dev_ioctl_exit(void)
3263 +{
3264 + misc_deregister(&_autofs_dev_ioctl_misc);
3265 + return;
3266 +}
3267 +
3268 --- linux-2.6.25.orig/fs/autofs4/init.c
3269 +++ linux-2.6.25/fs/autofs4/init.c
3270 @@ -29,11 +29,20 @@ static struct file_system_type autofs_fs
3271
3272 static int __init init_autofs4_fs(void)
3273 {
3274 - return register_filesystem(&autofs_fs_type);
3275 + int err;
3276 +
3277 + err = register_filesystem(&autofs_fs_type);
3278 + if (err)
3279 + return err;
3280 +
3281 + autofs_dev_ioctl_init();
3282 +
3283 + return err;
3284 }
3285
3286 static void __exit exit_autofs4_fs(void)
3287 {
3288 + autofs_dev_ioctl_exit();
3289 unregister_filesystem(&autofs_fs_type);
3290 }
3291
3292 --- /dev/null
3293 +++ linux-2.6.25/include/linux/auto_dev-ioctl.h
3294 @@ -0,0 +1,229 @@
3295 +/*
3296 + * Copyright 2008 Red Hat, Inc. All rights reserved.
3297 + * Copyright 2008 Ian Kent <[email protected]>
3298 + *
3299 + * This file is part of the Linux kernel and is made available under
3300 + * the terms of the GNU General Public License, version 2, or at your
3301 + * option, any later version, incorporated herein by reference.
3302 + */
3303 +
3304 +#ifndef _LINUX_AUTO_DEV_IOCTL_H
3305 +#define _LINUX_AUTO_DEV_IOCTL_H
3306 +
3307 +#include <linux/auto_fs.h>
3308 +
3309 +#ifdef __KERNEL__
3310 +#include <linux/string.h>
3311 +#else
3312 +#include <string.h>
3313 +#endif /* __KERNEL__ */
3314 +
3315 +#define AUTOFS_DEVICE_NAME "autofs"
3316 +
3317 +#define AUTOFS_DEV_IOCTL_VERSION_MAJOR 1
3318 +#define AUTOFS_DEV_IOCTL_VERSION_MINOR 0
3319 +
3320 +#define AUTOFS_DEVID_LEN 16
3321 +
3322 +#define AUTOFS_DEV_IOCTL_SIZE sizeof(struct autofs_dev_ioctl)
3323 +
3324 +/*
3325 + * An ioctl interface for autofs mount point control.
3326 + */
3327 +
3328 +struct args_protover {
3329 + __u32 version;
3330 +};
3331 +
3332 +struct args_protosubver {
3333 + __u32 sub_version;
3334 +};
3335 +
3336 +struct args_openmount {
3337 + __u32 devid;
3338 +};
3339 +
3340 +struct args_ready {
3341 + __u32 token;
3342 +};
3343 +
3344 +struct args_fail {
3345 + __u32 token;
3346 + __s32 status;
3347 +};
3348 +
3349 +struct args_setpipefd {
3350 + __s32 pipefd;
3351 +};
3352 +
3353 +struct args_timeout {
3354 + __u64 timeout;
3355 +};
3356 +
3357 +struct args_requester {
3358 + __u32 uid;
3359 + __u32 gid;
3360 +};
3361 +
3362 +struct args_expire {
3363 + __u32 how;
3364 +};
3365 +
3366 +struct args_askumount {
3367 + __u32 may_umount;
3368 +};
3369 +
3370 +struct args_ismountpoint {
3371 + union {
3372 + struct args_in {
3373 + __u32 type;
3374 + } in;
3375 + struct args_out {
3376 + __u32 devid;
3377 + __u32 magic;
3378 + } out;
3379 + };
3380 +};
3381 +
3382 +/*
3383 + * All the ioctls use this structure.
3384 + * When sending a path size must account for the total length
3385 + * of the chunk of memory otherwise is is the size of the
3386 + * structure.
3387 + */
3388 +
3389 +struct autofs_dev_ioctl {
3390 + __u32 ver_major;
3391 + __u32 ver_minor;
3392 + __u32 size; /* total size of data passed in
3393 + * including this struct */
3394 + __s32 ioctlfd; /* automount command fd */
3395 +
3396 + /* Command parameters */
3397 +
3398 + union {
3399 + struct args_protover protover;
3400 + struct args_protosubver protosubver;
3401 + struct args_openmount openmount;
3402 + struct args_ready ready;
3403 + struct args_fail fail;
3404 + struct args_setpipefd setpipefd;
3405 + struct args_timeout timeout;
3406 + struct args_requester requester;
3407 + struct args_expire expire;
3408 + struct args_askumount askumount;
3409 + struct args_ismountpoint ismountpoint;
3410 + };
3411 +
3412 + char path[0];
3413 +};
3414 +
3415 +static inline void init_autofs_dev_ioctl(struct autofs_dev_ioctl *in)
3416 +{
3417 + memset(in, 0, sizeof(struct autofs_dev_ioctl));
3418 + in->ver_major = AUTOFS_DEV_IOCTL_VERSION_MAJOR;
3419 + in->ver_minor = AUTOFS_DEV_IOCTL_VERSION_MINOR;
3420 + in->size = sizeof(struct autofs_dev_ioctl);
3421 + in->ioctlfd = -1;
3422 + return;
3423 +}
3424 +
3425 +/*
3426 + * If you change this make sure you make the corresponding change
3427 + * to autofs-dev-ioctl.c:lookup_ioctl()
3428 + */
3429 +enum {
3430 + /* Get various version info */
3431 + AUTOFS_DEV_IOCTL_VERSION_CMD = 0x71,
3432 + AUTOFS_DEV_IOCTL_PROTOVER_CMD,
3433 + AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD,
3434 +
3435 + /* Open mount ioctl fd */
3436 + AUTOFS_DEV_IOCTL_OPENMOUNT_CMD,
3437 +
3438 + /* Close mount ioctl fd */
3439 + AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD,
3440 +
3441 + /* Mount/expire status returns */
3442 + AUTOFS_DEV_IOCTL_READY_CMD,
3443 + AUTOFS_DEV_IOCTL_FAIL_CMD,
3444 +
3445 + /* Activate/deactivate autofs mount */
3446 + AUTOFS_DEV_IOCTL_SETPIPEFD_CMD,
3447 + AUTOFS_DEV_IOCTL_CATATONIC_CMD,
3448 +
3449 + /* Expiry timeout */
3450 + AUTOFS_DEV_IOCTL_TIMEOUT_CMD,
3451 +
3452 + /* Get mount last requesting uid and gid */
3453 + AUTOFS_DEV_IOCTL_REQUESTER_CMD,
3454 +
3455 + /* Check for eligible expire candidates */
3456 + AUTOFS_DEV_IOCTL_EXPIRE_CMD,
3457 +
3458 + /* Request busy status */
3459 + AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD,
3460 +
3461 + /* Check if path is a mountpoint */
3462 + AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD,
3463 +};
3464 +
3465 +#define AUTOFS_IOCTL 0x93
3466 +
3467 +#define AUTOFS_DEV_IOCTL_VERSION \
3468 + _IOWR(AUTOFS_IOCTL, \
3469 + AUTOFS_DEV_IOCTL_VERSION_CMD, struct autofs_dev_ioctl)
3470 +
3471 +#define AUTOFS_DEV_IOCTL_PROTOVER \
3472 + _IOWR(AUTOFS_IOCTL, \
3473 + AUTOFS_DEV_IOCTL_PROTOVER_CMD, struct autofs_dev_ioctl)
3474 +
3475 +#define AUTOFS_DEV_IOCTL_PROTOSUBVER \
3476 + _IOWR(AUTOFS_IOCTL, \
3477 + AUTOFS_DEV_IOCTL_PROTOSUBVER_CMD, struct autofs_dev_ioctl)
3478 +
3479 +#define AUTOFS_DEV_IOCTL_OPENMOUNT \
3480 + _IOWR(AUTOFS_IOCTL, \
3481 + AUTOFS_DEV_IOCTL_OPENMOUNT_CMD, struct autofs_dev_ioctl)
3482 +
3483 +#define AUTOFS_DEV_IOCTL_CLOSEMOUNT \
3484 + _IOWR(AUTOFS_IOCTL, \
3485 + AUTOFS_DEV_IOCTL_CLOSEMOUNT_CMD, struct autofs_dev_ioctl)
3486 +
3487 +#define AUTOFS_DEV_IOCTL_READY \
3488 + _IOWR(AUTOFS_IOCTL, \
3489 + AUTOFS_DEV_IOCTL_READY_CMD, struct autofs_dev_ioctl)
3490 +
3491 +#define AUTOFS_DEV_IOCTL_FAIL \
3492 + _IOWR(AUTOFS_IOCTL, \
3493 + AUTOFS_DEV_IOCTL_FAIL_CMD, struct autofs_dev_ioctl)
3494 +
3495 +#define AUTOFS_DEV_IOCTL_SETPIPEFD \
3496 + _IOWR(AUTOFS_IOCTL, \
3497 + AUTOFS_DEV_IOCTL_SETPIPEFD_CMD, struct autofs_dev_ioctl)
3498 +
3499 +#define AUTOFS_DEV_IOCTL_CATATONIC \
3500 + _IOWR(AUTOFS_IOCTL, \
3501 + AUTOFS_DEV_IOCTL_CATATONIC_CMD, struct autofs_dev_ioctl)
3502 +
3503 +#define AUTOFS_DEV_IOCTL_TIMEOUT \
3504 + _IOWR(AUTOFS_IOCTL, \
3505 + AUTOFS_DEV_IOCTL_TIMEOUT_CMD, struct autofs_dev_ioctl)
3506 +
3507 +#define AUTOFS_DEV_IOCTL_REQUESTER \
3508 + _IOWR(AUTOFS_IOCTL, \
3509 + AUTOFS_DEV_IOCTL_REQUESTER_CMD, struct autofs_dev_ioctl)
3510 +
3511 +#define AUTOFS_DEV_IOCTL_EXPIRE \
3512 + _IOWR(AUTOFS_IOCTL, \
3513 + AUTOFS_DEV_IOCTL_EXPIRE_CMD, struct autofs_dev_ioctl)
3514 +
3515 +#define AUTOFS_DEV_IOCTL_ASKUMOUNT \
3516 + _IOWR(AUTOFS_IOCTL, \
3517 + AUTOFS_DEV_IOCTL_ASKUMOUNT_CMD, struct autofs_dev_ioctl)
3518 +
3519 +#define AUTOFS_DEV_IOCTL_ISMOUNTPOINT \
3520 + _IOWR(AUTOFS_IOCTL, \
3521 + AUTOFS_DEV_IOCTL_ISMOUNTPOINT_CMD, struct autofs_dev_ioctl)
3522 +
3523 +#endif /* _LINUX_AUTO_DEV_IOCTL_H */
3524 --- linux-2.6.25.orig/include/linux/auto_fs.h
3525 +++ linux-2.6.25/include/linux/auto_fs.h
3526 @@ -17,11 +17,13 @@
3527 #ifdef __KERNEL__
3528 #include <linux/fs.h>
3529 #include <linux/limits.h>
3530 +#include <linux/types.h>
3531 +#include <linux/ioctl.h>
3532 +#else
3533 #include <asm/types.h>
3534 +#include <sys/ioctl.h>
3535 #endif /* __KERNEL__ */
3536
3537 -#include <linux/ioctl.h>
3538 -
3539 /* This file describes autofs v3 */
3540 #define AUTOFS_PROTO_VERSION 3
3541