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.

rpc_pipe: saner primitive for creating subdirectories

All users of __rpc_mkdir() have the same form - start_creating(),
followed, in case of success, by __rpc_mkdir() and unlocking parent.

Combine that into a single helper, expanding __rpc_mkdir() into it,
along with the call of __rpc_create_common() in it.

Don't mess with d_drop() + d_add() - just d_instantiate() and be
done with that. The reason __rpc_create_common() goes for that
dance is that dentry it gets might or might not be hashed; here
we know it's hashed.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro fc1abdca 41a6b9e5

+39 -28
+39 -28
net/sunrpc/rpc_pipe.c
··· 524 524 return 0; 525 525 } 526 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 527 static void 543 528 init_pipe(struct rpc_pipe *pipe) 544 529 { ··· 579 594 return 0; 580 595 } 581 596 597 + static struct dentry *rpc_new_dir(struct dentry *parent, 598 + const char *name, 599 + umode_t mode, 600 + void *private) 601 + { 602 + struct dentry *dentry = simple_start_creating(parent, name); 603 + struct inode *dir = parent->d_inode; 604 + struct inode *inode; 605 + 606 + if (IS_ERR(dentry)) 607 + return dentry; 608 + 609 + inode = rpc_get_inode(dir->i_sb, S_IFDIR | mode); 610 + if (unlikely(!inode)) { 611 + dput(dentry); 612 + inode_unlock(dir); 613 + return ERR_PTR(-ENOMEM); 614 + } 615 + 616 + inode->i_ino = iunique(dir->i_sb, 100); 617 + rpc_inode_setowner(inode, private); 618 + inc_nlink(dir); 619 + d_instantiate(dentry, inode); 620 + fsnotify_mkdir(dir, dentry); 621 + inode_unlock(dir); 622 + 623 + return dentry; 624 + } 625 + 582 626 static int rpc_populate(struct dentry *parent, 583 627 const struct rpc_filelist *files, 584 628 int start, int eof, ··· 618 604 int i, err; 619 605 620 606 for (i = start; i < eof; i++) { 621 - dentry = simple_start_creating(parent, files[i].name); 622 - err = PTR_ERR(dentry); 623 - if (IS_ERR(dentry)) 624 - goto out_bad; 625 607 switch (files[i].mode & S_IFMT) { 626 608 default: 627 609 BUG(); 628 610 case S_IFREG: 611 + dentry = simple_start_creating(parent, files[i].name); 612 + err = PTR_ERR(dentry); 613 + if (IS_ERR(dentry)) 614 + goto out_bad; 629 615 err = __rpc_create(dir, dentry, 630 616 files[i].mode, 631 617 files[i].i_fop, ··· 633 619 inode_unlock(dir); 634 620 break; 635 621 case S_IFDIR: 636 - err = __rpc_mkdir(dir, dentry, 622 + dentry = rpc_new_dir(parent, 623 + files[i].name, 637 624 files[i].mode, 638 - NULL, 639 625 private); 640 - inode_unlock(dir); 626 + err = PTR_ERR(dentry); 627 + if (IS_ERR(dentry)) 628 + goto out_bad; 641 629 } 642 630 if (err != 0) 643 631 goto out_bad; ··· 656 640 int (*populate)(struct dentry *, void *), void *args_populate) 657 641 { 658 642 struct dentry *dentry; 659 - struct inode *dir = d_inode(parent); 660 643 int error; 661 644 662 - dentry = simple_start_creating(parent, name); 645 + dentry = rpc_new_dir(parent, name, mode, private); 663 646 if (IS_ERR(dentry)) 664 647 return dentry; 665 - error = __rpc_mkdir(dir, dentry, mode, NULL, private); 666 - inode_unlock(dir); 667 - if (error != 0) 668 - return ERR_PTR(error); 669 648 if (populate != NULL) { 670 649 error = populate(dentry, args_populate); 671 650 if (error) {