Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: (46 commits)
[PATCH] fs: add a sanity check in d_free
[PATCH] i_version: remount support
[patch] vfs: make security_inode_setattr() calling consistent
[patch 1/3] FS_MBCACHE: don't needlessly make it built-in
[PATCH] move executable checking into ->permission()
[PATCH] fs/dcache.c: update comment of d_validate()
[RFC PATCH] touch_mnt_namespace when the mount flags change
[PATCH] reiserfs: add missing llseek method
[PATCH] fix ->llseek for more directories
[PATCH vfs-2.6 6/6] vfs: add LOOKUP_RENAME_TARGET intent
[PATCH vfs-2.6 5/6] vfs: remove LOOKUP_PARENT from non LOOKUP_PARENT lookup
[PATCH vfs-2.6 4/6] vfs: remove unnecessary fsnotify_d_instantiate()
[PATCH vfs-2.6 3/6] vfs: add __d_instantiate() helper
[PATCH vfs-2.6 2/6] vfs: add d_ancestor()
[PATCH vfs-2.6 1/6] vfs: replace parent == dentry->d_parent by IS_ROOT()
[PATCH] get rid of on-stack dentry in udf
[PATCH 2/2] anondev: switch to IDA
[PATCH 1/2] anondev: init IDR statically
[JFFS2] Use d_splice_alias() not d_add() in jffs2_lookup()
[PATCH] Optimise NFS readdir hack slightly.
...

