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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'pull-rpc_pipefs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull rpc_pipefs updates from Al Viro:
"Massage rpc_pipefs to use saner primitives and clean up the APIs
provided to the rest of the kernel"

* tag 'pull-rpc_pipefs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
rpc_create_client_dir(): return 0 or -E...
rpc_create_client_dir(): don't bother with rpc_populate()
rpc_new_dir(): the last argument is always NULL
rpc_pipe: expand the calls of rpc_mkdir_populate()
rpc_gssd_dummy_populate(): don't bother with rpc_populate()
rpc_mkpipe_dentry(): switch to simple_start_creating()
rpc_pipe: saner primitive for creating regular files
rpc_pipe: saner primitive for creating subdirectories
rpc_pipe: don't overdo directory locking
rpc_mkpipe_dentry(): saner calling conventions
rpc_unlink(): saner calling conventions
rpc_populate(): lift cleanup into callers
rpc_unlink(): use simple_recursive_removal()
rpc_{rmdir_,}depopulate(): use simple_recursive_removal() instead
rpc_pipe: clean failure exits in fill_super
new helper: simple_start_creating()

+227 -536
+3 -18
fs/debugfs/inode.c
··· 384 384 if (!parent) 385 385 parent = debugfs_mount->mnt_root; 386 386 387 - inode_lock(d_inode(parent)); 388 - if (unlikely(IS_DEADDIR(d_inode(parent)))) 389 - dentry = ERR_PTR(-ENOENT); 390 - else 391 - dentry = lookup_noperm(&QSTR(name), parent); 392 - if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { 393 - if (d_is_dir(dentry)) 394 - pr_err("Directory '%s' with parent '%s' already present!\n", 395 - name, parent->d_name.name); 396 - else 397 - pr_err("File '%s' in directory '%s' already present!\n", 398 - name, parent->d_name.name); 399 - dput(dentry); 400 - dentry = ERR_PTR(-EEXIST); 401 - } 402 - 387 + dentry = simple_start_creating(parent, name); 403 388 if (IS_ERR(dentry)) { 404 - inode_unlock(d_inode(parent)); 389 + if (dentry == ERR_PTR(-EEXIST)) 390 + pr_err("'%s' already exists in '%pd'\n", name, parent); 405 391 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 406 392 } 407 - 408 393 return dentry; 409 394 } 410 395
+25
fs/libfs.c
··· 2272 2272 */ 2273 2273 cmpxchg(stashed, dentry, NULL); 2274 2274 } 2275 + 2276 + /* parent must be held exclusive */ 2277 + struct dentry *simple_start_creating(struct dentry *parent, const char *name) 2278 + { 2279 + struct dentry *dentry; 2280 + struct inode *dir = d_inode(parent); 2281 + 2282 + inode_lock(dir); 2283 + if (unlikely(IS_DEADDIR(dir))) { 2284 + inode_unlock(dir); 2285 + return ERR_PTR(-ENOENT); 2286 + } 2287 + dentry = lookup_noperm(&QSTR(name), parent); 2288 + if (IS_ERR(dentry)) { 2289 + inode_unlock(dir); 2290 + return dentry; 2291 + } 2292 + if (dentry->d_inode) { 2293 + dput(dentry); 2294 + inode_unlock(dir); 2295 + return ERR_PTR(-EEXIST); 2296 + } 2297 + return dentry; 2298 + } 2299 + EXPORT_SYMBOL(simple_start_creating);
+18 -35
fs/nfs/blocklayout/rpc_pipefs.c
··· 141 141 .destroy_msg = bl_pipe_destroy_msg, 142 142 }; 143 143 144 - static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb, 144 + static int nfs4blocklayout_register_sb(struct super_block *sb, 145 145 struct rpc_pipe *pipe) 146 146 { 147 - struct dentry *dir, *dentry; 147 + struct dentry *dir; 148 + int err; 148 149 149 150 dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME); 150 151 if (dir == NULL) 151 - return ERR_PTR(-ENOENT); 152 - dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe); 152 + return -ENOENT; 153 + err = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe); 153 154 dput(dir); 154 - return dentry; 155 - } 156 - 157 - static void nfs4blocklayout_unregister_sb(struct super_block *sb, 158 - struct rpc_pipe *pipe) 159 - { 160 - if (pipe->dentry) 161 - rpc_unlink(pipe->dentry); 155 + return err; 162 156 } 163 157 164 158 static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event, ··· 161 167 struct super_block *sb = ptr; 162 168 struct net *net = sb->s_fs_info; 163 169 struct nfs_net *nn = net_generic(net, nfs_net_id); 164 - struct dentry *dentry; 165 170 int ret = 0; 166 171 167 172 if (!try_module_get(THIS_MODULE)) ··· 173 180 174 181 switch (event) { 175 182 case RPC_PIPEFS_MOUNT: 176 - dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe); 177 - if (IS_ERR(dentry)) { 178 - ret = PTR_ERR(dentry); 179 - break; 180 - } 181 - nn->bl_device_pipe->dentry = dentry; 183 + ret = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe); 182 184 break; 183 185 case RPC_PIPEFS_UMOUNT: 184 - if (nn->bl_device_pipe->dentry) 185 - nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe); 186 + rpc_unlink(nn->bl_device_pipe); 186 187 break; 187 188 default: 188 189 ret = -ENOTSUPP; ··· 190 203 .notifier_call = rpc_pipefs_event, 191 204 }; 192 205 193 - static struct dentry *nfs4blocklayout_register_net(struct net *net, 194 - struct rpc_pipe *pipe) 206 + static int nfs4blocklayout_register_net(struct net *net, struct rpc_pipe *pipe) 195 207 { 196 208 struct super_block *pipefs_sb; 197 - struct dentry *dentry; 209 + int ret; 198 210 199 211 pipefs_sb = rpc_get_sb_net(net); 200 212 if (!pipefs_sb) 201 - return NULL; 202 - dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe); 213 + return 0; 214 + ret = nfs4blocklayout_register_sb(pipefs_sb, pipe); 203 215 rpc_put_sb_net(net); 204 - return dentry; 216 + return ret; 205 217 } 206 218 207 219 static void nfs4blocklayout_unregister_net(struct net *net, ··· 210 224 211 225 pipefs_sb = rpc_get_sb_net(net); 212 226 if (pipefs_sb) { 213 - nfs4blocklayout_unregister_sb(pipefs_sb, pipe); 227 + rpc_unlink(pipe); 214 228 rpc_put_sb_net(net); 215 229 } 216 230 } ··· 218 232 static int nfs4blocklayout_net_init(struct net *net) 219 233 { 220 234 struct nfs_net *nn = net_generic(net, nfs_net_id); 221 - struct dentry *dentry; 235 + int err; 222 236 223 237 mutex_init(&nn->bl_mutex); 224 238 init_waitqueue_head(&nn->bl_wq); 225 239 nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0); 226 240 if (IS_ERR(nn->bl_device_pipe)) 227 241 return PTR_ERR(nn->bl_device_pipe); 228 - dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe); 229 - if (IS_ERR(dentry)) { 242 + err = nfs4blocklayout_register_net(net, nn->bl_device_pipe); 243 + if (unlikely(err)) 230 244 rpc_destroy_pipe_data(nn->bl_device_pipe); 231 - return PTR_ERR(dentry); 232 - } 233 - nn->bl_device_pipe->dentry = dentry; 234 - return 0; 245 + return err; 235 246 } 236 247 237 248 static void nfs4blocklayout_net_exit(struct net *net)
+2 -12
fs/nfs/nfs4idmap.c
··· 424 424 struct rpc_pipe_dir_object *pdo) 425 425 { 426 426 struct idmap *idmap = pdo->pdo_data; 427 - struct rpc_pipe *pipe = idmap->idmap_pipe; 428 427 429 - if (pipe->dentry) { 430 - rpc_unlink(pipe->dentry); 431 - pipe->dentry = NULL; 432 - } 428 + rpc_unlink(idmap->idmap_pipe); 433 429 } 434 430 435 431 static int nfs_idmap_pipe_create(struct dentry *dir, 436 432 struct rpc_pipe_dir_object *pdo) 437 433 { 438 434 struct idmap *idmap = pdo->pdo_data; 439 - struct rpc_pipe *pipe = idmap->idmap_pipe; 440 - struct dentry *dentry; 441 435 442 - dentry = rpc_mkpipe_dentry(dir, "idmap", idmap, pipe); 443 - if (IS_ERR(dentry)) 444 - return PTR_ERR(dentry); 445 - pipe->dentry = dentry; 446 - return 0; 436 + return rpc_mkpipe_dentry(dir, "idmap", idmap, idmap->idmap_pipe); 447 437 } 448 438 449 439 static const struct rpc_pipe_dir_object_ops nfs_idmap_pipe_dir_object_ops = {
+16 -33
fs/nfsd/nfs4recover.c
··· 950 950 .destroy_msg = cld_pipe_destroy_msg, 951 951 }; 952 952 953 - static struct dentry * 953 + static int 954 954 nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe) 955 955 { 956 - struct dentry *dir, *dentry; 956 + struct dentry *dir; 957 + int err; 957 958 958 959 dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR); 959 960 if (dir == NULL) 960 - return ERR_PTR(-ENOENT); 961 - dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe); 961 + return -ENOENT; 962 + err = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe); 962 963 dput(dir); 963 - return dentry; 964 + return err; 964 965 } 965 966 966 - static void 967 - nfsd4_cld_unregister_sb(struct rpc_pipe *pipe) 968 - { 969 - if (pipe->dentry) 970 - rpc_unlink(pipe->dentry); 971 - } 972 - 973 - static struct dentry * 967 + static int 974 968 nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe) 975 969 { 976 970 struct super_block *sb; 977 - struct dentry *dentry; 971 + int err; 978 972 979 973 sb = rpc_get_sb_net(net); 980 974 if (!sb) 981 - return NULL; 982 - dentry = nfsd4_cld_register_sb(sb, pipe); 975 + return 0; 976 + err = nfsd4_cld_register_sb(sb, pipe); 983 977 rpc_put_sb_net(net); 984 - return dentry; 978 + return err; 985 979 } 986 980 987 981 static void ··· 985 991 986 992 sb = rpc_get_sb_net(net); 987 993 if (sb) { 988 - nfsd4_cld_unregister_sb(pipe); 994 + rpc_unlink(pipe); 989 995 rpc_put_sb_net(net); 990 996 } 991 997 } ··· 995 1001 __nfsd4_init_cld_pipe(struct net *net) 996 1002 { 997 1003 int ret; 998 - struct dentry *dentry; 999 1004 struct nfsd_net *nn = net_generic(net, nfsd_net_id); 1000 1005 struct cld_net *cn; 1001 1006 ··· 1015 1022 spin_lock_init(&cn->cn_lock); 1016 1023 INIT_LIST_HEAD(&cn->cn_list); 1017 1024 1018 - dentry = nfsd4_cld_register_net(net, cn->cn_pipe); 1019 - if (IS_ERR(dentry)) { 1020 - ret = PTR_ERR(dentry); 1025 + ret = nfsd4_cld_register_net(net, cn->cn_pipe); 1026 + if (unlikely(ret)) 1021 1027 goto err_destroy_data; 1022 - } 1023 1028 1024 - cn->cn_pipe->dentry = dentry; 1025 1029 #ifdef CONFIG_NFSD_LEGACY_CLIENT_TRACKING 1026 1030 cn->cn_has_legacy = false; 1027 1031 #endif ··· 2111 2121 struct net *net = sb->s_fs_info; 2112 2122 struct nfsd_net *nn = net_generic(net, nfsd_net_id); 2113 2123 struct cld_net *cn = nn->cld_net; 2114 - struct dentry *dentry; 2115 2124 int ret = 0; 2116 2125 2117 2126 if (!try_module_get(THIS_MODULE)) ··· 2123 2134 2124 2135 switch (event) { 2125 2136 case RPC_PIPEFS_MOUNT: 2126 - dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe); 2127 - if (IS_ERR(dentry)) { 2128 - ret = PTR_ERR(dentry); 2129 - break; 2130 - } 2131 - cn->cn_pipe->dentry = dentry; 2137 + ret = nfsd4_cld_register_sb(sb, cn->cn_pipe); 2132 2138 break; 2133 2139 case RPC_PIPEFS_UMOUNT: 2134 - if (cn->cn_pipe->dentry) 2135 - nfsd4_cld_unregister_sb(cn->cn_pipe); 2140 + rpc_unlink(cn->cn_pipe); 2136 2141 break; 2137 2142 default: 2138 2143 ret = -ENOTSUPP;
+2 -13
fs/tracefs/inode.c
··· 562 562 if (!parent) 563 563 parent = tracefs_mount->mnt_root; 564 564 565 - inode_lock(d_inode(parent)); 566 - if (unlikely(IS_DEADDIR(d_inode(parent)))) 567 - dentry = ERR_PTR(-ENOENT); 568 - else 569 - dentry = lookup_noperm(&QSTR(name), parent); 570 - if (!IS_ERR(dentry) && d_inode(dentry)) { 571 - dput(dentry); 572 - dentry = ERR_PTR(-EEXIST); 573 - } 574 - 575 - if (IS_ERR(dentry)) { 576 - inode_unlock(d_inode(parent)); 565 + dentry = simple_start_creating(parent, name); 566 + if (IS_ERR(dentry)) 577 567 simple_release_fs(&tracefs_mount, &tracefs_mount_count); 578 - } 579 568 580 569 return dentry; 581 570 }
+1
include/linux/fs.h
··· 3627 3627 const struct tree_descr *); 3628 3628 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 3629 3629 extern void simple_release_fs(struct vfsmount **mount, int *count); 3630 + struct dentry *simple_start_creating(struct dentry *, const char *); 3630 3631 3631 3632 extern ssize_t simple_read_from_buffer(void __user *to, size_t count, 3632 3633 loff_t *ppos, const void *from, size_t available);
+3 -3
include/linux/sunrpc/rpc_pipe_fs.h
··· 98 98 } 99 99 100 100 struct rpc_clnt; 101 - extern struct dentry *rpc_create_client_dir(struct dentry *, const char *, struct rpc_clnt *); 101 + extern int rpc_create_client_dir(struct dentry *, const char *, struct rpc_clnt *); 102 102 extern int rpc_remove_client_dir(struct rpc_clnt *); 103 103 104 104 extern void rpc_init_pipe_dir_head(struct rpc_pipe_dir_head *pdh); ··· 127 127 128 128 struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags); 129 129 void rpc_destroy_pipe_data(struct rpc_pipe *pipe); 130 - extern struct dentry *rpc_mkpipe_dentry(struct dentry *, const char *, void *, 130 + extern int rpc_mkpipe_dentry(struct dentry *, const char *, void *, 131 131 struct rpc_pipe *); 132 - extern int rpc_unlink(struct dentry *); 132 + extern void rpc_unlink(struct rpc_pipe *); 133 133 extern int register_rpc_pipefs(void); 134 134 extern void unregister_rpc_pipefs(void); 135 135
+2 -11
net/sunrpc/auth_gss/auth_gss.c
··· 887 887 struct rpc_pipe_dir_object *pdo) 888 888 { 889 889 struct gss_pipe *gss_pipe = pdo->pdo_data; 890 - struct rpc_pipe *pipe = gss_pipe->pipe; 891 890 892 - if (pipe->dentry != NULL) { 893 - rpc_unlink(pipe->dentry); 894 - pipe->dentry = NULL; 895 - } 891 + rpc_unlink(gss_pipe->pipe); 896 892 } 897 893 898 894 static int gss_pipe_dentry_create(struct dentry *dir, 899 895 struct rpc_pipe_dir_object *pdo) 900 896 { 901 897 struct gss_pipe *p = pdo->pdo_data; 902 - struct dentry *dentry; 903 898 904 - dentry = rpc_mkpipe_dentry(dir, p->name, p->clnt, p->pipe); 905 - if (IS_ERR(dentry)) 906 - return PTR_ERR(dentry); 907 - p->pipe->dentry = dentry; 908 - return 0; 899 + return rpc_mkpipe_dentry(dir, p->name, p->clnt, p->pipe); 909 900 } 910 901 911 902 static const struct rpc_pipe_dir_object_ops gss_pipe_dir_object_ops = {
+14 -22
net/sunrpc/clnt.c
··· 112 112 } 113 113 } 114 114 115 - static struct dentry *rpc_setup_pipedir_sb(struct super_block *sb, 115 + static int rpc_setup_pipedir_sb(struct super_block *sb, 116 116 struct rpc_clnt *clnt) 117 117 { 118 118 static uint32_t clntid; 119 119 const char *dir_name = clnt->cl_program->pipe_dir_name; 120 120 char name[15]; 121 - struct dentry *dir, *dentry; 121 + struct dentry *dir; 122 + int err; 122 123 123 124 dir = rpc_d_lookup_sb(sb, dir_name); 124 125 if (dir == NULL) { 125 126 pr_info("RPC: pipefs directory doesn't exist: %s\n", dir_name); 126 - return dir; 127 + return -ENOENT; 127 128 } 128 129 for (;;) { 129 130 snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++); 130 131 name[sizeof(name) - 1] = '\0'; 131 - dentry = rpc_create_client_dir(dir, name, clnt); 132 - if (!IS_ERR(dentry)) 132 + err = rpc_create_client_dir(dir, name, clnt); 133 + if (!err) 133 134 break; 134 - if (dentry == ERR_PTR(-EEXIST)) 135 + if (err == -EEXIST) 135 136 continue; 136 137 printk(KERN_INFO "RPC: Couldn't create pipefs entry" 137 - " %s/%s, error %ld\n", 138 - dir_name, name, PTR_ERR(dentry)); 138 + " %s/%s, error %d\n", 139 + dir_name, name, err); 139 140 break; 140 141 } 141 142 dput(dir); 142 - return dentry; 143 + return err; 143 144 } 144 145 145 146 static int 146 147 rpc_setup_pipedir(struct super_block *pipefs_sb, struct rpc_clnt *clnt) 147 148 { 148 - struct dentry *dentry; 149 - 150 149 clnt->pipefs_sb = pipefs_sb; 151 150 152 151 if (clnt->cl_program->pipe_dir_name != NULL) { 153 - dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt); 154 - if (IS_ERR(dentry)) 155 - return PTR_ERR(dentry); 152 + int err = rpc_setup_pipedir_sb(pipefs_sb, clnt); 153 + if (err && err != -ENOENT) 154 + return err; 156 155 } 157 156 return 0; 158 157 } ··· 179 180 static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event, 180 181 struct super_block *sb) 181 182 { 182 - struct dentry *dentry; 183 - 184 183 switch (event) { 185 184 case RPC_PIPEFS_MOUNT: 186 - dentry = rpc_setup_pipedir_sb(sb, clnt); 187 - if (!dentry) 188 - return -ENOENT; 189 - if (IS_ERR(dentry)) 190 - return PTR_ERR(dentry); 191 - break; 185 + return rpc_setup_pipedir_sb(sb, clnt); 192 186 case RPC_PIPEFS_UMOUNT: 193 187 __rpc_clnt_remove_pipedir(clnt); 194 188 break;
+141 -389
net/sunrpc/rpc_pipe.c
··· 168 168 } 169 169 170 170 static void 171 - rpc_close_pipes(struct inode *inode) 171 + rpc_close_pipes(struct dentry *dentry) 172 172 { 173 + struct inode *inode = dentry->d_inode; 173 174 struct rpc_pipe *pipe = RPC_I(inode)->pipe; 174 175 int need_release; 175 176 LIST_HEAD(free_list); ··· 485 484 return inode; 486 485 } 487 486 488 - static int __rpc_create_common(struct inode *dir, struct dentry *dentry, 489 - umode_t mode, 490 - const struct file_operations *i_fop, 491 - void *private) 492 - { 493 - struct inode *inode; 494 - 495 - d_drop(dentry); 496 - inode = rpc_get_inode(dir->i_sb, mode); 497 - if (!inode) 498 - goto out_err; 499 - inode->i_ino = iunique(dir->i_sb, 100); 500 - if (i_fop) 501 - inode->i_fop = i_fop; 502 - if (private) 503 - rpc_inode_setowner(inode, private); 504 - d_add(dentry, inode); 505 - return 0; 506 - out_err: 507 - printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %pd\n", 508 - __FILE__, __func__, dentry); 509 - dput(dentry); 510 - return -ENOMEM; 511 - } 512 - 513 - static int __rpc_create(struct inode *dir, struct dentry *dentry, 514 - umode_t mode, 515 - const struct file_operations *i_fop, 516 - void *private) 517 - { 518 - int err; 519 - 520 - err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private); 521 - if (err) 522 - return err; 523 - fsnotify_create(dir, dentry); 524 - return 0; 525 - } 526 - 527 - static int __rpc_mkdir(struct inode *dir, struct dentry *dentry, 528 - umode_t mode, 529 - const struct file_operations *i_fop, 530 - void *private) 531 - { 532 - int err; 533 - 534 - err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private); 535 - if (err) 536 - return err; 537 - inc_nlink(dir); 538 - fsnotify_mkdir(dir, dentry); 539 - return 0; 540 - } 541 - 542 487 static void 543 488 init_pipe(struct rpc_pipe *pipe) 544 489 { ··· 521 574 } 522 575 EXPORT_SYMBOL_GPL(rpc_mkpipe_data); 523 576 524 - static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, 525 - umode_t mode, 526 - const struct file_operations *i_fop, 527 - void *private, 528 - struct rpc_pipe *pipe) 577 + static int rpc_new_file(struct dentry *parent, 578 + const char *name, 579 + umode_t mode, 580 + const struct file_operations *i_fop, 581 + void *private) 529 582 { 530 - struct rpc_inode *rpci; 531 - int err; 583 + struct dentry *dentry = simple_start_creating(parent, name); 584 + struct inode *dir = parent->d_inode; 585 + struct inode *inode; 532 586 533 - err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private); 534 - if (err) 535 - return err; 536 - rpci = RPC_I(d_inode(dentry)); 537 - rpci->private = private; 538 - rpci->pipe = pipe; 587 + if (IS_ERR(dentry)) 588 + return PTR_ERR(dentry); 589 + 590 + inode = rpc_get_inode(dir->i_sb, S_IFREG | mode); 591 + if (unlikely(!inode)) { 592 + dput(dentry); 593 + inode_unlock(dir); 594 + return -ENOMEM; 595 + } 596 + inode->i_ino = iunique(dir->i_sb, 100); 597 + if (i_fop) 598 + inode->i_fop = i_fop; 599 + rpc_inode_setowner(inode, private); 600 + d_instantiate(dentry, inode); 539 601 fsnotify_create(dir, dentry); 602 + inode_unlock(dir); 540 603 return 0; 541 604 } 542 605 543 - static int __rpc_rmdir(struct inode *dir, struct dentry *dentry) 606 + static struct dentry *rpc_new_dir(struct dentry *parent, 607 + const char *name, 608 + umode_t mode) 544 609 { 545 - int ret; 610 + struct dentry *dentry = simple_start_creating(parent, name); 611 + struct inode *dir = parent->d_inode; 612 + struct inode *inode; 546 613 547 - dget(dentry); 548 - ret = simple_rmdir(dir, dentry); 549 - d_drop(dentry); 550 - if (!ret) 551 - fsnotify_rmdir(dir, dentry); 552 - dput(dentry); 553 - return ret; 554 - } 555 - 556 - static int __rpc_unlink(struct inode *dir, struct dentry *dentry) 557 - { 558 - int ret; 559 - 560 - dget(dentry); 561 - ret = simple_unlink(dir, dentry); 562 - d_drop(dentry); 563 - if (!ret) 564 - fsnotify_unlink(dir, dentry); 565 - dput(dentry); 566 - return ret; 567 - } 568 - 569 - static int __rpc_rmpipe(struct inode *dir, struct dentry *dentry) 570 - { 571 - struct inode *inode = d_inode(dentry); 572 - 573 - rpc_close_pipes(inode); 574 - return __rpc_unlink(dir, dentry); 575 - } 576 - 577 - static struct dentry *__rpc_lookup_create_exclusive(struct dentry *parent, 578 - const char *name) 579 - { 580 - struct qstr q = QSTR(name); 581 - struct dentry *dentry = try_lookup_noperm(&q, parent); 582 - if (!dentry) { 583 - dentry = d_alloc(parent, &q); 584 - if (!dentry) 585 - return ERR_PTR(-ENOMEM); 586 - } 587 - if (d_really_is_negative(dentry)) 614 + if (IS_ERR(dentry)) 588 615 return dentry; 589 - dput(dentry); 590 - return ERR_PTR(-EEXIST); 591 - } 592 616 593 - /* 594 - * FIXME: This probably has races. 595 - */ 596 - static void __rpc_depopulate(struct dentry *parent, 597 - const struct rpc_filelist *files, 598 - int start, int eof) 599 - { 600 - struct inode *dir = d_inode(parent); 601 - struct dentry *dentry; 602 - struct qstr name; 603 - int i; 604 - 605 - for (i = start; i < eof; i++) { 606 - name.name = files[i].name; 607 - name.len = strlen(files[i].name); 608 - dentry = try_lookup_noperm(&name, parent); 609 - 610 - if (dentry == NULL) 611 - continue; 612 - if (d_really_is_negative(dentry)) 613 - goto next; 614 - switch (d_inode(dentry)->i_mode & S_IFMT) { 615 - default: 616 - BUG(); 617 - case S_IFREG: 618 - __rpc_unlink(dir, dentry); 619 - break; 620 - case S_IFDIR: 621 - __rpc_rmdir(dir, dentry); 622 - } 623 - next: 617 + inode = rpc_get_inode(dir->i_sb, S_IFDIR | mode); 618 + if (unlikely(!inode)) { 624 619 dput(dentry); 620 + inode_unlock(dir); 621 + return ERR_PTR(-ENOMEM); 625 622 } 626 - } 627 623 628 - static void rpc_depopulate(struct dentry *parent, 629 - const struct rpc_filelist *files, 630 - int start, int eof) 631 - { 632 - struct inode *dir = d_inode(parent); 633 - 634 - inode_lock_nested(dir, I_MUTEX_CHILD); 635 - __rpc_depopulate(parent, files, start, eof); 624 + inode->i_ino = iunique(dir->i_sb, 100); 625 + inc_nlink(dir); 626 + d_instantiate(dentry, inode); 627 + fsnotify_mkdir(dir, dentry); 636 628 inode_unlock(dir); 629 + 630 + return dentry; 637 631 } 638 632 639 633 static int rpc_populate(struct dentry *parent, ··· 582 694 int start, int eof, 583 695 void *private) 584 696 { 585 - struct inode *dir = d_inode(parent); 586 697 struct dentry *dentry; 587 698 int i, err; 588 699 589 - inode_lock(dir); 590 700 for (i = start; i < eof; i++) { 591 - dentry = __rpc_lookup_create_exclusive(parent, files[i].name); 592 - err = PTR_ERR(dentry); 593 - if (IS_ERR(dentry)) 594 - goto out_bad; 595 701 switch (files[i].mode & S_IFMT) { 596 702 default: 597 703 BUG(); 598 704 case S_IFREG: 599 - err = __rpc_create(dir, dentry, 705 + err = rpc_new_file(parent, 706 + files[i].name, 600 707 files[i].mode, 601 708 files[i].i_fop, 602 709 private); 710 + if (err) 711 + goto out_bad; 603 712 break; 604 713 case S_IFDIR: 605 - err = __rpc_mkdir(dir, dentry, 606 - files[i].mode, 607 - NULL, 608 - private); 714 + dentry = rpc_new_dir(parent, 715 + files[i].name, 716 + files[i].mode); 717 + if (IS_ERR(dentry)) { 718 + err = PTR_ERR(dentry); 719 + goto out_bad; 720 + } 609 721 } 610 - if (err != 0) 611 - goto out_bad; 612 722 } 613 - inode_unlock(dir); 614 723 return 0; 615 724 out_bad: 616 - __rpc_depopulate(parent, files, start, eof); 617 - inode_unlock(dir); 618 725 printk(KERN_WARNING "%s: %s failed to populate directory %pd\n", 619 726 __FILE__, __func__, parent); 620 727 return err; 621 - } 622 - 623 - static struct dentry *rpc_mkdir_populate(struct dentry *parent, 624 - const char *name, umode_t mode, void *private, 625 - int (*populate)(struct dentry *, void *), void *args_populate) 626 - { 627 - struct dentry *dentry; 628 - struct inode *dir = d_inode(parent); 629 - int error; 630 - 631 - inode_lock_nested(dir, I_MUTEX_PARENT); 632 - dentry = __rpc_lookup_create_exclusive(parent, name); 633 - if (IS_ERR(dentry)) 634 - goto out; 635 - error = __rpc_mkdir(dir, dentry, mode, NULL, private); 636 - if (error != 0) 637 - goto out_err; 638 - if (populate != NULL) { 639 - error = populate(dentry, args_populate); 640 - if (error) 641 - goto err_rmdir; 642 - } 643 - out: 644 - inode_unlock(dir); 645 - return dentry; 646 - err_rmdir: 647 - __rpc_rmdir(dir, dentry); 648 - out_err: 649 - dentry = ERR_PTR(error); 650 - goto out; 651 - } 652 - 653 - static int rpc_rmdir_depopulate(struct dentry *dentry, 654 - void (*depopulate)(struct dentry *)) 655 - { 656 - struct dentry *parent; 657 - struct inode *dir; 658 - int error; 659 - 660 - parent = dget_parent(dentry); 661 - dir = d_inode(parent); 662 - inode_lock_nested(dir, I_MUTEX_PARENT); 663 - if (depopulate != NULL) 664 - depopulate(dentry); 665 - error = __rpc_rmdir(dir, dentry); 666 - inode_unlock(dir); 667 - dput(parent); 668 - return error; 669 728 } 670 729 671 730 /** ··· 634 799 * The @private argument passed here will be available to all these methods 635 800 * from the file pointer, via RPC_I(file_inode(file))->private. 636 801 */ 637 - struct dentry *rpc_mkpipe_dentry(struct dentry *parent, const char *name, 802 + int rpc_mkpipe_dentry(struct dentry *parent, const char *name, 638 803 void *private, struct rpc_pipe *pipe) 639 804 { 640 - struct dentry *dentry; 641 805 struct inode *dir = d_inode(parent); 806 + struct dentry *dentry; 807 + struct inode *inode; 808 + struct rpc_inode *rpci; 642 809 umode_t umode = S_IFIFO | 0600; 643 810 int err; 644 811 ··· 649 812 if (pipe->ops->downcall == NULL) 650 813 umode &= ~0222; 651 814 652 - inode_lock_nested(dir, I_MUTEX_PARENT); 653 - dentry = __rpc_lookup_create_exclusive(parent, name); 654 - if (IS_ERR(dentry)) 655 - goto out; 656 - err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops, 657 - private, pipe); 658 - if (err) 659 - goto out_err; 660 - out: 815 + dentry = simple_start_creating(parent, name); 816 + if (IS_ERR(dentry)) { 817 + err = PTR_ERR(dentry); 818 + goto failed; 819 + } 820 + 821 + inode = rpc_get_inode(dir->i_sb, umode); 822 + if (unlikely(!inode)) { 823 + dput(dentry); 824 + inode_unlock(dir); 825 + err = -ENOMEM; 826 + goto failed; 827 + } 828 + inode->i_ino = iunique(dir->i_sb, 100); 829 + inode->i_fop = &rpc_pipe_fops; 830 + rpci = RPC_I(inode); 831 + rpci->private = private; 832 + rpci->pipe = pipe; 833 + rpc_inode_setowner(inode, private); 834 + d_instantiate(dentry, inode); 835 + pipe->dentry = dentry; 836 + fsnotify_create(dir, dentry); 661 837 inode_unlock(dir); 662 - return dentry; 663 - out_err: 664 - dentry = ERR_PTR(err); 665 - printk(KERN_WARNING "%s: %s() failed to create pipe %pd/%s (errno = %d)\n", 666 - __FILE__, __func__, parent, name, 667 - err); 668 - goto out; 838 + return 0; 839 + 840 + failed: 841 + pr_warn("%s() failed to create pipe %pd/%s (errno = %d)\n", 842 + __func__, parent, name, err); 843 + return err; 669 844 } 670 845 EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry); 671 846 672 847 /** 673 848 * rpc_unlink - remove a pipe 674 - * @dentry: dentry for the pipe, as returned from rpc_mkpipe 849 + * @pipe: the pipe to be removed 675 850 * 676 851 * After this call, lookups will no longer find the pipe, and any 677 852 * attempts to read or write using preexisting opens of the pipe will 678 853 * return -EPIPE. 679 854 */ 680 - int 681 - rpc_unlink(struct dentry *dentry) 855 + void 856 + rpc_unlink(struct rpc_pipe *pipe) 682 857 { 683 - struct dentry *parent; 684 - struct inode *dir; 685 - int error = 0; 686 - 687 - parent = dget_parent(dentry); 688 - dir = d_inode(parent); 689 - inode_lock_nested(dir, I_MUTEX_PARENT); 690 - error = __rpc_rmpipe(dir, dentry); 691 - inode_unlock(dir); 692 - dput(parent); 693 - return error; 858 + if (pipe->dentry) { 859 + simple_recursive_removal(pipe->dentry, rpc_close_pipes); 860 + pipe->dentry = NULL; 861 + } 694 862 } 695 863 EXPORT_SYMBOL_GPL(rpc_unlink); 696 864 ··· 852 1010 pdo->pdo_ops->destroy(dir, pdo); 853 1011 } 854 1012 855 - enum { 856 - RPCAUTH_info, 857 - RPCAUTH_EOF 858 - }; 859 - 860 - static const struct rpc_filelist authfiles[] = { 861 - [RPCAUTH_info] = { 862 - .name = "info", 863 - .i_fop = &rpc_info_operations, 864 - .mode = S_IFREG | 0400, 865 - }, 866 - }; 867 - 868 - static int rpc_clntdir_populate(struct dentry *dentry, void *private) 869 - { 870 - return rpc_populate(dentry, 871 - authfiles, RPCAUTH_info, RPCAUTH_EOF, 872 - private); 873 - } 874 - 875 - static void rpc_clntdir_depopulate(struct dentry *dentry) 876 - { 877 - rpc_depopulate(dentry, authfiles, RPCAUTH_info, RPCAUTH_EOF); 878 - } 879 - 880 1013 /** 881 1014 * rpc_create_client_dir - Create a new rpc_client directory in rpc_pipefs 882 1015 * @dentry: the parent of new directory ··· 863 1046 * information about the client, together with any "pipes" that may 864 1047 * later be created using rpc_mkpipe(). 865 1048 */ 866 - struct dentry *rpc_create_client_dir(struct dentry *dentry, 867 - const char *name, 868 - struct rpc_clnt *rpc_client) 1049 + int rpc_create_client_dir(struct dentry *dentry, 1050 + const char *name, 1051 + struct rpc_clnt *rpc_client) 869 1052 { 870 1053 struct dentry *ret; 1054 + int err; 871 1055 872 - ret = rpc_mkdir_populate(dentry, name, 0555, NULL, 873 - rpc_clntdir_populate, rpc_client); 874 - if (!IS_ERR(ret)) { 875 - rpc_client->cl_pipedir_objects.pdh_dentry = ret; 876 - rpc_create_pipe_dir_objects(&rpc_client->cl_pipedir_objects); 1056 + ret = rpc_new_dir(dentry, name, 0555); 1057 + if (IS_ERR(ret)) 1058 + return PTR_ERR(ret); 1059 + err = rpc_new_file(ret, "info", S_IFREG | 0400, 1060 + &rpc_info_operations, rpc_client); 1061 + if (err) { 1062 + pr_warn("%s failed to populate directory %pd\n", 1063 + __func__, ret); 1064 + simple_recursive_removal(ret, NULL); 1065 + return err; 877 1066 } 878 - return ret; 1067 + rpc_client->cl_pipedir_objects.pdh_dentry = ret; 1068 + rpc_create_pipe_dir_objects(&rpc_client->cl_pipedir_objects); 1069 + return 0; 879 1070 } 880 1071 881 1072 /** ··· 898 1073 return 0; 899 1074 rpc_destroy_pipe_dir_objects(&rpc_client->cl_pipedir_objects); 900 1075 rpc_client->cl_pipedir_objects.pdh_dentry = NULL; 901 - return rpc_rmdir_depopulate(dentry, rpc_clntdir_depopulate); 1076 + simple_recursive_removal(dentry, NULL); 1077 + return 0; 902 1078 } 903 1079 904 1080 static const struct rpc_filelist cache_pipefs_files[3] = { ··· 920 1094 }, 921 1095 }; 922 1096 923 - static int rpc_cachedir_populate(struct dentry *dentry, void *private) 924 - { 925 - return rpc_populate(dentry, 926 - cache_pipefs_files, 0, 3, 927 - private); 928 - } 929 - 930 - static void rpc_cachedir_depopulate(struct dentry *dentry) 931 - { 932 - rpc_depopulate(dentry, cache_pipefs_files, 0, 3); 933 - } 934 - 935 1097 struct dentry *rpc_create_cache_dir(struct dentry *parent, const char *name, 936 1098 umode_t umode, struct cache_detail *cd) 937 1099 { 938 - return rpc_mkdir_populate(parent, name, umode, NULL, 939 - rpc_cachedir_populate, cd); 1100 + struct dentry *dentry; 1101 + 1102 + dentry = rpc_new_dir(parent, name, umode); 1103 + if (!IS_ERR(dentry)) { 1104 + int error = rpc_populate(dentry, cache_pipefs_files, 0, 3, cd); 1105 + if (error) { 1106 + simple_recursive_removal(dentry, NULL); 1107 + return ERR_PTR(error); 1108 + } 1109 + } 1110 + return dentry; 940 1111 } 941 1112 942 1113 void rpc_remove_cache_dir(struct dentry *dentry) 943 1114 { 944 - rpc_rmdir_depopulate(dentry, rpc_cachedir_depopulate); 1115 + simple_recursive_removal(dentry, NULL); 945 1116 } 946 1117 947 1118 /* ··· 964 1141 RPCAUTH_nfsd4_cb, 965 1142 RPCAUTH_cache, 966 1143 RPCAUTH_nfsd, 967 - RPCAUTH_gssd, 968 1144 RPCAUTH_RootEOF 969 1145 }; 970 1146 ··· 998 1176 }, 999 1177 [RPCAUTH_nfsd] = { 1000 1178 .name = "nfsd", 1001 - .mode = S_IFDIR | 0555, 1002 - }, 1003 - [RPCAUTH_gssd] = { 1004 - .name = "gssd", 1005 1179 .mode = S_IFDIR | 0555, 1006 1180 }, 1007 1181 }; ··· 1059 1241 } 1060 1242 EXPORT_SYMBOL_GPL(rpc_put_sb_net); 1061 1243 1062 - static const struct rpc_filelist gssd_dummy_clnt_dir[] = { 1063 - [0] = { 1064 - .name = "clntXX", 1065 - .mode = S_IFDIR | 0555, 1066 - }, 1067 - }; 1068 - 1069 1244 static ssize_t 1070 1245 dummy_downcall(struct file *filp, const char __user *src, size_t len) 1071 1246 { ··· 1087 1276 } 1088 1277 DEFINE_SHOW_ATTRIBUTE(rpc_dummy_info); 1089 1278 1090 - static const struct rpc_filelist gssd_dummy_info_file[] = { 1091 - [0] = { 1092 - .name = "info", 1093 - .i_fop = &rpc_dummy_info_fops, 1094 - .mode = S_IFREG | 0400, 1095 - }, 1096 - }; 1097 - 1098 1279 /** 1099 1280 * rpc_gssd_dummy_populate - create a dummy gssd pipe 1100 1281 * @root: root of the rpc_pipefs filesystem ··· 1095 1292 * Create a dummy set of directories and a pipe that gssd can hold open to 1096 1293 * indicate that it is up and running. 1097 1294 */ 1098 - static struct dentry * 1295 + static int 1099 1296 rpc_gssd_dummy_populate(struct dentry *root, struct rpc_pipe *pipe_data) 1100 1297 { 1101 - int ret = 0; 1102 - struct dentry *gssd_dentry; 1103 - struct dentry *clnt_dentry = NULL; 1104 - struct dentry *pipe_dentry = NULL; 1298 + struct dentry *gssd_dentry, *clnt_dentry; 1299 + int err; 1105 1300 1106 - /* We should never get this far if "gssd" doesn't exist */ 1107 - gssd_dentry = try_lookup_noperm(&QSTR(files[RPCAUTH_gssd].name), root); 1108 - if (!gssd_dentry) 1109 - return ERR_PTR(-ENOENT); 1301 + gssd_dentry = rpc_new_dir(root, "gssd", 0555); 1302 + if (IS_ERR(gssd_dentry)) 1303 + return -ENOENT; 1110 1304 1111 - ret = rpc_populate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1, NULL); 1112 - if (ret) { 1113 - pipe_dentry = ERR_PTR(ret); 1114 - goto out; 1115 - } 1305 + clnt_dentry = rpc_new_dir(gssd_dentry, "clntXX", 0555); 1306 + if (IS_ERR(clnt_dentry)) 1307 + return -ENOENT; 1116 1308 1117 - clnt_dentry = try_lookup_noperm(&QSTR(gssd_dummy_clnt_dir[0].name), 1118 - gssd_dentry); 1119 - if (!clnt_dentry) { 1120 - __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1); 1121 - pipe_dentry = ERR_PTR(-ENOENT); 1122 - goto out; 1123 - } 1124 - 1125 - ret = rpc_populate(clnt_dentry, gssd_dummy_info_file, 0, 1, NULL); 1126 - if (ret) { 1127 - __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1); 1128 - pipe_dentry = ERR_PTR(ret); 1129 - goto out; 1130 - } 1131 - 1132 - pipe_dentry = rpc_mkpipe_dentry(clnt_dentry, "gssd", NULL, pipe_data); 1133 - if (IS_ERR(pipe_dentry)) { 1134 - __rpc_depopulate(clnt_dentry, gssd_dummy_info_file, 0, 1); 1135 - __rpc_depopulate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1); 1136 - } 1137 - out: 1138 - dput(clnt_dentry); 1139 - dput(gssd_dentry); 1140 - return pipe_dentry; 1141 - } 1142 - 1143 - static void 1144 - rpc_gssd_dummy_depopulate(struct dentry *pipe_dentry) 1145 - { 1146 - struct dentry *clnt_dir = pipe_dentry->d_parent; 1147 - struct dentry *gssd_dir = clnt_dir->d_parent; 1148 - 1149 - dget(pipe_dentry); 1150 - __rpc_rmpipe(d_inode(clnt_dir), pipe_dentry); 1151 - __rpc_depopulate(clnt_dir, gssd_dummy_info_file, 0, 1); 1152 - __rpc_depopulate(gssd_dir, gssd_dummy_clnt_dir, 0, 1); 1153 - dput(pipe_dentry); 1309 + err = rpc_new_file(clnt_dentry, "info", 0400, 1310 + &rpc_dummy_info_fops, NULL); 1311 + if (!err) 1312 + err = rpc_mkpipe_dentry(clnt_dentry, "gssd", NULL, pipe_data); 1313 + return err; 1154 1314 } 1155 1315 1156 1316 static int 1157 1317 rpc_fill_super(struct super_block *sb, struct fs_context *fc) 1158 1318 { 1159 1319 struct inode *inode; 1160 - struct dentry *root, *gssd_dentry; 1320 + struct dentry *root; 1161 1321 struct net *net = sb->s_fs_info; 1162 1322 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id); 1163 1323 int err; ··· 1139 1373 if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL)) 1140 1374 return -ENOMEM; 1141 1375 1142 - gssd_dentry = rpc_gssd_dummy_populate(root, sn->gssd_dummy); 1143 - if (IS_ERR(gssd_dentry)) { 1144 - __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF); 1145 - return PTR_ERR(gssd_dentry); 1146 - } 1376 + err = rpc_gssd_dummy_populate(root, sn->gssd_dummy); 1377 + if (err) 1378 + return err; 1147 1379 1148 1380 dprintk("RPC: sending pipefs MOUNT notification for net %x%s\n", 1149 1381 net->ns.inum, NET_NAME(net)); ··· 1150 1386 err = blocking_notifier_call_chain(&rpc_pipefs_notifier_list, 1151 1387 RPC_PIPEFS_MOUNT, 1152 1388 sb); 1153 - if (err) 1154 - goto err_depopulate; 1155 - mutex_unlock(&sn->pipefs_sb_lock); 1156 - return 0; 1157 - 1158 - err_depopulate: 1159 - rpc_gssd_dummy_depopulate(gssd_dentry); 1160 - blocking_notifier_call_chain(&rpc_pipefs_notifier_list, 1161 - RPC_PIPEFS_UMOUNT, 1162 - sb); 1163 - sn->pipefs_sb = NULL; 1164 - __rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF); 1165 1389 mutex_unlock(&sn->pipefs_sb_lock); 1166 1390 return err; 1167 1391 }