diff options
| author | Jeff Garzik <jeff@garzik.org> | 2006-03-29 19:58:22 -0500 |
|---|---|---|
| committer | Jeff Garzik <jeff@garzik.org> | 2006-03-29 19:58:22 -0500 |
| commit | 79072f38909e3d9883317238887460c39ddcc4cb (patch) | |
| tree | 28369f5a844535ff836565eefd62695b0e890fa3 /fs/autofs4/root.c | |
| parent | 200d5a7684cc49ef4be40e832daf3f217e70dfbb (diff) | |
| parent | 55d8ca4f8094246da6e71889a4e04bfafaa78b10 (diff) | |
Merge branch 'upstream'
Diffstat (limited to 'fs/autofs4/root.c')
| -rw-r--r-- | fs/autofs4/root.c | 328 |
1 files changed, 180 insertions, 148 deletions
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c index 62d8d4acb8bb..84e030c8ddd0 100644 --- a/fs/autofs4/root.c +++ b/fs/autofs4/root.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | * | 4 | * |
| 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved | 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved |
| 6 | * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org> | 6 | * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org> |
| 7 | * Copyright 2001-2003 Ian Kent <raven@themaw.net> | 7 | * Copyright 2001-2006 Ian Kent <raven@themaw.net> |
| 8 | * | 8 | * |
| 9 | * This file is part of the Linux kernel and is made available under | 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 | 10 | * the terms of the GNU General Public License, version 2, or at your |
| @@ -30,9 +30,9 @@ 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); | 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); | 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 *); | 32 | static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); |
| 33 | static int autofs4_dcache_readdir(struct file *, void *, filldir_t); | 33 | static void *autofs4_follow_link(struct dentry *, struct nameidata *); |
| 34 | 34 | ||
| 35 | struct file_operations autofs4_root_operations = { | 35 | const struct file_operations autofs4_root_operations = { |
| 36 | .open = dcache_dir_open, | 36 | .open = dcache_dir_open, |
| 37 | .release = dcache_dir_close, | 37 | .release = dcache_dir_close, |
| 38 | .read = generic_read_dir, | 38 | .read = generic_read_dir, |
| @@ -40,14 +40,14 @@ struct file_operations autofs4_root_operations = { | |||
| 40 | .ioctl = autofs4_root_ioctl, | 40 | .ioctl = autofs4_root_ioctl, |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | struct file_operations autofs4_dir_operations = { | 43 | const struct file_operations autofs4_dir_operations = { |
| 44 | .open = autofs4_dir_open, | 44 | .open = autofs4_dir_open, |
| 45 | .release = autofs4_dir_close, | 45 | .release = autofs4_dir_close, |
| 46 | .read = generic_read_dir, | 46 | .read = generic_read_dir, |
| 47 | .readdir = autofs4_dir_readdir, | 47 | .readdir = autofs4_dir_readdir, |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | struct inode_operations autofs4_root_inode_operations = { | 50 | struct inode_operations autofs4_indirect_root_inode_operations = { |
| 51 | .lookup = autofs4_lookup, | 51 | .lookup = autofs4_lookup, |
| 52 | .unlink = autofs4_dir_unlink, | 52 | .unlink = autofs4_dir_unlink, |
| 53 | .symlink = autofs4_dir_symlink, | 53 | .symlink = autofs4_dir_symlink, |
| @@ -55,6 +55,14 @@ struct inode_operations autofs4_root_inode_operations = { | |||
| 55 | .rmdir = autofs4_dir_rmdir, | 55 | .rmdir = autofs4_dir_rmdir, |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | struct inode_operations autofs4_direct_root_inode_operations = { | ||
| 59 | .lookup = autofs4_lookup, | ||
| 60 | .unlink = autofs4_dir_unlink, | ||
| 61 | .mkdir = autofs4_dir_mkdir, | ||
| 62 | .rmdir = autofs4_dir_rmdir, | ||
| 63 | .follow_link = autofs4_follow_link, | ||
| 64 | }; | ||
| 65 | |||
| 58 | struct inode_operations autofs4_dir_inode_operations = { | 66 | struct inode_operations autofs4_dir_inode_operations = { |
| 59 | .lookup = autofs4_lookup, | 67 | .lookup = autofs4_lookup, |
| 60 | .unlink = autofs4_dir_unlink, | 68 | .unlink = autofs4_dir_unlink, |
| @@ -82,87 +90,7 @@ static int autofs4_root_readdir(struct file *file, void *dirent, | |||
| 82 | 90 | ||
| 83 | DPRINTK("needs_reghost = %d", sbi->needs_reghost); | 91 | DPRINTK("needs_reghost = %d", sbi->needs_reghost); |
| 84 | 92 | ||
| 85 | return autofs4_dcache_readdir(file, dirent, filldir); | 93 | return dcache_readdir(file, dirent, filldir); |
| 86 | } | ||
| 87 | |||
| 88 | /* Update usage from here to top of tree, so that scan of | ||
| 89 | top-level directories will give a useful result */ | ||
| 90 | static void autofs4_update_usage(struct vfsmount *mnt, struct dentry *dentry) | ||
| 91 | { | ||
| 92 | struct dentry *top = dentry->d_sb->s_root; | ||
| 93 | |||
| 94 | spin_lock(&dcache_lock); | ||
| 95 | for(; dentry != top; dentry = dentry->d_parent) { | ||
| 96 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | ||
| 97 | |||
| 98 | if (ino) { | ||
| 99 | touch_atime(mnt, dentry); | ||
| 100 | ino->last_used = jiffies; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | spin_unlock(&dcache_lock); | ||
| 104 | } | ||
| 105 | |||
| 106 | /* | ||
| 107 | * From 2.4 kernel readdir.c | ||
| 108 | */ | ||
| 109 | static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) | ||
| 110 | { | ||
| 111 | int i; | ||
| 112 | struct dentry *dentry = filp->f_dentry; | ||
| 113 | |||
| 114 | i = filp->f_pos; | ||
| 115 | switch (i) { | ||
| 116 | case 0: | ||
| 117 | if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0) | ||
| 118 | break; | ||
| 119 | i++; | ||
| 120 | filp->f_pos++; | ||
| 121 | /* fallthrough */ | ||
| 122 | case 1: | ||
| 123 | if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) | ||
| 124 | break; | ||
| 125 | i++; | ||
| 126 | filp->f_pos++; | ||
| 127 | /* fallthrough */ | ||
| 128 | default: { | ||
| 129 | struct list_head *list; | ||
| 130 | int j = i-2; | ||
| 131 | |||
| 132 | spin_lock(&dcache_lock); | ||
| 133 | list = dentry->d_subdirs.next; | ||
| 134 | |||
| 135 | for (;;) { | ||
| 136 | if (list == &dentry->d_subdirs) { | ||
| 137 | spin_unlock(&dcache_lock); | ||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | if (!j) | ||
| 141 | break; | ||
| 142 | j--; | ||
| 143 | list = list->next; | ||
| 144 | } | ||
| 145 | |||
| 146 | while(1) { | ||
| 147 | struct dentry *de = list_entry(list, | ||
| 148 | struct dentry, d_u.d_child); | ||
| 149 | |||
| 150 | if (!d_unhashed(de) && de->d_inode) { | ||
| 151 | spin_unlock(&dcache_lock); | ||
| 152 | if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0) | ||
| 153 | break; | ||
| 154 | spin_lock(&dcache_lock); | ||
| 155 | } | ||
| 156 | filp->f_pos++; | ||
| 157 | list = list->next; | ||
| 158 | if (list != &dentry->d_subdirs) | ||
| 159 | continue; | ||
| 160 | spin_unlock(&dcache_lock); | ||
| 161 | break; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | } | ||
| 165 | return 0; | ||
| 166 | } | 94 | } |
| 167 | 95 | ||
| 168 | static int autofs4_dir_open(struct inode *inode, struct file *file) | 96 | static int autofs4_dir_open(struct inode *inode, struct file *file) |
| @@ -170,8 +98,16 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) | |||
| 170 | struct dentry *dentry = file->f_dentry; | 98 | struct dentry *dentry = file->f_dentry; |
| 171 | struct vfsmount *mnt = file->f_vfsmnt; | 99 | struct vfsmount *mnt = file->f_vfsmnt; |
| 172 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 100 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 101 | struct dentry *cursor; | ||
| 173 | int status; | 102 | int status; |
| 174 | 103 | ||
| 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 | |||
| 175 | DPRINTK("file=%p dentry=%p %.*s", | 111 | DPRINTK("file=%p dentry=%p %.*s", |
| 176 | file, dentry, dentry->d_name.len, dentry->d_name.name); | 112 | file, dentry, dentry->d_name.len, dentry->d_name.name); |
| 177 | 113 | ||
| @@ -180,12 +116,15 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) | |||
| 180 | 116 | ||
| 181 | if (autofs4_ispending(dentry)) { | 117 | if (autofs4_ispending(dentry)) { |
| 182 | DPRINTK("dentry busy"); | 118 | DPRINTK("dentry busy"); |
| 183 | return -EBUSY; | 119 | dcache_dir_close(inode, file); |
| 120 | status = -EBUSY; | ||
| 121 | goto out; | ||
| 184 | } | 122 | } |
| 185 | 123 | ||
| 124 | status = -ENOENT; | ||
| 186 | if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { | 125 | if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { |
| 187 | struct nameidata nd; | 126 | struct nameidata nd; |
| 188 | int empty; | 127 | int empty, ret; |
| 189 | 128 | ||
| 190 | /* In case there are stale directory dentrys from a failed mount */ | 129 | /* In case there are stale directory dentrys from a failed mount */ |
| 191 | spin_lock(&dcache_lock); | 130 | spin_lock(&dcache_lock); |
| @@ -195,13 +134,13 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) | |||
| 195 | if (!empty) | 134 | if (!empty) |
| 196 | d_invalidate(dentry); | 135 | d_invalidate(dentry); |
| 197 | 136 | ||
| 198 | nd.dentry = dentry; | ||
| 199 | nd.mnt = mnt; | ||
| 200 | nd.flags = LOOKUP_DIRECTORY; | 137 | nd.flags = LOOKUP_DIRECTORY; |
| 201 | status = (dentry->d_op->d_revalidate)(dentry, &nd); | 138 | ret = (dentry->d_op->d_revalidate)(dentry, &nd); |
| 202 | 139 | ||
| 203 | if (!status) | 140 | if (!ret) { |
| 204 | return -ENOENT; | 141 | dcache_dir_close(inode, file); |
| 142 | goto out; | ||
| 143 | } | ||
| 205 | } | 144 | } |
| 206 | 145 | ||
| 207 | if (d_mountpoint(dentry)) { | 146 | if (d_mountpoint(dentry)) { |
| @@ -212,25 +151,29 @@ static int autofs4_dir_open(struct inode *inode, struct file *file) | |||
| 212 | if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) { | 151 | if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) { |
| 213 | dput(fp_dentry); | 152 | dput(fp_dentry); |
| 214 | mntput(fp_mnt); | 153 | mntput(fp_mnt); |
| 215 | return -ENOENT; | 154 | dcache_dir_close(inode, file); |
| 155 | goto out; | ||
| 216 | } | 156 | } |
| 217 | 157 | ||
| 218 | fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); | 158 | fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); |
| 219 | status = PTR_ERR(fp); | 159 | status = PTR_ERR(fp); |
| 220 | if (IS_ERR(fp)) { | 160 | if (IS_ERR(fp)) { |
| 221 | file->private_data = NULL; | 161 | dcache_dir_close(inode, file); |
| 222 | return status; | 162 | goto out; |
| 223 | } | 163 | } |
| 224 | file->private_data = fp; | 164 | cursor->d_fsdata = fp; |
| 225 | } | 165 | } |
| 226 | out: | ||
| 227 | return 0; | 166 | return 0; |
| 167 | out: | ||
| 168 | return status; | ||
| 228 | } | 169 | } |
| 229 | 170 | ||
| 230 | static int autofs4_dir_close(struct inode *inode, struct file *file) | 171 | static int autofs4_dir_close(struct inode *inode, struct file *file) |
| 231 | { | 172 | { |
| 232 | struct dentry *dentry = file->f_dentry; | 173 | struct dentry *dentry = file->f_dentry; |
| 233 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 174 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 175 | struct dentry *cursor = file->private_data; | ||
| 176 | int status = 0; | ||
| 234 | 177 | ||
| 235 | DPRINTK("file=%p dentry=%p %.*s", | 178 | DPRINTK("file=%p dentry=%p %.*s", |
| 236 | file, dentry, dentry->d_name.len, dentry->d_name.name); | 179 | file, dentry, dentry->d_name.len, dentry->d_name.name); |
| @@ -240,26 +183,28 @@ static int autofs4_dir_close(struct inode *inode, struct file *file) | |||
| 240 | 183 | ||
| 241 | if (autofs4_ispending(dentry)) { | 184 | if (autofs4_ispending(dentry)) { |
| 242 | DPRINTK("dentry busy"); | 185 | DPRINTK("dentry busy"); |
| 243 | return -EBUSY; | 186 | status = -EBUSY; |
| 187 | goto out; | ||
| 244 | } | 188 | } |
| 245 | 189 | ||
| 246 | if (d_mountpoint(dentry)) { | 190 | if (d_mountpoint(dentry)) { |
| 247 | struct file *fp = file->private_data; | 191 | struct file *fp = cursor->d_fsdata; |
| 248 | 192 | if (!fp) { | |
| 249 | if (!fp) | 193 | status = -ENOENT; |
| 250 | return -ENOENT; | 194 | goto out; |
| 251 | 195 | } | |
| 252 | filp_close(fp, current->files); | 196 | filp_close(fp, current->files); |
| 253 | file->private_data = NULL; | ||
| 254 | } | 197 | } |
| 255 | out: | 198 | out: |
| 256 | return 0; | 199 | dcache_dir_close(inode, file); |
| 200 | return status; | ||
| 257 | } | 201 | } |
| 258 | 202 | ||
| 259 | static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) | 203 | static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) |
| 260 | { | 204 | { |
| 261 | struct dentry *dentry = file->f_dentry; | 205 | struct dentry *dentry = file->f_dentry; |
| 262 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 206 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 207 | struct dentry *cursor = file->private_data; | ||
| 263 | int status; | 208 | int status; |
| 264 | 209 | ||
| 265 | DPRINTK("file=%p dentry=%p %.*s", | 210 | DPRINTK("file=%p dentry=%p %.*s", |
| @@ -274,7 +219,7 @@ static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldi | |||
| 274 | } | 219 | } |
| 275 | 220 | ||
| 276 | if (d_mountpoint(dentry)) { | 221 | if (d_mountpoint(dentry)) { |
| 277 | struct file *fp = file->private_data; | 222 | struct file *fp = cursor->d_fsdata; |
| 278 | 223 | ||
| 279 | if (!fp) | 224 | if (!fp) |
| 280 | return -ENOENT; | 225 | return -ENOENT; |
| @@ -289,27 +234,26 @@ static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldi | |||
| 289 | return status; | 234 | return status; |
| 290 | } | 235 | } |
| 291 | out: | 236 | out: |
| 292 | return autofs4_dcache_readdir(file, dirent, filldir); | 237 | return dcache_readdir(file, dirent, filldir); |
| 293 | } | 238 | } |
| 294 | 239 | ||
| 295 | static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int flags) | 240 | static int try_to_fill_dentry(struct dentry *dentry, int flags) |
| 296 | { | 241 | { |
| 297 | struct super_block *sb = mnt->mnt_sb; | 242 | struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); |
| 298 | struct autofs_sb_info *sbi = autofs4_sbi(sb); | 243 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 299 | struct autofs_info *de_info = autofs4_dentry_ino(dentry); | ||
| 300 | int status = 0; | 244 | int status = 0; |
| 301 | 245 | ||
| 302 | /* Block on any pending expiry here; invalidate the dentry | 246 | /* Block on any pending expiry here; invalidate the dentry |
| 303 | when expiration is done to trigger mount request with a new | 247 | when expiration is done to trigger mount request with a new |
| 304 | dentry */ | 248 | dentry */ |
| 305 | if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) { | 249 | if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { |
| 306 | DPRINTK("waiting for expire %p name=%.*s", | 250 | DPRINTK("waiting for expire %p name=%.*s", |
| 307 | dentry, dentry->d_name.len, dentry->d_name.name); | 251 | dentry, dentry->d_name.len, dentry->d_name.name); |
| 308 | 252 | ||
| 309 | status = autofs4_wait(sbi, dentry, NFY_NONE); | 253 | status = autofs4_wait(sbi, dentry, NFY_NONE); |
| 310 | 254 | ||
| 311 | DPRINTK("expire done status=%d", status); | 255 | DPRINTK("expire done status=%d", status); |
| 312 | 256 | ||
| 313 | /* | 257 | /* |
| 314 | * If the directory still exists the mount request must | 258 | * If the directory still exists the mount request must |
| 315 | * continue otherwise it can't be followed at the right | 259 | * continue otherwise it can't be followed at the right |
| @@ -317,34 +261,36 @@ static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int f | |||
| 317 | */ | 261 | */ |
| 318 | status = d_invalidate(dentry); | 262 | status = d_invalidate(dentry); |
| 319 | if (status != -EBUSY) | 263 | if (status != -EBUSY) |
| 320 | return 0; | 264 | return -ENOENT; |
| 321 | } | 265 | } |
| 322 | 266 | ||
| 323 | DPRINTK("dentry=%p %.*s ino=%p", | 267 | DPRINTK("dentry=%p %.*s ino=%p", |
| 324 | dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode); | 268 | dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode); |
| 325 | 269 | ||
| 326 | /* Wait for a pending mount, triggering one if there isn't one already */ | 270 | /* |
| 271 | * Wait for a pending mount, triggering one if there | ||
| 272 | * isn't one already | ||
| 273 | */ | ||
| 327 | if (dentry->d_inode == NULL) { | 274 | if (dentry->d_inode == NULL) { |
| 328 | DPRINTK("waiting for mount name=%.*s", | 275 | DPRINTK("waiting for mount name=%.*s", |
| 329 | dentry->d_name.len, dentry->d_name.name); | 276 | dentry->d_name.len, dentry->d_name.name); |
| 330 | 277 | ||
| 331 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); | 278 | status = autofs4_wait(sbi, dentry, NFY_MOUNT); |
| 332 | 279 | ||
| 333 | DPRINTK("mount done status=%d", status); | 280 | DPRINTK("mount done status=%d", status); |
| 334 | 281 | ||
| 335 | if (status && dentry->d_inode) | 282 | if (status && dentry->d_inode) |
| 336 | return 0; /* Try to get the kernel to invalidate this dentry */ | 283 | return status; /* Try to get the kernel to invalidate this dentry */ |
| 337 | 284 | ||
| 338 | /* Turn this into a real negative dentry? */ | 285 | /* Turn this into a real negative dentry? */ |
| 339 | if (status == -ENOENT) { | 286 | if (status == -ENOENT) { |
| 340 | dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT; | ||
| 341 | spin_lock(&dentry->d_lock); | 287 | spin_lock(&dentry->d_lock); |
| 342 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 288 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 343 | spin_unlock(&dentry->d_lock); | 289 | spin_unlock(&dentry->d_lock); |
| 344 | return 1; | 290 | return status; |
| 345 | } else if (status) { | 291 | } else if (status) { |
| 346 | /* Return a negative dentry, but leave it "pending" */ | 292 | /* Return a negative dentry, but leave it "pending" */ |
| 347 | return 1; | 293 | return status; |
| 348 | } | 294 | } |
| 349 | /* Trigger mount for path component or follow link */ | 295 | /* Trigger mount for path component or follow link */ |
| 350 | } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) || | 296 | } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) || |
| @@ -363,19 +309,87 @@ static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int f | |||
| 363 | spin_lock(&dentry->d_lock); | 309 | spin_lock(&dentry->d_lock); |
| 364 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 310 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 365 | spin_unlock(&dentry->d_lock); | 311 | spin_unlock(&dentry->d_lock); |
| 366 | return 0; | 312 | return status; |
| 367 | } | 313 | } |
| 368 | } | 314 | } |
| 369 | 315 | ||
| 370 | /* We don't update the usages for the autofs daemon itself, this | 316 | /* Initialize expiry counter after successful mount */ |
| 371 | is necessary for recursive autofs mounts */ | 317 | if (ino) |
| 372 | if (!autofs4_oz_mode(sbi)) | 318 | ino->last_used = jiffies; |
| 373 | autofs4_update_usage(mnt, dentry); | ||
| 374 | 319 | ||
| 375 | spin_lock(&dentry->d_lock); | 320 | spin_lock(&dentry->d_lock); |
| 376 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 321 | dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; |
| 377 | spin_unlock(&dentry->d_lock); | 322 | spin_unlock(&dentry->d_lock); |
| 378 | return 1; | 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); | ||
| 330 | int oz_mode = autofs4_oz_mode(sbi); | ||
| 331 | unsigned int lookup_type; | ||
| 332 | int status; | ||
| 333 | |||
| 334 | DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d", | ||
| 335 | dentry, dentry->d_name.len, dentry->d_name.name, oz_mode, | ||
| 336 | nd->flags); | ||
| 337 | |||
| 338 | /* If it's our master or we shouldn't trigger a mount we're done */ | ||
| 339 | lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY); | ||
| 340 | if (oz_mode || !lookup_type) | ||
| 341 | goto done; | ||
| 342 | |||
| 343 | /* | ||
| 344 | * If a request is pending wait for it. | ||
| 345 | * If it's a mount then it won't be expired till at least | ||
| 346 | * a liitle later and if it's an expire then we might need | ||
| 347 | * to mount it again. | ||
| 348 | */ | ||
| 349 | if (autofs4_ispending(dentry)) { | ||
| 350 | DPRINTK("waiting for active request %p name=%.*s", | ||
| 351 | dentry, dentry->d_name.len, dentry->d_name.name); | ||
| 352 | |||
| 353 | status = autofs4_wait(sbi, dentry, NFY_NONE); | ||
| 354 | |||
| 355 | DPRINTK("request done status=%d", status); | ||
| 356 | } | ||
| 357 | |||
| 358 | /* | ||
| 359 | * If the dentry contains directories then it is an | ||
| 360 | * autofs multi-mount with no root mount offset. So | ||
| 361 | * don't try to mount it again. | ||
| 362 | */ | ||
| 363 | spin_lock(&dcache_lock); | ||
| 364 | if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) { | ||
| 365 | spin_unlock(&dcache_lock); | ||
| 366 | |||
| 367 | status = try_to_fill_dentry(dentry, 0); | ||
| 368 | if (status) | ||
| 369 | goto out_error; | ||
| 370 | |||
| 371 | /* | ||
| 372 | * The mount succeeded but if there is no root mount | ||
| 373 | * it must be an autofs multi-mount with no root offset | ||
| 374 | * so we don't need to follow the mount. | ||
| 375 | */ | ||
| 376 | if (d_mountpoint(dentry)) { | ||
| 377 | if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) { | ||
| 378 | status = -ENOENT; | ||
| 379 | goto out_error; | ||
| 380 | } | ||
| 381 | } | ||
| 382 | |||
| 383 | goto done; | ||
| 384 | } | ||
| 385 | spin_unlock(&dcache_lock); | ||
| 386 | |||
| 387 | done: | ||
| 388 | return NULL; | ||
| 389 | |||
| 390 | out_error: | ||
| 391 | path_release(nd); | ||
| 392 | return ERR_PTR(status); | ||
| 379 | } | 393 | } |
| 380 | 394 | ||
| 381 | /* | 395 | /* |
| @@ -384,47 +398,43 @@ static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int f | |||
| 384 | * yet completely filled in, and revalidate has to delay such | 398 | * yet completely filled in, and revalidate has to delay such |
| 385 | * lookups.. | 399 | * lookups.. |
| 386 | */ | 400 | */ |
| 387 | static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd) | 401 | static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd) |
| 388 | { | 402 | { |
| 389 | struct inode * dir = dentry->d_parent->d_inode; | 403 | struct inode *dir = dentry->d_parent->d_inode; |
| 390 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 404 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 391 | int oz_mode = autofs4_oz_mode(sbi); | 405 | int oz_mode = autofs4_oz_mode(sbi); |
| 392 | int flags = nd ? nd->flags : 0; | 406 | int flags = nd ? nd->flags : 0; |
| 393 | int status = 1; | 407 | int status = 0; |
| 394 | 408 | ||
| 395 | /* Pending dentry */ | 409 | /* Pending dentry */ |
| 396 | if (autofs4_ispending(dentry)) { | 410 | if (autofs4_ispending(dentry)) { |
| 397 | if (!oz_mode) | 411 | if (!oz_mode) |
| 398 | status = try_to_fill_dentry(nd->mnt, dentry, flags); | 412 | status = try_to_fill_dentry(dentry, flags); |
| 399 | return status; | 413 | return !status; |
| 400 | } | 414 | } |
| 401 | 415 | ||
| 402 | /* Negative dentry.. invalidate if "old" */ | 416 | /* Negative dentry.. invalidate if "old" */ |
| 403 | if (dentry->d_inode == NULL) | 417 | if (dentry->d_inode == NULL) |
| 404 | return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT); | 418 | return 0; |
| 405 | 419 | ||
| 406 | /* Check for a non-mountpoint directory with no contents */ | 420 | /* Check for a non-mountpoint directory with no contents */ |
| 407 | spin_lock(&dcache_lock); | 421 | spin_lock(&dcache_lock); |
| 408 | if (S_ISDIR(dentry->d_inode->i_mode) && | 422 | if (S_ISDIR(dentry->d_inode->i_mode) && |
| 409 | !d_mountpoint(dentry) && | 423 | !d_mountpoint(dentry) && |
| 410 | list_empty(&dentry->d_subdirs)) { | 424 | __simple_empty(dentry)) { |
| 411 | DPRINTK("dentry=%p %.*s, emptydir", | 425 | DPRINTK("dentry=%p %.*s, emptydir", |
| 412 | dentry, dentry->d_name.len, dentry->d_name.name); | 426 | dentry, dentry->d_name.len, dentry->d_name.name); |
| 413 | spin_unlock(&dcache_lock); | 427 | spin_unlock(&dcache_lock); |
| 414 | if (!oz_mode) | 428 | if (!oz_mode) |
| 415 | status = try_to_fill_dentry(nd->mnt, dentry, flags); | 429 | status = try_to_fill_dentry(dentry, flags); |
| 416 | return status; | 430 | return !status; |
| 417 | } | 431 | } |
| 418 | spin_unlock(&dcache_lock); | 432 | spin_unlock(&dcache_lock); |
| 419 | 433 | ||
| 420 | /* Update the usage list */ | ||
| 421 | if (!oz_mode) | ||
| 422 | autofs4_update_usage(nd->mnt, dentry); | ||
| 423 | |||
| 424 | return 1; | 434 | return 1; |
| 425 | } | 435 | } |
| 426 | 436 | ||
| 427 | static void autofs4_dentry_release(struct dentry *de) | 437 | void autofs4_dentry_release(struct dentry *de) |
| 428 | { | 438 | { |
| 429 | struct autofs_info *inf; | 439 | struct autofs_info *inf; |
| 430 | 440 | ||
| @@ -462,12 +472,13 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s | |||
| 462 | DPRINTK("name = %.*s", | 472 | DPRINTK("name = %.*s", |
| 463 | dentry->d_name.len, dentry->d_name.name); | 473 | dentry->d_name.len, dentry->d_name.name); |
| 464 | 474 | ||
| 475 | /* File name too long to exist */ | ||
| 465 | if (dentry->d_name.len > NAME_MAX) | 476 | if (dentry->d_name.len > NAME_MAX) |
| 466 | return ERR_PTR(-ENAMETOOLONG);/* File name too long to exist */ | 477 | return ERR_PTR(-ENAMETOOLONG); |
| 467 | 478 | ||
| 468 | sbi = autofs4_sbi(dir->i_sb); | 479 | sbi = autofs4_sbi(dir->i_sb); |
| 469 | |||
| 470 | oz_mode = autofs4_oz_mode(sbi); | 480 | oz_mode = autofs4_oz_mode(sbi); |
| 481 | |||
| 471 | DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", | 482 | DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", |
| 472 | current->pid, process_group(current), sbi->catatonic, oz_mode); | 483 | current->pid, process_group(current), sbi->catatonic, oz_mode); |
| 473 | 484 | ||
| @@ -519,7 +530,7 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s | |||
| 519 | * doesn't do the right thing for all system calls, but it should | 530 | * doesn't do the right thing for all system calls, but it should |
| 520 | * be OK for the operations we permit from an autofs. | 531 | * be OK for the operations we permit from an autofs. |
| 521 | */ | 532 | */ |
| 522 | if ( dentry->d_inode && d_unhashed(dentry) ) | 533 | if (dentry->d_inode && d_unhashed(dentry)) |
| 523 | return ERR_PTR(-ENOENT); | 534 | return ERR_PTR(-ENOENT); |
| 524 | 535 | ||
| 525 | return NULL; | 536 | return NULL; |
| @@ -531,6 +542,7 @@ static int autofs4_dir_symlink(struct inode *dir, | |||
| 531 | { | 542 | { |
| 532 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 543 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 533 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | 544 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 545 | struct autofs_info *p_ino; | ||
| 534 | struct inode *inode; | 546 | struct inode *inode; |
| 535 | char *cp; | 547 | char *cp; |
| 536 | 548 | ||
| @@ -564,6 +576,10 @@ static int autofs4_dir_symlink(struct inode *dir, | |||
| 564 | 576 | ||
| 565 | dentry->d_fsdata = ino; | 577 | dentry->d_fsdata = ino; |
| 566 | ino->dentry = dget(dentry); | 578 | ino->dentry = dget(dentry); |
| 579 | atomic_inc(&ino->count); | ||
| 580 | p_ino = autofs4_dentry_ino(dentry->d_parent); | ||
| 581 | if (p_ino && dentry->d_parent != dentry) | ||
| 582 | atomic_inc(&p_ino->count); | ||
| 567 | ino->inode = inode; | 583 | ino->inode = inode; |
| 568 | 584 | ||
| 569 | dir->i_mtime = CURRENT_TIME; | 585 | dir->i_mtime = CURRENT_TIME; |
| @@ -590,11 +606,17 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry) | |||
| 590 | { | 606 | { |
| 591 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 607 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 592 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | 608 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 609 | struct autofs_info *p_ino; | ||
| 593 | 610 | ||
| 594 | /* This allows root to remove symlinks */ | 611 | /* This allows root to remove symlinks */ |
| 595 | if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) ) | 612 | if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) ) |
| 596 | return -EACCES; | 613 | return -EACCES; |
| 597 | 614 | ||
| 615 | if (atomic_dec_and_test(&ino->count)) { | ||
| 616 | p_ino = autofs4_dentry_ino(dentry->d_parent); | ||
| 617 | if (p_ino && dentry->d_parent != dentry) | ||
| 618 | atomic_dec(&p_ino->count); | ||
| 619 | } | ||
| 598 | dput(ino->dentry); | 620 | dput(ino->dentry); |
| 599 | 621 | ||
| 600 | dentry->d_inode->i_size = 0; | 622 | dentry->d_inode->i_size = 0; |
| @@ -611,6 +633,7 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) | |||
| 611 | { | 633 | { |
| 612 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 634 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 613 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | 635 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 636 | struct autofs_info *p_ino; | ||
| 614 | 637 | ||
| 615 | if (!autofs4_oz_mode(sbi)) | 638 | if (!autofs4_oz_mode(sbi)) |
| 616 | return -EACCES; | 639 | return -EACCES; |
| @@ -625,8 +648,12 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) | |||
| 625 | spin_unlock(&dentry->d_lock); | 648 | spin_unlock(&dentry->d_lock); |
| 626 | spin_unlock(&dcache_lock); | 649 | spin_unlock(&dcache_lock); |
| 627 | 650 | ||
| 651 | if (atomic_dec_and_test(&ino->count)) { | ||
| 652 | p_ino = autofs4_dentry_ino(dentry->d_parent); | ||
| 653 | if (p_ino && dentry->d_parent != dentry) | ||
| 654 | atomic_dec(&p_ino->count); | ||
| 655 | } | ||
| 628 | dput(ino->dentry); | 656 | dput(ino->dentry); |
| 629 | |||
| 630 | dentry->d_inode->i_size = 0; | 657 | dentry->d_inode->i_size = 0; |
| 631 | dentry->d_inode->i_nlink = 0; | 658 | dentry->d_inode->i_nlink = 0; |
| 632 | 659 | ||
| @@ -640,6 +667,7 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 640 | { | 667 | { |
| 641 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 668 | struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); |
| 642 | struct autofs_info *ino = autofs4_dentry_ino(dentry); | 669 | struct autofs_info *ino = autofs4_dentry_ino(dentry); |
| 670 | struct autofs_info *p_ino; | ||
| 643 | struct inode *inode; | 671 | struct inode *inode; |
| 644 | 672 | ||
| 645 | if ( !autofs4_oz_mode(sbi) ) | 673 | if ( !autofs4_oz_mode(sbi) ) |
| @@ -662,6 +690,10 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
| 662 | 690 | ||
| 663 | dentry->d_fsdata = ino; | 691 | dentry->d_fsdata = ino; |
| 664 | ino->dentry = dget(dentry); | 692 | ino->dentry = dget(dentry); |
| 693 | atomic_inc(&ino->count); | ||
| 694 | p_ino = autofs4_dentry_ino(dentry->d_parent); | ||
| 695 | if (p_ino && dentry->d_parent != dentry) | ||
| 696 | atomic_inc(&p_ino->count); | ||
| 665 | ino->inode = inode; | 697 | ino->inode = inode; |
| 666 | dir->i_nlink++; | 698 | dir->i_nlink++; |
| 667 | dir->i_mtime = CURRENT_TIME; | 699 | dir->i_mtime = CURRENT_TIME; |
| @@ -745,7 +777,7 @@ static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p) | |||
| 745 | { | 777 | { |
| 746 | int status = 0; | 778 | int status = 0; |
| 747 | 779 | ||
| 748 | if (may_umount(mnt) == 0) | 780 | if (may_umount(mnt)) |
| 749 | status = 1; | 781 | status = 1; |
| 750 | 782 | ||
| 751 | DPRINTK("returning %d", status); | 783 | DPRINTK("returning %d", status); |
