blob: cdabb796ff018aa65eb20c4d6ec034613ab8e1c8 [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 Kent9b1e3af2005-06-21 17:16:38 -070059 if (!autofs4_follow_mount(&mnt, &dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 goto done;
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* This is an autofs submount, we can't expire it */
63 if (is_autofs4_dentry(dentry))
64 goto done;
65
Ian Kente0a7aae2006-03-27 01:14:47 -080066 /* Update the expiry counter if fs is busy */
Ian Kente3474a82006-03-27 01:14:51 -080067 if (!may_umount_tree(mnt)) {
Ian Kente0a7aae2006-03-27 01:14:47 -080068 struct autofs_info *ino = autofs4_dentry_ino(top);
69 ino->last_used = jiffies;
70 goto done;
71 }
72
73 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074done:
75 DPRINTK("returning = %d", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 dput(dentry);
Jan Blunck868eb7a2008-05-01 04:35:10 -070077 mntput(mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 return status;
79}
80
Ian Kent1ce12ba2006-03-27 01:14:45 -080081/*
82 * Calculate next entry in top down tree traversal.
83 * From next_mnt in namespace.c - elegant.
84 */
85static struct dentry *next_dentry(struct dentry *p, struct dentry *root)
86{
87 struct list_head *next = p->d_subdirs.next;
88
89 if (next == &p->d_subdirs) {
90 while (1) {
91 if (p == root)
92 return NULL;
93 next = p->d_u.d_child.next;
94 if (next != &p->d_parent->d_subdirs)
95 break;
96 p = p->d_parent;
97 }
98 }
99 return list_entry(next, struct dentry, d_u.d_child);
100}
101
Ian Kent3a15e2a2006-03-27 01:14:55 -0800102/*
103 * Check a direct mount point for busyness.
104 * Direct mounts have similar expiry semantics to tree mounts.
105 * The tree is not busy iff no mountpoints are busy and there are no
106 * autofs submounts.
107 */
108static int autofs4_direct_busy(struct vfsmount *mnt,
109 struct dentry *top,
110 unsigned long timeout,
111 int do_now)
112{
113 DPRINTK("top %p %.*s",
114 top, (int) top->d_name.len, top->d_name.name);
115
Ian Kent3a15e2a2006-03-27 01:14:55 -0800116 /* If it's busy update the expiry counters */
117 if (!may_umount_tree(mnt)) {
118 struct autofs_info *ino = autofs4_dentry_ino(top);
119 if (ino)
120 ino->last_used = jiffies;
121 return 1;
122 }
123
124 /* Timeout of a direct mount is determined by its top dentry */
125 if (!autofs4_can_expire(top, timeout, do_now))
126 return 1;
127
128 return 0;
129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* Check a directory tree of mount points for busyness
132 * The tree is not busy iff no mountpoints are busy
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 */
Ian Kent1f5f2c32006-03-27 01:14:44 -0800134static int autofs4_tree_busy(struct vfsmount *mnt,
135 struct dentry *top,
136 unsigned long timeout,
137 int do_now)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Ian Kente0a7aae2006-03-27 01:14:47 -0800139 struct autofs_info *top_ino = autofs4_dentry_ino(top);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800140 struct dentry *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Ian Kent1f5f2c32006-03-27 01:14:44 -0800142 DPRINTK("top %p %.*s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 top, (int)top->d_name.len, top->d_name.name);
144
145 /* Negative dentry - give up */
146 if (!simple_positive(top))
Ian Kent1f5f2c32006-03-27 01:14:44 -0800147 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 spin_lock(&dcache_lock);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800150 for (p = top; p; p = next_dentry(p, top)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* Negative dentry - give up */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800152 if (!simple_positive(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 DPRINTK("dentry %p %.*s",
Ian Kent1ce12ba2006-03-27 01:14:45 -0800156 p, (int) p->d_name.len, p->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Ian Kent1ce12ba2006-03-27 01:14:45 -0800158 p = dget(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 spin_unlock(&dcache_lock);
160
Ian Kent1aff3c82006-03-27 01:14:46 -0800161 /*
162 * Is someone visiting anywhere in the subtree ?
163 * If there's no mount we need to check the usage
164 * count for the autofs dentry.
Ian Kente0a7aae2006-03-27 01:14:47 -0800165 * If the fs is busy update the expiry counter.
Ian Kent1aff3c82006-03-27 01:14:46 -0800166 */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800167 if (d_mountpoint(p)) {
Ian Kent1ce12ba2006-03-27 01:14:45 -0800168 if (autofs4_mount_busy(mnt, p)) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800169 top_ino->last_used = jiffies;
Ian Kent1ce12ba2006-03-27 01:14:45 -0800170 dput(p);
Ian Kent1f5f2c32006-03-27 01:14:44 -0800171 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
Ian Kent1aff3c82006-03-27 01:14:46 -0800173 } else {
Ian Kente0a7aae2006-03-27 01:14:47 -0800174 struct autofs_info *ino = autofs4_dentry_ino(p);
Ian Kent1aff3c82006-03-27 01:14:46 -0800175 unsigned int ino_count = atomic_read(&ino->count);
176
Ian Kentf9022f62006-06-25 05:48:47 -0700177 /*
178 * Clean stale dentries below that have not been
179 * invalidated after a mount fail during lookup
180 */
181 d_invalidate(p);
182
Ian Kent1aff3c82006-03-27 01:14:46 -0800183 /* allow for dget above and top is already dgot */
184 if (p == top)
185 ino_count += 2;
186 else
187 ino_count++;
188
189 if (atomic_read(&p->d_count) > ino_count) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800190 top_ino->last_used = jiffies;
Ian Kent1aff3c82006-03-27 01:14:46 -0800191 dput(p);
192 return 1;
193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
Ian Kent1ce12ba2006-03-27 01:14:45 -0800195 dput(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 spin_lock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198 spin_unlock(&dcache_lock);
Ian Kent1aff3c82006-03-27 01:14:46 -0800199
200 /* Timeout of a tree mount is ultimately determined by its top dentry */
201 if (!autofs4_can_expire(top, timeout, do_now))
202 return 1;
203
Ian Kent1f5f2c32006-03-27 01:14:44 -0800204 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207static struct dentry *autofs4_check_leaves(struct vfsmount *mnt,
208 struct dentry *parent,
209 unsigned long timeout,
210 int do_now)
211{
Ian Kent1ce12ba2006-03-27 01:14:45 -0800212 struct dentry *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 DPRINTK("parent %p %.*s",
215 parent, (int)parent->d_name.len, parent->d_name.name);
216
217 spin_lock(&dcache_lock);
Ian Kent1ce12ba2006-03-27 01:14:45 -0800218 for (p = parent; p; p = next_dentry(p, parent)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 /* Negative dentry - give up */
Ian Kent1ce12ba2006-03-27 01:14:45 -0800220 if (!simple_positive(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 DPRINTK("dentry %p %.*s",
Ian Kent1ce12ba2006-03-27 01:14:45 -0800224 p, (int) p->d_name.len, p->d_name.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Ian Kent1ce12ba2006-03-27 01:14:45 -0800226 p = dget(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 spin_unlock(&dcache_lock);
228
Ian Kent1ce12ba2006-03-27 01:14:45 -0800229 if (d_mountpoint(p)) {
Ian Kente0a7aae2006-03-27 01:14:47 -0800230 /* Can we umount this guy */
231 if (autofs4_mount_busy(mnt, p))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 goto cont;
233
Ian Kente0a7aae2006-03-27 01:14:47 -0800234 /* Can we expire this guy */
235 if (autofs4_can_expire(p, timeout, do_now))
Ian Kent1ce12ba2006-03-27 01:14:45 -0800236 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238cont:
Ian Kent1ce12ba2006-03-27 01:14:45 -0800239 dput(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 spin_lock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return NULL;
244}
245
Ian Kent3a15e2a2006-03-27 01:14:55 -0800246/* Check if we can expire a direct mount (possibly a tree) */
247static struct dentry *autofs4_expire_direct(struct super_block *sb,
248 struct vfsmount *mnt,
249 struct autofs_sb_info *sbi,
250 int how)
251{
252 unsigned long timeout;
253 struct dentry *root = dget(sb->s_root);
254 int do_now = how & AUTOFS_EXP_IMMEDIATE;
255
Ian Kentc0ba7e52006-09-25 16:24:16 -0700256 if (!root)
Ian Kent3a15e2a2006-03-27 01:14:55 -0800257 return NULL;
258
259 now = jiffies;
260 timeout = sbi->exp_timeout;
261
Ian Kent3a15e2a2006-03-27 01:14:55 -0800262 spin_lock(&sbi->fs_lock);
263 if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
264 struct autofs_info *ino = autofs4_dentry_ino(root);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700265 if (d_mountpoint(root)) {
266 ino->flags |= AUTOFS_INF_MOUNTPOINT;
267 root->d_mounted--;
268 }
Ian Kent3a15e2a2006-03-27 01:14:55 -0800269 ino->flags |= AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700270 init_completion(&ino->expire_complete);
Ian Kent3a15e2a2006-03-27 01:14:55 -0800271 spin_unlock(&sbi->fs_lock);
272 return root;
273 }
274 spin_unlock(&sbi->fs_lock);
275 dput(root);
276
277 return NULL;
278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280/*
281 * Find an eligible tree to time-out
282 * A tree is eligible if :-
283 * - it is unused by any user process
284 * - it has been unused for exp_timeout time
285 */
Ian Kent3a15e2a2006-03-27 01:14:55 -0800286static struct dentry *autofs4_expire_indirect(struct super_block *sb,
287 struct vfsmount *mnt,
288 struct autofs_sb_info *sbi,
289 int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 unsigned long timeout;
292 struct dentry *root = sb->s_root;
293 struct dentry *expired = NULL;
294 struct list_head *next;
295 int do_now = how & AUTOFS_EXP_IMMEDIATE;
296 int exp_leaves = how & AUTOFS_EXP_LEAVES;
Ian Kent97e74492008-07-23 21:30:26 -0700297 struct autofs_info *ino;
298 unsigned int ino_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Ian Kentc0ba7e52006-09-25 16:24:16 -0700300 if (!root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 return NULL;
302
303 now = jiffies;
304 timeout = sbi->exp_timeout;
305
306 spin_lock(&dcache_lock);
307 next = root->d_subdirs.next;
308
309 /* On exit from the loop expire is set to a dgot dentry
310 * to expire or it's NULL */
311 while ( next != &root->d_subdirs ) {
Eric Dumazet5160ee62006-01-08 01:03:32 -0800312 struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 /* Negative dentry - give up */
Ian Kent1f5f2c32006-03-27 01:14:44 -0800315 if (!simple_positive(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 next = next->next;
317 continue;
318 }
319
320 dentry = dget(dentry);
321 spin_unlock(&dcache_lock);
322
Ian Kent97e74492008-07-23 21:30:26 -0700323 spin_lock(&sbi->fs_lock);
324 ino = autofs4_dentry_ino(dentry);
325
Ian Kent3a15e2a2006-03-27 01:14:55 -0800326 /*
327 * Case 1: (i) indirect mount or top level pseudo direct mount
328 * (autofs-4.1).
329 * (ii) indirect mount with offset mount, check the "/"
330 * offset (autofs-5.0+).
331 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (d_mountpoint(dentry)) {
333 DPRINTK("checking mountpoint %p %.*s",
334 dentry, (int)dentry->d_name.len, dentry->d_name.name);
335
Ian Kent97e74492008-07-23 21:30:26 -0700336 /* Path walk currently on this dentry? */
337 ino_count = atomic_read(&ino->count) + 2;
338 if (atomic_read(&dentry->d_count) > ino_count)
339 goto next;
340
Ian Kente0a7aae2006-03-27 01:14:47 -0800341 /* Can we umount this guy */
342 if (autofs4_mount_busy(mnt, dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 goto next;
344
Ian Kente0a7aae2006-03-27 01:14:47 -0800345 /* Can we expire this guy */
346 if (autofs4_can_expire(dentry, timeout, do_now)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 expired = dentry;
Ian Kentafec5702008-05-01 04:35:06 -0700348 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350 goto next;
351 }
352
Ian Kent1f5f2c32006-03-27 01:14:44 -0800353 if (simple_empty(dentry))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 goto next;
355
356 /* Case 2: tree mount, expire iff entire tree is not busy */
357 if (!exp_leaves) {
Ian Kent97e74492008-07-23 21:30:26 -0700358 /* Path walk currently on this dentry? */
359 ino_count = atomic_read(&ino->count) + 1;
360 if (atomic_read(&dentry->d_count) > ino_count)
361 goto next;
Ian Kent3a9720c2005-05-01 08:59:17 -0700362
Ian Kent97e74492008-07-23 21:30:26 -0700363 if (!autofs4_tree_busy(mnt, dentry, timeout, do_now)) {
Ian Kent3a9720c2005-05-01 08:59:17 -0700364 expired = dentry;
Ian Kentafec5702008-05-01 04:35:06 -0700365 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Ian Kent3a15e2a2006-03-27 01:14:55 -0800367 /*
368 * Case 3: pseudo direct mount, expire individual leaves
369 * (autofs-4.1).
370 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 } else {
Ian Kent97e74492008-07-23 21:30:26 -0700372 /* Path walk currently on this dentry? */
373 ino_count = atomic_read(&ino->count) + 1;
374 if (atomic_read(&dentry->d_count) > ino_count)
375 goto next;
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
378 if (expired) {
379 dput(dentry);
Ian Kentafec5702008-05-01 04:35:06 -0700380 goto found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382 }
383next:
Ian Kent97e74492008-07-23 21:30:26 -0700384 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 dput(dentry);
386 spin_lock(&dcache_lock);
387 next = next->next;
388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return NULL;
Ian Kentafec5702008-05-01 04:35:06 -0700391
392found:
393 DPRINTK("returning %p %.*s",
394 expired, (int)expired->d_name.len, expired->d_name.name);
Ian Kent97e74492008-07-23 21:30:26 -0700395 ino = autofs4_dentry_ino(expired);
396 ino->flags |= AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700397 init_completion(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700398 spin_unlock(&sbi->fs_lock);
Ian Kentafec5702008-05-01 04:35:06 -0700399 spin_lock(&dcache_lock);
400 list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
401 spin_unlock(&dcache_lock);
402 return expired;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
Ian Kent06a35982008-07-23 21:30:28 -0700405int autofs4_expire_wait(struct dentry *dentry)
406{
407 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
408 struct autofs_info *ino = autofs4_dentry_ino(dentry);
409 int status;
410
411 /* Block on any pending expire */
412 spin_lock(&sbi->fs_lock);
413 if (ino->flags & AUTOFS_INF_EXPIRING) {
414 spin_unlock(&sbi->fs_lock);
415
416 DPRINTK("waiting for expire %p name=%.*s",
417 dentry, dentry->d_name.len, dentry->d_name.name);
418
419 status = autofs4_wait(sbi, dentry, NFY_NONE);
420 wait_for_completion(&ino->expire_complete);
421
422 DPRINTK("expire done status=%d", status);
423
424 if (d_unhashed(dentry))
425 return -EAGAIN;
426
427 return status;
428 }
429 spin_unlock(&sbi->fs_lock);
430
431 return 0;
432}
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/* Perform an expiry operation */
435int autofs4_expire_run(struct super_block *sb,
436 struct vfsmount *mnt,
437 struct autofs_sb_info *sbi,
438 struct autofs_packet_expire __user *pkt_p)
439{
440 struct autofs_packet_expire pkt;
Ian Kent97e74492008-07-23 21:30:26 -0700441 struct autofs_info *ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 struct dentry *dentry;
Ian Kent97e74492008-07-23 21:30:26 -0700443 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 memset(&pkt,0,sizeof pkt);
446
447 pkt.hdr.proto_version = sbi->version;
448 pkt.hdr.type = autofs_ptype_expire;
449
Ian Kent3a15e2a2006-03-27 01:14:55 -0800450 if ((dentry = autofs4_expire_indirect(sb, mnt, sbi, 0)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return -EAGAIN;
452
453 pkt.len = dentry->d_name.len;
454 memcpy(pkt.name, dentry->d_name.name, pkt.len);
455 pkt.name[pkt.len] = '\0';
456 dput(dentry);
457
458 if ( copy_to_user(pkt_p, &pkt, sizeof(struct autofs_packet_expire)) )
Ian Kent97e74492008-07-23 21:30:26 -0700459 ret = -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Ian Kent97e74492008-07-23 21:30:26 -0700461 spin_lock(&sbi->fs_lock);
462 ino = autofs4_dentry_ino(dentry);
463 ino->flags &= ~AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700464 complete_all(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700465 spin_unlock(&sbi->fs_lock);
466
467 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
470/* Call repeatedly until it returns -EAGAIN, meaning there's nothing
471 more to be done */
472int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,
473 struct autofs_sb_info *sbi, int __user *arg)
474{
475 struct dentry *dentry;
476 int ret = -EAGAIN;
477 int do_now = 0;
478
479 if (arg && get_user(do_now, arg))
480 return -EFAULT;
481
Ian Kent44d53eb2006-03-27 01:14:56 -0800482 if (sbi->type & AUTOFS_TYPE_DIRECT)
Ian Kent3a15e2a2006-03-27 01:14:55 -0800483 dentry = autofs4_expire_direct(sb, mnt, sbi, do_now);
484 else
485 dentry = autofs4_expire_indirect(sb, mnt, sbi, do_now);
486
487 if (dentry) {
Ian Kent1f5f2c32006-03-27 01:14:44 -0800488 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 /* This is synchronous because it makes the daemon a
491 little easier */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700493
Ian Kent97e74492008-07-23 21:30:26 -0700494 spin_lock(&sbi->fs_lock);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700495 if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
496 sb->s_root->d_mounted++;
497 ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
498 }
Ian Kent1f5f2c32006-03-27 01:14:44 -0800499 ino->flags &= ~AUTOFS_INF_EXPIRING;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700500 complete_all(&ino->expire_complete);
Ian Kent97e74492008-07-23 21:30:26 -0700501 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 dput(dentry);
503 }
Ian Kent1f5f2c32006-03-27 01:14:44 -0800504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 return ret;
506}
507