Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* -*- c -*- --------------------------------------------------------------- * |
2 | * | |
3 | * linux/fs/autofs/root.c | |
4 | * | |
5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved | |
6 | * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org> | |
34ca959c | 7 | * Copyright 2001-2006 Ian Kent <raven@themaw.net> |
1da177e4 LT |
8 | * |
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 | ||
16f7e0fe | 15 | #include <linux/capability.h> |
1da177e4 LT |
16 | #include <linux/errno.h> |
17 | #include <linux/stat.h> | |
18 | #include <linux/param.h> | |
19 | #include <linux/time.h> | |
1da177e4 LT |
20 | #include "autofs_i.h" |
21 | ||
22 | static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *); | |
23 | static int autofs4_dir_unlink(struct inode *,struct dentry *); | |
24 | static int autofs4_dir_rmdir(struct inode *,struct dentry *); | |
25 | static int autofs4_dir_mkdir(struct inode *,struct dentry *,int); | |
26 | static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long); | |
27 | static int autofs4_dir_open(struct inode *inode, struct file *file); | |
28 | static int autofs4_dir_close(struct inode *inode, struct file *file); | |
29 | static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir); | |
30 | static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir); | |
31 | static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); | |
34ca959c | 32 | static void *autofs4_follow_link(struct dentry *, struct nameidata *); |
1da177e4 | 33 | |
4b6f5d20 | 34 | const struct file_operations autofs4_root_operations = { |
1da177e4 LT |
35 | .open = dcache_dir_open, |
36 | .release = dcache_dir_close, | |
37 | .read = generic_read_dir, | |
38 | .readdir = autofs4_root_readdir, | |
39 | .ioctl = autofs4_root_ioctl, | |
40 | }; | |
41 | ||
4b6f5d20 | 42 | const struct file_operations autofs4_dir_operations = { |
1da177e4 LT |
43 | .open = autofs4_dir_open, |
44 | .release = autofs4_dir_close, | |
45 | .read = generic_read_dir, | |
46 | .readdir = autofs4_dir_readdir, | |
47 | }; | |
48 | ||
754661f1 | 49 | const struct inode_operations autofs4_indirect_root_inode_operations = { |
1da177e4 LT |
50 | .lookup = autofs4_lookup, |
51 | .unlink = autofs4_dir_unlink, | |
52 | .symlink = autofs4_dir_symlink, | |
53 | .mkdir = autofs4_dir_mkdir, | |
54 | .rmdir = autofs4_dir_rmdir, | |
55 | }; | |
56 | ||
754661f1 | 57 | const struct inode_operations autofs4_direct_root_inode_operations = { |
34ca959c | 58 | .lookup = autofs4_lookup, |
871f9434 IK |
59 | .unlink = autofs4_dir_unlink, |
60 | .mkdir = autofs4_dir_mkdir, | |
61 | .rmdir = autofs4_dir_rmdir, | |
34ca959c IK |
62 | .follow_link = autofs4_follow_link, |
63 | }; | |
64 | ||
754661f1 | 65 | const struct inode_operations autofs4_dir_inode_operations = { |
1da177e4 LT |
66 | .lookup = autofs4_lookup, |
67 | .unlink = autofs4_dir_unlink, | |
68 | .symlink = autofs4_dir_symlink, | |
69 | .mkdir = autofs4_dir_mkdir, | |
70 | .rmdir = autofs4_dir_rmdir, | |
71 | }; | |
72 | ||
73 | static int autofs4_root_readdir(struct file *file, void *dirent, | |
74 | filldir_t filldir) | |
75 | { | |
a4669ed8 | 76 | struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb); |
1da177e4 LT |
77 | int oz_mode = autofs4_oz_mode(sbi); |
78 | ||
79 | DPRINTK("called, filp->f_pos = %lld", file->f_pos); | |
80 | ||
81 | /* | |
82 | * Don't set reghost flag if: | |
83 | * 1) f_pos is larger than zero -- we've already been here. | |
84 | * 2) we haven't even enabled reghosting in the 1st place. | |
85 | * 3) this is the daemon doing a readdir | |
86 | */ | |
87 | if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled) | |
88 | sbi->needs_reghost = 1; | |
89 | ||
90 | DPRINTK("needs_reghost = %d", sbi->needs_reghost); | |
91 | ||
f360ce3b | 92 | return dcache_readdir(file, dirent, filldir); |
1da177e4 LT |
93 | } |
94 | ||
1da177e4 LT |
95 | static int autofs4_dir_open(struct inode *inode, struct file *file) |
96 | { | |
a4669ed8 JJS |
97 | struct dentry *dentry = file->f_path.dentry; |
98 | struct vfsmount *mnt = file->f_path.mnt; | |
1da177e4 | 99 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
f360ce3b | 100 | struct dentry *cursor; |
1da177e4 LT |
101 | int status; |
102 | ||
f360ce3b IK |
103 | status = dcache_dir_open(inode, file); |
104 | if (status) | |
105 | goto out; | |
106 | ||
107 | cursor = file->private_data; | |
108 | cursor->d_fsdata = NULL; | |
109 | ||
1da177e4 LT |
110 | DPRINTK("file=%p dentry=%p %.*s", |
111 | file, dentry, dentry->d_name.len, dentry->d_name.name); | |
112 | ||
113 | if (autofs4_oz_mode(sbi)) | |
114 | goto out; | |
115 | ||
116 | if (autofs4_ispending(dentry)) { | |
117 | DPRINTK("dentry busy"); | |
f360ce3b IK |
118 | dcache_dir_close(inode, file); |
119 | status = -EBUSY; | |
120 | goto out; | |
1da177e4 LT |
121 | } |
122 | ||
f360ce3b | 123 | status = -ENOENT; |
1da177e4 LT |
124 | if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { |
125 | struct nameidata nd; | |
f360ce3b | 126 | int empty, ret; |
1da177e4 LT |
127 | |
128 | /* In case there are stale directory dentrys from a failed mount */ | |
129 | spin_lock(&dcache_lock); | |
130 | empty = list_empty(&dentry->d_subdirs); | |
131 | spin_unlock(&dcache_lock); | |
132 | ||
133 | if (!empty) | |
134 | d_invalidate(dentry); | |
135 | ||
136 | nd.flags = LOOKUP_DIRECTORY; | |
f360ce3b | 137 | ret = (dentry->d_op->d_revalidate)(dentry, &nd); |
1da177e4 | 138 | |
bcdc5e01 IK |
139 | if (ret <= 0) { |
140 | if (ret < 0) | |
141 | status = ret; | |
f360ce3b IK |
142 | dcache_dir_close(inode, file); |
143 | goto out; | |
144 | } | |
1da177e4 LT |
145 | } |
146 | ||
147 | if (d_mountpoint(dentry)) { | |
148 | struct file *fp = NULL; | |
868eb7a8 | 149 | struct path fp_path = { .dentry = dentry, .mnt = mnt }; |
1da177e4 | 150 | |
868eb7a8 JB |
151 | path_get(&fp_path); |
152 | ||
153 | if (!autofs4_follow_mount(&fp_path.mnt, &fp_path.dentry)) { | |
154 | path_put(&fp_path); | |
f360ce3b IK |
155 | dcache_dir_close(inode, file); |
156 | goto out; | |
9b1e3afd | 157 | } |
1da177e4 | 158 | |
868eb7a8 | 159 | fp = dentry_open(fp_path.dentry, fp_path.mnt, file->f_flags); |
1da177e4 LT |
160 | status = PTR_ERR(fp); |
161 | if (IS_ERR(fp)) { | |
f360ce3b IK |
162 | dcache_dir_close(inode, file); |
163 | goto out; | |
1da177e4 | 164 | } |
f360ce3b | 165 | cursor->d_fsdata = fp; |
1da177e4 | 166 | } |
1da177e4 | 167 | return 0; |
f360ce3b IK |
168 | out: |
169 | return status; | |
1da177e4 LT |
170 | } |
171 | ||
172 | static int autofs4_dir_close(struct inode *inode, struct file *file) | |
173 | { | |
a4669ed8 | 174 | struct dentry *dentry = file->f_path.dentry; |
1da177e4 | 175 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
f360ce3b IK |
176 | struct dentry *cursor = file->private_data; |
177 | int status = 0; | |
1da177e4 LT |
178 | |
179 | DPRINTK("file=%p dentry=%p %.*s", | |
180 | file, dentry, dentry->d_name.len, dentry->d_name.name); | |
181 | ||
182 | if (autofs4_oz_mode(sbi)) | |
183 | goto out; | |
184 | ||
185 | if (autofs4_ispending(dentry)) { | |
186 | DPRINTK("dentry busy"); | |
f360ce3b IK |
187 | status = -EBUSY; |
188 | goto out; | |
1da177e4 LT |
189 | } |
190 | ||
191 | if (d_mountpoint(dentry)) { | |
f360ce3b IK |
192 | struct file *fp = cursor->d_fsdata; |
193 | if (!fp) { | |
194 | status = -ENOENT; | |
195 | goto out; | |
196 | } | |
1da177e4 | 197 | filp_close(fp, current->files); |
1da177e4 LT |
198 | } |
199 | out: | |
f360ce3b IK |
200 | dcache_dir_close(inode, file); |
201 | return status; | |
1da177e4 LT |
202 | } |
203 | ||
204 | static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) | |
205 | { | |
a4669ed8 | 206 | struct dentry *dentry = file->f_path.dentry; |
1da177e4 | 207 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
f360ce3b | 208 | struct dentry *cursor = file->private_data; |
1da177e4 LT |
209 | int status; |
210 | ||
211 | DPRINTK("file=%p dentry=%p %.*s", | |
212 | file, dentry, dentry->d_name.len, dentry->d_name.name); | |
213 | ||
214 | if (autofs4_oz_mode(sbi)) | |
215 | goto out; | |
216 | ||
217 | if (autofs4_ispending(dentry)) { | |
218 | DPRINTK("dentry busy"); | |
219 | return -EBUSY; | |
220 | } | |
221 | ||
222 | if (d_mountpoint(dentry)) { | |
f360ce3b | 223 | struct file *fp = cursor->d_fsdata; |
1da177e4 LT |
224 | |
225 | if (!fp) | |
226 | return -ENOENT; | |
227 | ||
228 | if (!fp->f_op || !fp->f_op->readdir) | |
229 | goto out; | |
230 | ||
231 | status = vfs_readdir(fp, filldir, dirent); | |
232 | file->f_pos = fp->f_pos; | |
233 | if (status) | |
234 | autofs4_copy_atime(file, fp); | |
235 | return status; | |
236 | } | |
237 | out: | |
f360ce3b | 238 | return dcache_readdir(file, dirent, filldir); |
1da177e4 LT |
239 | } |
240 | ||
862b110f | 241 | static int try_to_fill_dentry(struct dentry *dentry, int flags) |
1da177e4 | 242 | { |
862b110f | 243 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
718c604a | 244 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
9d2de6ad | 245 | int status; |
1da177e4 LT |
246 | |
247 | /* Block on any pending expiry here; invalidate the dentry | |
248 | when expiration is done to trigger mount request with a new | |
249 | dentry */ | |
718c604a | 250 | if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { |
1da177e4 LT |
251 | DPRINTK("waiting for expire %p name=%.*s", |
252 | dentry, dentry->d_name.len, dentry->d_name.name); | |
253 | ||
254 | status = autofs4_wait(sbi, dentry, NFY_NONE); | |
718c604a | 255 | |
1da177e4 | 256 | DPRINTK("expire done status=%d", status); |
718c604a | 257 | |
1684b2bb IK |
258 | /* |
259 | * If the directory still exists the mount request must | |
260 | * continue otherwise it can't be followed at the right | |
261 | * time during the walk. | |
262 | */ | |
263 | status = d_invalidate(dentry); | |
264 | if (status != -EBUSY) | |
f50b6f86 | 265 | return -EAGAIN; |
1da177e4 LT |
266 | } |
267 | ||
268 | DPRINTK("dentry=%p %.*s ino=%p", | |
269 | dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode); | |
270 | ||
718c604a IK |
271 | /* |
272 | * Wait for a pending mount, triggering one if there | |
273 | * isn't one already | |
274 | */ | |
1da177e4 LT |
275 | if (dentry->d_inode == NULL) { |
276 | DPRINTK("waiting for mount name=%.*s", | |
277 | dentry->d_name.len, dentry->d_name.name); | |
278 | ||
279 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); | |
718c604a | 280 | |
1da177e4 LT |
281 | DPRINTK("mount done status=%d", status); |
282 | ||
1da177e4 LT |
283 | /* Turn this into a real negative dentry? */ |
284 | if (status == -ENOENT) { | |
1da177e4 LT |
285 | spin_lock(&dentry->d_lock); |
286 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | |
287 | spin_unlock(&dentry->d_lock); | |
34ca959c | 288 | return status; |
1da177e4 LT |
289 | } else if (status) { |
290 | /* Return a negative dentry, but leave it "pending" */ | |
34ca959c | 291 | return status; |
1da177e4 LT |
292 | } |
293 | /* Trigger mount for path component or follow link */ | |
294 | } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) || | |
295 | current->link_count) { | |
296 | DPRINTK("waiting for mount name=%.*s", | |
297 | dentry->d_name.len, dentry->d_name.name); | |
298 | ||
299 | spin_lock(&dentry->d_lock); | |
300 | dentry->d_flags |= DCACHE_AUTOFS_PENDING; | |
301 | spin_unlock(&dentry->d_lock); | |
302 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); | |
303 | ||
304 | DPRINTK("mount done status=%d", status); | |
305 | ||
306 | if (status) { | |
307 | spin_lock(&dentry->d_lock); | |
308 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | |
309 | spin_unlock(&dentry->d_lock); | |
34ca959c | 310 | return status; |
1da177e4 LT |
311 | } |
312 | } | |
313 | ||
e0a7aae9 IK |
314 | /* Initialize expiry counter after successful mount */ |
315 | if (ino) | |
316 | ino->last_used = jiffies; | |
317 | ||
1da177e4 LT |
318 | spin_lock(&dentry->d_lock); |
319 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | |
320 | spin_unlock(&dentry->d_lock); | |
03379044 | 321 | |
9d2de6ad | 322 | return 0; |
34ca959c IK |
323 | } |
324 | ||
325 | /* For autofs direct mounts the follow link triggers the mount */ | |
326 | static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) | |
327 | { | |
328 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | |
a5370553 | 329 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
34ca959c IK |
330 | int oz_mode = autofs4_oz_mode(sbi); |
331 | unsigned int lookup_type; | |
332 | int status; | |
333 | ||
334 | DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d", | |
335 | dentry, dentry->d_name.len, dentry->d_name.name, oz_mode, | |
336 | nd->flags); | |
337 | ||
338 | /* If it's our master or we shouldn't trigger a mount we're done */ | |
339 | lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY); | |
340 | if (oz_mode || !lookup_type) | |
341 | goto done; | |
342 | ||
a5370553 IK |
343 | /* If an expire request is pending wait for it. */ |
344 | if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { | |
871f9434 IK |
345 | DPRINTK("waiting for active request %p name=%.*s", |
346 | dentry, dentry->d_name.len, dentry->d_name.name); | |
347 | ||
348 | status = autofs4_wait(sbi, dentry, NFY_NONE); | |
349 | ||
350 | DPRINTK("request done status=%d", status); | |
351 | } | |
34ca959c | 352 | |
871f9434 IK |
353 | /* |
354 | * If the dentry contains directories then it is an | |
355 | * autofs multi-mount with no root mount offset. So | |
356 | * don't try to mount it again. | |
357 | */ | |
358 | spin_lock(&dcache_lock); | |
be3ca7fe | 359 | if (!d_mountpoint(dentry) && __simple_empty(dentry)) { |
871f9434 IK |
360 | spin_unlock(&dcache_lock); |
361 | ||
362 | status = try_to_fill_dentry(dentry, 0); | |
363 | if (status) | |
364 | goto out_error; | |
365 | ||
366 | /* | |
367 | * The mount succeeded but if there is no root mount | |
368 | * it must be an autofs multi-mount with no root offset | |
369 | * so we don't need to follow the mount. | |
370 | */ | |
371 | if (d_mountpoint(dentry)) { | |
4ac91378 JB |
372 | if (!autofs4_follow_mount(&nd->path.mnt, |
373 | &nd->path.dentry)) { | |
871f9434 IK |
374 | status = -ENOENT; |
375 | goto out_error; | |
376 | } | |
377 | } | |
378 | ||
379 | goto done; | |
34ca959c | 380 | } |
871f9434 | 381 | spin_unlock(&dcache_lock); |
34ca959c IK |
382 | |
383 | done: | |
384 | return NULL; | |
385 | ||
386 | out_error: | |
1d957f9b | 387 | path_put(&nd->path); |
34ca959c | 388 | return ERR_PTR(status); |
1da177e4 LT |
389 | } |
390 | ||
391 | /* | |
392 | * Revalidate is called on every cache lookup. Some of those | |
393 | * cache lookups may actually happen while the dentry is not | |
394 | * yet completely filled in, and revalidate has to delay such | |
395 | * lookups.. | |
396 | */ | |
718c604a | 397 | static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd) |
1da177e4 | 398 | { |
718c604a | 399 | struct inode *dir = dentry->d_parent->d_inode; |
1da177e4 LT |
400 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
401 | int oz_mode = autofs4_oz_mode(sbi); | |
402 | int flags = nd ? nd->flags : 0; | |
bcdc5e01 | 403 | int status = 1; |
1da177e4 LT |
404 | |
405 | /* Pending dentry */ | |
406 | if (autofs4_ispending(dentry)) { | |
bcdc5e01 IK |
407 | /* The daemon never causes a mount to trigger */ |
408 | if (oz_mode) | |
409 | return 1; | |
410 | ||
411 | /* | |
412 | * A zero status is success otherwise we have a | |
413 | * negative error code. | |
414 | */ | |
415 | status = try_to_fill_dentry(dentry, flags); | |
416 | if (status == 0) | |
f50b6f86 IK |
417 | return 1; |
418 | ||
419 | /* | |
420 | * A status of EAGAIN here means that the dentry has gone | |
421 | * away while waiting for an expire to complete. If we are | |
422 | * racing with expire lookup will wait for it so this must | |
423 | * be a revalidate and we need to send it to lookup. | |
424 | */ | |
425 | if (status == -EAGAIN) | |
426 | return 0; | |
bcdc5e01 IK |
427 | |
428 | return status; | |
1da177e4 LT |
429 | } |
430 | ||
431 | /* Negative dentry.. invalidate if "old" */ | |
432 | if (dentry->d_inode == NULL) | |
2d753e62 | 433 | return 0; |
1da177e4 LT |
434 | |
435 | /* Check for a non-mountpoint directory with no contents */ | |
436 | spin_lock(&dcache_lock); | |
437 | if (S_ISDIR(dentry->d_inode->i_mode) && | |
438 | !d_mountpoint(dentry) && | |
90a59c7c | 439 | __simple_empty(dentry)) { |
1da177e4 LT |
440 | DPRINTK("dentry=%p %.*s, emptydir", |
441 | dentry, dentry->d_name.len, dentry->d_name.name); | |
442 | spin_unlock(&dcache_lock); | |
bcdc5e01 IK |
443 | /* The daemon never causes a mount to trigger */ |
444 | if (oz_mode) | |
445 | return 1; | |
446 | ||
447 | /* | |
448 | * A zero status is success otherwise we have a | |
449 | * negative error code. | |
450 | */ | |
451 | status = try_to_fill_dentry(dentry, flags); | |
452 | if (status == 0) | |
453 | return 1; | |
454 | ||
455 | return status; | |
1da177e4 LT |
456 | } |
457 | spin_unlock(&dcache_lock); | |
458 | ||
1da177e4 LT |
459 | return 1; |
460 | } | |
461 | ||
34ca959c | 462 | void autofs4_dentry_release(struct dentry *de) |
1da177e4 LT |
463 | { |
464 | struct autofs_info *inf; | |
465 | ||
466 | DPRINTK("releasing %p", de); | |
467 | ||
468 | inf = autofs4_dentry_ino(de); | |
469 | de->d_fsdata = NULL; | |
470 | ||
471 | if (inf) { | |
f50b6f86 IK |
472 | struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb); |
473 | ||
f50b6f86 | 474 | if (sbi) { |
5f6f4f28 | 475 | spin_lock(&sbi->lookup_lock); |
25767378 IK |
476 | if (!list_empty(&inf->active)) |
477 | list_del(&inf->active); | |
5f6f4f28 IK |
478 | if (!list_empty(&inf->expiring)) |
479 | list_del(&inf->expiring); | |
480 | spin_unlock(&sbi->lookup_lock); | |
f50b6f86 IK |
481 | } |
482 | ||
c3724b12 JM |
483 | inf->dentry = NULL; |
484 | inf->inode = NULL; | |
485 | ||
1da177e4 LT |
486 | autofs4_free_ino(inf); |
487 | } | |
488 | } | |
489 | ||
490 | /* For dentries of directories in the root dir */ | |
491 | static struct dentry_operations autofs4_root_dentry_operations = { | |
492 | .d_revalidate = autofs4_revalidate, | |
493 | .d_release = autofs4_dentry_release, | |
494 | }; | |
495 | ||
496 | /* For other dentries */ | |
497 | static struct dentry_operations autofs4_dentry_operations = { | |
498 | .d_revalidate = autofs4_revalidate, | |
499 | .d_release = autofs4_dentry_release, | |
500 | }; | |
501 | ||
25767378 IK |
502 | static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name) |
503 | { | |
504 | unsigned int len = name->len; | |
505 | unsigned int hash = name->hash; | |
506 | const unsigned char *str = name->name; | |
507 | struct list_head *p, *head; | |
508 | ||
509 | spin_lock(&dcache_lock); | |
510 | spin_lock(&sbi->lookup_lock); | |
511 | head = &sbi->active_list; | |
512 | list_for_each(p, head) { | |
513 | struct autofs_info *ino; | |
514 | struct dentry *dentry; | |
515 | struct qstr *qstr; | |
516 | ||
517 | ino = list_entry(p, struct autofs_info, active); | |
518 | dentry = ino->dentry; | |
519 | ||
520 | spin_lock(&dentry->d_lock); | |
521 | ||
522 | /* Already gone? */ | |
523 | if (atomic_read(&dentry->d_count) == 0) | |
524 | goto next; | |
525 | ||
526 | qstr = &dentry->d_name; | |
527 | ||
528 | if (dentry->d_name.hash != hash) | |
529 | goto next; | |
530 | if (dentry->d_parent != parent) | |
531 | goto next; | |
532 | ||
533 | if (qstr->len != len) | |
534 | goto next; | |
535 | if (memcmp(qstr->name, str, len)) | |
536 | goto next; | |
537 | ||
538 | if (d_unhashed(dentry)) { | |
539 | dget(dentry); | |
540 | spin_unlock(&dentry->d_lock); | |
541 | spin_unlock(&sbi->lookup_lock); | |
542 | spin_unlock(&dcache_lock); | |
543 | return dentry; | |
544 | } | |
545 | next: | |
546 | spin_unlock(&dentry->d_lock); | |
547 | } | |
548 | spin_unlock(&sbi->lookup_lock); | |
549 | spin_unlock(&dcache_lock); | |
550 | ||
551 | return NULL; | |
552 | } | |
553 | ||
5f6f4f28 | 554 | static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name) |
f50b6f86 IK |
555 | { |
556 | unsigned int len = name->len; | |
557 | unsigned int hash = name->hash; | |
558 | const unsigned char *str = name->name; | |
559 | struct list_head *p, *head; | |
560 | ||
561 | spin_lock(&dcache_lock); | |
5f6f4f28 IK |
562 | spin_lock(&sbi->lookup_lock); |
563 | head = &sbi->expiring_list; | |
f50b6f86 IK |
564 | list_for_each(p, head) { |
565 | struct autofs_info *ino; | |
566 | struct dentry *dentry; | |
567 | struct qstr *qstr; | |
568 | ||
5f6f4f28 | 569 | ino = list_entry(p, struct autofs_info, expiring); |
f50b6f86 IK |
570 | dentry = ino->dentry; |
571 | ||
572 | spin_lock(&dentry->d_lock); | |
573 | ||
574 | /* Bad luck, we've already been dentry_iput */ | |
575 | if (!dentry->d_inode) | |
576 | goto next; | |
577 | ||
578 | qstr = &dentry->d_name; | |
579 | ||
580 | if (dentry->d_name.hash != hash) | |
581 | goto next; | |
582 | if (dentry->d_parent != parent) | |
583 | goto next; | |
584 | ||
585 | if (qstr->len != len) | |
586 | goto next; | |
587 | if (memcmp(qstr->name, str, len)) | |
588 | goto next; | |
589 | ||
590 | if (d_unhashed(dentry)) { | |
f50b6f86 | 591 | dget(dentry); |
f50b6f86 | 592 | spin_unlock(&dentry->d_lock); |
5f6f4f28 | 593 | spin_unlock(&sbi->lookup_lock); |
f50b6f86 IK |
594 | spin_unlock(&dcache_lock); |
595 | return dentry; | |
596 | } | |
597 | next: | |
598 | spin_unlock(&dentry->d_lock); | |
599 | } | |
5f6f4f28 | 600 | spin_unlock(&sbi->lookup_lock); |
f50b6f86 IK |
601 | spin_unlock(&dcache_lock); |
602 | ||
603 | return NULL; | |
604 | } | |
605 | ||
1da177e4 LT |
606 | /* Lookups in the root directory */ |
607 | static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | |
608 | { | |
609 | struct autofs_sb_info *sbi; | |
25767378 IK |
610 | struct autofs_info *ino; |
611 | struct dentry *expiring, *unhashed; | |
1da177e4 LT |
612 | int oz_mode; |
613 | ||
614 | DPRINTK("name = %.*s", | |
615 | dentry->d_name.len, dentry->d_name.name); | |
616 | ||
718c604a | 617 | /* File name too long to exist */ |
1da177e4 | 618 | if (dentry->d_name.len > NAME_MAX) |
718c604a | 619 | return ERR_PTR(-ENAMETOOLONG); |
1da177e4 LT |
620 | |
621 | sbi = autofs4_sbi(dir->i_sb); | |
1da177e4 | 622 | oz_mode = autofs4_oz_mode(sbi); |
718c604a | 623 | |
1da177e4 | 624 | DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", |
a47afb0f | 625 | current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); |
1da177e4 | 626 | |
5f6f4f28 IK |
627 | expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name); |
628 | if (expiring) { | |
f50b6f86 IK |
629 | /* |
630 | * If we are racing with expire the request might not | |
631 | * be quite complete but the directory has been removed | |
632 | * so it must have been successful, so just wait for it. | |
633 | */ | |
25767378 | 634 | ino = autofs4_dentry_ino(expiring); |
1864f7bd | 635 | while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { |
f50b6f86 | 636 | DPRINTK("wait for incomplete expire %p name=%.*s", |
5f6f4f28 IK |
637 | expiring, expiring->d_name.len, |
638 | expiring->d_name.name); | |
639 | autofs4_wait(sbi, expiring, NFY_NONE); | |
f50b6f86 IK |
640 | DPRINTK("request completed"); |
641 | } | |
5f6f4f28 IK |
642 | spin_lock(&sbi->lookup_lock); |
643 | if (!list_empty(&ino->expiring)) | |
644 | list_del_init(&ino->expiring); | |
645 | spin_unlock(&sbi->lookup_lock); | |
646 | dput(expiring); | |
f50b6f86 | 647 | } |
1da177e4 | 648 | |
25767378 IK |
649 | unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name); |
650 | if (unhashed) | |
651 | dentry = unhashed; | |
652 | else { | |
653 | /* | |
654 | * Mark the dentry incomplete but don't hash it. We do this | |
655 | * to serialize our inode creation operations (symlink and | |
656 | * mkdir) which prevents deadlock during the callback to | |
657 | * the daemon. Subsequent user space lookups for the same | |
658 | * dentry are placed on the wait queue while the daemon | |
659 | * itself is allowed passage unresticted so the create | |
660 | * operation itself can then hash the dentry. Finally, | |
661 | * we check for the hashed dentry and return the newly | |
662 | * hashed dentry. | |
663 | */ | |
664 | dentry->d_op = &autofs4_root_dentry_operations; | |
665 | ||
666 | /* | |
667 | * And we need to ensure that the same dentry is used for | |
668 | * all following lookup calls until it is hashed so that | |
669 | * the dentry flags are persistent throughout the request. | |
670 | */ | |
671 | ino = autofs4_init_ino(NULL, sbi, 0555); | |
672 | if (!ino) | |
673 | return ERR_PTR(-ENOMEM); | |
674 | ||
675 | dentry->d_fsdata = ino; | |
676 | ino->dentry = dentry; | |
677 | ||
678 | spin_lock(&sbi->lookup_lock); | |
679 | list_add(&ino->active, &sbi->active_list); | |
680 | spin_unlock(&sbi->lookup_lock); | |
5f6f4f28 | 681 | |
25767378 IK |
682 | d_instantiate(dentry, NULL); |
683 | } | |
5f6f4f28 | 684 | |
1da177e4 LT |
685 | if (!oz_mode) { |
686 | spin_lock(&dentry->d_lock); | |
687 | dentry->d_flags |= DCACHE_AUTOFS_PENDING; | |
688 | spin_unlock(&dentry->d_lock); | |
c432c258 IK |
689 | if (dentry->d_op && dentry->d_op->d_revalidate) { |
690 | mutex_unlock(&dir->i_mutex); | |
691 | (dentry->d_op->d_revalidate)(dentry, nd); | |
692 | mutex_lock(&dir->i_mutex); | |
693 | } | |
1da177e4 LT |
694 | } |
695 | ||
696 | /* | |
697 | * If we are still pending, check if we had to handle | |
698 | * a signal. If so we can force a restart.. | |
699 | */ | |
700 | if (dentry->d_flags & DCACHE_AUTOFS_PENDING) { | |
701 | /* See if we were interrupted */ | |
702 | if (signal_pending(current)) { | |
703 | sigset_t *sigset = ¤t->pending.signal; | |
704 | if (sigismember (sigset, SIGKILL) || | |
705 | sigismember (sigset, SIGQUIT) || | |
706 | sigismember (sigset, SIGINT)) { | |
25767378 IK |
707 | if (unhashed) |
708 | dput(unhashed); | |
1da177e4 LT |
709 | return ERR_PTR(-ERESTARTNOINTR); |
710 | } | |
711 | } | |
25767378 IK |
712 | if (!oz_mode) { |
713 | spin_lock(&dentry->d_lock); | |
714 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | |
715 | spin_unlock(&dentry->d_lock); | |
716 | } | |
1da177e4 LT |
717 | } |
718 | ||
719 | /* | |
720 | * If this dentry is unhashed, then we shouldn't honour this | |
c9ffec48 IK |
721 | * lookup. Returning ENOENT here doesn't do the right thing |
722 | * for all system calls, but it should be OK for the operations | |
723 | * we permit from an autofs. | |
1da177e4 | 724 | */ |
1864f7bd | 725 | if (!oz_mode && d_unhashed(dentry)) { |
c9ffec48 IK |
726 | /* |
727 | * A user space application can (and has done in the past) | |
728 | * remove and re-create this directory during the callback. | |
729 | * This can leave us with an unhashed dentry, but a | |
730 | * successful mount! So we need to perform another | |
731 | * cached lookup in case the dentry now exists. | |
732 | */ | |
733 | struct dentry *parent = dentry->d_parent; | |
734 | struct dentry *new = d_lookup(parent, &dentry->d_name); | |
735 | if (new != NULL) | |
736 | dentry = new; | |
737 | else | |
738 | dentry = ERR_PTR(-ENOENT); | |
739 | ||
25767378 IK |
740 | if (unhashed) |
741 | dput(unhashed); | |
742 | ||
c9ffec48 | 743 | return dentry; |
f50b6f86 IK |
744 | } |
745 | ||
25767378 IK |
746 | if (unhashed) |
747 | return unhashed; | |
748 | ||
1da177e4 LT |
749 | return NULL; |
750 | } | |
751 | ||
752 | static int autofs4_dir_symlink(struct inode *dir, | |
753 | struct dentry *dentry, | |
754 | const char *symname) | |
755 | { | |
756 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | |
757 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
1aff3c8b | 758 | struct autofs_info *p_ino; |
1da177e4 LT |
759 | struct inode *inode; |
760 | char *cp; | |
761 | ||
762 | DPRINTK("%s <- %.*s", symname, | |
763 | dentry->d_name.len, dentry->d_name.name); | |
764 | ||
765 | if (!autofs4_oz_mode(sbi)) | |
766 | return -EACCES; | |
767 | ||
768 | ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555); | |
25767378 IK |
769 | if (!ino) |
770 | return -ENOMEM; | |
1da177e4 | 771 | |
25767378 IK |
772 | spin_lock(&sbi->lookup_lock); |
773 | if (!list_empty(&ino->active)) | |
774 | list_del_init(&ino->active); | |
775 | spin_unlock(&sbi->lookup_lock); | |
1da177e4 | 776 | |
ef581a74 | 777 | ino->size = strlen(symname); |
25767378 IK |
778 | cp = kmalloc(ino->size + 1, GFP_KERNEL); |
779 | if (!cp) { | |
780 | if (!dentry->d_fsdata) | |
781 | kfree(ino); | |
782 | return -ENOMEM; | |
1da177e4 LT |
783 | } |
784 | ||
785 | strcpy(cp, symname); | |
786 | ||
787 | inode = autofs4_get_inode(dir->i_sb, ino); | |
25767378 IK |
788 | if (!inode) { |
789 | kfree(cp); | |
790 | if (!dentry->d_fsdata) | |
791 | kfree(ino); | |
792 | return -ENOMEM; | |
793 | } | |
1864f7bd | 794 | d_add(dentry, inode); |
1da177e4 LT |
795 | |
796 | if (dir == dir->i_sb->s_root->d_inode) | |
797 | dentry->d_op = &autofs4_root_dentry_operations; | |
798 | else | |
799 | dentry->d_op = &autofs4_dentry_operations; | |
800 | ||
801 | dentry->d_fsdata = ino; | |
802 | ino->dentry = dget(dentry); | |
1aff3c8b IK |
803 | atomic_inc(&ino->count); |
804 | p_ino = autofs4_dentry_ino(dentry->d_parent); | |
805 | if (p_ino && dentry->d_parent != dentry) | |
806 | atomic_inc(&p_ino->count); | |
1da177e4 LT |
807 | ino->inode = inode; |
808 | ||
25767378 | 809 | ino->u.symlink = cp; |
1da177e4 LT |
810 | dir->i_mtime = CURRENT_TIME; |
811 | ||
812 | return 0; | |
813 | } | |
814 | ||
815 | /* | |
816 | * NOTE! | |
817 | * | |
818 | * Normal filesystems would do a "d_delete()" to tell the VFS dcache | |
819 | * that the file no longer exists. However, doing that means that the | |
820 | * VFS layer can turn the dentry into a negative dentry. We don't want | |
f50b6f86 | 821 | * this, because the unlink is probably the result of an expire. |
5f6f4f28 IK |
822 | * We simply d_drop it and add it to a expiring list in the super block, |
823 | * which allows the dentry lookup to check for an incomplete expire. | |
1da177e4 LT |
824 | * |
825 | * If a process is blocked on the dentry waiting for the expire to finish, | |
826 | * it will invalidate the dentry and try to mount with a new one. | |
827 | * | |
828 | * Also see autofs4_dir_rmdir().. | |
829 | */ | |
830 | static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry) | |
831 | { | |
832 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | |
833 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
1aff3c8b | 834 | struct autofs_info *p_ino; |
1da177e4 LT |
835 | |
836 | /* This allows root to remove symlinks */ | |
d78e53c8 | 837 | if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) |
1da177e4 LT |
838 | return -EACCES; |
839 | ||
1aff3c8b IK |
840 | if (atomic_dec_and_test(&ino->count)) { |
841 | p_ino = autofs4_dentry_ino(dentry->d_parent); | |
842 | if (p_ino && dentry->d_parent != dentry) | |
843 | atomic_dec(&p_ino->count); | |
844 | } | |
1da177e4 LT |
845 | dput(ino->dentry); |
846 | ||
847 | dentry->d_inode->i_size = 0; | |
ce71ec36 | 848 | clear_nlink(dentry->d_inode); |
1da177e4 LT |
849 | |
850 | dir->i_mtime = CURRENT_TIME; | |
851 | ||
f50b6f86 | 852 | spin_lock(&dcache_lock); |
5f6f4f28 | 853 | spin_lock(&sbi->lookup_lock); |
25767378 IK |
854 | if (list_empty(&ino->expiring)) |
855 | list_add(&ino->expiring, &sbi->expiring_list); | |
5f6f4f28 | 856 | spin_unlock(&sbi->lookup_lock); |
f50b6f86 IK |
857 | spin_lock(&dentry->d_lock); |
858 | __d_drop(dentry); | |
859 | spin_unlock(&dentry->d_lock); | |
860 | spin_unlock(&dcache_lock); | |
1da177e4 LT |
861 | |
862 | return 0; | |
863 | } | |
864 | ||
865 | static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) | |
866 | { | |
867 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | |
868 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
1aff3c8b | 869 | struct autofs_info *p_ino; |
1da177e4 | 870 | |
f50b6f86 IK |
871 | DPRINTK("dentry %p, removing %.*s", |
872 | dentry, dentry->d_name.len, dentry->d_name.name); | |
873 | ||
1da177e4 LT |
874 | if (!autofs4_oz_mode(sbi)) |
875 | return -EACCES; | |
876 | ||
877 | spin_lock(&dcache_lock); | |
878 | if (!list_empty(&dentry->d_subdirs)) { | |
879 | spin_unlock(&dcache_lock); | |
880 | return -ENOTEMPTY; | |
881 | } | |
5f6f4f28 | 882 | spin_lock(&sbi->lookup_lock); |
25767378 IK |
883 | if (list_empty(&ino->expiring)) |
884 | list_add(&ino->expiring, &sbi->expiring_list); | |
5f6f4f28 | 885 | spin_unlock(&sbi->lookup_lock); |
1da177e4 LT |
886 | spin_lock(&dentry->d_lock); |
887 | __d_drop(dentry); | |
888 | spin_unlock(&dentry->d_lock); | |
889 | spin_unlock(&dcache_lock); | |
890 | ||
1aff3c8b IK |
891 | if (atomic_dec_and_test(&ino->count)) { |
892 | p_ino = autofs4_dentry_ino(dentry->d_parent); | |
893 | if (p_ino && dentry->d_parent != dentry) | |
894 | atomic_dec(&p_ino->count); | |
895 | } | |
1da177e4 | 896 | dput(ino->dentry); |
1da177e4 | 897 | dentry->d_inode->i_size = 0; |
ce71ec36 | 898 | clear_nlink(dentry->d_inode); |
1da177e4 LT |
899 | |
900 | if (dir->i_nlink) | |
9a53c3a7 | 901 | drop_nlink(dir); |
1da177e4 LT |
902 | |
903 | return 0; | |
904 | } | |
905 | ||
906 | static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |
907 | { | |
908 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | |
909 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | |
1aff3c8b | 910 | struct autofs_info *p_ino; |
1da177e4 LT |
911 | struct inode *inode; |
912 | ||
d78e53c8 | 913 | if (!autofs4_oz_mode(sbi)) |
1da177e4 LT |
914 | return -EACCES; |
915 | ||
916 | DPRINTK("dentry %p, creating %.*s", | |
917 | dentry, dentry->d_name.len, dentry->d_name.name); | |
918 | ||
919 | ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); | |
25767378 IK |
920 | if (!ino) |
921 | return -ENOMEM; | |
922 | ||
923 | spin_lock(&sbi->lookup_lock); | |
924 | if (!list_empty(&ino->active)) | |
925 | list_del_init(&ino->active); | |
926 | spin_unlock(&sbi->lookup_lock); | |
1da177e4 LT |
927 | |
928 | inode = autofs4_get_inode(dir->i_sb, ino); | |
25767378 IK |
929 | if (!inode) { |
930 | if (!dentry->d_fsdata) | |
931 | kfree(ino); | |
932 | return -ENOMEM; | |
933 | } | |
1864f7bd | 934 | d_add(dentry, inode); |
1da177e4 LT |
935 | |
936 | if (dir == dir->i_sb->s_root->d_inode) | |
937 | dentry->d_op = &autofs4_root_dentry_operations; | |
938 | else | |
939 | dentry->d_op = &autofs4_dentry_operations; | |
940 | ||
941 | dentry->d_fsdata = ino; | |
942 | ino->dentry = dget(dentry); | |
1aff3c8b IK |
943 | atomic_inc(&ino->count); |
944 | p_ino = autofs4_dentry_ino(dentry->d_parent); | |
945 | if (p_ino && dentry->d_parent != dentry) | |
946 | atomic_inc(&p_ino->count); | |
1da177e4 | 947 | ino->inode = inode; |
d8c76e6f | 948 | inc_nlink(dir); |
1da177e4 LT |
949 | dir->i_mtime = CURRENT_TIME; |
950 | ||
951 | return 0; | |
952 | } | |
953 | ||
954 | /* Get/set timeout ioctl() operation */ | |
955 | static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi, | |
956 | unsigned long __user *p) | |
957 | { | |
958 | int rv; | |
959 | unsigned long ntimeout; | |
960 | ||
d78e53c8 SB |
961 | if ((rv = get_user(ntimeout, p)) || |
962 | (rv = put_user(sbi->exp_timeout/HZ, p))) | |
1da177e4 LT |
963 | return rv; |
964 | ||
d78e53c8 | 965 | if (ntimeout > ULONG_MAX/HZ) |
1da177e4 LT |
966 | sbi->exp_timeout = 0; |
967 | else | |
968 | sbi->exp_timeout = ntimeout * HZ; | |
969 | ||
970 | return 0; | |
971 | } | |
972 | ||
973 | /* Return protocol version */ | |
974 | static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p) | |
975 | { | |
976 | return put_user(sbi->version, p); | |
977 | } | |
978 | ||
979 | /* Return protocol sub version */ | |
980 | static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p) | |
981 | { | |
982 | return put_user(sbi->sub_version, p); | |
983 | } | |
984 | ||
985 | /* | |
986 | * Tells the daemon whether we need to reghost or not. Also, clears | |
987 | * the reghost_needed flag. | |
988 | */ | |
989 | static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p) | |
990 | { | |
991 | int status; | |
992 | ||
993 | DPRINTK("returning %d", sbi->needs_reghost); | |
994 | ||
995 | status = put_user(sbi->needs_reghost, p); | |
d78e53c8 | 996 | if (status) |
1da177e4 LT |
997 | return status; |
998 | ||
999 | sbi->needs_reghost = 0; | |
1000 | return 0; | |
1001 | } | |
1002 | ||
1003 | /* | |
1004 | * Enable / Disable reghosting ioctl() operation | |
1005 | */ | |
1006 | static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p) | |
1007 | { | |
1008 | int status; | |
1009 | int val; | |
1010 | ||
1011 | status = get_user(val, p); | |
1012 | ||
1013 | DPRINTK("reghost = %d", val); | |
1014 | ||
1015 | if (status) | |
1016 | return status; | |
1017 | ||
1018 | /* turn on/off reghosting, with the val */ | |
1019 | sbi->reghost_enabled = val; | |
1020 | return 0; | |
1021 | } | |
1022 | ||
1023 | /* | |
1024 | * Tells the daemon whether it can umount the autofs mount. | |
1025 | */ | |
1026 | static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p) | |
1027 | { | |
1028 | int status = 0; | |
1029 | ||
e3474a8e | 1030 | if (may_umount(mnt)) |
1da177e4 LT |
1031 | status = 1; |
1032 | ||
1033 | DPRINTK("returning %d", status); | |
1034 | ||
1035 | status = put_user(status, p); | |
1036 | ||
1037 | return status; | |
1038 | } | |
1039 | ||
1040 | /* Identify autofs4_dentries - this is so we can tell if there's | |
1041 | an extra dentry refcount or not. We only hold a refcount on the | |
1042 | dentry if its non-negative (ie, d_inode != NULL) | |
1043 | */ | |
1044 | int is_autofs4_dentry(struct dentry *dentry) | |
1045 | { | |
1046 | return dentry && dentry->d_inode && | |
1047 | (dentry->d_op == &autofs4_root_dentry_operations || | |
1048 | dentry->d_op == &autofs4_dentry_operations) && | |
1049 | dentry->d_fsdata != NULL; | |
1050 | } | |
1051 | ||
1052 | /* | |
1053 | * ioctl()'s on the root directory is the chief method for the daemon to | |
1054 | * generate kernel reactions | |
1055 | */ | |
1056 | static int autofs4_root_ioctl(struct inode *inode, struct file *filp, | |
1057 | unsigned int cmd, unsigned long arg) | |
1058 | { | |
1059 | struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb); | |
1060 | void __user *p = (void __user *)arg; | |
1061 | ||
1062 | DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u", | |
a47afb0f | 1063 | cmd,arg,sbi,task_pgrp_nr(current)); |
1da177e4 | 1064 | |
d78e53c8 SB |
1065 | if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) || |
1066 | _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT) | |
1da177e4 LT |
1067 | return -ENOTTY; |
1068 | ||
d78e53c8 | 1069 | if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) |
1da177e4 LT |
1070 | return -EPERM; |
1071 | ||
1072 | switch(cmd) { | |
1073 | case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */ | |
1074 | return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0); | |
1075 | case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */ | |
1076 | return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT); | |
1077 | case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */ | |
1078 | autofs4_catatonic_mode(sbi); | |
1079 | return 0; | |
1080 | case AUTOFS_IOC_PROTOVER: /* Get protocol version */ | |
1081 | return autofs4_get_protover(sbi, p); | |
1082 | case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */ | |
1083 | return autofs4_get_protosubver(sbi, p); | |
1084 | case AUTOFS_IOC_SETTIMEOUT: | |
1085 | return autofs4_get_set_timeout(sbi, p); | |
1086 | ||
1087 | case AUTOFS_IOC_TOGGLEREGHOST: | |
1088 | return autofs4_toggle_reghost(sbi, p); | |
1089 | case AUTOFS_IOC_ASKREGHOST: | |
1090 | return autofs4_ask_reghost(sbi, p); | |
1091 | ||
1092 | case AUTOFS_IOC_ASKUMOUNT: | |
a4669ed8 | 1093 | return autofs4_ask_umount(filp->f_path.mnt, p); |
1da177e4 LT |
1094 | |
1095 | /* return a single thing to expire */ | |
1096 | case AUTOFS_IOC_EXPIRE: | |
a4669ed8 | 1097 | return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p); |
1da177e4 LT |
1098 | /* same as above, but can send multiple expires through pipe */ |
1099 | case AUTOFS_IOC_EXPIRE_MULTI: | |
a4669ed8 | 1100 | return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p); |
1da177e4 LT |
1101 | |
1102 | default: | |
1103 | return -ENOSYS; | |
1104 | } | |
1105 | } |