+890 -1140
+2 -5
arch/alpha/kernel/osf_sys.c
··· 165 165 buf.error = 0; 166 166 167 167 error = vfs_readdir(file, osf_filldir, &buf); 168 - if (error < 0) 169 - goto out_putf; 170 - 171 - error = buf.error; 168 + if (error >= 0) 169 + error = buf.error; 172 170 if (count != buf.count) 173 171 error = count - buf.count; 174 172 175 - out_putf: 176 173 fput(file); 177 174 out: 178 175 return error;
+2 -3
arch/parisc/hpux/fs.c
··· 127 127 buf.error = 0; 128 128 129 129 error = vfs_readdir(file, filldir, &buf); 130 - if (error < 0) 131 - goto out_putf; 132 - error = buf.error; 130 + if (error >= 0) 131 + error = buf.error; 133 132 lastdirent = buf.previous; 134 133 if (lastdirent) { 135 134 if (put_user(file->f_pos, &lastdirent->d_off))
+2 -2
arch/powerpc/platforms/cell/spufs/syscalls.c
··· 69 69 if (!IS_ERR(tmp)) { 70 70 struct nameidata nd; 71 71 72 - ret = path_lookup(tmp, LOOKUP_PARENT| 73 - LOOKUP_OPEN|LOOKUP_CREATE, &nd); 72 + ret = path_lookup(tmp, LOOKUP_PARENT, &nd); 74 73 if (!ret) { 74 + nd.flags |= LOOKUP_OPEN | LOOKUP_CREATE; 75 75 ret = spufs_create(&nd, flags, mode, neighbor); 76 76 path_put(&nd.path); 77 77 }
+6 -15
drivers/md/dm-table.c
··· 313 313 } 314 314 315 315 /* 316 - * Convert a device path to a dev_t. 317 - */ 318 - static int lookup_device(const char *path, dev_t *dev) 319 - { 320 - struct block_device *bdev = lookup_bdev(path); 321 - if (IS_ERR(bdev)) 322 - return PTR_ERR(bdev); 323 - *dev = bdev->bd_dev; 324 - bdput(bdev); 325 - return 0; 326 - } 327 - 328 - /* 329 316 * See if we've already got a device in the list. 330 317 */ 331 318 static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev) ··· 424 437 return -EOVERFLOW; 425 438 } else { 426 439 /* convert the path to a device */ 427 - if ((r = lookup_device(path, &dev))) 428 - return r; 440 + struct block_device *bdev = lookup_bdev(path); 441 + 442 + if (IS_ERR(bdev)) 443 + return PTR_ERR(bdev); 444 + dev = bdev->bd_dev; 445 + bdput(bdev); 429 446 } 430 447 431 448 dd = find_device(&t->devices, dev);
+4 -3
fs/Kconfig
··· 22 22 config FS_MBCACHE 23 23 # Meta block cache for Extended Attributes (ext2/ext3/ext4) 24 24 tristate 25 - depends on EXT2_FS_XATTR || EXT3_FS_XATTR || EXT4_FS_XATTR 26 - default y if EXT2_FS=y || EXT3_FS=y || EXT4_FS=y 27 - default m if EXT2_FS=m || EXT3_FS=m || EXT4_FS=m 25 + default y if EXT2_FS=y && EXT2_FS_XATTR 26 + default y if EXT3_FS=y && EXT3_FS_XATTR 27 + default y if EXT4_FS=y && EXT4_FS_XATTR 28 + default m if EXT2_FS_XATTR || EXT3_FS_XATTR || EXT4_FS_XATTR 28 29 29 30 config REISERFS_FS 30 31 tristate "Reiserfs support"
+1
fs/afs/dir.c
··· 45 45 .release = afs_release, 46 46 .readdir = afs_readdir, 47 47 .lock = afs_lock, 48 + .llseek = generic_file_llseek, 48 49 }; 49 50 50 51 const struct inode_operations afs_dir_inode_operations = {
+5 -5
fs/attr.c
··· 159 159 if (!(attr->ia_valid & ~(ATTR_KILL_SUID | ATTR_KILL_SGID))) 160 160 return 0; 161 161 162 + error = security_inode_setattr(dentry, attr); 163 + if (error) 164 + return error; 165 + 162 166 if (ia_valid & ATTR_SIZE) 163 167 down_write(&dentry->d_inode->i_alloc_sem); 164 168 165 169 if (inode->i_op && inode->i_op->setattr) { 166 - error = security_inode_setattr(dentry, attr); 167 - if (!error) 168 - error = inode->i_op->setattr(dentry, attr); 170 + error = inode->i_op->setattr(dentry, attr); 169 171 } else { 170 172 error = inode_change_ok(inode, attr); 171 - if (!error) 172 - error = security_inode_setattr(dentry, attr); 173 173 if (!error) { 174 174 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || 175 175 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
+1
fs/bfs/dir.c
··· 80 80 .read = generic_read_dir, 81 81 .readdir = bfs_readdir, 82 82 .fsync = file_fsync, 83 + .llseek = generic_file_llseek, 83 84 }; 84 85 85 86 extern void dump_imap(const char *, struct super_block *);
+7 -7
fs/block_dev.c
··· 1268 1268 * namespace if possible and return it. Return ERR_PTR(error) 1269 1269 * otherwise. 1270 1270 */ 1271 - struct block_device *lookup_bdev(const char *path) 1271 + struct block_device *lookup_bdev(const char *pathname) 1272 1272 { 1273 1273 struct block_device *bdev; 1274 1274 struct inode *inode; 1275 - struct nameidata nd; 1275 + struct path path; 1276 1276 int error; 1277 1277 1278 - if (!path || !*path) 1278 + if (!pathname || !*pathname) 1279 1279 return ERR_PTR(-EINVAL); 1280 1280 1281 - error = path_lookup(path, LOOKUP_FOLLOW, &nd); 1281 + error = kern_path(pathname, LOOKUP_FOLLOW, &path); 1282 1282 if (error) 1283 1283 return ERR_PTR(error); 1284 1284 1285 - inode = nd.path.dentry->d_inode; 1285 + inode = path.dentry->d_inode; 1286 1286 error = -ENOTBLK; 1287 1287 if (!S_ISBLK(inode->i_mode)) 1288 1288 goto fail; 1289 1289 error = -EACCES; 1290 - if (nd.path.mnt->mnt_flags & MNT_NODEV) 1290 + if (path.mnt->mnt_flags & MNT_NODEV) 1291 1291 goto fail; 1292 1292 error = -ENOMEM; 1293 1293 bdev = bd_acquire(inode); 1294 1294 if (!bdev) 1295 1295 goto fail; 1296 1296 out: 1297 - path_put(&nd.path); 1297 + path_put(&path); 1298 1298 return bdev; 1299 1299 fail: 1300 1300 bdev = ERR_PTR(error);
+14 -7
fs/char_dev.c
··· 386 386 cdev_put(new); 387 387 if (ret) 388 388 return ret; 389 + 390 + ret = -ENXIO; 389 391 filp->f_op = fops_get(p->ops); 390 - if (!filp->f_op) { 391 - cdev_put(p); 392 - return -ENXIO; 393 - } 394 - if (filp->f_op->open) 392 + if (!filp->f_op) 393 + goto out_cdev_put; 394 + 395 + if (filp->f_op->open) { 395 396 ret = filp->f_op->open(inode,filp); 396 - if (ret) 397 - cdev_put(p); 397 + if (ret) 398 + goto out_cdev_put; 399 + } 400 + 401 + return 0; 402 + 403 + out_cdev_put: 404 + cdev_put(p); 398 405 return ret; 399 406 } 400 407
+7 -3
fs/cifs/cifsfs.c
··· 275 275 276 276 cifs_sb = CIFS_SB(inode->i_sb); 277 277 278 - if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) 279 - return 0; 280 - else /* file mode might have been restricted at mount time 278 + if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) { 279 + if ((mask & MAY_EXEC) && !execute_ok(inode)) 280 + return -EACCES; 281 + else 282 + return 0; 283 + } else /* file mode might have been restricted at mount time 281 284 on the client (above and beyond ACL on servers) for 282 285 servers which do not support setting and viewing mode bits, 283 286 so allowing client to check permissions is useful */ ··· 768 765 .dir_notify = cifs_dir_notify, 769 766 #endif /* CONFIG_CIFS_EXPERIMENTAL */ 770 767 .unlocked_ioctl = cifs_ioctl, 768 + .llseek = generic_file_llseek, 771 769 }; 772 770 773 771 static void
+3
fs/coda/dir.c
··· 146 146 if (!mask) 147 147 return 0; 148 148 149 + if ((mask & MAY_EXEC) && !execute_ok(inode)) 150 + return -EACCES; 151 + 149 152 lock_kernel(); 150 153 151 154 if (coda_cache_check(inode, mask))
+1 -1
fs/coda/pioctl.c
··· 43 43 /* the coda pioctl inode ops */ 44 44 static int coda_ioctl_permission(struct inode *inode, int mask) 45 45 { 46 - return 0; 46 + return (mask & MAY_EXEC) ? -EACCES : 0; 47 47 } 48 48 49 49 static int coda_pioctl(struct inode * inode, struct file * filp,
+8 -14
fs/compat.c
··· 869 869 buf.dirent = dirent; 870 870 871 871 error = vfs_readdir(file, compat_fillonedir, &buf); 872 - if (error >= 0) 872 + if (buf.result) 873 873 error = buf.result; 874 874 875 875 fput(file); ··· 956 956 buf.error = 0; 957 957 958 958 error = vfs_readdir(file, compat_filldir, &buf); 959 - if (error < 0) 960 - goto out_putf; 961 - error = buf.error; 959 + if (error >= 0) 960 + error = buf.error; 962 961 lastdirent = buf.previous; 963 962 if (lastdirent) { 964 963 if (put_user(file->f_pos, &lastdirent->d_off)) ··· 965 966 else 966 967 error = count - buf.count; 967 968 } 968 - 969 - out_putf: 970 969 fput(file); 971 970 out: 972 971 return error; ··· 1044 1047 buf.error = 0; 1045 1048 1046 1049 error = vfs_readdir(file, compat_filldir64, &buf); 1047 - if (error < 0) 1048 - goto out_putf; 1049 - error = buf.error; 1050 + if (error >= 0) 1051 + error = buf.error; 1050 1052 lastdirent = buf.previous; 1051 1053 if (lastdirent) { 1052 1054 typeof(lastdirent->d_off) d_off = file->f_pos; 1053 - error = -EFAULT; 1054 1055 if (__put_user_unaligned(d_off, &lastdirent->d_off)) 1055 - goto out_putf; 1056 - error = count - buf.count; 1056 + error = -EFAULT; 1057 + else 1058 + error = count - buf.count; 1057 1059 } 1058 - 1059 - out_putf: 1060 1060 fput(file); 1061 1061 out: 1062 1062 return error;
+8 -8
fs/configfs/symlink.c
··· 108 108 } 109 109 110 110 111 - static int get_target(const char *symname, struct nameidata *nd, 111 + static int get_target(const char *symname, struct path *path, 112 112 struct config_item **target) 113 113 { 114 114 int ret; 115 115 116 - ret = path_lookup(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, nd); 116 + ret = kern_path(symname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, path); 117 117 if (!ret) { 118 - if (nd->path.dentry->d_sb == configfs_sb) { 119 - *target = configfs_get_config_item(nd->path.dentry); 118 + if (path->dentry->d_sb == configfs_sb) { 119 + *target = configfs_get_config_item(path->dentry); 120 120 if (!*target) { 121 121 ret = -ENOENT; 122 - path_put(&nd->path); 122 + path_put(path); 123 123 } 124 124 } else 125 125 ret = -EPERM; ··· 132 132 int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) 133 133 { 134 134 int ret; 135 - struct nameidata nd; 135 + struct path path; 136 136 struct configfs_dirent *sd; 137 137 struct config_item *parent_item; 138 138 struct config_item *target_item; ··· 159 159 !type->ct_item_ops->allow_link) 160 160 goto out_put; 161 161 162 - ret = get_target(symname, &nd, &target_item); 162 + ret = get_target(symname, &path, &target_item); 163 163 if (ret) 164 164 goto out_put; 165 165 ··· 174 174 } 175 175 176 176 config_item_put(target_item); 177 - path_put(&nd.path); 177 + path_put(&path); 178 178 179 179 out_put: 180 180 config_item_put(parent_item);
+96 -92
fs/dcache.c
··· 69 69 70 70 static void __d_free(struct dentry *dentry) 71 71 { 72 + WARN_ON(!list_empty(&dentry->d_alias)); 72 73 if (dname_external(dentry)) 73 74 kfree(dentry->d_name.name); 74 75 kmem_cache_free(dentry_cache, dentry); ··· 175 174 dentry_stat.nr_dentry--; /* For d_free, below */ 176 175 /*drops the locks, at that point nobody can reach this dentry */ 177 176 dentry_iput(dentry); 178 - parent = dentry->d_parent; 177 + if (IS_ROOT(dentry)) 178 + parent = NULL; 179 + else 180 + parent = dentry->d_parent; 179 181 d_free(dentry); 180 - return dentry == parent ? NULL : parent; 182 + return parent; 181 183 } 182 184 183 185 /* ··· 670 666 BUG(); 671 667 } 672 668 673 - parent = dentry->d_parent; 674 - if (parent == dentry) 669 + if (IS_ROOT(dentry)) 675 670 parent = NULL; 676 - else 671 + else { 672 + parent = dentry->d_parent; 677 673 atomic_dec(&parent->d_count); 674 + } 678 675 679 676 list_del(&dentry->d_u.d_child); 680 677 detached++; ··· 982 977 return d_alloc(parent, &q); 983 978 } 984 979 980 + /* the caller must hold dcache_lock */ 981 + static void __d_instantiate(struct dentry *dentry, struct inode *inode) 982 + { 983 + if (inode) 984 + list_add(&dentry->d_alias, &inode->i_dentry); 985 + dentry->d_inode = inode; 986 + fsnotify_d_instantiate(dentry, inode); 987 + } 988 + 985 989 /** 986 990 * d_instantiate - fill in inode information for a dentry 987 991 * @entry: dentry to complete ··· 1010 996 { 1011 997 BUG_ON(!list_empty(&entry->d_alias)); 1012 998 spin_lock(&dcache_lock); 1013 - if (inode) 1014 - list_add(&entry->d_alias, &inode->i_dentry); 1015 - entry->d_inode = inode; 1016 - fsnotify_d_instantiate(entry, inode); 999 + __d_instantiate(entry, inode); 1017 1000 spin_unlock(&dcache_lock); 1018 1001 security_d_instantiate(entry, inode); 1019 1002 } ··· 1040 1029 unsigned int hash = entry->d_name.hash; 1041 1030 1042 1031 if (!inode) { 1043 - entry->d_inode = NULL; 1032 + __d_instantiate(entry, NULL); 1044 1033 return NULL; 1045 1034 } 1046 1035 ··· 1059 1048 return alias; 1060 1049 } 1061 1050 1062 - list_add(&entry->d_alias, &inode->i_dentry); 1063 - entry->d_inode = inode; 1064 - fsnotify_d_instantiate(entry, inode); 1051 + __d_instantiate(entry, inode); 1065 1052 return NULL; 1066 1053 } 1067 1054 ··· 1120 1111 } 1121 1112 1122 1113 /** 1123 - * d_alloc_anon - allocate an anonymous dentry 1114 + * d_obtain_alias - find or allocate a dentry for a given inode 1124 1115 * @inode: inode to allocate the dentry for 1125 1116 * 1126 - * This is similar to d_alloc_root. It is used by filesystems when 1127 - * creating a dentry for a given inode, often in the process of 1128 - * mapping a filehandle to a dentry. The returned dentry may be 1129 - * anonymous, or may have a full name (if the inode was already 1130 - * in the cache). The file system may need to make further 1131 - * efforts to connect this dentry into the dcache properly. 1117 + * Obtain a dentry for an inode resulting from NFS filehandle conversion or 1118 + * similar open by handle operations. The returned dentry may be anonymous, 1119 + * or may have a full name (if the inode was already in the cache). 1132 1120 * 1133 - * When called on a directory inode, we must ensure that 1134 - * the inode only ever has one dentry. If a dentry is 1135 - * found, that is returned instead of allocating a new one. 1121 + * When called on a directory inode, we must ensure that the inode only ever 1122 + * has one dentry. If a dentry is found, that is returned instead of 1123 + * allocating a new one. 1136 1124 * 1137 1125 * On successful return, the reference to the inode has been transferred 1138 - * to the dentry. If %NULL is returned (indicating kmalloc failure), 1139 - * the reference on the inode has not been released. 1126 + * to the dentry. In case of an error the reference on the inode is released. 1127 + * To make it easier to use in export operations a %NULL or IS_ERR inode may 1128 + * be passed in and will be the error will be propagate to the return value, 1129 + * with a %NULL @inode replaced by ERR_PTR(-ESTALE). 1140 1130 */ 1141 - 1142 - struct dentry * d_alloc_anon(struct inode *inode) 1131 + struct dentry *d_obtain_alias(struct inode *inode) 1143 1132 { 1144 1133 static const struct qstr anonstring = { .name = "" }; 1145 1134 struct dentry *tmp; 1146 1135 struct dentry *res; 1147 1136 1148 - if ((res = d_find_alias(inode))) { 1149 - iput(inode); 1150 - return res; 1151 - } 1137 + if (!inode) 1138 + return ERR_PTR(-ESTALE); 1139 + if (IS_ERR(inode)) 1140 + return ERR_CAST(inode); 1141 + 1142 + res = d_find_alias(inode); 1143 + if (res) 1144 + goto out_iput; 1152 1145 1153 1146 tmp = d_alloc(NULL, &anonstring); 1154 - if (!tmp) 1155 - return NULL; 1156 - 1147 + if (!tmp) { 1148 + res = ERR_PTR(-ENOMEM); 1149 + goto out_iput; 1150 + } 1157 1151 tmp->d_parent = tmp; /* make sure dput doesn't croak */ 1158 - 1152 + 1159 1153 spin_lock(&dcache_lock); 1160 1154 res = __d_find_alias(inode, 0); 1161 - if (!res) { 1162 - /* attach a disconnected dentry */ 1163 - res = tmp; 1164 - tmp = NULL; 1165 - spin_lock(&res->d_lock); 1166 - res->d_sb = inode->i_sb; 1167 - res->d_parent = res; 1168 - res->d_inode = inode; 1169 - res->d_flags |= DCACHE_DISCONNECTED; 1170 - res->d_flags &= ~DCACHE_UNHASHED; 1171 - list_add(&res->d_alias, &inode->i_dentry); 1172 - hlist_add_head(&res->d_hash, &inode->i_sb->s_anon); 1173 - spin_unlock(&res->d_lock); 1174 - 1175 - inode = NULL; /* don't drop reference */ 1176 - } 1177 - spin_unlock(&dcache_lock); 1178 - 1179 - if (inode) 1180 - iput(inode); 1181 - if (tmp) 1155 + if (res) { 1156 + spin_unlock(&dcache_lock); 1182 1157 dput(tmp); 1158 + goto out_iput; 1159 + } 1160 + 1161 + /* attach a disconnected dentry */ 1162 + spin_lock(&tmp->d_lock); 1163 + tmp->d_sb = inode->i_sb; 1164 + tmp->d_inode = inode; 1165 + tmp->d_flags |= DCACHE_DISCONNECTED; 1166 + tmp->d_flags &= ~DCACHE_UNHASHED; 1167 + list_add(&tmp->d_alias, &inode->i_dentry); 1168 + hlist_add_head(&tmp->d_hash, &inode->i_sb->s_anon); 1169 + spin_unlock(&tmp->d_lock); 1170 + 1171 + spin_unlock(&dcache_lock); 1172 + return tmp; 1173 + 1174 + out_iput: 1175 + iput(inode); 1183 1176 return res; 1184 1177 } 1185 - 1178 + EXPORT_SYMBOL_GPL(d_obtain_alias); 1186 1179 1187 1180 /** 1188 1181 * d_splice_alias - splice a disconnected dentry into the tree if one exists ··· 1211 1200 new = __d_find_alias(inode, 1); 1212 1201 if (new) { 1213 1202 BUG_ON(!(new->d_flags & DCACHE_DISCONNECTED)); 1214 - fsnotify_d_instantiate(new, inode); 1215 1203 spin_unlock(&dcache_lock); 1216 1204 security_d_instantiate(new, inode); 1217 1205 d_rehash(dentry); 1218 1206 d_move(new, dentry); 1219 1207 iput(inode); 1220 1208 } else { 1221 - /* d_instantiate takes dcache_lock, so we do it by hand */ 1222 - list_add(&dentry->d_alias, &inode->i_dentry); 1223 - dentry->d_inode = inode; 1224 - fsnotify_d_instantiate(dentry, inode); 1209 + /* already taking dcache_lock, so d_add() by hand */ 1210 + __d_instantiate(dentry, inode); 1225 1211 spin_unlock(&dcache_lock); 1226 1212 security_d_instantiate(dentry, inode); 1227 1213 d_rehash(dentry); ··· 1301 1293 * d_instantiate() by hand because it takes dcache_lock which 1302 1294 * we already hold. 1303 1295 */ 1304 - list_add(&found->d_alias, &inode->i_dentry); 1305 - found->d_inode = inode; 1296 + __d_instantiate(found, inode); 1306 1297 spin_unlock(&dcache_lock); 1307 1298 security_d_instantiate(found, inode); 1308 1299 return found; ··· 1463 1456 * d_validate - verify dentry provided from insecure source 1464 1457 * @dentry: The dentry alleged to be valid child of @dparent 1465 1458 * @dparent: The parent dentry (known to be valid) 1466 - * @hash: Hash of the dentry 1467 - * @len: Length of the name 1468 1459 * 1469 1460 * An insecure source has sent us a dentry, here we verify it and dget() it. 1470 1461 * This is used by ncpfs in its readdir implementation. ··· 1719 1714 spin_unlock(&dcache_lock); 1720 1715 } 1721 1716 1722 - /* 1723 - * Helper that returns 1 if p1 is a parent of p2, else 0 1717 + /** 1718 + * d_ancestor - search for an ancestor 1719 + * @p1: ancestor dentry 1720 + * @p2: child dentry 1721 + * 1722 + * Returns the ancestor dentry of p2 which is a child of p1, if p1 is 1723 + * an ancestor of p2, else NULL. 1724 1724 */ 1725 - static int d_isparent(struct dentry *p1, struct dentry *p2) 1725 + struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2) 1726 1726 { 1727 1727 struct dentry *p; 1728 1728 1729 - for (p = p2; p->d_parent != p; p = p->d_parent) { 1729 + for (p = p2; !IS_ROOT(p); p = p->d_parent) { 1730 1730 if (p->d_parent == p1) 1731 - return 1; 1731 + return p; 1732 1732 } 1733 - return 0; 1733 + return NULL; 1734 1734 } 1735 1735 1736 1736 /* ··· 1759 1749 1760 1750 /* Check for loops */ 1761 1751 ret = ERR_PTR(-ELOOP); 1762 - if (d_isparent(alias, dentry)) 1752 + if (d_ancestor(alias, dentry)) 1763 1753 goto out_err; 1764 1754 1765 1755 /* See lock_rename() */ ··· 1832 1822 1833 1823 if (!inode) { 1834 1824 actual = dentry; 1835 - dentry->d_inode = NULL; 1825 + __d_instantiate(dentry, NULL); 1836 1826 goto found_lock; 1837 1827 } 1838 1828 ··· 2159 2149 * Caller must ensure that "new_dentry" is pinned before calling is_subdir() 2160 2150 */ 2161 2151 2162 - int is_subdir(struct dentry * new_dentry, struct dentry * old_dentry) 2152 + int is_subdir(struct dentry *new_dentry, struct dentry *old_dentry) 2163 2153 { 2164 2154 int result; 2165 - struct dentry * saved = new_dentry; 2166 2155 unsigned long seq; 2167 2156 2168 - /* need rcu_readlock to protect against the d_parent trashing due to 2169 - * d_move 2157 + /* FIXME: This is old behavior, needed? Please check callers. */ 2158 + if (new_dentry == old_dentry) 2159 + return 1; 2160 + 2161 + /* 2162 + * Need rcu_readlock to protect against the d_parent trashing 2163 + * due to d_move 2170 2164 */ 2171 2165 rcu_read_lock(); 2172 - do { 2166 + do { 2173 2167 /* for restarting inner loop in case of seq retry */ 2174 - new_dentry = saved; 2175 - result = 0; 2176 2168 seq = read_seqbegin(&rename_lock); 2177 - for (;;) { 2178 - if (new_dentry != old_dentry) { 2179 - struct dentry * parent = new_dentry->d_parent; 2180 - if (parent == new_dentry) 2181 - break; 2182 - new_dentry = parent; 2183 - continue; 2184 - } 2169 + if (d_ancestor(old_dentry, new_dentry)) 2185 2170 result = 1; 2186 - break; 2187 - } 2171 + else 2172 + result = 0; 2188 2173 } while (read_seqretry(&rename_lock, seq)); 2189 2174 rcu_read_unlock(); 2190 2175 ··· 2349 2344 } 2350 2345 2351 2346 EXPORT_SYMBOL(d_alloc); 2352 - EXPORT_SYMBOL(d_alloc_anon); 2353 2347 EXPORT_SYMBOL(d_alloc_root); 2354 2348 EXPORT_SYMBOL(d_delete); 2355 2349 EXPORT_SYMBOL(d_find_alias);
+5 -5
fs/dquot.c
··· 1805 1805 } 1806 1806 1807 1807 /* Actual function called from quotactl() */ 1808 - int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path, 1808 + int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name, 1809 1809 int remount) 1810 1810 { 1811 - struct nameidata nd; 1811 + struct path path; 1812 1812 int error; 1813 1813 1814 1814 if (remount) 1815 1815 return vfs_quota_on_remount(sb, type); 1816 1816 1817 - error = path_lookup(path, LOOKUP_FOLLOW, &nd); 1817 + error = kern_path(name, LOOKUP_FOLLOW, &path); 1818 1818 if (!error) { 1819 - error = vfs_quota_on_path(sb, type, format_id, &nd.path); 1820 - path_put(&nd.path); 1819 + error = vfs_quota_on_path(sb, type, format_id, &path); 1820 + path_put(&path); 1821 1821 } 1822 1822 return error; 1823 1823 }
+9 -14
fs/ecryptfs/main.c
··· 471 471 */ 472 472 static int ecryptfs_read_super(struct super_block *sb, const char *dev_name) 473 473 { 474 + struct path path; 474 475 int rc; 475 - struct nameidata nd; 476 - struct dentry *lower_root; 477 - struct vfsmount *lower_mnt; 478 476 479 - memset(&nd, 0, sizeof(struct nameidata)); 480 - rc = path_lookup(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &nd); 477 + rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); 481 478 if (rc) { 482 479 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n"); 483 480 goto out; 484 481 } 485 - lower_root = nd.path.dentry; 486 - lower_mnt = nd.path.mnt; 487 - ecryptfs_set_superblock_lower(sb, lower_root->d_sb); 488 - sb->s_maxbytes = lower_root->d_sb->s_maxbytes; 489 - sb->s_blocksize = lower_root->d_sb->s_blocksize; 490 - ecryptfs_set_dentry_lower(sb->s_root, lower_root); 491 - ecryptfs_set_dentry_lower_mnt(sb->s_root, lower_mnt); 492 - rc = ecryptfs_interpose(lower_root, sb->s_root, sb, 0); 482 + ecryptfs_set_superblock_lower(sb, path.dentry->d_sb); 483 + sb->s_maxbytes = path.dentry->d_sb->s_maxbytes; 484 + sb->s_blocksize = path.dentry->d_sb->s_blocksize; 485 + ecryptfs_set_dentry_lower(sb->s_root, path.dentry); 486 + ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt); 487 + rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0); 493 488 if (rc) 494 489 goto out_free; 495 490 rc = 0; 496 491 goto out; 497 492 out_free: 498 - path_put(&nd.path); 493 + path_put(&path); 499 494 out: 500 495 return rc; 501 496 }
+4 -25
fs/efs/namei.c
··· 112 112 113 113 struct dentry *efs_get_parent(struct dentry *child) 114 114 { 115 - struct dentry *parent; 116 - struct inode *inode; 115 + struct dentry *parent = ERR_PTR(-ENOENT); 117 116 efs_ino_t ino; 118 - long error; 119 117 120 118 lock_kernel(); 121 - 122 - error = -ENOENT; 123 119 ino = efs_find_entry(child->d_inode, "..", 2); 124 - if (!ino) 125 - goto fail; 126 - 127 - inode = efs_iget(child->d_inode->i_sb, ino); 128 - if (IS_ERR(inode)) { 129 - error = PTR_ERR(inode); 130 - goto fail; 131 - } 132 - 133 - error = -ENOMEM; 134 - parent = d_alloc_anon(inode); 135 - if (!parent) 136 - goto fail_iput; 137 - 120 + if (ino) 121 + parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino)); 138 122 unlock_kernel(); 123 + 139 124 return parent; 140 - 141 - fail_iput: 142 - iput(inode); 143 - fail: 144 - unlock_kernel(); 145 - return ERR_PTR(error); 146 125 }
+8 -12
fs/exportfs/expfs.c
··· 94 94 * It may already be, as the flag isn't always updated when connection happens. 95 95 */ 96 96 static int 97 - reconnect_path(struct vfsmount *mnt, struct dentry *target_dir) 97 + reconnect_path(struct vfsmount *mnt, struct dentry *target_dir, char *nbuf) 98 98 { 99 - char nbuf[NAME_MAX+1]; 100 99 int noprogress = 0; 101 100 int err = -ESTALE; 102 101 ··· 280 281 int old_seq = buffer.sequence; 281 282 282 283 error = vfs_readdir(file, filldir_one, &buffer); 284 + if (buffer.found) { 285 + error = 0; 286 + break; 287 + } 283 288 284 289 if (error < 0) 285 290 break; 286 291 287 - error = 0; 288 - if (buffer.found) 289 - break; 290 292 error = -ENOENT; 291 293 if (old_seq == buffer.sequence) 292 294 break; ··· 360 360 { 361 361 const struct export_operations *nop = mnt->mnt_sb->s_export_op; 362 362 struct dentry *result, *alias; 363 + char nbuf[NAME_MAX+1]; 363 364 int err; 364 365 365 366 /* 366 367 * Try to get any dentry for the given file handle from the filesystem. 367 368 */ 368 369 result = nop->fh_to_dentry(mnt->mnt_sb, fid, fh_len, fileid_type); 369 - if (!result) 370 - result = ERR_PTR(-ESTALE); 371 370 if (IS_ERR(result)) 372 371 return result; 373 372 ··· 380 381 * filesystem root. 381 382 */ 382 383 if (result->d_flags & DCACHE_DISCONNECTED) { 383 - err = reconnect_path(mnt, result); 384 + err = reconnect_path(mnt, result, nbuf); 384 385 if (err) 385 386 goto err_result; 386 387 } ··· 396 397 * It's not a directory. Life is a little more complicated. 397 398 */ 398 399 struct dentry *target_dir, *nresult; 399 - char nbuf[NAME_MAX+1]; 400 400 401 401 /* 402 402 * See if either the dentry we just got from the filesystem ··· 420 422 421 423 target_dir = nop->fh_to_parent(mnt->mnt_sb, fid, 422 424 fh_len, fileid_type); 423 - if (!target_dir) 424 - goto err_result; 425 425 err = PTR_ERR(target_dir); 426 426 if (IS_ERR(target_dir)) 427 427 goto err_result; ··· 429 433 * connected to the filesystem root. The VFS really doesn't 430 434 * like disconnected directories.. 431 435 */ 432 - err = reconnect_path(mnt, target_dir); 436 + err = reconnect_path(mnt, target_dir, nbuf); 433 437 if (err) { 434 438 dput(target_dir); 435 439 goto err_result;
+7 -7
fs/ext2/dir.c
··· 354 354 * (as a parameter - res_dir). Page is returned mapped and unlocked. 355 355 * Entry is guaranteed to be valid. 356 356 */ 357 - struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir, 358 - struct dentry *dentry, struct page ** res_page) 357 + struct ext2_dir_entry_2 *ext2_find_entry (struct inode * dir, 358 + struct qstr *child, struct page ** res_page) 359 359 { 360 - const char *name = dentry->d_name.name; 361 - int namelen = dentry->d_name.len; 360 + const char *name = child->name; 361 + int namelen = child->len; 362 362 unsigned reclen = EXT2_DIR_REC_LEN(namelen); 363 363 unsigned long start, n; 364 364 unsigned long npages = dir_pages(dir); ··· 431 431 return de; 432 432 } 433 433 434 - ino_t ext2_inode_by_name(struct inode * dir, struct dentry *dentry) 434 + ino_t ext2_inode_by_name(struct inode *dir, struct qstr *child) 435 435 { 436 436 ino_t res = 0; 437 - struct ext2_dir_entry_2 * de; 437 + struct ext2_dir_entry_2 *de; 438 438 struct page *page; 439 439 440 - de = ext2_find_entry (dir, dentry, &page); 440 + de = ext2_find_entry (dir, child, &page); 441 441 if (de) { 442 442 res = le32_to_cpu(de->inode); 443 443 ext2_put_page(page);
+2 -2
fs/ext2/ext2.h
··· 105 105 106 106 /* dir.c */ 107 107 extern int ext2_add_link (struct dentry *, struct inode *); 108 - extern ino_t ext2_inode_by_name(struct inode *, struct dentry *); 108 + extern ino_t ext2_inode_by_name(struct inode *, struct qstr *); 109 109 extern int ext2_make_empty(struct inode *, struct inode *); 110 - extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct dentry *, struct page **); 110 + extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct qstr *, struct page **); 111 111 extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *); 112 112 extern int ext2_empty_dir (struct inode *); 113 113 extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
+7 -23
fs/ext2/namei.c
··· 60 60 if (dentry->d_name.len > EXT2_NAME_LEN) 61 61 return ERR_PTR(-ENAMETOOLONG); 62 62 63 - ino = ext2_inode_by_name(dir, dentry); 63 + ino = ext2_inode_by_name(dir, &dentry->d_name); 64 64 inode = NULL; 65 65 if (ino) { 66 66 inode = ext2_iget(dir->i_sb, ino); ··· 72 72 73 73 struct dentry *ext2_get_parent(struct dentry *child) 74 74 { 75 - unsigned long ino; 76 - struct dentry *parent; 77 - struct inode *inode; 78 - struct dentry dotdot; 79 - 80 - dotdot.d_name.name = ".."; 81 - dotdot.d_name.len = 2; 82 - 83 - ino = ext2_inode_by_name(child->d_inode, &dotdot); 75 + struct qstr dotdot = {.name = "..", .len = 2}; 76 + unsigned long ino = ext2_inode_by_name(child->d_inode, &dotdot); 84 77 if (!ino) 85 78 return ERR_PTR(-ENOENT); 86 - inode = ext2_iget(child->d_inode->i_sb, ino); 87 - 88 - if (IS_ERR(inode)) 89 - return ERR_CAST(inode); 90 - parent = d_alloc_anon(inode); 91 - if (!parent) { 92 - iput(inode); 93 - parent = ERR_PTR(-ENOMEM); 94 - } 95 - return parent; 79 + return d_obtain_alias(ext2_iget(child->d_inode->i_sb, ino)); 96 80 } 97 81 98 82 /* ··· 241 257 struct page * page; 242 258 int err = -ENOENT; 243 259 244 - de = ext2_find_entry (dir, dentry, &page); 260 + de = ext2_find_entry (dir, &dentry->d_name, &page); 245 261 if (!de) 246 262 goto out; 247 263 ··· 283 299 struct ext2_dir_entry_2 * old_de; 284 300 int err = -ENOENT; 285 301 286 - old_de = ext2_find_entry (old_dir, old_dentry, &old_page); 302 + old_de = ext2_find_entry (old_dir, &old_dentry->d_name, &old_page); 287 303 if (!old_de) 288 304 goto out; 289 305 ··· 303 319 goto out_dir; 304 320 305 321 err = -ENOENT; 306 - new_de = ext2_find_entry (new_dir, new_dentry, &new_page); 322 + new_de = ext2_find_entry (new_dir, &new_dentry->d_name, &new_page); 307 323 if (!new_de) 308 324 goto out_dir; 309 325 inode_inc_link_count(old_inode);
+34 -50
fs/ext3/namei.c
··· 159 159 static void dx_set_limit (struct dx_entry *entries, unsigned value); 160 160 static unsigned dx_root_limit (struct inode *dir, unsigned infosize); 161 161 static unsigned dx_node_limit (struct inode *dir); 162 - static struct dx_frame *dx_probe(struct dentry *dentry, 162 + static struct dx_frame *dx_probe(struct qstr *entry, 163 163 struct inode *dir, 164 164 struct dx_hash_info *hinfo, 165 165 struct dx_frame *frame, ··· 176 176 struct dx_frame *frame, 177 177 struct dx_frame *frames, 178 178 __u32 *start_hash); 179 - static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, 180 - struct ext3_dir_entry_2 **res_dir, int *err); 179 + static struct buffer_head * ext3_dx_find_entry(struct inode *dir, 180 + struct qstr *entry, struct ext3_dir_entry_2 **res_dir, 181 + int *err); 181 182 static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, 182 183 struct inode *inode); 183 184 ··· 343 342 * back to userspace. 344 343 */ 345 344 static struct dx_frame * 346 - dx_probe(struct dentry *dentry, struct inode *dir, 345 + dx_probe(struct qstr *entry, struct inode *dir, 347 346 struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err) 348 347 { 349 348 unsigned count, indirect; ··· 354 353 u32 hash; 355 354 356 355 frame->bh = NULL; 357 - if (dentry) 358 - dir = dentry->d_parent->d_inode; 359 356 if (!(bh = ext3_bread (NULL,dir, 0, 0, err))) 360 357 goto fail; 361 358 root = (struct dx_root *) bh->b_data; ··· 369 370 } 370 371 hinfo->hash_version = root->info.hash_version; 371 372 hinfo->seed = EXT3_SB(dir->i_sb)->s_hash_seed; 372 - if (dentry) 373 - ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo); 373 + if (entry) 374 + ext3fs_dirhash(entry->name, entry->len, hinfo); 374 375 hash = hinfo->hash; 375 376 376 377 if (root->info.unused_flags & 1) { ··· 802 803 */ 803 804 static inline int search_dirblock(struct buffer_head * bh, 804 805 struct inode *dir, 805 - struct dentry *dentry, 806 + struct qstr *child, 806 807 unsigned long offset, 807 808 struct ext3_dir_entry_2 ** res_dir) 808 809 { 809 810 struct ext3_dir_entry_2 * de; 810 811 char * dlimit; 811 812 int de_len; 812 - const char *name = dentry->d_name.name; 813 - int namelen = dentry->d_name.len; 813 + const char *name = child->name; 814 + int namelen = child->len; 814 815 815 816 de = (struct ext3_dir_entry_2 *) bh->b_data; 816 817 dlimit = bh->b_data + dir->i_sb->s_blocksize; ··· 849 850 * The returned buffer_head has ->b_count elevated. The caller is expected 850 851 * to brelse() it when appropriate. 851 852 */ 852 - static struct buffer_head * ext3_find_entry (struct dentry *dentry, 853 - struct ext3_dir_entry_2 ** res_dir) 853 + static struct buffer_head *ext3_find_entry(struct inode *dir, 854 + struct qstr *entry, 855 + struct ext3_dir_entry_2 **res_dir) 854 856 { 855 857 struct super_block * sb; 856 858 struct buffer_head * bh_use[NAMEI_RA_SIZE]; ··· 863 863 buffer */ 864 864 int num = 0; 865 865 int nblocks, i, err; 866 - struct inode *dir = dentry->d_parent->d_inode; 867 866 int namelen; 868 867 869 868 *res_dir = NULL; 870 869 sb = dir->i_sb; 871 - namelen = dentry->d_name.len; 870 + namelen = entry->len; 872 871 if (namelen > EXT3_NAME_LEN) 873 872 return NULL; 874 873 if (is_dx(dir)) { 875 - bh = ext3_dx_find_entry(dentry, res_dir, &err); 874 + bh = ext3_dx_find_entry(dir, entry, res_dir, &err); 876 875 /* 877 876 * On success, or if the error was file not found, 878 877 * return. Otherwise, fall back to doing a search the ··· 922 923 brelse(bh); 923 924 goto next; 924 925 } 925 - i = search_dirblock(bh, dir, dentry, 926 + i = search_dirblock(bh, dir, entry, 926 927 block << EXT3_BLOCK_SIZE_BITS(sb), res_dir); 927 928 if (i == 1) { 928 929 EXT3_I(dir)->i_dir_start_lookup = block; ··· 956 957 return ret; 957 958 } 958 959 959 - static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, 960 - struct ext3_dir_entry_2 **res_dir, int *err) 960 + static struct buffer_head * ext3_dx_find_entry(struct inode *dir, 961 + struct qstr *entry, struct ext3_dir_entry_2 **res_dir, 962 + int *err) 961 963 { 962 964 struct super_block * sb; 963 965 struct dx_hash_info hinfo; ··· 968 968 struct buffer_head *bh; 969 969 unsigned long block; 970 970 int retval; 971 - int namelen = dentry->d_name.len; 972 - const u8 *name = dentry->d_name.name; 973 - struct inode *dir = dentry->d_parent->d_inode; 971 + int namelen = entry->len; 972 + const u8 *name = entry->name; 974 973 975 974 sb = dir->i_sb; 976 975 /* NFS may look up ".." - look at dx_root directory block */ 977 - if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){ 978 - if (!(frame = dx_probe(dentry, NULL, &hinfo, frames, err))) 976 + if (namelen > 2 || name[0] != '.'|| (namelen == 2 && name[1] != '.')) { 977 + if (!(frame = dx_probe(entry, dir, &hinfo, frames, err))) 979 978 return NULL; 980 979 } else { 981 980 frame = frames; ··· 1035 1036 if (dentry->d_name.len > EXT3_NAME_LEN) 1036 1037 return ERR_PTR(-ENAMETOOLONG); 1037 1038 1038 - bh = ext3_find_entry(dentry, &de); 1039 + bh = ext3_find_entry(dir, &dentry->d_name, &de); 1039 1040 inode = NULL; 1040 1041 if (bh) { 1041 1042 unsigned long ino = le32_to_cpu(de->inode); ··· 1056 1057 struct dentry *ext3_get_parent(struct dentry *child) 1057 1058 { 1058 1059 unsigned long ino; 1059 - struct dentry *parent; 1060 - struct inode *inode; 1061 - struct dentry dotdot; 1060 + struct qstr dotdot = {.name = "..", .len = 2}; 1062 1061 struct ext3_dir_entry_2 * de; 1063 1062 struct buffer_head *bh; 1064 1063 1065 - dotdot.d_name.name = ".."; 1066 - dotdot.d_name.len = 2; 1067 - dotdot.d_parent = child; /* confusing, isn't it! */ 1068 - 1069 - bh = ext3_find_entry(&dotdot, &de); 1070 - inode = NULL; 1064 + bh = ext3_find_entry(child->d_inode, &dotdot, &de); 1071 1065 if (!bh) 1072 1066 return ERR_PTR(-ENOENT); 1073 1067 ino = le32_to_cpu(de->inode); ··· 1072 1080 return ERR_PTR(-EIO); 1073 1081 } 1074 1082 1075 - inode = ext3_iget(child->d_inode->i_sb, ino); 1076 - if (IS_ERR(inode)) 1077 - return ERR_CAST(inode); 1078 - 1079 - parent = d_alloc_anon(inode); 1080 - if (!parent) { 1081 - iput(inode); 1082 - parent = ERR_PTR(-ENOMEM); 1083 - } 1084 - return parent; 1083 + return d_obtain_alias(ext3_iget(child->d_inode->i_sb, ino)); 1085 1084 } 1086 1085 1087 1086 #define S_SHIFT 12 ··· 1486 1503 struct ext3_dir_entry_2 *de; 1487 1504 int err; 1488 1505 1489 - frame = dx_probe(dentry, NULL, &hinfo, frames, &err); 1506 + frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err); 1490 1507 if (!frame) 1491 1508 return err; 1492 1509 entries = frame->entries; ··· 2039 2056 return PTR_ERR(handle); 2040 2057 2041 2058 retval = -ENOENT; 2042 - bh = ext3_find_entry (dentry, &de); 2059 + bh = ext3_find_entry(dir, &dentry->d_name, &de); 2043 2060 if (!bh) 2044 2061 goto end_rmdir; 2045 2062 ··· 2101 2118 handle->h_sync = 1; 2102 2119 2103 2120 retval = -ENOENT; 2104 - bh = ext3_find_entry (dentry, &de); 2121 + bh = ext3_find_entry(dir, &dentry->d_name, &de); 2105 2122 if (!bh) 2106 2123 goto end_unlink; 2107 2124 ··· 2259 2276 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) 2260 2277 handle->h_sync = 1; 2261 2278 2262 - old_bh = ext3_find_entry (old_dentry, &old_de); 2279 + old_bh = ext3_find_entry(old_dir, &old_dentry->d_name, &old_de); 2263 2280 /* 2264 2281 * Check for inode number is _not_ due to possible IO errors. 2265 2282 * We might rmdir the source, keep it as pwd of some process ··· 2272 2289 goto end_rename; 2273 2290 2274 2291 new_inode = new_dentry->d_inode; 2275 - new_bh = ext3_find_entry (new_dentry, &new_de); 2292 + new_bh = ext3_find_entry(new_dir, &new_dentry->d_name, &new_de); 2276 2293 if (new_bh) { 2277 2294 if (!new_inode) { 2278 2295 brelse (new_bh); ··· 2338 2355 struct buffer_head *old_bh2; 2339 2356 struct ext3_dir_entry_2 *old_de2; 2340 2357 2341 - old_bh2 = ext3_find_entry(old_dentry, &old_de2); 2358 + old_bh2 = ext3_find_entry(old_dir, &old_dentry->d_name, 2359 + &old_de2); 2342 2360 if (old_bh2) { 2343 2361 retval = ext3_delete_entry(handle, old_dir, 2344 2362 old_de2, old_bh2);
+11 -11
fs/ext3/super.c
··· 2794 2794 * Standard function to be called on quota_on 2795 2795 */ 2796 2796 static int ext3_quota_on(struct super_block *sb, int type, int format_id, 2797 - char *path, int remount) 2797 + char *name, int remount) 2798 2798 { 2799 2799 int err; 2800 - struct nameidata nd; 2800 + struct path path; 2801 2801 2802 2802 if (!test_opt(sb, QUOTA)) 2803 2803 return -EINVAL; 2804 - /* When remounting, no checks are needed and in fact, path is NULL */ 2804 + /* When remounting, no checks are needed and in fact, name is NULL */ 2805 2805 if (remount) 2806 - return vfs_quota_on(sb, type, format_id, path, remount); 2806 + return vfs_quota_on(sb, type, format_id, name, remount); 2807 2807 2808 - err = path_lookup(path, LOOKUP_FOLLOW, &nd); 2808 + err = kern_path(name, LOOKUP_FOLLOW, &path); 2809 2809 if (err) 2810 2810 return err; 2811 2811 2812 2812 /* Quotafile not on the same filesystem? */ 2813 - if (nd.path.mnt->mnt_sb != sb) { 2814 - path_put(&nd.path); 2813 + if (path.mnt->mnt_sb != sb) { 2814 + path_put(&path); 2815 2815 return -EXDEV; 2816 2816 } 2817 2817 /* Journaling quota? */ 2818 2818 if (EXT3_SB(sb)->s_qf_names[type]) { 2819 2819 /* Quotafile not of fs root? */ 2820 - if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode) 2820 + if (path.dentry->d_parent != sb->s_root) 2821 2821 printk(KERN_WARNING 2822 2822 "EXT3-fs: Quota file not on filesystem root. " 2823 2823 "Journaled quota will not work.\n"); ··· 2827 2827 * When we journal data on quota file, we have to flush journal to see 2828 2828 * all updates to the file when we bypass pagecache... 2829 2829 */ 2830 - if (ext3_should_journal_data(nd.path.dentry->d_inode)) { 2830 + if (ext3_should_journal_data(path.dentry->d_inode)) { 2831 2831 /* 2832 2832 * We don't need to lock updates but journal_flush() could 2833 2833 * otherwise be livelocked... ··· 2841 2841 } 2842 2842 } 2843 2843 2844 - err = vfs_quota_on_path(sb, type, format_id, &nd.path); 2845 - path_put(&nd.path); 2844 + err = vfs_quota_on_path(sb, type, format_id, &path); 2845 + path_put(&path); 2846 2846 return err; 2847 2847 } 2848 2848
+1 -10
fs/ext4/namei.c
··· 1083 1083 return ERR_PTR(-EIO); 1084 1084 } 1085 1085 1086 - inode = ext4_iget(child->d_inode->i_sb, ino); 1087 - if (IS_ERR(inode)) 1088 - return ERR_CAST(inode); 1089 - 1090 - parent = d_alloc_anon(inode); 1091 - if (!parent) { 1092 - iput(inode); 1093 - parent = ERR_PTR(-ENOMEM); 1094 - } 1095 - return parent; 1086 + return d_obtain_alias(ext4_iget(child->d_inode->i_sb, ino)); 1096 1087 } 1097 1088 1098 1089 #define S_SHIFT 12
+12 -12
fs/ext4/super.c
··· 3328 3328 * Standard function to be called on quota_on 3329 3329 */ 3330 3330 static int ext4_quota_on(struct super_block *sb, int type, int format_id, 3331 - char *path, int remount) 3331 + char *name, int remount) 3332 3332 { 3333 3333 int err; 3334 - struct nameidata nd; 3334 + struct path path; 3335 3335 3336 3336 if (!test_opt(sb, QUOTA)) 3337 3337 return -EINVAL; 3338 - /* When remounting, no checks are needed and in fact, path is NULL */ 3338 + /* When remounting, no checks are needed and in fact, name is NULL */ 3339 3339 if (remount) 3340 - return vfs_quota_on(sb, type, format_id, path, remount); 3340 + return vfs_quota_on(sb, type, format_id, name, remount); 3341 3341 3342 - err = path_lookup(path, LOOKUP_FOLLOW, &nd); 3342 + err = kern_path(name, LOOKUP_FOLLOW, &path); 3343 3343 if (err) 3344 3344 return err; 3345 3345 3346 3346 /* Quotafile not on the same filesystem? */ 3347 - if (nd.path.mnt->mnt_sb != sb) { 3348 - path_put(&nd.path); 3347 + if (path.mnt->mnt_sb != sb) { 3348 + path_put(&path); 3349 3349 return -EXDEV; 3350 3350 } 3351 3351 /* Journaling quota? */ 3352 3352 if (EXT4_SB(sb)->s_qf_names[type]) { 3353 3353 /* Quotafile not in fs root? */ 3354 - if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode) 3354 + if (path.dentry->d_parent != sb->s_root) 3355 3355 printk(KERN_WARNING 3356 3356 "EXT4-fs: Quota file not on filesystem root. " 3357 3357 "Journaled quota will not work.\n"); ··· 3361 3361 * When we journal data on quota file, we have to flush journal to see 3362 3362 * all updates to the file when we bypass pagecache... 3363 3363 */ 3364 - if (ext4_should_journal_data(nd.path.dentry->d_inode)) { 3364 + if (ext4_should_journal_data(path.dentry->d_inode)) { 3365 3365 /* 3366 3366 * We don't need to lock updates but journal_flush() could 3367 3367 * otherwise be livelocked... ··· 3370 3370 err = jbd2_journal_flush(EXT4_SB(sb)->s_journal); 3371 3371 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3372 3372 if (err) { 3373 - path_put(&nd.path); 3373 + path_put(&path); 3374 3374 return err; 3375 3375 } 3376 3376 } 3377 3377 3378 - err = vfs_quota_on_path(sb, type, format_id, &nd.path); 3379 - path_put(&nd.path); 3378 + err = vfs_quota_on_path(sb, type, format_id, &path); 3379 + path_put(&path); 3380 3380 return err; 3381 3381 } 3382 3382
+1
fs/fat/dir.c
··· 839 839 .compat_ioctl = fat_compat_dir_ioctl, 840 840 #endif 841 841 .fsync = file_fsync, 842 + .llseek = generic_file_llseek, 842 843 }; 843 844 844 845 static int fat_get_short_entry(struct inode *dir, loff_t *pos,
+18 -34
fs/fat/inode.c
··· 681 681 inode = NULL; 682 682 } 683 683 } 684 - if (!inode) { 685 - /* For now, do nothing 686 - * What we could do is: 687 - * follow the file starting at fh[4], and record 688 - * the ".." entry, and the name of the fh[2] entry. 689 - * The follow the ".." file finding the next step up. 690 - * This way we build a path to the root of 691 - * the tree. If this works, we lookup the path and so 692 - * get this inode into the cache. 693 - * Finally try the fat_iget lookup again 694 - * If that fails, then weare totally out of luck 695 - * But all that is for another day 696 - */ 697 - } 698 - if (!inode) 699 - return ERR_PTR(-ESTALE); 700 684 701 - 702 - /* now to find a dentry. 703 - * If possible, get a well-connected one 685 + /* 686 + * For now, do nothing if the inode is not found. 687 + * 688 + * What we could do is: 689 + * 690 + * - follow the file starting at fh[4], and record the ".." entry, 691 + * and the name of the fh[2] entry. 692 + * - then follow the ".." file finding the next step up. 693 + * 694 + * This way we build a path to the root of the tree. If this works, we 695 + * lookup the path and so get this inode into the cache. Finally try 696 + * the fat_iget lookup again. If that fails, then we are totally out 697 + * of luck. But all that is for another day 704 698 */ 705 - result = d_alloc_anon(inode); 706 - if (result == NULL) { 707 - iput(inode); 708 - return ERR_PTR(-ENOMEM); 709 - } 710 - result->d_op = sb->s_root->d_op; 699 + result = d_obtain_alias(inode); 700 + if (!IS_ERR(result)) 701 + result->d_op = sb->s_root->d_op; 711 702 return result; 712 703 } 713 704 ··· 745 754 } 746 755 inode = fat_build_inode(sb, de, i_pos); 747 756 brelse(bh); 748 - if (IS_ERR(inode)) { 749 - parent = ERR_CAST(inode); 750 - goto out; 751 - } 752 - parent = d_alloc_anon(inode); 753 - if (!parent) { 754 - iput(inode); 755 - parent = ERR_PTR(-ENOMEM); 756 - } 757 + 758 + parent = d_obtain_alias(inode); 757 759 out: 758 760 unlock_super(sb); 759 761
+8 -15
fs/fuse/inode.c
··· 596 596 if (inode->i_generation != handle->generation) 597 597 goto out_iput; 598 598 599 - entry = d_alloc_anon(inode); 600 - err = -ENOMEM; 601 - if (!entry) 602 - goto out_iput; 603 - 604 - if (get_node_id(inode) != FUSE_ROOT_ID) { 599 + entry = d_obtain_alias(inode); 600 + if (!IS_ERR(entry) && get_node_id(inode) != FUSE_ROOT_ID) { 605 601 entry->d_op = &fuse_dentry_operations; 606 602 fuse_invalidate_entry_cache(entry); 607 603 } ··· 692 696 name.name = ".."; 693 697 err = fuse_lookup_name(child_inode->i_sb, get_node_id(child_inode), 694 698 &name, &outarg, &inode); 695 - if (err && err != -ENOENT) 699 + if (err) { 700 + if (err == -ENOENT) 701 + return ERR_PTR(-ESTALE); 696 702 return ERR_PTR(err); 697 - if (err || !inode) 698 - return ERR_PTR(-ESTALE); 699 - 700 - parent = d_alloc_anon(inode); 701 - if (!parent) { 702 - iput(inode); 703 - return ERR_PTR(-ENOMEM); 704 703 } 705 - if (get_node_id(inode) != FUSE_ROOT_ID) { 704 + 705 + parent = d_obtain_alias(inode); 706 + if (!IS_ERR(parent) && get_node_id(inode) != FUSE_ROOT_ID) { 706 707 parent->d_op = &fuse_dentry_operations; 707 708 fuse_invalidate_entry_cache(parent); 708 709 }
+9 -24
fs/gfs2/ops_export.c
··· 130 130 static struct dentry *gfs2_get_parent(struct dentry *child) 131 131 { 132 132 struct qstr dotdot; 133 - struct inode *inode; 134 133 struct dentry *dentry; 135 134 136 - gfs2_str2qstr(&dotdot, ".."); 137 - inode = gfs2_lookupi(child->d_inode, &dotdot, 1); 138 - 139 - if (!inode) 140 - return ERR_PTR(-ENOENT); 141 135 /* 142 - * In case of an error, @inode carries the error value, and we 143 - * have to return that as a(n invalid) pointer to dentry. 136 + * XXX(hch): it would be a good idea to keep this around as a 137 + * static variable. 144 138 */ 145 - if (IS_ERR(inode)) 146 - return ERR_CAST(inode); 139 + gfs2_str2qstr(&dotdot, ".."); 147 140 148 - dentry = d_alloc_anon(inode); 149 - if (!dentry) { 150 - iput(inode); 151 - return ERR_PTR(-ENOMEM); 152 - } 153 - 154 - dentry->d_op = &gfs2_dops; 141 + dentry = d_obtain_alias(gfs2_lookupi(child->d_inode, &dotdot, 1)); 142 + if (!IS_ERR(dentry)) 143 + dentry->d_op = &gfs2_dops; 155 144 return dentry; 156 145 } 157 146 ··· 222 233 gfs2_glock_dq_uninit(&i_gh); 223 234 224 235 out_inode: 225 - dentry = d_alloc_anon(inode); 226 - if (!dentry) { 227 - iput(inode); 228 - return ERR_PTR(-ENOMEM); 229 - } 230 - 231 - dentry->d_op = &gfs2_dops; 236 + dentry = d_obtain_alias(inode); 237 + if (!IS_ERR(dentry)) 238 + dentry->d_op = &gfs2_dops; 232 239 return dentry; 233 240 234 241 fail_rgd:
+1 -1
fs/gfs2/ops_inode.c
··· 69 69 mark_inode_dirty(inode); 70 70 break; 71 71 } else if (PTR_ERR(inode) != -EEXIST || 72 - (nd && (nd->intent.open.flags & O_EXCL))) { 72 + (nd && nd->flags & LOOKUP_EXCL)) { 73 73 gfs2_holder_uninit(ghs); 74 74 return PTR_ERR(inode); 75 75 }
-8
fs/hfs/inode.c
··· 511 511 } 512 512 } 513 513 514 - static int hfs_permission(struct inode *inode, int mask) 515 - { 516 - if (S_ISREG(inode->i_mode) && mask & MAY_EXEC) 517 - return 0; 518 - return generic_permission(inode, mask, NULL); 519 - } 520 - 521 514 static int hfs_file_open(struct inode *inode, struct file *file) 522 515 { 523 516 if (HFS_IS_RSRC(inode)) ··· 609 616 .lookup = hfs_file_lookup, 610 617 .truncate = hfs_file_truncate, 611 618 .setattr = hfs_inode_setattr, 612 - .permission = hfs_permission, 613 619 .setxattr = hfs_setxattr, 614 620 .getxattr = hfs_getxattr, 615 621 .listxattr = hfs_listxattr,
-13
fs/hfsplus/inode.c
··· 238 238 perms->dev = cpu_to_be32(HFSPLUS_I(inode).dev); 239 239 } 240 240 241 - static int hfsplus_permission(struct inode *inode, int mask) 242 - { 243 - /* MAY_EXEC is also used for lookup, if no x bit is set allow lookup, 244 - * open_exec has the same test, so it's still not executable, if a x bit 245 - * is set fall back to standard permission check. 246 - */ 247 - if (S_ISREG(inode->i_mode) && mask & MAY_EXEC && !(inode->i_mode & 0111)) 248 - return 0; 249 - return generic_permission(inode, mask, NULL); 250 - } 251 - 252 - 253 241 static int hfsplus_file_open(struct inode *inode, struct file *file) 254 242 { 255 243 if (HFSPLUS_IS_RSRC(inode)) ··· 269 281 static const struct inode_operations hfsplus_file_inode_operations = { 270 282 .lookup = hfsplus_file_lookup, 271 283 .truncate = hfsplus_file_truncate, 272 - .permission = hfsplus_permission, 273 284 .setxattr = hfsplus_setxattr, 274 285 .getxattr = hfsplus_getxattr, 275 286 .listxattr = hfsplus_listxattr,
+1 -1
fs/hpfs/file.c
··· 143 143 const struct inode_operations hpfs_file_iops = 144 144 { 145 145 .truncate = hpfs_truncate, 146 - .setattr = hpfs_notify_change, 146 + .setattr = hpfs_setattr, 147 147 };
+1 -1
fs/hpfs/hpfs_fn.h
··· 275 275 void hpfs_read_inode(struct inode *); 276 276 void hpfs_write_inode(struct inode *); 277 277 void hpfs_write_inode_nolock(struct inode *); 278 - int hpfs_notify_change(struct dentry *, struct iattr *); 278 + int hpfs_setattr(struct dentry *, struct iattr *); 279 279 void hpfs_write_if_changed(struct inode *); 280 280 void hpfs_delete_inode(struct inode *); 281 281
+19 -10
fs/hpfs/inode.c
··· 260 260 brelse(bh); 261 261 } 262 262 263 - int hpfs_notify_change(struct dentry *dentry, struct iattr *attr) 263 + int hpfs_setattr(struct dentry *dentry, struct iattr *attr) 264 264 { 265 265 struct inode *inode = dentry->d_inode; 266 - int error=0; 266 + int error = -EINVAL; 267 + 267 268 lock_kernel(); 268 - if ( ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size) || 269 - (hpfs_sb(inode->i_sb)->sb_root == inode->i_ino) ) { 270 - error = -EINVAL; 271 - } else if ((error = inode_change_ok(inode, attr))) { 272 - } else if ((error = inode_setattr(inode, attr))) { 273 - } else { 274 - hpfs_write_inode(inode); 275 - } 269 + if (inode->i_ino == hpfs_sb(inode->i_sb)->sb_root) 270 + goto out_unlock; 271 + if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size) 272 + goto out_unlock; 273 + 274 + error = inode_change_ok(inode, attr); 275 + if (error) 276 + goto out_unlock; 277 + 278 + error = inode_setattr(inode, attr); 279 + if (error) 280 + goto out_unlock; 281 + 282 + hpfs_write_inode(inode); 283 + 284 + out_unlock: 276 285 unlock_kernel(); 277 286 return error; 278 287 }
+1 -1
fs/hpfs/namei.c
··· 669 669 .rmdir = hpfs_rmdir, 670 670 .mknod = hpfs_mknod, 671 671 .rename = hpfs_rename, 672 - .setattr = hpfs_notify_change, 672 + .setattr = hpfs_setattr, 673 673 };
+5 -28
fs/isofs/export.c
··· 22 22 __u32 generation) 23 23 { 24 24 struct inode *inode; 25 - struct dentry *result; 25 + 26 26 if (block == 0) 27 27 return ERR_PTR(-ESTALE); 28 28 inode = isofs_iget(sb, block, offset); ··· 32 32 iput(inode); 33 33 return ERR_PTR(-ESTALE); 34 34 } 35 - result = d_alloc_anon(inode); 36 - if (!result) { 37 - iput(inode); 38 - return ERR_PTR(-ENOMEM); 39 - } 40 - return result; 35 + return d_obtain_alias(inode); 41 36 } 42 37 43 38 /* This function is surprisingly simple. The trick is understanding ··· 46 51 unsigned long parent_offset = 0; 47 52 struct inode *child_inode = child->d_inode; 48 53 struct iso_inode_info *e_child_inode = ISOFS_I(child_inode); 49 - struct inode *parent_inode = NULL; 50 54 struct iso_directory_record *de = NULL; 51 55 struct buffer_head * bh = NULL; 52 56 struct dentry *rv = NULL; ··· 98 104 /* Normalize */ 99 105 isofs_normalize_block_and_offset(de, &parent_block, &parent_offset); 100 106 101 - /* Get the inode. */ 102 - parent_inode = isofs_iget(child_inode->i_sb, 103 - parent_block, 104 - parent_offset); 105 - if (IS_ERR(parent_inode)) { 106 - rv = ERR_CAST(parent_inode); 107 - if (rv != ERR_PTR(-ENOMEM)) 108 - rv = ERR_PTR(-EACCES); 109 - goto out; 110 - } 111 - 112 - /* Allocate the dentry. */ 113 - rv = d_alloc_anon(parent_inode); 114 - if (rv == NULL) { 115 - rv = ERR_PTR(-ENOMEM); 116 - goto out; 117 - } 118 - 107 + rv = d_obtain_alias(isofs_iget(child_inode->i_sb, parent_block, 108 + parent_offset)); 119 109 out: 120 - if (bh) { 110 + if (bh) 121 111 brelse(bh); 122 - } 123 112 return rv; 124 113 } 125 114
+3 -4
fs/jffs2/dir.c
··· 39 39 .read = generic_read_dir, 40 40 .readdir = jffs2_readdir, 41 41 .unlocked_ioctl=jffs2_ioctl, 42 - .fsync = jffs2_fsync 42 + .fsync = jffs2_fsync, 43 + .llseek = generic_file_llseek, 43 44 }; 44 45 45 46 ··· 109 108 } 110 109 } 111 110 112 - d_add(target, inode); 113 - 114 - return NULL; 111 + return d_splice_alias(inode, target); 115 112 } 116 113 117 114 /***********************************************************************/
+48
fs/jffs2/super.c
··· 22 22 #include <linux/mtd/super.h> 23 23 #include <linux/ctype.h> 24 24 #include <linux/namei.h> 25 + #include <linux/exportfs.h> 25 26 #include "compr.h" 26 27 #include "nodelist.h" 27 28 ··· 62 61 mutex_unlock(&c->alloc_sem); 63 62 return 0; 64 63 } 64 + 65 + static struct inode *jffs2_nfs_get_inode(struct super_block *sb, uint64_t ino, 66 + uint32_t generation) 67 + { 68 + /* We don't care about i_generation. We'll destroy the flash 69 + before we start re-using inode numbers anyway. And even 70 + if that wasn't true, we'd have other problems...*/ 71 + return jffs2_iget(sb, ino); 72 + } 73 + 74 + static struct dentry *jffs2_fh_to_dentry(struct super_block *sb, struct fid *fid, 75 + int fh_len, int fh_type) 76 + { 77 + return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 78 + jffs2_nfs_get_inode); 79 + } 80 + 81 + static struct dentry *jffs2_fh_to_parent(struct super_block *sb, struct fid *fid, 82 + int fh_len, int fh_type) 83 + { 84 + return generic_fh_to_parent(sb, fid, fh_len, fh_type, 85 + jffs2_nfs_get_inode); 86 + } 87 + 88 + static struct dentry *jffs2_get_parent(struct dentry *child) 89 + { 90 + struct jffs2_inode_info *f; 91 + uint32_t pino; 92 + 93 + BUG_ON(!S_ISDIR(child->d_inode->i_mode)); 94 + 95 + f = JFFS2_INODE_INFO(child->d_inode); 96 + 97 + pino = f->inocache->pino_nlink; 98 + 99 + JFFS2_DEBUG("Parent of directory ino #%u is #%u\n", 100 + f->inocache->ino, pino); 101 + 102 + return d_obtain_alias(jffs2_iget(child->d_inode->i_sb, pino)); 103 + } 104 + 105 + static struct export_operations jffs2_export_ops = { 106 + .get_parent = jffs2_get_parent, 107 + .fh_to_dentry = jffs2_fh_to_dentry, 108 + .fh_to_parent = jffs2_fh_to_parent, 109 + }; 65 110 66 111 static const struct super_operations jffs2_super_operations = 67 112 { ··· 151 104 spin_lock_init(&c->inocache_lock); 152 105 153 106 sb->s_op = &jffs2_super_operations; 107 + sb->s_export_op = &jffs2_export_ops; 154 108 sb->s_flags = sb->s_flags | MS_NOATIME; 155 109 sb->s_xattr = jffs2_xattr_handlers; 156 110 #ifdef CONFIG_JFFS2_FS_POSIX_ACL
+2 -14
fs/jfs/namei.c
··· 1511 1511 1512 1512 struct dentry *jfs_get_parent(struct dentry *dentry) 1513 1513 { 1514 - struct super_block *sb = dentry->d_inode->i_sb; 1515 - struct dentry *parent = ERR_PTR(-ENOENT); 1516 - struct inode *inode; 1517 1514 unsigned long parent_ino; 1518 1515 1519 1516 parent_ino = 1520 1517 le32_to_cpu(JFS_IP(dentry->d_inode)->i_dtroot.header.idotdot); 1521 - inode = jfs_iget(sb, parent_ino); 1522 - if (IS_ERR(inode)) { 1523 - parent = ERR_CAST(inode); 1524 - } else { 1525 - parent = d_alloc_anon(inode); 1526 - if (!parent) { 1527 - parent = ERR_PTR(-ENOMEM); 1528 - iput(inode); 1529 - } 1530 - } 1531 1518 1532 - return parent; 1519 + return d_obtain_alias(jfs_iget(dentry->d_inode->i_sb, parent_ino)); 1533 1520 } 1534 1521 1535 1522 const struct inode_operations jfs_dir_inode_operations = { ··· 1547 1560 #ifdef CONFIG_COMPAT 1548 1561 .compat_ioctl = jfs_compat_ioctl, 1549 1562 #endif 1563 + .llseek = generic_file_llseek, 1550 1564 }; 1551 1565 1552 1566 static int jfs_ci_hash(struct dentry *dir, struct qstr *this)
+2 -24
fs/libfs.c
··· 732 732 return ret; 733 733 } 734 734 735 - /* 736 - * This is what d_alloc_anon should have been. Once the exportfs 737 - * argument transition has been finished I will update d_alloc_anon 738 - * to this prototype and this wrapper will go away. --hch 739 - */ 740 - static struct dentry *exportfs_d_alloc(struct inode *inode) 741 - { 742 - struct dentry *dentry; 743 - 744 - if (!inode) 745 - return NULL; 746 - if (IS_ERR(inode)) 747 - return ERR_PTR(PTR_ERR(inode)); 748 - 749 - dentry = d_alloc_anon(inode); 750 - if (!dentry) { 751 - iput(inode); 752 - dentry = ERR_PTR(-ENOMEM); 753 - } 754 - return dentry; 755 - } 756 - 757 735 /** 758 736 * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation 759 737 * @sb: filesystem to do the file handle conversion on ··· 760 782 break; 761 783 } 762 784 763 - return exportfs_d_alloc(inode); 785 + return d_obtain_alias(inode); 764 786 } 765 787 EXPORT_SYMBOL_GPL(generic_fh_to_dentry); 766 788 ··· 793 815 break; 794 816 } 795 817 796 - return exportfs_d_alloc(inode); 818 + return d_obtain_alias(inode); 797 819 } 798 820 EXPORT_SYMBOL_GPL(generic_fh_to_parent); 799 821
+73 -83
fs/namei.c
··· 212 212 * Read/write DACs are always overridable. 213 213 * Executable DACs are overridable if at least one exec bit is set. 214 214 */ 215 - if (!(mask & MAY_EXEC) || 216 - (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode)) 215 + if (!(mask & MAY_EXEC) || execute_ok(inode)) 217 216 if (capable(CAP_DAC_OVERRIDE)) 218 217 return 0; 219 218 ··· 248 249 } 249 250 250 251 /* Ordinary permission routines do not understand MAY_APPEND. */ 251 - if (inode->i_op && inode->i_op->permission) { 252 + if (inode->i_op && inode->i_op->permission) 252 253 retval = inode->i_op->permission(inode, mask); 253 - if (!retval) { 254 - /* 255 - * Exec permission on a regular file is denied if none 256 - * of the execute bits are set. 257 - * 258 - * This check should be done by the ->permission() 259 - * method. 260 - */ 261 - if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode) && 262 - !(inode->i_mode & S_IXUGO)) 263 - return -EACCES; 264 - } 265 - } else { 254 + else 266 255 retval = generic_permission(inode, mask, NULL); 267 - } 256 + 268 257 if (retval) 269 258 return retval; 270 259 ··· 1093 1106 return do_path_lookup(AT_FDCWD, name, flags, nd); 1094 1107 } 1095 1108 1109 + int kern_path(const char *name, unsigned int flags, struct path *path) 1110 + { 1111 + struct nameidata nd; 1112 + int res = do_path_lookup(AT_FDCWD, name, flags, &nd); 1113 + if (!res) 1114 + *path = nd.path; 1115 + return res; 1116 + } 1117 + 1096 1118 /** 1097 1119 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair 1098 1120 * @dentry: pointer to dentry of the base directory ··· 1134 1138 1135 1139 } 1136 1140 1137 - static int __path_lookup_intent_open(int dfd, const char *name, 1138 - unsigned int lookup_flags, struct nameidata *nd, 1139 - int open_flags, int create_mode) 1140 - { 1141 - struct file *filp = get_empty_filp(); 1142 - int err; 1143 - 1144 - if (filp == NULL) 1145 - return -ENFILE; 1146 - nd->intent.open.file = filp; 1147 - nd->intent.open.flags = open_flags; 1148 - nd->intent.open.create_mode = create_mode; 1149 - err = do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd); 1150 - if (IS_ERR(nd->intent.open.file)) { 1151 - if (err == 0) { 1152 - err = PTR_ERR(nd->intent.open.file); 1153 - path_put(&nd->path); 1154 - } 1155 - } else if (err != 0) 1156 - release_open_intent(nd); 1157 - return err; 1158 - } 1159 - 1160 1141 /** 1161 1142 * path_lookup_open - lookup a file path with open intent 1162 1143 * @dfd: the directory to use as base, or AT_FDCWD ··· 1145 1172 int path_lookup_open(int dfd, const char *name, unsigned int lookup_flags, 1146 1173 struct nameidata *nd, int open_flags) 1147 1174 { 1148 - return __path_lookup_intent_open(dfd, name, lookup_flags, nd, 1149 - open_flags, 0); 1150 - } 1175 + struct file *filp = get_empty_filp(); 1176 + int err; 1151 1177 1152 - /** 1153 - * path_lookup_create - lookup a file path with open + create intent 1154 - * @dfd: the directory to use as base, or AT_FDCWD 1155 - * @name: pointer to file name 1156 - * @lookup_flags: lookup intent flags 1157 - * @nd: pointer to nameidata 1158 - * @open_flags: open intent flags 1159 - * @create_mode: create intent flags 1160 - */ 1161 - static int path_lookup_create(int dfd, const char *name, 1162 - unsigned int lookup_flags, struct nameidata *nd, 1163 - int open_flags, int create_mode) 1164 - { 1165 - return __path_lookup_intent_open(dfd, name, lookup_flags|LOOKUP_CREATE, 1166 - nd, open_flags, create_mode); 1178 + if (filp == NULL) 1179 + return -ENFILE; 1180 + nd->intent.open.file = filp; 1181 + nd->intent.open.flags = open_flags; 1182 + nd->intent.open.create_mode = 0; 1183 + err = do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd); 1184 + if (IS_ERR(nd->intent.open.file)) { 1185 + if (err == 0) { 1186 + err = PTR_ERR(nd->intent.open.file); 1187 + path_put(&nd->path); 1188 + } 1189 + } else if (err != 0) 1190 + release_open_intent(nd); 1191 + return err; 1167 1192 } 1168 1193 1169 1194 static struct dentry *__lookup_hash(struct qstr *name, ··· 1441 1470 1442 1471 mutex_lock(&p1->d_inode->i_sb->s_vfs_rename_mutex); 1443 1472 1444 - for (p = p1; p->d_parent != p; p = p->d_parent) { 1445 - if (p->d_parent == p2) { 1446 - mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT); 1447 - mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_CHILD); 1448 - return p; 1449 - } 1473 + p = d_ancestor(p2, p1); 1474 + if (p) { 1475 + mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT); 1476 + mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_CHILD); 1477 + return p; 1450 1478 } 1451 1479 1452 - for (p = p2; p->d_parent != p; p = p->d_parent) { 1453 - if (p->d_parent == p1) { 1454 - mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT); 1455 - mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD); 1456 - return p; 1457 - } 1480 + p = d_ancestor(p1, p2); 1481 + if (p) { 1482 + mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT); 1483 + mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD); 1484 + return p; 1458 1485 } 1459 1486 1460 1487 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT); ··· 1671 1702 /* 1672 1703 * Create - we need to know the parent. 1673 1704 */ 1674 - error = path_lookup_create(dfd, pathname, LOOKUP_PARENT, 1675 - &nd, flag, mode); 1705 + error = do_path_lookup(dfd, pathname, LOOKUP_PARENT, &nd); 1676 1706 if (error) 1677 1707 return ERR_PTR(error); 1678 1708 ··· 1682 1714 */ 1683 1715 error = -EISDIR; 1684 1716 if (nd.last_type != LAST_NORM || nd.last.name[nd.last.len]) 1685 - goto exit; 1717 + goto exit_parent; 1686 1718 1719 + error = -ENFILE; 1720 + filp = get_empty_filp(); 1721 + if (filp == NULL) 1722 + goto exit_parent; 1723 + nd.intent.open.file = filp; 1724 + nd.intent.open.flags = flag; 1725 + nd.intent.open.create_mode = mode; 1687 1726 dir = nd.path.dentry; 1688 1727 nd.flags &= ~LOOKUP_PARENT; 1728 + nd.flags |= LOOKUP_CREATE | LOOKUP_OPEN; 1729 + if (flag & O_EXCL) 1730 + nd.flags |= LOOKUP_EXCL; 1689 1731 mutex_lock(&dir->d_inode->i_mutex); 1690 1732 path.dentry = lookup_hash(&nd); 1691 1733 path.mnt = nd.path.mnt; ··· 1800 1822 exit: 1801 1823 if (!IS_ERR(nd.intent.open.file)) 1802 1824 release_open_intent(&nd); 1825 + exit_parent: 1803 1826 path_put(&nd.path); 1804 1827 return ERR_PTR(error); 1805 1828 ··· 1893 1914 if (nd->last_type != LAST_NORM) 1894 1915 goto fail; 1895 1916 nd->flags &= ~LOOKUP_PARENT; 1896 - nd->flags |= LOOKUP_CREATE; 1917 + nd->flags |= LOOKUP_CREATE | LOOKUP_EXCL; 1897 1918 nd->intent.open.flags = O_EXCL; 1898 1919 1899 1920 /* ··· 2157 2178 return error; 2158 2179 2159 2180 switch(nd.last_type) { 2160 - case LAST_DOTDOT: 2161 - error = -ENOTEMPTY; 2162 - goto exit1; 2163 - case LAST_DOT: 2164 - error = -EINVAL; 2165 - goto exit1; 2166 - case LAST_ROOT: 2167 - error = -EBUSY; 2168 - goto exit1; 2181 + case LAST_DOTDOT: 2182 + error = -ENOTEMPTY; 2183 + goto exit1; 2184 + case LAST_DOT: 2185 + error = -EINVAL; 2186 + goto exit1; 2187 + case LAST_ROOT: 2188 + error = -EBUSY; 2189 + goto exit1; 2169 2190 } 2191 + 2192 + nd.flags &= ~LOOKUP_PARENT; 2193 + 2170 2194 mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); 2171 2195 dentry = lookup_hash(&nd); 2172 2196 error = PTR_ERR(dentry); ··· 2247 2265 error = -EISDIR; 2248 2266 if (nd.last_type != LAST_NORM) 2249 2267 goto exit1; 2268 + 2269 + nd.flags &= ~LOOKUP_PARENT; 2270 + 2250 2271 mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT); 2251 2272 dentry = lookup_hash(&nd); 2252 2273 error = PTR_ERR(dentry); ··· 2639 2654 if (newnd.last_type != LAST_NORM) 2640 2655 goto exit2; 2641 2656 2657 + oldnd.flags &= ~LOOKUP_PARENT; 2658 + newnd.flags &= ~LOOKUP_PARENT; 2659 + newnd.flags |= LOOKUP_RENAME_TARGET; 2660 + 2642 2661 trap = lock_rename(new_dir, old_dir); 2643 2662 2644 2663 old_dentry = lookup_hash(&oldnd); ··· 2844 2855 EXPORT_SYMBOL(page_symlink); 2845 2856 EXPORT_SYMBOL(page_symlink_inode_operations); 2846 2857 EXPORT_SYMBOL(path_lookup); 2858 + EXPORT_SYMBOL(kern_path); 2847 2859 EXPORT_SYMBOL(vfs_path_lookup); 2848 2860 EXPORT_SYMBOL(inode_permission); 2849 2861 EXPORT_SYMBOL(vfs_permission);
+65 -68
fs/namespace.c
··· 1167 1167 1168 1168 #endif 1169 1169 1170 - static int mount_is_safe(struct nameidata *nd) 1170 + static int mount_is_safe(struct path *path) 1171 1171 { 1172 1172 if (capable(CAP_SYS_ADMIN)) 1173 1173 return 0; 1174 1174 return -EPERM; 1175 1175 #ifdef notyet 1176 - if (S_ISLNK(nd->path.dentry->d_inode->i_mode)) 1176 + if (S_ISLNK(path->dentry->d_inode->i_mode)) 1177 1177 return -EPERM; 1178 - if (nd->path.dentry->d_inode->i_mode & S_ISVTX) { 1179 - if (current->uid != nd->path.dentry->d_inode->i_uid) 1178 + if (path->dentry->d_inode->i_mode & S_ISVTX) { 1179 + if (current->uid != path->dentry->d_inode->i_uid) 1180 1180 return -EPERM; 1181 1181 } 1182 - if (vfs_permission(nd, MAY_WRITE)) 1182 + if (inode_permission(path->dentry->d_inode, MAY_WRITE)) 1183 1183 return -EPERM; 1184 1184 return 0; 1185 1185 #endif ··· 1425 1425 1426 1426 /* 1427 1427 * recursively change the type of the mountpoint. 1428 - * noinline this do_mount helper to save do_mount stack space. 1429 1428 */ 1430 - static noinline int do_change_type(struct nameidata *nd, int flag) 1429 + static int do_change_type(struct path *path, int flag) 1431 1430 { 1432 - struct vfsmount *m, *mnt = nd->path.mnt; 1431 + struct vfsmount *m, *mnt = path->mnt; 1433 1432 int recurse = flag & MS_REC; 1434 1433 int type = flag & ~MS_REC; 1435 1434 int err = 0; ··· 1436 1437 if (!capable(CAP_SYS_ADMIN)) 1437 1438 return -EPERM; 1438 1439 1439 - if (nd->path.dentry != nd->path.mnt->mnt_root) 1440 + if (path->dentry != path->mnt->mnt_root) 1440 1441 return -EINVAL; 1441 1442 1442 1443 down_write(&namespace_sem); ··· 1458 1459 1459 1460 /* 1460 1461 * do loopback mount. 1461 - * noinline this do_mount helper to save do_mount stack space. 1462 1462 */ 1463 - static noinline int do_loopback(struct nameidata *nd, char *old_name, 1463 + static int do_loopback(struct path *path, char *old_name, 1464 1464 int recurse) 1465 1465 { 1466 - struct nameidata old_nd; 1466 + struct path old_path; 1467 1467 struct vfsmount *mnt = NULL; 1468 - int err = mount_is_safe(nd); 1468 + int err = mount_is_safe(path); 1469 1469 if (err) 1470 1470 return err; 1471 1471 if (!old_name || !*old_name) 1472 1472 return -EINVAL; 1473 - err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd); 1473 + err = kern_path(old_name, LOOKUP_FOLLOW, &old_path); 1474 1474 if (err) 1475 1475 return err; 1476 1476 1477 1477 down_write(&namespace_sem); 1478 1478 err = -EINVAL; 1479 - if (IS_MNT_UNBINDABLE(old_nd.path.mnt)) 1479 + if (IS_MNT_UNBINDABLE(old_path.mnt)) 1480 1480 goto out; 1481 1481 1482 - if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) 1482 + if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) 1483 1483 goto out; 1484 1484 1485 1485 err = -ENOMEM; 1486 1486 if (recurse) 1487 - mnt = copy_tree(old_nd.path.mnt, old_nd.path.dentry, 0); 1487 + mnt = copy_tree(old_path.mnt, old_path.dentry, 0); 1488 1488 else 1489 - mnt = clone_mnt(old_nd.path.mnt, old_nd.path.dentry, 0); 1489 + mnt = clone_mnt(old_path.mnt, old_path.dentry, 0); 1490 1490 1491 1491 if (!mnt) 1492 1492 goto out; 1493 1493 1494 - err = graft_tree(mnt, &nd->path); 1494 + err = graft_tree(mnt, path); 1495 1495 if (err) { 1496 1496 LIST_HEAD(umount_list); 1497 1497 spin_lock(&vfsmount_lock); ··· 1501 1503 1502 1504 out: 1503 1505 up_write(&namespace_sem); 1504 - path_put(&old_nd.path); 1506 + path_put(&old_path); 1505 1507 return err; 1506 1508 } 1507 1509 ··· 1526 1528 * change filesystem flags. dir should be a physical root of filesystem. 1527 1529 * If you've mounted a non-root directory somewhere and want to do remount 1528 1530 * on it - tough luck. 1529 - * noinline this do_mount helper to save do_mount stack space. 1530 1531 */ 1531 - static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags, 1532 + static int do_remount(struct path *path, int flags, int mnt_flags, 1532 1533 void *data) 1533 1534 { 1534 1535 int err; 1535 - struct super_block *sb = nd->path.mnt->mnt_sb; 1536 + struct super_block *sb = path->mnt->mnt_sb; 1536 1537 1537 1538 if (!capable(CAP_SYS_ADMIN)) 1538 1539 return -EPERM; 1539 1540 1540 - if (!check_mnt(nd->path.mnt)) 1541 + if (!check_mnt(path->mnt)) 1541 1542 return -EINVAL; 1542 1543 1543 - if (nd->path.dentry != nd->path.mnt->mnt_root) 1544 + if (path->dentry != path->mnt->mnt_root) 1544 1545 return -EINVAL; 1545 1546 1546 1547 down_write(&sb->s_umount); 1547 1548 if (flags & MS_BIND) 1548 - err = change_mount_flags(nd->path.mnt, flags); 1549 + err = change_mount_flags(path->mnt, flags); 1549 1550 else 1550 1551 err = do_remount_sb(sb, flags, data, 0); 1551 1552 if (!err) 1552 - nd->path.mnt->mnt_flags = mnt_flags; 1553 + path->mnt->mnt_flags = mnt_flags; 1553 1554 up_write(&sb->s_umount); 1554 - if (!err) 1555 - security_sb_post_remount(nd->path.mnt, flags, data); 1555 + if (!err) { 1556 + security_sb_post_remount(path->mnt, flags, data); 1557 + 1558 + spin_lock(&vfsmount_lock); 1559 + touch_mnt_namespace(path->mnt->mnt_ns); 1560 + spin_unlock(&vfsmount_lock); 1561 + } 1556 1562 return err; 1557 1563 } 1558 1564 ··· 1570 1568 return 0; 1571 1569 } 1572 1570 1573 - /* 1574 - * noinline this do_mount helper to save do_mount stack space. 1575 - */ 1576 - static noinline int do_move_mount(struct nameidata *nd, char *old_name) 1571 + static int do_move_mount(struct path *path, char *old_name) 1577 1572 { 1578 - struct nameidata old_nd; 1579 - struct path parent_path; 1573 + struct path old_path, parent_path; 1580 1574 struct vfsmount *p; 1581 1575 int err = 0; 1582 1576 if (!capable(CAP_SYS_ADMIN)) 1583 1577 return -EPERM; 1584 1578 if (!old_name || !*old_name) 1585 1579 return -EINVAL; 1586 - err = path_lookup(old_name, LOOKUP_FOLLOW, &old_nd); 1580 + err = kern_path(old_name, LOOKUP_FOLLOW, &old_path); 1587 1581 if (err) 1588 1582 return err; 1589 1583 1590 1584 down_write(&namespace_sem); 1591 - while (d_mountpoint(nd->path.dentry) && 1592 - follow_down(&nd->path.mnt, &nd->path.dentry)) 1585 + while (d_mountpoint(path->dentry) && 1586 + follow_down(&path->mnt, &path->dentry)) 1593 1587 ; 1594 1588 err = -EINVAL; 1595 - if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) 1589 + if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) 1596 1590 goto out; 1597 1591 1598 1592 err = -ENOENT; 1599 - mutex_lock(&nd->path.dentry->d_inode->i_mutex); 1600 - if (IS_DEADDIR(nd->path.dentry->d_inode)) 1593 + mutex_lock(&path->dentry->d_inode->i_mutex); 1594 + if (IS_DEADDIR(path->dentry->d_inode)) 1601 1595 goto out1; 1602 1596 1603 - if (!IS_ROOT(nd->path.dentry) && d_unhashed(nd->path.dentry)) 1597 + if (!IS_ROOT(path->dentry) && d_unhashed(path->dentry)) 1604 1598 goto out1; 1605 1599 1606 1600 err = -EINVAL; 1607 - if (old_nd.path.dentry != old_nd.path.mnt->mnt_root) 1601 + if (old_path.dentry != old_path.mnt->mnt_root) 1608 1602 goto out1; 1609 1603 1610 - if (old_nd.path.mnt == old_nd.path.mnt->mnt_parent) 1604 + if (old_path.mnt == old_path.mnt->mnt_parent) 1611 1605 goto out1; 1612 1606 1613 - if (S_ISDIR(nd->path.dentry->d_inode->i_mode) != 1614 - S_ISDIR(old_nd.path.dentry->d_inode->i_mode)) 1607 + if (S_ISDIR(path->dentry->d_inode->i_mode) != 1608 + S_ISDIR(old_path.dentry->d_inode->i_mode)) 1615 1609 goto out1; 1616 1610 /* 1617 1611 * Don't move a mount residing in a shared parent. 1618 1612 */ 1619 - if (old_nd.path.mnt->mnt_parent && 1620 - IS_MNT_SHARED(old_nd.path.mnt->mnt_parent)) 1613 + if (old_path.mnt->mnt_parent && 1614 + IS_MNT_SHARED(old_path.mnt->mnt_parent)) 1621 1615 goto out1; 1622 1616 /* 1623 1617 * Don't move a mount tree containing unbindable mounts to a destination 1624 1618 * mount which is shared. 1625 1619 */ 1626 - if (IS_MNT_SHARED(nd->path.mnt) && 1627 - tree_contains_unbindable(old_nd.path.mnt)) 1620 + if (IS_MNT_SHARED(path->mnt) && 1621 + tree_contains_unbindable(old_path.mnt)) 1628 1622 goto out1; 1629 1623 err = -ELOOP; 1630 - for (p = nd->path.mnt; p->mnt_parent != p; p = p->mnt_parent) 1631 - if (p == old_nd.path.mnt) 1624 + for (p = path->mnt; p->mnt_parent != p; p = p->mnt_parent) 1625 + if (p == old_path.mnt) 1632 1626 goto out1; 1633 1627 1634 - err = attach_recursive_mnt(old_nd.path.mnt, &nd->path, &parent_path); 1628 + err = attach_recursive_mnt(old_path.mnt, path, &parent_path); 1635 1629 if (err) 1636 1630 goto out1; 1637 1631 1638 1632 /* if the mount is moved, it should no longer be expire 1639 1633 * automatically */ 1640 - list_del_init(&old_nd.path.mnt->mnt_expire); 1634 + list_del_init(&old_path.mnt->mnt_expire); 1641 1635 out1: 1642 - mutex_unlock(&nd->path.dentry->d_inode->i_mutex); 1636 + mutex_unlock(&path->dentry->d_inode->i_mutex); 1643 1637 out: 1644 1638 up_write(&namespace_sem); 1645 1639 if (!err) 1646 1640 path_put(&parent_path); 1647 - path_put(&old_nd.path); 1641 + path_put(&old_path); 1648 1642 return err; 1649 1643 } 1650 1644 1651 1645 /* 1652 1646 * create a new mount for userspace and request it to be added into the 1653 1647 * namespace's tree 1654 - * noinline this do_mount helper to save do_mount stack space. 1655 1648 */ 1656 - static noinline int do_new_mount(struct nameidata *nd, char *type, int flags, 1649 + static int do_new_mount(struct path *path, char *type, int flags, 1657 1650 int mnt_flags, char *name, void *data) 1658 1651 { 1659 1652 struct vfsmount *mnt; ··· 1664 1667 if (IS_ERR(mnt)) 1665 1668 return PTR_ERR(mnt); 1666 1669 1667 - return do_add_mount(mnt, &nd->path, mnt_flags, NULL); 1670 + return do_add_mount(mnt, path, mnt_flags, NULL); 1668 1671 } 1669 1672 1670 1673 /* ··· 1899 1902 long do_mount(char *dev_name, char *dir_name, char *type_page, 1900 1903 unsigned long flags, void *data_page) 1901 1904 { 1902 - struct nameidata nd; 1905 + struct path path; 1903 1906 int retval = 0; 1904 1907 int mnt_flags = 0; 1905 1908 ··· 1937 1940 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT); 1938 1941 1939 1942 /* ... and get the mountpoint */ 1940 - retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd); 1943 + retval = kern_path(dir_name, LOOKUP_FOLLOW, &path); 1941 1944 if (retval) 1942 1945 return retval; 1943 1946 1944 - retval = security_sb_mount(dev_name, &nd.path, 1947 + retval = security_sb_mount(dev_name, &path, 1945 1948 type_page, flags, data_page); 1946 1949 if (retval) 1947 1950 goto dput_out; 1948 1951 1949 1952 if (flags & MS_REMOUNT) 1950 - retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags, 1953 + retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags, 1951 1954 data_page); 1952 1955 else if (flags & MS_BIND) 1953 - retval = do_loopback(&nd, dev_name, flags & MS_REC); 1956 + retval = do_loopback(&path, dev_name, flags & MS_REC); 1954 1957 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)) 1955 - retval = do_change_type(&nd, flags); 1958 + retval = do_change_type(&path, flags); 1956 1959 else if (flags & MS_MOVE) 1957 - retval = do_move_mount(&nd, dev_name); 1960 + retval = do_move_mount(&path, dev_name); 1958 1961 else 1959 - retval = do_new_mount(&nd, type_page, flags, mnt_flags, 1962 + retval = do_new_mount(&path, type_page, flags, mnt_flags, 1960 1963 dev_name, data_page); 1961 1964 dput_out: 1962 - path_put(&nd.path); 1965 + path_put(&path); 1963 1966 return retval; 1964 1967 } 1965 1968
+5 -4
fs/nfs/dir.c
··· 707 707 { 708 708 if (NFS_PROTO(dir)->version == 2) 709 709 return 0; 710 - if (nd == NULL || nfs_lookup_check_intent(nd, LOOKUP_CREATE) == 0) 711 - return 0; 712 - return (nd->intent.open.flags & O_EXCL) != 0; 710 + return nd && nfs_lookup_check_intent(nd, LOOKUP_EXCL); 713 711 } 714 712 715 713 /* ··· 1007 1009 1008 1010 /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash 1009 1011 * the dentry. */ 1010 - if (nd->intent.open.flags & O_EXCL) { 1012 + if (nd->flags & LOOKUP_EXCL) { 1011 1013 d_instantiate(dentry, NULL); 1012 1014 goto out; 1013 1015 } ··· 1957 1959 } else 1958 1960 res = PTR_ERR(cred); 1959 1961 out: 1962 + if (!res && (mask & MAY_EXEC) && !execute_ok(inode)) 1963 + res = -EACCES; 1964 + 1960 1965 dfprintk(VFS, "NFS: permission(%s/%ld), mask=0x%x, res=%d\n", 1961 1966 inode->i_sb->s_id, inode->i_ino, mask, res); 1962 1967 return res;
+6 -8
fs/nfs/getroot.c
··· 107 107 * if the dentry tree reaches them; however if the dentry already 108 108 * exists, we'll pick it up at this point and use it as the root 109 109 */ 110 - mntroot = d_alloc_anon(inode); 111 - if (!mntroot) { 112 - iput(inode); 110 + mntroot = d_obtain_alias(inode); 111 + if (IS_ERR(mntroot)) { 113 112 dprintk("nfs_get_root: get root dentry failed\n"); 114 - return ERR_PTR(-ENOMEM); 113 + return mntroot; 115 114 } 116 115 117 116 security_d_instantiate(mntroot, inode); ··· 276 277 * if the dentry tree reaches them; however if the dentry already 277 278 * exists, we'll pick it up at this point and use it as the root 278 279 */ 279 - mntroot = d_alloc_anon(inode); 280 - if (!mntroot) { 281 - iput(inode); 280 + mntroot = d_obtain_alias(inode); 281 + if (IS_ERR(mntroot)) { 282 282 dprintk("nfs_get_root: get root dentry failed\n"); 283 - return ERR_PTR(-ENOMEM); 283 + return mntroot; 284 284 } 285 285 286 286 security_d_instantiate(mntroot, inode);
+58 -67
fs/nfsd/export.c
··· 163 163 if (!ek) 164 164 err = -ENOMEM; 165 165 } else { 166 - struct nameidata nd; 167 - err = path_lookup(buf, 0, &nd); 166 + err = kern_path(buf, 0, &key.ek_path); 168 167 if (err) 169 168 goto out; 170 169 171 170 dprintk("Found the path %s\n", buf); 172 - key.ek_path = nd.path; 173 171 174 172 ek = svc_expkey_update(&key, ek); 175 173 if (!ek) 176 174 err = -ENOMEM; 177 - path_put(&nd.path); 175 + path_put(&key.ek_path); 178 176 } 179 177 cache_flush(); 180 178 out: ··· 499 501 int len; 500 502 int err; 501 503 struct auth_domain *dom = NULL; 502 - struct nameidata nd; 503 - struct svc_export exp, *expp; 504 + struct svc_export exp = {}, *expp; 504 505 int an_int; 505 - 506 - nd.path.dentry = NULL; 507 - exp.ex_pathname = NULL; 508 - 509 - /* fs locations */ 510 - exp.ex_fslocs.locations = NULL; 511 - exp.ex_fslocs.locations_count = 0; 512 - exp.ex_fslocs.migrated = 0; 513 - 514 - exp.ex_uuid = NULL; 515 - 516 - /* secinfo */ 517 - exp.ex_nflavors = 0; 518 506 519 507 if (mesg[mlen-1] != '\n') 520 508 return -EINVAL; 521 509 mesg[mlen-1] = 0; 522 510 523 511 buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 524 - err = -ENOMEM; 525 - if (!buf) goto out; 512 + if (!buf) 513 + return -ENOMEM; 526 514 527 515 /* client */ 528 - len = qword_get(&mesg, buf, PAGE_SIZE); 529 516 err = -EINVAL; 530 - if (len <= 0) goto out; 517 + len = qword_get(&mesg, buf, PAGE_SIZE); 518 + if (len <= 0) 519 + goto out; 531 520 532 521 err = -ENOENT; 533 522 dom = auth_domain_find(buf); ··· 523 538 524 539 /* path */ 525 540 err = -EINVAL; 526 - if ((len=qword_get(&mesg, buf, PAGE_SIZE)) <= 0) 527 - goto out; 528 - err = path_lookup(buf, 0, &nd); 529 - if (err) goto out_no_path; 541 + if ((len = qword_get(&mesg, buf, PAGE_SIZE)) <= 0) 542 + goto out1; 530 543 531 - exp.h.flags = 0; 544 + err = kern_path(buf, 0, &exp.ex_path); 545 + if (err) 546 + goto out1; 547 + 532 548 exp.ex_client = dom; 533 - exp.ex_path.mnt = nd.path.mnt; 534 - exp.ex_path.dentry = nd.path.dentry; 535 - exp.ex_pathname = kstrdup(buf, GFP_KERNEL); 549 + 536 550 err = -ENOMEM; 551 + exp.ex_pathname = kstrdup(buf, GFP_KERNEL); 537 552 if (!exp.ex_pathname) 538 - goto out; 553 + goto out2; 539 554 540 555 /* expiry */ 541 556 err = -EINVAL; 542 557 exp.h.expiry_time = get_expiry(&mesg); 543 558 if (exp.h.expiry_time == 0) 544 - goto out; 559 + goto out3; 545 560 546 561 /* flags */ 547 562 err = get_int(&mesg, &an_int); ··· 549 564 err = 0; 550 565 set_bit(CACHE_NEGATIVE, &exp.h.flags); 551 566 } else { 552 - if (err || an_int < 0) goto out; 567 + if (err || an_int < 0) 568 + goto out3; 553 569 exp.ex_flags= an_int; 554 570 555 571 /* anon uid */ 556 572 err = get_int(&mesg, &an_int); 557 - if (err) goto out; 573 + if (err) 574 + goto out3; 558 575 exp.ex_anon_uid= an_int; 559 576 560 577 /* anon gid */ 561 578 err = get_int(&mesg, &an_int); 562 - if (err) goto out; 579 + if (err) 580 + goto out3; 563 581 exp.ex_anon_gid= an_int; 564 582 565 583 /* fsid */ 566 584 err = get_int(&mesg, &an_int); 567 - if (err) goto out; 585 + if (err) 586 + goto out3; 568 587 exp.ex_fsid = an_int; 569 588 570 589 while ((len = qword_get(&mesg, buf, PAGE_SIZE)) > 0) { ··· 594 605 */ 595 606 break; 596 607 if (err) 597 - goto out; 608 + goto out4; 598 609 } 599 610 600 - err = check_export(nd.path.dentry->d_inode, exp.ex_flags, 611 + err = check_export(exp.ex_path.dentry->d_inode, exp.ex_flags, 601 612 exp.ex_uuid); 602 - if (err) goto out; 613 + if (err) 614 + goto out4; 603 615 } 604 616 605 617 expp = svc_export_lookup(&exp); ··· 613 623 err = -ENOMEM; 614 624 else 615 625 exp_put(expp); 616 - out: 626 + out4: 617 627 nfsd4_fslocs_free(&exp.ex_fslocs); 618 628 kfree(exp.ex_uuid); 629 + out3: 619 630 kfree(exp.ex_pathname); 620 - if (nd.path.dentry) 621 - path_put(&nd.path); 622 - out_no_path: 623 - if (dom) 624 - auth_domain_put(dom); 631 + out2: 632 + path_put(&exp.ex_path); 633 + out1: 634 + auth_domain_put(dom); 635 + out: 625 636 kfree(buf); 626 637 return err; 627 638 } ··· 990 999 struct svc_export *exp = NULL; 991 1000 struct svc_export new; 992 1001 struct svc_expkey *fsid_key = NULL; 993 - struct nameidata nd; 1002 + struct path path; 994 1003 int err; 995 1004 996 1005 /* Consistency check */ ··· 1013 1022 1014 1023 1015 1024 /* Look up the dentry */ 1016 - err = path_lookup(nxp->ex_path, 0, &nd); 1025 + err = kern_path(nxp->ex_path, 0, &path); 1017 1026 if (err) 1018 1027 goto out_put_clp; 1019 1028 err = -EINVAL; 1020 1029 1021 - exp = exp_get_by_name(clp, nd.path.mnt, nd.path.dentry, NULL); 1030 + exp = exp_get_by_name(clp, path.mnt, path.dentry, NULL); 1022 1031 1023 1032 memset(&new, 0, sizeof(new)); 1024 1033 ··· 1026 1035 if ((nxp->ex_flags & NFSEXP_FSID) && 1027 1036 (!IS_ERR(fsid_key = exp_get_fsid_key(clp, nxp->ex_dev))) && 1028 1037 fsid_key->ek_path.mnt && 1029 - (fsid_key->ek_path.mnt != nd.path.mnt || 1030 - fsid_key->ek_path.dentry != nd.path.dentry)) 1038 + (fsid_key->ek_path.mnt != path.mnt || 1039 + fsid_key->ek_path.dentry != path.dentry)) 1031 1040 goto finish; 1032 1041 1033 1042 if (!IS_ERR(exp)) { ··· 1043 1052 goto finish; 1044 1053 } 1045 1054 1046 - err = check_export(nd.path.dentry->d_inode, nxp->ex_flags, NULL); 1055 + err = check_export(path.dentry->d_inode, nxp->ex_flags, NULL); 1047 1056 if (err) goto finish; 1048 1057 1049 1058 err = -ENOMEM; ··· 1056 1065 if (!new.ex_pathname) 1057 1066 goto finish; 1058 1067 new.ex_client = clp; 1059 - new.ex_path = nd.path; 1068 + new.ex_path = path; 1060 1069 new.ex_flags = nxp->ex_flags; 1061 1070 new.ex_anon_uid = nxp->ex_anon_uid; 1062 1071 new.ex_anon_gid = nxp->ex_anon_gid; ··· 1082 1091 exp_put(exp); 1083 1092 if (fsid_key && !IS_ERR(fsid_key)) 1084 1093 cache_put(&fsid_key->h, &svc_expkey_cache); 1085 - path_put(&nd.path); 1094 + path_put(&path); 1086 1095 out_put_clp: 1087 1096 auth_domain_put(clp); 1088 1097 out_unlock: ··· 1113 1122 { 1114 1123 struct auth_domain *dom; 1115 1124 svc_export *exp; 1116 - struct nameidata nd; 1125 + struct path path; 1117 1126 int err; 1118 1127 1119 1128 /* Consistency check */ ··· 1130 1139 goto out_unlock; 1131 1140 } 1132 1141 1133 - err = path_lookup(nxp->ex_path, 0, &nd); 1142 + err = kern_path(nxp->ex_path, 0, &path); 1134 1143 if (err) 1135 1144 goto out_domain; 1136 1145 1137 1146 err = -EINVAL; 1138 - exp = exp_get_by_name(dom, nd.path.mnt, nd.path.dentry, NULL); 1139 - path_put(&nd.path); 1147 + exp = exp_get_by_name(dom, path.mnt, path.dentry, NULL); 1148 + path_put(&path); 1140 1149 if (IS_ERR(exp)) 1141 1150 goto out_domain; 1142 1151 ··· 1158 1167 * since its harder to fool a kernel module than a user space program. 1159 1168 */ 1160 1169 int 1161 - exp_rootfh(svc_client *clp, char *path, struct knfsd_fh *f, int maxsize) 1170 + exp_rootfh(svc_client *clp, char *name, struct knfsd_fh *f, int maxsize) 1162 1171 { 1163 1172 struct svc_export *exp; 1164 - struct nameidata nd; 1173 + struct path path; 1165 1174 struct inode *inode; 1166 1175 struct svc_fh fh; 1167 1176 int err; 1168 1177 1169 1178 err = -EPERM; 1170 1179 /* NB: we probably ought to check that it's NUL-terminated */ 1171 - if (path_lookup(path, 0, &nd)) { 1172 - printk("nfsd: exp_rootfh path not found %s", path); 1180 + if (kern_path(name, 0, &path)) { 1181 + printk("nfsd: exp_rootfh path not found %s", name); 1173 1182 return err; 1174 1183 } 1175 - inode = nd.path.dentry->d_inode; 1184 + inode = path.dentry->d_inode; 1176 1185 1177 1186 dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n", 1178 - path, nd.path.dentry, clp->name, 1187 + name, path.dentry, clp->name, 1179 1188 inode->i_sb->s_id, inode->i_ino); 1180 - exp = exp_parent(clp, nd.path.mnt, nd.path.dentry, NULL); 1189 + exp = exp_parent(clp, path.mnt, path.dentry, NULL); 1181 1190 if (IS_ERR(exp)) { 1182 1191 err = PTR_ERR(exp); 1183 1192 goto out; ··· 1187 1196 * fh must be initialized before calling fh_compose 1188 1197 */ 1189 1198 fh_init(&fh, maxsize); 1190 - if (fh_compose(&fh, exp, nd.path.dentry, NULL)) 1199 + if (fh_compose(&fh, exp, path.dentry, NULL)) 1191 1200 err = -EINVAL; 1192 1201 else 1193 1202 err = 0; ··· 1195 1204 fh_put(&fh); 1196 1205 exp_put(exp); 1197 1206 out: 1198 - path_put(&nd.path); 1207 + path_put(&path); 1199 1208 return err; 1200 1209 } 1201 1210
+25 -25
fs/nfsd/nfs4recover.c
··· 51 51 #define NFSDDBG_FACILITY NFSDDBG_PROC 52 52 53 53 /* Globals */ 54 - static struct nameidata rec_dir; 54 + static struct path rec_dir; 55 55 static int rec_dir_init = 0; 56 56 57 57 static void ··· 121 121 static void 122 122 nfsd4_sync_rec_dir(void) 123 123 { 124 - mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex); 125 - nfsd_sync_dir(rec_dir.path.dentry); 126 - mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex); 124 + mutex_lock(&rec_dir.dentry->d_inode->i_mutex); 125 + nfsd_sync_dir(rec_dir.dentry); 126 + mutex_unlock(&rec_dir.dentry->d_inode->i_mutex); 127 127 } 128 128 129 129 int ··· 143 143 nfs4_save_user(&uid, &gid); 144 144 145 145 /* lock the parent */ 146 - mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex); 146 + mutex_lock(&rec_dir.dentry->d_inode->i_mutex); 147 147 148 - dentry = lookup_one_len(dname, rec_dir.path.dentry, HEXDIR_LEN-1); 148 + dentry = lookup_one_len(dname, rec_dir.dentry, HEXDIR_LEN-1); 149 149 if (IS_ERR(dentry)) { 150 150 status = PTR_ERR(dentry); 151 151 goto out_unlock; ··· 155 155 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n"); 156 156 goto out_put; 157 157 } 158 - status = mnt_want_write(rec_dir.path.mnt); 158 + status = mnt_want_write(rec_dir.mnt); 159 159 if (status) 160 160 goto out_put; 161 - status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU); 162 - mnt_drop_write(rec_dir.path.mnt); 161 + status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU); 162 + mnt_drop_write(rec_dir.mnt); 163 163 out_put: 164 164 dput(dentry); 165 165 out_unlock: 166 - mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex); 166 + mutex_unlock(&rec_dir.dentry->d_inode->i_mutex); 167 167 if (status == 0) { 168 168 clp->cl_firststate = 1; 169 169 nfsd4_sync_rec_dir(); ··· 226 226 227 227 nfs4_save_user(&uid, &gid); 228 228 229 - filp = dentry_open(dget(dir), mntget(rec_dir.path.mnt), O_RDONLY); 229 + filp = dentry_open(dget(dir), mntget(rec_dir.mnt), O_RDONLY); 230 230 status = PTR_ERR(filp); 231 231 if (IS_ERR(filp)) 232 232 goto out; ··· 291 291 292 292 dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name); 293 293 294 - mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex); 295 - dentry = lookup_one_len(name, rec_dir.path.dentry, namlen); 296 - mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex); 294 + mutex_lock(&rec_dir.dentry->d_inode->i_mutex); 295 + dentry = lookup_one_len(name, rec_dir.dentry, namlen); 296 + mutex_unlock(&rec_dir.dentry->d_inode->i_mutex); 297 297 if (IS_ERR(dentry)) { 298 298 status = PTR_ERR(dentry); 299 299 return status; ··· 302 302 if (!dentry->d_inode) 303 303 goto out; 304 304 305 - status = nfsd4_clear_clid_dir(rec_dir.path.dentry, dentry); 305 + status = nfsd4_clear_clid_dir(rec_dir.dentry, dentry); 306 306 out: 307 307 dput(dentry); 308 308 return status; ··· 318 318 if (!rec_dir_init || !clp->cl_firststate) 319 319 return; 320 320 321 - status = mnt_want_write(rec_dir.path.mnt); 321 + status = mnt_want_write(rec_dir.mnt); 322 322 if (status) 323 323 goto out; 324 324 clp->cl_firststate = 0; ··· 327 327 nfs4_reset_user(uid, gid); 328 328 if (status == 0) 329 329 nfsd4_sync_rec_dir(); 330 - mnt_drop_write(rec_dir.path.mnt); 330 + mnt_drop_write(rec_dir.mnt); 331 331 out: 332 332 if (status) 333 333 printk("NFSD: Failed to remove expired client state directory" ··· 357 357 358 358 if (!rec_dir_init) 359 359 return; 360 - status = mnt_want_write(rec_dir.path.mnt); 360 + status = mnt_want_write(rec_dir.mnt); 361 361 if (status) 362 362 goto out; 363 - status = nfsd4_list_rec_dir(rec_dir.path.dentry, purge_old); 363 + status = nfsd4_list_rec_dir(rec_dir.dentry, purge_old); 364 364 if (status == 0) 365 365 nfsd4_sync_rec_dir(); 366 - mnt_drop_write(rec_dir.path.mnt); 366 + mnt_drop_write(rec_dir.mnt); 367 367 out: 368 368 if (status) 369 369 printk("nfsd4: failed to purge old clients from recovery" 370 - " directory %s\n", rec_dir.path.dentry->d_name.name); 370 + " directory %s\n", rec_dir.dentry->d_name.name); 371 371 } 372 372 373 373 static int ··· 387 387 nfsd4_recdir_load(void) { 388 388 int status; 389 389 390 - status = nfsd4_list_rec_dir(rec_dir.path.dentry, load_recdir); 390 + status = nfsd4_list_rec_dir(rec_dir.dentry, load_recdir); 391 391 if (status) 392 392 printk("nfsd4: failed loading clients from recovery" 393 - " directory %s\n", rec_dir.path.dentry->d_name.name); 393 + " directory %s\n", rec_dir.dentry->d_name.name); 394 394 return status; 395 395 } 396 396 ··· 412 412 413 413 nfs4_save_user(&uid, &gid); 414 414 415 - status = path_lookup(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, 415 + status = kern_path(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, 416 416 &rec_dir); 417 417 if (status) 418 418 printk("NFSD: unable to find recovery directory %s\n", ··· 429 429 if (!rec_dir_init) 430 430 return; 431 431 rec_dir_init = 0; 432 - path_put(&rec_dir.path); 432 + path_put(&rec_dir); 433 433 }
+4 -4
fs/nfsd/nfs4state.c
··· 3284 3284 nfs4_reset_recoverydir(char *recdir) 3285 3285 { 3286 3286 int status; 3287 - struct nameidata nd; 3287 + struct path path; 3288 3288 3289 - status = path_lookup(recdir, LOOKUP_FOLLOW, &nd); 3289 + status = kern_path(recdir, LOOKUP_FOLLOW, &path); 3290 3290 if (status) 3291 3291 return status; 3292 3292 status = -ENOTDIR; 3293 - if (S_ISDIR(nd.path.dentry->d_inode->i_mode)) { 3293 + if (S_ISDIR(path.dentry->d_inode->i_mode)) { 3294 3294 nfs4_set_recdir(recdir); 3295 3295 status = 0; 3296 3296 } 3297 - path_put(&nd.path); 3297 + path_put(&path); 3298 3298 return status; 3299 3299 } 3300 3300
+4 -4
fs/nfsd/nfsctl.c
··· 341 341 342 342 static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size) 343 343 { 344 - struct nameidata nd; 344 + struct path path; 345 345 char *fo_path; 346 346 int error; 347 347 ··· 356 356 if (qword_get(&buf, fo_path, size) < 0) 357 357 return -EINVAL; 358 358 359 - error = path_lookup(fo_path, 0, &nd); 359 + error = kern_path(fo_path, 0, &path); 360 360 if (error) 361 361 return error; 362 362 363 - error = nlmsvc_unlock_all_by_sb(nd.path.mnt->mnt_sb); 363 + error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb); 364 364 365 - path_put(&nd.path); 365 + path_put(&path); 366 366 return error; 367 367 } 368 368
+110 -16
fs/nfsd/vfs.c
··· 1818 1818 } 1819 1819 1820 1820 /* 1821 + * We do this buffering because we must not call back into the file 1822 + * system's ->lookup() method from the filldir callback. That may well 1823 + * deadlock a number of file systems. 1824 + * 1825 + * This is based heavily on the implementation of same in XFS. 1826 + */ 1827 + struct buffered_dirent { 1828 + u64 ino; 1829 + loff_t offset; 1830 + int namlen; 1831 + unsigned int d_type; 1832 + char name[]; 1833 + }; 1834 + 1835 + struct readdir_data { 1836 + char *dirent; 1837 + size_t used; 1838 + int full; 1839 + }; 1840 + 1841 + static int nfsd_buffered_filldir(void *__buf, const char *name, int namlen, 1842 + loff_t offset, u64 ino, unsigned int d_type) 1843 + { 1844 + struct readdir_data *buf = __buf; 1845 + struct buffered_dirent *de = (void *)(buf->dirent + buf->used); 1846 + unsigned int reclen; 1847 + 1848 + reclen = ALIGN(sizeof(struct buffered_dirent) + namlen, sizeof(u64)); 1849 + if (buf->used + reclen > PAGE_SIZE) { 1850 + buf->full = 1; 1851 + return -EINVAL; 1852 + } 1853 + 1854 + de->namlen = namlen; 1855 + de->offset = offset; 1856 + de->ino = ino; 1857 + de->d_type = d_type; 1858 + memcpy(de->name, name, namlen); 1859 + buf->used += reclen; 1860 + 1861 + return 0; 1862 + } 1863 + 1864 + static int nfsd_buffered_readdir(struct file *file, filldir_t func, 1865 + struct readdir_cd *cdp, loff_t *offsetp) 1866 + { 1867 + struct readdir_data buf; 1868 + struct buffered_dirent *de; 1869 + int host_err; 1870 + int size; 1871 + loff_t offset; 1872 + 1873 + buf.dirent = (void *)__get_free_page(GFP_KERNEL); 1874 + if (!buf.dirent) 1875 + return -ENOMEM; 1876 + 1877 + offset = *offsetp; 1878 + cdp->err = nfserr_eof; /* will be cleared on successful read */ 1879 + 1880 + while (1) { 1881 + unsigned int reclen; 1882 + 1883 + buf.used = 0; 1884 + buf.full = 0; 1885 + 1886 + host_err = vfs_readdir(file, nfsd_buffered_filldir, &buf); 1887 + if (buf.full) 1888 + host_err = 0; 1889 + 1890 + if (host_err < 0) 1891 + break; 1892 + 1893 + size = buf.used; 1894 + 1895 + if (!size) 1896 + break; 1897 + 1898 + de = (struct buffered_dirent *)buf.dirent; 1899 + while (size > 0) { 1900 + offset = de->offset; 1901 + 1902 + if (func(cdp, de->name, de->namlen, de->offset, 1903 + de->ino, de->d_type)) 1904 + goto done; 1905 + 1906 + if (cdp->err != nfs_ok) 1907 + goto done; 1908 + 1909 + reclen = ALIGN(sizeof(*de) + de->namlen, 1910 + sizeof(u64)); 1911 + size -= reclen; 1912 + de = (struct buffered_dirent *)((char *)de + reclen); 1913 + } 1914 + offset = vfs_llseek(file, 0, SEEK_CUR); 1915 + if (!buf.full) 1916 + break; 1917 + } 1918 + 1919 + done: 1920 + free_page((unsigned long)(buf.dirent)); 1921 + 1922 + if (host_err) 1923 + return nfserrno(host_err); 1924 + 1925 + *offsetp = offset; 1926 + return cdp->err; 1927 + } 1928 + 1929 + /* 1821 1930 * Read entries from a directory. 1822 1931 * The NFSv3/4 verifier we ignore for now. 1823 1932 */ ··· 1935 1826 struct readdir_cd *cdp, filldir_t func) 1936 1827 { 1937 1828 __be32 err; 1938 - int host_err; 1939 1829 struct file *file; 1940 1830 loff_t offset = *offsetp; 1941 1831 ··· 1948 1840 goto out_close; 1949 1841 } 1950 1842 1951 - /* 1952 - * Read the directory entries. This silly loop is necessary because 1953 - * readdir() is not guaranteed to fill up the entire buffer, but 1954 - * may choose to do less. 1955 - */ 1956 - 1957 - do { 1958 - cdp->err = nfserr_eof; /* will be cleared on successful read */ 1959 - host_err = vfs_readdir(file, func, cdp); 1960 - } while (host_err >=0 && cdp->err == nfs_ok); 1961 - if (host_err) 1962 - err = nfserrno(host_err); 1963 - else 1964 - err = cdp->err; 1965 - *offsetp = vfs_llseek(file, 0, 1); 1843 + err = nfsd_buffered_readdir(file, func, cdp, offsetp); 1966 1844 1967 1845 if (err == nfserr_eof || err == nfserr_toosmall) 1968 1846 err = nfs_ok; /* can still be found in ->err */
+2 -20
fs/ntfs/namei.c
··· 304 304 ntfs_attr_search_ctx *ctx; 305 305 ATTR_RECORD *attr; 306 306 FILE_NAME_ATTR *fn; 307 - struct inode *parent_vi; 308 - struct dentry *parent_dent; 309 307 unsigned long parent_ino; 310 308 int err; 311 309 ··· 343 345 /* Release the search context and the mft record of the child. */ 344 346 ntfs_attr_put_search_ctx(ctx); 345 347 unmap_mft_record(ni); 346 - /* Get the inode of the parent directory. */ 347 - parent_vi = ntfs_iget(vi->i_sb, parent_ino); 348 - if (IS_ERR(parent_vi) || unlikely(is_bad_inode(parent_vi))) { 349 - if (!IS_ERR(parent_vi)) 350 - iput(parent_vi); 351 - ntfs_error(vi->i_sb, "Failed to get parent directory inode " 352 - "0x%lx of child inode 0x%lx.", parent_ino, 353 - vi->i_ino); 354 - return ERR_PTR(-EACCES); 355 - } 356 - /* Finally get a dentry for the parent directory and return it. */ 357 - parent_dent = d_alloc_anon(parent_vi); 358 - if (unlikely(!parent_dent)) { 359 - iput(parent_vi); 360 - return ERR_PTR(-ENOMEM); 361 - } 362 - ntfs_debug("Done for inode 0x%lx.", vi->i_ino); 363 - return parent_dent; 348 + 349 + return d_obtain_alias(ntfs_iget(vi->i_sb, parent_ino)); 364 350 } 365 351 366 352 static struct inode *ntfs_nfs_get_inode(struct super_block *sb,
+6 -24
fs/ocfs2/export.c
··· 68 68 return ERR_PTR(-ESTALE); 69 69 } 70 70 71 - result = d_alloc_anon(inode); 72 - 73 - if (!result) { 74 - iput(inode); 75 - mlog_errno(-ENOMEM); 76 - return ERR_PTR(-ENOMEM); 77 - } 78 - result->d_op = &ocfs2_dentry_ops; 71 + result = d_obtain_alias(inode); 72 + if (!IS_ERR(result)) 73 + result->d_op = &ocfs2_dentry_ops; 79 74 80 75 mlog_exit_ptr(result); 81 76 return result; ··· 81 86 int status; 82 87 u64 blkno; 83 88 struct dentry *parent; 84 - struct inode *inode; 85 89 struct inode *dir = child->d_inode; 86 90 87 91 mlog_entry("(0x%p, '%.*s')\n", child, ··· 103 109 goto bail_unlock; 104 110 } 105 111 106 - inode = ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0); 107 - if (IS_ERR(inode)) { 108 - mlog(ML_ERROR, "Unable to create inode %llu\n", 109 - (unsigned long long)blkno); 110 - parent = ERR_PTR(-EACCES); 111 - goto bail_unlock; 112 - } 113 - 114 - parent = d_alloc_anon(inode); 115 - if (!parent) { 116 - iput(inode); 117 - parent = ERR_PTR(-ENOMEM); 118 - } 119 - 120 - parent->d_op = &ocfs2_dentry_ops; 112 + parent = d_obtain_alias(ocfs2_iget(OCFS2_SB(dir->i_sb), blkno, 0, 0)); 113 + if (!IS_ERR(parent)) 114 + parent->d_op = &ocfs2_dentry_ops; 121 115 122 116 bail_unlock: 123 117 ocfs2_inode_unlock(dir, 0);
+1
fs/omfs/dir.c
··· 501 501 struct file_operations omfs_dir_operations = { 502 502 .read = generic_read_dir, 503 503 .readdir = omfs_readdir, 504 + .llseek = generic_file_llseek, 504 505 };
+1
fs/openpromfs/inode.c
··· 167 167 static const struct file_operations openprom_operations = { 168 168 .read = generic_read_dir, 169 169 .readdir = openpromfs_readdir, 170 + .llseek = generic_file_llseek, 170 171 }; 171 172 172 173 static struct dentry *openpromfs_lookup(struct inode *, struct dentry *, struct nameidata *);
+9 -2
fs/proc/proc_sysctl.c
··· 298 298 * sysctl entries that are not writeable, 299 299 * are _NOT_ writeable, capabilities or not. 300 300 */ 301 - struct ctl_table_header *head = grab_header(inode); 302 - struct ctl_table *table = PROC_I(inode)->sysctl_entry; 301 + struct ctl_table_header *head; 302 + struct ctl_table *table; 303 303 int error; 304 304 305 + /* Executable files are not allowed under /proc/sys/ */ 306 + if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) 307 + return -EACCES; 308 + 309 + head = grab_header(inode); 305 310 if (IS_ERR(head)) 306 311 return PTR_ERR(head); 307 312 313 + table = PROC_I(inode)->sysctl_entry; 308 314 if (!table) /* global root - r-xr-xr-x */ 309 315 error = mask & MAY_WRITE ? -EACCES : 0; 310 316 else /* Use the permissions on the sysctl table entry */ ··· 359 353 360 354 static const struct file_operations proc_sys_dir_file_operations = { 361 355 .readdir = proc_sys_readdir, 356 + .llseek = generic_file_llseek, 362 357 }; 363 358 364 359 static const struct inode_operations proc_sys_inode_operations = {
+40 -18
fs/read_write.c
··· 31 31 32 32 EXPORT_SYMBOL(generic_ro_fops); 33 33 34 + /** 35 + * generic_file_llseek_unlocked - lockless generic llseek implementation 36 + * @file: file structure to seek on 37 + * @offset: file offset to seek to 38 + * @origin: type of seek 39 + * 40 + * Updates the file offset to the value specified by @offset and @origin. 41 + * Locking must be provided by the caller. 42 + */ 34 43 loff_t 35 44 generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin) 36 45 { 37 - loff_t retval; 38 46 struct inode *inode = file->f_mapping->host; 39 47 40 48 switch (origin) { 41 - case SEEK_END: 42 - offset += inode->i_size; 43 - break; 44 - case SEEK_CUR: 45 - offset += file->f_pos; 49 + case SEEK_END: 50 + offset += inode->i_size; 51 + break; 52 + case SEEK_CUR: 53 + offset += file->f_pos; 54 + break; 46 55 } 47 - retval = -EINVAL; 48 - if (offset>=0 && offset<=inode->i_sb->s_maxbytes) { 49 - /* Special lock needed here? */ 50 - if (offset != file->f_pos) { 51 - file->f_pos = offset; 52 - file->f_version = 0; 53 - } 54 - retval = offset; 56 + 57 + if (offset < 0 || offset > inode->i_sb->s_maxbytes) 58 + return -EINVAL; 59 + 60 + /* Special lock needed here? */ 61 + if (offset != file->f_pos) { 62 + file->f_pos = offset; 63 + file->f_version = 0; 55 64 } 56 - return retval; 65 + 66 + return offset; 57 67 } 58 68 EXPORT_SYMBOL(generic_file_llseek_unlocked); 59 69 70 + /** 71 + * generic_file_llseek - generic llseek implementation for regular files 72 + * @file: file structure to seek on 73 + * @offset: file offset to seek to 74 + * @origin: type of seek 75 + * 76 + * This is a generic implemenation of ->llseek useable for all normal local 77 + * filesystems. It just updates the file offset to the value specified by 78 + * @offset and @origin under i_mutex. 79 + */ 60 80 loff_t generic_file_llseek(struct file *file, loff_t offset, int origin) 61 81 { 62 - loff_t n; 82 + loff_t rval; 83 + 63 84 mutex_lock(&file->f_dentry->d_inode->i_mutex); 64 - n = generic_file_llseek_unlocked(file, offset, origin); 85 + rval = generic_file_llseek_unlocked(file, offset, origin); 65 86 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 66 - return n; 87 + 88 + return rval; 67 89 } 68 90 EXPORT_SYMBOL(generic_file_llseek); 69 91
+8 -14
fs/readdir.c
··· 117 117 buf.dirent = dirent; 118 118 119 119 error = vfs_readdir(file, fillonedir, &buf); 120 - if (error >= 0) 120 + if (buf.result) 121 121 error = buf.result; 122 122 123 123 fput(file); ··· 209 209 buf.error = 0; 210 210 211 211 error = vfs_readdir(file, filldir, &buf); 212 - if (error < 0) 213 - goto out_putf; 214 - error = buf.error; 212 + if (error >= 0) 213 + error = buf.error; 215 214 lastdirent = buf.previous; 216 215 if (lastdirent) { 217 216 if (put_user(file->f_pos, &lastdirent->d_off)) ··· 218 219 else 219 220 error = count - buf.count; 220 221 } 221 - 222 - out_putf: 223 222 fput(file); 224 223 out: 225 224 return error; ··· 290 293 buf.error = 0; 291 294 292 295 error = vfs_readdir(file, filldir64, &buf); 293 - if (error < 0) 294 - goto out_putf; 295 - error = buf.error; 296 + if (error >= 0) 297 + error = buf.error; 296 298 lastdirent = buf.previous; 297 299 if (lastdirent) { 298 300 typeof(lastdirent->d_off) d_off = file->f_pos; 299 - error = -EFAULT; 300 301 if (__put_user(d_off, &lastdirent->d_off)) 301 - goto out_putf; 302 - error = count - buf.count; 302 + error = -EFAULT; 303 + else 304 + error = count - buf.count; 303 305 } 304 - 305 - out_putf: 306 306 fput(file); 307 307 out: 308 308 return error;
+1
fs/reiserfs/file.c
··· 296 296 .aio_write = generic_file_aio_write, 297 297 .splice_read = generic_file_splice_read, 298 298 .splice_write = generic_file_splice_write, 299 + .llseek = generic_file_llseek, 299 300 }; 300 301 301 302 const struct inode_operations reiserfs_file_inode_operations = {
+2 -11
fs/reiserfs/inode.c
··· 1522 1522 1523 1523 { 1524 1524 struct cpu_key key; 1525 - struct dentry *result; 1526 1525 struct inode *inode; 1527 1526 1528 1527 key.on_disk_key.k_objectid = objectid; ··· 1534 1535 inode = NULL; 1535 1536 } 1536 1537 reiserfs_write_unlock(sb); 1537 - if (!inode) 1538 - inode = ERR_PTR(-ESTALE); 1539 - if (IS_ERR(inode)) 1540 - return ERR_CAST(inode); 1541 - result = d_alloc_anon(inode); 1542 - if (!result) { 1543 - iput(inode); 1544 - return ERR_PTR(-ENOMEM); 1545 - } 1546 - return result; 1538 + 1539 + return d_obtain_alias(inode); 1547 1540 } 1548 1541 1549 1542 struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+1 -10
fs/reiserfs/namei.c
··· 383 383 struct inode *inode = NULL; 384 384 struct reiserfs_dir_entry de; 385 385 INITIALIZE_PATH(path_to_entry); 386 - struct dentry *parent; 387 386 struct inode *dir = child->d_inode; 388 387 389 388 if (dir->i_nlink == 0) { ··· 400 401 inode = reiserfs_iget(dir->i_sb, (struct cpu_key *)&(de.de_dir_id)); 401 402 reiserfs_write_unlock(dir->i_sb); 402 403 403 - if (!inode || IS_ERR(inode)) { 404 - return ERR_PTR(-EACCES); 405 - } 406 - parent = d_alloc_anon(inode); 407 - if (!parent) { 408 - iput(inode); 409 - parent = ERR_PTR(-ENOMEM); 410 - } 411 - return parent; 404 + return d_obtain_alias(inode); 412 405 } 413 406 414 407 /* add entry to the directory (entry can be hidden).
+9 -9
fs/reiserfs/super.c
··· 2058 2058 * Standard function to be called on quota_on 2059 2059 */ 2060 2060 static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, 2061 - char *path, int remount) 2061 + char *name, int remount) 2062 2062 { 2063 2063 int err; 2064 - struct nameidata nd; 2064 + struct path path; 2065 2065 struct inode *inode; 2066 2066 struct reiserfs_transaction_handle th; 2067 2067 ··· 2069 2069 return -EINVAL; 2070 2070 /* No more checks needed? Path and format_id are bogus anyway... */ 2071 2071 if (remount) 2072 - return vfs_quota_on(sb, type, format_id, path, 1); 2073 - err = path_lookup(path, LOOKUP_FOLLOW, &nd); 2072 + return vfs_quota_on(sb, type, format_id, name, 1); 2073 + err = kern_path(name, LOOKUP_FOLLOW, &path); 2074 2074 if (err) 2075 2075 return err; 2076 2076 /* Quotafile not on the same filesystem? */ 2077 - if (nd.path.mnt->mnt_sb != sb) { 2077 + if (path.mnt->mnt_sb != sb) { 2078 2078 err = -EXDEV; 2079 2079 goto out; 2080 2080 } 2081 - inode = nd.path.dentry->d_inode; 2081 + inode = path.dentry->d_inode; 2082 2082 /* We must not pack tails for quota files on reiserfs for quota IO to work */ 2083 2083 if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) { 2084 2084 err = reiserfs_unpack(inode, NULL); ··· 2094 2094 /* Journaling quota? */ 2095 2095 if (REISERFS_SB(sb)->s_qf_names[type]) { 2096 2096 /* Quotafile not of fs root? */ 2097 - if (nd.path.dentry->d_parent->d_inode != sb->s_root->d_inode) 2097 + if (path.dentry->d_parent != sb->s_root) 2098 2098 reiserfs_warning(sb, 2099 2099 "reiserfs: Quota file not on filesystem root. " 2100 2100 "Journalled quota will not work."); ··· 2113 2113 if (err) 2114 2114 goto out; 2115 2115 } 2116 - err = vfs_quota_on_path(sb, type, format_id, &nd.path); 2116 + err = vfs_quota_on_path(sb, type, format_id, &path); 2117 2117 out: 2118 - path_put(&nd.path); 2118 + path_put(&path); 2119 2119 return err; 2120 2120 } 2121 2121
+5 -10
fs/super.c
··· 682 682 * filesystems which don't use real block-devices. -- jrs 683 683 */ 684 684 685 - static struct idr unnamed_dev_idr; 685 + static DEFINE_IDA(unnamed_dev_ida); 686 686 static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ 687 687 688 688 int set_anon_super(struct super_block *s, void *data) ··· 691 691 int error; 692 692 693 693 retry: 694 - if (idr_pre_get(&unnamed_dev_idr, GFP_ATOMIC) == 0) 694 + if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) 695 695 return -ENOMEM; 696 696 spin_lock(&unnamed_dev_lock); 697 - error = idr_get_new(&unnamed_dev_idr, NULL, &dev); 697 + error = ida_get_new(&unnamed_dev_ida, &dev); 698 698 spin_unlock(&unnamed_dev_lock); 699 699 if (error == -EAGAIN) 700 700 /* We raced and lost with another CPU. */ ··· 704 704 705 705 if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) { 706 706 spin_lock(&unnamed_dev_lock); 707 - idr_remove(&unnamed_dev_idr, dev); 707 + ida_remove(&unnamed_dev_ida, dev); 708 708 spin_unlock(&unnamed_dev_lock); 709 709 return -EMFILE; 710 710 } ··· 720 720 721 721 generic_shutdown_super(sb); 722 722 spin_lock(&unnamed_dev_lock); 723 - idr_remove(&unnamed_dev_idr, slot); 723 + ida_remove(&unnamed_dev_ida, slot); 724 724 spin_unlock(&unnamed_dev_lock); 725 725 } 726 726 727 727 EXPORT_SYMBOL(kill_anon_super); 728 - 729 - void __init unnamed_dev_init(void) 730 - { 731 - idr_init(&unnamed_dev_idr); 732 - } 733 728 734 729 void kill_litter_super(struct super_block *sb) 735 730 {
+1
fs/sysfs/dir.c
··· 983 983 const struct file_operations sysfs_dir_operations = { 984 984 .read = generic_read_dir, 985 985 .readdir = sysfs_readdir, 986 + .llseek = generic_file_llseek, 986 987 };
+13 -30
fs/udf/namei.c
··· 142 142 } 143 143 144 144 static struct fileIdentDesc *udf_find_entry(struct inode *dir, 145 - struct dentry *dentry, 145 + struct qstr *child, 146 146 struct udf_fileident_bh *fibh, 147 147 struct fileIdentDesc *cfi) 148 148 { ··· 159 159 sector_t offset; 160 160 struct extent_position epos = {}; 161 161 struct udf_inode_info *dinfo = UDF_I(dir); 162 - int isdotdot = dentry->d_name.len == 2 && 163 - dentry->d_name.name[0] == '.' && dentry->d_name.name[1] == '.'; 162 + int isdotdot = child->len == 2 && 163 + child->name[0] == '.' && child->name[1] == '.'; 164 164 165 165 size = udf_ext0_offset(dir) + dir->i_size; 166 166 f_pos = udf_ext0_offset(dir); ··· 238 238 continue; 239 239 240 240 flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi); 241 - if (flen && udf_match(flen, fname, dentry->d_name.len, 242 - dentry->d_name.name)) 241 + if (flen && udf_match(flen, fname, child->len, child->name)) 243 242 goto out_ok; 244 243 } 245 244 ··· 282 283 } else 283 284 #endif /* UDF_RECOVERY */ 284 285 285 - if (udf_find_entry(dir, dentry, &fibh, &cfi)) { 286 + if (udf_find_entry(dir, &dentry->d_name, &fibh, &cfi)) { 286 287 if (fibh.sbh != fibh.ebh) 287 288 brelse(fibh.ebh); 288 289 brelse(fibh.sbh); ··· 782 783 783 784 retval = -ENOENT; 784 785 lock_kernel(); 785 - fi = udf_find_entry(dir, dentry, &fibh, &cfi); 786 + fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 786 787 if (!fi) 787 788 goto out; 788 789 ··· 828 829 829 830 retval = -ENOENT; 830 831 lock_kernel(); 831 - fi = udf_find_entry(dir, dentry, &fibh, &cfi); 832 + fi = udf_find_entry(dir, &dentry->d_name, &fibh, &cfi); 832 833 if (!fi) 833 834 goto out; 834 835 ··· 1112 1113 struct udf_inode_info *old_iinfo = UDF_I(old_inode); 1113 1114 1114 1115 lock_kernel(); 1115 - ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); 1116 + ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 1116 1117 if (ofi) { 1117 1118 if (ofibh.sbh != ofibh.ebh) 1118 1119 brelse(ofibh.ebh); ··· 1123 1124 != old_inode->i_ino) 1124 1125 goto end_rename; 1125 1126 1126 - nfi = udf_find_entry(new_dir, new_dentry, &nfibh, &ncfi); 1127 + nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi); 1127 1128 if (nfi) { 1128 1129 if (!new_inode) { 1129 1130 if (nfibh.sbh != nfibh.ebh) ··· 1191 1192 udf_write_fi(new_dir, &ncfi, nfi, &nfibh, NULL, NULL); 1192 1193 1193 1194 /* The old fid may have moved - find it again */ 1194 - ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi); 1195 + ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi); 1195 1196 udf_delete_entry(old_dir, ofi, &ofibh, &ocfi); 1196 1197 1197 1198 if (new_inode) { ··· 1242 1243 1243 1244 static struct dentry *udf_get_parent(struct dentry *child) 1244 1245 { 1245 - struct dentry *parent; 1246 1246 struct inode *inode = NULL; 1247 - struct dentry dotdot; 1247 + struct qstr dotdot = {.name = "..", .len = 2}; 1248 1248 struct fileIdentDesc cfi; 1249 1249 struct udf_fileident_bh fibh; 1250 - 1251 - dotdot.d_name.name = ".."; 1252 - dotdot.d_name.len = 2; 1253 1250 1254 1251 lock_kernel(); 1255 1252 if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi)) ··· 1261 1266 goto out_unlock; 1262 1267 unlock_kernel(); 1263 1268 1264 - parent = d_alloc_anon(inode); 1265 - if (!parent) { 1266 - iput(inode); 1267 - parent = ERR_PTR(-ENOMEM); 1268 - } 1269 - 1270 - return parent; 1269 + return d_obtain_alias(inode); 1271 1270 out_unlock: 1272 1271 unlock_kernel(); 1273 1272 return ERR_PTR(-EACCES); ··· 1272 1283 u16 partref, __u32 generation) 1273 1284 { 1274 1285 struct inode *inode; 1275 - struct dentry *result; 1276 1286 kernel_lb_addr loc; 1277 1287 1278 1288 if (block == 0) ··· 1288 1300 iput(inode); 1289 1301 return ERR_PTR(-ESTALE); 1290 1302 } 1291 - result = d_alloc_anon(inode); 1292 - if (!result) { 1293 - iput(inode); 1294 - return ERR_PTR(-ENOMEM); 1295 - } 1296 - return result; 1303 + return d_obtain_alias(inode); 1297 1304 } 1298 1305 1299 1306 static struct dentry *udf_fh_to_dentry(struct super_block *sb,
+1
fs/ufs/dir.c
··· 667 667 .read = generic_read_dir, 668 668 .readdir = ufs_readdir, 669 669 .fsync = file_fsync, 670 + .llseek = generic_file_llseek, 670 671 };
+3 -29
fs/xfs/linux-2.6/xfs_export.c
··· 148 148 { 149 149 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; 150 150 struct inode *inode = NULL; 151 - struct dentry *result; 152 151 153 152 if (fh_len < xfs_fileid_length(fileid_type)) 154 153 return NULL; ··· 163 164 break; 164 165 } 165 166 166 - if (!inode) 167 - return NULL; 168 - if (IS_ERR(inode)) 169 - return ERR_CAST(inode); 170 - result = d_alloc_anon(inode); 171 - if (!result) { 172 - iput(inode); 173 - return ERR_PTR(-ENOMEM); 174 - } 175 - return result; 167 + return d_obtain_alias(inode); 176 168 } 177 169 178 170 STATIC struct dentry * ··· 172 182 { 173 183 struct xfs_fid64 *fid64 = (struct xfs_fid64 *)fid; 174 184 struct inode *inode = NULL; 175 - struct dentry *result; 176 185 177 186 switch (fileid_type) { 178 187 case FILEID_INO32_GEN_PARENT: ··· 184 195 break; 185 196 } 186 197 187 - if (!inode) 188 - return NULL; 189 - if (IS_ERR(inode)) 190 - return ERR_CAST(inode); 191 - result = d_alloc_anon(inode); 192 - if (!result) { 193 - iput(inode); 194 - return ERR_PTR(-ENOMEM); 195 - } 196 - return result; 198 + return d_obtain_alias(inode); 197 199 } 198 200 199 201 STATIC struct dentry * ··· 193 213 { 194 214 int error; 195 215 struct xfs_inode *cip; 196 - struct dentry *parent; 197 216 198 217 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL); 199 218 if (unlikely(error)) 200 219 return ERR_PTR(-error); 201 220 202 - parent = d_alloc_anon(VFS_I(cip)); 203 - if (unlikely(!parent)) { 204 - iput(VFS_I(cip)); 205 - return ERR_PTR(-ENOMEM); 206 - } 207 - return parent; 221 + return d_obtain_alias(VFS_I(cip)); 208 222 } 209 223 210 224 const struct export_operations xfs_export_operations = {
-128
fs/xfs/linux-2.6/xfs_file.c
··· 204 204 return -xfs_fsync(XFS_I(dentry->d_inode)); 205 205 } 206 206 207 - /* 208 - * Unfortunately we can't just use the clean and simple readdir implementation 209 - * below, because nfs might call back into ->lookup from the filldir callback 210 - * and that will deadlock the low-level btree code. 211 - * 212 - * Hopefully we'll find a better workaround that allows to use the optimal 213 - * version at least for local readdirs for 2.6.25. 214 - */ 215 - #if 0 216 207 STATIC int 217 208 xfs_file_readdir( 218 209 struct file *filp, ··· 235 244 return -error; 236 245 return 0; 237 246 } 238 - #else 239 - 240 - struct hack_dirent { 241 - u64 ino; 242 - loff_t offset; 243 - int namlen; 244 - unsigned int d_type; 245 - char name[]; 246 - }; 247 - 248 - struct hack_callback { 249 - char *dirent; 250 - size_t len; 251 - size_t used; 252 - }; 253 - 254 - STATIC int 255 - xfs_hack_filldir( 256 - void *__buf, 257 - const char *name, 258 - int namlen, 259 - loff_t offset, 260 - u64 ino, 261 - unsigned int d_type) 262 - { 263 - struct hack_callback *buf = __buf; 264 - struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used); 265 - unsigned int reclen; 266 - 267 - reclen = ALIGN(sizeof(struct hack_dirent) + namlen, sizeof(u64)); 268 - if (buf->used + reclen > buf->len) 269 - return -EINVAL; 270 - 271 - de->namlen = namlen; 272 - de->offset = offset; 273 - de->ino = ino; 274 - de->d_type = d_type; 275 - memcpy(de->name, name, namlen); 276 - buf->used += reclen; 277 - return 0; 278 - } 279 - 280 - STATIC int 281 - xfs_file_readdir( 282 - struct file *filp, 283 - void *dirent, 284 - filldir_t filldir) 285 - { 286 - struct inode *inode = filp->f_path.dentry->d_inode; 287 - xfs_inode_t *ip = XFS_I(inode); 288 - struct hack_callback buf; 289 - struct hack_dirent *de; 290 - int error; 291 - loff_t size; 292 - int eof = 0; 293 - xfs_off_t start_offset, curr_offset, offset; 294 - 295 - /* 296 - * Try fairly hard to get memory 297 - */ 298 - buf.len = PAGE_CACHE_SIZE; 299 - do { 300 - buf.dirent = kmalloc(buf.len, GFP_KERNEL); 301 - if (buf.dirent) 302 - break; 303 - buf.len >>= 1; 304 - } while (buf.len >= 1024); 305 - 306 - if (!buf.dirent) 307 - return -ENOMEM; 308 - 309 - curr_offset = filp->f_pos; 310 - if (curr_offset == 0x7fffffff) 311 - offset = 0xffffffff; 312 - else 313 - offset = filp->f_pos; 314 - 315 - while (!eof) { 316 - unsigned int reclen; 317 - 318 - start_offset = offset; 319 - 320 - buf.used = 0; 321 - error = -xfs_readdir(ip, &buf, buf.len, &offset, 322 - xfs_hack_filldir); 323 - if (error || offset == start_offset) { 324 - size = 0; 325 - break; 326 - } 327 - 328 - size = buf.used; 329 - de = (struct hack_dirent *)buf.dirent; 330 - while (size > 0) { 331 - curr_offset = de->offset /* & 0x7fffffff */; 332 - if (filldir(dirent, de->name, de->namlen, 333 - curr_offset & 0x7fffffff, 334 - de->ino, de->d_type)) { 335 - goto done; 336 - } 337 - 338 - reclen = ALIGN(sizeof(struct hack_dirent) + de->namlen, 339 - sizeof(u64)); 340 - size -= reclen; 341 - de = (struct hack_dirent *)((char *)de + reclen); 342 - } 343 - } 344 - 345 - done: 346 - if (!error) { 347 - if (size == 0) 348 - filp->f_pos = offset & 0x7fffffff; 349 - else if (de) 350 - filp->f_pos = curr_offset; 351 - } 352 - 353 - kfree(buf.dirent); 354 - return error; 355 - } 356 - #endif 357 247 358 248 STATIC int 359 249 xfs_file_mmap(
+3 -4
fs/xfs/linux-2.6/xfs_ioctl.c
··· 311 311 return new_fd; 312 312 } 313 313 314 - dentry = d_alloc_anon(inode); 315 - if (dentry == NULL) { 316 - iput(inode); 314 + dentry = d_obtain_alias(inode); 315 + if (IS_ERR(dentry)) { 317 316 put_unused_fd(new_fd); 318 - return -XFS_ERROR(ENOMEM); 317 + return PTR_ERR(dentry); 319 318 } 320 319 321 320 /* Ensure umount returns EBUSY on umounts while this file is open. */
+2 -1
include/linux/dcache.h
··· 228 228 229 229 /* allocate/de-allocate */ 230 230 extern struct dentry * d_alloc(struct dentry *, const struct qstr *); 231 - extern struct dentry * d_alloc_anon(struct inode *); 232 231 extern struct dentry * d_splice_alias(struct inode *, struct dentry *); 233 232 extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); 233 + extern struct dentry * d_obtain_alias(struct inode *); 234 234 extern void shrink_dcache_sb(struct super_block *); 235 235 extern void shrink_dcache_parent(struct dentry *); 236 236 extern void shrink_dcache_for_umount(struct super_block *); ··· 287 287 288 288 /* used for rename() and baskets */ 289 289 extern void d_move(struct dentry *, struct dentry *); 290 + extern struct dentry *d_ancestor(struct dentry *, struct dentry *); 290 291 291 292 /* appendix may either be NULL or be used for transname suffixes */ 292 293 extern struct dentry * d_lookup(struct dentry *, struct qstr *);
+6 -2
include/linux/fs.h
··· 136 136 /* 137 137 * Superblock flags that can be altered by MS_REMOUNT 138 138 */ 139 - #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK) 139 + #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION) 140 140 141 141 /* 142 142 * Old magic mount flag and mask ··· 1593 1593 struct vfsmount *mnt); 1594 1594 extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); 1595 1595 int __put_super_and_need_restart(struct super_block *sb); 1596 - void unnamed_dev_init(void); 1597 1596 1598 1597 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ 1599 1598 #define fops_get(fops) \ ··· 1850 1851 extern int inode_permission(struct inode *, int); 1851 1852 extern int generic_permission(struct inode *, int, 1852 1853 int (*check_acl)(struct inode *, int)); 1854 + 1855 + static inline bool execute_ok(struct inode *inode) 1856 + { 1857 + return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode); 1858 + } 1853 1859 1854 1860 extern int get_write_access(struct inode *); 1855 1861 extern int deny_write_access(struct file *);
+6 -2
include/linux/namei.h
··· 51 51 /* 52 52 * Intent data 53 53 */ 54 - #define LOOKUP_OPEN (0x0100) 55 - #define LOOKUP_CREATE (0x0200) 54 + #define LOOKUP_OPEN 0x0100 55 + #define LOOKUP_CREATE 0x0200 56 + #define LOOKUP_EXCL 0x0400 57 + #define LOOKUP_RENAME_TARGET 0x0800 56 58 57 59 extern int user_path_at(int, const char __user *, unsigned, struct path *); 58 60 ··· 62 60 #define user_lpath(name, path) user_path_at(AT_FDCWD, name, 0, path) 63 61 #define user_path_dir(name, path) \ 64 62 user_path_at(AT_FDCWD, name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, path) 63 + 64 + extern int kern_path(const char *, unsigned, struct path *); 65 65 66 66 extern int path_lookup(const char *, unsigned, struct nameidata *); 67 67 extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
-1
init/main.c
··· 672 672 fork_init(num_physpages); 673 673 proc_caches_init(); 674 674 buffer_init(); 675 - unnamed_dev_init(); 676 675 key_init(); 677 676 security_init(); 678 677 vfs_caches_init(num_physpages);
+24 -24
kernel/audit_tree.c
··· 532 532 list_add(&cursor, &tree_list); 533 533 while (cursor.next != &tree_list) { 534 534 struct audit_tree *tree; 535 - struct nameidata nd; 535 + struct path path; 536 536 struct vfsmount *root_mnt; 537 537 struct node *node; 538 538 struct list_head list; ··· 544 544 list_add(&cursor, &tree->list); 545 545 mutex_unlock(&audit_filter_mutex); 546 546 547 - err = path_lookup(tree->pathname, 0, &nd); 547 + err = kern_path(tree->pathname, 0, &path); 548 548 if (err) 549 549 goto skip_it; 550 550 551 - root_mnt = collect_mounts(nd.path.mnt, nd.path.dentry); 552 - path_put(&nd.path); 551 + root_mnt = collect_mounts(path.mnt, path.dentry); 552 + path_put(&path); 553 553 if (!root_mnt) 554 554 goto skip_it; 555 555 ··· 580 580 } 581 581 582 582 static int is_under(struct vfsmount *mnt, struct dentry *dentry, 583 - struct nameidata *nd) 583 + struct path *path) 584 584 { 585 - if (mnt != nd->path.mnt) { 585 + if (mnt != path->mnt) { 586 586 for (;;) { 587 587 if (mnt->mnt_parent == mnt) 588 588 return 0; 589 - if (mnt->mnt_parent == nd->path.mnt) 589 + if (mnt->mnt_parent == path->mnt) 590 590 break; 591 591 mnt = mnt->mnt_parent; 592 592 } 593 593 dentry = mnt->mnt_mountpoint; 594 594 } 595 - return is_subdir(dentry, nd->path.dentry); 595 + return is_subdir(dentry, path->dentry); 596 596 } 597 597 598 598 int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) ··· 618 618 int audit_add_tree_rule(struct audit_krule *rule) 619 619 { 620 620 struct audit_tree *seed = rule->tree, *tree; 621 - struct nameidata nd; 621 + struct path path; 622 622 struct vfsmount *mnt, *p; 623 623 struct list_head list; 624 624 int err; ··· 637 637 /* do not set rule->tree yet */ 638 638 mutex_unlock(&audit_filter_mutex); 639 639 640 - err = path_lookup(tree->pathname, 0, &nd); 640 + err = kern_path(tree->pathname, 0, &path); 641 641 if (err) 642 642 goto Err; 643 - mnt = collect_mounts(nd.path.mnt, nd.path.dentry); 644 - path_put(&nd.path); 643 + mnt = collect_mounts(path.mnt, path.dentry); 644 + path_put(&path); 645 645 if (!mnt) { 646 646 err = -ENOMEM; 647 647 goto Err; ··· 690 690 { 691 691 struct list_head cursor, barrier; 692 692 int failed = 0; 693 - struct nameidata nd; 693 + struct path path; 694 694 struct vfsmount *tagged; 695 695 struct list_head list; 696 696 struct vfsmount *mnt; 697 697 struct dentry *dentry; 698 698 int err; 699 699 700 - err = path_lookup(new, 0, &nd); 700 + err = kern_path(new, 0, &path); 701 701 if (err) 702 702 return err; 703 - tagged = collect_mounts(nd.path.mnt, nd.path.dentry); 704 - path_put(&nd.path); 703 + tagged = collect_mounts(path.mnt, path.dentry); 704 + path_put(&path); 705 705 if (!tagged) 706 706 return -ENOMEM; 707 707 708 - err = path_lookup(old, 0, &nd); 708 + err = kern_path(old, 0, &path); 709 709 if (err) { 710 710 drop_collected_mounts(tagged); 711 711 return err; 712 712 } 713 - mnt = mntget(nd.path.mnt); 714 - dentry = dget(nd.path.dentry); 715 - path_put(&nd.path); 713 + mnt = mntget(path.mnt); 714 + dentry = dget(path.dentry); 715 + path_put(&path); 716 716 717 717 if (dentry == tagged->mnt_root && dentry == mnt->mnt_root) 718 718 follow_up(&mnt, &dentry); ··· 733 733 list_add(&cursor, &tree->list); 734 734 mutex_unlock(&audit_filter_mutex); 735 735 736 - err = path_lookup(tree->pathname, 0, &nd); 736 + err = kern_path(tree->pathname, 0, &path); 737 737 if (err) { 738 738 put_tree(tree); 739 739 mutex_lock(&audit_filter_mutex); ··· 741 741 } 742 742 743 743 spin_lock(&vfsmount_lock); 744 - if (!is_under(mnt, dentry, &nd)) { 744 + if (!is_under(mnt, dentry, &path)) { 745 745 spin_unlock(&vfsmount_lock); 746 - path_put(&nd.path); 746 + path_put(&path); 747 747 put_tree(tree); 748 748 mutex_lock(&audit_filter_mutex); 749 749 continue; 750 750 } 751 751 spin_unlock(&vfsmount_lock); 752 - path_put(&nd.path); 752 + path_put(&path); 753 753 754 754 list_for_each_entry(p, &list, mnt_list) { 755 755 failed = tag_chunk(p->mnt_root->d_inode, tree);
+10 -8
net/unix/af_unix.c
··· 711 711 int type, unsigned hash, int *error) 712 712 { 713 713 struct sock *u; 714 - struct nameidata nd; 714 + struct path path; 715 715 int err = 0; 716 716 717 717 if (sunname->sun_path[0]) { 718 - err = path_lookup(sunname->sun_path, LOOKUP_FOLLOW, &nd); 718 + struct inode *inode; 719 + err = kern_path(sunname->sun_path, LOOKUP_FOLLOW, &path); 719 720 if (err) 720 721 goto fail; 721 - err = vfs_permission(&nd, MAY_WRITE); 722 + inode = path.dentry->d_inode; 723 + err = inode_permission(inode, MAY_WRITE); 722 724 if (err) 723 725 goto put_fail; 724 726 725 727 err = -ECONNREFUSED; 726 - if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode)) 728 + if (!S_ISSOCK(inode->i_mode)) 727 729 goto put_fail; 728 - u = unix_find_socket_byinode(net, nd.path.dentry->d_inode); 730 + u = unix_find_socket_byinode(net, inode); 729 731 if (!u) 730 732 goto put_fail; 731 733 732 734 if (u->sk_type == type) 733 - touch_atime(nd.path.mnt, nd.path.dentry); 735 + touch_atime(path.mnt, path.dentry); 734 736 735 - path_put(&nd.path); 737 + path_put(&path); 736 738 737 739 err=-EPROTOTYPE; 738 740 if (u->sk_type != type) { ··· 755 753 return u; 756 754 757 755 put_fail: 758 - path_put(&nd.path); 756 + path_put(&path); 759 757 fail: 760 758 *error=err; 761 759 return NULL;