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