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