Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
autofs4: clean ->d_release() and autofs4_free_ino() up
autofs4: split autofs4_init_ino()
autofs4: mkdir and symlink always get a dentry that had passed lookup
autofs4: autofs4_get_inode() doesn't need autofs_info * argument anymore
autofs4: kill ->size in autofs_info
autofs4: pass mode to autofs4_get_inode() explicitly
autofs4: autofs4_mkroot() is not different from autofs4_init_ino()
autofs4: keep symlink body in inode->i_private
autofs4 - fix debug print in autofs4_lookup()
vfs - fix dentry ref count in do_lookup()
autofs4 - fix get_next_positive_dentry()

+66 -121
+3 -11
fs/autofs4/autofs_i.h
··· 88 89 uid_t uid; 90 gid_t gid; 91 - 92 - mode_t mode; 93 - size_t size; 94 - 95 - void (*free)(struct autofs_info *); 96 - union { 97 - const char *symlink; 98 - } u; 99 }; 100 101 #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */ ··· 167 return 0; 168 } 169 170 - struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *); 171 void autofs4_free_ino(struct autofs_info *); 172 173 /* Expiration */ ··· 277 /* Initializing function */ 278 279 int autofs4_fill_super(struct super_block *, void *, int); 280 - struct autofs_info *autofs4_init_ino(struct autofs_info *, struct autofs_sb_info *sbi, mode_t mode); 281 282 /* Queue management functions */ 283 ··· 338 return; 339 } 340 341 - void autofs4_dentry_release(struct dentry *); 342 extern void autofs4_kill_sb(struct super_block *);
··· 88 89 uid_t uid; 90 gid_t gid; 91 }; 92 93 #define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */ ··· 175 return 0; 176 } 177 178 + struct inode *autofs4_get_inode(struct super_block *, mode_t); 179 void autofs4_free_ino(struct autofs_info *); 180 181 /* Expiration */ ··· 285 /* Initializing function */ 286 287 int autofs4_fill_super(struct super_block *, void *, int); 288 + struct autofs_info *autofs4_new_ino(struct autofs_sb_info *); 289 + void autofs4_clean_ino(struct autofs_info *); 290 291 /* Queue management functions */ 292 ··· 345 return; 346 } 347 348 extern void autofs4_kill_sb(struct super_block *);
+2 -2
fs/autofs4/expire.c
··· 96 struct dentry *p, *ret; 97 98 if (prev == NULL) 99 - return dget(prev); 100 101 spin_lock(&autofs4_lock); 102 relock: ··· 133 spin_lock_nested(&ret->d_lock, DENTRY_D_LOCK_NESTED); 134 /* Negative dentry - try next */ 135 if (!simple_positive(ret)) { 136 - spin_unlock(&ret->d_lock); 137 p = ret; 138 goto again; 139 }
··· 96 struct dentry *p, *ret; 97 98 if (prev == NULL) 99 + return dget(root); 100 101 spin_lock(&autofs4_lock); 102 relock: ··· 133 spin_lock_nested(&ret->d_lock, DENTRY_D_LOCK_NESTED); 134 /* Negative dentry - try next */ 135 if (!simple_positive(ret)) { 136 + spin_unlock(&p->d_lock); 137 p = ret; 138 goto again; 139 }
+22 -66
fs/autofs4/inode.c
··· 22 #include "autofs_i.h" 23 #include <linux/module.h> 24 25 - static void ino_lnkfree(struct autofs_info *ino) 26 { 27 - if (ino->u.symlink) { 28 - kfree(ino->u.symlink); 29 - ino->u.symlink = NULL; 30 } 31 } 32 33 - struct autofs_info *autofs4_init_ino(struct autofs_info *ino, 34 - struct autofs_sb_info *sbi, mode_t mode) 35 { 36 - int reinit = 1; 37 - 38 - if (ino == NULL) { 39 - reinit = 0; 40 - ino = kmalloc(sizeof(*ino), GFP_KERNEL); 41 - } 42 - 43 - if (ino == NULL) 44 - return NULL; 45 - 46 - if (!reinit) { 47 - ino->flags = 0; 48 - ino->dentry = NULL; 49 - ino->size = 0; 50 - INIT_LIST_HEAD(&ino->active); 51 - ino->active_count = 0; 52 - INIT_LIST_HEAD(&ino->expiring); 53 - atomic_set(&ino->count, 0); 54 - } 55 - 56 ino->uid = 0; 57 ino->gid = 0; 58 - ino->mode = mode; 59 ino->last_used = jiffies; 60 - 61 - ino->sbi = sbi; 62 - 63 - if (reinit && ino->free) 64 - (ino->free)(ino); 65 - 66 - memset(&ino->u, 0, sizeof(ino->u)); 67 - 68 - ino->free = NULL; 69 - 70 - if (S_ISLNK(mode)) 71 - ino->free = ino_lnkfree; 72 - 73 - return ino; 74 } 75 76 void autofs4_free_ino(struct autofs_info *ino) 77 { 78 - if (ino->dentry) { 79 - ino->dentry->d_fsdata = NULL; 80 - ino->dentry = NULL; 81 - } 82 - if (ino->free) 83 - (ino->free)(ino); 84 kfree(ino); 85 } 86 ··· 98 return 0; 99 } 100 101 static const struct super_operations autofs4_sops = { 102 .statfs = simple_statfs, 103 .show_options = autofs4_show_options, 104 }; 105 106 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, ··· 197 return (*pipefd < 0); 198 } 199 200 - static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi) 201 - { 202 - struct autofs_info *ino; 203 - 204 - ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755); 205 - if (!ino) 206 - return NULL; 207 - 208 - return ino; 209 - } 210 - 211 int autofs4_fill_super(struct super_block *s, void *data, int silent) 212 { 213 struct inode * root_inode; ··· 240 /* 241 * Get the root inode and dentry, but defer checking for errors. 242 */ 243 - ino = autofs4_mkroot(sbi); 244 if (!ino) 245 goto fail_free; 246 - root_inode = autofs4_get_inode(s, ino); 247 if (!root_inode) 248 goto fail_ino; 249 ··· 326 return -EINVAL; 327 } 328 329 - struct inode *autofs4_get_inode(struct super_block *sb, 330 - struct autofs_info *inf) 331 { 332 struct inode *inode = new_inode(sb); 333 334 if (inode == NULL) 335 return NULL; 336 337 - inode->i_mode = inf->mode; 338 if (sb->s_root) { 339 inode->i_uid = sb->s_root->d_inode->i_uid; 340 inode->i_gid = sb->s_root->d_inode->i_gid; ··· 341 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 342 inode->i_ino = get_next_ino(); 343 344 - if (S_ISDIR(inf->mode)) { 345 inode->i_nlink = 2; 346 inode->i_op = &autofs4_dir_inode_operations; 347 inode->i_fop = &autofs4_dir_operations; 348 - } else if (S_ISLNK(inf->mode)) { 349 - inode->i_size = inf->size; 350 inode->i_op = &autofs4_symlink_inode_operations; 351 } 352
··· 22 #include "autofs_i.h" 23 #include <linux/module.h> 24 25 + struct autofs_info *autofs4_new_ino(struct autofs_sb_info *sbi) 26 { 27 + struct autofs_info *ino = kzalloc(sizeof(*ino), GFP_KERNEL); 28 + if (ino) { 29 + INIT_LIST_HEAD(&ino->active); 30 + INIT_LIST_HEAD(&ino->expiring); 31 + ino->last_used = jiffies; 32 + ino->sbi = sbi; 33 } 34 + return ino; 35 } 36 37 + void autofs4_clean_ino(struct autofs_info *ino) 38 { 39 ino->uid = 0; 40 ino->gid = 0; 41 ino->last_used = jiffies; 42 } 43 44 void autofs4_free_ino(struct autofs_info *ino) 45 { 46 kfree(ino); 47 } 48 ··· 136 return 0; 137 } 138 139 + static void autofs4_evict_inode(struct inode *inode) 140 + { 141 + end_writeback(inode); 142 + kfree(inode->i_private); 143 + } 144 + 145 static const struct super_operations autofs4_sops = { 146 .statfs = simple_statfs, 147 .show_options = autofs4_show_options, 148 + .evict_inode = autofs4_evict_inode, 149 }; 150 151 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, ··· 228 return (*pipefd < 0); 229 } 230 231 int autofs4_fill_super(struct super_block *s, void *data, int silent) 232 { 233 struct inode * root_inode; ··· 282 /* 283 * Get the root inode and dentry, but defer checking for errors. 284 */ 285 + ino = autofs4_new_ino(sbi); 286 if (!ino) 287 goto fail_free; 288 + root_inode = autofs4_get_inode(s, S_IFDIR | 0755); 289 if (!root_inode) 290 goto fail_ino; 291 ··· 368 return -EINVAL; 369 } 370 371 + struct inode *autofs4_get_inode(struct super_block *sb, mode_t mode) 372 { 373 struct inode *inode = new_inode(sb); 374 375 if (inode == NULL) 376 return NULL; 377 378 + inode->i_mode = mode; 379 if (sb->s_root) { 380 inode->i_uid = sb->s_root->d_inode->i_uid; 381 inode->i_gid = sb->s_root->d_inode->i_gid; ··· 384 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 385 inode->i_ino = get_next_ino(); 386 387 + if (S_ISDIR(mode)) { 388 inode->i_nlink = 2; 389 inode->i_op = &autofs4_dir_inode_operations; 390 inode->i_fop = &autofs4_dir_operations; 391 + } else if (S_ISLNK(mode)) { 392 inode->i_op = &autofs4_symlink_inode_operations; 393 } 394
+35 -39
fs/autofs4/root.c
··· 37 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); 38 static struct vfsmount *autofs4_d_automount(struct path *); 39 static int autofs4_d_manage(struct dentry *, bool, bool); 40 41 const struct file_operations autofs4_root_operations = { 42 .open = dcache_dir_open, ··· 139 return dcache_dir_open(inode, file); 140 } 141 142 - void autofs4_dentry_release(struct dentry *de) 143 { 144 - struct autofs_info *inf; 145 146 DPRINTK("releasing %p", de); 147 148 - inf = autofs4_dentry_ino(de); 149 - if (inf) { 150 - struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb); 151 - if (sbi) { 152 - spin_lock(&sbi->lookup_lock); 153 - if (!list_empty(&inf->active)) 154 - list_del(&inf->active); 155 - if (!list_empty(&inf->expiring)) 156 - list_del(&inf->expiring); 157 - spin_unlock(&sbi->lookup_lock); 158 - } 159 - autofs4_free_ino(inf); 160 } 161 } 162 163 static struct dentry *autofs4_lookup_active(struct dentry *dentry) ··· 490 sbi = autofs4_sbi(dir->i_sb); 491 492 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", 493 - current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode); 494 495 active = autofs4_lookup_active(dentry); 496 if (active) { ··· 510 if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent)) 511 __managed_dentry_set_managed(dentry); 512 513 - ino = autofs4_init_ino(NULL, sbi, 0555); 514 if (!ino) 515 return ERR_PTR(-ENOMEM); 516 ··· 532 struct autofs_info *ino = autofs4_dentry_ino(dentry); 533 struct autofs_info *p_ino; 534 struct inode *inode; 535 char *cp; 536 537 DPRINTK("%s <- %.*s", symname, ··· 541 if (!autofs4_oz_mode(sbi)) 542 return -EACCES; 543 544 - ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555); 545 - if (!ino) 546 - return -ENOMEM; 547 548 autofs4_del_active(dentry); 549 550 - ino->size = strlen(symname); 551 - cp = kmalloc(ino->size + 1, GFP_KERNEL); 552 - if (!cp) { 553 - if (!dentry->d_fsdata) 554 - kfree(ino); 555 return -ENOMEM; 556 - } 557 558 strcpy(cp, symname); 559 560 - inode = autofs4_get_inode(dir->i_sb, ino); 561 if (!inode) { 562 kfree(cp); 563 if (!dentry->d_fsdata) 564 kfree(ino); 565 return -ENOMEM; 566 } 567 d_add(dentry, inode); 568 569 - dentry->d_fsdata = ino; 570 - ino->dentry = dget(dentry); 571 atomic_inc(&ino->count); 572 p_ino = autofs4_dentry_ino(dentry->d_parent); 573 if (p_ino && dentry->d_parent != dentry) 574 atomic_inc(&p_ino->count); 575 576 - ino->u.symlink = cp; 577 dir->i_mtime = CURRENT_TIME; 578 579 return 0; ··· 732 DPRINTK("dentry %p, creating %.*s", 733 dentry, dentry->d_name.len, dentry->d_name.name); 734 735 - ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); 736 - if (!ino) 737 - return -ENOMEM; 738 739 autofs4_del_active(dentry); 740 741 - inode = autofs4_get_inode(dir->i_sb, ino); 742 - if (!inode) { 743 - if (!dentry->d_fsdata) 744 - kfree(ino); 745 return -ENOMEM; 746 - } 747 d_add(dentry, inode); 748 749 if (sbi->version < 5) 750 autofs_set_leaf_automount_flags(dentry); 751 752 - dentry->d_fsdata = ino; 753 - ino->dentry = dget(dentry); 754 atomic_inc(&ino->count); 755 p_ino = autofs4_dentry_ino(dentry->d_parent); 756 if (p_ino && dentry->d_parent != dentry)
··· 37 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); 38 static struct vfsmount *autofs4_d_automount(struct path *); 39 static int autofs4_d_manage(struct dentry *, bool, bool); 40 + static void autofs4_dentry_release(struct dentry *); 41 42 const struct file_operations autofs4_root_operations = { 43 .open = dcache_dir_open, ··· 138 return dcache_dir_open(inode, file); 139 } 140 141 + static void autofs4_dentry_release(struct dentry *de) 142 { 143 + struct autofs_info *ino = autofs4_dentry_ino(de); 144 + struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb); 145 146 DPRINTK("releasing %p", de); 147 148 + if (!ino) 149 + return; 150 + 151 + if (sbi) { 152 + spin_lock(&sbi->lookup_lock); 153 + if (!list_empty(&ino->active)) 154 + list_del(&ino->active); 155 + if (!list_empty(&ino->expiring)) 156 + list_del(&ino->expiring); 157 + spin_unlock(&sbi->lookup_lock); 158 } 159 + 160 + autofs4_free_ino(ino); 161 } 162 163 static struct dentry *autofs4_lookup_active(struct dentry *dentry) ··· 488 sbi = autofs4_sbi(dir->i_sb); 489 490 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", 491 + current->pid, task_pgrp_nr(current), sbi->catatonic, 492 + autofs4_oz_mode(sbi)); 493 494 active = autofs4_lookup_active(dentry); 495 if (active) { ··· 507 if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent)) 508 __managed_dentry_set_managed(dentry); 509 510 + ino = autofs4_new_ino(sbi); 511 if (!ino) 512 return ERR_PTR(-ENOMEM); 513 ··· 529 struct autofs_info *ino = autofs4_dentry_ino(dentry); 530 struct autofs_info *p_ino; 531 struct inode *inode; 532 + size_t size = strlen(symname); 533 char *cp; 534 535 DPRINTK("%s <- %.*s", symname, ··· 537 if (!autofs4_oz_mode(sbi)) 538 return -EACCES; 539 540 + BUG_ON(!ino); 541 + 542 + autofs4_clean_ino(ino); 543 544 autofs4_del_active(dentry); 545 546 + cp = kmalloc(size + 1, GFP_KERNEL); 547 + if (!cp) 548 return -ENOMEM; 549 550 strcpy(cp, symname); 551 552 + inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555); 553 if (!inode) { 554 kfree(cp); 555 if (!dentry->d_fsdata) 556 kfree(ino); 557 return -ENOMEM; 558 } 559 + inode->i_private = cp; 560 + inode->i_size = size; 561 d_add(dentry, inode); 562 563 + dget(dentry); 564 atomic_inc(&ino->count); 565 p_ino = autofs4_dentry_ino(dentry->d_parent); 566 if (p_ino && dentry->d_parent != dentry) 567 atomic_inc(&p_ino->count); 568 569 dir->i_mtime = CURRENT_TIME; 570 571 return 0; ··· 732 DPRINTK("dentry %p, creating %.*s", 733 dentry, dentry->d_name.len, dentry->d_name.name); 734 735 + BUG_ON(!ino); 736 + 737 + autofs4_clean_ino(ino); 738 739 autofs4_del_active(dentry); 740 741 + inode = autofs4_get_inode(dir->i_sb, S_IFDIR | 0555); 742 + if (!inode) 743 return -ENOMEM; 744 d_add(dentry, inode); 745 746 if (sbi->version < 5) 747 autofs_set_leaf_automount_flags(dentry); 748 749 + dget(dentry); 750 atomic_inc(&ino->count); 751 p_ino = autofs4_dentry_ino(dentry->d_parent); 752 if (p_ino && dentry->d_parent != dentry)
+1 -2
fs/autofs4/symlink.c
··· 14 15 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) 16 { 17 - struct autofs_info *ino = autofs4_dentry_ino(dentry); 18 - nd_set_link(nd, (char *)ino->u.symlink); 19 return NULL; 20 } 21
··· 14 15 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) 16 { 17 + nd_set_link(nd, dentry->d_inode->i_private); 18 return NULL; 19 } 20
+3 -1
fs/namei.c
··· 1272 path->mnt = mnt; 1273 path->dentry = dentry; 1274 err = follow_managed(path, nd->flags); 1275 - if (unlikely(err < 0)) 1276 return err; 1277 *inode = path->dentry->d_inode; 1278 return 0; 1279
··· 1272 path->mnt = mnt; 1273 path->dentry = dentry; 1274 err = follow_managed(path, nd->flags); 1275 + if (unlikely(err < 0)) { 1276 + path_put_conditional(path, nd); 1277 return err; 1278 + } 1279 *inode = path->dentry->d_inode; 1280 return 0; 1281