blob: 4b6fb3f628c04be94a2863ad5f7ee05feace9c44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- c -*- --------------------------------------------------------------- *
2 *
3 * linux/fs/autofs/expire.c
4 *
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
Ian Kent3a15e2a2006-03-27 01:14:55 -08007 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This file is part of the Linux kernel and is made available under
10 * the terms of the GNU General Public License, version 2, or at your
11 * option, any later version, incorporated herein by reference.
12 *
13 * ------------------------------------------------------------------------- */
14
15#include "autofs_i.h"
16
17static unsigned long now;
18
Ian Kent1f5f2c32006-03-27 01:14:44 -080019/* Check if a dentry can be expired */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static inline int autofs4_can_expire(struct dentry *dentry,
21 unsigned long timeout, int do_now)
22{
23 struct autofs_info *ino = autofs4_dentry_ino(dentry);
24
25 /* dentry in the process of being deleted */
26 if (ino == NULL)
27 return 0;
28
29 /* No point expiring a pending mount */
30 if (dentry->d_flags & DCACHE_AUTOFS_PENDING)
31 return 0;
32
33 if (!do_now) {
34 /* Too young to die */
Ian Kentc0ba7e52006-09-25 16:24:16 -070035 if (!timeout || time_after(ino->last_used + timeout, now))
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 return 0;
37
38 /* update last_used here :-
39 - obviously makes sense if it is in use now
40 - less obviously, prevents rapid-fire expire
41 attempts if expire fails the first time */
42 ino->last_used = now;
43 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 return 1;
45}
46
Ian Kent1f5f2c32006-03-27 01:14:44 -080047/* Check a mount point for busyness */
48static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Ian Kente0a7aae2006-03-27 01:14:47 -080050 struct dentry *top = dentry;
Ian Kent1f5f2c32006-03-27 01:14:44 -080051 int status = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 DPRINTK("dentry %p %.*s",
54 dentry, (int)dentry->d_name.len, dentry->d_name.name);
55
56 mntget(mnt);
57 dget(dentry);
58
Ian Kentbc9c4062008-11-06 12:53:22 -080059 if (!follow_down(&mnt, &dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 goto done;
61
Ian Kentbc9c4062008-11-06 12:53:22 -080062 if (is_autofs4_dentry(dentry)) {
63 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
64
65 /* This is an autofs submount, we can't expire it */
66 if (sbi->type == AUTOFS_TYPE_INDIRECT)
67 goto done;
68
69 /*
70 * Otherwise it's an offset mount and we need to check
71 * if we can umount its mount, if there is one.
72 */
73 if (!d_mountpoint(dentry))
74 goto done;
75 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Ian Kente0a7aae2006-03-27 01:14:47 -080077 /* Update the expiry counter if fs is busy */
Ian Kente3474a82006-03-27 01:14:51 -080078 if (!may_umount_tree(mnt)) {
Ian Kente0a7aae2006-03-27 01:14:47 -080079 struct autofs_info *ino = autofs4_dentry_ino(top);
80 ino->last_used = jiffies;
81 goto done;
82 }
83
84 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085done:
86 DPRINTK("returning = %d", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 dput(dentry);
Jan Blunck868eb7a2008-05-01 04:35:10 -070088 mntput(mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return status;
90}
91
Ian Kent1ce12ba2006-03-27 01:14:45 -080092/*
93 * Calculate next entry in top down tree traversal.
94 * From next_mnt in namespace.c - elegant.
95 */
96static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
97{
98 struct list_head *next = p->d_subdirs.next;
99
100 if (next == &p->d_subdirs) {
101 while (1) {
102 if (p == root)
103 return NULL;
104 next = p->d_u.d_child.next;
105 if (next != &p->d_parent->d_subdirs)
106 break;
107 p = p->d_parent;
108 }
109 }
110 return list_entry(next, struct dentry, d_u.d_child);
111}
112
Ian Kent3a15e2a2006-03-27 01:14:55 -0800113/*
114 * Check a direct mount point for busyness.
115 * Direct mounts have similar expiry semantics to tree mounts.
116 * The tree is not busy iff no mountpoints are busy and there are no
117 * autofs submounts.
118 */
119static int autofs4_direct_busy(struct vfsmount *mnt,
120 struct dentry *top,
121 unsigned long timeout,
122 int do_now)
123{
124 DPRINTK("top %p %.*s",
125 top, (int) top->d_name.len, top->d_name.name);
126
Ian Kent3a15e2a2006-03-27 01:14:55 -0800127 /* If it's busy update the expiry counters */
128 if (!may_umount_tree(mnt)) {
129 struct autofs_info *ino = autofs4_dentry_ino(top);
130 if (ino)
131 ino->last_used = jiffies;
132 return 1;
133 }
134
135 /* Timeout of a direct mount is determined by its top dentry */
136 if (!autofs4_can_expire(top, timeout, do_now))
137 return 1;
138
139 return 0;
140}
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/* Check a directory tree of mount points for busyness
143 * The tree is not busy iff no mountpoints are busy
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 */
Ian Kent1f5f2c32006-03-27 01:14:44 -0800145static int autofs4_tree_busy(struct vfsmount *mnt,
146 struct dentry *top,
147 unsigned long timeout,
148 int do_now)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Ian Kente0a7aae2006-03-27 01:14:47 -0800150 struct autofs_info *top_ino = autofs4_dentry_ino(top);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800151 struct dentry *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Ian Kent1f5f2c32006-03-27 01:14:44 -0800153 DPRINTK("top %p %.*s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 top, (int)top->d_name.len, top->d_name.name);
155
156 /* Negative dentry - give up */
157 if (!simple_positive(top))
Ian Kent1f5f2c32006-03-27 01:14:44 -0800158 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 spin_lock(&dcache_lock);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800161 for (p = top; p; p = next_dentry(p, top)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* Negative dentry - give up */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800163 if (!simple_positive(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 DPRINTK("dentry %p %.*s",
Ian Kent1ce12ba2006-03-27 01:14:45 -0800167 p, (int) p->d_name.len, p->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Ian Kent1ce12ba2006-03-27 01:14:45 -0800169 p = dget(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 spin_unlock(&dcache_lock);
171
Ian Kent1aff3c82006-03-27 01:14:46 -0800172 /*
173 * Is someone visiting anywhere in the subtree ?
174 * If there's no mount we need to check the usage
175 * count for the autofs dentry.
Ian Kente0a7aae2006-03-27 01:14:47 -0800176 * If the fs is busy update the expiry counter.
Ian Kent1aff3c82006-03-27 01:14:46 -0800177 */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800178 if (d_mountpoint(p)) {
Ian Kent1ce12ba2006-03-27 01:14:45 -0800179 if (autofs4_mount_busy(mnt, p)) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800180 top_ino->last_used = jiffies;
Ian Kent1ce12ba2006-03-27 01:14:45 -0800181 dput(p);
Ian Kent1f5f2c32006-03-27 01:14:44 -0800182 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
Ian Kent1aff3c82006-03-27 01:14:46 -0800184 } else {
Ian Kente0a7aae2006-03-27 01:14:47 -0800185 struct autofs_info *ino = autofs4_dentry_ino(p);
Ian Kent1aff3c82006-03-27 01:14:46 -0800186 unsigned int ino_count = atomic_read(&ino->count);
187
Ian Kentf9022f62006-06-25 05:48:47 -0700188 /*
189 * Clean stale dentries below that have not been
190 * invalidated after a mount fail during lookup
191 */
192 d_invalidate(p);
193
Ian Kent1aff3c82006-03-27 01:14:46 -0800194 /* allow for dget above and top is already dgot */
195 if (p == top)
196 ino_count += 2;
197 else
198 ino_count++;
199
200 if (atomic_read(&p->d_count) > ino_count) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800201 top_ino->last_used = jiffies;
Ian Kent1aff3c82006-03-27 01:14:46 -0800202 dput(p);
203 return 1;
204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
Ian Kent1ce12ba2006-03-27 01:14:45 -0800206 dput(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 spin_lock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209 spin_unlock(&dcache_lock);
Ian Kent1aff3c82006-03-27 01:14:46 -0800210
211 /* Timeout of a tree mount is ultimately determined by its top dentry */
212 if (!autofs4_can_expire(top, timeout, do_now))
213 return 1;
214
Ian Kent1f5f2c32006-03-27 01:14:44 -0800215 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
219 struct dentry *parent,
220 unsigned long timeout,
221 int do_now)
222{
Ian Kent1ce12ba2006-03-27 01:14:45 -0800223 struct dentry *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 DPRINTK("parent %p %.*s",
226 parent, (int)parent->d_name.len, parent->d_name.name);
227
228 spin_lock(&dcache_lock);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800229 for (p = parent; p; p = next_dentry(p, parent)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 /* Negative dentry - give up */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800231 if (!simple_positive(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 DPRINTK("dentry %p %.*s",
Ian Kent1ce12ba2006-03-27 01:14:45 -0800235 p, (int) p->d_name.len, p->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Ian Kent1ce12ba2006-03-27 01:14:45 -0800237 p = dget(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 spin_unlock(&dcache_lock);
239
Ian Kent1ce12ba2006-03-27 01:14:45 -0800240 if (d_mountpoint(p)) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800241 /* Can we umount this guy */
242 if (autofs4_mount_busy(mnt, p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 goto cont;
244
Ian Kente0a7aae2006-03-27 01:14:47 -0800245 /* Can we expire this guy */
246 if (autofs4_can_expire(p, timeout, do_now))
Ian Kent1ce12ba2006-03-27 01:14:45 -0800247 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249cont:
Ian Kent1ce12ba2006-03-27 01:14:45 -0800250 dput(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 spin_lock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return NULL;
255}
256
Ian Kent3a15e2a2006-03-27 01:14:55 -0800257/* Check if we can expire a direct mount (possibly a tree) */
Ian Kent8d7b48e2008-10-15 22:02:54 -0700258struct dentry *autofs4_expire_direct(struct super_block *sb,
259 struct vfsmount *mnt,
260 struct autofs_sb_info *sbi,
261 int how)
Ian Kent3a15e2a2006-03-27 01:14:55 -0800262{
263 unsigned long timeout;
264 struct dentry *root = dget(sb->s_root);
265 int do_now = how & AUTOFS_EXP_IMMEDIATE;
266
Ian Kentc0ba7e52006-09-25 16:24:16 -0700267 if (!root)
Ian Kent3a15e2a2006-03-27 01:14:55 -0800268 return NULL;
269
270 now = jiffies;
271 timeout = sbi->exp_timeout;
272
Ian Kent3a15e2a2006-03-27 01:14:55 -0800273 spin_lock(&sbi->fs_lock);
274 if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
275 struct autofs_info *ino = autofs4_dentry_ino(root);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700276 if (d_mountpoint(root)) {
277 ino->flags |= AUTOFS_INF_MOUNTPOINT;
278 root->d_mounted--;
279 }
Ian Kent3a15e2a2006-03-27 01:14:55 -0800280 ino->flags |= AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700281 init_completion(&ino->expire_complete);
Ian Kent3a15e2a2006-03-27 01:14:55 -0800282 spin_unlock(&sbi->fs_lock);
283 return root;
284 }
285 spin_unlock(&sbi->fs_lock);
286 dput(root);
287
288 return NULL;
289}
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291/*
292 * Find an eligible tree to time-out
293 * A tree is eligible if :-
294 * - it is unused by any user process
295 * - it has been unused for exp_timeout time
296 */
Ian Kent8d7b48e2008-10-15 22:02:54 -0700297struct dentry *autofs4_expire_indirect(struct super_block *sb,
298 struct vfsmount *mnt,
299 struct autofs_sb_info *sbi,
300 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 unsigned long timeout;
303 struct dentry *root = sb->s_root;
304 struct dentry *expired = NULL;
305 struct list_head *next;
306 int do_now = how & AUTOFS_EXP_IMMEDIATE;
307 int exp_leaves = how & AUTOFS_EXP_LEAVES;
Ian Kent97e74492008-07-23 21:30:26 -0700308 struct autofs_info *ino;
309 unsigned int ino_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Ian Kentc0ba7e52006-09-25 16:24:16 -0700311 if (!root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return NULL;
313
314 now = jiffies;
315 timeout = sbi->exp_timeout;
316
317 spin_lock(&dcache_lock);
318 next = root->d_subdirs.next;
319
320 /* On exit from the loop expire is set to a dgot dentry
321 * to expire or it's NULL */
322 while ( next != &root->d_subdirs ) {
Eric Dumazet5160ee62006-01-08 01:03:32 -0800323 struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 /* Negative dentry - give up */
Ian Kent1f5f2c32006-03-27 01:14:44 -0800326 if (!simple_positive(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 next = next->next;
328 continue;
329 }
330
331 dentry = dget(dentry);
332 spin_unlock(&dcache_lock);
333
Ian Kent97e74492008-07-23 21:30:26 -0700334 spin_lock(&sbi->fs_lock);
335 ino = autofs4_dentry_ino(dentry);
336
Ian Kent3a15e2a2006-03-27 01:14:55 -0800337 /*
338 * Case 1: (i) indirect mount or top level pseudo direct mount
339 * (autofs-4.1).
340 * (ii) indirect mount with offset mount, check the "/"
341 * offset (autofs-5.0+).
342 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 if (d_mountpoint(dentry)) {
344 DPRINTK("checking mountpoint %p %.*s",
345 dentry, (int)dentry->d_name.len, dentry->d_name.name);
346
Ian Kent97e74492008-07-23 21:30:26 -0700347 /* Path walk currently on this dentry? */
348 ino_count = atomic_read(&ino->count) + 2;
349 if (atomic_read(&dentry->d_count) > ino_count)
350 goto next;
351
Ian Kente0a7aae2006-03-27 01:14:47 -0800352 /* Can we umount this guy */
353 if (autofs4_mount_busy(mnt, dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 goto next;
355
Ian Kente0a7aae2006-03-27 01:14:47 -0800356 /* Can we expire this guy */
357 if (autofs4_can_expire(dentry, timeout, do_now)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 expired = dentry;
Ian Kentafec5702008-05-01 04:35:06 -0700359 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361 goto next;
362 }
363
Ian Kent1f5f2c32006-03-27 01:14:44 -0800364 if (simple_empty(dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 goto next;
366
367 /* Case 2: tree mount, expire iff entire tree is not busy */
368 if (!exp_leaves) {
Ian Kent97e74492008-07-23 21:30:26 -0700369 /* Path walk currently on this dentry? */
370 ino_count = atomic_read(&ino->count) + 1;
371 if (atomic_read(&dentry->d_count) > ino_count)
372 goto next;
Ian Kent3a9720c2005-05-01 08:59:17 -0700373
Ian Kent97e74492008-07-23 21:30:26 -0700374 if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
Ian Kent3a9720c2005-05-01 08:59:17 -0700375 expired = dentry;
Ian Kentafec5702008-05-01 04:35:06 -0700376 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
Ian Kent3a15e2a2006-03-27 01:14:55 -0800378 /*
379 * Case 3: pseudo direct mount, expire individual leaves
380 * (autofs-4.1).
381 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 } else {
Ian Kent97e74492008-07-23 21:30:26 -0700383 /* Path walk currently on this dentry? */
384 ino_count = atomic_read(&ino->count) + 1;
385 if (atomic_read(&dentry->d_count) > ino_count)
386 goto next;
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
389 if (expired) {
390 dput(dentry);
Ian Kentafec5702008-05-01 04:35:06 -0700391 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
393 }
394next:
Ian Kent97e74492008-07-23 21:30:26 -0700395 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 dput(dentry);
397 spin_lock(&dcache_lock);
398 next = next->next;
399 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 return NULL;
Ian Kentafec5702008-05-01 04:35:06 -0700402
403found:
404 DPRINTK("returning %p %.*s",
405 expired, (int)expired->d_name.len, expired->d_name.name);
Ian Kent97e74492008-07-23 21:30:26 -0700406 ino = autofs4_dentry_ino(expired);
407 ino->flags |= AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700408 init_completion(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700409 spin_unlock(&sbi->fs_lock);
Ian Kentafec5702008-05-01 04:35:06 -0700410 spin_lock(&dcache_lock);
411 list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
412 spin_unlock(&dcache_lock);
413 return expired;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Ian Kent06a35982008-07-23 21:30:28 -0700416int autofs4_expire_wait(struct dentry *dentry)
417{
418 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
419 struct autofs_info *ino = autofs4_dentry_ino(dentry);
420 int status;
421
422 /* Block on any pending expire */
423 spin_lock(&sbi->fs_lock);
424 if (ino->flags & AUTOFS_INF_EXPIRING) {
425 spin_unlock(&sbi->fs_lock);
426
427 DPRINTK("waiting for expire %p name=%.*s",
428 dentry, dentry->d_name.len, dentry->d_name.name);
429
430 status = autofs4_wait(sbi, dentry, NFY_NONE);
431 wait_for_completion(&ino->expire_complete);
432
433 DPRINTK("expire done status=%d", status);
434
435 if (d_unhashed(dentry))
436 return -EAGAIN;
437
438 return status;
439 }
440 spin_unlock(&sbi->fs_lock);
441
442 return 0;
443}
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445/* Perform an expiry operation */
446int autofs4_expire_run(struct super_block *sb,
447 struct vfsmount *mnt,
448 struct autofs_sb_info *sbi,
449 struct autofs_packet_expire __user *pkt_p)
450{
451 struct autofs_packet_expire pkt;
Ian Kent97e74492008-07-23 21:30:26 -0700452 struct autofs_info *ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 struct dentry *dentry;
Ian Kent97e74492008-07-23 21:30:26 -0700454 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 memset(&pkt,0,sizeof pkt);
457
458 pkt.hdr.proto_version = sbi->version;
459 pkt.hdr.type = autofs_ptype_expire;
460
Ian Kent3a15e2a2006-03-27 01:14:55 -0800461 if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 return -EAGAIN;
463
464 pkt.len = dentry->d_name.len;
465 memcpy(pkt.name, dentry->d_name.name, pkt.len);
466 pkt.name[pkt.len] = '\0';
467 dput(dentry);
468
469 if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
Ian Kent97e74492008-07-23 21:30:26 -0700470 ret = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Ian Kent97e74492008-07-23 21:30:26 -0700472 spin_lock(&sbi->fs_lock);
473 ino = autofs4_dentry_ino(dentry);
474 ino->flags &= ~AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700475 complete_all(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700476 spin_unlock(&sbi->fs_lock);
477
478 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
482 more to be done */
483int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,
484 struct autofs_sb_info *sbi, int __user *arg)
485{
486 struct dentry *dentry;
487 int ret = -EAGAIN;
488 int do_now = 0;
489
490 if (arg && get_user(do_now, arg))
491 return -EFAULT;
492
Ian Kentbb979d72008-10-15 22:02:52 -0700493 if (sbi->type & AUTOFS_TYPE_TRIGGER)
Ian Kent3a15e2a2006-03-27 01:14:55 -0800494 dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
495 else
496 dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
497
498 if (dentry) {
Ian Kent1f5f2c32006-03-27 01:14:44 -0800499 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 /* This is synchronous because it makes the daemon a
502 little easier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700504
Ian Kent97e74492008-07-23 21:30:26 -0700505 spin_lock(&sbi->fs_lock);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700506 if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
507 sb->s_root->d_mounted++;
508 ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
509 }
Ian Kent1f5f2c32006-03-27 01:14:44 -0800510 ino->flags &= ~AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700511 complete_all(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700512 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 dput(dentry);
514 }
Ian Kent1f5f2c32006-03-27 01:14:44 -0800515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 return ret;
517}
518