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> |
| 20 | #include <linux/smp_lock.h> |
| 21 | #include "autofs_i.h" |
| 22 | |
| 23 | static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *); |
| 24 | static int autofs4_dir_unlink(struct inode *,struct dentry *); |
| 25 | static int autofs4_dir_rmdir(struct inode *,struct dentry *); |
| 26 | static int autofs4_dir_mkdir(struct inode *,struct dentry *,int); |
| 27 | static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long); |
| 28 | static int autofs4_dir_open(struct inode *inode, struct file *file); |
| 29 | static int autofs4_dir_close(struct inode *inode, struct file *file); |
| 30 | static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir); |
| 31 | static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir); |
| 32 | static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 33 | static void *autofs4_follow_link(struct dentry *, struct nameidata *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
| 45 | .release = autofs4_dir_close, |
| 46 | .read = generic_read_dir, |
| 47 | .readdir = autofs4_dir_readdir, |
| 48 | }; |
| 49 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 50 | 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 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 58 | struct inode_operations autofs4_direct_root_inode_operations = { |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | struct inode_operations autofs4_dir_inode_operations = { |
| 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 | { |
| 77 | struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb); |
| 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 | { |
| 98 | struct dentry *dentry = file->f_dentry; |
| 99 | struct vfsmount *mnt = file->f_vfsmnt; |
| 100 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 101 | struct dentry *cursor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | int status; |
| 103 | |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 104 | status = dcache_dir_open(inode, file); |
| 105 | if (status) |
| 106 | goto out; |
| 107 | |
| 108 | cursor = file->private_data; |
| 109 | cursor->d_fsdata = NULL; |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | DPRINTK("file=%p dentry=%p %.*s", |
| 112 | file, dentry, dentry->d_name.len, dentry->d_name.name); |
| 113 | |
| 114 | if (autofs4_oz_mode(sbi)) |
| 115 | goto out; |
| 116 | |
| 117 | if (autofs4_ispending(dentry)) { |
| 118 | DPRINTK("dentry busy"); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 119 | dcache_dir_close(inode, file); |
| 120 | status = -EBUSY; |
| 121 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 124 | status = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { |
| 126 | struct nameidata nd; |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 127 | int empty, ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* In case there are stale directory dentrys from a failed mount */ |
| 130 | spin_lock(&dcache_lock); |
| 131 | empty = list_empty(&dentry->d_subdirs); |
| 132 | spin_unlock(&dcache_lock); |
| 133 | |
| 134 | if (!empty) |
| 135 | d_invalidate(dentry); |
| 136 | |
| 137 | nd.flags = LOOKUP_DIRECTORY; |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 138 | ret = (dentry->d_op->d_revalidate)(dentry, &nd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 140 | if (!ret) { |
| 141 | dcache_dir_close(inode, file); |
| 142 | goto out; |
| 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | if (d_mountpoint(dentry)) { |
| 147 | struct file *fp = NULL; |
| 148 | struct vfsmount *fp_mnt = mntget(mnt); |
| 149 | struct dentry *fp_dentry = dget(dentry); |
| 150 | |
Ian Kent | 9b1e3af | 2005-06-21 17:16:38 -0700 | [diff] [blame] | 151 | if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) { |
| 152 | dput(fp_dentry); |
| 153 | mntput(fp_mnt); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 154 | dcache_dir_close(inode, file); |
| 155 | goto out; |
Ian Kent | 9b1e3af | 2005-06-21 17:16:38 -0700 | [diff] [blame] | 156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); |
| 159 | status = PTR_ERR(fp); |
| 160 | if (IS_ERR(fp)) { |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 161 | dcache_dir_close(inode, file); |
| 162 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 164 | cursor->d_fsdata = fp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return 0; |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 167 | out: |
| 168 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static int autofs4_dir_close(struct inode *inode, struct file *file) |
| 172 | { |
| 173 | struct dentry *dentry = file->f_dentry; |
| 174 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 175 | struct dentry *cursor = file->private_data; |
| 176 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | DPRINTK("file=%p dentry=%p %.*s", |
| 179 | file, dentry, dentry->d_name.len, dentry->d_name.name); |
| 180 | |
| 181 | if (autofs4_oz_mode(sbi)) |
| 182 | goto out; |
| 183 | |
| 184 | if (autofs4_ispending(dentry)) { |
| 185 | DPRINTK("dentry busy"); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 186 | status = -EBUSY; |
| 187 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | if (d_mountpoint(dentry)) { |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 191 | struct file *fp = cursor->d_fsdata; |
| 192 | if (!fp) { |
| 193 | status = -ENOENT; |
| 194 | goto out; |
| 195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | filp_close(fp, current->files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | out: |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 199 | dcache_dir_close(inode, file); |
| 200 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) |
| 204 | { |
| 205 | struct dentry *dentry = file->f_dentry; |
| 206 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 207 | struct dentry *cursor = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | int status; |
| 209 | |
| 210 | DPRINTK("file=%p dentry=%p %.*s", |
| 211 | file, dentry, dentry->d_name.len, dentry->d_name.name); |
| 212 | |
| 213 | if (autofs4_oz_mode(sbi)) |
| 214 | goto out; |
| 215 | |
| 216 | if (autofs4_ispending(dentry)) { |
| 217 | DPRINTK("dentry busy"); |
| 218 | return -EBUSY; |
| 219 | } |
| 220 | |
| 221 | if (d_mountpoint(dentry)) { |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 222 | struct file *fp = cursor->d_fsdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | if (!fp) |
| 225 | return -ENOENT; |
| 226 | |
| 227 | if (!fp->f_op || !fp->f_op->readdir) |
| 228 | goto out; |
| 229 | |
| 230 | status = vfs_readdir(fp, filldir, dirent); |
| 231 | file->f_pos = fp->f_pos; |
| 232 | if (status) |
| 233 | autofs4_copy_atime(file, fp); |
| 234 | return status; |
| 235 | } |
| 236 | out: |
Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 237 | return dcache_readdir(file, dirent, filldir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 240 | static int try_to_fill_dentry(struct dentry *dentry, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 242 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 243 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | int status = 0; |
| 245 | |
| 246 | /* Block on any pending expiry here; invalidate the dentry |
| 247 | when expiration is done to trigger mount request with a new |
| 248 | dentry */ |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 249 | if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | DPRINTK("waiting for expire %p name=%.*s", |
| 251 | dentry, dentry->d_name.len, dentry->d_name.name); |
| 252 | |
| 253 | status = autofs4_wait(sbi, dentry, NFY_NONE); |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | DPRINTK("expire done status=%d", status); |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 256 | |
Ian Kent | 1684b2b | 2005-06-21 17:16:41 -0700 | [diff] [blame] | 257 | /* |
| 258 | * If the directory still exists the mount request must |
| 259 | * continue otherwise it can't be followed at the right |
| 260 | * time during the walk. |
| 261 | */ |
| 262 | status = d_invalidate(dentry); |
| 263 | if (status != -EBUSY) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 264 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | DPRINTK("dentry=%p %.*s ino=%p", |
| 268 | dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode); |
| 269 | |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 270 | /* |
| 271 | * Wait for a pending mount, triggering one if there |
| 272 | * isn't one already |
| 273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | if (dentry->d_inode == NULL) { |
| 275 | DPRINTK("waiting for mount name=%.*s", |
| 276 | dentry->d_name.len, dentry->d_name.name); |
| 277 | |
| 278 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | DPRINTK("mount done status=%d", status); |
| 281 | |
| 282 | if (status && dentry->d_inode) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 283 | return status; /* Try to get the kernel to invalidate this dentry */ |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* Turn this into a real negative dentry? */ |
| 286 | if (status == -ENOENT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | spin_lock(&dentry->d_lock); |
| 288 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 289 | spin_unlock(&dentry->d_lock); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 290 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } else if (status) { |
| 292 | /* Return a negative dentry, but leave it "pending" */ |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 293 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | /* Trigger mount for path component or follow link */ |
| 296 | } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) || |
| 297 | current->link_count) { |
| 298 | DPRINTK("waiting for mount name=%.*s", |
| 299 | dentry->d_name.len, dentry->d_name.name); |
| 300 | |
| 301 | spin_lock(&dentry->d_lock); |
| 302 | dentry->d_flags |= DCACHE_AUTOFS_PENDING; |
| 303 | spin_unlock(&dentry->d_lock); |
| 304 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); |
| 305 | |
| 306 | DPRINTK("mount done status=%d", status); |
| 307 | |
| 308 | if (status) { |
| 309 | spin_lock(&dentry->d_lock); |
| 310 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 311 | spin_unlock(&dentry->d_lock); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 312 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
Ian Kent | e0a7aae | 2006-03-27 01:14:47 -0800 | [diff] [blame] | 316 | /* Initialize expiry counter after successful mount */ |
| 317 | if (ino) |
| 318 | ino->last_used = jiffies; |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | spin_lock(&dentry->d_lock); |
| 321 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 322 | spin_unlock(&dentry->d_lock); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 323 | return status; |
| 324 | } |
| 325 | |
| 326 | /* For autofs direct mounts the follow link triggers the mount */ |
| 327 | static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 328 | { |
| 329 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 330 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 331 | int oz_mode = autofs4_oz_mode(sbi); |
| 332 | unsigned int lookup_type; |
| 333 | int status; |
| 334 | |
| 335 | DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d", |
| 336 | dentry, dentry->d_name.len, dentry->d_name.name, oz_mode, |
| 337 | nd->flags); |
| 338 | |
| 339 | /* If it's our master or we shouldn't trigger a mount we're done */ |
| 340 | lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY); |
| 341 | if (oz_mode || !lookup_type) |
| 342 | goto done; |
| 343 | |
Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 344 | /* If an expire request is pending wait for it. */ |
| 345 | if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { |
Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 346 | DPRINTK("waiting for active request %p name=%.*s", |
| 347 | dentry, dentry->d_name.len, dentry->d_name.name); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 348 | |
Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 349 | status = autofs4_wait(sbi, dentry, NFY_NONE); |
| 350 | |
| 351 | DPRINTK("request done status=%d", status); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 354 | /* |
| 355 | * If the dentry contains directories then it is an |
| 356 | * autofs multi-mount with no root mount offset. So |
| 357 | * don't try to mount it again. |
| 358 | */ |
| 359 | spin_lock(&dcache_lock); |
| 360 | if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { |
| 361 | spin_unlock(&dcache_lock); |
| 362 | |
| 363 | status = try_to_fill_dentry(dentry, 0); |
| 364 | if (status) |
| 365 | goto out_error; |
| 366 | |
| 367 | /* |
| 368 | * The mount succeeded but if there is no root mount |
| 369 | * it must be an autofs multi-mount with no root offset |
| 370 | * so we don't need to follow the mount. |
| 371 | */ |
| 372 | if (d_mountpoint(dentry)) { |
| 373 | if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) { |
| 374 | status = -ENOENT; |
| 375 | goto out_error; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | goto done; |
| 380 | } |
| 381 | spin_unlock(&dcache_lock); |
| 382 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 383 | done: |
| 384 | return NULL; |
| 385 | |
| 386 | out_error: |
| 387 | path_release(nd); |
| 388 | return ERR_PTR(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /* |
| 392 | * Revalidate is called on every cache lookup. Some of those |
| 393 | * cache lookups may actually happen while the dentry is not |
| 394 | * yet completely filled in, and revalidate has to delay such |
| 395 | * lookups.. |
| 396 | */ |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 397 | static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 399 | struct inode *dir = dentry->d_parent->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 401 | int oz_mode = autofs4_oz_mode(sbi); |
| 402 | int flags = nd ? nd->flags : 0; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 403 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | /* Pending dentry */ |
| 406 | if (autofs4_ispending(dentry)) { |
| 407 | if (!oz_mode) |
Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 408 | status = try_to_fill_dentry(dentry, flags); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 409 | return !status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* Negative dentry.. invalidate if "old" */ |
| 413 | if (dentry->d_inode == NULL) |
Ian Kent | 2d753e6 | 2006-03-27 01:14:44 -0800 | [diff] [blame] | 414 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | /* Check for a non-mountpoint directory with no contents */ |
| 417 | spin_lock(&dcache_lock); |
| 418 | if (S_ISDIR(dentry->d_inode->i_mode) && |
| 419 | !d_mountpoint(dentry) && |
Ian Kent | 90a59c7 | 2006-03-27 01:14:50 -0800 | [diff] [blame] | 420 | __simple_empty(dentry)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | DPRINTK("dentry=%p %.*s, emptydir", |
| 422 | dentry, dentry->d_name.len, dentry->d_name.name); |
| 423 | spin_unlock(&dcache_lock); |
| 424 | if (!oz_mode) |
Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 425 | status = try_to_fill_dentry(dentry, flags); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 426 | return !status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | spin_unlock(&dcache_lock); |
| 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | return 1; |
| 431 | } |
| 432 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 433 | void autofs4_dentry_release(struct dentry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
| 435 | struct autofs_info *inf; |
| 436 | |
| 437 | DPRINTK("releasing %p", de); |
| 438 | |
| 439 | inf = autofs4_dentry_ino(de); |
| 440 | de->d_fsdata = NULL; |
| 441 | |
| 442 | if (inf) { |
| 443 | inf->dentry = NULL; |
| 444 | inf->inode = NULL; |
| 445 | |
| 446 | autofs4_free_ino(inf); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /* For dentries of directories in the root dir */ |
| 451 | static struct dentry_operations autofs4_root_dentry_operations = { |
| 452 | .d_revalidate = autofs4_revalidate, |
| 453 | .d_release = autofs4_dentry_release, |
| 454 | }; |
| 455 | |
| 456 | /* For other dentries */ |
| 457 | static struct dentry_operations autofs4_dentry_operations = { |
| 458 | .d_revalidate = autofs4_revalidate, |
| 459 | .d_release = autofs4_dentry_release, |
| 460 | }; |
| 461 | |
| 462 | /* Lookups in the root directory */ |
| 463 | static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 464 | { |
| 465 | struct autofs_sb_info *sbi; |
| 466 | int oz_mode; |
| 467 | |
| 468 | DPRINTK("name = %.*s", |
| 469 | dentry->d_name.len, dentry->d_name.name); |
| 470 | |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 471 | /* File name too long to exist */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | if (dentry->d_name.len > NAME_MAX) |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 473 | return ERR_PTR(-ENAMETOOLONG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | sbi = autofs4_sbi(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | oz_mode = autofs4_oz_mode(sbi); |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", |
| 479 | current->pid, process_group(current), sbi->catatonic, oz_mode); |
| 480 | |
| 481 | /* |
| 482 | * Mark the dentry incomplete, but add it. This is needed so |
| 483 | * that the VFS layer knows about the dentry, and we can count |
| 484 | * on catching any lookups through the revalidate. |
| 485 | * |
| 486 | * Let all the hard work be done by the revalidate function that |
| 487 | * needs to be able to do this anyway.. |
| 488 | * |
| 489 | * We need to do this before we release the directory semaphore. |
| 490 | */ |
| 491 | dentry->d_op = &autofs4_root_dentry_operations; |
| 492 | |
| 493 | if (!oz_mode) { |
| 494 | spin_lock(&dentry->d_lock); |
| 495 | dentry->d_flags |= DCACHE_AUTOFS_PENDING; |
| 496 | spin_unlock(&dentry->d_lock); |
| 497 | } |
| 498 | dentry->d_fsdata = NULL; |
| 499 | d_add(dentry, NULL); |
| 500 | |
| 501 | if (dentry->d_op && dentry->d_op->d_revalidate) { |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 502 | mutex_unlock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | (dentry->d_op->d_revalidate)(dentry, nd); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 504 | mutex_lock(&dir->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* |
| 508 | * If we are still pending, check if we had to handle |
| 509 | * a signal. If so we can force a restart.. |
| 510 | */ |
| 511 | if (dentry->d_flags & DCACHE_AUTOFS_PENDING) { |
| 512 | /* See if we were interrupted */ |
| 513 | if (signal_pending(current)) { |
| 514 | sigset_t *sigset = ¤t->pending.signal; |
| 515 | if (sigismember (sigset, SIGKILL) || |
| 516 | sigismember (sigset, SIGQUIT) || |
| 517 | sigismember (sigset, SIGINT)) { |
| 518 | return ERR_PTR(-ERESTARTNOINTR); |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * If this dentry is unhashed, then we shouldn't honour this |
| 525 | * lookup even if the dentry is positive. Returning ENOENT here |
| 526 | * doesn't do the right thing for all system calls, but it should |
| 527 | * be OK for the operations we permit from an autofs. |
| 528 | */ |
Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 529 | if (dentry->d_inode && d_unhashed(dentry)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return ERR_PTR(-ENOENT); |
| 531 | |
| 532 | return NULL; |
| 533 | } |
| 534 | |
| 535 | static int autofs4_dir_symlink(struct inode *dir, |
| 536 | struct dentry *dentry, |
| 537 | const char *symname) |
| 538 | { |
| 539 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 540 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 541 | struct autofs_info *p_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | struct inode *inode; |
| 543 | char *cp; |
| 544 | |
| 545 | DPRINTK("%s <- %.*s", symname, |
| 546 | dentry->d_name.len, dentry->d_name.name); |
| 547 | |
| 548 | if (!autofs4_oz_mode(sbi)) |
| 549 | return -EACCES; |
| 550 | |
| 551 | ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555); |
| 552 | if (ino == NULL) |
| 553 | return -ENOSPC; |
| 554 | |
| 555 | ino->size = strlen(symname); |
| 556 | ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL); |
| 557 | |
| 558 | if (cp == NULL) { |
| 559 | kfree(ino); |
| 560 | return -ENOSPC; |
| 561 | } |
| 562 | |
| 563 | strcpy(cp, symname); |
| 564 | |
| 565 | inode = autofs4_get_inode(dir->i_sb, ino); |
| 566 | d_instantiate(dentry, inode); |
| 567 | |
| 568 | if (dir == dir->i_sb->s_root->d_inode) |
| 569 | dentry->d_op = &autofs4_root_dentry_operations; |
| 570 | else |
| 571 | dentry->d_op = &autofs4_dentry_operations; |
| 572 | |
| 573 | dentry->d_fsdata = ino; |
| 574 | ino->dentry = dget(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 575 | atomic_inc(&ino->count); |
| 576 | p_ino = autofs4_dentry_ino(dentry->d_parent); |
| 577 | if (p_ino && dentry->d_parent != dentry) |
| 578 | atomic_inc(&p_ino->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | ino->inode = inode; |
| 580 | |
| 581 | dir->i_mtime = CURRENT_TIME; |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * NOTE! |
| 588 | * |
| 589 | * Normal filesystems would do a "d_delete()" to tell the VFS dcache |
| 590 | * that the file no longer exists. However, doing that means that the |
| 591 | * VFS layer can turn the dentry into a negative dentry. We don't want |
| 592 | * this, because since the unlink is probably the result of an expire. |
| 593 | * We simply d_drop it, which allows the dentry lookup to remount it |
| 594 | * if necessary. |
| 595 | * |
| 596 | * If a process is blocked on the dentry waiting for the expire to finish, |
| 597 | * it will invalidate the dentry and try to mount with a new one. |
| 598 | * |
| 599 | * Also see autofs4_dir_rmdir().. |
| 600 | */ |
| 601 | static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry) |
| 602 | { |
| 603 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 604 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 605 | struct autofs_info *p_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /* This allows root to remove symlinks */ |
| 608 | if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) ) |
| 609 | return -EACCES; |
| 610 | |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 611 | if (atomic_dec_and_test(&ino->count)) { |
| 612 | p_ino = autofs4_dentry_ino(dentry->d_parent); |
| 613 | if (p_ino && dentry->d_parent != dentry) |
| 614 | atomic_dec(&p_ino->count); |
| 615 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | dput(ino->dentry); |
| 617 | |
| 618 | dentry->d_inode->i_size = 0; |
| 619 | dentry->d_inode->i_nlink = 0; |
| 620 | |
| 621 | dir->i_mtime = CURRENT_TIME; |
| 622 | |
| 623 | d_drop(dentry); |
| 624 | |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) |
| 629 | { |
| 630 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 631 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 632 | struct autofs_info *p_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | if (!autofs4_oz_mode(sbi)) |
| 635 | return -EACCES; |
| 636 | |
| 637 | spin_lock(&dcache_lock); |
| 638 | if (!list_empty(&dentry->d_subdirs)) { |
| 639 | spin_unlock(&dcache_lock); |
| 640 | return -ENOTEMPTY; |
| 641 | } |
| 642 | spin_lock(&dentry->d_lock); |
| 643 | __d_drop(dentry); |
| 644 | spin_unlock(&dentry->d_lock); |
| 645 | spin_unlock(&dcache_lock); |
| 646 | |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 647 | if (atomic_dec_and_test(&ino->count)) { |
| 648 | p_ino = autofs4_dentry_ino(dentry->d_parent); |
| 649 | if (p_ino && dentry->d_parent != dentry) |
| 650 | atomic_dec(&p_ino->count); |
| 651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | dput(ino->dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | dentry->d_inode->i_size = 0; |
| 654 | dentry->d_inode->i_nlink = 0; |
| 655 | |
| 656 | if (dir->i_nlink) |
| 657 | dir->i_nlink--; |
| 658 | |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
| 663 | { |
| 664 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 665 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 666 | struct autofs_info *p_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | struct inode *inode; |
| 668 | |
| 669 | if ( !autofs4_oz_mode(sbi) ) |
| 670 | return -EACCES; |
| 671 | |
| 672 | DPRINTK("dentry %p, creating %.*s", |
| 673 | dentry, dentry->d_name.len, dentry->d_name.name); |
| 674 | |
| 675 | ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); |
| 676 | if (ino == NULL) |
| 677 | return -ENOSPC; |
| 678 | |
| 679 | inode = autofs4_get_inode(dir->i_sb, ino); |
| 680 | d_instantiate(dentry, inode); |
| 681 | |
| 682 | if (dir == dir->i_sb->s_root->d_inode) |
| 683 | dentry->d_op = &autofs4_root_dentry_operations; |
| 684 | else |
| 685 | dentry->d_op = &autofs4_dentry_operations; |
| 686 | |
| 687 | dentry->d_fsdata = ino; |
| 688 | ino->dentry = dget(dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 689 | atomic_inc(&ino->count); |
| 690 | p_ino = autofs4_dentry_ino(dentry->d_parent); |
| 691 | if (p_ino && dentry->d_parent != dentry) |
| 692 | atomic_inc(&p_ino->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | ino->inode = inode; |
| 694 | dir->i_nlink++; |
| 695 | dir->i_mtime = CURRENT_TIME; |
| 696 | |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | /* Get/set timeout ioctl() operation */ |
| 701 | static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi, |
| 702 | unsigned long __user *p) |
| 703 | { |
| 704 | int rv; |
| 705 | unsigned long ntimeout; |
| 706 | |
| 707 | if ( (rv = get_user(ntimeout, p)) || |
| 708 | (rv = put_user(sbi->exp_timeout/HZ, p)) ) |
| 709 | return rv; |
| 710 | |
| 711 | if ( ntimeout > ULONG_MAX/HZ ) |
| 712 | sbi->exp_timeout = 0; |
| 713 | else |
| 714 | sbi->exp_timeout = ntimeout * HZ; |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
| 719 | /* Return protocol version */ |
| 720 | static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p) |
| 721 | { |
| 722 | return put_user(sbi->version, p); |
| 723 | } |
| 724 | |
| 725 | /* Return protocol sub version */ |
| 726 | static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p) |
| 727 | { |
| 728 | return put_user(sbi->sub_version, p); |
| 729 | } |
| 730 | |
| 731 | /* |
| 732 | * Tells the daemon whether we need to reghost or not. Also, clears |
| 733 | * the reghost_needed flag. |
| 734 | */ |
| 735 | static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p) |
| 736 | { |
| 737 | int status; |
| 738 | |
| 739 | DPRINTK("returning %d", sbi->needs_reghost); |
| 740 | |
| 741 | status = put_user(sbi->needs_reghost, p); |
| 742 | if ( status ) |
| 743 | return status; |
| 744 | |
| 745 | sbi->needs_reghost = 0; |
| 746 | return 0; |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Enable / Disable reghosting ioctl() operation |
| 751 | */ |
| 752 | static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p) |
| 753 | { |
| 754 | int status; |
| 755 | int val; |
| 756 | |
| 757 | status = get_user(val, p); |
| 758 | |
| 759 | DPRINTK("reghost = %d", val); |
| 760 | |
| 761 | if (status) |
| 762 | return status; |
| 763 | |
| 764 | /* turn on/off reghosting, with the val */ |
| 765 | sbi->reghost_enabled = val; |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | * Tells the daemon whether it can umount the autofs mount. |
| 771 | */ |
| 772 | static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p) |
| 773 | { |
| 774 | int status = 0; |
| 775 | |
Ian Kent | e3474a8 | 2006-03-27 01:14:51 -0800 | [diff] [blame] | 776 | if (may_umount(mnt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | status = 1; |
| 778 | |
| 779 | DPRINTK("returning %d", status); |
| 780 | |
| 781 | status = put_user(status, p); |
| 782 | |
| 783 | return status; |
| 784 | } |
| 785 | |
| 786 | /* Identify autofs4_dentries - this is so we can tell if there's |
| 787 | an extra dentry refcount or not. We only hold a refcount on the |
| 788 | dentry if its non-negative (ie, d_inode != NULL) |
| 789 | */ |
| 790 | int is_autofs4_dentry(struct dentry *dentry) |
| 791 | { |
| 792 | return dentry && dentry->d_inode && |
| 793 | (dentry->d_op == &autofs4_root_dentry_operations || |
| 794 | dentry->d_op == &autofs4_dentry_operations) && |
| 795 | dentry->d_fsdata != NULL; |
| 796 | } |
| 797 | |
| 798 | /* |
| 799 | * ioctl()'s on the root directory is the chief method for the daemon to |
| 800 | * generate kernel reactions |
| 801 | */ |
| 802 | static int autofs4_root_ioctl(struct inode *inode, struct file *filp, |
| 803 | unsigned int cmd, unsigned long arg) |
| 804 | { |
| 805 | struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb); |
| 806 | void __user *p = (void __user *)arg; |
| 807 | |
| 808 | DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u", |
| 809 | cmd,arg,sbi,process_group(current)); |
| 810 | |
| 811 | if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) || |
| 812 | _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT ) |
| 813 | return -ENOTTY; |
| 814 | |
| 815 | if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) ) |
| 816 | return -EPERM; |
| 817 | |
| 818 | switch(cmd) { |
| 819 | case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */ |
| 820 | return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0); |
| 821 | case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */ |
| 822 | return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT); |
| 823 | case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */ |
| 824 | autofs4_catatonic_mode(sbi); |
| 825 | return 0; |
| 826 | case AUTOFS_IOC_PROTOVER: /* Get protocol version */ |
| 827 | return autofs4_get_protover(sbi, p); |
| 828 | case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */ |
| 829 | return autofs4_get_protosubver(sbi, p); |
| 830 | case AUTOFS_IOC_SETTIMEOUT: |
| 831 | return autofs4_get_set_timeout(sbi, p); |
| 832 | |
| 833 | case AUTOFS_IOC_TOGGLEREGHOST: |
| 834 | return autofs4_toggle_reghost(sbi, p); |
| 835 | case AUTOFS_IOC_ASKREGHOST: |
| 836 | return autofs4_ask_reghost(sbi, p); |
| 837 | |
| 838 | case AUTOFS_IOC_ASKUMOUNT: |
| 839 | return autofs4_ask_umount(filp->f_vfsmnt, p); |
| 840 | |
| 841 | /* return a single thing to expire */ |
| 842 | case AUTOFS_IOC_EXPIRE: |
| 843 | return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi, p); |
| 844 | /* same as above, but can send multiple expires through pipe */ |
| 845 | case AUTOFS_IOC_EXPIRE_MULTI: |
| 846 | return autofs4_expire_multi(inode->i_sb,filp->f_vfsmnt,sbi, p); |
| 847 | |
| 848 | default: |
| 849 | return -ENOSYS; |
| 850 | } |
| 851 | } |