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.

fs: make unlazy_walk() error handling consistent

Most callers check for non-zero return, and assume it's -ECHILD (which
it always will be). One caller uses the actual error return. Clean this
up and make it fully consistent, by having unlazy_walk() return a bool
instead. Rename it to try_to_unlazy() and return true on success, and
failure on error. That's easier to read.

No functional changes in this patch.

Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Jens Axboe and committed by
Al Viro
e36cffed 26ddb45e

+17 -26
+17 -26
fs/namei.c
··· 669 669 */ 670 670 671 671 /** 672 - * unlazy_walk - try to switch to ref-walk mode. 672 + * try_to_unlazy - try to switch to ref-walk mode. 673 673 * @nd: nameidata pathwalk data 674 - * Returns: 0 on success, -ECHILD on failure 674 + * Returns: true on success, false on failure 675 675 * 676 - * unlazy_walk attempts to legitimize the current nd->path and nd->root 676 + * try_to_unlazy attempts to legitimize the current nd->path and nd->root 677 677 * for ref-walk mode. 678 678 * Must be called from rcu-walk context. 679 - * Nothing should touch nameidata between unlazy_walk() failure and 679 + * Nothing should touch nameidata between try_to_unlazy() failure and 680 680 * terminate_walk(). 681 681 */ 682 - static int unlazy_walk(struct nameidata *nd) 682 + static bool try_to_unlazy(struct nameidata *nd) 683 683 { 684 684 struct dentry *parent = nd->path.dentry; 685 685 ··· 694 694 goto out; 695 695 rcu_read_unlock(); 696 696 BUG_ON(nd->inode != parent->d_inode); 697 - return 0; 697 + return true; 698 698 699 699 out1: 700 700 nd->path.mnt = NULL; 701 701 nd->path.dentry = NULL; 702 702 out: 703 703 rcu_read_unlock(); 704 - return -ECHILD; 704 + return false; 705 705 } 706 706 707 707 /** ··· 792 792 */ 793 793 if (!(nd->flags & (LOOKUP_ROOT | LOOKUP_IS_SCOPED))) 794 794 nd->root.mnt = NULL; 795 - if (unlikely(unlazy_walk(nd))) 795 + if (!try_to_unlazy(nd)) 796 796 return -ECHILD; 797 797 } 798 798 ··· 1466 1466 unsigned seq; 1467 1467 dentry = __d_lookup_rcu(parent, &nd->last, &seq); 1468 1468 if (unlikely(!dentry)) { 1469 - if (unlazy_walk(nd)) 1469 + if (!try_to_unlazy(nd)) 1470 1470 return ERR_PTR(-ECHILD); 1471 1471 return NULL; 1472 1472 } ··· 1567 1567 { 1568 1568 if (nd->flags & LOOKUP_RCU) { 1569 1569 int err = inode_permission(nd->inode, MAY_EXEC|MAY_NOT_BLOCK); 1570 - if (err != -ECHILD) 1570 + if (err != -ECHILD || !try_to_unlazy(nd)) 1571 1571 return err; 1572 - if (unlazy_walk(nd)) 1573 - return -ECHILD; 1574 1572 } 1575 1573 return inode_permission(nd->inode, MAY_EXEC); 1576 1574 } ··· 1590 1592 // unlazy even if we fail to grab the link - cleanup needs it 1591 1593 bool grabbed_link = legitimize_path(nd, link, seq); 1592 1594 1593 - if (unlazy_walk(nd) != 0 || !grabbed_link) 1595 + if (!try_to_unlazy(nd) != 0 || !grabbed_link) 1594 1596 return -ECHILD; 1595 1597 1596 1598 if (nd_alloc_stack(nd)) ··· 1632 1634 touch_atime(&last->link); 1633 1635 cond_resched(); 1634 1636 } else if (atime_needs_update(&last->link, inode)) { 1635 - if (unlikely(unlazy_walk(nd))) 1637 + if (!try_to_unlazy(nd)) 1636 1638 return ERR_PTR(-ECHILD); 1637 1639 touch_atime(&last->link); 1638 1640 } ··· 1649 1651 get = inode->i_op->get_link; 1650 1652 if (nd->flags & LOOKUP_RCU) { 1651 1653 res = get(NULL, inode, &last->done); 1652 - if (res == ERR_PTR(-ECHILD)) { 1653 - if (unlikely(unlazy_walk(nd))) 1654 - return ERR_PTR(-ECHILD); 1654 + if (res == ERR_PTR(-ECHILD) && try_to_unlazy(nd)) 1655 1655 res = get(link->dentry, inode, &last->done); 1656 - } 1657 1656 } else { 1658 1657 res = get(link->dentry, inode, &last->done); 1659 1658 } ··· 2190 2195 } 2191 2196 if (unlikely(!d_can_lookup(nd->path.dentry))) { 2192 2197 if (nd->flags & LOOKUP_RCU) { 2193 - if (unlazy_walk(nd)) 2198 + if (!try_to_unlazy(nd)) 2194 2199 return -ECHILD; 2195 2200 } 2196 2201 return -ENOTDIR; ··· 3124 3129 struct inode *inode; 3125 3130 struct dentry *dentry; 3126 3131 const char *res; 3127 - int error; 3128 3132 3129 3133 nd->flags |= op->intent; 3130 3134 ··· 3147 3153 } else { 3148 3154 /* create side of things */ 3149 3155 if (nd->flags & LOOKUP_RCU) { 3150 - error = unlazy_walk(nd); 3151 - if (unlikely(error)) 3152 - return ERR_PTR(error); 3156 + if (!try_to_unlazy(nd)) 3157 + return ERR_PTR(-ECHILD); 3153 3158 } 3154 3159 audit_inode(nd->name, dir, AUDIT_INODE_PARENT); 3155 3160 /* trailing slashes? */ ··· 3157 3164 } 3158 3165 3159 3166 if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) { 3160 - error = mnt_want_write(nd->path.mnt); 3161 - if (!error) 3162 - got_write = true; 3167 + got_write = !mnt_want_write(nd->path.mnt); 3163 3168 /* 3164 3169 * do _not_ fail yet - we might not need that or fail with 3165 3170 * a different error; let lookup_open() decide; we'll be