non-recursive pathname resolution
Subsystems (29)
Al Viro
maintainerRFC PATCH 1/1 non-recursive pathname resolution
My apologies for the patchbomb from hell, but I really think
it needs a public review.
There are several things in that queue; most of it is fs/namei.c
rewrite and closer to the end we get
* non-recursive link_path_walk()
* the only symlink-related limitation is that there should be no
more than 40 symlinks traversals, no matter how nested they are.
* stack footprint independent from the nesting and about on par with
mainline in "no symlinks" case.
* some work towards the symlink traversal without dropping from
RCU mode; not complete, but much better starting point than the current mainline.
* IMO more readable logics around the pathname resolution in
general, but then I'd spent the last couple of weeks messing with that code, so my perception might be seriously warped.
Most of that stuff is mine, with exception of 3 commits from
Neil's series (with some modifications). I've marked those with [N] in the list below.
It really needs review and more testing; it *does* pass xfstests,
LTP and local tests with no regressions, but at the very least it'll need careful profiling, as well as more eyes to read it through. The whole thing is based at -rc1. Individual patches are in followups; those who prefer to access it via git can fetch it at git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git link_path_walk
Please, read and comment.
Roadmap:
* assorted preliminary patches:
[1/79] 9p: don't bother with 4K allocation for 24-byte local array... [2/79] 9p: don't bother with __getname() in ->follow_link() [3/79][N] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link [4/79] ext4: split inode_operations for encrypted symlinks off the rest
* getting rid of boilerplate for inline symlinks
[5/79] libfs: simple_follow_link()
[6/79] ext2: use simple_follow_link()
[7/79] befs: switch to simple_follow_link()
[8/79] ext3: switch to simple_follow_link()
[9/79] ext4: switch to simple_follow_link()
[10/79] jffs2: switch to simple_follow_link()
[11/79] shmem: switch to simple_follow_link()
[12/79] debugfs: switch to simple_follow_link() [13/79] ufs: switch to simple_follow_link()
[14/79] ubifs: switch to simple_follow_link()
[15/79] sysv: switch to simple_follow_link()
[16/79] jfs: switch to simple_follow_link()
[17/79] freevxfs: switch to simple_follow_link() [18/79] exofs: switch to {simple,page}_symlink_inode_operations [19/79] ceph: switch to simple_follow_link()
* more assorted preparations:
[20/79] logfs: fix a pagecache leak for symlinks [21/79][N] SECURITY: remove nameidata arg from inode_follow_link. [22/79] uninline walk_component()
* getting trailing symlinks handling in do_last() into saner shape:
[23/79] namei: take O_NOFOLLOW treatment into do_last() [24/79] do_last: kill symlink_ok
[25/79] do_last: regularize the logics around following symlinks
* getting rid of nameidata on stack during ->rmdir()/->unlink() and double nameidata during ->rename():
[26/79] namei: get rid of lookup_hash()
[27/79] name: shift nameidata down into user_path_walk()
* single instance of nameidata across the adjacent path_mountpoint() calls:
[28/79] namei: lift nameidata into filename_mountpoint()
At that point preparations end. The next one changes the calling conventions for ->follow_link/->put_link. We still are passing nameidata to ->follow_link(), but almost all instances do not use it anymore. Moreover, nd->saved_names[] is gone and so's nameidata in generic_readlink(). That one has the biggest footprint outside of fs/namei.c - it's a flagday change.
[29/79] new ->follow_link() and ->put_link() calling conventions
* some preparations for link_path_walk() massage:
[30/79] namei.c: separate the parts of follow_link() that find the link body [31/79] namei: don't bother with ->follow_link() if ->i_link is set [32/79] namei: introduce nameidata->link
[33/79] do_last: move path there from caller's stack frame
* link_path_walk()/follow_link() rewrite. It's done in small steps, getting the damn thing into form that would allow to get rid of recursion:
[34/79] namei: expand nested_symlink() in its only caller
[35/79] namei: expand the call of follow_link() in link_path_walk() [36/79] namei: move the calls of may_follow_link() into follow_link() [37/79] namei: rename follow_link to trailing_symlink, move it down [38/79] link_path_walk: handle get_link() returning ERR_PTR() immediately [39/79] link_path_walk: don't bother with walk_component() after jumping link [40/79] link_path_walk: turn inner loop into explicit goto [41/79] link_path_walk: massage a bit more
[42/79] link_path_walk: get rid of duplication
[43/79] link_path_walk: final preparations to killing recursion
* dumb and staightforward "put all variables we needed to be separate in each frame into an array of structs" killing of recursion. Array is still on stack frame of link_path_walk(), we are still with the same depth limits,
etc. All of that will change shortly afterwards.
[44/79] link_path_walk: kill the recursion
* post-operation cleanup:
[45/79] link_path_walk: split "return from recursive call" path [46/79] link_path_walk: cleanup - turn goto start; into continue;
* array moves into nameidata, with extra (0th) element used instead of link/cookie pairs of local variables we used to have in trailing symlink loops:
[47/79] namei: move link/cookie pairs into nameidata
* more post-op cleanup - arguments of several functions are always the fields of the same array element or pointers to such:
[48/79] namei: trim redundant arguments of trailing_symlink() [49/79] namei: trim redundant arguments of fs/namei.c:put_link() [50/79] namei: trim the arguments of get_link()
* trim the array in nameidata to a couple of elements, use it until we need more and allocate a big (41-element) array when needed. Result:
no more nesting limitations.
[51/79] namei: remove restrictions on nesting depth
* the use of array is seriously counterintuitive - for everything except the last component we are _not_ using the first element of array; moreover, way too many places are manipulating nd->depth. I've tried to sanitize all of that in one patch, but after several failures I ended up splitting the massage into smaller steps. The composition of those has ended up fairly small, but convincing yourself that it's correct will mean reporoducing this splitup ;-/
[52/79] link_path_walk: nd->depth massage, part 1
[53/79] link_path_walk: nd->depth massage, part 2
[54/79] link_path_walk: nd->depth massage, part 3
[55/79] link_path_walk: nd->depth massage, part 4
[56/79] trailing_symlink: nd->depth massage, part 5
[57/79] get_link: nd->depth massage, part 6
[58/79] trailing_symlink: nd->depth massage, part 7
[59/79] put_link: nd->depth massage, part 8
[60/79] link_path_walk: nd->depth massage, part 9
[61/79] link_path_walk: nd->depth massage, part 10
[62/79] link_path_walk: end of nd->depth massage
[63/79] namei: we never need more than MAXSYMLINKS entries in nd->stack
* getting more regular rules for calling terminate_walk()/put_link(). The reason for that part is (besides getting simpler logics in the end) that with RCU-symlink series we'll really need to have terminate_walk() trigger put_link() on everything we have on stack:
[64/79] namei: lift (open-coded) terminate_walk() in follow_dotdot_rcu() into callers
[65/79] lift terminate_walk() into callers of walk_component() [66/79] namei: lift (open-coded) terminate_walk() into callers of get_link() [67/79] namei: take put_link() into {lookup,mountpoint,do}_last() [68/79] namei: have terminate_walk() do put_link() on everything left [69/79] link_path_walk: move the OK: inside the loop
* more put_link() work - basically, we are consolidating the "we decide that we'd found a symlink that needs to be followed" logics. Again, that's one of the areas RCU-symlink will need to modify:
[70/79] namei: new calling conventions for walk_component() [71/79] namei: make should_follow_link() store the link in nd->link [72/79] namei: move link count check and stack allocation into pick_link()
At that point the parts of the core work I consider reasonably stable are over. Next 4 commits are about not passing nameidata to ->follow_link() - it's the same situation as with pt_regs and IRQ handlers and the same kind of solution. Only 2 instances out of 26 use nameidata at all, and only to pass it to nd_jump_link(); seeing that we already have the "begin using this nameidata instance/end using it" pairs bracketing the areas where thread works with given instance (we need that for sane freeing of on-demand allocated nd->stack), the solution is obvious...
[73/79] lustre: rip the private symlink nesting limit out [74/79][N] VFS: replace {, total_}link_count in task_struct with pointer to nameidata
[75/79] namei: simplify the callers of follow_managed()
[76/79] don't pass nameidata to ->follow_link()
The rest is very preliminary bits and pieces for RCU-symlink; it's almost certainly going to be replaced and can be pretty much ignored for now:
[77/79] namei: move unlazying on symlinks towards get_link() call sites [78/79] namei: new helper - is_stale()
[79/79] namei: stretch RCU mode into get_link()
Al Viro
maintainerPATCH 1/79 9p: don't bother with 4K allocation for 24-byte local array...
From: Al Viro <[email protected]>
--- fs/9p/vfs_inode.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
fs/9p/vfs_inode.c +5 -21
@@ -1370,6 +1370,8 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)return v9fs_vfs_mkspecial (dir, dentry,P9_DMSYMLINK , symname); } +#define U32_MAX_DIGITS 10 +/** * v9fs_vfs_link - create a hardlink * @old_dentry: dentry for file to link to
@@ -1383,7 +1385,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) {int retval; -char *name; +char name[1 +U32_MAX_DIGITS +2 ];/* sign + number + \n + \0 */ struct p9_fid *oldfid; p9_debug(P9_DEBUG_VFS, " %lu,%pd,%pd\n",
@@ -1393,20 +1395,12 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,if (IS_ERR (oldfid))return PTR_ERR (oldfid); - name =__getname (); -if (unlikely (!name)) { - retval = -ENOMEM ; - goto clunk_fid; - } -sprintf (name,"%d\n" , oldfid->fid); retval =v9fs_vfs_mkspecial (dir, dentry,P9_DMLINK , name); -__putname (name);if (!retval) {v9fs_refresh_inode (oldfid,d_inode (old_dentry));v9fs_invalidate_inode_attr (dir); } -clunk_fid:p9_client_clunk (oldfid);return retval; }
@@ -1425,7 +1419,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rde {struct v9fs_session_info *v9ses =v9fs_inode2v9ses (dir);int retval; -char *name; +char name[2 +U32_MAX_DIGITS +1 +U32_MAX_DIGITS +1 ];u32 perm; p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
@@ -1435,26 +1429,16 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdeif (!new_valid_dev (rdev))return -EINVAL ; - name =__getname (); -if (!name) -return -ENOMEM ;/* build extension */ if (S_ISBLK (mode))sprintf (name,"b %u %u" ,MAJOR (rdev),MINOR (rdev));else if (S_ISCHR (mode))sprintf (name,"c %u %u" ,MAJOR (rdev),MINOR (rdev)); -else if (S_ISFIFO (mode)) - *name =0 ; -else if (S_ISSOCK (mode)) +else *name =0 ; -else { -__putname (name); -return -EINVAL ; - } perm =unixmode2p9mode (v9ses, mode); retval =v9fs_vfs_mkspecial (dir, dentry, perm, name); -__putname (name);return retval; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 2/79 9p: don't bother with __getname() in ->follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
We copy there a kmalloc'ed string and proceed to kfree that string immediately after that. Easier to just feed that string to nd_set_link() and _not_ kfree it until ->put_link() (which becomes kfree_put_link() in that case).
--- fs/9p/v9fs.h | 2 -- fs/9p/vfs_inode.c | 93 ++++++++++---------------------------------------- fs/9p/vfs_inode_dotl.c | 31 +++++------------ 3 files changed, 26 insertions(+), 100 deletions(-)
fs/9p/v9fs.h +0 -2
@@ -149,8 +149,6 @@ extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);extern int v9fs_vfs_rmdir (struct inode *i,struct dentry *d);extern int v9fs_vfs_rename (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry); -extern void v9fs_vfs_put_link (struct dentry *dentry,struct nameidata *nd, -void *p);extern struct inode *v9fs_inode_from_fid (struct v9fs_session_info *v9ses,struct p9_fid *fid,struct super_block *sb,int new);
fs/9p/vfs_inode.c +18 -75
128 lines not on this page · raw message
fs/9p/vfs_inode_dotl.c +8 -23
@@ -912,33 +912,18 @@ error:static void *v9fs_vfs_follow_link_dotl (struct dentry *dentry,struct nameidata *nd) { -int retval; -struct p9_fid *fid; -char *link =__getname (); +struct p9_fid *fid =v9fs_fid_lookup (dentry);char *target; +int retval;p9_debug (P9_DEBUG_VFS ,"%pd\n" , dentry); -if (!link) { - link =ERR_PTR (-ENOMEM ); - goto ndset; - } - fid =v9fs_fid_lookup (dentry); -if (IS_ERR (fid)) { -__putname (link); - link =ERR_CAST (fid); - goto ndset; - } +if (IS_ERR (fid)) +return ERR_CAST (fid); retval =p9_client_readlink (fid, &target); -if (!retval) { -strcpy (link, target); -kfree (target); - goto ndset; - } -__putname (link); - link =ERR_PTR (retval); -ndset: -nd_set_link (nd, link); +if (retval) +return ERR_PTR (retval); +nd_set_link (nd, target);return NULL ; }
@@ -1006,7 +991,7 @@ const struct inode_operations v9fs_file_inode_operations_dotl = {const struct inode_operations v9fs_symlink_inode_operations_dotl = { .readlink = generic_readlink, .follow_link = v9fs_vfs_follow_link_dotl, - .put_link = v9fs_vfs_put_link, + .put_link = kfree_put_link, .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 3/79 ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
In reply to Al ViroFrom: NeilBrown <[email protected]>
ovl_follow_link current calls ->put_link on an error path. However ->put_link is about to change in a way that it will be impossible to call it from ovl_follow_link.
So rearrange the code to avoid the need for that error path.
Specifically: move the kmalloc() call before the ->follow_link() call to the subordinate filesystem.
--- fs/overlayfs/inode.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
fs/overlayfs/inode.c +12 -13
@@ -145,6 +145,7 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)void *ret;struct dentry *realdentry;struct inode *realinode; +struct ovl_link_data *data =NULL ; realdentry =ovl_dentry_real (dentry); realinode = realdentry->d_inode;
@@ -152,25 +153,23 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)if (WARN_ON (!realinode->i_op->follow_link))return ERR_PTR (-EPERM ); - ret = realinode->i_op->follow_link (realdentry, nd); -if (IS_ERR (ret)) -return ret; -if (realinode->i_op->put_link) { -struct ovl_link_data *data; - data =kmalloc (sizeof (struct ovl_link_data ),GFP_KERNEL ); -if (!data) { - realinode->i_op->put_link (realdentry, nd, ret); +if (!data)return ERR_PTR (-ENOMEM ); - } data->realdentry = realdentry; - data->cookie = ret; + } -return data; - }else { -return NULL ; + ret = realinode->i_op->follow_link (realdentry, nd); +if (IS_ERR (ret)) { +kfree (data); +return ret; } + +if (data) + data->cookie = ret; + +return data; }static void ovl_put_link (struct dentry *dentry,struct nameidata *nd,void *c)
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 4/79 ext4: split inode_operations for encrypted symlinks off the rest
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 10 ++++++++-- fs/ext4/namei.c | 9 +++++---- fs/ext4/symlink.c | 30 ++++++++++-------------------- 4 files changed, 24 insertions(+), 26 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -2849,6 +2849,7 @@ extern int ext4_mpage_readpages(struct address_space *mapping, unsigned nr_pages);/* symlink.c */ +extern const struct inode_operations ext4_encrypted_symlink_inode_operations;extern const struct inode_operations ext4_symlink_inode_operations;extern const struct inode_operations ext4_fast_symlink_inode_operations;
fs/ext4/inode.c +8 -2
@@ -4211,8 +4211,14 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext4_dir_inode_operations; inode->i_fop = &ext4_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (ext4_inode_is_fast_symlink (inode) && - !ext4_encrypted_inode (inode)) { +if (ext4_encrypted_inode (inode)) { +#ifdef CONFIG_EXT4_FS_ENCRYPTION + inode->i_op = &ext4_encrypted_symlink_inode_operations; +ext4_set_aops (inode); +#else +BUILD_BUG (); +#endif + }else if (ext4_inode_is_fast_symlink (inode)) { inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext4/namei.c +5 -4
@@ -3266,10 +3266,12 @@ static int ext4_symlink(struct inode *dir, goto err_drop_inode; sd->len =cpu_to_le16 (ostr.len); disk_link.name = (char *) sd; + inode->i_op = &ext4_encrypted_symlink_inode_operations; }if ((disk_link.len >EXT4_N_BLOCKS *4 )) { - inode->i_op = &ext4_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_symlink_inode_operations;ext4_set_aops (inode);/* * We cannot call page_symlink() with transaction started
@@ -3309,9 +3311,8 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); - inode->i_op = encryption_required ? - &ext4_symlink_inode_operations : - &ext4_fast_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_fast_symlink_inode_operations;memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;
fs/ext4/symlink.c +10 -20
@@ -35,9 +35,6 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)int res;u32 plen, max_size = inode->i_sb->s_blocksize; -if (!ext4_encrypted_inode (inode)) -return page_follow_link_light (dentry, nd); - ctx =ext4_get_fname_crypto_ctx (inode, inode->i_sb->s_blocksize);if (IS_ERR (ctx))return ctx;
@@ -97,18 +94,16 @@ errout: return ERR_PTR(res); } -static void ext4_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) -{ -struct page *page = cookie; - -if (!page) { -kfree (nd_get_link (nd)); - }else { -kunmap (page); -page_cache_release (page); - } -} +const struct inode_operations ext4_encrypted_symlink_inode_operations = { + .readlink = generic_readlink, + .follow_link = ext4_follow_link, + .put_link = kfree_put_link, + .setattr = ext4_setattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, + .listxattr = ext4_listxattr, + .removexattr = generic_removexattr, +};#endif static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd)
@@ -120,13 +115,8 @@ static void *ext4_follow_fast_link(struct dentry *dentry, struct nameidata *nd)const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, -#ifdef CONFIG_EXT4_FS_ENCRYPTION - .follow_link = ext4_follow_link, - .put_link = ext4_put_link, -#else .follow_link = page_follow_link_light, .put_link = page_put_link, -#endif .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,
Signature · 1 line
2.1.4
Re: [PATCH 04/79] ext4: split inode_operations for encrypted symlinks off the rest
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 134 lines
--- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 10 ++++++++-- fs/ext4/namei.c | 9 +++++---- fs/ext4/symlink.c | 30 ++++++++++-------------------- 4 files changed, 24 insertions(+), 26 deletions(-)fs/ext4/ext4.h +1
-0@@ -2849,6 +2849,7 @@ extern int ext4_mpage_readpages(struct address_space *mapping, unsigned nr_pages);/* symlink.c */ +extern const struct inode_operations ext4_encrypted_symlink_inode_operations;extern const struct inode_operations ext4_symlink_inode_operations;extern const struct inode_operations ext4_fast_symlink_inode_operations;fs/ext4/inode.c +8
-2@@ -4211,8 +4211,14 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext4_dir_inode_operations; inode->i_fop = &ext4_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (ext4_inode_is_fast_symlink (inode) && - !ext4_encrypted_inode (inode)) { +if (ext4_encrypted_inode (inode)) { +#ifdef CONFIG_EXT4_FS_ENCRYPTION + inode->i_op = &ext4_encrypted_symlink_inode_operations; +ext4_set_aops (inode); +#else +BUILD_BUG (); +#endif + }else if (ext4_inode_is_fast_symlink (inode)) { inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );fs/ext4/namei.c +5
-4@@ -3266,10 +3266,12 @@ static int ext4_symlink(struct inode *dir, goto err_drop_inode; sd->len =cpu_to_le16 (ostr.len); disk_link.name = (char *) sd; + inode->i_op = &ext4_encrypted_symlink_inode_operations; }if ((disk_link.len >EXT4_N_BLOCKS *4 )) { - inode->i_op = &ext4_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_symlink_inode_operations;ext4_set_aops (inode);/* * We cannot call page_symlink() with transaction started @@ -3309,9 +3311,8 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); - inode->i_op = encryption_required ? - &ext4_symlink_inode_operations : - &ext4_fast_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_fast_symlink_inode_operations;memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;fs/ext4/symlink.c +10
-20@@ -35,9 +35,6 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)int res;u32 plen, max_size = inode->i_sb->s_blocksize; -if (!ext4_encrypted_inode (inode)) -return page_follow_link_light (dentry, nd); - ctx =ext4_get_fname_crypto_ctx (inode, inode->i_sb->s_blocksize);if (IS_ERR (ctx))return ctx;@@ -97,18 +94,16 @@ errout: return ERR_PTR(res); } -static void ext4_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) -{ -struct page *page = cookie; - -if (!page) { -kfree (nd_get_link (nd)); - }else { -kunmap (page); -page_cache_release (page); - } -} +const struct inode_operations ext4_encrypted_symlink_inode_operations = { + .readlink = generic_readlink, + .follow_link = ext4_follow_link, + .put_link = kfree_put_link, + .setattr = ext4_setattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, + .listxattr = ext4_listxattr, + .removexattr = generic_removexattr, +};#endif static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd)@@ -120,13 +115,8 @@ static void *ext4_follow_fast_link(struct dentry *dentry, struct nameidata *nd)const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, -#ifdef CONFIG_EXT4_FS_ENCRYPTION - .follow_link = ext4_follow_link, - .put_link = ext4_put_link, -#else .follow_link = page_follow_link_light, .put_link = page_put_link, -#endif .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 04/79] ext4: split inode_operations for encrypted symlinks off the rest
In reply to Al ViroQuoted 4 lines · Al Viro
} else if (S_ISLNK(inode->i_mode)) {fs/ext4/inode.c +1
-2-if (ext4_inode_is_fast_symlink (inode) && - !ext4_encrypted_inode (inode)) { +if (ext4_encrypted_inode (inode)) {
fs/ext4/inode.c struct inode *ext4_iget(struct super_block *sb, unsigned long ino) · line 4224
Quoted 10 lines
fs/ext4/inode.c +7
-0+#ifdef CONFIG_EXT4_FS_ENCRYPTION + inode->i_op = &ext4_encrypted_symlink_inode_operations; +ext4_set_aops (inode); +#else +BUILD_BUG (); +#endif + }else if (ext4_inode_is_fast_symlink (inode)) { inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
Ugh. Could we aim to *not* add code like this.
Instead, just declare (but don't define) the ext4_encrypted_symlink_inode_operations thing, so that *if* somebody uses it they get a link error, and make sure that "ext4_encrypted_inode()" ends up always returning zero when encryption isn't enabled, so that the compiler will actually optimize the whole thing out (which apparently is already the case, judging by the build-bug-on.
I really prefer to not see #ifdef's inside the middle of anything but trivial helper functions. I know we have them, and I wish we didn't, but at least we can aim to not add more of them.
Linus
Al Viro
maintainerRe: [PATCH 04/79] ext4: split inode_operations for encrypted symlinks off the rest
Quoted 9 lines · Linus Torvalds
Ugh. Could we aim to *not* add code like this.
Instead, just declare (but don't define) the
ext4_encrypted_symlink_inode_operationsthing, so that *if* somebody uses it they get a link error, and make sure that "ext4_encrypted_inode()" ends up always returning zero when encryption isn't enabled, so that the compiler will actually optimize the whole thing out (which apparently is already the case, judging by the build-bug-on.
Sure, no problem. BUILD_BUG_ON was used only because it triggered an error earlier, I simply forgot to rip it out afterwards.
Al Viro
maintainerPATCH 5/79 libfs: simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
let "fast" symlinks store the pointer to the body into ->i_link and use simple_follow_link for ->follow_link()
--- fs/inode.c | 1 + fs/libfs.c | 13 +++++++++++++ include/linux/fs.h | 3 +++ 3 files changed, 17 insertions(+)
fs/inode.c +1 -0
@@ -152,6 +152,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ; + inode->i_link =NULL ; inode->i_rdev =0 ; inode->dirtied_when =0 ;
fs/libfs.c +13 -0
@@ -1093,3 +1093,16 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp,return -EINVAL ; }EXPORT_SYMBOL (simple_nosetlease); + +void *simple_follow_link (struct dentry *dentry,struct nameidata *nd) +{ +nd_set_link (nd,d_inode (dentry)->i_link); +return NULL ; +} +EXPORT_SYMBOL (simple_follow_link); + +const struct inode_operations simple_symlink_inode_operations = { + .follow_link = simple_follow_link, + .readlink = generic_readlink +}; +EXPORT_SYMBOL (simple_symlink_inode_operations);
include/linux/fs.h +3 -0
@@ -656,6 +656,7 @@ struct inode {struct pipe_inode_info *i_pipe;struct block_device *i_bdev;struct cdev *i_cdev; +char *i_link; };__u32 i_generation;
@@ -2721,6 +2722,8 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes);void inode_sub_bytes (struct inode *inode,loff_t bytes);loff_t inode_get_bytes (struct inode *inode);void inode_set_bytes (struct inode *inode,loff_t bytes); +void *simple_follow_link (struct dentry *,struct nameidata *); +extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);
Signature · 1 line
2.1.4
Re: [PATCH 05/79] libfs: simple_follow_link()
Quoted 6 lines · Al Viro
From: Al Viro <[email protected]>
let "fast" symlinks store the pointer to the body into ->i_link and use
simple_follow_linkfor ->follow_link()Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 67 lines
--- fs/inode.c | 1 + fs/libfs.c | 13 +++++++++++++ include/linux/fs.h | 3 +++ 3 files changed, 17 insertions(+)fs/inode.c +1
-0@@ -152,6 +152,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ; + inode->i_link =NULL ; inode->i_rdev =0 ; inode->dirtied_when =0 ;fs/libfs.c +13
-0@@ -1093,3 +1093,16 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp,return -EINVAL ; }EXPORT_SYMBOL (simple_nosetlease); + +void *simple_follow_link (struct dentry *dentry,struct nameidata *nd) +{ +nd_set_link (nd,d_inode (dentry)->i_link); +return NULL ; +} +EXPORT_SYMBOL (simple_follow_link); + +const struct inode_operations simple_symlink_inode_operations = { + .follow_link = simple_follow_link, + .readlink = generic_readlink +}; +EXPORT_SYMBOL (simple_symlink_inode_operations);include/linux/fs.h +3
-0@@ -656,6 +656,7 @@ struct inode {struct pipe_inode_info *i_pipe;struct block_device *i_bdev;struct cdev *i_cdev; +char *i_link; };__u32 i_generation;@@ -2721,6 +2722,8 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes);void inode_sub_bytes (struct inode *inode,loff_t bytes);loff_t inode_get_bytes (struct inode *inode);void inode_set_bytes (struct inode *inode,loff_t bytes); +void *simple_follow_link (struct dentry *,struct nameidata *); +extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 6/79 ext2: use simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext2/inode.c | 1 + fs/ext2/namei.c | 3 ++- fs/ext2/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)
fs/ext2/inode.c +1 -0
@@ -1403,6 +1403,7 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &ext2_aops; }else if (S_ISLNK (inode->i_mode)) {if (ext2_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext2_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext2/namei.c +2 -1
@@ -189,7 +189,8 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry, }else {/* fast symlink */ inode->i_op = &ext2_fast_symlink_inode_operations; -memcpy ((char *)(EXT2_I (inode)->i_data),symname,l); + inode->i_link = (char *)EXT2_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }mark_inode_dirty (inode);
fs/ext2/symlink.c +1 -9
@@ -19,14 +19,6 @@#include "ext2.h" #include "xattr.h" -#include <linux/namei.h> - -static void *ext2_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext2_inode_info *ei =EXT2_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -}const struct inode_operations ext2_symlink_inode_operations = { .readlink = generic_readlink,
@@ -43,7 +35,7 @@ const struct inode_operations ext2_symlink_inode_operations = {const struct inode_operations ext2_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext2_follow_link, + .follow_link = simple_follow_link, .setattr = ext2_setattr, #ifdef CONFIG_EXT2_FS_XATTR .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Re: [PATCH 06/79] ext2: use simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 67 lines
--- fs/ext2/inode.c | 1 + fs/ext2/namei.c | 3 ++- fs/ext2/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)fs/ext2/inode.c +1
-0@@ -1403,6 +1403,7 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &ext2_aops; }else if (S_ISLNK (inode->i_mode)) {if (ext2_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext2_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );fs/ext2/namei.c +2
-1@@ -189,7 +189,8 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry, }else {/* fast symlink */ inode->i_op = &ext2_fast_symlink_inode_operations; -memcpy ((char *)(EXT2_I (inode)->i_data),symname,l); + inode->i_link = (char *)EXT2_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }mark_inode_dirty (inode);fs/ext2/symlink.c +1
-9@@ -19,14 +19,6 @@#include "ext2.h" #include "xattr.h" -#include <linux/namei.h> - -static void *ext2_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext2_inode_info *ei =EXT2_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -}const struct inode_operations ext2_symlink_inode_operations = { .readlink = generic_readlink,@@ -43,7 +35,7 @@ const struct inode_operations ext2_symlink_inode_operations = {const struct inode_operations ext2_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext2_follow_link, + .follow_link = simple_follow_link, .setattr = ext2_setattr, #ifdef CONFIG_EXT2_FS_XATTR .setxattr = generic_setxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 7/79 befs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/befs/linuxvfs.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
fs/befs/linuxvfs.c +5 -19
@@ -43,7 +43,6 @@ static struct inode *befs_alloc_inode(struct super_block *sb);static void befs_destroy_inode (struct inode *inode);static void befs_destroy_inodecache (void );static void *befs_follow_link (struct dentry *,struct nameidata *); -static void *befs_fast_follow_link (struct dentry *,struct nameidata *);static int befs_utf2nls (struct super_block *sb,const char *in,int in_len,char **out,int *out_len); static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,
@@ -80,11 +79,6 @@ static const struct address_space_operations befs_aops = { .bmap = befs_bmap, }; -static const struct inode_operations befs_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = befs_fast_follow_link, -}; -static const struct inode_operations befs_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = befs_follow_link,
@@ -403,10 +397,12 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &befs_dir_inode_operations; inode->i_fop = &befs_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) +if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) { inode->i_op = &befs_symlink_inode_operations; -else - inode->i_op = &befs_fast_symlink_inode_operations; + }else { + inode->i_link = befs_ino->i_data.symlink; + inode->i_op = &simple_symlink_inode_operations; + } }else {befs_error (sb,"Inode %lu is not a regular file, " "directory or symlink. THAT IS WRONG! BeFS has no "
@@ -497,16 +493,6 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)return NULL ; } - -static void * -befs_fast_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct befs_inode_info *befs_ino =BEFS_I (d_inode (dentry)); - -nd_set_link (nd, befs_ino->i_data.symlink); -return NULL ; -} -/* * UTF-8 to NLS charset convert routine *
Signature · 1 line
2.1.4
Re: [PATCH 07/79] befs: switch to simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 68 lines
--- fs/befs/linuxvfs.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)fs/befs/linuxvfs.c +5
-19@@ -43,7 +43,6 @@ static struct inode *befs_alloc_inode(struct super_block *sb);static void befs_destroy_inode (struct inode *inode);static void befs_destroy_inodecache (void );static void *befs_follow_link (struct dentry *,struct nameidata *); -static void *befs_fast_follow_link (struct dentry *,struct nameidata *);static int befs_utf2nls (struct super_block *sb,const char *in,int in_len,char **out,int *out_len); static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,@@ -80,11 +79,6 @@ static const struct address_space_operations befs_aops = { .bmap = befs_bmap, }; -static const struct inode_operations befs_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = befs_fast_follow_link, -}; -static const struct inode_operations befs_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = befs_follow_link,@@ -403,10 +397,12 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &befs_dir_inode_operations; inode->i_fop = &befs_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) +if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) { inode->i_op = &befs_symlink_inode_operations; -else - inode->i_op = &befs_fast_symlink_inode_operations; + }else { + inode->i_link = befs_ino->i_data.symlink; + inode->i_op = &simple_symlink_inode_operations; + } }else {befs_error (sb,"Inode %lu is not a regular file, " "directory or symlink. THAT IS WRONG! BeFS has no "@@ -497,16 +493,6 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)return NULL ; } - -static void * -befs_fast_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct befs_inode_info *befs_ino =BEFS_I (d_inode (dentry)); - -nd_set_link (nd, befs_ino->i_data.symlink); -return NULL ; -} -/* * UTF-8 to NLS charset convert routine * Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 8/79 ext3: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext3/inode.c | 1 + fs/ext3/namei.c | 3 ++- fs/ext3/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)
fs/ext3/inode.c +1 -0
@@ -2999,6 +2999,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext3_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 ); + inode->i_link = (char *)ei->i_data; }else { inode->i_op = &ext3_symlink_inode_operations;ext3_set_aops (inode);
fs/ext3/namei.c +2 -1
@@ -2308,7 +2308,8 @@ retry: } }else { inode->i_op = &ext3_fast_symlink_inode_operations; -memcpy ((char *)&EXT3_I (inode)->i_data,symname,l); + inode->i_link = (char *)&EXT3_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }EXT3_I (inode)->i_disksize = inode->i_size;
fs/ext3/symlink.c +1 -9
@@ -17,17 +17,9 @@* ext3 symlink handling code */ -#include <linux/namei.h> #include "ext3.h" #include "xattr.h" -static void *ext3_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext3_inode_info *ei =EXT3_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -} -const struct inode_operations ext3_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,
@@ -43,7 +35,7 @@ const struct inode_operations ext3_symlink_inode_operations = {const struct inode_operations ext3_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext3_follow_link, + .follow_link = simple_follow_link, .setattr = ext3_setattr, #ifdef CONFIG_EXT3_FS_XATTR .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Re: [PATCH 08/79] ext3: switch to simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 70 lines
--- fs/ext3/inode.c | 1 + fs/ext3/namei.c | 3 ++- fs/ext3/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)fs/ext3/inode.c +1
-0@@ -2999,6 +2999,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext3_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 ); + inode->i_link = (char *)ei->i_data; }else { inode->i_op = &ext3_symlink_inode_operations;ext3_set_aops (inode);fs/ext3/namei.c +2
-1@@ -2308,7 +2308,8 @@ retry: } }else { inode->i_op = &ext3_fast_symlink_inode_operations; -memcpy ((char *)&EXT3_I (inode)->i_data,symname,l); + inode->i_link = (char *)&EXT3_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }EXT3_I (inode)->i_disksize = inode->i_size;fs/ext3/symlink.c +1
-9@@ -17,17 +17,9 @@* ext3 symlink handling code */ -#include <linux/namei.h> #include "ext3.h" #include "xattr.h" -static void *ext3_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext3_inode_info *ei =EXT3_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -} -const struct inode_operations ext3_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,@@ -43,7 +35,7 @@ const struct inode_operations ext3_symlink_inode_operations = {const struct inode_operations ext3_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext3_follow_link, + .follow_link = simple_follow_link, .setattr = ext3_setattr, #ifdef CONFIG_EXT3_FS_XATTR .setxattr = generic_setxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 9/79 ext4: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
for fast symlinks only, of course...
--- fs/ext4/inode.c | 1 + fs/ext4/namei.c | 4 +++- fs/ext4/symlink.c | 9 +-------- 3 files changed, 5 insertions(+), 9 deletions(-)
fs/ext4/inode.c +1 -0
@@ -4219,6 +4219,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)BUILD_BUG ();#endif }else if (ext4_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext4/namei.c +3 -1
@@ -3311,8 +3311,10 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); -if (!encryption_required) +if (!encryption_required) { inode->i_op = &ext4_fast_symlink_inode_operations; + inode->i_link = (char *)&EXT4_I (inode)->i_data; + }memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;
fs/ext4/symlink.c +1 -8
@@ -106,13 +106,6 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { };#endif -static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext4_inode_info *ei =EXT4_I (d_inode (dentry)); -nd_set_link (nd, (char *) ei->i_data); -return NULL ; -} -const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,
@@ -126,7 +119,7 @@ const struct inode_operations ext4_symlink_inode_operations = {const struct inode_operations ext4_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext4_follow_fast_link, + .follow_link = simple_follow_link, .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,
Signature · 1 line
2.1.4
Re: [PATCH 09/79] ext4: switch to simple_follow_link()
Quoted 5 lines · Al Viro
From: Al Viro <[email protected]>
for fast symlinks only, of course...
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 68 lines
--- fs/ext4/inode.c | 1 + fs/ext4/namei.c | 4 +++- fs/ext4/symlink.c | 9 +-------- 3 files changed, 5 insertions(+), 9 deletions(-)fs/ext4/inode.c +1
-0@@ -4219,6 +4219,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)BUILD_BUG ();#endif }else if (ext4_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );fs/ext4/namei.c +3
-1@@ -3311,8 +3311,10 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); -if (!encryption_required) +if (!encryption_required) { inode->i_op = &ext4_fast_symlink_inode_operations; + inode->i_link = (char *)&EXT4_I (inode)->i_data; + }memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;fs/ext4/symlink.c +1
-8@@ -106,13 +106,6 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { };#endif -static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext4_inode_info *ei =EXT4_I (d_inode (dentry)); -nd_set_link (nd, (char *) ei->i_data); -return NULL ; -} -const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,@@ -126,7 +119,7 @@ const struct inode_operations ext4_symlink_inode_operations = {const struct inode_operations ext4_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext4_follow_fast_link, + .follow_link = simple_follow_link, .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 10/79 jffs2: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/jffs2/dir.c | 1 + fs/jffs2/fs.c | 1 + fs/jffs2/symlink.c | 45 +-------------------------------------------- 3 files changed, 3 insertions(+), 44 deletions(-)
fs/jffs2/dir.c +1 -0
@@ -354,6 +354,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char ret = -ENOMEM ; goto fail; } + inode->i_link = f->target;jffs2_dbg (1 ,"%s(): symlink's target '%s' cached\n" , __func__, (char *)f->target);
fs/jffs2/fs.c +1 -0
@@ -294,6 +294,7 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)case S_IFLNK : inode->i_op = &jffs2_symlink_inode_operations; + inode->i_link = f->target;break ;case S_IFDIR :
fs/jffs2/symlink.c +1 -44
59 lines not on this page · raw message
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 11/79 shmem: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- mm/shmem.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/shmem.c +2 -7
@@ -2451,6 +2451,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn -ENOMEM ; } inode->i_op = &shmem_short_symlink_operations; + inode->i_link = info->symlink; }else { error =shmem_getpage (inode,0 , &page,SGP_WRITE ,NULL );if (error) {
@@ -2474,12 +2475,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn 0 ; } -static void *shmem_follow_short_symlink (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,SHMEM_I (d_inode (dentry))->symlink); -return NULL ; -} -static void *shmem_follow_link (struct dentry *dentry,struct nameidata *nd) {struct page *page =NULL ;
@@ -2642,7 +2637,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)static const struct inode_operations shmem_short_symlink_operations = { .readlink = generic_readlink, - .follow_link = shmem_follow_short_symlink, + .follow_link = simple_follow_link, #ifdef CONFIG_TMPFS_XATTR .setxattr = shmem_setxattr, .getxattr = shmem_getxattr,
Signature · 1 line
2.1.4
Re: [PATCH 11/79] shmem: switch to simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 45 lines
--- mm/shmem.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)mm/shmem.c +2
-7@@ -2451,6 +2451,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn -ENOMEM ; } inode->i_op = &shmem_short_symlink_operations; + inode->i_link = info->symlink; }else { error =shmem_getpage (inode,0 , &page,SGP_WRITE ,NULL );if (error) {@@ -2474,12 +2475,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn 0 ; } -static void *shmem_follow_short_symlink (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,SHMEM_I (d_inode (dentry))->symlink); -return NULL ; -} -static void *shmem_follow_link (struct dentry *dentry,struct nameidata *nd) {struct page *page =NULL ;@@ -2642,7 +2637,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)static const struct inode_operations shmem_short_symlink_operations = { .readlink = generic_readlink, - .follow_link = shmem_follow_short_symlink, + .follow_link = simple_follow_link, #ifdef CONFIG_TMPFS_XATTR .setxattr = shmem_setxattr, .getxattr = shmem_getxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 12/79 debugfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/debugfs/file.c | 12 ------------ fs/debugfs/inode.c | 6 +++--- include/linux/debugfs.h | 1 - 3 files changed, 3 insertions(+), 16 deletions(-)
fs/debugfs/file.c +0 -12
@@ -17,7 +17,6 @@#include <linux/fs.h> #include <linux/seq_file.h> #include <linux/pagemap.h> -#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/io.h> #include <linux/slab.h>
@@ -43,17 +42,6 @@ const struct file_operations debugfs_file_operations = { .llseek = noop_llseek, }; -static void *debugfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,d_inode (dentry)->i_private); -return NULL ; -} - -const struct inode_operations debugfs_link_operations = { - .readlink = generic_readlink, - .follow_link = debugfs_follow_link, -}; -static int debugfs_u8_set (void *data,u64 val) { *(u8 *)data = val;
fs/debugfs/inode.c +3 -3
@@ -174,7 +174,7 @@ static void debugfs_evict_inode(struct inode *inode)truncate_inode_pages_final (&inode->i_data);clear_inode (inode);if (S_ISLNK (inode->i_mode)) -kfree (inode->i_private); +kfree (inode->i_link); }static const struct super_operations debugfs_super_operations = {
@@ -511,8 +511,8 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,return failed_creating (dentry); } inode->i_mode =S_IFLNK |S_IRWXUGO ; - inode->i_op = &debugfs_link_operations; - inode->i_private = link; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = link;d_instantiate (dentry, inode);return end_creating (dentry); }
include/linux/debugfs.h +0 -1
@@ -45,7 +45,6 @@ extern struct dentry *arch_debugfs_dir;/* declared over in file.c */ extern const struct file_operations debugfs_file_operations; -extern const struct inode_operations debugfs_link_operations; struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data,
Signature · 1 line
2.1.4
Re: [PATCH 12/79] debugfs: switch to simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 79 lines
--- fs/debugfs/file.c | 12 ------------ fs/debugfs/inode.c | 6 +++--- include/linux/debugfs.h | 1 - 3 files changed, 3 insertions(+), 16 deletions(-)fs/debugfs/file.c +0
-12@@ -17,7 +17,6 @@#include <linux/fs.h> #include <linux/seq_file.h> #include <linux/pagemap.h> -#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/io.h> #include <linux/slab.h> @@ -43,17 +42,6 @@ const struct file_operations debugfs_file_operations = { .llseek = noop_llseek, }; -static void *debugfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,d_inode (dentry)->i_private); -return NULL ; -} - -const struct inode_operations debugfs_link_operations = { - .readlink = generic_readlink, - .follow_link = debugfs_follow_link, -}; -static int debugfs_u8_set (void *data,u64 val) { *(u8 *)data = val;fs/debugfs/inode.c +3
-3@@ -174,7 +174,7 @@ static void debugfs_evict_inode(struct inode *inode)truncate_inode_pages_final (&inode->i_data);clear_inode (inode);if (S_ISLNK (inode->i_mode)) -kfree (inode->i_private); +kfree (inode->i_link); }static const struct super_operations debugfs_super_operations = {@@ -511,8 +511,8 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,return failed_creating (dentry); } inode->i_mode =S_IFLNK |S_IRWXUGO ; - inode->i_op = &debugfs_link_operations; - inode->i_private = link; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = link;d_instantiate (dentry, inode);return end_creating (dentry); }include/linux/debugfs.h +0
-1@@ -45,7 +45,6 @@ extern struct dentry *arch_debugfs_dir;/* declared over in file.c */ extern const struct file_operations debugfs_file_operations; -extern const struct inode_operations debugfs_link_operations; struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerPATCH 13/79 ufs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ufs/inode.c | 5 +++-- fs/ufs/namei.c | 3 ++- fs/ufs/symlink.c | 13 +------------ 3 files changed, 6 insertions(+), 15 deletions(-)
fs/ufs/inode.c +3 -2
@@ -572,9 +572,10 @@ static void ufs_set_inode_ops(struct inode *inode) inode->i_fop = &ufs_dir_operations; inode->i_mapping->a_ops = &ufs_aops; }else if (S_ISLNK (inode->i_mode)) { -if (!inode->i_blocks) +if (!inode->i_blocks) { inode->i_op = &ufs_fast_symlink_inode_operations; -else { + inode->i_link = (char *)UFS_I (inode)->i_u1.i_symlink; + }else { inode->i_op = &ufs_symlink_inode_operations; inode->i_mapping->a_ops = &ufs_aops; }
fs/ufs/namei.c +2 -1
@@ -144,7 +144,8 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry, }else {/* fast symlink */ inode->i_op = &ufs_fast_symlink_inode_operations; -memcpy (UFS_I (inode)->i_u1.i_symlink, symname, l); + inode->i_link = (char *)UFS_I (inode)->i_u1.i_symlink; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }mark_inode_dirty (inode);
fs/ufs/symlink.c +1 -12
@@ -25,23 +25,12 @@* ext2 symlink handling code */ -#include <linux/fs.h> -#include <linux/namei.h> -#include "ufs_fs.h" #include "ufs.h" - -static void *ufs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ufs_inode_info *p =UFS_I (d_inode (dentry)); -nd_set_link (nd, (char *)p->i_u1.i_symlink); -return NULL ; -} -const struct inode_operations ufs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ufs_follow_link, + .follow_link = simple_follow_link, .setattr = ufs_setattr, };
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 14/79 ubifs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ubifs/dir.c | 1 + fs/ubifs/file.c | 11 +---------- fs/ubifs/super.c | 1 + 3 files changed, 3 insertions(+), 10 deletions(-)
fs/ubifs/dir.c +1 -0
@@ -889,6 +889,7 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,memcpy (ui->data, symname, len); ((char *)ui->data)[len] ='\0' ; + inode->i_link = ui->data;/* * The terminating zero byte is not written to the flash media and it * is put just to make later in-memory string processing simpler. Thus,
fs/ubifs/file.c +1 -10
@@ -51,7 +51,6 @@#include "ubifs.h" #include <linux/mount.h> -#include <linux/namei.h> #include <linux/slab.h> static int read_block(struct inode *inode, void *addr, unsigned int block,
@@ -1300,14 +1299,6 @@ static void ubifs_invalidatepage(struct page *page, unsigned int offset,ClearPageChecked (page); } -static void *ubifs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ubifs_inode *ui =ubifs_inode (d_inode (dentry)); - -nd_set_link (nd, ui->data); -return NULL ; -} -int ubifs_fsync (struct file *file,loff_t start,loff_t end,int datasync) {struct inode *inode = file->f_mapping->host;
@@ -1570,7 +1561,7 @@ const struct inode_operations ubifs_file_inode_operations = {const struct inode_operations ubifs_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ubifs_follow_link, + .follow_link = simple_follow_link, .setattr = ubifs_setattr, .getattr = ubifs_getattr, .setxattr = ubifs_setxattr,
fs/ubifs/super.c +1 -0
@@ -195,6 +195,7 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum) }memcpy (ui->data, ino->data, ui->data_len); ((char *)ui->data)[ui->data_len] ='\0' ; + inode->i_link = ui->data;break ;case S_IFBLK :case S_IFCHR :
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 15/79 sysv: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/sysv/Makefile | 2 +- fs/sysv/inode.c | 5 +++-- fs/sysv/symlink.c | 20 -------------------- fs/sysv/sysv.h | 1 - 4 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 fs/sysv/symlink.c
fs/sysv/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_SYSV_FS) += sysv.o sysv-objs := ialloc.o balloc.o inode.o itree.o file.o dir.o \ - namei.o super.o symlink.o + namei.o super.o
fs/sysv/inode.c +3 -2
@@ -166,8 +166,9 @@ void sysv_set_inode(struct inode *inode, dev_t rdev) inode->i_op = &sysv_symlink_inode_operations; inode->i_mapping->a_ops = &sysv_aops; }else { - inode->i_op = &sysv_fast_symlink_inode_operations; -nd_terminate_link (SYSV_I (inode)->i_data, inode->i_size, + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)SYSV_I (inode)->i_data; +nd_terminate_link (inode->i_link, inode->i_size,sizeof (SYSV_I (inode)->i_data) -1 ); } }else
fs/sysv/symlink.c deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* linux/fs/sysv/symlink.c -* -* Handling of System V filesystem fast symlinks extensions. -* Aug 2001, Christoph Hellwig ([email protected]) -*/ - -#include "sysv.h" -#include <linux/namei.h> - -static void *sysv_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd, (char *)SYSV_I (d_inode (dentry))->i_data); -return NULL ; -} - -const struct inode_operations sysv_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = sysv_follow_link, -};
fs/sysv/sysv.h +0 -1
@@ -161,7 +161,6 @@ extern ino_t sysv_inode_by_name(struct dentry *);extern const struct inode_operations sysv_file_inode_operations;extern const struct inode_operations sysv_dir_inode_operations; -extern const struct inode_operations sysv_fast_symlink_inode_operations;extern const struct file_operations sysv_file_operations;extern const struct file_operations sysv_dir_operations;extern const struct address_space_operations sysv_aops;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 16/79 jfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/jfs/inode.c | 3 ++- fs/jfs/namei.c | 5 ++--- fs/jfs/symlink.c | 10 +--------- 3 files changed, 5 insertions(+), 13 deletions(-)
fs/jfs/inode.c +2 -1
@@ -63,11 +63,12 @@ struct inode *jfs_iget(struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &jfs_aops; }else { inode->i_op = &jfs_fast_symlink_inode_operations; + inode->i_link =JFS_IP (inode)->i_inline;/* * The inline data should be null-terminated, but * don't let on-disk corruption crash the kernel */ -JFS_IP (inode)->i_inline[inode->i_size] ='\0' ; + inode->i_link[inode->i_size] ='\0' ; } }else { inode->i_op = &jfs_file_inode_operations;
fs/jfs/namei.c +2 -3
@@ -880,7 +880,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,int ssize;/* source pathname size */ struct btstack btstack;struct inode *ip =d_inode (dentry); -unchar *i_fastsymlink;s64 xlen =0 ;int bmask =0 , xsize;s64 xaddr;
@@ -946,8 +945,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,if (ssize <=IDATASIZE ) { ip->i_op = &jfs_fast_symlink_inode_operations; - i_fastsymlink =JFS_IP (ip)->i_inline; -memcpy (i_fastsymlink, name, ssize); + ip->i_link =JFS_IP (ip)->i_inline; +memcpy (ip->i_link, name, ssize); ip->i_size = ssize -1 ;/*
fs/jfs/symlink.c +1 -9
@@ -17,21 +17,13 @@*/ #include <linux/fs.h> -#include <linux/namei.h> #include "jfs_incore.h" #include "jfs_inode.h" #include "jfs_xattr.h" -static void *jfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -char *s =JFS_IP (d_inode (dentry))->i_inline; -nd_set_link (nd, s); -return NULL ; -} -const struct inode_operations jfs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = jfs_follow_link, + .follow_link = simple_follow_link, .setattr = jfs_setattr, .setxattr = jfs_setxattr, .getxattr = jfs_getxattr,
Signature · 1 line
2.1.4
Re: [PATCH 16/79] jfs: switch to simple_follow_link()
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Looks good. You can add:
Honza
Quoted 81 lines
--- fs/jfs/inode.c | 3 ++- fs/jfs/namei.c | 5 ++--- fs/jfs/symlink.c | 10 +--------- 3 files changed, 5 insertions(+), 13 deletions(-)fs/jfs/inode.c +2
-1@@ -63,11 +63,12 @@ struct inode *jfs_iget(struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &jfs_aops; }else { inode->i_op = &jfs_fast_symlink_inode_operations; + inode->i_link =JFS_IP (inode)->i_inline;/* * The inline data should be null-terminated, but * don't let on-disk corruption crash the kernel */ -JFS_IP (inode)->i_inline[inode->i_size] ='\0' ; + inode->i_link[inode->i_size] ='\0' ; } }else { inode->i_op = &jfs_file_inode_operations;fs/jfs/namei.c +2
-3@@ -880,7 +880,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,int ssize;/* source pathname size */ struct btstack btstack;struct inode *ip =d_inode (dentry); -unchar *i_fastsymlink;s64 xlen =0 ;int bmask =0 , xsize;s64 xaddr;@@ -946,8 +945,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,if (ssize <=IDATASIZE ) { ip->i_op = &jfs_fast_symlink_inode_operations; - i_fastsymlink =JFS_IP (ip)->i_inline; -memcpy (i_fastsymlink, name, ssize); + ip->i_link =JFS_IP (ip)->i_inline; +memcpy (ip->i_link, name, ssize); ip->i_size = ssize -1 ;/* fs/jfs/symlink.c +1
-9@@ -17,21 +17,13 @@*/ #include <linux/fs.h> -#include <linux/namei.h> #include "jfs_incore.h" #include "jfs_inode.h" #include "jfs_xattr.h" -static void *jfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -char *s =JFS_IP (d_inode (dentry))->i_inline; -nd_set_link (nd, s); -return NULL ; -} -const struct inode_operations jfs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = jfs_follow_link, + .follow_link = simple_follow_link, .setattr = jfs_setattr, .setxattr = jfs_setxattr, .getxattr = jfs_getxattr,Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 16/79] jfs: switch to simple_follow_link()
In reply to Al ViroQuoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Quoted 75 lines
--- fs/jfs/inode.c | 3 ++- fs/jfs/namei.c | 5 ++--- fs/jfs/symlink.c | 10 +--------- 3 files changed, 5 insertions(+), 13 deletions(-)fs/jfs/inode.c +2
-1@@ -63,11 +63,12 @@ struct inode *jfs_iget(struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &jfs_aops; }else { inode->i_op = &jfs_fast_symlink_inode_operations; + inode->i_link =JFS_IP (inode)->i_inline;/* * The inline data should be null-terminated, but * don't let on-disk corruption crash the kernel */ -JFS_IP (inode)->i_inline[inode->i_size] ='\0' ; + inode->i_link[inode->i_size] ='\0' ; } }else { inode->i_op = &jfs_file_inode_operations;fs/jfs/namei.c +2
-3@@ -880,7 +880,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,int ssize;/* source pathname size */ struct btstack btstack;struct inode *ip =d_inode (dentry); -unchar *i_fastsymlink;s64 xlen =0 ;int bmask =0 , xsize;s64 xaddr;@@ -946,8 +945,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,if (ssize <=IDATASIZE ) { ip->i_op = &jfs_fast_symlink_inode_operations; - i_fastsymlink =JFS_IP (ip)->i_inline; -memcpy (i_fastsymlink, name, ssize); + ip->i_link =JFS_IP (ip)->i_inline; +memcpy (ip->i_link, name, ssize); ip->i_size = ssize -1 ;/* fs/jfs/symlink.c +1
-9@@ -17,21 +17,13 @@*/ #include <linux/fs.h> -#include <linux/namei.h> #include "jfs_incore.h" #include "jfs_inode.h" #include "jfs_xattr.h" -static void *jfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -char *s =JFS_IP (d_inode (dentry))->i_inline; -nd_set_link (nd, s); -return NULL ; -} -const struct inode_operations jfs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = jfs_follow_link, + .follow_link = simple_follow_link, .setattr = jfs_setattr, .setxattr = jfs_setxattr, .getxattr = jfs_getxattr,
Al Viro
maintainerPATCH 17/79 freevxfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/freevxfs/vxfs_extern.h | 3 --- fs/freevxfs/vxfs_immed.c | 34 ---------------------------------- fs/freevxfs/vxfs_inode.c | 7 +++++-- 3 files changed, 5 insertions(+), 39 deletions(-)
fs/freevxfs/vxfs_extern.h +0 -3
@@ -50,9 +50,6 @@ extern daddr_t vxfs_bmap1(struct inode *, long);/* vxfs_fshead.c */ extern int vxfs_read_fshead (struct super_block *); -/* vxfs_immed.c */ -extern const struct inode_operations vxfs_immed_symlink_iops; -/* vxfs_inode.c */ extern const struct address_space_operations vxfs_immed_aops;extern struct kmem_cache *vxfs_inode_cachep;
fs/freevxfs/vxfs_immed.c +0 -34
@@ -32,29 +32,15 @@*/ #include <linux/fs.h> #include <linux/pagemap.h> -#include <linux/namei.h> #include "vxfs.h" #include "vxfs_extern.h" #include "vxfs_inode.h" -static void *vxfs_immed_follow_link (struct dentry *,struct nameidata *); -static int vxfs_immed_readpage (struct file *,struct page *);/* -* Inode operations for immed symlinks. -* -* Unliked all other operations we do not go through the pagecache, -* but do all work directly on the inode. -*/ -const struct inode_operations vxfs_immed_symlink_iops = { - .readlink = generic_readlink, - .follow_link = vxfs_immed_follow_link, -}; - -/* * Address space operations for immed files and directories. */ const struct address_space_operations vxfs_immed_aops = {
@@ -62,26 +48,6 @@ const struct address_space_operations vxfs_immed_aops = { };/** -* vxfs_immed_follow_link - follow immed symlink -* @dp: dentry for the link -* @np: pathname lookup data for the current path walk -* -* Description: -* vxfs_immed_follow_link restarts the pathname lookup with -* the data obtained from @dp. -* -* Returns: -* Zero on success, else a negative error code. -*/ -static void * -vxfs_immed_follow_link (struct dentry *dp,struct nameidata *np) -{ -struct vxfs_inode_info *vip =VXFS_INO (d_inode (dp)); -nd_set_link (np, vip->vii_immed.vi_immed); -return NULL ; -} - -/** * vxfs_immed_readpage - read part of an immed inode into pagecache * @file: file context (unused) * @page: page frame to fill in.
fs/freevxfs/vxfs_inode.c +5 -2
@@ -35,6 +35,7 @@#include <linux/pagemap.h> #include <linux/kernel.h> #include <linux/slab.h> +#include <linux/namei.h> #include "vxfs.h" #include "vxfs_inode.h"
@@ -327,8 +328,10 @@ vxfs_iget(struct super_block *sbp, ino_t ino) ip->i_op = &page_symlink_inode_operations; ip->i_mapping->a_ops = &vxfs_aops; }else { - ip->i_op = &vxfs_immed_symlink_iops; - vip->vii_immed.vi_immed[ip->i_size] ='\0' ; + ip->i_op = &simple_symlink_inode_operations; + ip->i_link = vip->vii_immed.vi_immed; +nd_terminate_link (ip->i_link, ip->i_size, +sizeof (vip->vii_immed.vi_immed) -1 ); } }else init_special_inode (ip, ip->i_mode,old_decode_dev (vip->vii_rdev));
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 18/79 exofs: switch to {simple,page}_symlink_inode_operations
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/exofs/Kbuild | 2 +- fs/exofs/exofs.h | 4 ---- fs/exofs/inode.c | 9 +++++---- fs/exofs/namei.c | 5 +++-- fs/exofs/symlink.c | 55 ------------------------------------------------------ 5 files changed, 9 insertions(+), 66 deletions(-) delete mode 100644 fs/exofs/symlink.c
fs/exofs/Kbuild +1 -1
@@ -16,5 +16,5 @@ libore-y := ore.o ore_raid.o obj-$(CONFIG_ORE) += libore.o -exofs-y := inode.o file.o symlink.o namei.o dir.o super.o sys.o +exofs-y := inode.o file.o namei.o dir.o super.o sys.o obj-$(CONFIG_EXOFS_FS) += exofs.o
fs/exofs/exofs.h +0 -4
@@ -207,10 +207,6 @@ extern const struct address_space_operations exofs_aops;extern const struct inode_operations exofs_dir_inode_operations;extern const struct inode_operations exofs_special_inode_operations; -/* symlink.c */ -extern const struct inode_operations exofs_symlink_inode_operations; -extern const struct inode_operations exofs_fast_symlink_inode_operations; -/* exofs_init_comps will initialize an ore_components device array * pointing to a single ore_comp struct, and a round-robin view * of the device table.
fs/exofs/inode.c +5 -4
@@ -1222,10 +1222,11 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) inode->i_fop = &exofs_dir_operations; inode->i_mapping->a_ops = &exofs_aops; }else if (S_ISLNK (inode->i_mode)) { -if (exofs_inode_is_fast_symlink (inode)) - inode->i_op = &exofs_fast_symlink_inode_operations; -else { - inode->i_op = &exofs_symlink_inode_operations; +if (exofs_inode_is_fast_symlink (inode)) { + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data; + }else { + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops; } }else {
fs/exofs/namei.c +3 -2
@@ -113,7 +113,7 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, oi =exofs_i (inode);if (l >sizeof (oi->i_data)) {/* slow symlink */ - inode->i_op = &exofs_symlink_inode_operations; + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops;memset (oi->i_data,0 ,sizeof (oi->i_data));
@@ -122,7 +122,8 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, goto out_fail; }else {/* fast symlink */ - inode->i_op = &exofs_fast_symlink_inode_operations; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data;memcpy (oi->i_data, symname, l); inode->i_size = l-1 ; }
fs/exofs/symlink.c deleted +0 -55
55 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH 18/79] exofs: switch to {simple,page}_symlink_inode_operations
Quoted 3 lines · Al Viro
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>
Thanks Al so much nicer (And safer)
Boaz
Quoted 140 lines
--- fs/exofs/Kbuild | 2 +- fs/exofs/exofs.h | 4 ---- fs/exofs/inode.c | 9 +++++---- fs/exofs/namei.c | 5 +++-- fs/exofs/symlink.c | 55 ------------------------------------------------------ 5 files changed, 9 insertions(+), 66 deletions(-) delete mode 100644 fs/exofs/symlink.cfs/exofs/Kbuild +1
-1@@ -16,5 +16,5 @@ libore-y := ore.o ore_raid.o obj-$(CONFIG_ORE) += libore.o -exofs-y := inode.o file.o symlink.o namei.o dir.o super.o sys.o +exofs-y := inode.o file.o namei.o dir.o super.o sys.o obj-$(CONFIG_EXOFS_FS) += exofs.ofs/exofs/exofs.h +0
-4@@ -207,10 +207,6 @@ extern const struct address_space_operations exofs_aops;extern const struct inode_operations exofs_dir_inode_operations;extern const struct inode_operations exofs_special_inode_operations; -/* symlink.c */ -extern const struct inode_operations exofs_symlink_inode_operations; -extern const struct inode_operations exofs_fast_symlink_inode_operations; -/* exofs_init_comps will initialize an ore_components device array * pointing to a single ore_comp struct, and a round-robin view * of the device table. fs/exofs/inode.c +5
-4@@ -1222,10 +1222,11 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) inode->i_fop = &exofs_dir_operations; inode->i_mapping->a_ops = &exofs_aops; }else if (S_ISLNK (inode->i_mode)) { -if (exofs_inode_is_fast_symlink (inode)) - inode->i_op = &exofs_fast_symlink_inode_operations; -else { - inode->i_op = &exofs_symlink_inode_operations; +if (exofs_inode_is_fast_symlink (inode)) { + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data; + }else { + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops; } }else {fs/exofs/namei.c +3
-2@@ -113,7 +113,7 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, oi =exofs_i (inode);if (l >sizeof (oi->i_data)) {/* slow symlink */ - inode->i_op = &exofs_symlink_inode_operations; + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops;memset (oi->i_data,0 ,sizeof (oi->i_data));@@ -122,7 +122,8 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, goto out_fail; }else {/* fast symlink */ - inode->i_op = &exofs_fast_symlink_inode_operations; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data;memcpy (oi->i_data, symname, l); inode->i_size = l-1 ; }fs/exofs/symlink.c deleted +0
-55@@ -1,55 +0,0 @@ -/* -* Copyright (C) 2005, 2006 -* Avishay Traeger ([email protected]) -* Copyright (C) 2008, 2009 -* Boaz Harrosh <[email protected]> -* -* Copyrights for code taken from ext2: -* Copyright (C) 1992, 1993, 1994, 1995 -* Remy Card ([email protected]) -* Laboratoire MASI - Institut Blaise Pascal -* Universite Pierre et Marie Curie (Paris VI) -* from -* linux/fs/minix/inode.c -* Copyright (C) 1991, 1992 Linus Torvalds -* -* This file is part of exofs. -* -* exofs is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation. Since it is based on ext2, and the only -* valid version of GPL for the Linux kernel is version 2, the only valid -* version of GPL for exofs is version 2. -* -* exofs is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with exofs; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include <linux/namei.h> - -#include "exofs.h" - -static void *exofs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct exofs_i_info *oi =exofs_i (d_inode (dentry)); - -nd_set_link (nd, (char *)oi->i_data); -return NULL ; -} - -const struct inode_operations exofs_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = page_follow_link_light, - .put_link = page_put_link, -}; - -const struct inode_operations exofs_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = exofs_follow_link, -};
Al Viro
maintainerPATCH 19/79 ceph: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ceph/inode.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
fs/ceph/inode.c +2 -9
@@ -6,7 +6,6 @@#include <linux/string.h> #include <linux/uaccess.h> #include <linux/kernel.h> -#include <linux/namei.h> #include <linux/writeback.h> #include <linux/vmalloc.h> #include <linux/posix_acl.h>
@@ -819,6 +818,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page,else kfree (sym);/* lost a race */ } + inode->i_link = ci->i_symlink;break ;case S_IFDIR : inode->i_op = &ceph_dir_iops;
@@ -1691,16 +1691,9 @@ retry:/* * symlinks */ -static void *ceph_sym_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ceph_inode_info *ci =ceph_inode (d_inode (dentry)); -nd_set_link (nd, ci->i_symlink); -return NULL ; -} -static const struct inode_operations ceph_symlink_iops = { .readlink = generic_readlink, - .follow_link = ceph_sym_follow_link, + .follow_link = simple_follow_link, .setattr = ceph_setattr, .getattr = ceph_getattr, .setxattr = ceph_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 20/79 logfs: fix a pagecache leak for symlinks
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/logfs/dir.c | 1 + 1 file changed, 1 insertion(+)
fs/logfs/dir.c +1 -0
@@ -779,6 +779,7 @@ fail:const struct inode_operations logfs_symlink_iops = { .readlink = generic_readlink, .follow_link = page_follow_link_light, + .put_link = page_put_link, };const struct inode_operations logfs_dir_iops = {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 21/79 SECURITY: remove nameidata arg from inode_follow_link.
In reply to Al ViroFrom: NeilBrown <[email protected]>
No ->inode_follow_link() methods use the nameidata arg, and it is about to become private to namei.c.
So remove from all inode_follow_link() functions.
--- fs/namei.c | 2 +- include/linux/security.h | 9 +++------ security/capability.c | 3 +-- security/security.c | 4 ++-- security/selinux/hooks.c | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-)
fs/namei.c +1 -1
@@ -871,7 +871,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)touch_atime (link);nd_set_link (nd,NULL ); - error =security_inode_follow_link (link->dentry, nd); + error =security_inode_follow_link (dentry);if (error) goto out_put_nd_path;
include/linux/security.h +3 -6
@@ -43,7 +43,6 @@ struct file;struct vfsmount ;struct path ;struct qstr ; -struct nameidata ;struct iattr ;struct fown_struct ;struct file_operations ;
@@ -477,7 +476,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @inode_follow_link: * Check permission to follow a symbolic link when looking up a pathname. * @dentry contains the dentry structure for the link. -* @nd contains the nameidata structure for the parent directory. * Return 0 if permission is granted. * @inode_permission: * Check permission before accessing an inode. This hook is called by the
@@ -1553,7 +1551,7 @@ struct security_operations {int (*inode_rename) (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry);int (*inode_readlink) (struct dentry *dentry); -int (*inode_follow_link) (struct dentry *dentry,struct nameidata *nd); +int (*inode_follow_link) (struct dentry *dentry);int (*inode_permission) (struct inode *inode,int mask);int (*inode_setattr) (struct dentry *dentry,struct iattr *attr);int (*inode_getattr) (const struct path *path);
@@ -1839,7 +1837,7 @@ int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags);int security_inode_readlink (struct dentry *dentry); -int security_inode_follow_link (struct dentry *dentry,struct nameidata *nd); +int security_inode_follow_link (struct dentry *dentry);int security_inode_permission (struct inode *inode,int mask);int security_inode_setattr (struct dentry *dentry,struct iattr *attr);int security_inode_getattr (const struct path *path);
@@ -2241,8 +2239,7 @@ static inline int security_inode_readlink(struct dentry *dentry)return 0 ; } -static inline int security_inode_follow_link (struct dentry *dentry, -struct nameidata *nd) +static inline int security_inode_follow_link (struct dentry *dentry) {return 0 ; }
security/capability.c +1 -2
@@ -209,8 +209,7 @@ static int cap_inode_readlink(struct dentry *dentry)return 0 ; } -static int cap_inode_follow_link (struct dentry *dentry, -struct nameidata *nameidata) +static int cap_inode_follow_link (struct dentry *dentry) {return 0 ; }
security/security.c +2 -2
@@ -581,11 +581,11 @@ int security_inode_readlink(struct dentry *dentry)return security_ops->inode_readlink (dentry); } -int security_inode_follow_link (struct dentry *dentry,struct nameidata *nd) +int security_inode_follow_link (struct dentry *dentry) {if (unlikely (IS_PRIVATE (d_backing_inode (dentry))))return 0 ; -return security_ops->inode_follow_link (dentry, nd); +return security_ops->inode_follow_link (dentry); }int security_inode_permission (struct inode *inode,int mask)
security/selinux/hooks.c +1 -1
@@ -2861,7 +2861,7 @@ static int selinux_inode_readlink(struct dentry *dentry)return dentry_has_perm (cred, dentry,FILE__READ ); } -static int selinux_inode_follow_link (struct dentry *dentry,struct nameidata *nameidata) +static int selinux_inode_follow_link (struct dentry *dentry) {const struct cred *cred =current_cred ();
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 22/79 uninline walk_component()
In reply to Al ViroFrom: Al Viro <[email protected]>
seriously improves the stack *and* I-cache footprint...
--- fs/namei.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/namei.c +1 -2
@@ -1561,8 +1561,7 @@ static inline int should_follow_link(struct dentry *dentry, int follow)return unlikely (d_is_symlink (dentry)) ? follow :0 ; } -static inline int walk_component (struct nameidata *nd,struct path *path, -int follow) +static int walk_component (struct nameidata *nd,struct path *path,int follow) {struct inode *inode;int err;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 23/79 namei: take O_NOFOLLOW treatment into do_last()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/namei.c +5 -6
@@ -3052,6 +3052,11 @@ finish_lookup: } }BUG_ON (inode != path->dentry->d_inode); +if (!(nd->flags &LOOKUP_FOLLOW )) { +path_put_conditional (path, nd); +path_put (&nd->path); +return -ELOOP ; + }return 1 ; }
@@ -3236,12 +3241,6 @@ static struct file *path_openat(int dfd, struct filename *pathname,while (unlikely (error >0 )) {/* trailing symlink */ struct path link = path;void *cookie; -if (!(nd->flags &LOOKUP_FOLLOW )) { -path_put_conditional (&path, nd); -path_put (&nd->path); - error = -ELOOP ; -break ; - } error =may_follow_link (&link, nd);if (unlikely (error))break ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 24/79 do_last: kill symlink_ok
In reply to Al ViroFrom: Al Viro <[email protected]>
When O_PATH is present, O_CREAT isn't, so symlink_ok is always equal to (open_flags & O_PATH) && !(nd->flags & LOOKUP_FOLLOW).
--- fs/namei.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/namei.c +2 -4
@@ -2923,7 +2923,6 @@ static int do_last(struct nameidata *nd, struct path *path,bool got_write = false;int acc_mode = op->acc_mode;struct inode *inode; -bool symlink_ok = false;struct path save_parent = { .dentry =NULL , .mnt =NULL };bool retried = false;int error;
@@ -2941,8 +2940,6 @@ static int do_last(struct nameidata *nd, struct path *path,if (!(open_flag &O_CREAT )) {if (nd->last.name[nd->last.len]) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; -if (open_flag &O_PATH && !(nd->flags &LOOKUP_FOLLOW )) - symlink_ok = true;/* we _can_ be in RCU mode here */ error =lookup_fast (nd, path, &inode);if (likely (!error))
@@ -3043,7 +3040,8 @@ finish_lookup: goto out; } -if (should_follow_link (path->dentry, !symlink_ok)) { +if (should_follow_link (path->dentry, + !(open_flag &O_PATH ) || (nd->flags &LOOKUP_FOLLOW ))) {if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path->mnt ||unlazy_walk (nd, path->dentry))) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 25/79 do_last: regularize the logics around following symlinks
In reply to Al ViroFrom: Al Viro <[email protected]>
With LOOKUP_FOLLOW we unlazy and return 1; without it we either fail with ELOOP or, for O_PATH opens, succeed. No need to mix those cases...
--- fs/namei.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/namei.c +7 -7
@@ -3040,8 +3040,7 @@ finish_lookup: goto out; } -if (should_follow_link (path->dentry, - !(open_flag &O_PATH ) || (nd->flags &LOOKUP_FOLLOW ))) { +if (should_follow_link (path->dentry, nd->flags &LOOKUP_FOLLOW )) {if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path->mnt ||unlazy_walk (nd, path->dentry))) {
@@ -3050,14 +3049,15 @@ finish_lookup: } }BUG_ON (inode != path->dentry->d_inode); -if (!(nd->flags &LOOKUP_FOLLOW )) { -path_put_conditional (path, nd); -path_put (&nd->path); -return -ELOOP ; - }return 1 ; } +if (unlikely (d_is_symlink (path->dentry)) && !(open_flag &O_PATH )) { +path_to_nameidata (path, nd); + error = -ELOOP ; + goto out; + } +if ((nd->flags &LOOKUP_RCU ) || nd->path.mnt != path->mnt) {path_to_nameidata (path, nd); }else {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 26/79 namei: get rid of lookup_hash()
In reply to Al ViroFrom: Al Viro <[email protected]>
it's a convenient helper, but we'll want to shift nameidata down the call chain, so it won't be available there...
--- fs/namei.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
fs/namei.c +5 -15
@@ -2120,16 +2120,6 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, }EXPORT_SYMBOL (vfs_path_lookup); -/* -* Restricted form of lookup. Doesn't follow links, single-component only, -* needs parent already locked. Doesn't follow mounts. -* SMP-safe. -*/ -static struct dentry *lookup_hash (struct nameidata *nd) -{ -return __lookup_hash (&nd->last, nd->path.dentry, nd->flags); -} -/** * lookup_one_len - filesystem helper to lookup single pathname component * @name: pathname component to lookup
@@ -3344,7 +3334,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,* Do the final lookup. */ mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags);if (IS_ERR (dentry)) goto unlock;
@@ -3658,7 +3648,7 @@ retry: goto exit1;mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2;
@@ -3778,7 +3768,7 @@ retry: goto exit1; retry_deleg:mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {/* Why not before? Because we want correct error value */
@@ -4297,7 +4287,7 @@ retry: retry_deleg: trap =lock_rename (new_dir, old_dir); - old_dentry =lookup_hash (&oldnd); + old_dentry =__lookup_hash (&oldnd.last, oldnd.path.dentry, oldnd.flags); error =PTR_ERR (old_dentry);if (IS_ERR (old_dentry)) goto exit3;
@@ -4305,7 +4295,7 @@ retry_deleg: error = -ENOENT ;if (d_is_negative (old_dentry)) goto exit4; - new_dentry =lookup_hash (&newnd); + new_dentry =__lookup_hash (&newnd.last, newnd.path.dentry, newnd.flags); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto exit4;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 27/79 name: shift nameidata down into user_path_walk()
In reply to Al ViroFrom: Al Viro <[email protected]>
that avoids having nameidata on stack during the calls of ->rmdir()/->unlink() and *two* of those during the calls of ->rename().
--- fs/namei.c | 124 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 67 insertions(+), 57 deletions(-)
fs/namei.c +67 -57
@@ -2203,9 +2203,13 @@ EXPORT_SYMBOL(user_path_at);* path-walking is complete. */ static struct filename * -user_path_parent (int dfd,const char __user *path,struct nameidata *nd, +user_path_parent (int dfd,const char __user *path, +struct path *parent, +struct qstr *last, +int *type,unsigned int flags) { +struct nameidata nd;struct filename *s =getname (path);int error;
@@ -2215,11 +2219,14 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd,if (IS_ERR (s))return s; - error =filename_lookup (dfd, s, flags |LOOKUP_PARENT , nd); + error =filename_lookup (dfd, s, flags |LOOKUP_PARENT , &nd);if (error) {putname (s);return ERR_PTR (error); } + *parent = nd.path; + *last = nd.last; + *type = nd.last_type;return s; }
@@ -3623,14 +3630,17 @@ static long do_rmdir(int dfd, const char __user *pathname)int error =0 ;struct filename *name;struct dentry *dentry; -struct nameidata nd; +struct path path; +struct qstr last; +int type;unsigned int lookup_flags =0 ; retry: - name =user_path_parent (dfd, pathname, &nd, lookup_flags); + name =user_path_parent (dfd, pathname, + &path, &last, &type, lookup_flags);if (IS_ERR (name))return PTR_ERR (name); -switch (nd.last_type) { +switch (type) {case LAST_DOTDOT : error = -ENOTEMPTY ; goto exit1;
@@ -3642,13 +3652,12 @@ retry: goto exit1; } - nd.flags &= ~LOOKUP_PARENT ; - error =mnt_want_write (nd.path.mnt); + error =mnt_want_write (path.mnt);if (error) goto exit1; -mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); +mutex_lock_nested (&path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); + dentry =__lookup_hash (&last, path.dentry, lookup_flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2;
@@ -3656,17 +3665,17 @@ retry: error = -ENOENT ; goto exit3; } - error =security_path_rmdir (&nd.path, dentry); + error =security_path_rmdir (&path, dentry);if (error) goto exit3; - error =vfs_rmdir (nd.path.dentry->d_inode, dentry); + error =vfs_rmdir (path.dentry->d_inode, dentry); exit3:dput (dentry); exit2: -mutex_unlock (&nd.path.dentry->d_inode->i_mutex); -mnt_drop_write (nd.path.mnt); +mutex_unlock (&path.dentry->d_inode->i_mutex); +mnt_drop_write (path.mnt); exit1: -path_put (&nd.path); +path_put (&path);putname (name);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ;
@@ -3749,43 +3758,45 @@ static long do_unlinkat(int dfd, const char __user *pathname)int error;struct filename *name;struct dentry *dentry; -struct nameidata nd; +struct path path; +struct qstr last; +int type;struct inode *inode =NULL ;struct inode *delegated_inode =NULL ;unsigned int lookup_flags =0 ; retry: - name =user_path_parent (dfd, pathname, &nd, lookup_flags); + name =user_path_parent (dfd, pathname, + &path, &last, &type, lookup_flags);if (IS_ERR (name))return PTR_ERR (name); error = -EISDIR ; -if (nd.last_type !=LAST_NORM ) +if (type !=LAST_NORM ) goto exit1; - nd.flags &= ~LOOKUP_PARENT ; - error =mnt_want_write (nd.path.mnt); + error =mnt_want_write (path.mnt);if (error) goto exit1; retry_deleg: -mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); +mutex_lock_nested (&path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); + dentry =__lookup_hash (&last, path.dentry, lookup_flags); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {/* Why not before? Because we want correct error value */ -if (nd.last.name[nd.last.len]) +if (last.name[last.len]) goto slashes; inode = dentry->d_inode;if (d_is_negative (dentry)) goto slashes;ihold (inode); - error =security_path_unlink (&nd.path, dentry); + error =security_path_unlink (&path, dentry);if (error) goto exit2; - error =vfs_unlink (nd.path.dentry->d_inode, dentry, &delegated_inode); + error =vfs_unlink (path.dentry->d_inode, dentry, &delegated_inode); exit2:dput (dentry); } -mutex_unlock (&nd.path.dentry->d_inode->i_mutex); +mutex_unlock (&path.dentry->d_inode->i_mutex);if (inode)iput (inode);/* truncate the inode here */ inode =NULL ;
@@ -3794,9 +3805,9 @@ exit2:if (!error) goto retry_deleg; } -mnt_drop_write (nd.path.mnt); +mnt_drop_write (path.mnt); exit1: -path_put (&nd.path); +path_put (&path);putname (name);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ;
@@ -4226,14 +4237,15 @@ EXPORT_SYMBOL(vfs_rename); SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname, unsigned int, flags) { -struct dentry *old_dir, *new_dir;struct dentry *old_dentry, *new_dentry;struct dentry *trap; -struct nameidata oldnd, newnd; +struct path old_path, new_path; +struct qstr old_last, new_last; +int old_type, new_type;struct inode *delegated_inode =NULL ;struct filename *from;struct filename *to; -unsigned int lookup_flags =0 ; +unsigned int lookup_flags =0 , target_flags =LOOKUP_RENAME_TARGET ;bool should_retry = false;int error;
@@ -4247,47 +4259,45 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname,if ((flags &RENAME_WHITEOUT ) && !capable (CAP_MKNOD ))return -EPERM ; +if (flags &RENAME_EXCHANGE ) + target_flags =0 ; + retry: - from =user_path_parent (olddfd, oldname, &oldnd, lookup_flags); + from =user_path_parent (olddfd, oldname, + &old_path, &old_last, &old_type, lookup_flags);if (IS_ERR (from)) { error =PTR_ERR (from); goto exit; } - to =user_path_parent (newdfd, newname, &newnd, lookup_flags); + to =user_path_parent (newdfd, newname, + &new_path, &new_last, &new_type, lookup_flags);if (IS_ERR (to)) { error =PTR_ERR (to); goto exit1; } error = -EXDEV ; -if (oldnd.path.mnt != newnd.path.mnt) +if (old_path.mnt != new_path.mnt) goto exit2; - old_dir = oldnd.path.dentry; error = -EBUSY ; -if (oldnd.last_type !=LAST_NORM ) +if (old_type !=LAST_NORM ) goto exit2; - new_dir = newnd.path.dentry;if (flags &RENAME_NOREPLACE ) error = -EEXIST ; -if (newnd.last_type !=LAST_NORM ) +if (new_type !=LAST_NORM ) goto exit2; - error =mnt_want_write (oldnd.path.mnt); + error =mnt_want_write (old_path.mnt);if (error) goto exit2; - oldnd.flags &= ~LOOKUP_PARENT ; - newnd.flags &= ~LOOKUP_PARENT ; -if (!(flags &RENAME_EXCHANGE )) - newnd.flags |=LOOKUP_RENAME_TARGET ; - retry_deleg: - trap =lock_rename (new_dir, old_dir); + trap =lock_rename (new_path.dentry, old_path.dentry); - old_dentry =__lookup_hash (&oldnd.last, oldnd.path.dentry, oldnd.flags); + old_dentry =__lookup_hash (&old_last, old_path.dentry, lookup_flags); error =PTR_ERR (old_dentry);if (IS_ERR (old_dentry)) goto exit3;
@@ -4295,7 +4305,7 @@ retry_deleg: error = -ENOENT ;if (d_is_negative (old_dentry)) goto exit4; - new_dentry =__lookup_hash (&newnd.last, newnd.path.dentry, newnd.flags); + new_dentry =__lookup_hash (&new_last, new_path.dentry, lookup_flags | target_flags); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto exit4;
@@ -4309,16 +4319,16 @@ retry_deleg:if (!d_is_dir (new_dentry)) { error = -ENOTDIR ; -if (newnd.last.name[newnd.last.len]) +if (new_last.name[new_last.len]) goto exit5; } }/* unless the source is a directory trailing slashes give -ENOTDIR */ if (!d_is_dir (old_dentry)) { error = -ENOTDIR ; -if (oldnd.last.name[oldnd.last.len]) +if (old_last.name[old_last.len]) goto exit5; -if (!(flags &RENAME_EXCHANGE ) && newnd.last.name[newnd.last.len]) +if (!(flags &RENAME_EXCHANGE ) && new_last.name[new_last.len]) goto exit5; }/* source should not be ancestor of target */
@@ -4331,32 +4341,32 @@ retry_deleg:if (new_dentry == trap) goto exit5; - error =security_path_rename (&oldnd.path, old_dentry, - &newnd.path, new_dentry, flags); + error =security_path_rename (&old_path, old_dentry, + &new_path, new_dentry, flags);if (error) goto exit5; - error =vfs_rename (old_dir->d_inode, old_dentry, - new_dir->d_inode, new_dentry, + error =vfs_rename (old_path.dentry->d_inode, old_dentry, + new_path.dentry->d_inode, new_dentry, &delegated_inode, flags); exit5:dput (new_dentry); exit4:dput (old_dentry); exit3: -unlock_rename (new_dir, old_dir); +unlock_rename (new_path.dentry, old_path.dentry);if (delegated_inode) { error =break_deleg_wait (&delegated_inode);if (!error) goto retry_deleg; } -mnt_drop_write (oldnd.path.mnt); +mnt_drop_write (old_path.mnt); exit2:if (retry_estale (error, lookup_flags)) should_retry = true; -path_put (&newnd.path); +path_put (&new_path);putname (to); exit1: -path_put (&oldnd.path); +path_put (&old_path);putname (from);if (should_retry) { should_retry = false;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 28/79 namei: lift nameidata into filename_mountpoint()
In reply to Al ViroFrom: Al Viro <[email protected]>
when we go for on-demand allocation of saved state in link_path_walk(), we'll want nameidata to stay around for all 3 calls of path_mountpoint().
--- fs/namei.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
fs/namei.c +13 -15
@@ -2336,31 +2336,28 @@ out:*/ static int path_mountpoint (int dfd,const struct filename *name,struct path *path, -unsigned int flags) +struct nameidata *nd,unsigned int flags) { -struct nameidata nd; -int err; - - err =path_init (dfd, name, flags, &nd); +int err =path_init (dfd, name, flags, nd);if (unlikely (err)) goto out; - err =mountpoint_last (&nd, path); + err =mountpoint_last (nd, path);while (err >0 ) {void *cookie;struct path link = *path; - err =may_follow_link (&link, &nd); + err =may_follow_link (&link, nd);if (unlikely (err))break ; - nd.flags |=LOOKUP_PARENT ; - err =follow_link (&link, &nd, &cookie); + nd->flags |=LOOKUP_PARENT ; + err =follow_link (&link, nd, &cookie);if (err)break ; - err =mountpoint_last (&nd, path); -put_link (&nd, &link, cookie); + err =mountpoint_last (nd, path); +put_link (nd, &link, cookie); } out: -path_cleanup (&nd); +path_cleanup (nd);return err; }
@@ -2368,14 +2365,15 @@ static int filename_mountpoint(int dfd, struct filename *name, struct path *path, unsigned int flags) { + struct nameidata nd;int error;if (IS_ERR (name))return PTR_ERR (name); - error =path_mountpoint (dfd, name, path, flags |LOOKUP_RCU ); + error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_RCU );if (unlikely (error == -ECHILD )) - error =path_mountpoint (dfd, name, path, flags); + error =path_mountpoint (dfd, name, path, &nd, flags);if (unlikely (error == -ESTALE )) - error =path_mountpoint (dfd, name, path, flags |LOOKUP_REVAL ); + error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_REVAL );if (likely (!error))audit_inode (name, path->dentry,0 );putname (name);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 29/79 new ->follow_link() and ->put_link() calling conventions
In reply to Al ViroFrom: Al Viro <[email protected]>
a) instead of storing the symlink body (via nd_set_link()) and returning an opaque pointer later passed to ->put_link(), ->follow_link() _stores_ that opaque pointer (into void * passed by address by caller) and returns the symlink body. Returning ERR_PTR() on error, NULL on jump (procfs magic symlinks) and pointer to symlink body for normal symlinks. Stored pointer is ignored in all cases except the last one.
Storing NULL for opaque pointer (or not storing it at all) means no call of ->put_link().
b) the body used to be passed to ->put_link() implicitly (via nameidata). Now only the opaque pointer is. In the cases when we used the symlink body to free stuff, ->follow_link() now should store it as opaque pointer in addition to returning it.
--- Documentation/filesystems/Locking | 4 +- Documentation/filesystems/vfs.txt | 4 +- drivers/staging/lustre/lustre/llite/symlink.c | 11 ++--- fs/9p/vfs_inode.c | 13 +++--- fs/9p/vfs_inode_dotl.c | 7 ++- fs/autofs4/symlink.c | 5 +- fs/befs/linuxvfs.c | 35 +++++++------- fs/cifs/cifsfs.h | 2 +- fs/cifs/link.c | 28 ++++++------ fs/configfs/symlink.c | 28 +++++------- fs/ecryptfs/inode.c | 8 ++-- fs/ext4/symlink.c | 9 ++-- fs/f2fs/namei.c | 20 +++----- fs/fuse/dir.c | 19 ++------ fs/gfs2/inode.c | 10 ++-- fs/hostfs/hostfs_kern.c | 15 +++--- fs/hppfs/hppfs.c | 9 ++-- fs/kernfs/symlink.c | 22 ++++----- fs/libfs.c | 12 ++--- fs/namei.c | 66 +++++++++------------------ fs/nfs/symlink.c | 19 +++----- fs/overlayfs/inode.c | 18 ++++---- fs/proc/base.c | 2 +- fs/proc/inode.c | 9 ++-- fs/proc/namespaces.c | 2 +- fs/proc/self.c | 24 +++++----- fs/proc/thread_self.c | 22 ++++----- fs/xfs/xfs_iops.c | 10 ++-- include/linux/fs.h | 12 ++--- include/linux/namei.h | 2 - mm/shmem.c | 23 +++++----- 31 files changed, 195 insertions(+), 275 deletions(-)
Documentation/filesystems/Locking +2 -2
@@ -50,8 +50,8 @@ prototypes: int (*rename2) (struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); int (*readlink) (struct dentry *, char __user *,int); - void * (*follow_link) (struct dentry *, struct nameidata *); - void (*put_link) (struct dentry *, struct nameidata *, void *); + const char *(*follow_link) (struct dentry *, void **, struct nameidata *); + void (*put_link) (struct dentry *, void *); void (*truncate) (struct inode *); int (*permission) (struct inode *, int, unsigned int); int (*get_acl)(struct inode *, int);
Documentation/filesystems/vfs.txt +2 -2
@@ -350,8 +350,8 @@ struct inode_operations { int (*rename2) (struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); int (*readlink) (struct dentry *, char __user *,int); - void * (*follow_link) (struct dentry *, struct nameidata *); - void (*put_link) (struct dentry *, struct nameidata *, void *); + const char *(*follow_link) (struct dentry *, void **, struct nameidata *); + void (*put_link) (struct dentry *, void *); int (*permission) (struct inode *, int); int (*get_acl)(struct inode *, int); int (*setattr) (struct dentry *, struct iattr *);
drivers/staging/lustre/lustre/llite/symlink.c +5 -6
@@ -118,7 +118,7 @@ failed:return rc; } -static void *ll_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *ll_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (dentry);struct ptlrpc_request *request =NULL ;
@@ -140,18 +140,17 @@ static void *ll_follow_link(struct dentry *dentry, struct nameidata *nd) }if (rc) {ptlrpc_req_finished (request); - request =NULL ; - symname =ERR_PTR (rc); +return ERR_PTR (rc); } -nd_set_link (nd, symname);/* symname may contain a pointer to the request message buffer, * we delay request releasing until ll_put_link then. */ -return request; + *cookie = request; +return symname; } -static void ll_put_link (struct dentry *dentry,struct nameidata *nd,void *cookie) +static void ll_put_link (struct dentry *dentry,void *cookie) {ptlrpc_req_finished (cookie); }
fs/9p/vfs_inode.c +7 -6
@@ -1230,11 +1230,12 @@ ino_t v9fs_qid2ino(struct p9_qid *qid)* */ -static void *v9fs_vfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *v9fs_vfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct v9fs_session_info *v9ses =v9fs_dentry2v9ses (dentry);struct p9_fid *fid =v9fs_fid_lookup (dentry);struct p9_wstat *st; +char *res;p9_debug (P9_DEBUG_VFS ,"%pd\n" , dentry);
@@ -1253,14 +1254,14 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)kfree (st);return ERR_PTR (-EINVAL ); } -if (strlen (st->extension) >=PATH_MAX ) - st->extension[PATH_MAX -1 ] ='\0' ; - -nd_set_link (nd, st->extension); + res = st->extension; st->extension =NULL ; +if (strlen (res) >=PATH_MAX ) + res[PATH_MAX -1 ] ='\0' ; +p9stat_free (st);kfree (st); -return NULL ; +return *cookie = res; }/**
fs/9p/vfs_inode_dotl.c +3 -4
@@ -909,8 +909,8 @@ error:* */ -static void * -v9fs_vfs_follow_link_dotl (struct dentry *dentry,struct nameidata *nd) +static const char * +v9fs_vfs_follow_link_dotl (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct p9_fid *fid =v9fs_fid_lookup (dentry);char *target;
@@ -923,8 +923,7 @@ v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) retval =p9_client_readlink (fid, &target);if (retval)return ERR_PTR (retval); -nd_set_link (nd, target); -return NULL ; +return *cookie = target; }int v9fs_refresh_inode_dotl (struct p9_fid *fid,struct inode *inode)
fs/autofs4/symlink.c +2 -3
@@ -12,14 +12,13 @@#include "autofs_i.h" -static void *autofs4_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *autofs4_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct autofs_sb_info *sbi =autofs4_sbi (dentry->d_sb);struct autofs_info *ino =autofs4_dentry_ino (dentry);if (ino && !autofs4_oz_mode (sbi)) ino->last_used = jiffies; -nd_set_link (nd,d_inode (dentry)->i_private); -return NULL ; +return d_inode (dentry)->i_private; }const struct inode_operations autofs4_symlink_inode_operations = {
fs/befs/linuxvfs.c +16 -19
@@ -42,7 +42,7 @@ static struct inode *befs_iget(struct super_block *, unsigned long);static struct inode *befs_alloc_inode (struct super_block *sb);static void befs_destroy_inode (struct inode *inode);static void befs_destroy_inodecache (void ); -static void *befs_follow_link (struct dentry *,struct nameidata *); +static const char *befs_follow_link (struct dentry *,void **,struct nameidata *nd);static int befs_utf2nls (struct super_block *sb,const char *in,int in_len,char **out,int *out_len); static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,
@@ -463,8 +463,8 @@ befs_destroy_inodecache(void)* The data stream become link name. Unless the LONG_SYMLINK * flag is set. */ -static void * -befs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char * +befs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct super_block *sb = dentry->d_sb;struct befs_inode_info *befs_ino =BEFS_I (d_inode (dentry));
@@ -474,23 +474,20 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)if (len ==0 ) {befs_error (sb,"Long symlink with illegal length" ); - link =ERR_PTR (-EIO ); - }else { -befs_debug (sb,"Follow long symlink" ); - - link =kmalloc (len,GFP_NOFS ); -if (!link) { - link =ERR_PTR (-ENOMEM ); - }else if (befs_read_lsymlink (sb, data, link, len) != len) { -kfree (link); -befs_error (sb,"Failed to read entire long symlink" ); - link =ERR_PTR (-EIO ); - }else { - link[len -1 ] ='\0' ; - } +return ERR_PTR (-EIO ); } -nd_set_link (nd, link); -return NULL ; +befs_debug (sb,"Follow long symlink" ); + + link =kmalloc (len,GFP_NOFS ); +if (!link) +return ERR_PTR (-ENOMEM ); +if (befs_read_lsymlink (sb, data, link, len) != len) { +kfree (link); +befs_error (sb,"Failed to read entire long symlink" ); +return ERR_PTR (-EIO ); + } + link[len -1 ] ='\0' ; +return *cookie = link; }/*
fs/cifs/cifsfs.h +1 -1
@@ -120,7 +120,7 @@ extern struct vfsmount *cifs_dfs_d_automount(struct path *path);#endif /* Functions related to symlinks */ -extern void *cifs_follow_link (struct dentry *direntry,struct nameidata *nd); +extern const char *cifs_follow_link (struct dentry *direntry,void **cookie,struct nameidata *nd);extern int cifs_readlink (struct dentry *direntry,char __user *buffer,int buflen); extern int cifs_symlink(struct inode *inode, struct dentry *direntry,
fs/cifs/link.c +13 -15
@@ -626,8 +626,8 @@ cifs_hl_exit:return rc; } -void * -cifs_follow_link (struct dentry *direntry,struct nameidata *nd) +const char * +cifs_follow_link (struct dentry *direntry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (direntry);int rc = -ENOMEM ;
@@ -643,16 +643,18 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) tlink =cifs_sb_tlink (cifs_sb);if (IS_ERR (tlink)) { - rc =PTR_ERR (tlink); - tlink =NULL ; - goto out; +free_xid (xid); +return ERR_CAST (tlink); } tcon =tlink_tcon (tlink); server = tcon->ses->server; full_path =build_path_from_dentry (direntry); -if (!full_path) - goto out; +if (!full_path) { +free_xid (xid); +cifs_put_tlink (tlink); +return ERR_PTR (-ENOMEM ); + }cifs_dbg (FYI ,"Full path: %s inode = 0x%p\n" , full_path, inode);
@@ -670,17 +672,13 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd) &target_path, cifs_sb);kfree (full_path); -out: +free_xid (xid); +cifs_put_tlink (tlink);if (rc !=0 ) {kfree (target_path); - target_path =ERR_PTR (rc); +return ERR_PTR (rc); } - -free_xid (xid); -if (tlink) -cifs_put_tlink (tlink); -nd_set_link (nd, target_path); -return NULL ; +return *cookie = target_path; }int
fs/configfs/symlink.c +12 -16
@@ -279,30 +279,26 @@ static int configfs_getlink(struct dentry *dentry, char * path) } -static void *configfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *configfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) { -int error = -ENOMEM ;unsigned long page =get_zeroed_page (GFP_KERNEL ); +int error; -if (page) { - error =configfs_getlink (dentry, (char *)page); -if (!error) { -nd_set_link (nd, (char *)page); -return (void *)page; - } +if (!page) +return ERR_PTR (-ENOMEM ); + + error =configfs_getlink (dentry, (char *)page); +if (!error) { +return *cookie = (void *)page; } -nd_set_link (nd,ERR_PTR (error)); -return NULL ; +free_page (page); +return ERR_PTR (error); } -static void configfs_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) +static void configfs_put_link (struct dentry *dentry,void *cookie) { -if (cookie) { -unsigned long page = (unsigned long )cookie; -free_page (page); - } +free_page ((unsigned long )cookie); }const struct inode_operations configfs_symlink_inode_operations = {
fs/ecryptfs/inode.c +3 -5
@@ -675,18 +675,16 @@ out:return rc ?ERR_PTR (rc) : buf; } -static void *ecryptfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *ecryptfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {size_t len;char *buf =ecryptfs_readlink_lower (dentry, &len);if (IS_ERR (buf)) - goto out; +return buf;fsstack_copy_attr_atime (d_inode (dentry),d_inode (ecryptfs_dentry_to_lower (dentry))); buf[len] ='\0' ; -out: -nd_set_link (nd, buf); -return NULL ; +return *cookie = buf; }/**
fs/ext4/symlink.c +4 -5
@@ -23,7 +23,7 @@#include "xattr.h" #ifdef CONFIG_EXT4_FS_ENCRYPTION -static void *ext4_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *ext4_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct page *cpage =NULL ;char *caddr, *paddr =NULL ;
@@ -37,7 +37,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) ctx =ext4_get_fname_crypto_ctx (inode, inode->i_sb->s_blocksize);if (IS_ERR (ctx)) -return ctx; +return ERR_CAST (ctx);if (ext4_inode_is_fast_symlink (inode)) { caddr = (char *)EXT4_I (inode)->i_data;
@@ -46,7 +46,7 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd) cpage =read_mapping_page (inode->i_mapping,0 ,NULL );if (IS_ERR (cpage)) {ext4_put_fname_crypto_ctx (&ctx); -return cpage; +return ERR_CAST (cpage); } caddr =kmap (cpage); caddr[size] =0 ;
@@ -77,13 +77,12 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)/* Null-terminate the name */ if (res <= plen) paddr[res] ='\0' ; -nd_set_link (nd, paddr);ext4_put_fname_crypto_ctx (&ctx);if (cpage) {kunmap (cpage);page_cache_release (cpage); } -return NULL ; +return *cookie = paddr; errout:ext4_put_fname_crypto_ctx (&ctx);if (cpage) {
fs/f2fs/namei.c +7 -13
@@ -296,21 +296,15 @@ fail:return err; } -static void *f2fs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *f2fs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) { -struct page *page; - - page =page_follow_link_light (dentry, nd); -if (IS_ERR (page)) -return page; - -/* this is broken symlink case */ -if (*nd_get_link (nd) ==0 ) { -kunmap (page); -page_cache_release (page); -return ERR_PTR (-ENOENT ); +const char *link =page_follow_link_light (dentry, cookie, nd); +if (!IS_ERR (link) && !*link) { +/* this is broken symlink case */ +page_put_link (dentry, *cookie); + link =ERR_PTR (-ENOENT ); } -return page; +return link; } static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
fs/fuse/dir.c +4 -15
@@ -1365,7 +1365,7 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)return err; } -static char *read_link (struct dentry *dentry) +static const char *fuse_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (dentry);struct fuse_conn *fc =get_fuse_conn (inode);
@@ -1389,26 +1389,15 @@ static char *read_link(struct dentry *dentry) link =ERR_PTR (ret); }else { link[ret] ='\0' ; + *cookie = link; }fuse_invalidate_atime (inode);return link; } -static void free_link (char *link) +static void fuse_put_link (struct dentry *dentry,void *cookie) { -if (!IS_ERR (link)) -free_page ((unsigned long ) link); -} - -static void *fuse_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,read_link (dentry)); -return NULL ; -} - -static void fuse_put_link (struct dentry *dentry,struct nameidata *nd,void *c) -{ -free_link (nd_get_link (nd)); +free_page ((unsigned long ) cookie); }static int fuse_dir_open (struct inode *inode,struct file *file)
fs/gfs2/inode.c +5 -5
@@ -1548,7 +1548,7 @@ out:* Returns: 0 on success or error code */ -static void *gfs2_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *gfs2_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct gfs2_inode *ip =GFS2_I (d_inode (dentry));struct gfs2_holder i_gh;
@@ -1561,8 +1561,7 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd) error =gfs2_glock_nq (&i_gh);if (error) {gfs2_holder_uninit (&i_gh); -nd_set_link (nd,ERR_PTR (error)); -return NULL ; +return ERR_PTR (error); } size = (unsigned int )i_size_read (&ip->i_inode);
@@ -1586,8 +1585,9 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)brelse (dibh); out:gfs2_glock_dq_uninit (&i_gh); -nd_set_link (nd, buf); -return NULL ; +if (!IS_ERR (buf)) + *cookie = buf; +return buf; }/**
fs/hostfs/hostfs_kern.c +6 -9
@@ -892,7 +892,7 @@ static const struct inode_operations hostfs_dir_iops = { .setattr = hostfs_setattr, }; -static void *hostfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *hostfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {char *link =__getname ();if (link) {
@@ -906,21 +906,18 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd) }if (err <0 ) {__putname (link); - link =ERR_PTR (err); +return ERR_PTR (err); } }else { - link =ERR_PTR (-ENOMEM ); +return ERR_PTR (-ENOMEM ); } -nd_set_link (nd, link); -return NULL ; +return *cookie = link; } -static void hostfs_put_link (struct dentry *dentry,struct nameidata *nd,void *cookie) +static void hostfs_put_link (struct dentry *dentry,void *cookie) { -char *s =nd_get_link (nd); -if (!IS_ERR (s)) -__putname (s); +__putname (cookie); }static const struct inode_operations hostfs_link_iops = {
fs/hppfs/hppfs.c +4 -5
@@ -642,20 +642,19 @@ static int hppfs_readlink(struct dentry *dentry, char __user *buffer, buflen); } -static void *hppfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *hppfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct dentry *proc_dentry =HPPFS_I (d_inode (dentry))->proc_dentry; -return d_inode (proc_dentry)->i_op->follow_link (proc_dentry, nd); +return d_inode (proc_dentry)->i_op->follow_link (proc_dentry, cookie, nd); } -static void hppfs_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) +static void hppfs_put_link (struct dentry *dentry,void *cookie) {struct dentry *proc_dentry =HPPFS_I (d_inode (dentry))->proc_dentry;if (d_inode (proc_dentry)->i_op->put_link) -d_inode (proc_dentry)->i_op->put_link (proc_dentry, nd, cookie); +d_inode (proc_dentry)->i_op->put_link (proc_dentry, cookie); }static const struct inode_operations hppfs_dir_iops = {
fs/kernfs/symlink.c +10 -12
@@ -112,25 +112,23 @@ static int kernfs_getlink(struct dentry *dentry, char *path)return error; } -static void *kernfs_iop_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *kernfs_iop_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {int error = -ENOMEM ;unsigned long page =get_zeroed_page (GFP_KERNEL ); -if (page) { - error =kernfs_getlink (dentry, (char *) page); -if (error <0 ) -free_page ((unsigned long )page); +if (!page) +return ERR_PTR (-ENOMEM ); + error =kernfs_getlink (dentry, (char *)page); +if (unlikely (error <0 )) { +free_page ((unsigned long )page); +return ERR_PTR (error); } -nd_set_link (nd, error ?ERR_PTR (error) : (char *)page); -return NULL ; +return *cookie = (char *)page; } -static void kernfs_iop_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) +static void kernfs_iop_put_link (struct dentry *dentry,void *cookie) { -char *page =nd_get_link (nd); -if (!IS_ERR (page)) -free_page ((unsigned long )page); +free_page ((unsigned long )cookie); }const struct inode_operations kernfs_symlink_iops = {
fs/libfs.c +4 -8
@@ -1024,12 +1024,9 @@ int noop_fsync(struct file *file, loff_t start, loff_t end, int datasync) }EXPORT_SYMBOL (noop_fsync); -void kfree_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) +void kfree_put_link (struct dentry *dentry,void *cookie) { -char *s =nd_get_link (nd); -if (!IS_ERR (s)) -kfree (s); +kfree (cookie); }EXPORT_SYMBOL (kfree_put_link);
@@ -1094,10 +1091,9 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp, }EXPORT_SYMBOL (simple_nosetlease); -void *simple_follow_link (struct dentry *dentry,struct nameidata *nd) +const char *simple_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) { -nd_set_link (nd,d_inode (dentry)->i_link); -return NULL ; +return d_inode (dentry)->i_link; }EXPORT_SYMBOL (simple_follow_link);
fs/namei.c +21 -45
131 lines not on this page · raw message
fs/nfs/symlink.c +6 -13
@@ -20,7 +20,6 @@#include <linux/stat.h> #include <linux/mm.h> #include <linux/string.h> -#include <linux/namei.h> /* Symlink caching in the page cache is even more simplistic * and straight-forward than readdir caching.
@@ -43,7 +42,7 @@ error:return -EIO ; } -static void *nfs_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *nfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (dentry);struct page *page;
@@ -51,19 +50,13 @@ static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd) err =ERR_PTR (nfs_revalidate_mapping (inode, inode->i_mapping));if (err) - goto read_failed; +return err; page =read_cache_page (&inode->i_data,0 , (filler_t *)nfs_symlink_filler, inode); -if (IS_ERR (page)) { - err = page; - goto read_failed; - } -nd_set_link (nd,kmap (page)); -return page; - -read_failed: -nd_set_link (nd, err); -return NULL ; +if (IS_ERR (page)) +return ERR_CAST (page); + *cookie = page; +return kmap (page); }/*
fs/overlayfs/inode.c +10 -8
@@ -140,12 +140,12 @@ struct ovl_link_data {void *cookie; }; -static void *ovl_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *ovl_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) { -void *ret;struct dentry *realdentry;struct inode *realinode;struct ovl_link_data *data =NULL ; +const char *ret; realdentry =ovl_dentry_real (dentry); realinode = realdentry->d_inode;
@@ -160,19 +160,21 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd) data->realdentry = realdentry; } - ret = realinode->i_op->follow_link (realdentry, nd); -if (IS_ERR (ret)) { + ret = realinode->i_op->follow_link (realdentry, cookie, nd); +if (IS_ERR_OR_NULL (ret)) {kfree (data);return ret; }if (data) - data->cookie = ret; + data->cookie = *cookie; -return data; + *cookie = data; + +return ret; } -static void ovl_put_link (struct dentry *dentry,struct nameidata *nd,void *c) +static void ovl_put_link (struct dentry *dentry,void *c) {struct inode *realinode;struct ovl_link_data *data = c;
@@ -181,7 +183,7 @@ static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c)return ; realinode = data->realdentry->d_inode; - realinode->i_op->put_link (data->realdentry, nd, data->cookie); + realinode->i_op->put_link (data->realdentry, data->cookie);kfree (data); }
fs/proc/base.c +1 -1
@@ -1380,7 +1380,7 @@ static int proc_exe_link(struct dentry *dentry, struct path *exe_path)return -ENOENT ; } -static void *proc_pid_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *proc_pid_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (dentry);struct path path;
fs/proc/inode.c +4 -5
@@ -23,7 +23,6 @@#include <linux/slab.h> #include <linux/mount.h> #include <linux/magic.h> -#include <linux/namei.h> #include <asm/uaccess.h>
@@ -394,16 +393,16 @@ static const struct file_operations proc_reg_file_ops_no_compat = { };#endif -static void *proc_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *proc_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct proc_dir_entry *pde =PDE (d_inode (dentry));if (unlikely (!use_pde (pde)))return ERR_PTR (-EINVAL ); -nd_set_link (nd, pde->data); -return pde; + *cookie = pde; +return pde->data; } -static void proc_put_link (struct dentry *dentry,struct nameidata *nd,void *p) +static void proc_put_link (struct dentry *dentry,void *p) {unuse_pde (p); }
fs/proc/namespaces.c +1 -1
@@ -30,7 +30,7 @@ static const struct proc_ns_operations *ns_entries[] = { &mntns_operations, }; -static void *proc_ns_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *proc_ns_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct inode *inode =d_inode (dentry);const struct proc_ns_operations *ns_ops =PROC_I (inode)->ns_ops;
fs/proc/self.c +11 -13
@@ -1,5 +1,4 @@#include <linux/sched.h> -#include <linux/namei.h> #include <linux/slab.h> #include <linux/pid_namespace.h> #include "internal.h"
@@ -19,21 +18,20 @@ static int proc_self_readlink(struct dentry *dentry, char __user *buffer,return readlink_copy (buffer, buflen, tmp); } -static void *proc_self_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *proc_self_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct pid_namespace *ns = dentry->d_sb->s_fs_info;pid_t tgid =task_tgid_nr_ns (current, ns); -char *name =ERR_PTR (-ENOENT ); -if (tgid) { -/* 11 for max length of signed int in decimal + NULL term */ - name =kmalloc (12 ,GFP_KERNEL ); -if (!name) - name =ERR_PTR (-ENOMEM ); -else -sprintf (name,"%d" , tgid); - } -nd_set_link (nd, name); -return NULL ; +char *name; + +if (!tgid) +return ERR_PTR (-ENOENT ); +/* 11 for max length of signed int in decimal + NULL term */ + name =kmalloc (12 ,GFP_KERNEL ); +if (!name) +return ERR_PTR (-ENOMEM ); +sprintf (name,"%d" , tgid); +return *cookie = name; }static const struct inode_operations proc_self_inode_operations = {
fs/proc/thread_self.c +10 -12
@@ -1,5 +1,4 @@#include <linux/sched.h> -#include <linux/namei.h> #include <linux/slab.h> #include <linux/pid_namespace.h> #include "internal.h"
@@ -20,21 +19,20 @@ static int proc_thread_self_readlink(struct dentry *dentry, char __user *buffer,return readlink_copy (buffer, buflen, tmp); } -static void *proc_thread_self_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *proc_thread_self_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct pid_namespace *ns = dentry->d_sb->s_fs_info;pid_t tgid =task_tgid_nr_ns (current, ns);pid_t pid =task_pid_nr_ns (current, ns); -char *name =ERR_PTR (-ENOENT ); -if (pid) { - name =kmalloc (PROC_NUMBUF +6 +PROC_NUMBUF ,GFP_KERNEL ); -if (!name) - name =ERR_PTR (-ENOMEM ); -else -sprintf (name,"%d/task/%d" , tgid, pid); - } -nd_set_link (nd, name); -return NULL ; +char *name; + +if (!pid) +return ERR_PTR (-ENOENT ); + name =kmalloc (PROC_NUMBUF +6 +PROC_NUMBUF ,GFP_KERNEL ); +if (!name) +return ERR_PTR (-ENOMEM ); +sprintf (name,"%d/task/%d" , tgid, pid); +return *cookie = name; }static const struct inode_operations proc_thread_self_inode_operations = {
fs/xfs/xfs_iops.c +4 -6
@@ -41,7 +41,6 @@#include <linux/capability.h> #include <linux/xattr.h> -#include <linux/namei.h> #include <linux/posix_acl.h> #include <linux/security.h> #include <linux/fiemap.h>
@@ -414,9 +413,10 @@ xfs_vn_rename(* we need to be very careful about how much stack we use. * uio is kmalloced for this reason... */ -STATIC void * +STATIC const char *xfs_vn_follow_link (struct dentry *dentry, +void **cookie,struct nameidata *nd) {char *link;
@@ -430,14 +430,12 @@ xfs_vn_follow_link(if (unlikely (error)) goto out_kfree; -nd_set_link (nd, link); -return NULL ; +return *cookie = link; out_kfree:kfree (link); out_err: -nd_set_link (nd,ERR_PTR (error)); -return NULL ; +return ERR_PTR (error); }STATIC int
include/linux/fs.h +6 -6
@@ -1608,12 +1608,12 @@ struct file_operations {struct inode_operations {struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int ); -void * (*follow_link) (struct dentry *,struct nameidata *); +const char * (*follow_link) (struct dentry *,void **,struct nameidata *);int (*permission) (struct inode *,int );struct posix_acl * (*get_acl)(struct inode *,int );int (*readlink) (struct dentry *,char __user *,int ); -void (*put_link) (struct dentry *,struct nameidata *,void *); +void (*put_link) (struct dentry *,void *);int (*create) (struct inode *,struct dentry *,umode_t ,bool );int (*link) (struct dentry *,struct inode *,struct dentry *);
@@ -2705,13 +2705,13 @@ extern const struct file_operations generic_ro_fops;extern int readlink_copy (char __user *,int ,const char *);extern int page_readlink (struct dentry *,char __user *,int ); -extern void *page_follow_link_light (struct dentry *,struct nameidata *); -extern void page_put_link (struct dentry *,struct nameidata *,void *); +extern const char *page_follow_link_light (struct dentry *,void **,struct nameidata *); +extern void page_put_link (struct dentry *,void *);extern int __page_symlink (struct inode *inode,const char *symname,int len,int nofs);extern int page_symlink (struct inode *inode,const char *symname,int len);extern const struct inode_operations page_symlink_inode_operations; -extern void kfree_put_link (struct dentry *,struct nameidata *,void *); +extern void kfree_put_link (struct dentry *,void *);extern int generic_readlink (struct dentry *,char __user *,int );extern void generic_fillattr (struct inode *,struct kstat *);int vfs_getattr_nosec (struct path *path,struct kstat *stat);
@@ -2722,7 +2722,7 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes);void inode_sub_bytes (struct inode *inode,loff_t bytes);loff_t inode_get_bytes (struct inode *inode);void inode_set_bytes (struct inode *inode,loff_t bytes); -void *simple_follow_link (struct dentry *,struct nameidata *); +const char *simple_follow_link (struct dentry *,void **,struct nameidata *);extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);
include/linux/namei.h +0 -2
@@ -71,8 +71,6 @@ extern struct dentry *lock_rename(struct dentry *, struct dentry *);extern void unlock_rename (struct dentry *,struct dentry *);extern void nd_jump_link (struct nameidata *nd,struct path *path); -extern void nd_set_link (struct nameidata *nd,char *path); -extern char *nd_get_link (struct nameidata *nd);static inline void nd_terminate_link (void *name,size_t len,size_t maxlen) {
mm/shmem.c +11 -12
@@ -2475,24 +2475,23 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn 0 ; } -static void *shmem_follow_link (struct dentry *dentry,struct nameidata *nd) +static const char *shmem_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) {struct page *page =NULL ;int error =shmem_getpage (d_inode (dentry),0 , &page,SGP_READ ,NULL ); -nd_set_link (nd, error ?ERR_PTR (error) :kmap (page)); -if (page) -unlock_page (page); -return page; +if (error) +return ERR_PTR (error); +unlock_page (page); + *cookie = page; +return kmap (page); } -static void shmem_put_link (struct dentry *dentry,struct nameidata *nd,void *cookie) +static void shmem_put_link (struct dentry *dentry,void *cookie) { -if (!IS_ERR (nd_get_link (nd))) { -struct page *page = cookie; -kunmap (page); -mark_page_accessed (page); -page_cache_release (page); - } +struct page *page = cookie; +kunmap (page); +mark_page_accessed (page); +page_cache_release (page); }#ifdef CONFIG_TMPFS_XATTR
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 30/79 namei.c: separate the parts of follow_link() that find the link body
In reply to Al ViroFrom: Al Viro <[email protected]>
Split a piece of fs/namei.c:follow_link() that does obtaining the link body into a separate function. follow_link() itself is converted to calling get_link() and then doing the body traversal (if any).
The next step will expand follow_link() call in link_path_walk() and this helps to keep the size down...
--- fs/namei.c | 65 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 29 deletions(-)
fs/namei.c +36 -29
@@ -836,21 +836,22 @@ static int may_linkat(struct path *link)return -EPERM ; } -static __always_inline int -follow_link (struct path *link,struct nameidata *nd,void **p) +static __always_inline const char * +get_link (struct path *link,struct nameidata *nd,void **p) {struct dentry *dentry = link->dentry; +struct inode *inode = dentry->d_inode;int error; -const char *s; +const char *res;BUG_ON (nd->flags &LOOKUP_RCU );if (link->mnt == nd->path.mnt)mntget (link->mnt); - error = -ELOOP ; + res =ERR_PTR (-ELOOP );if (unlikely (current->total_link_count >=40 )) - goto out_put_nd_path; + goto out;cond_resched (); current->total_link_count++;
@@ -858,37 +859,43 @@ follow_link(struct path *link, struct nameidata *nd, void **p)touch_atime (link); error =security_inode_follow_link (dentry); + res =ERR_PTR (error);if (error) - goto out_put_nd_path; + goto out; nd->last_type =LAST_BIND ; *p =NULL ; - s = dentry->d_inode->i_op->follow_link (dentry, p, nd); - error =PTR_ERR (s); -if (IS_ERR (s)) - goto out_put_nd_path; - - error =0 ; -if (s) { -if (*s =='/' ) { -if (!nd->root.mnt) -set_root (nd); -path_put (&nd->path); - nd->path = nd->root; -path_get (&nd->root); - nd->flags |=LOOKUP_JUMPED ; - } - nd->inode = nd->path.dentry->d_inode; - error =link_path_walk (s, nd); -if (unlikely (error)) -put_link (nd, link, *p); + res = inode->i_op->follow_link (dentry, p, nd); +if (IS_ERR (res)) { +out: +path_put (&nd->path); +path_put (link); } +return res; +} -return error; +static __always_inline int +follow_link (struct path *link,struct nameidata *nd,void **p) +{ +const char *s =get_link (link, nd, p); +int error; -out_put_nd_path: -path_put (&nd->path); -path_put (link); +if (unlikely (IS_ERR (s))) +return PTR_ERR (s); +if (unlikely (!s)) +return 0 ; +if (*s =='/' ) { +if (!nd->root.mnt) +set_root (nd); +path_put (&nd->path); + nd->path = nd->root; +path_get (&nd->root); + nd->flags |=LOOKUP_JUMPED ; + } + nd->inode = nd->path.dentry->d_inode; + error =link_path_walk (s, nd); +if (unlikely (error)) +put_link (nd, link, *p);return error; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 31/79 namei: don't bother with ->follow_link() if ->i_link is set
In reply to Al ViroFrom: Al Viro <[email protected]>
with new calling conventions it's trivial
Conflicts:
fs/namei.c
--- fs/namei.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
fs/namei.c +13 -7
@@ -865,11 +865,14 @@ get_link(struct path *link, struct nameidata *nd, void **p) nd->last_type =LAST_BIND ; *p =NULL ; - res = inode->i_op->follow_link (dentry, p, nd); -if (IS_ERR (res)) { + res = inode->i_link; +if (!res) { + res = inode->i_op->follow_link (dentry, p, nd); +if (IS_ERR (res)) { out: -path_put (&nd->path); -path_put (link); +path_put (&nd->path); +path_put (link); + } }return res; }
@@ -4411,11 +4414,14 @@ EXPORT_SYMBOL(readlink_copy);int generic_readlink (struct dentry *dentry,char __user *buffer,int buflen) {void *cookie; -const char *link = dentry->d_inode->i_op->follow_link (dentry, &cookie,NULL ); +const char *link = dentry->d_inode->i_link;int res; -if (IS_ERR (link)) -return PTR_ERR (link); +if (!link) { + link = dentry->d_inode->i_op->follow_link (dentry, &cookie,NULL ); +if (IS_ERR (link)) +return PTR_ERR (link); + } res =readlink_copy (buffer, buflen, link);if (cookie && dentry->d_inode->i_op->put_link) dentry->d_inode->i_op->put_link (dentry, cookie);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 32/79 namei: introduce nameidata->link
In reply to Al ViroFrom: Al Viro <[email protected]>
shares space with nameidata->next, walk_component() et.al. store the struct path of symlink instead of returning it into a variable passed by caller.
--- fs/namei.c | 62 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 28 deletions(-)
fs/namei.c +34 -28
@@ -494,7 +494,10 @@ EXPORT_SYMBOL(path_put);struct nameidata {struct path path; -struct qstr last; +union { +struct qstr last; +struct path link; + };struct path root;struct inode *inode;/* path.dentry.d_inode */ unsigned int flags;
@@ -1551,8 +1554,9 @@ static inline int should_follow_link(struct dentry *dentry, int follow)return unlikely (d_is_symlink (dentry)) ? follow :0 ; } -static int walk_component (struct nameidata *nd,struct path *path,int follow) +static int walk_component (struct nameidata *nd,int follow) { +struct path path;struct inode *inode;int err;/*
@@ -1562,38 +1566,39 @@ static int walk_component(struct nameidata *nd, struct path *path, int follow)*/ if (unlikely (nd->last_type !=LAST_NORM ))return handle_dots (nd, nd->last_type); - err =lookup_fast (nd, path, &inode); + err =lookup_fast (nd, &path, &inode);if (unlikely (err)) {if (err <0 ) goto out_err; - err =lookup_slow (nd, path); + err =lookup_slow (nd, &path);if (err <0 ) goto out_err; - inode = path->dentry->d_inode; + inode = path.dentry->d_inode; } err = -ENOENT ; -if (d_is_negative (path->dentry)) +if (d_is_negative (path.dentry)) goto out_path_put; -if (should_follow_link (path->dentry, follow)) { +if (should_follow_link (path.dentry, follow)) {if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->path.mnt != path->mnt || -unlazy_walk (nd, path->dentry))) { +if (unlikely (nd->path.mnt != path.mnt || +unlazy_walk (nd, path.dentry))) { err = -ECHILD ; goto out_err; } } -BUG_ON (inode != path->dentry->d_inode); +BUG_ON (inode != path.dentry->d_inode); + nd->link = path;return 1 ; } -path_to_nameidata (path, nd); +path_to_nameidata (&path, nd); nd->inode = inode;return 0 ; out_path_put: -path_to_nameidata (path, nd); +path_to_nameidata (&path, nd); out_err:terminate_walk (nd);return err;
@@ -1606,12 +1611,12 @@ out_err:* Without that kind of total limit, nasty chains of consecutive * symlinks can cause almost arbitrarily long lookups. */ -static inline int nested_symlink (struct path *path,struct nameidata *nd) +static inline int nested_symlink (struct nameidata *nd) {int res;if (unlikely (current->link_count >=MAX_NESTED_LINKS )) { -path_put_conditional (path, nd); +path_put_conditional (&nd->link, nd);path_put (&nd->path);return -ELOOP ; }
@@ -1621,13 +1626,13 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) current->link_count++;do { -struct path link = *path; +struct path link = nd->link;void *cookie; res =follow_link (&link, nd, &cookie);if (res)break ; - res =walk_component (nd, path,LOOKUP_FOLLOW ); + res =walk_component (nd,LOOKUP_FOLLOW );put_link (nd, &link, cookie); }while (res >0 );
@@ -1762,7 +1767,6 @@ static inline u64 hash_name(const char *name)*/ static int link_path_walk (const char *name,struct nameidata *nd) { -struct path next;int err;while (*name=='/' )
@@ -1822,17 +1826,17 @@ static int link_path_walk(const char *name, struct nameidata *nd)if (!*name)return 0 ; - err =walk_component (nd, &next,LOOKUP_FOLLOW ); + err =walk_component (nd,LOOKUP_FOLLOW );if (err <0 )return err;if (err) { - err =nested_symlink (&next, nd); + err =nested_symlink (nd);if (err)return err; }if (!d_can_lookup (nd->path.dentry)) { - err = -ENOTDIR ; + err = -ENOTDIR ;break ; } }
@@ -1952,20 +1956,19 @@ static void path_cleanup(struct nameidata *nd)fput (nd->base); } -static inline int lookup_last (struct nameidata *nd,struct path *path) +static inline int lookup_last (struct nameidata *nd) {if (nd->last_type ==LAST_NORM && nd->last.name[nd->last.len]) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; nd->flags &= ~LOOKUP_PARENT ; -return walk_component (nd, path, nd->flags &LOOKUP_FOLLOW ); +return walk_component (nd, nd->flags &LOOKUP_FOLLOW ); }/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ static int path_lookupat (int dfd,const struct filename *name,unsigned int flags,struct nameidata *nd) { -struct path path;int err;/*
@@ -1984,10 +1987,10 @@ static int path_lookupat(int dfd, const struct filename *name,*/ err =path_init (dfd, name, flags, nd);if (!err && !(flags &LOOKUP_PARENT )) { - err =lookup_last (nd, &path); + err =lookup_last (nd);while (err >0 ) {void *cookie; -struct path link = path; +struct path link = nd->link; err =may_follow_link (&link, nd);if (unlikely (err))break ;
@@ -1995,7 +1998,7 @@ static int path_lookupat(int dfd, const struct filename *name, err =follow_link (&link, nd, &cookie);if (err)break ; - err =lookup_last (nd, &path); + err =lookup_last (nd);put_link (nd, &link, cookie); } }
@@ -2304,8 +2307,10 @@ done: } path->dentry = dentry; path->mnt = nd->path.mnt; -if (should_follow_link (dentry, nd->flags &LOOKUP_FOLLOW )) +if (should_follow_link (dentry, nd->flags &LOOKUP_FOLLOW )) { + nd->link = *path;return 1 ; + }mntget (path->mnt);follow_mount (path); error =0 ;
@@ -3034,6 +3039,7 @@ finish_lookup: } }BUG_ON (inode != path->dentry->d_inode); + nd->link = *path;return 1 ; }
@@ -3222,7 +3228,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, error =do_last (nd, &path, file, op, &opened, pathname);while (unlikely (error >0 )) {/* trailing symlink */ -struct path link = path; +struct path link = nd->link;void *cookie; error =may_follow_link (&link, nd);if (unlikely (error))
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 33/79 do_last: move path there from caller's stack frame
In reply to Al ViroFrom: Al Viro <[email protected]>
We used to need it to feed to follow_link(). No more...
--- fs/namei.c | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
fs/namei.c +25 -25
@@ -2903,7 +2903,7 @@ out_dput:/* * Handle the last step of open() */ -static int do_last (struct nameidata *nd,struct path *path, +static int do_last (struct nameidata *nd,struct file *file,const struct open_flags *op,int *opened,struct filename *name) {
@@ -2914,6 +2914,7 @@ static int do_last(struct nameidata *nd, struct path *path,int acc_mode = op->acc_mode;struct inode *inode;struct path save_parent = { .dentry =NULL , .mnt =NULL }; +struct path path;bool retried = false;int error;
@@ -2931,7 +2932,7 @@ static int do_last(struct nameidata *nd, struct path *path,if (nd->last.name[nd->last.len]) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ;/* we _can_ be in RCU mode here */ - error =lookup_fast (nd, path, &inode); + error =lookup_fast (nd, &path, &inode);if (likely (!error)) goto finish_lookup;
@@ -2969,7 +2970,7 @@ retry_lookup:*/ }mutex_lock (&dir->d_inode->i_mutex); - error =lookup_open (nd, path, file, op, got_write, opened); + error =lookup_open (nd, &path, file, op, got_write, opened);mutex_unlock (&dir->d_inode->i_mutex);if (error <=0 ) {
@@ -2989,15 +2990,15 @@ retry_lookup: open_flag &= ~O_TRUNC ; will_truncate = false; acc_mode =MAY_OPEN ; -path_to_nameidata (path, nd); +path_to_nameidata (&path, nd); goto finish_open_created; }/* * create/update audit record if it already exists. */ -if (d_is_positive (path->dentry)) -audit_inode (name, path->dentry,0 ); +if (d_is_positive (path.dentry)) +audit_inode (name, path.dentry,0 );/* * If atomic_open() acquired write access it is dropped now due to
@@ -3013,7 +3014,7 @@ retry_lookup:if ((open_flag & (O_EXCL |O_CREAT )) == (O_EXCL |O_CREAT )) goto exit_dput; - error =follow_managed (path, nd->flags); + error =follow_managed (&path, nd->flags);if (error <0 ) goto exit_dput;
@@ -3021,40 +3022,40 @@ retry_lookup: nd->flags |=LOOKUP_JUMPED ;BUG_ON (nd->flags &LOOKUP_RCU ); - inode = path->dentry->d_inode; + inode = path.dentry->d_inode; finish_lookup:/* we _can_ be in RCU mode here */ error = -ENOENT ; -if (d_is_negative (path->dentry)) { -path_to_nameidata (path, nd); +if (d_is_negative (path.dentry)) { +path_to_nameidata (&path, nd); goto out; } -if (should_follow_link (path->dentry, nd->flags &LOOKUP_FOLLOW )) { +if (should_follow_link (path.dentry, nd->flags &LOOKUP_FOLLOW )) {if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->path.mnt != path->mnt || -unlazy_walk (nd, path->dentry))) { +if (unlikely (nd->path.mnt != path.mnt || +unlazy_walk (nd, path.dentry))) { error = -ECHILD ; goto out; } } -BUG_ON (inode != path->dentry->d_inode); - nd->link = *path; +BUG_ON (inode != path.dentry->d_inode); + nd->link = path;return 1 ; } -if (unlikely (d_is_symlink (path->dentry)) && !(open_flag &O_PATH )) { -path_to_nameidata (path, nd); +if (unlikely (d_is_symlink (path.dentry)) && !(open_flag &O_PATH )) { +path_to_nameidata (&path, nd); error = -ELOOP ; goto out; } -if ((nd->flags &LOOKUP_RCU ) || nd->path.mnt != path->mnt) { -path_to_nameidata (path, nd); +if ((nd->flags &LOOKUP_RCU ) || nd->path.mnt != path.mnt) { +path_to_nameidata (&path, nd); }else { save_parent.dentry = nd->path.dentry; - save_parent.mnt =mntget (path->mnt); - nd->path.dentry = path->dentry; + save_parent.mnt =mntget (path.mnt); + nd->path.dentry = path.dentry; } nd->inode = inode;
@@ -3116,7 +3117,7 @@ out:return error; exit_dput: -path_put_conditional (path, nd); +path_put_conditional (&path, nd); goto out; exit_fput:fput (file);
@@ -3207,7 +3208,6 @@ static struct file *path_openat(int dfd, struct filename *pathname, struct nameidata *nd, const struct open_flags *op, int flags) { struct file *file; -struct path path;int opened =0 ;int error;
@@ -3226,7 +3226,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,if (unlikely (error)) goto out; - error =do_last (nd, &path, file, op, &opened, pathname); + error =do_last (nd, file, op, &opened, pathname);while (unlikely (error >0 )) {/* trailing symlink */ struct path link = nd->link;void *cookie;
@@ -3238,7 +3238,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, error =follow_link (&link, nd, &cookie);if (unlikely (error))break ; - error =do_last (nd, &path, file, op, &opened, pathname); + error =do_last (nd, file, op, &opened, pathname);put_link (nd, &link, cookie); } out:
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 34/79 namei: expand nested_symlink() in its only caller
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 61 +++++++++++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-)
fs/namei.c +23 -38
@@ -1605,43 +1605,6 @@ out_err: }/* -* This limits recursive symlink follows to 8, while -* limiting consecutive symlinks to 40. -* -* Without that kind of total limit, nasty chains of consecutive -* symlinks can cause almost arbitrarily long lookups. -*/ -static inline int nested_symlink (struct nameidata *nd) -{ -int res; - -if (unlikely (current->link_count >=MAX_NESTED_LINKS )) { -path_put_conditional (&nd->link, nd); -path_put (&nd->path); -return -ELOOP ; - } -BUG_ON (nd->depth >=MAX_NESTED_LINKS ); - - nd->depth++; - current->link_count++; - -do { -struct path link = nd->link; -void *cookie; - - res =follow_link (&link, nd, &cookie); -if (res) -break ; - res =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd, &link, cookie); - }while (res >0 ); - - current->link_count--; - nd->depth--; -return res; -} - -/* * We can do the critical dentry name comparison and hashing * operations one word at a time, but we are limited to: *
@@ -1831,7 +1794,29 @@ static int link_path_walk(const char *name, struct nameidata *nd)return err;if (err) { - err =nested_symlink (nd); +if (unlikely (current->link_count >=MAX_NESTED_LINKS )) { +path_put_conditional (&nd->link, nd); +path_put (&nd->path); +return -ELOOP ; + } +BUG_ON (nd->depth >=MAX_NESTED_LINKS ); + + nd->depth++; + current->link_count++; + +do { +struct path link = nd->link; +void *cookie; + + err =follow_link (&link, nd, &cookie); +if (err) +break ; + err =walk_component (nd,LOOKUP_FOLLOW ); +put_link (nd, &link, cookie); + }while (err >0 ); + + current->link_count--; + nd->depth--;if (err)return err; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 35/79 namei: expand the call of follow_link() in link_path_walk()
In reply to Al ViroFrom: Al Viro <[email protected]>
... and strip __always_inline from follow_link() - remaining callers don't need that.
Now link_path_walk() recursion is a direct one.
--- fs/namei.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
fs/namei.c +22 -4
@@ -880,8 +880,7 @@ out:return res; } -static __always_inline int -follow_link (struct path *link,struct nameidata *nd,void **p) +static int follow_link (struct path *link,struct nameidata *nd,void **p) {const char *s =get_link (link, nd, p);int error;
@@ -1807,10 +1806,29 @@ static int link_path_walk(const char *name, struct nameidata *nd)do {struct path link = nd->link;void *cookie; +const char *s =get_link (&link, nd, &cookie); - err =follow_link (&link, nd, &cookie); -if (err) +if (unlikely (IS_ERR (s))) { + err =PTR_ERR (s);break ; + } + err =0 ; +if (likely (s)) { +if (*s =='/' ) { +if (!nd->root.mnt) +set_root (nd); +path_put (&nd->path); + nd->path = nd->root; +path_get (&nd->root); + nd->flags |=LOOKUP_JUMPED ; + } + nd->inode = nd->path.dentry->d_inode; + err =link_path_walk (s, nd); +if (unlikely (err)) { +put_link (nd, &link, cookie); +break ; + } + } err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd, &link, cookie); }while (err >0 );
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 36/79 namei: move the calls of may_follow_link() into follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
All remaining callers of the former are preceded by the latter
--- fs/namei.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-)
fs/namei.c +6 -15
@@ -882,9 +882,12 @@ out:static int follow_link (struct path *link,struct nameidata *nd,void **p) { -const char *s =get_link (link, nd, p); -int error; - +const char *s; +int error =may_follow_link (link, nd); +if (unlikely (error)) +return error; + nd->flags |=LOOKUP_PARENT ; + s =get_link (link, nd, p);if (unlikely (IS_ERR (s)))return PTR_ERR (s);if (unlikely (!s))
@@ -1994,10 +1997,6 @@ static int path_lookupat(int dfd, const struct filename *name,while (err >0 ) {void *cookie;struct path link = nd->link; - err =may_follow_link (&link, nd); -if (unlikely (err)) -break ; - nd->flags |=LOOKUP_PARENT ; err =follow_link (&link, nd, &cookie);if (err)break ;
@@ -2344,10 +2343,6 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,while (err >0 ) {void *cookie;struct path link = *path; - err =may_follow_link (&link, nd); -if (unlikely (err)) -break ; - nd->flags |=LOOKUP_PARENT ; err =follow_link (&link, nd, &cookie);if (err)break ;
@@ -3233,10 +3228,6 @@ static struct file *path_openat(int dfd, struct filename *pathname,while (unlikely (error >0 )) {/* trailing symlink */ struct path link = nd->link;void *cookie; - error =may_follow_link (&link, nd); -if (unlikely (error)) -break ; - nd->flags |=LOOKUP_PARENT ; nd->flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL ); error =follow_link (&link, nd, &cookie);if (unlikely (error))
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 37/79 namei: rename follow_link to trailing_symlink, move it down
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 62 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 32 deletions(-)
fs/namei.c +30 -32
@@ -668,8 +668,6 @@ static __always_inline void set_root(struct nameidata *nd)get_fs_root (current->fs, &nd->root); } -static int link_path_walk (const char *,struct nameidata *); -static __always_inline unsigned set_root_rcu (struct nameidata *nd) {struct fs_struct *fs = current->fs;
@@ -880,33 +878,6 @@ out:return res; } -static int follow_link (struct path *link,struct nameidata *nd,void **p) -{ -const char *s; -int error =may_follow_link (link, nd); -if (unlikely (error)) -return error; - nd->flags |=LOOKUP_PARENT ; - s =get_link (link, nd, p); -if (unlikely (IS_ERR (s))) -return PTR_ERR (s); -if (unlikely (!s)) -return 0 ; -if (*s =='/' ) { -if (!nd->root.mnt) -set_root (nd); -path_put (&nd->path); - nd->path = nd->root; -path_get (&nd->root); - nd->flags |=LOOKUP_JUMPED ; - } - nd->inode = nd->path.dentry->d_inode; - error =link_path_walk (s, nd); -if (unlikely (error)) -put_link (nd, link, *p); -return error; -} -static int follow_up_rcu (struct path *path) {struct mount *mnt =real_mount (path->mnt);
@@ -1962,6 +1933,33 @@ static void path_cleanup(struct nameidata *nd)fput (nd->base); } +static int trailing_symlink (struct path *link,struct nameidata *nd,void **p) +{ +const char *s; +int error =may_follow_link (link, nd); +if (unlikely (error)) +return error; + nd->flags |=LOOKUP_PARENT ; + s =get_link (link, nd, p); +if (unlikely (IS_ERR (s))) +return PTR_ERR (s); +if (unlikely (!s)) +return 0 ; +if (*s =='/' ) { +if (!nd->root.mnt) +set_root (nd); +path_put (&nd->path); + nd->path = nd->root; +path_get (&nd->root); + nd->flags |=LOOKUP_JUMPED ; + } + nd->inode = nd->path.dentry->d_inode; + error =link_path_walk (s, nd); +if (unlikely (error)) +put_link (nd, link, *p); +return error; +} +static inline int lookup_last (struct nameidata *nd) {if (nd->last_type ==LAST_NORM && nd->last.name[nd->last.len])
@@ -1997,7 +1995,7 @@ static int path_lookupat(int dfd, const struct filename *name,while (err >0 ) {void *cookie;struct path link = nd->link; - err =follow_link (&link, nd, &cookie); + err =trailing_symlink (&link, nd, &cookie);if (err)break ; err =lookup_last (nd);
@@ -2343,7 +2341,7 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,while (err >0 ) {void *cookie;struct path link = *path; - err =follow_link (&link, nd, &cookie); + err =trailing_symlink (&link, nd, &cookie);if (err)break ; err =mountpoint_last (nd, path);
@@ -3229,7 +3227,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,struct path link = nd->link;void *cookie; nd->flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL ); - error =follow_link (&link, nd, &cookie); + error =trailing_symlink (&link, nd, &cookie);if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 38/79 link_path_walk: handle get_link() returning ERR_PTR() immediately
In reply to Al ViroFrom: Al Viro <[email protected]>
If we get ERR_PTR() from get_link(), we are guaranteed to get err != 0 when we break out of do-while, so we are going to hit if (err) return err; shortly after it. Pull that into the if (IS_ERR(s)) body.
--- fs/namei.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/namei.c +3 -1
@@ -1784,7 +1784,9 @@ static int link_path_walk(const char *name, struct nameidata *nd)if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); -break ; + current->link_count--; + nd->depth--; +return err; } err =0 ;if (likely (s)) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 39/79 link_path_walk: don't bother with walk_component() after jumping link
In reply to Al ViroFrom: Al Viro <[email protected]>
... it does nothing if nd->last_type is LAST_BIND.
--- fs/namei.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/namei.c +7 -3
@@ -1789,7 +1789,11 @@ static int link_path_walk(const char *name, struct nameidata *nd)return err; } err =0 ; -if (likely (s)) { +if (unlikely (!s)) { +/* jumped */ +put_link (nd, &link, cookie); +break ; + }else {if (*s =='/' ) {if (!nd->root.mnt)set_root (nd);
@@ -1804,9 +1808,9 @@ static int link_path_walk(const char *name, struct nameidata *nd)put_link (nd, &link, cookie);break ; } + err =walk_component (nd,LOOKUP_FOLLOW ); +put_link (nd, &link, cookie); } - err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd, &link, cookie); }while (err >0 ); current->link_count--;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 40/79 link_path_walk: turn inner loop into explicit goto
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 61 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 29 deletions(-)
fs/namei.c +32 -29
@@ -1767,6 +1767,10 @@ static int link_path_walk(const char *name, struct nameidata *nd)return err;if (err) { +struct path link; +void *cookie; +const char *s; +if (unlikely (current->link_count >=MAX_NESTED_LINKS )) {path_put_conditional (&nd->link, nd);path_put (&nd->path);
@@ -1777,41 +1781,40 @@ static int link_path_walk(const char *name, struct nameidata *nd) nd->depth++; current->link_count++; -do { -struct path link = nd->link; -void *cookie; -const char *s =get_link (&link, nd, &cookie); - -if (unlikely (IS_ERR (s))) { - err =PTR_ERR (s); - current->link_count--; - nd->depth--; -return err; +l: + link = nd->link; + s =get_link (&link, nd, &cookie); + +if (unlikely (IS_ERR (s))) { + err =PTR_ERR (s); + current->link_count--; + nd->depth--; +return err; + } + err =0 ; +if (unlikely (!s)) { +/* jumped */ +put_link (nd, &link, cookie); + }else { +if (*s =='/' ) { +if (!nd->root.mnt) +set_root (nd); +path_put (&nd->path); + nd->path = nd->root; +path_get (&nd->root); + nd->flags |=LOOKUP_JUMPED ; } - err =0 ; -if (unlikely (!s)) { -/* jumped */ + nd->inode = nd->path.dentry->d_inode; + err =link_path_walk (s, nd); +if (unlikely (err)) {put_link (nd, &link, cookie); -break ; }else { -if (*s =='/' ) { -if (!nd->root.mnt) -set_root (nd); -path_put (&nd->path); - nd->path = nd->root; -path_get (&nd->root); - nd->flags |=LOOKUP_JUMPED ; - } - nd->inode = nd->path.dentry->d_inode; - err =link_path_walk (s, nd); -if (unlikely (err)) { -put_link (nd, &link, cookie); -break ; - } err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd, &link, cookie); +if (err >0 ) + goto l; } - }while (err >0 ); + } current->link_count--; nd->depth--;
Signature · 1 line
2.1.4
Re: [PATCH 40/79] link_path_walk: turn inner loop into explicit goto
Quoted 1 line · Al Viro
+l:
This looked like noise.
PLEASE. We're not programming in Pascal (and thank all Gods for that), so we can have labels that have meaningful names. Also, we're not ashamed of using goto where it makes sense, so we don't need to try to hide the labels by making them look like specks of dirt on our monitor.
So give the label a real name that describes what it is. Not this kind of thing.
Linus
Al Viro
maintainerRe: [PATCH 40/79] link_path_walk: turn inner loop into explicit goto
Quoted 5 lines · Linus Torvalds
Quoted 1 line · Al Viro
+l:
This looked like noise.
Quoted 7 lines
PLEASE. We're not programming in Pascal (and thank all Gods for that), so we can have labels that have meaningful names. Also, we're not ashamed of using goto where it makes sense, so we don't need to try to hide the labels by making them look like specks of dirt on our monitor.
So give the label a real name that describes what it is. Not this kind of thing.
Something like this_used_to_be_the_beginning_of_loop_body?
Seriously, it's strictly temporary thing - it lives for two commits and gets killed after that. Exactly because it has no good inherent meaning. The label replacing it two commits later (several lines upstream) does, and it gets better name...
Re: [PATCH 40/79] link_path_walk: turn inner loop into explicit goto
Quoted 2 lines · Al Viro
Something like
this_used_to_be_the_beginning_of_loop_body?
No, but at least "loop:" or "repeat:" or something.
That "l:" really looked like a fly shat on my monitor.
Linus
OT / Pascal (was: [PATCH 40/79] link_path_walk: turn inner loop into explicit goto)
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds <torvalds <at> linux-foundation.org> writes:
Quoted 1 line · On Mon, May 4, 2015 at 10:22 PM, Al Viro <viro <at> zeniv.linux.org.uk> wrote:
+l:
This looked like noise.
PLEASE. We're not programming in Pascal
What is it with Pascal that every C-like programmer is bashing (uh oh..) it ?
Quoted 1 line
(and thank all Gods for that),
[...]
;)
Quoted 3 lines
Linus
el es
Al Viro
maintainerPATCH 41/79 link_path_walk: massage a bit more
In reply to Al ViroFrom: Al Viro <[email protected]>
Pull the block after the if-else in the end of what used to be do-while body into all branches there. We are almost done with the massage...
--- fs/namei.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
fs/namei.c +13 -6
@@ -1795,6 +1795,8 @@ l:if (unlikely (!s)) {/* jumped */ put_link (nd, &link, cookie); + current->link_count--; + nd->depth--; }else {if (*s =='/' ) {if (!nd->root.mnt)
@@ -1808,18 +1810,23 @@ l: err =link_path_walk (s, nd);if (unlikely (err)) {put_link (nd, &link, cookie); + current->link_count--; + nd->depth--; +return err; }else { err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd, &link, cookie); -if (err >0 ) + current->link_count--; + nd->depth--; +if (err <0 ) +return err; +if (err >0 ) { + current->link_count++; + nd->depth++; goto l; + } } } - - current->link_count--; - nd->depth--; -if (err) -return err; }if (!d_can_lookup (nd->path.dentry)) { err = -ENOTDIR ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 42/79 link_path_walk: get rid of duplication
In reply to Al ViroFrom: Al Viro <[email protected]>
What we do after the second walk_component() + put_link() + depth decrement in there is exactly equivalent to what's done right after the first walk_component(). Easy to verify and not at all surprising, seeing that there we have just walked the last component of nested symlink.
--- fs/namei.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
fs/namei.c +2 -8
@@ -1763,6 +1763,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)return 0 ; err =walk_component (nd,LOOKUP_FOLLOW ); +Walked:if (err <0 )return err;
@@ -1781,7 +1782,6 @@ static int link_path_walk(const char *name, struct nameidata *nd) nd->depth++; current->link_count++; -l: link = nd->link; s =get_link (&link, nd, &cookie);
@@ -1818,13 +1818,7 @@ l:put_link (nd, &link, cookie); current->link_count--; nd->depth--; -if (err <0 ) -return err; -if (err >0 ) { - current->link_count++; - nd->depth++; - goto l; - } + goto Walked; } } }
Signature · 1 line
2.1.4
Re: [PATCH 42/79] link_path_walk: get rid of duplication
Quoted 1 line · Al Viro
-l:
Ok, I guess this gets rid of the nasty badly-named label I complained about.
Linus
Al Viro
maintainerPATCH 43/79 link_path_walk: final preparations to killing recursion
In reply to Al ViroFrom: Al Viro <[email protected]>
reduce the number of returns in there - turn all places where it returns zero into goto OK and places where it returns non-zero into goto Err. The only non-trivial detail is that all breaks in the loop are guaranteed to be with non-zero err.
--- fs/namei.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
fs/namei.c +11 -7
@@ -1708,7 +1708,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)while (*name=='/' ) name++;if (!*name) -return 0 ; + goto OK;/* At this point we know we have a real path component. */ for (;;) {
@@ -1751,7 +1751,7 @@ static int link_path_walk(const char *name, struct nameidata *nd) name +=hashlen_len (hash_len);if (!*name) -return 0 ; + goto OK;/* * If it wasn't NUL, we know it was '/'. Skip that * slash, and continue until no more slashes.
@@ -1760,12 +1760,12 @@ static int link_path_walk(const char *name, struct nameidata *nd) name++; }while (unlikely (*name =='/' ));if (!*name) -return 0 ; + goto OK; err =walk_component (nd,LOOKUP_FOLLOW ); Walked:if (err <0 ) -return err; + goto Err;if (err) {struct path link;
@@ -1775,7 +1775,8 @@ Walked:if (unlikely (current->link_count >=MAX_NESTED_LINKS )) {path_put_conditional (&nd->link, nd);path_put (&nd->path); -return -ELOOP ; + err = -ELOOP ; + goto Err; }BUG_ON (nd->depth >=MAX_NESTED_LINKS );
@@ -1789,7 +1790,7 @@ Walked: err =PTR_ERR (s); current->link_count--; nd->depth--; -return err; + goto Err; } err =0 ;if (unlikely (!s)) {
@@ -1812,7 +1813,7 @@ Walked:put_link (nd, &link, cookie); current->link_count--; nd->depth--; -return err; + goto Err; }else { err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd, &link, cookie);
@@ -1828,7 +1829,10 @@ Walked: } }terminate_walk (nd); +Err:return err; +OK: +return 0 ; } static int path_init(int dfd, const struct filename *name, unsigned int flags,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 44/79 link_path_walk: kill the recursion
In reply to Al ViroFrom: Al Viro <[email protected]>
absolutely straightforward now - the only variables we need to preserve across the recursive call are name, link and cookie, and recursion depth is limited (and can is equal to nd->depth). So arrange an array of triples to hold instances of those and be done with that.
--- fs/namei.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
fs/namei.c +29 -11
@@ -1703,8 +1703,14 @@ static inline u64 hash_name(const char *name)*/ static int link_path_walk (const char *name,struct nameidata *nd) { +struct saved { +struct path link; +void *cookie; +const char *name; + } stack[MAX_NESTED_LINKS ], *last = stack + nd->depth -1 ;int err; - + +start:while (*name=='/' ) name++;if (!*name)
@@ -1768,8 +1774,6 @@ Walked: goto Err;if (err) { -struct path link; -void *cookie;const char *s;if (unlikely (current->link_count >=MAX_NESTED_LINKS )) {
@@ -1782,22 +1786,25 @@ Walked: nd->depth++; current->link_count++; + last++; - link = nd->link; - s =get_link (&link, nd, &cookie); + last->link = nd->link; + s =get_link (&last->link, nd, &last->cookie);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); current->link_count--; nd->depth--; + last--; goto Err; } err =0 ;if (unlikely (!s)) {/* jumped */ -put_link (nd, &link, cookie); +put_link (nd, &last->link, last->cookie); current->link_count--; nd->depth--; + last--; }else {if (*s =='/' ) {if (!nd->root.mnt)
@@ -1808,17 +1815,24 @@ Walked: nd->flags |=LOOKUP_JUMPED ; } nd->inode = nd->path.dentry->d_inode; - err =link_path_walk (s, nd); + last->name = name; + name = s; + goto start; + +back: + name = last->name;if (unlikely (err)) { -put_link (nd, &link, cookie); +put_link (nd, &last->link, last->cookie); current->link_count--; nd->depth--; + last--; goto Err; }else { err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd, &link, cookie); +put_link (nd, &last->link, last->cookie); current->link_count--; nd->depth--; + last--; goto Walked; } }
@@ -1830,9 +1844,13 @@ Walked: }terminate_walk (nd); Err: -return err; +if (likely (!nd->depth)) +return err; + goto back; OK: -return 0 ; +if (likely (!nd->depth)) +return 0 ; + goto back; } static int path_init(int dfd, const struct filename *name, unsigned int flags,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 45/79 link_path_walk: split "return from recursive call" path
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
fs/namei.c +17 -23
@@ -1818,23 +1818,6 @@ Walked: last->name = name; name = s; goto start; - -back: - name = last->name; -if (unlikely (err)) { -put_link (nd, &last->link, last->cookie); - current->link_count--; - nd->depth--; - last--; - goto Err; - }else { - err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd, &last->link, last->cookie); - current->link_count--; - nd->depth--; - last--; - goto Walked; - } } }if (!d_can_lookup (nd->path.dentry)) {
@@ -1844,13 +1827,24 @@ back: }terminate_walk (nd); Err: -if (likely (!nd->depth)) -return err; - goto back; +while (unlikely (nd->depth)) { +put_link (nd, &last->link, last->cookie); + current->link_count--; + nd->depth--; + last--; + } +return err; OK: -if (likely (!nd->depth)) -return 0 ; - goto back; +if (unlikely (nd->depth)) { + name = last->name; + err =walk_component (nd,LOOKUP_FOLLOW ); +put_link (nd, &last->link, last->cookie); + current->link_count--; + nd->depth--; + last--; + goto Walked; + } +return 0 ; } static int path_init(int dfd, const struct filename *name, unsigned int flags,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 46/79 link_path_walk: cleanup - turn goto start; into continue;
In reply to Al ViroFrom: Al Viro <[email protected]>
Deal with skipping leading slashes before what used to be the recursive call. That way we can get rid of that goto completely.
--- fs/namei.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/namei.c +6 -3
@@ -1710,11 +1710,10 @@ static int link_path_walk(const char *name, struct nameidata *nd) } stack[MAX_NESTED_LINKS ], *last = stack + nd->depth -1 ;int err; -start:while (*name=='/' ) name++;if (!*name) - goto OK; +return 0 ;/* At this point we know we have a real path component. */ for (;;) {
@@ -1813,11 +1812,15 @@ Walked: nd->path = nd->root;path_get (&nd->root); nd->flags |=LOOKUP_JUMPED ; +while (unlikely (*++s =='/' )) + ; } nd->inode = nd->path.dentry->d_inode; last->name = name; +if (!*s) + goto OK; name = s; - goto start; +continue ; } }if (!d_can_lookup (nd->path.dentry)) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 47/79 namei: move link/cookie pairs into nameidata
In reply to Al ViroFrom: Al Viro <[email protected]>
Array of MAX_NESTED_LINKS + 1 elements put into nameidata; what used to be a local array in link_path_walk() occupies entries 1 .. MAX_NESTED_LINKS in it, link and cookie from the trailing symlink handling loops - entry 0.
This is _not_ the final arrangement; just an easily verified incremental step.
--- fs/namei.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
fs/namei.c +18 -17
@@ -505,6 +505,11 @@ struct nameidata {int last_type;unsigned depth;struct file *base; +struct saved { +struct path link; +void *cookie; +const char *name; + } stack[MAX_NESTED_LINKS +1 ]; };/*
@@ -1703,11 +1708,7 @@ static inline u64 hash_name(const char *name)*/ static int link_path_walk (const char *name,struct nameidata *nd) { -struct saved { -struct path link; -void *cookie; -const char *name; - } stack[MAX_NESTED_LINKS ], *last = stack + nd->depth -1 ; +struct saved *last = nd->stack;int err;while (*name=='/' )
@@ -2022,13 +2023,13 @@ static int path_lookupat(int dfd, const struct filename *name,if (!err && !(flags &LOOKUP_PARENT )) { err =lookup_last (nd);while (err >0 ) { -void *cookie; -struct path link = nd->link; - err =trailing_symlink (&link, nd, &cookie); + nd->stack[0 ].link = nd->link; + err =trailing_symlink (&nd->stack[0 ].link, + nd, &nd->stack[0 ].cookie);if (err)break ; err =lookup_last (nd); -put_link (nd, &link, cookie); +put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); } }
@@ -2368,13 +2369,13 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path, err =mountpoint_last (nd, path);while (err >0 ) { -void *cookie; -struct path link = *path; - err =trailing_symlink (&link, nd, &cookie); + nd->stack[0 ].link = nd->link; + err =trailing_symlink (&nd->stack[0 ].link, + nd, &nd->stack[0 ].cookie);if (err)break ; err =mountpoint_last (nd, path); -put_link (nd, &link, cookie); +put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); } out:path_cleanup (nd);
@@ -3253,14 +3254,14 @@ static struct file *path_openat(int dfd, struct filename *pathname, error =do_last (nd, file, op, &opened, pathname);while (unlikely (error >0 )) {/* trailing symlink */ -struct path link = nd->link; -void *cookie; nd->flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL ); - error =trailing_symlink (&link, nd, &cookie); + nd->stack[0 ].link = nd->link; + error=trailing_symlink (&nd->stack[0 ].link, + nd, &nd->stack[0 ].cookie);if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname); -put_link (nd, &link, cookie); +put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); } out:path_cleanup (nd);
Signature · 1 line
2.1.4
Re: [PATCH 47/79] namei: move link/cookie pairs into nameidata
Quoted 32 lines · On Tue, 5 May 2015 06:22:21 +0100 Al Viro <[email protected]> wrote:
From: Al Viro <[email protected]>
Array of
MAX_NESTED_LINKS+ 1 elements put into nameidata; what used to be a local array inlink_path_walk()occupies entries 1 ..MAX_NESTED_LINKSin it, link and cookie from the trailing symlink handling loops - entry 0.This is _not_ the final arrangement; just an easily verified incremental step.
Signed-off-by Al Viro <[email protected]>--- fs/namei.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)fs/namei.c +5
-0@@ -505,6 +505,11 @@ struct nameidata {int last_type;unsigned depth;struct file *base; +struct saved { +struct path link; +void *cookie; +const char *name; + } stack[MAX_NESTED_LINKS +1 ]; };/*
fs/namei.c static inline u64 hash_name(const char *name) · line 1711
Quoted 9 lines
fs/namei.c +1
-5@@ -1703,11 +1708,7 @@ static inline u64 hash_name(const char *name)*/ static int link_path_walk (const char *name,struct nameidata *nd) { -struct saved { -struct path link; -void *cookie; -const char *name; - } stack[MAX_NESTED_LINKS ], *last = stack + nd->depth -1 ; +struct saved *last = nd->stack;
This looks wrong. 'last' used to be dependent on nd->depth, now it isn't.
Three patches later we have:
+const char *get_link(struct nameidata *nd)
{
- struct dentry *dentry = link->dentry;
+ struct saved *last = nd->stack + nd->depth;
+ struct dentry *dentry = nd->link.dentry;
struct inode *inode = dentry->d_inode;
and
static int link_path_walk(const char *name, struct nameidata *nd) {
- struct saved *last = nd->stack;
int err;
....
- last->link = nd->link;
- s = get_link(&last->link, nd, &last->cookie);
+ s = get_link(nd);
so the nd->depth offset is restored in get_link() so the next result appears correct, but the intermediate states appear to be wrong.
NeilBrown
Al Viro
maintainerRe: [PATCH 47/79] namei: move link/cookie pairs into nameidata
Quoted 10 lines · NeilBrown
fs/namei.c static inline u64 hash_name(const char *name) · line 1711
Quoted 8 lines
static int
link_path_walk(const char *name, struct nameidata *nd){fs/namei.c +1
-5-struct saved { -struct path link; -void *cookie; -const char *name; - } stack[MAX_NESTED_LINKS ], *last = stack + nd->depth -1 ; +struct saved *last = nd->stack;This looks wrong. 'last' used to be dependent on
nd->depth, now it isn't.
On the entry to link_path_walk() we have nd->depth == 0.
And nd->depth and last are changed in sync.
Al Viro
maintainerPATCH 48/79 namei: trim redundant arguments of trailing_symlink()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)
fs/namei.c +8 -13
@@ -1963,14 +1963,15 @@ static void path_cleanup(struct nameidata *nd)fput (nd->base); } -static int trailing_symlink (struct path *link,struct nameidata *nd,void **p) +static int trailing_symlink (struct nameidata *nd) {const char *s; -int error =may_follow_link (link, nd); +int error =may_follow_link (&nd->link, nd);if (unlikely (error))return error; nd->flags |=LOOKUP_PARENT ; - s =get_link (link, nd, p); + nd->stack[0 ].link = nd->link; + s =get_link (&nd->stack[0 ].link, nd, &nd->stack[0 ].cookie);if (unlikely (IS_ERR (s)))return PTR_ERR (s);if (unlikely (!s))
@@ -1986,7 +1987,7 @@ static int trailing_symlink(struct path *link, struct nameidata *nd, void **p) nd->inode = nd->path.dentry->d_inode; error =link_path_walk (s, nd);if (unlikely (error)) -put_link (nd, link, *p); +put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie);return error; }
@@ -2023,9 +2024,7 @@ static int path_lookupat(int dfd, const struct filename *name,if (!err && !(flags &LOOKUP_PARENT )) { err =lookup_last (nd);while (err >0 ) { - nd->stack[0 ].link = nd->link; - err =trailing_symlink (&nd->stack[0 ].link, - nd, &nd->stack[0 ].cookie); + err =trailing_symlink (nd);if (err)break ; err =lookup_last (nd);
@@ -2369,9 +2368,7 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path, err =mountpoint_last (nd, path);while (err >0 ) { - nd->stack[0 ].link = nd->link; - err =trailing_symlink (&nd->stack[0 ].link, - nd, &nd->stack[0 ].cookie); + err =trailing_symlink (nd);if (err)break ; err =mountpoint_last (nd, path);
@@ -3255,9 +3252,7 @@ static struct file *path_openat(int dfd, struct filename *pathname, error =do_last (nd, file, op, &opened, pathname);while (unlikely (error >0 )) {/* trailing symlink */ nd->flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL ); - nd->stack[0 ].link = nd->link; - error=trailing_symlink (&nd->stack[0 ].link, - nd, &nd->stack[0 ].cookie); + error =trailing_symlink (nd);if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 49/79 namei: trim redundant arguments of fs/namei.c:put_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
fs/namei.c +13 -12
@@ -718,12 +718,13 @@ void nd_jump_link(struct nameidata *nd, struct path *path) nd->flags |=LOOKUP_JUMPED ; } -static inline void put_link (struct nameidata *nd,struct path *link,void *cookie) +static inline void put_link (struct nameidata *nd) { -struct inode *inode = link->dentry->d_inode; -if (cookie && inode->i_op->put_link) - inode->i_op->put_link (link->dentry, cookie); -path_put (link); +struct saved *last = nd->stack + nd->depth; +struct inode *inode = last->link.dentry->d_inode; +if (last->cookie && inode->i_op->put_link) + inode->i_op->put_link (last->link.dentry, last->cookie); +path_put (&last->link); }int sysctl_protected_symlinks__read_mostly =0 ;
@@ -1801,7 +1802,7 @@ Walked: err =0 ;if (unlikely (!s)) {/* jumped */ -put_link (nd, &last->link, last->cookie); +put_link (nd); current->link_count--; nd->depth--; last--;
@@ -1832,7 +1833,7 @@ Walked:terminate_walk (nd); Err:while (unlikely (nd->depth)) { -put_link (nd, &last->link, last->cookie); +put_link (nd); current->link_count--; nd->depth--; last--;
@@ -1842,7 +1843,7 @@ OK:if (unlikely (nd->depth)) { name = last->name; err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd, &last->link, last->cookie); +put_link (nd); current->link_count--; nd->depth--; last--;
@@ -1987,7 +1988,7 @@ static int trailing_symlink(struct nameidata *nd) nd->inode = nd->path.dentry->d_inode; error =link_path_walk (s, nd);if (unlikely (error)) -put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); +put_link (nd);return error; }
@@ -2028,7 +2029,7 @@ static int path_lookupat(int dfd, const struct filename *name,if (err)break ; err =lookup_last (nd); -put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); +put_link (nd); } }
@@ -2372,7 +2373,7 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,if (err)break ; err =mountpoint_last (nd, path); -put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); +put_link (nd); } out:path_cleanup (nd);
@@ -3256,7 +3257,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname); -put_link (nd, &nd->stack[0 ].link, nd->stack[0 ].cookie); +put_link (nd); } out:path_cleanup (nd);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 50/79 namei: trim the arguments of get_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
same story as the previous commit
--- fs/namei.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-)
fs/namei.c +21 -24
@@ -843,27 +843,33 @@ static int may_linkat(struct path *link)return -EPERM ; } -static __always_inline const char * -get_link (struct path *link,struct nameidata *nd,void **p) +static __always_inline +const char *get_link(struct nameidata *nd) { -struct dentry *dentry = link->dentry; +struct saved *last = nd->stack + nd->depth; +struct dentry *dentry = nd->link.dentry;struct inode *inode = dentry->d_inode;int error;const char *res;BUG_ON (nd->flags &LOOKUP_RCU ); -if (link->mnt == nd->path.mnt) -mntget (link->mnt); +if (nd->link.mnt == nd->path.mnt) +mntget (nd->link.mnt); - res =ERR_PTR (-ELOOP ); -if (unlikely (current->total_link_count >=40 )) - goto out; +if (unlikely (current->total_link_count >=40 )) { +path_put (&nd->path); +path_put (&nd->link); +return ERR_PTR (-ELOOP ); + } + + last->link = nd->link; + last->cookie =NULL ;cond_resched (); current->total_link_count++; -touch_atime (link); +touch_atime (&last->link); error =security_inode_follow_link (dentry); res =ERR_PTR (error);
@@ -871,14 +877,13 @@ get_link(struct path *link, struct nameidata *nd, void **p) goto out; nd->last_type =LAST_BIND ; - *p =NULL ; res = inode->i_link;if (!res) { - res = inode->i_op->follow_link (dentry, p, nd); + res = inode->i_op->follow_link (dentry, &last->cookie, nd);if (IS_ERR (res)) { out:path_put (&nd->path); -path_put (link); +path_put (&last->link); } }return res;
@@ -1709,7 +1714,6 @@ static inline u64 hash_name(const char *name)*/ static int link_path_walk (const char *name,struct nameidata *nd) { -struct saved *last = nd->stack;int err;while (*name=='/' )
@@ -1787,16 +1791,13 @@ Walked: nd->depth++; current->link_count++; - last++; - last->link = nd->link; - s =get_link (&last->link, nd, &last->cookie); + s =get_link (nd);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); current->link_count--; nd->depth--; - last--; goto Err; } err =0 ;
@@ -1805,7 +1806,6 @@ Walked:put_link (nd); current->link_count--; nd->depth--; - last--; }else {if (*s =='/' ) {if (!nd->root.mnt)
@@ -1818,7 +1818,7 @@ Walked: ; } nd->inode = nd->path.dentry->d_inode; - last->name = name; + nd->stack[nd->depth].name = name;if (!*s) goto OK; name = s;
@@ -1836,17 +1836,15 @@ Err:put_link (nd); current->link_count--; nd->depth--; - last--; }return err; OK:if (unlikely (nd->depth)) { - name = last->name; + name = nd->stack[nd->depth].name; err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd); current->link_count--; nd->depth--; - last--; goto Walked; }return 0 ;
@@ -1971,8 +1969,7 @@ static int trailing_symlink(struct nameidata *nd)if (unlikely (error))return error; nd->flags |=LOOKUP_PARENT ; - nd->stack[0 ].link = nd->link; - s =get_link (&nd->stack[0 ].link, nd, &nd->stack[0 ].cookie); + s =get_link (nd);if (unlikely (IS_ERR (s)))return PTR_ERR (s);if (unlikely (!s))
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 51/79 namei: remove restrictions on nesting depth
In reply to Al ViroFrom: Al Viro <[email protected]>
The only restriction is that on the total amount of symlinks crossed; how they are nested does not matter
--- fs/namei.c | 66 ++++++++++++++++++++++++++++++++++++++++----------- include/linux/namei.h | 2 ++ 2 files changed, 54 insertions(+), 14 deletions(-)
fs/namei.c +52 -14
@@ -492,6 +492,7 @@ void path_put(const struct path *path) }EXPORT_SYMBOL (path_put); +#define EMBEDDED_LEVELS 2struct nameidata {struct path path;union {
@@ -509,9 +510,42 @@ struct nameidata {struct path link;void *cookie;const char *name; - } stack[MAX_NESTED_LINKS +1 ]; + } *stack, internal[EMBEDDED_LEVELS ]; }; +static void set_nameidata (struct nameidata *nd) +{ + nd->stack = nd->internal; +} + +static void restore_nameidata (struct nameidata *nd) +{ +if (nd->stack != nd->internal) { +kfree (nd->stack); + nd->stack = nd->internal; + } +} + +static int __nd_alloc_stack (struct nameidata *nd) +{ +struct saved *p =kmalloc ((MAXSYMLINKS +1 ) *sizeof (struct saved ), +GFP_KERNEL ); +if (unlikely (!p)) +return -ENOMEM ; +memcpy (p, nd->internal,sizeof (nd->internal)); + nd->stack = p; +return 0 ; +} + +static inline int nd_alloc_stack (struct nameidata *nd) +{ +if (likely (nd->depth !=EMBEDDED_LEVELS -1 )) +return 0 ; +if (likely (nd->stack != nd->internal)) +return 0 ; +return __nd_alloc_stack (nd); +} +/* * Path walking has 2 modes, rcu-walk and ref-walk (see * Documentation/filesystems/path-lookup.txt). In situations when we can't
@@ -857,7 +891,7 @@ const char *get_link(struct nameidata *nd)if (nd->link.mnt == nd->path.mnt)mntget (nd->link.mnt); -if (unlikely (current->total_link_count >=40 )) { +if (unlikely (current->total_link_count >=MAXSYMLINKS )) {path_put (&nd->path);path_put (&nd->link);return ERR_PTR (-ELOOP );
@@ -1781,22 +1815,18 @@ Walked:if (err) {const char *s; -if (unlikely (current->link_count >=MAX_NESTED_LINKS )) { -path_put_conditional (&nd->link, nd); -path_put (&nd->path); - err = -ELOOP ; - goto Err; + err =nd_alloc_stack (nd); +if (unlikely (err)) { +path_to_nameidata (&nd->link, nd); +break ; } -BUG_ON (nd->depth >=MAX_NESTED_LINKS ); nd->depth++; - current->link_count++; s =get_link (nd);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); - current->link_count--; nd->depth--; goto Err; }
@@ -1804,7 +1834,6 @@ Walked:if (unlikely (!s)) {/* jumped */ put_link (nd); - current->link_count--; nd->depth--; }else {if (*s =='/' ) {
@@ -1834,7 +1863,6 @@ Walked: Err:while (unlikely (nd->depth)) {put_link (nd); - current->link_count--; nd->depth--; }return err;
@@ -1843,7 +1871,6 @@ OK: name = nd->stack[nd->depth].name; err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd); - current->link_count--; nd->depth--; goto Walked; }
@@ -2047,7 +2074,11 @@ static int path_lookupat(int dfd, const struct filename *name,static int filename_lookup (int dfd,struct filename *name,unsigned int flags,struct nameidata *nd) { -int retval =path_lookupat (dfd, name, flags |LOOKUP_RCU , nd); +int retval; + +set_nameidata (nd); + retval =path_lookupat (dfd, name, flags |LOOKUP_RCU , nd); +if (unlikely (retval == -ECHILD )) retval =path_lookupat (dfd, name, flags, nd);if (unlikely (retval == -ESTALE ))
@@ -2055,6 +2086,7 @@ static int filename_lookup(int dfd, struct filename *name,if (likely (!retval))audit_inode (name, nd->path.dentry, flags &LOOKUP_PARENT ); +restore_nameidata (nd);return retval; }
@@ -2385,6 +2417,7 @@ filename_mountpoint(int dfd, struct filename *name, struct path *path,int error;if (IS_ERR (name))return PTR_ERR (name); +set_nameidata (&nd); error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_RCU );if (unlikely (error == -ECHILD )) error =path_mountpoint (dfd, name, path, &nd, flags);
@@ -2392,6 +2425,7 @@ filename_mountpoint(int dfd, struct filename *name, struct path *path, error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_REVAL );if (likely (!error))audit_inode (name, path->dentry,0 ); +restore_nameidata (&nd);putname (name);return error; }
@@ -3281,11 +3315,13 @@ struct file *do_filp_open(int dfd, struct filename *pathname,int flags = op->lookup_flags;struct file *filp; +set_nameidata (&nd); filp =path_openat (dfd, pathname, &nd, op, flags |LOOKUP_RCU );if (unlikely (filp ==ERR_PTR (-ECHILD ))) filp =path_openat (dfd, pathname, &nd, op, flags);if (unlikely (filp ==ERR_PTR (-ESTALE ))) filp =path_openat (dfd, pathname, &nd, op, flags |LOOKUP_REVAL ); +restore_nameidata (&nd);return filp; }
@@ -3299,6 +3335,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, nd.root.mnt = mnt; nd.root.dentry = dentry; +set_nameidata (&nd);if (d_is_symlink (dentry) && op->intent &LOOKUP_OPEN )return ERR_PTR (-ELOOP );
@@ -3312,6 +3349,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt, file =path_openat (-1 , filename, &nd, op, flags);if (unlikely (file ==ERR_PTR (-ESTALE ))) file =path_openat (-1 , filename, &nd, op, flags |LOOKUP_REVAL ); +restore_nameidata (&nd);putname (filename);return file; }
include/linux/namei.h +2 -0
@@ -11,6 +11,8 @@ struct nameidata;enum {MAX_NESTED_LINKS =8 }; +#define MAXSYMLINKS 40 +/* * Type of the last component on LOOKUP_PARENT */
Signature · 1 line
2.1.4
Re: [PATCH 51/79] namei: remove restrictions on nesting depth
fs/namei.c const char *get_link(struct nameidata *nd) · line 894
Quoted 11 lines · On Tue, 5 May 2015 06:22:25 +0100 Al Viro <[email protected]> wrote:
From: Al Viro <[email protected]>
The only restriction is that on the total amount of symlinks crossed; how they are nested does not matter
Signed-off-by Al Viro <[email protected]>---
fs/namei.c +1
-1-if (unlikely (current->total_link_count >=40 )) { +if (unlikely (current->total_link_count >=MAXSYMLINKS )) {
There is still a literal '40' in follow_automount.
current->total_link_count++;
if (current->total_link_count >= 40)
return -ELOOP;should that become MAXSYMLINKS too?
Thanks,
NeilBrown
Al Viro
maintainerRe: [PATCH 51/79] namei: remove restrictions on nesting depth
Quoted 11 lines · NeilBrown
fs/namei.c const char *get_link(struct nameidata *nd) · line 894
Quoted 2 lines
fs/namei.c +1
-1-if (unlikely (current->total_link_count >=40 )) { +if (unlikely (current->total_link_count >=MAXSYMLINKS )) {There is still a literal '40' in
follow_automount.current->total_link_count++; if (current->total_link_count >= 40) return -ELOOP;should that become MAXSYMLINKS too?
Yes, assuming we want to keep it at all...
Al Viro
maintainerRe: [PATCH 51/79] namei: remove restrictions on nesting depth
Quoted 7 lines · Al Viro
Quoted 5 lines · NeilBrown
fs/namei.c const char *get_link(struct nameidata *nd) · line 894
Quoted 2 lines
fs/namei.c +1
-1-if (unlikely (current->total_link_count >=40 )) { +if (unlikely (current->total_link_count >=MAXSYMLINKS )) {There is still a literal '40' in
follow_automount.
Quoted 8 lines
Quoted 6 lines
current->total_link_count++; if (current->total_link_count >= 40) return -ELOOP;should that become MAXSYMLINKS too?
Yes, assuming we want to keep it at all...
To elaborate a bit - the reason why we count those among the symlink crossings is historical; we used to implement automounting via ->follow_link().
Note that it's not really consistent - once a process has triggered automount, subsequent lookups crossing that point *won't* have it counted as link traversal. Except for ones that come while automount attempt is in progress, etc.
Limit on link traversals makes obvious sense wrt avoiding loops and DoS - reaching a symlink in effect is adding a pile of path components to the path yet to be traversed. Automount points do nothing of that sort - the pending path remains as-is.
So I'm not sure it makes sense to have those contribute to the same counter. OTOH, there _is_ an unpleasant problem around follow_automount() - it's a place where we call a method with heavy stack footprint still fairly deep in stack; in mainline it can get as bad as ~2.8K deep, with this tree the worst call chain entirely inside fs/namei.c is
SyS_renameat2 -> user_path_parent -> filename_lookup -> path_lookupat -> path_init -> link_path_walk -> walk_component -> lookup_fast -> follow_managed -> ->d_automount
and it costs 1.1K; slightly more shallow chains lead from linkat(2) and do_filp_open()/do_file_open_root(). Again, mainline is more than two times worse on those.
->d_manage() gets hit on the same depth, ->d_revalidate() at a bit less than that.
FWIW, the sums on a fairly sane amd64 config are
[->d_manage] 1104
[->d_automount] 1104
[->d_revalidate] 1024
[->lookup] 992
[->put_link] 896
[->permission] 832
[->follow_link] 768
[->d_hash] 768
[->d_weak_revalidate] 624
[->create] 544
[->tmpfile] 480
[->atomic_open] 480
[->rename] 336
[->rename2] 336
[->link] 240
[->unlink] 224
[->rmdir] 176
[->mknod] 160
[->symlink] 144
[->mkdir] 144
And ->d_automount() is easily the heaviest of that bunch in terms of stack footprint. So much that I really wonder if we ought to use something like schedule_work() and (interruptibly) wait for completion; the interesting question here is how much of the initiator's state is needed by worker. The real namespace isn't - actual mounting is in finish_automount(). Credentials probably are; what about netns? Suppose a process steps on NFS4 referral point and triggers a new NFS mount; which netns should be used - that of the triggering process or that of the NFS mount where we'd run into the referral? Ditto for AFS and CIFS...
BTW, if you want to torture the whole thing wrt stack footprint, try to make /lib/firmware a symlink that would lead you through a referral point (on the mainline - do so at the maximal nesting depth). The thing is, request_firmware() will chase that one *on* *caller's* *stack*. Seeing that we do have an async variant anyway (request_firmware_nowait()), could we have request_firmware() itself go through schedule_work() (and wait for completion, of course)?
Al Viro
maintainerPATCH 52/79 link_path_walk: nd->depth massage, part 1
In reply to Al ViroFrom: Al Viro <[email protected]>
nd->stack[0] is unused until the handling of trailing symlinks and we want to get rid of that. Having fucked that transformation up several times, I went for bloody pedantic series of provably equivalent transformations. Sorry.
Step 1: keep nd->depth higher by one in link_path_walk() - increment upon entry, decrement on exits, adjust the arithmetics inside and surround the calls of functions that care about nd->depth value (nd_alloc_stack(), get_link(), put_link()) with decrement/increment pairs.
--- fs/namei.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
fs/namei.c +17 -5
@@ -1755,6 +1755,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)if (!*name)return 0 ; + nd->depth++;/* At this point we know we have a real path component. */ for (;;) {u64 hash_len;
@@ -1815,15 +1816,18 @@ Walked:if (err) {const char *s; + nd->depth--; err =nd_alloc_stack (nd); + nd->depth++;if (unlikely (err)) {path_to_nameidata (&nd->link, nd);break ; } nd->depth++; - + nd->depth--; s =get_link (nd); + nd->depth++;if (unlikely (IS_ERR (s))) { err =PTR_ERR (s);
@@ -1833,7 +1837,9 @@ Walked: err =0 ;if (unlikely (!s)) {/* jumped */ + nd->depth--;put_link (nd); + nd->depth++; nd->depth--; }else {if (*s =='/' ) {
@@ -1847,7 +1853,7 @@ Walked: ; } nd->inode = nd->path.dentry->d_inode; - nd->stack[nd->depth].name = name; + nd->stack[nd->depth -1 ].name = name;if (!*s) goto OK; name = s;
@@ -1861,19 +1867,25 @@ Walked: }terminate_walk (nd); Err: -while (unlikely (nd->depth)) { +while (unlikely (nd->depth >1 )) { + nd->depth--;put_link (nd); + nd->depth++; nd->depth--; } + nd->depth--;return err; OK: -if (unlikely (nd->depth)) { - name = nd->stack[nd->depth].name; +if (unlikely (nd->depth >1 )) { + name = nd->stack[nd->depth -1 ].name; err =walk_component (nd,LOOKUP_FOLLOW ); + nd->depth--;put_link (nd); + nd->depth++; nd->depth--; goto Walked; } + nd->depth--;return 0 ; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 53/79 link_path_walk: nd->depth massage, part 2
In reply to Al ViroFrom: Al Viro <[email protected]>
collapse adjacent increment/decrement pairs.
--- fs/namei.c | 8 -------- 1 file changed, 8 deletions(-)
fs/namei.c +0 -8
@@ -1824,8 +1824,6 @@ Walked:break ; } - nd->depth++; - nd->depth--; s =get_link (nd); nd->depth++;
@@ -1839,8 +1837,6 @@ Walked:/* jumped */ nd->depth--;put_link (nd); - nd->depth++; - nd->depth--; }else {if (*s =='/' ) {if (!nd->root.mnt)
@@ -1870,8 +1866,6 @@ Err:while (unlikely (nd->depth >1 )) { nd->depth--;put_link (nd); - nd->depth++; - nd->depth--; } nd->depth--;return err;
@@ -1881,8 +1875,6 @@ OK: err =walk_component (nd,LOOKUP_FOLLOW ); nd->depth--;put_link (nd); - nd->depth++; - nd->depth--; goto Walked; } nd->depth--;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 54/79 link_path_walk: nd->depth massage, part 3
In reply to Al ViroFrom: Al Viro <[email protected]>
remove decrement/increment surrounding nd_alloc_stack(), adjust the test in it.
--- fs/namei.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/namei.c +1 -3
@@ -539,7 +539,7 @@ static int __nd_alloc_stack(struct nameidata *nd)static inline int nd_alloc_stack (struct nameidata *nd) { -if (likely (nd->depth !=EMBEDDED_LEVELS -1 )) +if (likely (nd->depth !=EMBEDDED_LEVELS ))return 0 ;if (likely (nd->stack != nd->internal))return 0 ;
@@ -1816,9 +1816,7 @@ Walked:if (err) {const char *s; - nd->depth--; err =nd_alloc_stack (nd); - nd->depth++;if (unlikely (err)) {path_to_nameidata (&nd->link, nd);break ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 55/79 link_path_walk: nd->depth massage, part 4
In reply to Al ViroFrom: Al Viro <[email protected]>
lift increment/decrement into link_path_walk() callers.
--- fs/namei.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/namei.c +6 -4
@@ -1755,7 +1755,6 @@ static int link_path_walk(const char *name, struct nameidata *nd)if (!*name)return 0 ; - nd->depth++;/* At this point we know we have a real path component. */ for (;;) {u64 hash_len;
@@ -1865,7 +1864,6 @@ Err: nd->depth--;put_link (nd); } - nd->depth--;return err; OK:if (unlikely (nd->depth >1 )) {
@@ -1875,7 +1873,6 @@ OK:put_link (nd); goto Walked; } - nd->depth--;return 0 ; }
@@ -1978,7 +1975,10 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags,return -ECHILD ; done: current->total_link_count =0 ; -return link_path_walk (s, nd); + nd->depth++; + retval =link_path_walk (s, nd); + nd->depth--; +return retval; }static void path_cleanup (struct nameidata *nd)
@@ -2012,7 +2012,9 @@ static int trailing_symlink(struct nameidata *nd) nd->flags |=LOOKUP_JUMPED ; } nd->inode = nd->path.dentry->d_inode; + nd->depth++; error =link_path_walk (s, nd); + nd->depth--;if (unlikely (error))put_link (nd);return error;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 56/79 trailing_symlink: nd->depth massage, part 5
In reply to Al ViroFrom: Al Viro <[email protected]>
move increment of ->depth to the point where we'd discovered that get_link() has not returned an error, adjust exits accordingly.
--- fs/namei.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
fs/namei.c +10 -5
@@ -2001,8 +2001,11 @@ static int trailing_symlink(struct nameidata *nd) s =get_link (nd);if (unlikely (IS_ERR (s)))return PTR_ERR (s); -if (unlikely (!s)) + nd->depth++; +if (unlikely (!s)) { + nd->depth--;return 0 ; + }if (*s =='/' ) {if (!nd->root.mnt)set_root (nd);
@@ -2012,12 +2015,14 @@ static int trailing_symlink(struct nameidata *nd) nd->flags |=LOOKUP_JUMPED ; } nd->inode = nd->path.dentry->d_inode; - nd->depth++; error =link_path_walk (s, nd); - nd->depth--; -if (unlikely (error)) +if (unlikely (error)) { + nd->depth--;put_link (nd); -return error; +return error; + } + nd->depth--; +return 0 ; }static inline int lookup_last (struct nameidata *nd)
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 57/79 get_link: nd->depth massage, part 6
In reply to Al ViroFrom: Al Viro <[email protected]>
make get_link() increment nd->depth on successful exit
--- fs/namei.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/namei.c +2 -3
@@ -918,8 +918,10 @@ const char *get_link(struct nameidata *nd) out:path_put (&nd->path);path_put (&last->link); +return res; } } + nd->depth++;return res; }
@@ -1822,11 +1824,9 @@ Walked: } s =get_link (nd); - nd->depth++;if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); - nd->depth--; goto Err; } err =0 ;
@@ -2001,7 +2001,6 @@ static int trailing_symlink(struct nameidata *nd) s =get_link (nd);if (unlikely (IS_ERR (s)))return PTR_ERR (s); - nd->depth++;if (unlikely (!s)) { nd->depth--;return 0 ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 58/79 trailing_symlink: nd->depth massage, part 7
In reply to Al ViroFrom: Al Viro <[email protected]>
move decrement of nd->depth on successful returns into the callers.
--- fs/namei.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/namei.c +4 -4
@@ -2001,10 +2001,8 @@ static int trailing_symlink(struct nameidata *nd) s =get_link (nd);if (unlikely (IS_ERR (s)))return PTR_ERR (s); -if (unlikely (!s)) { - nd->depth--; +if (unlikely (!s))return 0 ; - }if (*s =='/' ) {if (!nd->root.mnt)set_root (nd);
@@ -2020,7 +2018,6 @@ static int trailing_symlink(struct nameidata *nd)put_link (nd);return error; } - nd->depth--;return 0 ; }
@@ -2061,6 +2058,7 @@ static int path_lookupat(int dfd, const struct filename *name,if (err)break ; err =lookup_last (nd); + nd->depth--;put_link (nd); } }
@@ -2410,6 +2408,7 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,if (err)break ; err =mountpoint_last (nd, path); + nd->depth--;put_link (nd); } out:
@@ -3296,6 +3295,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname); + nd->depth--;put_link (nd); } out:
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 59/79 put_link: nd->depth massage, part 8
In reply to Al ViroFrom: Al Viro <[email protected]>
all calls are preceded by decrement of nd->depth; move it into put_link() itself.
--- fs/namei.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
fs/namei.c +4 -14
@@ -754,7 +754,7 @@ void nd_jump_link(struct nameidata *nd, struct path *path)static inline void put_link (struct nameidata *nd) { -struct saved *last = nd->stack + nd->depth; +struct saved *last = nd->stack + --nd->depth;struct inode *inode = last->link.dentry->d_inode;if (last->cookie && inode->i_op->put_link) inode->i_op->put_link (last->link.dentry, last->cookie);
@@ -1832,7 +1832,6 @@ Walked: err =0 ;if (unlikely (!s)) {/* jumped */ - nd->depth--;put_link (nd); }else {if (*s =='/' ) {
@@ -1860,16 +1859,13 @@ Walked: }terminate_walk (nd); Err: -while (unlikely (nd->depth >1 )) { - nd->depth--; +while (unlikely (nd->depth >1 ))put_link (nd); - }return err; OK:if (unlikely (nd->depth >1 )) { name = nd->stack[nd->depth -1 ].name; err =walk_component (nd,LOOKUP_FOLLOW ); - nd->depth--;put_link (nd); goto Walked; }
@@ -2013,12 +2009,9 @@ static int trailing_symlink(struct nameidata *nd) } nd->inode = nd->path.dentry->d_inode; error =link_path_walk (s, nd); -if (unlikely (error)) { - nd->depth--; +if (unlikely (error))put_link (nd); -return error; - } -return 0 ; +return error; }static inline int lookup_last (struct nameidata *nd)
@@ -2058,7 +2051,6 @@ static int path_lookupat(int dfd, const struct filename *name,if (err)break ; err =lookup_last (nd); - nd->depth--;put_link (nd); } }
@@ -2408,7 +2400,6 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,if (err)break ; err =mountpoint_last (nd, path); - nd->depth--;put_link (nd); } out:
@@ -3295,7 +3286,6 @@ static struct file *path_openat(int dfd, struct filename *pathname,if (unlikely (error))break ; error =do_last (nd, file, op, &opened, pathname); - nd->depth--;put_link (nd); } out:
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 60/79 link_path_walk: nd->depth massage, part 9
In reply to Al ViroFrom: Al Viro <[email protected]>
Make link_path_walk() work with any value of nd->depth on entry - memorize it and use it in tests instead of comparing with 1. Don't bother with increment/decrement in path_init().
--- fs/namei.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/namei.c +4 -6
@@ -1751,6 +1751,7 @@ static inline u64 hash_name(const char *name)static int link_path_walk (const char *name,struct nameidata *nd) {int err; +int orig_depth = nd->depth;while (*name=='/' ) name++;
@@ -1859,11 +1860,11 @@ Walked: }terminate_walk (nd); Err: -while (unlikely (nd->depth >1 )) +while (unlikely (nd->depth > orig_depth))put_link (nd);return err; OK: -if (unlikely (nd->depth >1 )) { +if (unlikely (nd->depth > orig_depth)) { name = nd->stack[nd->depth -1 ].name; err =walk_component (nd,LOOKUP_FOLLOW );put_link (nd);
@@ -1971,10 +1972,7 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags,return -ECHILD ; done: current->total_link_count =0 ; - nd->depth++; - retval =link_path_walk (s, nd); - nd->depth--; -return retval; +return link_path_walk (s, nd); }static void path_cleanup (struct nameidata *nd)
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 61/79 link_path_walk: nd->depth massage, part 10
In reply to Al ViroFrom: Al Viro <[email protected]>
Get rid of orig_depth checks in OK: logics. If nd->depth is zero, we had been called from path_init() and we are done. If it is greater than 1, we are not done, whether we'd been called from path_init() or trailing_symlink(). And in case when it's 1, we might have been called from path_init() and reached the end of nested symlink (in which case nd->stack[0].name will point to the rest of pathname and we are not done) or from trailing_symlink(), in which case we are done.
Just have trailing_symlink() leave NULL in nd->stack[0].name and use that to discriminate between those cases.
--- fs/namei.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
fs/namei.c +10 -7
@@ -1864,13 +1864,15 @@ Err:put_link (nd);return err; OK: -if (unlikely (nd->depth > orig_depth)) { - name = nd->stack[nd->depth -1 ].name; - err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd); - goto Walked; - } -return 0 ; +if (!nd->depth)/* called from path_init(), done */ +return 0 ; + name = nd->stack[nd->depth -1 ].name; +if (!name)/* called from trailing_symlink(), done */ +return 0 ; + + err =walk_component (nd,LOOKUP_FOLLOW ); +put_link (nd); + goto Walked; } static int path_init(int dfd, const struct filename *name, unsigned int flags,
@@ -2006,6 +2008,7 @@ static int trailing_symlink(struct nameidata *nd) nd->flags |=LOOKUP_JUMPED ; } nd->inode = nd->path.dentry->d_inode; + nd->stack[0 ].name =NULL ; error =link_path_walk (s, nd);if (unlikely (error))put_link (nd);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 62/79 link_path_walk: end of nd->depth massage
In reply to Al ViroFrom: Al Viro <[email protected]>
get rid of orig_depth - we only use it on error exit to tell whether to stop doing put_link() when depth reaches 0 (call from path_init()) or when it reaches 1 (call from trailing_symlink()). However, in the latter case the caller would immediately follow with one more put_link(). Just keep doing it until the depth reaches zero (and simplify trailing_symlink() as the result).
--- fs/namei.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/namei.c +2 -6
@@ -1751,7 +1751,6 @@ static inline u64 hash_name(const char *name)static int link_path_walk (const char *name,struct nameidata *nd) {int err; -int orig_depth = nd->depth;while (*name=='/' ) name++;
@@ -1860,7 +1859,7 @@ Walked: }terminate_walk (nd); Err: -while (unlikely (nd->depth > orig_depth)) +while (unlikely (nd->depth))put_link (nd);return err; OK:
@@ -2009,10 +2008,7 @@ static int trailing_symlink(struct nameidata *nd) } nd->inode = nd->path.dentry->d_inode; nd->stack[0 ].name =NULL ; - error =link_path_walk (s, nd); -if (unlikely (error)) -put_link (nd); -return error; +return link_path_walk (s, nd); }static inline int lookup_last (struct nameidata *nd)
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 63/79 namei: we never need more than MAXSYMLINKS entries in nd->stack
In reply to Al ViroFrom: Al Viro <[email protected]>
The only reason why we needed one more was that purely nested MAXSYMLINKS symlinks could lead to path_init() using that many entries in addition to nd->stack[0] which it left unused.
That can't happen now - path_init() starts with entry 0 (and trailing_symlink() is called only when we'd already encountered one symlink, so no more than MAXSYMLINKS-1 are left).
--- fs/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namei.c +1 -1
@@ -528,7 +528,7 @@ static void restore_nameidata(struct nameidata *nd)static int __nd_alloc_stack (struct nameidata *nd) { -struct saved *p =kmalloc ((MAXSYMLINKS +1 ) *sizeof (struct saved ), +struct saved *p =kmalloc (MAXSYMLINKS *sizeof (struct saved ),GFP_KERNEL );if (unlikely (!p))return -ENOMEM ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 64/79 namei: lift (open-coded) terminate_walk() in follow_dotdot_rcu() into callers
In reply to Al ViroFrom: Al Viro <[email protected]>
follow_dotdot_rcu() does an equivalent of terminate_walk() on failure; shifting it into callers makes for simpler rules and those callers already have terminate_walk() on other failure exits.
--- fs/namei.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
fs/namei.c +10 -9
@@ -1230,10 +1230,6 @@ static int follow_dotdot_rcu(struct nameidata *nd)return 0 ; failed: - nd->flags &= ~LOOKUP_RCU ; -if (!(nd->flags &LOOKUP_ROOT )) - nd->root.mnt =NULL ; -rcu_read_unlock ();return -ECHILD ; }
@@ -1543,8 +1539,7 @@ static inline int handle_dots(struct nameidata *nd, int type) {if (type ==LAST_DOTDOT ) {if (nd->flags &LOOKUP_RCU ) { -if (follow_dotdot_rcu (nd)) -return -ECHILD ; +return follow_dotdot_rcu (nd); }else follow_dotdot (nd); }
@@ -1584,8 +1579,12 @@ static int walk_component(struct nameidata *nd, int follow)* to be able to know about the current root directory and * parent relationships. */ -if (unlikely (nd->last_type !=LAST_NORM )) -return handle_dots (nd, nd->last_type); +if (unlikely (nd->last_type !=LAST_NORM )) { + err =handle_dots (nd, nd->last_type); +if (err) + goto out_err; +return 0 ; + } err =lookup_fast (nd, &path, &inode);if (unlikely (err)) {if (err <0 )
@@ -2973,8 +2972,10 @@ static int do_last(struct nameidata *nd,if (nd->last_type !=LAST_NORM ) { error =handle_dots (nd, nd->last_type); -if (error) +if (unlikely (error)) { +terminate_walk (nd);return error; + } goto finish_open; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 65/79 lift terminate_walk() into callers of walk_component()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
fs/namei.c +11 -14
@@ -1579,20 +1579,16 @@ static int walk_component(struct nameidata *nd, int follow)* to be able to know about the current root directory and * parent relationships. */ -if (unlikely (nd->last_type !=LAST_NORM )) { - err =handle_dots (nd, nd->last_type); -if (err) - goto out_err; -return 0 ; - } +if (unlikely (nd->last_type !=LAST_NORM )) +return handle_dots (nd, nd->last_type); err =lookup_fast (nd, &path, &inode);if (unlikely (err)) {if (err <0 ) - goto out_err; +return err; err =lookup_slow (nd, &path);if (err <0 ) - goto out_err; +return err; inode = path.dentry->d_inode; }
@@ -1604,8 +1600,7 @@ static int walk_component(struct nameidata *nd, int follow)if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path.mnt ||unlazy_walk (nd, path.dentry))) { - err = -ECHILD ; - goto out_err; +return -ECHILD ; } }BUG_ON (inode != path.dentry->d_inode);
@@ -1618,8 +1613,6 @@ static int walk_component(struct nameidata *nd, int follow) out_path_put:path_to_nameidata (&path, nd); -out_err: -terminate_walk (nd);return err; }
@@ -1811,7 +1804,7 @@ static int link_path_walk(const char *name, struct nameidata *nd) err =walk_component (nd,LOOKUP_FOLLOW ); Walked:if (err <0 ) - goto Err; +break ;if (err) {const char *s;
@@ -2012,11 +2005,15 @@ static int trailing_symlink(struct nameidata *nd)static inline int lookup_last (struct nameidata *nd) { +int err;if (nd->last_type ==LAST_NORM && nd->last.name[nd->last.len]) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; nd->flags &= ~LOOKUP_PARENT ; -return walk_component (nd, nd->flags &LOOKUP_FOLLOW ); + err =walk_component (nd, nd->flags &LOOKUP_FOLLOW ); +if (err <0 ) +terminate_walk (nd); +return err; }/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 66/79 namei: lift (open-coded) terminate_walk() into callers of get_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/namei.c +4 -5
@@ -892,7 +892,6 @@ const char *get_link(struct nameidata *nd)mntget (nd->link.mnt);if (unlikely (current->total_link_count >=MAXSYMLINKS )) { -path_put (&nd->path);path_put (&nd->link);return ERR_PTR (-ELOOP ); }
@@ -916,7 +915,6 @@ const char *get_link(struct nameidata *nd) res = inode->i_op->follow_link (dentry, &last->cookie, nd);if (IS_ERR (res)) { out: -path_put (&nd->path);path_put (&last->link);return res; }
@@ -1819,7 +1817,7 @@ Walked:if (unlikely (IS_ERR (s))) { err =PTR_ERR (s); - goto Err; +break ; } err =0 ;if (unlikely (!s)) {
@@ -1850,7 +1848,6 @@ Walked: } }terminate_walk (nd); -Err:while (unlikely (nd->depth))put_link (nd);return err;
@@ -1986,8 +1983,10 @@ static int trailing_symlink(struct nameidata *nd)return error; nd->flags |=LOOKUP_PARENT ; s =get_link (nd); -if (unlikely (IS_ERR (s))) +if (unlikely (IS_ERR (s))) { +terminate_walk (nd);return PTR_ERR (s); + }if (unlikely (!s))return 0 ;if (*s =='/' ) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 67/79 namei: take put_link() into {lookup,mountpoint,do}_last()
In reply to Al ViroFrom: Al Viro <[email protected]>
rationale: we'll need to have terminate_walk() do put_link() on everything, which will mean that in some cases ..._last() will do put_link() anyway. Easier to have them do it in all cases.
--- fs/namei.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
fs/namei.c +21 -13
@@ -2010,6 +2010,8 @@ static inline int lookup_last(struct nameidata *nd) nd->flags &= ~LOOKUP_PARENT ; err =walk_component (nd, nd->flags &LOOKUP_FOLLOW ); +if (nd->depth) +put_link (nd);if (err <0 )terminate_walk (nd);return err;
@@ -2037,13 +2039,10 @@ static int path_lookupat(int dfd, const struct filename *name,*/ err =path_init (dfd, name, flags, nd);if (!err && !(flags &LOOKUP_PARENT )) { - err =lookup_last (nd); -while (err >0 ) { +while ((err =lookup_last (nd)) >0 ) { err =trailing_symlink (nd);if (err)break ; - err =lookup_last (nd); -put_link (nd); } }
@@ -2354,6 +2353,8 @@ done:dput (dentry); goto out; } +if (nd->depth) +put_link (nd); path->dentry = dentry; path->mnt = nd->path.mnt;if (should_follow_link (dentry, nd->flags &LOOKUP_FOLLOW )) {
@@ -2365,6 +2366,8 @@ done: error =0 ; out:terminate_walk (nd); +if (nd->depth) +put_link (nd);return error; }
@@ -2386,13 +2389,10 @@ path_mountpoint(int dfd, const struct filename *name, struct path *path,if (unlikely (err)) goto out; - err =mountpoint_last (nd, path); -while (err >0 ) { +while ((err =mountpoint_last (nd, path)) >0 ) { err =trailing_symlink (nd);if (err)break ; - err =mountpoint_last (nd, path); -put_link (nd); } out:path_cleanup (nd);
@@ -2970,6 +2970,8 @@ static int do_last(struct nameidata *nd, error =handle_dots (nd, nd->last_type);if (unlikely (error)) {terminate_walk (nd); +if (nd->depth) +put_link (nd);return error; } goto finish_open;
@@ -2995,8 +2997,11 @@ static int do_last(struct nameidata *nd,* about to look up */ error =complete_walk (nd); -if (error) +if (error) { +if (nd->depth) +put_link (nd);return error; + }audit_inode (name, dir,LOOKUP_PARENT ); error = -EISDIR ;
@@ -3087,6 +3092,8 @@ finish_lookup: } }BUG_ON (inode != path.dentry->d_inode); +if (nd->depth) +put_link (nd); nd->link = path;return 1 ; }
@@ -3110,6 +3117,8 @@ finish_lookup: finish_open: error =complete_walk (nd);if (error) { +if (nd->depth) +put_link (nd);path_put (&save_parent);return error; }
@@ -3161,6 +3170,8 @@ out:mnt_drop_write (nd->path.mnt);path_put (&save_parent);terminate_walk (nd); +if (nd->depth) +put_link (nd);return error; exit_dput:
@@ -3273,14 +3284,11 @@ static struct file *path_openat(int dfd, struct filename *pathname,if (unlikely (error)) goto out; - error =do_last (nd, file, op, &opened, pathname); -while (unlikely (error >0 )) {/* trailing symlink */ +while ((error =do_last (nd, file, op, &opened, pathname)) >0 ) { nd->flags &= ~(LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_EXCL ); error =trailing_symlink (nd);if (unlikely (error))break ; - error =do_last (nd, file, op, &opened, pathname); -put_link (nd); } out:path_cleanup (nd);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 68/79 namei: have terminate_walk() do put_link() on everything left
In reply to Al ViroFrom: Al Viro <[email protected]>
All callers of terminate_walk() are followed by more or less open-coded eqiuvalent of "do put_link() on everything left in nd->stack". Better done in terminate_walk() itself, and when we go for RCU symlink traversal we'll have to do it there anyway.
--- fs/namei.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
fs/namei.c +2 -8
@@ -1554,6 +1554,8 @@ static void terminate_walk(struct nameidata *nd) nd->root.mnt =NULL ;rcu_read_unlock (); } +while (unlikely (nd->depth)) +put_link (nd); }/*
@@ -1848,8 +1850,6 @@ Walked: } }terminate_walk (nd); -while (unlikely (nd->depth)) -put_link (nd);return err; OK:if (!nd->depth)/* called from path_init(), done */
@@ -2366,8 +2366,6 @@ done: error =0 ; out:terminate_walk (nd); -if (nd->depth) -put_link (nd);return error; }
@@ -2970,8 +2968,6 @@ static int do_last(struct nameidata *nd, error =handle_dots (nd, nd->last_type);if (unlikely (error)) {terminate_walk (nd); -if (nd->depth) -put_link (nd);return error; } goto finish_open;
@@ -3170,8 +3166,6 @@ out:mnt_drop_write (nd->path.mnt);path_put (&save_parent);terminate_walk (nd); -if (nd->depth) -put_link (nd);return error; exit_dput:
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 69/79 link_path_walk: move the OK: inside the loop
In reply to Al ViroFrom: Al Viro <[email protected]>
fewer labels that way; in particular, resuming after the end of nested symlink is straight-line.
--- fs/namei.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
fs/namei.c +15 -15
@@ -1798,11 +1798,21 @@ static int link_path_walk(const char *name, struct nameidata *nd)do { name++; }while (unlikely (*name =='/' )); -if (!*name) - goto OK; - - err =walk_component (nd,LOOKUP_FOLLOW ); -Walked: +if (unlikely (!*name)) { +OK: +/* called from path_init(), done */ +if (!nd->depth) +return 0 ; + name = nd->stack[nd->depth -1 ].name; +/* called from trailing_symlink(), done */ +if (!name) +return 0 ; +/* last component of nested symlink */ + err =walk_component (nd,LOOKUP_FOLLOW ); +put_link (nd); + }else { + err =walk_component (nd,LOOKUP_FOLLOW ); + }if (err <0 )break ;
@@ -1851,16 +1861,6 @@ Walked: }terminate_walk (nd);return err; -OK: -if (!nd->depth)/* called from path_init(), done */ -return 0 ; - name = nd->stack[nd->depth -1 ].name; -if (!name)/* called from trailing_symlink(), done */ -return 0 ; - - err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd); - goto Walked; } static int path_init(int dfd, const struct filename *name, unsigned int flags,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 70/79 namei: new calling conventions for walk_component()
In reply to Al ViroFrom: Al Viro <[email protected]>
instead of a single flag (!= 0 => we want to follow symlinks) pass two bits - WALK_GET (want to follow symlinks) and WALK_PUT (put_link() once we are done looking at the name). The latter matters only for success exits - on failure the caller will discard everything anyway.
Suggestions for better variant are welcome; what this thing aims for is making sure that pending put_link() is done *before* walk_component() decides to pick a symlink up, rather than between picking it up and acting upon it. See the next commit for payoff.
--- fs/namei.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
fs/namei.c +20 -10
@@ -1569,7 +1569,9 @@ static inline int should_follow_link(struct dentry *dentry, int follow)return unlikely (d_is_symlink (dentry)) ? follow :0 ; } -static int walk_component (struct nameidata *nd,int follow) +enum {WALK_GET =1 ,WALK_PUT =2 }; + +static int walk_component (struct nameidata *nd,int flags) {struct path path;struct inode *inode;
@@ -1579,8 +1581,12 @@ static int walk_component(struct nameidata *nd, int follow)* to be able to know about the current root directory and * parent relationships. */ -if (unlikely (nd->last_type !=LAST_NORM )) -return handle_dots (nd, nd->last_type); +if (unlikely (nd->last_type !=LAST_NORM )) { + err =handle_dots (nd, nd->last_type); +if (flags &WALK_PUT ) +put_link (nd); +return err; + } err =lookup_fast (nd, &path, &inode);if (unlikely (err)) {if (err <0 )
@@ -1596,7 +1602,9 @@ static int walk_component(struct nameidata *nd, int follow)if (d_is_negative (path.dentry)) goto out_path_put; -if (should_follow_link (path.dentry, follow)) { +if (flags &WALK_PUT ) +put_link (nd); +if (should_follow_link (path.dentry, flags &WALK_GET )) {if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path.mnt ||unlazy_walk (nd, path.dentry))) {
@@ -1808,10 +1816,9 @@ OK:if (!name)return 0 ;/* last component of nested symlink */ - err =walk_component (nd,LOOKUP_FOLLOW ); -put_link (nd); + err =walk_component (nd,WALK_GET |WALK_PUT ); }else { - err =walk_component (nd,LOOKUP_FOLLOW ); + err =walk_component (nd,WALK_GET ); }if (err <0 )break ;
@@ -2009,9 +2016,12 @@ static inline int lookup_last(struct nameidata *nd) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; nd->flags &= ~LOOKUP_PARENT ; - err =walk_component (nd, nd->flags &LOOKUP_FOLLOW ); -if (nd->depth) -put_link (nd); + err =walk_component (nd, + nd->flags &LOOKUP_FOLLOW + ? nd->depth + ?WALK_PUT |WALK_GET + :WALK_GET + :0 );if (err <0 )terminate_walk (nd);return err;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 71/79 namei: make should_follow_link() store the link in nd->link
In reply to Al ViroFrom: Al Viro <[email protected]>
... if it decides to follow, that is.
--- fs/namei.c | 63 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 29 deletions(-)
fs/namei.c +34 -29
@@ -1558,15 +1558,31 @@ static void terminate_walk(struct nameidata *nd)put_link (nd); } +static int pick_link (struct nameidata *nd,struct path *link) +{ +if (nd->flags &LOOKUP_RCU ) { +if (unlikely (nd->path.mnt != link->mnt || +unlazy_walk (nd, link->dentry))) { +return -ECHILD ; + } + } + nd->link = *link; +return 1 ; +} +/* * Do we need to follow links? We _really_ want to be able * to do this check without having to look at inode->i_op, * so we keep a cache of "no, this doesn't need follow_link" * for the common case. */ -static inline int should_follow_link (struct dentry *dentry,int follow) +static inline int should_follow_link (struct nameidata *nd,struct path *link,int follow) { -return unlikely (d_is_symlink (dentry)) ? follow :0 ; +if (likely (!d_is_symlink (link->dentry))) +return 0 ; +if (!follow) +return 0 ; +return pick_link (nd, link); }enum {WALK_GET =1 ,WALK_PUT =2 };
@@ -1604,17 +1620,9 @@ static int walk_component(struct nameidata *nd, int flags)if (flags &WALK_PUT )put_link (nd); -if (should_follow_link (path.dentry, flags &WALK_GET )) { -if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->path.mnt != path.mnt || -unlazy_walk (nd, path.dentry))) { -return -ECHILD ; - } - } -BUG_ON (inode != path.dentry->d_inode); - nd->link = path; -return 1 ; - } + err =should_follow_link (nd, &path, flags &WALK_GET ); +if (unlikely (err)) +return err;path_to_nameidata (&path, nd); nd->inode = inode;return 0 ;
@@ -2367,9 +2375,11 @@ done:put_link (nd); path->dentry = dentry; path->mnt = nd->path.mnt; -if (should_follow_link (dentry, nd->flags &LOOKUP_FOLLOW )) { - nd->link = *path; -return 1 ; + error =should_follow_link (nd, path, nd->flags &LOOKUP_FOLLOW ); +if (unlikely (error)) { +if (error <0 ) + goto out; +return error; }mntget (path->mnt);follow_mount (path);
@@ -3089,19 +3099,14 @@ finish_lookup: goto out; } -if (should_follow_link (path.dentry, nd->flags &LOOKUP_FOLLOW )) { -if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->path.mnt != path.mnt || -unlazy_walk (nd, path.dentry))) { - error = -ECHILD ; - goto out; - } - } -BUG_ON (inode != path.dentry->d_inode); -if (nd->depth) -put_link (nd); - nd->link = path; -return 1 ; +if (nd->depth) +put_link (nd); + + error =should_follow_link (nd, &path, nd->flags &LOOKUP_FOLLOW ); +if (unlikely (error)) { +if (error <0 ) + goto out; +return error; }if (unlikely (d_is_symlink (path.dentry)) && !(open_flag &O_PATH )) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 72/79 namei: move link count check and stack allocation into pick_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
fs/namei.c +12 -15
@@ -891,16 +891,10 @@ const char *get_link(struct nameidata *nd)if (nd->link.mnt == nd->path.mnt)mntget (nd->link.mnt); -if (unlikely (current->total_link_count >=MAXSYMLINKS )) { -path_put (&nd->link); -return ERR_PTR (-ELOOP ); - } - last->link = nd->link; last->cookie =NULL ;cond_resched (); - current->total_link_count++;touch_atime (&last->link);
@@ -1560,12 +1554,23 @@ static void terminate_walk(struct nameidata *nd)static int pick_link (struct nameidata *nd,struct path *link) { +int error; +if (unlikely (current->total_link_count++ >=MAXSYMLINKS )) { +path_to_nameidata (link, nd); +return -ELOOP ; + }if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != link->mnt ||unlazy_walk (nd, link->dentry))) {return -ECHILD ; } } + error =nd_alloc_stack (nd); +if (unlikely (error)) { +path_to_nameidata (link, nd); +return error; + } + nd->link = *link;return 1 ; }
@@ -1832,15 +1837,7 @@ OK:break ;if (err) { -const char *s; - - err =nd_alloc_stack (nd); -if (unlikely (err)) { -path_to_nameidata (&nd->link, nd); -break ; - } - - s =get_link (nd); +const char *s =get_link (nd);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 73/79 lustre: rip the private symlink nesting limit out
In reply to Al ViroFrom: Al Viro <[email protected]>
--- drivers/staging/lustre/lustre/llite/symlink.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/staging/lustre/lustre/llite/symlink.c +3 -12
@@ -126,18 +126,9 @@ static const char *ll_follow_link(struct dentry *dentry, void **cookie, struct nchar *symname =NULL ;CDEBUG (D_VFSTRACE ,"VFS Op\n" ); -/* Limit the recursive symlink depth to 5 instead of default -* 8 links when kernel has 4k stack to prevent stack overflow. -* For 8k stacks we need to limit it to 7 for local servers. */ -if (THREAD_SIZE <8192 && current->link_count >=6 ) { - rc = -ELOOP ; - }else if (THREAD_SIZE ==8192 && current->link_count >=8 ) { - rc = -ELOOP ; - }else { -ll_inode_size_lock (inode); - rc =ll_readlink_internal (inode, &request, &symname); -ll_inode_size_unlock (inode); - } +ll_inode_size_lock (inode); + rc =ll_readlink_internal (inode, &request, &symname); +ll_inode_size_unlock (inode);if (rc) {ptlrpc_req_finished (request);return ERR_PTR (rc);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 74/79 VFS: replace {, total_}link_count in task_struct with pointer to nameidata
In reply to Al ViroFrom: NeilBrown <[email protected]>
task_struct currently contains two ad-hoc members for use by the VFS:link_count and total_link_count. These are only interesting to fs/namei.c, so exposing them explicitly is poor layering. Incidentally, link_count isn't used anymore, so it can just die.
This patches replaces those with a single pointer to 'struct nameidata'. This structure represents the current filename lookup of which there can only be one per process, and is a natural place to store total_link_count.
This will allow the current "nameidata" argument to all follow_link operations to be removed as current->nameidata can be used instead in the _very_ few instances that care about it at all.
As there are occasional circumstances where pathname lookup can recurse, such as through kern_path_locked, we always save and old current->nameidata (if there is one) when setting a new value, and make sure any active link_counts are preserved.
follow_mount and follow_automount now get a 'struct nameidata *' rather than 'int flags' so that they can directly access total_link_count, rather than going through 'current'.
--- fs/namei.c | 70 ++++++++++++++++++++++++++++----------------------- include/linux/sched.h | 2 +- 2 files changed, 40 insertions(+), 32 deletions(-)
fs/namei.c +39 -31
@@ -505,6 +505,7 @@ struct nameidata {unsigned seq, m_seq;int last_type;unsigned depth; +int total_link_count;struct file *base;struct saved {struct path link;
@@ -513,16 +514,25 @@ struct nameidata { } *stack, internal[EMBEDDED_LEVELS ]; }; -static void set_nameidata (struct nameidata *nd) +static struct nameidata *set_nameidata (struct nameidata *p) { - nd->stack = nd->internal; +struct nameidata *old = current->nameidata; + p->stack = p->internal; + p->total_link_count = old ? old->total_link_count :0 ; + current->nameidata = p; +return old; } -static void restore_nameidata (struct nameidata *nd) +static void restore_nameidata (struct nameidata *old) { -if (nd->stack != nd->internal) { -kfree (nd->stack); - nd->stack = nd->internal; +struct nameidata *now = current->nameidata; + + current->nameidata = old; +if (old) + old->total_link_count = now->total_link_count; +if (now->stack != now->internal) { +kfree (now->stack); + now->stack = now->internal; } }
@@ -970,7 +980,7 @@ EXPORT_SYMBOL(follow_up);* - return -EISDIR to tell follow_managed() to stop and return the path we * were called with. */ -static int follow_automount (struct path *path,unsigned flags, +static int follow_automount (struct path *path,struct nameidata *nd,bool *need_mntput) {struct vfsmount *mnt;
@@ -990,13 +1000,13 @@ static int follow_automount(struct path *path, unsigned flags,* as being automount points. These will need the attentions * of the daemon to instantiate them before they can be used. */ -if (!(flags & (LOOKUP_PARENT |LOOKUP_DIRECTORY | -LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_AUTOMOUNT )) && +if (!(nd->flags & (LOOKUP_PARENT |LOOKUP_DIRECTORY | +LOOKUP_OPEN |LOOKUP_CREATE |LOOKUP_AUTOMOUNT )) && path->dentry->d_inode)return -EISDIR ; - current->total_link_count++; -if (current->total_link_count >=40 ) + nd->total_link_count++; +if (nd->total_link_count >=40 )return -ELOOP ; mnt = path->dentry->d_op->d_automount (path);
@@ -1010,7 +1020,7 @@ static int follow_automount(struct path *path, unsigned flags,* the path being looked up; if it wasn't then the remainder of * the path is inaccessible and we should say so. */ -if (PTR_ERR (mnt) == -EISDIR && (flags &LOOKUP_PARENT )) +if (PTR_ERR (mnt) == -EISDIR && (nd->flags &LOOKUP_PARENT ))return -EREMOTE ;return PTR_ERR (mnt); }
@@ -1050,7 +1060,7 @@ static int follow_automount(struct path *path, unsigned flags,* * Serialization is taken care of in namespace.c */ -static int follow_managed (struct path *path,unsigned flags) +static int follow_managed (struct path *path,struct nameidata *nd) {struct vfsmount *mnt = path->mnt;/* held by caller, must be left alone */ unsigned managed;
@@ -1094,7 +1104,7 @@ static int follow_managed(struct path *path, unsigned flags)/* Handle an automount point */ if (managed &DCACHE_NEED_AUTOMOUNT ) { - ret =follow_automount (path, flags, &need_mntput); + ret =follow_automount (path, nd, &need_mntput);if (ret <0 )break ;continue ;
@@ -1475,7 +1485,7 @@ unlazy: path->mnt = mnt; path->dentry = dentry; - err =follow_managed (path, nd->flags); + err =follow_managed (path, nd);if (unlikely (err <0 )) {path_put_conditional (path, nd);return err;
@@ -1505,7 +1515,7 @@ static int lookup_slow(struct nameidata *nd, struct path *path)return PTR_ERR (dentry); path->mnt = nd->path.mnt; path->dentry = dentry; - err =follow_managed (path, nd->flags); + err =follow_managed (path, nd);if (unlikely (err <0 )) {path_put_conditional (path, nd);return err;
@@ -1555,7 +1565,7 @@ static void terminate_walk(struct nameidata *nd)static int pick_link (struct nameidata *nd,struct path *link) {int error; -if (unlikely (current->total_link_count++ >=MAXSYMLINKS )) { +if (unlikely (nd->total_link_count++ >=MAXSYMLINKS )) {path_to_nameidata (link, nd);return -ELOOP ; }
@@ -1973,7 +1983,7 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags,rcu_read_unlock ();return -ECHILD ; done: - current->total_link_count =0 ; + nd->total_link_count =0 ;return link_path_walk (s, nd); }
@@ -2079,10 +2089,9 @@ static int filename_lookup(int dfd, struct filename *name, unsigned int flags, struct nameidata *nd) { int retval; +struct nameidata *saved_nd =set_nameidata (nd); -set_nameidata (nd); retval =path_lookupat (dfd, name, flags |LOOKUP_RCU , nd); -if (unlikely (retval == -ECHILD )) retval =path_lookupat (dfd, name, flags, nd);if (unlikely (retval == -ESTALE ))
@@ -2090,7 +2099,7 @@ static int filename_lookup(int dfd, struct filename *name,if (likely (!retval))audit_inode (name, nd->path.dentry, flags &LOOKUP_PARENT ); -restore_nameidata (nd); +restore_nameidata (saved_nd);return retval; }
@@ -2418,11 +2427,11 @@ static int filename_mountpoint(int dfd, struct filename *name, struct path *path, unsigned int flags) { - struct nameidata nd; + struct nameidata nd, *saved;int error;if (IS_ERR (name))return PTR_ERR (name); -set_nameidata (&nd); + saved =set_nameidata (&nd); error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_RCU );if (unlikely (error == -ECHILD )) error =path_mountpoint (dfd, name, path, &nd, flags);
@@ -2430,7 +2439,7 @@ filename_mountpoint(int dfd, struct filename *name, struct path *path, error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_REVAL );if (likely (!error))audit_inode (name, path->dentry,0 ); -restore_nameidata (&nd); +restore_nameidata (saved);putname (name);return error; }
@@ -3079,7 +3088,7 @@ retry_lookup:if ((open_flag & (O_EXCL |O_CREAT )) == (O_EXCL |O_CREAT )) goto exit_dput; - error =follow_managed (&path, nd->flags); + error =follow_managed (&path, nd);if (error <0 ) goto exit_dput;
@@ -3317,31 +3326,29 @@ out:struct file *do_filp_open (int dfd,struct filename *pathname,const struct open_flags *op) { -struct nameidata nd; +struct nameidata nd, *saved_nd =set_nameidata (&nd);int flags = op->lookup_flags;struct file *filp; -set_nameidata (&nd); filp =path_openat (dfd, pathname, &nd, op, flags |LOOKUP_RCU );if (unlikely (filp ==ERR_PTR (-ECHILD ))) filp =path_openat (dfd, pathname, &nd, op, flags);if (unlikely (filp ==ERR_PTR (-ESTALE ))) filp =path_openat (dfd, pathname, &nd, op, flags |LOOKUP_REVAL ); -restore_nameidata (&nd); +restore_nameidata (saved_nd);return filp; }struct file *do_file_open_root (struct dentry *dentry,struct vfsmount *mnt,const char *name,const struct open_flags *op) { -struct nameidata nd; +struct nameidata nd, *saved_nd;struct file *file;struct filename *filename;int flags = op->lookup_flags |LOOKUP_ROOT ; nd.root.mnt = mnt; nd.root.dentry = dentry; -set_nameidata (&nd);if (d_is_symlink (dentry) && op->intent &LOOKUP_OPEN )return ERR_PTR (-ELOOP );
@@ -3350,12 +3357,13 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,if (unlikely (IS_ERR (filename)))return ERR_CAST (filename); + saved_nd =set_nameidata (&nd); file =path_openat (-1 , filename, &nd, op, flags |LOOKUP_RCU );if (unlikely (file ==ERR_PTR (-ECHILD ))) file =path_openat (-1 , filename, &nd, op, flags);if (unlikely (file ==ERR_PTR (-ESTALE ))) file =path_openat (-1 , filename, &nd, op, flags |LOOKUP_REVAL ); -restore_nameidata (&nd); +restore_nameidata (saved_nd);putname (filename);return file; }
include/linux/sched.h +1 -1
@@ -1469,7 +1469,7 @@ struct task_struct {it with task_lock()) - initialized normally by setup_new_exec */ /* file system info */ -int link_count, total_link_count; +struct nameidata *nameidata;#ifdef CONFIG_SYSVIPC /* ipc stuff */ struct sysv_sem sysvsem;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 75/79 namei: simplify the callers of follow_managed()
In reply to Al ViroFrom: Al Viro <[email protected]>
now that it gets nameidata, no reason to have setting LOOKUP_JUMPED on mountpoint crossing and calling path_put_conditional() on failures done in every caller.
--- fs/namei.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-)
fs/namei.c +10 -22
@@ -1118,7 +1118,11 @@ static int follow_managed(struct path *path, struct nameidata *nd)mntput (path->mnt);if (ret == -EISDIR ) ret =0 ; -return ret <0 ? ret : need_mntput; +if (need_mntput) + nd->flags |=LOOKUP_JUMPED ; +if (unlikely (ret <0 )) +path_put_conditional (path, nd); +return ret; }int follow_down_one (struct path *path)
@@ -1486,14 +1490,9 @@ unlazy: path->mnt = mnt; path->dentry = dentry; err =follow_managed (path, nd); -if (unlikely (err <0 )) { -path_put_conditional (path, nd); -return err; - } -if (err) - nd->flags |=LOOKUP_JUMPED ; - *inode = path->dentry->d_inode; -return 0 ; +if (likely (!err)) + *inode = path->dentry->d_inode; +return err; need_lookup:return 1 ;
@@ -1503,7 +1502,6 @@ need_lookup:static int lookup_slow (struct nameidata *nd,struct path *path) {struct dentry *dentry, *parent; -int err; parent = nd->path.dentry;BUG_ON (nd->inode != parent->d_inode);
@@ -1515,14 +1513,7 @@ static int lookup_slow(struct nameidata *nd, struct path *path)return PTR_ERR (dentry); path->mnt = nd->path.mnt; path->dentry = dentry; - err =follow_managed (path, nd); -if (unlikely (err <0 )) { -path_put_conditional (path, nd); -return err; - } -if (err) - nd->flags |=LOOKUP_JUMPED ; -return 0 ; +return follow_managed (path, nd); }static inline int may_lookup (struct nameidata *nd)
@@ -3090,10 +3081,7 @@ retry_lookup: error =follow_managed (&path, nd);if (error <0 ) - goto exit_dput; - -if (error) - nd->flags |=LOOKUP_JUMPED ; + goto out;BUG_ON (nd->flags &LOOKUP_RCU ); inode = path.dentry->d_inode;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 76/79 don't pass nameidata to ->follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
its only use is getting passed to nd_jump_link(), which can obtain it from current->nameidata
--- Documentation/filesystems/Locking | 2 +- Documentation/filesystems/vfs.txt | 2 +- drivers/staging/lustre/lustre/llite/symlink.c | 2 +- fs/9p/vfs_inode.c | 2 +- fs/9p/vfs_inode_dotl.c | 2 +- fs/autofs4/symlink.c | 2 +- fs/befs/linuxvfs.c | 4 ++-- fs/cifs/cifsfs.h | 2 +- fs/cifs/link.c | 2 +- fs/configfs/symlink.c | 2 +- fs/ecryptfs/inode.c | 2 +- fs/ext4/symlink.c | 2 +- fs/f2fs/namei.c | 4 ++-- fs/fuse/dir.c | 2 +- fs/gfs2/inode.c | 2 +- fs/hostfs/hostfs_kern.c | 2 +- fs/hppfs/hppfs.c | 4 ++-- fs/kernfs/symlink.c | 2 +- fs/libfs.c | 2 +- fs/namei.c | 11 ++++++----- fs/nfs/symlink.c | 2 +- fs/overlayfs/inode.c | 4 ++-- fs/proc/base.c | 4 ++-- fs/proc/inode.c | 2 +- fs/proc/namespaces.c | 4 ++-- fs/proc/self.c | 2 +- fs/proc/thread_self.c | 2 +- fs/xfs/xfs_iops.c | 3 +-- include/linux/fs.h | 6 +++--- include/linux/namei.h | 2 +- mm/shmem.c | 2 +- 31 files changed, 44 insertions(+), 44 deletions(-)
Documentation/filesystems/Locking +1 -1
@@ -50,7 +50,7 @@ prototypes: int (*rename2) (struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); int (*readlink) (struct dentry *, char __user *,int); - const char *(*follow_link) (struct dentry *, void **, struct nameidata *); + const char *(*follow_link) (struct dentry *, void **); void (*put_link) (struct dentry *, void *); void (*truncate) (struct inode *); int (*permission) (struct inode *, int, unsigned int);
Documentation/filesystems/vfs.txt +1 -1
@@ -350,7 +350,7 @@ struct inode_operations { int (*rename2) (struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); int (*readlink) (struct dentry *, char __user *,int); - const char *(*follow_link) (struct dentry *, void **, struct nameidata *); + const char *(*follow_link) (struct dentry *, void **); void (*put_link) (struct dentry *, void *); int (*permission) (struct inode *, int); int (*get_acl)(struct inode *, int);
drivers/staging/lustre/lustre/llite/symlink.c +1 -1
@@ -118,7 +118,7 @@ failed:return rc; } -static const char *ll_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *ll_follow_link (struct dentry *dentry,void **cookie) {struct inode *inode =d_inode (dentry);struct ptlrpc_request *request =NULL ;
fs/9p/vfs_inode.c +1 -1
@@ -1230,7 +1230,7 @@ ino_t v9fs_qid2ino(struct p9_qid *qid)* */ -static const char *v9fs_vfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *v9fs_vfs_follow_link (struct dentry *dentry,void **cookie) {struct v9fs_session_info *v9ses =v9fs_dentry2v9ses (dentry);struct p9_fid *fid =v9fs_fid_lookup (dentry);
fs/9p/vfs_inode_dotl.c +1 -1
@@ -910,7 +910,7 @@ error:*/ static const char * -v9fs_vfs_follow_link_dotl (struct dentry *dentry,void **cookie,struct nameidata *nd) +v9fs_vfs_follow_link_dotl (struct dentry *dentry,void **cookie) {struct p9_fid *fid =v9fs_fid_lookup (dentry);char *target;
fs/autofs4/symlink.c +1 -1
@@ -12,7 +12,7 @@#include "autofs_i.h" -static const char *autofs4_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *autofs4_follow_link (struct dentry *dentry,void **cookie) {struct autofs_sb_info *sbi =autofs4_sbi (dentry->d_sb);struct autofs_info *ino =autofs4_dentry_ino (dentry);
fs/befs/linuxvfs.c +2 -2
@@ -42,7 +42,7 @@ static struct inode *befs_iget(struct super_block *, unsigned long);static struct inode *befs_alloc_inode (struct super_block *sb);static void befs_destroy_inode (struct inode *inode);static void befs_destroy_inodecache (void ); -static const char *befs_follow_link (struct dentry *,void **,struct nameidata *nd); +static const char *befs_follow_link (struct dentry *,void **);static int befs_utf2nls (struct super_block *sb,const char *in,int in_len,char **out,int *out_len); static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,
@@ -464,7 +464,7 @@ befs_destroy_inodecache(void)* flag is set. */ static const char * -befs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +befs_follow_link (struct dentry *dentry,void **cookie) {struct super_block *sb = dentry->d_sb;struct befs_inode_info *befs_ino =BEFS_I (d_inode (dentry));
fs/cifs/cifsfs.h +1 -1
@@ -120,7 +120,7 @@ extern struct vfsmount *cifs_dfs_d_automount(struct path *path);#endif /* Functions related to symlinks */ -extern const char *cifs_follow_link (struct dentry *direntry,void **cookie,struct nameidata *nd); +extern const char *cifs_follow_link (struct dentry *direntry,void **cookie);extern int cifs_readlink (struct dentry *direntry,char __user *buffer,int buflen); extern int cifs_symlink(struct inode *inode, struct dentry *direntry,
fs/cifs/link.c +1 -1
@@ -627,7 +627,7 @@ cifs_hl_exit: }const char * -cifs_follow_link (struct dentry *direntry,void **cookie,struct nameidata *nd) +cifs_follow_link (struct dentry *direntry,void **cookie) {struct inode *inode =d_inode (direntry);int rc = -ENOMEM ;
fs/configfs/symlink.c +1 -1
@@ -279,7 +279,7 @@ static int configfs_getlink(struct dentry *dentry, char * path) } -static const char *configfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *configfs_follow_link (struct dentry *dentry,void **cookie) {unsigned long page =get_zeroed_page (GFP_KERNEL );int error;
fs/ecryptfs/inode.c +1 -1
@@ -675,7 +675,7 @@ out:return rc ?ERR_PTR (rc) : buf; } -static const char *ecryptfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *ecryptfs_follow_link (struct dentry *dentry,void **cookie) {size_t len;char *buf =ecryptfs_readlink_lower (dentry, &len);
fs/ext4/symlink.c +1 -1
@@ -23,7 +23,7 @@#include "xattr.h" #ifdef CONFIG_EXT4_FS_ENCRYPTION -static const char *ext4_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *ext4_follow_link (struct dentry *dentry,void **cookie) {struct page *cpage =NULL ;char *caddr, *paddr =NULL ;
fs/f2fs/namei.c +2 -2
@@ -296,9 +296,9 @@ fail:return err; } -static const char *f2fs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *f2fs_follow_link (struct dentry *dentry,void **cookie) { -const char *link =page_follow_link_light (dentry, cookie, nd); +const char *link =page_follow_link_light (dentry, cookie);if (!IS_ERR (link) && !*link) {/* this is broken symlink case */ page_put_link (dentry, *cookie);
fs/fuse/dir.c +1 -1
@@ -1365,7 +1365,7 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)return err; } -static const char *fuse_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *fuse_follow_link (struct dentry *dentry,void **cookie) {struct inode *inode =d_inode (dentry);struct fuse_conn *fc =get_fuse_conn (inode);
fs/gfs2/inode.c +1 -1
@@ -1548,7 +1548,7 @@ out:* Returns: 0 on success or error code */ -static const char *gfs2_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *gfs2_follow_link (struct dentry *dentry,void **cookie) {struct gfs2_inode *ip =GFS2_I (d_inode (dentry));struct gfs2_holder i_gh;
fs/hostfs/hostfs_kern.c +1 -1
@@ -892,7 +892,7 @@ static const struct inode_operations hostfs_dir_iops = { .setattr = hostfs_setattr, }; -static const char *hostfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *hostfs_follow_link (struct dentry *dentry,void **cookie) {char *link =__getname ();if (link) {
fs/hppfs/hppfs.c +2 -2
@@ -642,11 +642,11 @@ static int hppfs_readlink(struct dentry *dentry, char __user *buffer, buflen); } -static const char *hppfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *hppfs_follow_link (struct dentry *dentry,void **cookie) {struct dentry *proc_dentry =HPPFS_I (d_inode (dentry))->proc_dentry; -return d_inode (proc_dentry)->i_op->follow_link (proc_dentry, cookie, nd); +return d_inode (proc_dentry)->i_op->follow_link (proc_dentry, cookie); }static void hppfs_put_link (struct dentry *dentry,void *cookie)
fs/kernfs/symlink.c +1 -1
@@ -112,7 +112,7 @@ static int kernfs_getlink(struct dentry *dentry, char *path)return error; } -static const char *kernfs_iop_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *kernfs_iop_follow_link (struct dentry *dentry,void **cookie) {int error = -ENOMEM ;unsigned long page =get_zeroed_page (GFP_KERNEL );
fs/libfs.c +1 -1
@@ -1091,7 +1091,7 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp, }EXPORT_SYMBOL (simple_nosetlease); -const char *simple_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +const char *simple_follow_link (struct dentry *dentry,void **cookie) {return d_inode (dentry)->i_link; }
fs/namei.c +6 -5
@@ -753,8 +753,9 @@ static inline void path_to_nameidata(const struct path *path,* Helper to directly jump to a known parsed path from ->follow_link, * caller must have taken a reference to path beforehand. */ -void nd_jump_link (struct nameidata *nd,struct path *path) +void nd_jump_link (struct path *path) { +struct nameidata *nd = current->nameidata;path_put (&nd->path); nd->path = *path;
@@ -916,7 +917,7 @@ const char *get_link(struct nameidata *nd) nd->last_type =LAST_BIND ; res = inode->i_link;if (!res) { - res = inode->i_op->follow_link (dentry, &last->cookie, nd); + res = inode->i_op->follow_link (dentry, &last->cookie);if (IS_ERR (res)) { out:path_put (&last->link);
@@ -4479,12 +4480,12 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)int res;if (!link) { - link = dentry->d_inode->i_op->follow_link (dentry, &cookie,NULL ); + link = dentry->d_inode->i_op->follow_link (dentry, &cookie);if (IS_ERR (link))return PTR_ERR (link); } res =readlink_copy (buffer, buflen, link); -if (cookie && dentry->d_inode->i_op->put_link) +if (dentry->d_inode->i_op->put_link) dentry->d_inode->i_op->put_link (dentry, cookie);return res; }
@@ -4517,7 +4518,7 @@ int page_readlink(struct dentry *dentry, char __user *buffer, int buflen) }EXPORT_SYMBOL (page_readlink); -const char *page_follow_link_light (struct dentry *dentry,void **cookie,struct nameidata *nd) +const char *page_follow_link_light (struct dentry *dentry,void **cookie) {struct page *page =NULL ;char *res =page_getlink (dentry, &page);
fs/nfs/symlink.c +1 -1
@@ -42,7 +42,7 @@ error:return -EIO ; } -static const char *nfs_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *nfs_follow_link (struct dentry *dentry,void **cookie) {struct inode *inode =d_inode (dentry);struct page *page;
fs/overlayfs/inode.c +2 -2
@@ -140,7 +140,7 @@ struct ovl_link_data {void *cookie; }; -static const char *ovl_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *ovl_follow_link (struct dentry *dentry,void **cookie) {struct dentry *realdentry;struct inode *realinode;
@@ -160,7 +160,7 @@ static const char *ovl_follow_link(struct dentry *dentry, void **cookie, struct data->realdentry = realdentry; } - ret = realinode->i_op->follow_link (realdentry, cookie, nd); + ret = realinode->i_op->follow_link (realdentry, cookie);if (IS_ERR_OR_NULL (ret)) {kfree (data);return ret;
fs/proc/base.c +2 -2
@@ -1380,7 +1380,7 @@ static int proc_exe_link(struct dentry *dentry, struct path *exe_path)return -ENOENT ; } -static const char *proc_pid_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *proc_pid_follow_link (struct dentry *dentry,void **cookie) {struct inode *inode =d_inode (dentry);struct path path;
@@ -1394,7 +1394,7 @@ static const char *proc_pid_follow_link(struct dentry *dentry, void **cookie, stif (error) goto out; -nd_jump_link (nd, &path); +nd_jump_link (&path);return NULL ; out:return ERR_PTR (error);
fs/proc/inode.c +1 -1
@@ -393,7 +393,7 @@ static const struct file_operations proc_reg_file_ops_no_compat = { };#endif -static const char *proc_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *proc_follow_link (struct dentry *dentry,void **cookie) {struct proc_dir_entry *pde =PDE (d_inode (dentry));if (unlikely (!use_pde (pde)))
fs/proc/namespaces.c +2 -2
@@ -30,7 +30,7 @@ static const struct proc_ns_operations *ns_entries[] = { &mntns_operations, }; -static const char *proc_ns_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *proc_ns_follow_link (struct dentry *dentry,void **cookie) {struct inode *inode =d_inode (dentry);const struct proc_ns_operations *ns_ops =PROC_I (inode)->ns_ops;
@@ -45,7 +45,7 @@ static const char *proc_ns_follow_link(struct dentry *dentry, void **cookie, strif (ptrace_may_access (task,PTRACE_MODE_READ )) { error =ns_get_path (&ns_path, task, ns_ops);if (!error) -nd_jump_link (nd, &ns_path); +nd_jump_link (&ns_path); }put_task_struct (task);return error;
fs/proc/self.c +1 -1
@@ -18,7 +18,7 @@ static int proc_self_readlink(struct dentry *dentry, char __user *buffer,return readlink_copy (buffer, buflen, tmp); } -static const char *proc_self_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *proc_self_follow_link (struct dentry *dentry,void **cookie) {struct pid_namespace *ns = dentry->d_sb->s_fs_info;pid_t tgid =task_tgid_nr_ns (current, ns);
fs/proc/thread_self.c +1 -1
@@ -19,7 +19,7 @@ static int proc_thread_self_readlink(struct dentry *dentry, char __user *buffer,return readlink_copy (buffer, buflen, tmp); } -static const char *proc_thread_self_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *proc_thread_self_follow_link (struct dentry *dentry,void **cookie) {struct pid_namespace *ns = dentry->d_sb->s_fs_info;pid_t tgid =task_tgid_nr_ns (current, ns);
fs/xfs/xfs_iops.c +1 -2
@@ -416,8 +416,7 @@ xfs_vn_rename( STATIC const char *xfs_vn_follow_link (struct dentry *dentry, -void **cookie, -struct nameidata *nd) +void **cookie) {char *link;int error = -ENOMEM ;
include/linux/fs.h +3 -3
@@ -1608,7 +1608,7 @@ struct file_operations {struct inode_operations {struct dentry * (*lookup) (struct inode *,struct dentry *,unsigned int ); -const char * (*follow_link) (struct dentry *,void **,struct nameidata *); +const char * (*follow_link) (struct dentry *,void **);int (*permission) (struct inode *,int );struct posix_acl * (*get_acl)(struct inode *,int );
@@ -2705,7 +2705,7 @@ extern const struct file_operations generic_ro_fops;extern int readlink_copy (char __user *,int ,const char *);extern int page_readlink (struct dentry *,char __user *,int ); -extern const char *page_follow_link_light (struct dentry *,void **,struct nameidata *); +extern const char *page_follow_link_light (struct dentry *,void **);extern void page_put_link (struct dentry *,void *);extern int __page_symlink (struct inode *inode,const char *symname,int len,int nofs);
@@ -2722,7 +2722,7 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes);void inode_sub_bytes (struct inode *inode,loff_t bytes);loff_t inode_get_bytes (struct inode *inode);void inode_set_bytes (struct inode *inode,loff_t bytes); -const char *simple_follow_link (struct dentry *,void **,struct nameidata *); +const char *simple_follow_link (struct dentry *,void **);extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);
include/linux/namei.h +1 -1
@@ -72,7 +72,7 @@ extern int follow_up(struct path *);extern struct dentry *lock_rename (struct dentry *,struct dentry *);extern void unlock_rename (struct dentry *,struct dentry *); -extern void nd_jump_link (struct nameidata *nd,struct path *path); +extern void nd_jump_link (struct path *path);static inline void nd_terminate_link (void *name,size_t len,size_t maxlen) {
mm/shmem.c +1 -1
@@ -2475,7 +2475,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn 0 ; } -static const char *shmem_follow_link (struct dentry *dentry,void **cookie,struct nameidata *nd) +static const char *shmem_follow_link (struct dentry *dentry,void **cookie) {struct page *page =NULL ;int error =shmem_getpage (d_inode (dentry),0 , &page,SGP_READ ,NULL );
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 77/79 namei: move unlazying on symlinks towards get_link() call sites
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-)
fs/namei.c +33 -12
@@ -538,10 +538,18 @@ static void restore_nameidata(struct nameidata *old)static int __nd_alloc_stack (struct nameidata *nd) { -struct saved *p =kmalloc (MAXSYMLINKS *sizeof (struct saved ), -GFP_KERNEL ); -if (unlikely (!p)) -return -ENOMEM ; +struct saved *p; +if (nd->flags &LOOKUP_RCU ) { + p =kmalloc (MAXSYMLINKS *sizeof (struct saved ), +GFP_ATOMIC ); +if (unlikely (!p)) +return -ECHILD ; + }else { + p =kmalloc (MAXSYMLINKS *sizeof (struct saved ), +GFP_KERNEL ); +if (unlikely (!p)) +return -ENOMEM ; + }memcpy (p, nd->internal,sizeof (nd->internal)); nd->stack = p;return 0 ;
@@ -1561,12 +1569,6 @@ static int pick_link(struct nameidata *nd, struct path *link)path_to_nameidata (link, nd);return -ELOOP ; } -if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->path.mnt != link->mnt || -unlazy_walk (nd, link->dentry))) { -return -ECHILD ; - } - } error =nd_alloc_stack (nd);if (unlikely (error)) {path_to_nameidata (link, nd);
@@ -1839,7 +1841,17 @@ OK:break ;if (err) { -const char *s =get_link (nd); +const char *s; + +if (nd->flags &LOOKUP_RCU ) { +if (unlikely (nd->link.mnt != nd->path.mnt || +unlazy_walk (nd, nd->link.dentry))) { + err = -ECHILD ; +break ; + } + } + + s =get_link (nd);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s);
@@ -1992,7 +2004,16 @@ static void path_cleanup(struct nameidata *nd)static int trailing_symlink (struct nameidata *nd) {const char *s; -int error =may_follow_link (&nd->link, nd); +int error; + +if (nd->flags &LOOKUP_RCU ) { +if (unlikely (nd->link.mnt != nd->path.mnt || +unlazy_walk (nd, nd->link.dentry))) { +terminate_walk (nd); +return -ECHILD ; + } + } + error =may_follow_link (&nd->link, nd);if (unlikely (error))return error; nd->flags |=LOOKUP_PARENT ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 78/79 namei: new helper - is_stale()
In reply to Al ViroFrom: Al Viro <[email protected]>
we have a lot of places where we open-code the check that dentry->d_seq matches nameidata...
--- fs/namei.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
fs/namei.c +10 -5
@@ -575,6 +575,11 @@ static inline int nd_alloc_stack(struct nameidata *nd)* to restart the path walk from the beginning in ref-walk mode. */ +static inline bool is_stale (struct nameidata *nd,struct dentry *dentry) +{ +return read_seqcount_retry (&dentry->d_seq, nd->seq); +} +/** * unlazy_walk - try to switch to ref-walk mode. * @nd: nameidata pathwalk data
@@ -621,13 +626,13 @@ static int unlazy_walk(struct nameidata *nd, struct dentry *dentry)* be valid if the child sequence number is still valid. */ if (!dentry) { -if (read_seqcount_retry (&parent->d_seq, nd->seq)) +if (is_stale (nd, parent)) goto out;BUG_ON (nd->inode != parent->d_inode); }else {if (!lockref_get_not_dead (&dentry->d_lockref)) goto out; -if (read_seqcount_retry (&dentry->d_seq, nd->seq)) +if (is_stale (nd, dentry)) goto drop_dentry; }
@@ -694,7 +699,7 @@ static int complete_walk(struct nameidata *nd)mntput (nd->path.mnt);return -ECHILD ; } -if (read_seqcount_retry (&dentry->d_seq, nd->seq)) { +if (is_stale (nd, dentry)) {rcu_read_unlock ();dput (dentry);mntput (nd->path.mnt);
@@ -1218,7 +1223,7 @@ static int follow_dotdot_rcu(struct nameidata *nd) inode = parent->d_inode; seq =read_seqcount_begin (&parent->d_seq); -if (read_seqcount_retry (&old->d_seq, nd->seq)) +if (is_stale (nd, old)) goto failed; nd->path.dentry = parent; nd->seq = seq;
@@ -1980,7 +1985,7 @@ static int path_init(int dfd, const struct filename *name, unsigned int flags, nd->inode = nd->path.dentry->d_inode;if (!(flags &LOOKUP_RCU )) goto done; -if (likely (!read_seqcount_retry (&nd->path.dentry->d_seq, nd->seq))) +if (likely (!is_stale (nd, nd->path.dentry))) goto done;if (!(nd->flags &LOOKUP_ROOT )) nd->root.mnt =NULL ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH 79/79 namei: stretch RCU mode into get_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
one potentially subtle point: may_follow_link() kludge rejecting symlink traversal in RCU mode is handled by returning -ECHILD and repeating everything in non-RCU mode. Reason: audit_log_link_denied() won't work in RCU mode.
--- fs/namei.c | 86 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 39 deletions(-)
fs/namei.c +47 -39
@@ -725,6 +725,29 @@ static int complete_walk(struct nameidata *nd)return status; } +static inline void put_link (struct nameidata *nd) +{ +struct saved *last = nd->stack + --nd->depth; +struct inode *inode = last->link.dentry->d_inode; +if (last->cookie && inode->i_op->put_link) + inode->i_op->put_link (last->link.dentry, last->cookie); +path_put (&last->link); +} + +static void terminate_walk (struct nameidata *nd) +{ +if (!(nd->flags &LOOKUP_RCU )) { +path_put (&nd->path); + }else { + nd->flags &= ~LOOKUP_RCU ; +if (!(nd->flags &LOOKUP_ROOT )) + nd->root.mnt =NULL ; +rcu_read_unlock (); + } +while (unlikely (nd->depth)) +put_link (nd); +} + static __always_inline void set_root(struct nameidata *nd) {get_fs_root (current->fs, &nd->root);
@@ -776,15 +799,6 @@ void nd_jump_link(struct path *path) nd->flags |=LOOKUP_JUMPED ; } -static inline void put_link (struct nameidata *nd) -{ -struct saved *last = nd->stack + --nd->depth; -struct inode *inode = last->link.dentry->d_inode; -if (last->cookie && inode->i_op->put_link) - inode->i_op->put_link (last->link.dentry, last->cookie); -path_put (&last->link); -} -int sysctl_protected_symlinks__read_mostly =0 ;int sysctl_protected_hardlinks__read_mostly =0 ;
@@ -804,21 +818,20 @@ int sysctl_protected_hardlinks __read_mostly = 0;* * Returns 0 if following the symlink is allowed, -ve on error. */ -static inline int may_follow_link (struct path *link,struct nameidata *nd) +static inline int may_follow_link (struct path *link,const struct inode *inode, +struct nameidata *nd) { -const struct inode *inode;const struct inode *parent;if (!sysctl_protected_symlinks)return 0 ;/* Allowed if owner and follower match. */ - inode = link->dentry->d_inode;if (uid_eq (current_cred ()->fsuid, inode->i_uid))return 0 ;/* Allowed if parent directory not sticky and world-writable. */ - parent = nd->path.dentry->d_inode; + parent = nd->inode;if ((parent->i_mode & (S_ISVTX |S_IWOTH )) != (S_ISVTX |S_IWOTH ))return 0 ;
@@ -826,9 +839,14 @@ static inline int may_follow_link(struct path *link, struct nameidata *nd)if (uid_eq (parent->i_uid, inode->i_uid))return 0 ; +if (nd->flags &LOOKUP_RCU ) { +terminate_walk (nd); +return -ECHILD ; + } +audit_log_link_denied ("follow_link" , link); -path_put_conditional (link, nd); -path_put (&nd->path); +path_to_nameidata (link, nd); +terminate_walk (nd);return -EACCES ; }
@@ -902,15 +920,19 @@ static int may_linkat(struct path *link) }static __always_inline -const char *get_link(struct nameidata *nd) +const char *get_link(struct nameidata *nd, struct inode *inode) {struct saved *last = nd->stack + nd->depth;struct dentry *dentry = nd->link.dentry; -struct inode *inode = dentry->d_inode;int error;const char *res; -BUG_ON (nd->flags &LOOKUP_RCU ); +if (nd->flags &LOOKUP_RCU ) { +if (unlikely (nd->link.mnt != nd->path.mnt || +unlazy_walk (nd, dentry))) { +return ERR_PTR (-ECHILD ); + } + }if (nd->link.mnt == nd->path.mnt)mntget (nd->link.mnt);
@@ -1553,20 +1575,6 @@ static inline int handle_dots(struct nameidata *nd, int type)return 0 ; } -static void terminate_walk (struct nameidata *nd) -{ -if (!(nd->flags &LOOKUP_RCU )) { -path_put (&nd->path); - }else { - nd->flags &= ~LOOKUP_RCU ; -if (!(nd->flags &LOOKUP_ROOT )) - nd->root.mnt =NULL ; -rcu_read_unlock (); - } -while (unlikely (nd->depth)) -put_link (nd); -} -static int pick_link (struct nameidata *nd,struct path *link) {int error;
@@ -1847,16 +1855,16 @@ OK:if (err) {const char *s; +struct inode *inode = nd->link.dentry->d_inode;if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->link.mnt != nd->path.mnt || -unlazy_walk (nd, nd->link.dentry))) { +if (unlikely (is_stale (nd, nd->link.dentry))) { err = -ECHILD ;break ; } } - s =get_link (nd); + s =get_link (nd, inode);if (unlikely (IS_ERR (s))) { err =PTR_ERR (s);
@@ -2009,20 +2017,20 @@ static void path_cleanup(struct nameidata *nd)static int trailing_symlink (struct nameidata *nd) {const char *s; +struct inode *inode = nd->link.dentry->d_inode;int error;if (nd->flags &LOOKUP_RCU ) { -if (unlikely (nd->link.mnt != nd->path.mnt || -unlazy_walk (nd, nd->link.dentry))) { +if (unlikely (is_stale (nd, nd->link.dentry))) {terminate_walk (nd);return -ECHILD ; } } - error =may_follow_link (&nd->link, nd); + error =may_follow_link (&nd->link, inode, nd);if (unlikely (error))return error; nd->flags |=LOOKUP_PARENT ; - s =get_link (nd); + s =get_link (nd, inode);if (unlikely (IS_ERR (s))) {terminate_walk (nd);return PTR_ERR (s);
Signature · 1 line
2.1.4
Quoted 2 lines · Al Viro
My apologies for the patchbomb from hell, but I really think
it needs a public review.
Aside from the small nits I noted (and I guess I can even live with the bad label name as long as it never gets resurrected) it looks good. But I'd obviously like it to get as much testing/beating on as possible before merging: I'm assuming it will have gone at least through xfstests etc..
Linus
Al Viro
maintainerQuoted 9 lines · Linus Torvalds
Quoted 2 lines · Al Viro
My apologies for the patchbomb from hell, but I really think
it needs a public review.Aside from the small nits I noted (and I guess I can even live with the bad label name as long as it never gets resurrected) it looks good. But I'd obviously like it to get as much testing/beating on as possible before merging: I'm assuming it will have gone at least through xfstests etc..
It is passing xfstests and LTP, plus some basic "create a twisted forest of symlinks and walk it" tests, but yes, it obviously needs more beating. I'll push everything up to #76 into -next tonight (with the changes you asked for).
As for the next steps...
* we want _all_ failure exits from RCU mode to empty the stack
immediately - it will be too late to call ->put_link() once we dropped rcu_read_lock().
* we want failure exits from complete_walk() to empty the stack,
for the sake of consistency (due to the above it will do so when called in RCU mode).
* we want to postpone assignment to nd->seq until after we are
sure we haven't found a symlink to follow; I have that in local queue, will post in the next batch for review.
* we want to have pick_link() store directly into nd->stack[...].link;
no point postponing that to get_link(). nd->link can die at that point. Done in local queue.
* we want to store inode and seq along with path in nd->stack[...].
It means extra 4 words in struct nameidata (EMBEDDED_LEVELS * 2), i.e. not too horrible wrt stack footprint. should_follow_link()/pick_link() get those as additional arguments. Done in local queue.
* we need a variant of legitimize_mnt() that would _not_ leave RCU
mode. What I have in mind islegitimize_mnt(m)
{
switch (__legitimize_mnt(m, seq)) {
case 0:
return true;
default:
rcu_read_unlock();
mntput(m);
rcu_read_lock();
case 1:
return false;
}
}with the ability to call __legitimize_mnt(), remember the return value and,
in case of failure, do all pending ->put_link() before dropping rcu_read_lock()
We'll need that for unlazy_walk() et.al. - do this __legitimize_mnt()
on path->nd.mnt and all nd->stack[0..nd->depth - 1].mnt, and if any of them
fail, stop right there, do ->put_link() on everything, drop rcu_read_lock(),mntput() everything on stack we'd already legitimized, reset nd->depth to 0 and bugger off the way we currently would. If all of __legitimize_mnt() succeed, we go and acquire dentry references, checking them against nd->seq fornd->path and nd->stack[i].seq for nd->stack[i].link. Any failure =>
->put_link() for everything on stack, rcu_read_unlock(), dput() everything
we'd managed to grab in the stack, mntput() everything in the stack,
reset nd->depth to 0 and bugger off the way we currently would.
complete_walk() is similar - it starts with could be
if (nd->flags & LOOKUP_RCU) {
if (!(nd->flags & LOOKUP_ROOT))
nd->root.mnt = NULL;
if (unlikely(unlazy_walk(nd, NULL))
return -ECHILD;
}and perhaps it would make sense to try just that and see if unlazy_walk() goes visibly higher in profiles... Note that it *can* be called with non-empty stack and be required to legitimize its (only) element - e.g. creat() on a dangling symlink will step into that. So we can't just start with unconditionally emptying the stack.
terminate_walk() is simpler - if we are in RCU mode, just call
->put_link() on everything in stack and reset nd->depth; if we are not, leave as in this patchset.
* ->put_link() should get inode + cookie instead of dentry + cookie;
sure, right now the only instance that wants more than cookie is in hppfs and that's scheduled for removal, but we need the inode to find the damn method anyway, so passing it is no extra burden. Should be RCU-safe, which is actually true for all instances.
* ->follow_link() should take dentry + inode, with NULL/inode meaning
"we are in RCU mode, return -ECHILD instead of doing anything you can't do in RCU pathwalk". get_link() should be basically
touch atime (might throw out of RCU mode)
do security_inode_follow_link(), fuck off if it fails
nd->last_type = LAST_BIND;
if (inode->i_link)
return it, we are done
if (in RCU mode) {
link = ...->follow_link(NULL, inode);
if (link == ERR_PTR(-ECHILD))
try to unlazy, return link if that fails
else
return link;
}
link = ...->follow_link(dentry, inode);
then as in this patchset.
* nd_alloc_stack() should do GFP_ATOMIC allocation in RCU mode andtreat a failure as "try to unlazy, fail with ECHILD if can't do that, proceed to GFP_KERNEL allocation otherwise".
* may_follow_link() should, in case of failure, check if it's in
RCU mode and do terminate_walk()/fail with ECHILD instead of going into audit crap. Sure, it'll cost us a restart that will almost certainly end with hard error on the same symlink, but audit_log_link_denied() isn't usable in RCU mode. We probably could just make it use GFP_ATOMIC for allocations, but that's a separate story...
* we need set_root_rcu() to store ->d_seq of root in nameidata,
so that traversing an absolute symlink in RCU mode would be able to start with correct nd->seq - fetch nd->root.dentry->d_inode, check nd->root.dentry->d_seq against nd->root_seq, fail with -ECHILD on mismatch and use inode and root_seq for nd->inode / nd->seq otherwise.
* put_link() should, as in Neil's patchset, have path_put() conditional
on non-RCU mode.
* unlazy_walk() is really unpleasant. In addition to the issues
around legitimizing many vfsmounts without being allowed to drop rcu_read_lock (discussed above), we have three use cases:
1) unlazy_walk(nd, NULL). legitimize nd->path and everything already in nd->stack, from 0 to nd->depth - 1. On failure do ->put_link() for everything on stack *before* dropping rcu_read_lock().
2) unlazy_walk() in lookup_fast(). We want to give it correct seq number (and I already have that done in local tree) and legitimize that dentry + what case 1 would do.
3) unlazy between deciding it's a symlink to follow and succeeding with ->follow_link() in get_link(). It's this case that really sucks - we want to legitimize everything we would in case 1 + path/dentry of our link. And it _can_ have a different vfsmount - we can't just rely on getting nd->path.mnt being equal to it. It's actually more like case 1 than case 2 - "legitimize nd->path and everything on stack from 0 to nd->depth, without ->put_link() in case of failure done only from 0 to nd->depth - 1 (as in case 1)". We probably should just do this:
m = mnt of pending link
res = __legitimize_mnt(m);
if (likely(!res)) {
d = dentry of pending link
try to legitimize d
if failed
res = 2;
}
if (unlikely(res)) {
terminate_walk(nd);
if (res != 1)
mntput(m);
return -ECHILD;
}
res = unlazy_walk(nd, NULL);
if (unlikely(res)) {
dput(d);
mntput(m);
}
return res;AFAICS, the above should suffice, modulo teaching ->follow_link() instances to fail with ECHILD when called in RCU mode and then teaching some of them _not_ to. Note that fast symlinks would be fine without the last part and that covers most of the actual use...
Al Viro
maintainerQuoted 4 lines · Al Viro
It is passing xfstests and LTP, plus some basic "create a twisted forest of symlinks and walk it" tests, but yes, it obviously needs more beating. I'll push everything up to #76 into -next tonight (with the changes you asked for).
[snip]
Quoted 4 lines
AFAICS, the above should suffice, modulo teaching ->follow_link() instances to fail with ECHILD when called in RCU mode and then teaching some of them _not_ to. Note that fast symlinks would be fine without the last part and that covers most of the actual use...
FWIW, right now vfs.git#link_path_walk seems to be working and doing just that - there's still some reordering to do in the new parts of queue, and right now it's dropping out of RCU mode as soon as it runs into a non-trivial symlink (== not a fast one), but the common case is handled without dropping out of RCU mode until the very end. I'll do reordering tomorrow (along with adding the missing documentation, etc.) and post the result for review, then into -next it goes... Right now it's 107 commits on top of what already went into mainline (1 from dhowells, 6 from neilb, the rest from me), so it's going to be another patchbomb from hell ;-/
Missing bits: teaching ->follow_link() to try and remain in RCU mode (IMO it should be getting (dentry, inode, &cookie) and have RCU mode indicated by dentry == NULL), figuring out what to do with automounts (I really think that ->d_automount() is worth offloading via schedule_work() or something similar) and more testing/profiling/tuning the inlining/etc.
Al Viro
maintainerRFC PATCH v3 1/1 non-recursive pathname resolution & RCU symlinks
In reply to Al ViroQuoted 14 lines
There are several things in that queue; most of it is
fs/namei.c
rewrite and closer to the end we get
* non-recursivelink_path_walk()
* the only symlink-related limitation is that there should be no
more than 40 symlinks traversals, no matter how nested they are.
* stack footprint independent from the nesting and about on par with
mainline in "no symlinks" case.
* some work towards the symlink traversal without dropping from
RCU mode; not complete, but much better starting point than the current mainline.
* IMO more readable logics around the pathname resolution in
general, but then I'd spent the last couple of weeks messing with that code, so my perception might be seriously warped.
... and in addition to that - symlink traversal without dropping out of RCU mode. For now - only the fast symlinks, but extending that to symlinks with non-trivial ->follow_link() is pretty straightforward.
Quoted 3 lines
Most of that stuff is mine, with exception of 3 commits from
Neil's series (with some modifications). I've marked those with [N] in the list below.
6 patches from Neil's series now, plus one from David Howells (marked [D]).
Quoted 6 lines
It really needs review and more testing; it *does* pass xfstests,
LTP and local tests with no regressions, but at the very least it'll need careful profiling, as well as more eyes to read it through. The whole thing is based at -rc1. Individual patches are in followups; those who prefer to access it via git can fetch it at git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.gitlink_path_walk
Same branch, rebased on -rc3. Still passes all tests with no regressions. Balance is at about -0.2KLoC...
Please, read and comment.
Series layout is pretty much unchanged - the first 76 commits (out of 110 ;-/) are fairly close to what had been posted in the previous series.
* assorted preliminary patches:
[1/110] 9p: don't bother with 4K allocation for 24-byte local array... [2/110] 9p: don't bother with __getname() in ->follow_link() [3/110][N] ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link [4/110] ext4: split inode_operations for encrypted symlinks off the rest
* getting rid of boilerplate for inline symlinks
[5/110] libfs: simple_follow_link()
[6/110] ext2: use simple_follow_link()
[7/110] befs: switch to simple_follow_link()
[8/110] ext3: switch to simple_follow_link()
[9/110] ext4: switch to simple_follow_link()
[10/110] jffs2: switch to simple_follow_link() [11/110] shmem: switch to simple_follow_link() [12/110] debugfs: switch to simple_follow_link() [13/110] ufs: switch to simple_follow_link()
[14/110] ubifs: switch to simple_follow_link() [15/110] sysv: switch to simple_follow_link()
[16/110] jfs: switch to simple_follow_link()
[17/110] freevxfs: switch to simple_follow_link() [18/110] exofs: switch to {simple,page}_symlink_inode_operations [19/110] ceph: switch to simple_follow_link()
* more assorted preparations:
[20/110] logfs: fix a pagecache leak for symlinks [21/110][N] SECURITY: remove nameidata arg from inode_follow_link. [22/110] uninline walk_component()
* getting trailing symlinks handling in do_last() into saner shape:
[23/110] namei: take O_NOFOLLOW treatment into do_last() [24/110] do_last: kill symlink_ok
[25/110] do_last: regularize the logics around following symlinks
* getting rid of nameidata on stack during ->rmdir()/->unlink() and double nameidata during ->rename():
[26/110] namei: get rid of lookup_hash()
[27/110] name: shift nameidata down into user_path_walk()
* single instance of nameidata across the adjacent path_mountpoint() calls:
[28/110] namei: lift nameidata into filename_mountpoint()
At that point preparations end. The next one changes the calling conventions for ->follow_link/->put_link. We still are passing nameidata to ->follow_link(), but almost all instances do not use it anymore. Moreover, nd->saved_names[] is gone and so's nameidata in generic_readlink(). That one has the biggest footprint outside of fs/namei.c - it's a flagday change.
[29/110] new ->follow_link() and ->put_link() calling conventions
* some preparations for link_path_walk() massage:
[30/110] namei.c: separate the parts of follow_link() that find the link body [31/110] namei: don't bother with ->follow_link() if ->i_link is set [32/110] namei: introduce nameidata->link
[33/110] do_last: move path there from caller's stack frame
* link_path_walk()/follow_link() rewrite. It's done in small steps, getting the damn thing into form that would allow to get rid of recursion:
[34/110] namei: expand nested_symlink() in its only caller [35/110] namei: expand the call of follow_link() in link_path_walk() [36/110] namei: move the calls of may_follow_link() into follow_link() [37/110] namei: rename follow_link to trailing_symlink, move it down [38/110] link_path_walk: handle get_link() returning ERR_PTR() immediately [39/110] link_path_walk: don't bother with walk_component() after jumping link [40/110] link_path_walk: turn inner loop into explicit goto [41/110] link_path_walk: massage a bit more
[42/110] link_path_walk: get rid of duplication
[43/110] link_path_walk: final preparations to killing recursion
* dumb and staightforward "put all variables we needed to be separate in each frame into an array of structs" killing of recursion. Array is still on stack frame of link_path_walk(), we are still with the same depth limits,
etc. All of that will change shortly afterwards.
[44/110] link_path_walk: kill the recursion
* post-operation cleanup:
[45/110] link_path_walk: split "return from recursive call" path [46/110] link_path_walk: cleanup - turn goto start; into continue;
* array moves into nameidata, with extra (0th) element used instead of link/cookie pairs of local variables we used to have in trailing symlink loops:
[47/110] namei: move link/cookie pairs into nameidata
* more post-op cleanup - arguments of several functions are always the fields of the same array element or pointers to such:
[48/110] namei: trim redundant arguments of trailing_symlink() [49/110] namei: trim redundant arguments of fs/namei.c:put_link() [50/110] namei: trim the arguments of get_link()
* trim the array in nameidata to a couple of elements, use it until we need more and allocate a big (41-element) array when needed. Result:
no more nesting limitations.
[51/110] namei: remove restrictions on nesting depth
* the use of array is seriously counterintuitive - for everything except the last component we are _not_ using the first element of array; moreover, way too many places are manipulating nd->depth. I've tried to sanitize all of that in one patch, but after several failures I ended up splitting the massage into smaller steps. The composition of those has ended up fairly small, but convincing yourself that it's correct will mean reporoducing this splitup ;-/
[52/110] link_path_walk: nd->depth massage, part 1
[53/110] link_path_walk: nd->depth massage, part 2
[54/110] link_path_walk: nd->depth massage, part 3
[55/110] link_path_walk: nd->depth massage, part 4
[56/110] trailing_symlink: nd->depth massage, part 5
[57/110] get_link: nd->depth massage, part 6
[58/110] trailing_symlink: nd->depth massage, part 7
[59/110] put_link: nd->depth massage, part 8
[60/110] link_path_walk: nd->depth massage, part 9
[61/110] link_path_walk: nd->depth massage, part 10
[62/110] link_path_walk: end of nd->depth massage
[63/110] namei: we never need more than MAXSYMLINKS entries in nd->stack
* getting more regular rules for calling terminate_walk()/put_link(). The reason for that part is (besides getting simpler logics in the end) that with RCU-symlink series we'll really need to have terminate_walk() trigger put_link() on everything we have on stack:
[64/110] namei: lift (open-coded) terminate_walk() in follow_dotdot_rcu() into callers
[65/110] lift terminate_walk() into callers of walk_component() [66/110] namei: lift (open-coded) terminate_walk() into callers of get_link() [67/110] namei: take put_link() into {lookup,mountpoint,do}_last() [68/110] namei: have terminate_walk() do put_link() on everything left [69/110] link_path_walk: move the OK: inside the loop
* more put_link() work - basically, we are consolidating the "we decide that we'd found a symlink that needs to be followed" logics. Again, that's one of the areas RCU-symlink will need to modify:
[70/110] namei: new calling conventions for walk_component() [71/110] namei: make should_follow_link() store the link in nd->link [72/110] namei: move link count check and stack allocation into pick_link()
Next 4 commits are about not passing nameidata to ->follow_link() - it's the same situation as with pt_regs and IRQ handlers and the same kind of solution. Only 2 instances out of 26 use nameidata at all, and only to pass it to nd_jump_link(); seeing that we already have the "begin using this nameidata instance/end using it" pairs bracketing the areas where thread works with given instance (we need that for sane freeing of on-demand allocated nd->stack), the solution is obvious...
[73/110] lustre: rip the private symlink nesting limit out [74/110][N] VFS: replace {, total_}link_count in task_struct with pointer to nameidata
[75/110] namei: simplify the callers of follow_managed() [76/110] don't pass nameidata to ->follow_link()
That's where the parts common with v2 end. The rest is new. get_link() reorganization - make it handle the jump-to-root and return the remaining part of link to follow, with "/" treated as we do treat pure jumps (i.e. return NULL). Adjust callers (sucking a lot of duplication into get_link()).
[77/110] namei: simplify failure exits in get_link()
[78/110] namei: simpler treatment of symlinks with nothing other that / in the body [79/110] namei: take the treatment of absolute symlinks to get_link()
convert complete_walk() to use of unlazy_walk()/terminate_walk():
[80/110] namei: fold put_link() into the failure case of complete_walk()
the next bunch takes pushing the link on stack from get_link() to pick_link():
[81/110] namei: move bumping the refcount of link->mnt into pick_link() [82/110] may_follow_link(): trim arguments
[83/110] namei: kill nd->link
[84/110] namei: take increment of nd->depth into pick_link()
Lifting terminate_walk() and link_path_walk() calls up, reorganization and cleanup of top-level loops:
[85/110] namei: may_follow_link() - lift terminate_walk() on failures into caller [86/110] namei: split off filename_lookupat() with LOOKUP_PARENT [87/110] namei: get rid of nameidata->base
[88/110] namei: path_init() calling conventions change
[89/110] namei: lift link_path_walk() call out of trailing_symlink() [90/110] namei: lift terminate_walk() all the way up
[91/110] link_path_walk: use explicit returns for failure exits
Preparations for RCU work: we need to stop manging nd->seq when finding a symlink and we'll need to keep inode as well as vfsmount/dentry in the stack:
[92/110] namei: explicitly pass seq number to unlazy_walk() when dentry != NULL [93/110] namei: don't mangle nd->seq in lookup_fast()
[94/110] namei: store inode in nd->stack[]
[95/110][D] VFS: Handle lower layer dentry/inode in pathwalk [96/110] namei: pick_link() callers already have inode
More prep work: RCU-safe Linux S&M interaction (that one's entirely Neil's) [97/110][N] security/selinux: pass 'flags' arg to avc_audit() and avc_has_perm_flags() [98/110][N] security: make inode_follow_link RCU-walk aware
minor ->put_link() API change:
[99/110] switch ->put_link() from dentry to inode
[100/110] new helper: free_page_put_link()
More prep work: put_link() and may_follow_link() made RCU-safe [101/110] namei: make put_link() RCU-safe
[102/110] namei: make may_follow_link() safe in RCU mode
Legitimizing nd->stack[] on unlazy_walk():
[103/110] new helper: __legitimize_mnt()
[104/110] namei: store seq numbers in nd->stack[]
[105/110] namei: make unlazy_walk and terminate_walk handle nd->stack, add unlazy_link
... and payoff - shift unlazying down to get_link() and narrow it to the "we don't have ->i_link and have to call the actual method" case:
[106/110] namei: don't unlazy until get_link()
[107/110][N] VFS/namei: make the use of touch_atime() in get_link() RCU-safe. [108/110] enable passing fast relative symlinks without dropping out of RCU mode [109/110] namei: handle absolute symlinks without dropping out of RCU mode
documenting the API changes so far:
[110/110] update Documentation/filesystems/ regarding the follow_link/put_link changes
Al Viro
maintainerPATCH v3 1/110 9p: don't bother with 4K allocation for 24-byte local array...
From: Al Viro <[email protected]>
--- fs/9p/vfs_inode.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-)
fs/9p/vfs_inode.c +5 -21
@@ -1370,6 +1370,8 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)return v9fs_vfs_mkspecial (dir, dentry,P9_DMSYMLINK , symname); } +#define U32_MAX_DIGITS 10 +/** * v9fs_vfs_link - create a hardlink * @old_dentry: dentry for file to link to
@@ -1383,7 +1385,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) {int retval; -char *name; +char name[1 +U32_MAX_DIGITS +2 ];/* sign + number + \n + \0 */ struct p9_fid *oldfid; p9_debug(P9_DEBUG_VFS, " %lu,%pd,%pd\n",
@@ -1393,20 +1395,12 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,if (IS_ERR (oldfid))return PTR_ERR (oldfid); - name =__getname (); -if (unlikely (!name)) { - retval = -ENOMEM ; - goto clunk_fid; - } -sprintf (name,"%d\n" , oldfid->fid); retval =v9fs_vfs_mkspecial (dir, dentry,P9_DMLINK , name); -__putname (name);if (!retval) {v9fs_refresh_inode (oldfid,d_inode (old_dentry));v9fs_invalidate_inode_attr (dir); } -clunk_fid:p9_client_clunk (oldfid);return retval; }
@@ -1425,7 +1419,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rde {struct v9fs_session_info *v9ses =v9fs_inode2v9ses (dir);int retval; -char *name; +char name[2 +U32_MAX_DIGITS +1 +U32_MAX_DIGITS +1 ];u32 perm; p9_debug(P9_DEBUG_VFS, " %lu,%pd mode: %hx MAJOR: %u MINOR: %u\n",
@@ -1435,26 +1429,16 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdeif (!new_valid_dev (rdev))return -EINVAL ; - name =__getname (); -if (!name) -return -ENOMEM ;/* build extension */ if (S_ISBLK (mode))sprintf (name,"b %u %u" ,MAJOR (rdev),MINOR (rdev));else if (S_ISCHR (mode))sprintf (name,"c %u %u" ,MAJOR (rdev),MINOR (rdev)); -else if (S_ISFIFO (mode)) - *name =0 ; -else if (S_ISSOCK (mode)) +else *name =0 ; -else { -__putname (name); -return -EINVAL ; - } perm =unixmode2p9mode (v9ses, mode); retval =v9fs_vfs_mkspecial (dir, dentry, perm, name); -__putname (name);return retval; }
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 2/110 9p: don't bother with __getname() in ->follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
We copy there a kmalloc'ed string and proceed to kfree that string immediately after that. Easier to just feed that string to nd_set_link() and _not_ kfree it until ->put_link() (which becomes kfree_put_link() in that case).
--- fs/9p/v9fs.h | 2 -- fs/9p/vfs_inode.c | 93 ++++++++++---------------------------------------- fs/9p/vfs_inode_dotl.c | 31 +++++------------ 3 files changed, 26 insertions(+), 100 deletions(-)
fs/9p/v9fs.h +0 -2
@@ -149,8 +149,6 @@ extern int v9fs_vfs_unlink(struct inode *i, struct dentry *d);extern int v9fs_vfs_rmdir (struct inode *i,struct dentry *d);extern int v9fs_vfs_rename (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry); -extern void v9fs_vfs_put_link (struct dentry *dentry,struct nameidata *nd, -void *p);extern struct inode *v9fs_inode_from_fid (struct v9fs_session_info *v9ses,struct p9_fid *fid,struct super_block *sb,int new);
fs/9p/vfs_inode.c +18 -75
128 lines not on this page · raw message
fs/9p/vfs_inode_dotl.c +8 -23
@@ -912,33 +912,18 @@ error:static void *v9fs_vfs_follow_link_dotl (struct dentry *dentry,struct nameidata *nd) { -int retval; -struct p9_fid *fid; -char *link =__getname (); +struct p9_fid *fid =v9fs_fid_lookup (dentry);char *target; +int retval;p9_debug (P9_DEBUG_VFS ,"%pd\n" , dentry); -if (!link) { - link =ERR_PTR (-ENOMEM ); - goto ndset; - } - fid =v9fs_fid_lookup (dentry); -if (IS_ERR (fid)) { -__putname (link); - link =ERR_CAST (fid); - goto ndset; - } +if (IS_ERR (fid)) +return ERR_CAST (fid); retval =p9_client_readlink (fid, &target); -if (!retval) { -strcpy (link, target); -kfree (target); - goto ndset; - } -__putname (link); - link =ERR_PTR (retval); -ndset: -nd_set_link (nd, link); +if (retval) +return ERR_PTR (retval); +nd_set_link (nd, target);return NULL ; }
@@ -1006,7 +991,7 @@ const struct inode_operations v9fs_file_inode_operations_dotl = {const struct inode_operations v9fs_symlink_inode_operations_dotl = { .readlink = generic_readlink, .follow_link = v9fs_vfs_follow_link_dotl, - .put_link = v9fs_vfs_put_link, + .put_link = kfree_put_link, .getattr = v9fs_vfs_getattr_dotl, .setattr = v9fs_vfs_setattr_dotl, .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 3/110 ovl: rearrange ovl_follow_link to it doesn't need to call ->put_link
In reply to Al ViroFrom: NeilBrown <[email protected]>
ovl_follow_link current calls ->put_link on an error path. However ->put_link is about to change in a way that it will be impossible to call it from ovl_follow_link.
So rearrange the code to avoid the need for that error path.
Specifically: move the kmalloc() call before the ->follow_link() call to the subordinate filesystem.
--- fs/overlayfs/inode.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
fs/overlayfs/inode.c +12 -13
@@ -145,6 +145,7 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)void *ret;struct dentry *realdentry;struct inode *realinode; +struct ovl_link_data *data =NULL ; realdentry =ovl_dentry_real (dentry); realinode = realdentry->d_inode;
@@ -152,25 +153,23 @@ static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)if (WARN_ON (!realinode->i_op->follow_link))return ERR_PTR (-EPERM ); - ret = realinode->i_op->follow_link (realdentry, nd); -if (IS_ERR (ret)) -return ret; -if (realinode->i_op->put_link) { -struct ovl_link_data *data; - data =kmalloc (sizeof (struct ovl_link_data ),GFP_KERNEL ); -if (!data) { - realinode->i_op->put_link (realdentry, nd, ret); +if (!data)return ERR_PTR (-ENOMEM ); - } data->realdentry = realdentry; - data->cookie = ret; + } -return data; - }else { -return NULL ; + ret = realinode->i_op->follow_link (realdentry, nd); +if (IS_ERR (ret)) { +kfree (data); +return ret; } + +if (data) + data->cookie = ret; + +return data; }static void ovl_put_link (struct dentry *dentry,struct nameidata *nd,void *c)
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 4/110 ext4: split inode_operations for encrypted symlinks off the rest
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext4/ext4.h | 1 + fs/ext4/inode.c | 6 ++++-- fs/ext4/namei.c | 9 +++++---- fs/ext4/symlink.c | 30 ++++++++++-------------------- 4 files changed, 20 insertions(+), 26 deletions(-)
fs/ext4/ext4.h +1 -0
@@ -2847,6 +2847,7 @@ extern int ext4_mpage_readpages(struct address_space *mapping, unsigned nr_pages);/* symlink.c */ +extern const struct inode_operations ext4_encrypted_symlink_inode_operations;extern const struct inode_operations ext4_symlink_inode_operations;extern const struct inode_operations ext4_fast_symlink_inode_operations;
fs/ext4/inode.c +4 -2
@@ -4213,8 +4213,10 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext4_dir_inode_operations; inode->i_fop = &ext4_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (ext4_inode_is_fast_symlink (inode) && - !ext4_encrypted_inode (inode)) { +if (ext4_encrypted_inode (inode)) { + inode->i_op = &ext4_encrypted_symlink_inode_operations; +ext4_set_aops (inode); + }else if (ext4_inode_is_fast_symlink (inode)) { inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext4/namei.c +5 -4
@@ -3206,10 +3206,12 @@ static int ext4_symlink(struct inode *dir, goto err_drop_inode; sd->len =cpu_to_le16 (ostr.len); disk_link.name = (char *) sd; + inode->i_op = &ext4_encrypted_symlink_inode_operations; }if ((disk_link.len >EXT4_N_BLOCKS *4 )) { - inode->i_op = &ext4_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_symlink_inode_operations;ext4_set_aops (inode);/* * We cannot call page_symlink() with transaction started
@@ -3249,9 +3251,8 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); - inode->i_op = encryption_required ? - &ext4_symlink_inode_operations : - &ext4_fast_symlink_inode_operations; +if (!encryption_required) + inode->i_op = &ext4_fast_symlink_inode_operations;memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;
fs/ext4/symlink.c +10 -20
@@ -35,9 +35,6 @@ static void *ext4_follow_link(struct dentry *dentry, struct nameidata *nd)int res;u32 plen, max_size = inode->i_sb->s_blocksize; -if (!ext4_encrypted_inode (inode)) -return page_follow_link_light (dentry, nd); - ctx =ext4_get_fname_crypto_ctx (inode, inode->i_sb->s_blocksize);if (IS_ERR (ctx))return ctx;
@@ -97,18 +94,16 @@ errout: return ERR_PTR(res); } -static void ext4_put_link (struct dentry *dentry,struct nameidata *nd, -void *cookie) -{ -struct page *page = cookie; - -if (!page) { -kfree (nd_get_link (nd)); - }else { -kunmap (page); -page_cache_release (page); - } -} +const struct inode_operations ext4_encrypted_symlink_inode_operations = { + .readlink = generic_readlink, + .follow_link = ext4_follow_link, + .put_link = kfree_put_link, + .setattr = ext4_setattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, + .listxattr = ext4_listxattr, + .removexattr = generic_removexattr, +};#endif static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd)
@@ -120,13 +115,8 @@ static void *ext4_follow_fast_link(struct dentry *dentry, struct nameidata *nd)const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, -#ifdef CONFIG_EXT4_FS_ENCRYPTION - .follow_link = ext4_follow_link, - .put_link = ext4_put_link, -#else .follow_link = page_follow_link_light, .put_link = page_put_link, -#endif .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,
Signature · 1 line
2.1.4
Re: [PATCH v3 004/110] ext4: split inode_operations for encrypted symlinks off the rest
Thanks. This looks much better now,
Linus
Al Viro
maintainerPATCH v3 5/110 libfs: simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
let "fast" symlinks store the pointer to the body into ->i_link and use simple_follow_link for ->follow_link()
--- fs/inode.c | 1 + fs/libfs.c | 13 +++++++++++++ include/linux/fs.h | 3 +++ 3 files changed, 17 insertions(+)
fs/inode.c +1 -0
@@ -152,6 +152,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_pipe =NULL ; inode->i_bdev =NULL ; inode->i_cdev =NULL ; + inode->i_link =NULL ; inode->i_rdev =0 ; inode->dirtied_when =0 ;
fs/libfs.c +13 -0
@@ -1093,3 +1093,16 @@ simple_nosetlease(struct file *filp, long arg, struct file_lock **flp,return -EINVAL ; }EXPORT_SYMBOL (simple_nosetlease); + +void *simple_follow_link (struct dentry *dentry,struct nameidata *nd) +{ +nd_set_link (nd,d_inode (dentry)->i_link); +return NULL ; +} +EXPORT_SYMBOL (simple_follow_link); + +const struct inode_operations simple_symlink_inode_operations = { + .follow_link = simple_follow_link, + .readlink = generic_readlink +}; +EXPORT_SYMBOL (simple_symlink_inode_operations);
include/linux/fs.h +3 -0
@@ -656,6 +656,7 @@ struct inode {struct pipe_inode_info *i_pipe;struct block_device *i_bdev;struct cdev *i_cdev; +char *i_link; };__u32 i_generation;
@@ -2721,6 +2722,8 @@ void __inode_sub_bytes(struct inode *inode, loff_t bytes);void inode_sub_bytes (struct inode *inode,loff_t bytes);loff_t inode_get_bytes (struct inode *inode);void inode_set_bytes (struct inode *inode,loff_t bytes); +void *simple_follow_link (struct dentry *,struct nameidata *); +extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 6/110 ext2: use simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext2/inode.c | 1 + fs/ext2/namei.c | 3 ++- fs/ext2/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)
fs/ext2/inode.c +1 -0
@@ -1403,6 +1403,7 @@ struct inode *ext2_iget (struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &ext2_aops; }else if (S_ISLNK (inode->i_mode)) {if (ext2_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext2_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext2/namei.c +2 -1
@@ -189,7 +189,8 @@ static int ext2_symlink (struct inode * dir, struct dentry * dentry, }else {/* fast symlink */ inode->i_op = &ext2_fast_symlink_inode_operations; -memcpy ((char *)(EXT2_I (inode)->i_data),symname,l); + inode->i_link = (char *)EXT2_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }mark_inode_dirty (inode);
fs/ext2/symlink.c +1 -9
@@ -19,14 +19,6 @@#include "ext2.h" #include "xattr.h" -#include <linux/namei.h> - -static void *ext2_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext2_inode_info *ei =EXT2_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -}const struct inode_operations ext2_symlink_inode_operations = { .readlink = generic_readlink,
@@ -43,7 +35,7 @@ const struct inode_operations ext2_symlink_inode_operations = {const struct inode_operations ext2_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext2_follow_link, + .follow_link = simple_follow_link, .setattr = ext2_setattr, #ifdef CONFIG_EXT2_FS_XATTR .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 7/110 befs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/befs/linuxvfs.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-)
fs/befs/linuxvfs.c +5 -19
@@ -43,7 +43,6 @@ static struct inode *befs_alloc_inode(struct super_block *sb);static void befs_destroy_inode (struct inode *inode);static void befs_destroy_inodecache (void );static void *befs_follow_link (struct dentry *,struct nameidata *); -static void *befs_fast_follow_link (struct dentry *,struct nameidata *);static int befs_utf2nls (struct super_block *sb,const char *in,int in_len,char **out,int *out_len); static int befs_nls2utf(struct super_block *sb, const char *in, int in_len,
@@ -80,11 +79,6 @@ static const struct address_space_operations befs_aops = { .bmap = befs_bmap, }; -static const struct inode_operations befs_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = befs_fast_follow_link, -}; -static const struct inode_operations befs_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = befs_follow_link,
@@ -403,10 +397,12 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino) inode->i_op = &befs_dir_inode_operations; inode->i_fop = &befs_dir_operations; }else if (S_ISLNK (inode->i_mode)) { -if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) +if (befs_ino->i_flags &BEFS_LONG_SYMLINK ) { inode->i_op = &befs_symlink_inode_operations; -else - inode->i_op = &befs_fast_symlink_inode_operations; + }else { + inode->i_link = befs_ino->i_data.symlink; + inode->i_op = &simple_symlink_inode_operations; + } }else {befs_error (sb,"Inode %lu is not a regular file, " "directory or symlink. THAT IS WRONG! BeFS has no "
@@ -497,16 +493,6 @@ befs_follow_link(struct dentry *dentry, struct nameidata *nd)return NULL ; } - -static void * -befs_fast_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct befs_inode_info *befs_ino =BEFS_I (d_inode (dentry)); - -nd_set_link (nd, befs_ino->i_data.symlink); -return NULL ; -} -/* * UTF-8 to NLS charset convert routine *
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 8/110 ext3: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ext3/inode.c | 1 + fs/ext3/namei.c | 3 ++- fs/ext3/symlink.c | 10 +--------- 3 files changed, 4 insertions(+), 10 deletions(-)
fs/ext3/inode.c +1 -0
@@ -2999,6 +2999,7 @@ struct inode *ext3_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext3_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 ); + inode->i_link = (char *)ei->i_data; }else { inode->i_op = &ext3_symlink_inode_operations;ext3_set_aops (inode);
fs/ext3/namei.c +2 -1
@@ -2308,7 +2308,8 @@ retry: } }else { inode->i_op = &ext3_fast_symlink_inode_operations; -memcpy ((char *)&EXT3_I (inode)->i_data,symname,l); + inode->i_link = (char *)&EXT3_I (inode)->i_data; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }EXT3_I (inode)->i_disksize = inode->i_size;
fs/ext3/symlink.c +1 -9
@@ -17,17 +17,9 @@* ext3 symlink handling code */ -#include <linux/namei.h> #include "ext3.h" #include "xattr.h" -static void *ext3_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext3_inode_info *ei =EXT3_I (d_inode (dentry)); -nd_set_link (nd, (char *)ei->i_data); -return NULL ; -} -const struct inode_operations ext3_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,
@@ -43,7 +35,7 @@ const struct inode_operations ext3_symlink_inode_operations = {const struct inode_operations ext3_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext3_follow_link, + .follow_link = simple_follow_link, .setattr = ext3_setattr, #ifdef CONFIG_EXT3_FS_XATTR .setxattr = generic_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 9/110 ext4: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
for fast symlinks only, of course...
--- fs/ext4/inode.c | 1 + fs/ext4/namei.c | 4 +++- fs/ext4/symlink.c | 9 +-------- 3 files changed, 5 insertions(+), 9 deletions(-)
fs/ext4/inode.c +1 -0
@@ -4217,6 +4217,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext4_encrypted_symlink_inode_operations;ext4_set_aops (inode); }else if (ext4_inode_is_fast_symlink (inode)) { + inode->i_link = (char *)ei->i_data; inode->i_op = &ext4_fast_symlink_inode_operations;nd_terminate_link (ei->i_data, inode->i_size,sizeof (ei->i_data) -1 );
fs/ext4/namei.c +3 -1
@@ -3251,8 +3251,10 @@ static int ext4_symlink(struct inode *dir, }else {/* clear the extent format for fast symlink */ ext4_clear_inode_flag (inode,EXT4_INODE_EXTENTS ); -if (!encryption_required) +if (!encryption_required) { inode->i_op = &ext4_fast_symlink_inode_operations; + inode->i_link = (char *)&EXT4_I (inode)->i_data; + }memcpy ((char *)&EXT4_I (inode)->i_data, disk_link.name, disk_link.len); inode->i_size = disk_link.len -1 ;
fs/ext4/symlink.c +1 -8
@@ -106,13 +106,6 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = { };#endif -static void *ext4_follow_fast_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ext4_inode_info *ei =EXT4_I (d_inode (dentry)); -nd_set_link (nd, (char *) ei->i_data); -return NULL ; -} -const struct inode_operations ext4_symlink_inode_operations = { .readlink = generic_readlink, .follow_link = page_follow_link_light,
@@ -126,7 +119,7 @@ const struct inode_operations ext4_symlink_inode_operations = {const struct inode_operations ext4_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ext4_follow_fast_link, + .follow_link = simple_follow_link, .setattr = ext4_setattr, .setxattr = generic_setxattr, .getxattr = generic_getxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 10/110 jffs2: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/jffs2/dir.c | 1 + fs/jffs2/fs.c | 1 + fs/jffs2/symlink.c | 45 +-------------------------------------------- 3 files changed, 3 insertions(+), 44 deletions(-)
fs/jffs2/dir.c +1 -0
@@ -354,6 +354,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char ret = -ENOMEM ; goto fail; } + inode->i_link = f->target;jffs2_dbg (1 ,"%s(): symlink's target '%s' cached\n" , __func__, (char *)f->target);
fs/jffs2/fs.c +1 -0
@@ -294,6 +294,7 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)case S_IFLNK : inode->i_op = &jffs2_symlink_inode_operations; + inode->i_link = f->target;break ;case S_IFDIR :
fs/jffs2/symlink.c +1 -44
59 lines not on this page · raw message
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 11/110 shmem: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- mm/shmem.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
mm/shmem.c +2 -7
@@ -2451,6 +2451,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn -ENOMEM ; } inode->i_op = &shmem_short_symlink_operations; + inode->i_link = info->symlink; }else { error =shmem_getpage (inode,0 , &page,SGP_WRITE ,NULL );if (error) {
@@ -2474,12 +2475,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *sreturn 0 ; } -static void *shmem_follow_short_symlink (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,SHMEM_I (d_inode (dentry))->symlink); -return NULL ; -} -static void *shmem_follow_link (struct dentry *dentry,struct nameidata *nd) {struct page *page =NULL ;
@@ -2642,7 +2637,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)static const struct inode_operations shmem_short_symlink_operations = { .readlink = generic_readlink, - .follow_link = shmem_follow_short_symlink, + .follow_link = simple_follow_link, #ifdef CONFIG_TMPFS_XATTR .setxattr = shmem_setxattr, .getxattr = shmem_getxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 12/110 debugfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/debugfs/file.c | 12 ------------ fs/debugfs/inode.c | 6 +++--- include/linux/debugfs.h | 1 - 3 files changed, 3 insertions(+), 16 deletions(-)
fs/debugfs/file.c +0 -12
@@ -17,7 +17,6 @@#include <linux/fs.h> #include <linux/seq_file.h> #include <linux/pagemap.h> -#include <linux/namei.h> #include <linux/debugfs.h> #include <linux/io.h> #include <linux/slab.h>
@@ -43,17 +42,6 @@ const struct file_operations debugfs_file_operations = { .llseek = noop_llseek, }; -static void *debugfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd,d_inode (dentry)->i_private); -return NULL ; -} - -const struct inode_operations debugfs_link_operations = { - .readlink = generic_readlink, - .follow_link = debugfs_follow_link, -}; -static int debugfs_u8_set (void *data,u64 val) { *(u8 *)data = val;
fs/debugfs/inode.c +3 -3
@@ -174,7 +174,7 @@ static void debugfs_evict_inode(struct inode *inode)truncate_inode_pages_final (&inode->i_data);clear_inode (inode);if (S_ISLNK (inode->i_mode)) -kfree (inode->i_private); +kfree (inode->i_link); }static const struct super_operations debugfs_super_operations = {
@@ -511,8 +511,8 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,return failed_creating (dentry); } inode->i_mode =S_IFLNK |S_IRWXUGO ; - inode->i_op = &debugfs_link_operations; - inode->i_private = link; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = link;d_instantiate (dentry, inode);return end_creating (dentry); }
include/linux/debugfs.h +0 -1
@@ -45,7 +45,6 @@ extern struct dentry *arch_debugfs_dir;/* declared over in file.c */ extern const struct file_operations debugfs_file_operations; -extern const struct inode_operations debugfs_link_operations; struct dentry *debugfs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 13/110 ufs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ufs/inode.c | 5 +++-- fs/ufs/namei.c | 3 ++- fs/ufs/symlink.c | 13 +------------ 3 files changed, 6 insertions(+), 15 deletions(-)
fs/ufs/inode.c +3 -2
@@ -572,9 +572,10 @@ static void ufs_set_inode_ops(struct inode *inode) inode->i_fop = &ufs_dir_operations; inode->i_mapping->a_ops = &ufs_aops; }else if (S_ISLNK (inode->i_mode)) { -if (!inode->i_blocks) +if (!inode->i_blocks) { inode->i_op = &ufs_fast_symlink_inode_operations; -else { + inode->i_link = (char *)UFS_I (inode)->i_u1.i_symlink; + }else { inode->i_op = &ufs_symlink_inode_operations; inode->i_mapping->a_ops = &ufs_aops; }
fs/ufs/namei.c +2 -1
@@ -144,7 +144,8 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry, }else {/* fast symlink */ inode->i_op = &ufs_fast_symlink_inode_operations; -memcpy (UFS_I (inode)->i_u1.i_symlink, symname, l); + inode->i_link = (char *)UFS_I (inode)->i_u1.i_symlink; +memcpy (inode->i_link, symname, l); inode->i_size = l-1 ; }mark_inode_dirty (inode);
fs/ufs/symlink.c +1 -12
@@ -25,23 +25,12 @@* ext2 symlink handling code */ -#include <linux/fs.h> -#include <linux/namei.h> -#include "ufs_fs.h" #include "ufs.h" - -static void *ufs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ufs_inode_info *p =UFS_I (d_inode (dentry)); -nd_set_link (nd, (char *)p->i_u1.i_symlink); -return NULL ; -} -const struct inode_operations ufs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ufs_follow_link, + .follow_link = simple_follow_link, .setattr = ufs_setattr, };
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 14/110 ubifs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ubifs/dir.c | 1 + fs/ubifs/file.c | 11 +---------- fs/ubifs/super.c | 1 + 3 files changed, 3 insertions(+), 10 deletions(-)
fs/ubifs/dir.c +1 -0
@@ -889,6 +889,7 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry,memcpy (ui->data, symname, len); ((char *)ui->data)[len] ='\0' ; + inode->i_link = ui->data;/* * The terminating zero byte is not written to the flash media and it * is put just to make later in-memory string processing simpler. Thus,
fs/ubifs/file.c +1 -10
@@ -51,7 +51,6 @@#include "ubifs.h" #include <linux/mount.h> -#include <linux/namei.h> #include <linux/slab.h> static int read_block(struct inode *inode, void *addr, unsigned int block,
@@ -1300,14 +1299,6 @@ static void ubifs_invalidatepage(struct page *page, unsigned int offset,ClearPageChecked (page); } -static void *ubifs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ubifs_inode *ui =ubifs_inode (d_inode (dentry)); - -nd_set_link (nd, ui->data); -return NULL ; -} -int ubifs_fsync (struct file *file,loff_t start,loff_t end,int datasync) {struct inode *inode = file->f_mapping->host;
@@ -1570,7 +1561,7 @@ const struct inode_operations ubifs_file_inode_operations = {const struct inode_operations ubifs_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = ubifs_follow_link, + .follow_link = simple_follow_link, .setattr = ubifs_setattr, .getattr = ubifs_getattr, .setxattr = ubifs_setxattr,
fs/ubifs/super.c +1 -0
@@ -195,6 +195,7 @@ struct inode *ubifs_iget(struct super_block *sb, unsigned long inum) }memcpy (ui->data, ino->data, ui->data_len); ((char *)ui->data)[ui->data_len] ='\0' ; + inode->i_link = ui->data;break ;case S_IFBLK :case S_IFCHR :
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 15/110 sysv: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/sysv/Makefile | 2 +- fs/sysv/inode.c | 5 +++-- fs/sysv/symlink.c | 20 -------------------- fs/sysv/sysv.h | 1 - 4 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 fs/sysv/symlink.c
fs/sysv/Makefile +1 -1
@@ -5,4 +5,4 @@ obj-$(CONFIG_SYSV_FS) += sysv.o sysv-objs := ialloc.o balloc.o inode.o itree.o file.o dir.o \ - namei.o super.o symlink.o + namei.o super.o
fs/sysv/inode.c +3 -2
@@ -166,8 +166,9 @@ void sysv_set_inode(struct inode *inode, dev_t rdev) inode->i_op = &sysv_symlink_inode_operations; inode->i_mapping->a_ops = &sysv_aops; }else { - inode->i_op = &sysv_fast_symlink_inode_operations; -nd_terminate_link (SYSV_I (inode)->i_data, inode->i_size, + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)SYSV_I (inode)->i_data; +nd_terminate_link (inode->i_link, inode->i_size,sizeof (SYSV_I (inode)->i_data) -1 ); } }else
fs/sysv/symlink.c deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* linux/fs/sysv/symlink.c -* -* Handling of System V filesystem fast symlinks extensions. -* Aug 2001, Christoph Hellwig ([email protected]) -*/ - -#include "sysv.h" -#include <linux/namei.h> - -static void *sysv_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -nd_set_link (nd, (char *)SYSV_I (d_inode (dentry))->i_data); -return NULL ; -} - -const struct inode_operations sysv_fast_symlink_inode_operations = { - .readlink = generic_readlink, - .follow_link = sysv_follow_link, -};
fs/sysv/sysv.h +0 -1
@@ -161,7 +161,6 @@ extern ino_t sysv_inode_by_name(struct dentry *);extern const struct inode_operations sysv_file_inode_operations;extern const struct inode_operations sysv_dir_inode_operations; -extern const struct inode_operations sysv_fast_symlink_inode_operations;extern const struct file_operations sysv_file_operations;extern const struct file_operations sysv_dir_operations;extern const struct address_space_operations sysv_aops;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 16/110 jfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/jfs/inode.c | 3 ++- fs/jfs/namei.c | 5 ++--- fs/jfs/symlink.c | 10 +--------- 3 files changed, 5 insertions(+), 13 deletions(-)
fs/jfs/inode.c +2 -1
@@ -63,11 +63,12 @@ struct inode *jfs_iget(struct super_block *sb, unsigned long ino) inode->i_mapping->a_ops = &jfs_aops; }else { inode->i_op = &jfs_fast_symlink_inode_operations; + inode->i_link =JFS_IP (inode)->i_inline;/* * The inline data should be null-terminated, but * don't let on-disk corruption crash the kernel */ -JFS_IP (inode)->i_inline[inode->i_size] ='\0' ; + inode->i_link[inode->i_size] ='\0' ; } }else { inode->i_op = &jfs_file_inode_operations;
fs/jfs/namei.c +2 -3
@@ -880,7 +880,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,int ssize;/* source pathname size */ struct btstack btstack;struct inode *ip =d_inode (dentry); -unchar *i_fastsymlink;s64 xlen =0 ;int bmask =0 , xsize;s64 xaddr;
@@ -946,8 +945,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,if (ssize <=IDATASIZE ) { ip->i_op = &jfs_fast_symlink_inode_operations; - i_fastsymlink =JFS_IP (ip)->i_inline; -memcpy (i_fastsymlink, name, ssize); + ip->i_link =JFS_IP (ip)->i_inline; +memcpy (ip->i_link, name, ssize); ip->i_size = ssize -1 ;/*
fs/jfs/symlink.c +1 -9
@@ -17,21 +17,13 @@*/ #include <linux/fs.h> -#include <linux/namei.h> #include "jfs_incore.h" #include "jfs_inode.h" #include "jfs_xattr.h" -static void *jfs_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -char *s =JFS_IP (d_inode (dentry))->i_inline; -nd_set_link (nd, s); -return NULL ; -} -const struct inode_operations jfs_fast_symlink_inode_operations = { .readlink = generic_readlink, - .follow_link = jfs_follow_link, + .follow_link = simple_follow_link, .setattr = jfs_setattr, .setxattr = jfs_setxattr, .getxattr = jfs_getxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 17/110 freevxfs: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/freevxfs/vxfs_extern.h | 3 --- fs/freevxfs/vxfs_immed.c | 34 ---------------------------------- fs/freevxfs/vxfs_inode.c | 7 +++++-- 3 files changed, 5 insertions(+), 39 deletions(-)
fs/freevxfs/vxfs_extern.h +0 -3
@@ -50,9 +50,6 @@ extern daddr_t vxfs_bmap1(struct inode *, long);/* vxfs_fshead.c */ extern int vxfs_read_fshead (struct super_block *); -/* vxfs_immed.c */ -extern const struct inode_operations vxfs_immed_symlink_iops; -/* vxfs_inode.c */ extern const struct address_space_operations vxfs_immed_aops;extern struct kmem_cache *vxfs_inode_cachep;
fs/freevxfs/vxfs_immed.c +0 -34
@@ -32,29 +32,15 @@*/ #include <linux/fs.h> #include <linux/pagemap.h> -#include <linux/namei.h> #include "vxfs.h" #include "vxfs_extern.h" #include "vxfs_inode.h" -static void *vxfs_immed_follow_link (struct dentry *,struct nameidata *); -static int vxfs_immed_readpage (struct file *,struct page *);/* -* Inode operations for immed symlinks. -* -* Unliked all other operations we do not go through the pagecache, -* but do all work directly on the inode. -*/ -const struct inode_operations vxfs_immed_symlink_iops = { - .readlink = generic_readlink, - .follow_link = vxfs_immed_follow_link, -}; - -/* * Address space operations for immed files and directories. */ const struct address_space_operations vxfs_immed_aops = {
@@ -62,26 +48,6 @@ const struct address_space_operations vxfs_immed_aops = { };/** -* vxfs_immed_follow_link - follow immed symlink -* @dp: dentry for the link -* @np: pathname lookup data for the current path walk -* -* Description: -* vxfs_immed_follow_link restarts the pathname lookup with -* the data obtained from @dp. -* -* Returns: -* Zero on success, else a negative error code. -*/ -static void * -vxfs_immed_follow_link (struct dentry *dp,struct nameidata *np) -{ -struct vxfs_inode_info *vip =VXFS_INO (d_inode (dp)); -nd_set_link (np, vip->vii_immed.vi_immed); -return NULL ; -} - -/** * vxfs_immed_readpage - read part of an immed inode into pagecache * @file: file context (unused) * @page: page frame to fill in.
fs/freevxfs/vxfs_inode.c +5 -2
@@ -35,6 +35,7 @@#include <linux/pagemap.h> #include <linux/kernel.h> #include <linux/slab.h> +#include <linux/namei.h> #include "vxfs.h" #include "vxfs_inode.h"
@@ -327,8 +328,10 @@ vxfs_iget(struct super_block *sbp, ino_t ino) ip->i_op = &page_symlink_inode_operations; ip->i_mapping->a_ops = &vxfs_aops; }else { - ip->i_op = &vxfs_immed_symlink_iops; - vip->vii_immed.vi_immed[ip->i_size] ='\0' ; + ip->i_op = &simple_symlink_inode_operations; + ip->i_link = vip->vii_immed.vi_immed; +nd_terminate_link (ip->i_link, ip->i_size, +sizeof (vip->vii_immed.vi_immed) -1 ); } }else init_special_inode (ip, ip->i_mode,old_decode_dev (vip->vii_rdev));
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 18/110 exofs: switch to {simple,page}_symlink_inode_operations
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/exofs/Kbuild | 2 +- fs/exofs/exofs.h | 4 ---- fs/exofs/inode.c | 9 +++++---- fs/exofs/namei.c | 5 +++-- fs/exofs/symlink.c | 55 ------------------------------------------------------ 5 files changed, 9 insertions(+), 66 deletions(-) delete mode 100644 fs/exofs/symlink.c
fs/exofs/Kbuild +1 -1
@@ -16,5 +16,5 @@ libore-y := ore.o ore_raid.o obj-$(CONFIG_ORE) += libore.o -exofs-y := inode.o file.o symlink.o namei.o dir.o super.o sys.o +exofs-y := inode.o file.o namei.o dir.o super.o sys.o obj-$(CONFIG_EXOFS_FS) += exofs.o
fs/exofs/exofs.h +0 -4
@@ -207,10 +207,6 @@ extern const struct address_space_operations exofs_aops;extern const struct inode_operations exofs_dir_inode_operations;extern const struct inode_operations exofs_special_inode_operations; -/* symlink.c */ -extern const struct inode_operations exofs_symlink_inode_operations; -extern const struct inode_operations exofs_fast_symlink_inode_operations; -/* exofs_init_comps will initialize an ore_components device array * pointing to a single ore_comp struct, and a round-robin view * of the device table.
fs/exofs/inode.c +5 -4
@@ -1222,10 +1222,11 @@ struct inode *exofs_iget(struct super_block *sb, unsigned long ino) inode->i_fop = &exofs_dir_operations; inode->i_mapping->a_ops = &exofs_aops; }else if (S_ISLNK (inode->i_mode)) { -if (exofs_inode_is_fast_symlink (inode)) - inode->i_op = &exofs_fast_symlink_inode_operations; -else { - inode->i_op = &exofs_symlink_inode_operations; +if (exofs_inode_is_fast_symlink (inode)) { + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data; + }else { + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops; } }else {
fs/exofs/namei.c +3 -2
@@ -113,7 +113,7 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, oi =exofs_i (inode);if (l >sizeof (oi->i_data)) {/* slow symlink */ - inode->i_op = &exofs_symlink_inode_operations; + inode->i_op = &page_symlink_inode_operations; inode->i_mapping->a_ops = &exofs_aops;memset (oi->i_data,0 ,sizeof (oi->i_data));
@@ -122,7 +122,8 @@ static int exofs_symlink(struct inode *dir, struct dentry *dentry, goto out_fail; }else {/* fast symlink */ - inode->i_op = &exofs_fast_symlink_inode_operations; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = (char *)oi->i_data;memcpy (oi->i_data, symname, l); inode->i_size = l-1 ; }
fs/exofs/symlink.c deleted +0 -55
55 lines not on this page · raw message
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 19/110 ceph: switch to simple_follow_link()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/ceph/inode.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
fs/ceph/inode.c +2 -9
@@ -6,7 +6,6 @@#include <linux/string.h> #include <linux/uaccess.h> #include <linux/kernel.h> -#include <linux/namei.h> #include <linux/writeback.h> #include <linux/vmalloc.h> #include <linux/posix_acl.h>
@@ -819,6 +818,7 @@ static int fill_inode(struct inode *inode, struct page *locked_page,else kfree (sym);/* lost a race */ } + inode->i_link = ci->i_symlink;break ;case S_IFDIR : inode->i_op = &ceph_dir_iops;
@@ -1691,16 +1691,9 @@ retry:/* * symlinks */ -static void *ceph_sym_follow_link (struct dentry *dentry,struct nameidata *nd) -{ -struct ceph_inode_info *ci =ceph_inode (d_inode (dentry)); -nd_set_link (nd, ci->i_symlink); -return NULL ; -} -static const struct inode_operations ceph_symlink_iops = { .readlink = generic_readlink, - .follow_link = ceph_sym_follow_link, + .follow_link = simple_follow_link, .setattr = ceph_setattr, .getattr = ceph_getattr, .setxattr = ceph_setxattr,
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 20/110 logfs: fix a pagecache leak for symlinks
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/logfs/dir.c | 1 + 1 file changed, 1 insertion(+)
fs/logfs/dir.c +1 -0
@@ -779,6 +779,7 @@ fail:const struct inode_operations logfs_symlink_iops = { .readlink = generic_readlink, .follow_link = page_follow_link_light, + .put_link = page_put_link, };const struct inode_operations logfs_dir_iops = {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 21/110 SECURITY: remove nameidata arg from inode_follow_link.
In reply to Al ViroFrom: NeilBrown <[email protected]>
No ->inode_follow_link() methods use the nameidata arg, and it is about to become private to namei.c.
So remove from all inode_follow_link() functions.
--- fs/namei.c | 2 +- include/linux/security.h | 9 +++------ security/capability.c | 3 +-- security/security.c | 4 ++-- security/selinux/hooks.c | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-)
fs/namei.c +1 -1
@@ -871,7 +871,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)touch_atime (link);nd_set_link (nd,NULL ); - error =security_inode_follow_link (link->dentry, nd); + error =security_inode_follow_link (dentry);if (error) goto out_put_nd_path;
include/linux/security.h +3 -6
@@ -43,7 +43,6 @@ struct file;struct vfsmount ;struct path ;struct qstr ; -struct nameidata ;struct iattr ;struct fown_struct ;struct file_operations ;
@@ -477,7 +476,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)* @inode_follow_link: * Check permission to follow a symbolic link when looking up a pathname. * @dentry contains the dentry structure for the link. -* @nd contains the nameidata structure for the parent directory. * Return 0 if permission is granted. * @inode_permission: * Check permission before accessing an inode. This hook is called by the
@@ -1553,7 +1551,7 @@ struct security_operations {int (*inode_rename) (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry);int (*inode_readlink) (struct dentry *dentry); -int (*inode_follow_link) (struct dentry *dentry,struct nameidata *nd); +int (*inode_follow_link) (struct dentry *dentry);int (*inode_permission) (struct inode *inode,int mask);int (*inode_setattr) (struct dentry *dentry,struct iattr *attr);int (*inode_getattr) (const struct path *path);
@@ -1839,7 +1837,7 @@ int security_inode_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags);int security_inode_readlink (struct dentry *dentry); -int security_inode_follow_link (struct dentry *dentry,struct nameidata *nd); +int security_inode_follow_link (struct dentry *dentry);int security_inode_permission (struct inode *inode,int mask);int security_inode_setattr (struct dentry *dentry,struct iattr *attr);int security_inode_getattr (const struct path *path);
@@ -2241,8 +2239,7 @@ static inline int security_inode_readlink(struct dentry *dentry)return 0 ; } -static inline int security_inode_follow_link (struct dentry *dentry, -struct nameidata *nd) +static inline int security_inode_follow_link (struct dentry *dentry) {return 0 ; }
security/capability.c +1 -2
@@ -209,8 +209,7 @@ static int cap_inode_readlink(struct dentry *dentry)return 0 ; } -static int cap_inode_follow_link (struct dentry *dentry, -struct nameidata *nameidata) +static int cap_inode_follow_link (struct dentry *dentry) {return 0 ; }
security/security.c +2 -2
@@ -581,11 +581,11 @@ int security_inode_readlink(struct dentry *dentry)return security_ops->inode_readlink (dentry); } -int security_inode_follow_link (struct dentry *dentry,struct nameidata *nd) +int security_inode_follow_link (struct dentry *dentry) {if (unlikely (IS_PRIVATE (d_backing_inode (dentry))))return 0 ; -return security_ops->inode_follow_link (dentry, nd); +return security_ops->inode_follow_link (dentry); }int security_inode_permission (struct inode *inode,int mask)
security/selinux/hooks.c +1 -1
@@ -2861,7 +2861,7 @@ static int selinux_inode_readlink(struct dentry *dentry)return dentry_has_perm (cred, dentry,FILE__READ ); } -static int selinux_inode_follow_link (struct dentry *dentry,struct nameidata *nameidata) +static int selinux_inode_follow_link (struct dentry *dentry) {const struct cred *cred =current_cred ();
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 22/110 uninline walk_component()
In reply to Al ViroFrom: Al Viro <[email protected]>
seriously improves the stack *and* I-cache footprint...
--- fs/namei.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/namei.c +1 -2
@@ -1569,8 +1569,7 @@ static inline int should_follow_link(struct dentry *dentry, int follow)return unlikely (d_is_symlink (dentry)) ? follow :0 ; } -static inline int walk_component (struct nameidata *nd,struct path *path, -int follow) +static int walk_component (struct nameidata *nd,struct path *path,int follow) {struct inode *inode;int err;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 23/110 namei: take O_NOFOLLOW treatment into do_last()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- fs/namei.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/namei.c +5 -6
@@ -3059,6 +3059,11 @@ finish_lookup: } }BUG_ON (inode != path->dentry->d_inode); +if (!(nd->flags &LOOKUP_FOLLOW )) { +path_put_conditional (path, nd); +path_put (&nd->path); +return -ELOOP ; + }return 1 ; }
@@ -3243,12 +3248,6 @@ static struct file *path_openat(int dfd, struct filename *pathname,while (unlikely (error >0 )) {/* trailing symlink */ struct path link = path;void *cookie; -if (!(nd->flags &LOOKUP_FOLLOW )) { -path_put_conditional (&path, nd); -path_put (&nd->path); - error = -ELOOP ; -break ; - } error =may_follow_link (&link, nd);if (unlikely (error))break ;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 24/110 do_last: kill symlink_ok
In reply to Al ViroFrom: Al Viro <[email protected]>
When O_PATH is present, O_CREAT isn't, so symlink_ok is always equal to (open_flags & O_PATH) && !(nd->flags & LOOKUP_FOLLOW).
--- fs/namei.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/namei.c +2 -4
@@ -2931,7 +2931,6 @@ static int do_last(struct nameidata *nd, struct path *path,bool got_write = false;int acc_mode = op->acc_mode;struct inode *inode; -bool symlink_ok = false;struct path save_parent = { .dentry =NULL , .mnt =NULL };bool retried = false;int error;
@@ -2949,8 +2948,6 @@ static int do_last(struct nameidata *nd, struct path *path,if (!(open_flag &O_CREAT )) {if (nd->last.name[nd->last.len]) nd->flags |=LOOKUP_FOLLOW |LOOKUP_DIRECTORY ; -if (open_flag &O_PATH && !(nd->flags &LOOKUP_FOLLOW )) - symlink_ok = true;/* we _can_ be in RCU mode here */ error =lookup_fast (nd, path, &inode);if (likely (!error))
@@ -3050,7 +3047,8 @@ retry_lookup: } finish_lookup:/* we _can_ be in RCU mode here */ -if (should_follow_link (path->dentry, !symlink_ok)) { +if (should_follow_link (path->dentry, + !(open_flag &O_PATH ) || (nd->flags &LOOKUP_FOLLOW ))) {if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path->mnt ||unlazy_walk (nd, path->dentry))) {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 25/110 do_last: regularize the logics around following symlinks
In reply to Al ViroFrom: Al Viro <[email protected]>
With LOOKUP_FOLLOW we unlazy and return 1; without it we either fail with ELOOP or, for O_PATH opens, succeed. No need to mix those cases...
--- fs/namei.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/namei.c +7 -8
@@ -3046,9 +3046,7 @@ retry_lookup: goto out; } finish_lookup: -/* we _can_ be in RCU mode here */ -if (should_follow_link (path->dentry, - !(open_flag &O_PATH ) || (nd->flags &LOOKUP_FOLLOW ))) { +if (should_follow_link (path->dentry, nd->flags &LOOKUP_FOLLOW )) {if (nd->flags &LOOKUP_RCU ) {if (unlikely (nd->path.mnt != path->mnt ||unlazy_walk (nd, path->dentry))) {
@@ -3057,14 +3055,15 @@ finish_lookup: } }BUG_ON (inode != path->dentry->d_inode); -if (!(nd->flags &LOOKUP_FOLLOW )) { -path_put_conditional (path, nd); -path_put (&nd->path); -return -ELOOP ; - }return 1 ; } +if (unlikely (d_is_symlink (path->dentry)) && !(open_flag &O_PATH )) { +path_to_nameidata (path, nd); + error = -ELOOP ; + goto out; + } +if ((nd->flags &LOOKUP_RCU ) || nd->path.mnt != path->mnt) {path_to_nameidata (path, nd); }else {
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 26/110 namei: get rid of lookup_hash()
In reply to Al ViroFrom: Al Viro <[email protected]>
it's a convenient helper, but we'll want to shift nameidata down the call chain, so it won't be available there...
--- fs/namei.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-)
fs/namei.c +5 -15
@@ -2128,16 +2128,6 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, }EXPORT_SYMBOL (vfs_path_lookup); -/* -* Restricted form of lookup. Doesn't follow links, single-component only, -* needs parent already locked. Doesn't follow mounts. -* SMP-safe. -*/ -static struct dentry *lookup_hash (struct nameidata *nd) -{ -return __lookup_hash (&nd->last, nd->path.dentry, nd->flags); -} -/** * lookup_one_len - filesystem helper to lookup single pathname component * @name: pathname component to lookup
@@ -3351,7 +3341,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,* Do the final lookup. */ mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags);if (IS_ERR (dentry)) goto unlock;
@@ -3665,7 +3655,7 @@ retry: goto exit1;mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2;
@@ -3785,7 +3775,7 @@ retry: goto exit1; retry_deleg:mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =lookup_hash (&nd); + dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {/* Why not before? Because we want correct error value */
@@ -4304,7 +4294,7 @@ retry: retry_deleg: trap =lock_rename (new_dir, old_dir); - old_dentry =lookup_hash (&oldnd); + old_dentry =__lookup_hash (&oldnd.last, oldnd.path.dentry, oldnd.flags); error =PTR_ERR (old_dentry);if (IS_ERR (old_dentry)) goto exit3;
@@ -4312,7 +4302,7 @@ retry_deleg: error = -ENOENT ;if (d_is_negative (old_dentry)) goto exit4; - new_dentry =lookup_hash (&newnd); + new_dentry =__lookup_hash (&newnd.last, newnd.path.dentry, newnd.flags); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto exit4;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 27/110 name: shift nameidata down into user_path_walk()
In reply to Al ViroFrom: Al Viro <[email protected]>
that avoids having nameidata on stack during the calls of ->rmdir()/->unlink() and *two* of those during the calls of ->rename().
--- fs/namei.c | 124 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 67 insertions(+), 57 deletions(-)
fs/namei.c +67 -57
@@ -2211,9 +2211,13 @@ EXPORT_SYMBOL(user_path_at);* path-walking is complete. */ static struct filename * -user_path_parent (int dfd,const char __user *path,struct nameidata *nd, +user_path_parent (int dfd,const char __user *path, +struct path *parent, +struct qstr *last, +int *type,unsigned int flags) { +struct nameidata nd;struct filename *s =getname (path);int error;
@@ -2223,11 +2227,14 @@ user_path_parent(int dfd, const char __user *path, struct nameidata *nd,if (IS_ERR (s))return s; - error =filename_lookup (dfd, s, flags |LOOKUP_PARENT , nd); + error =filename_lookup (dfd, s, flags |LOOKUP_PARENT , &nd);if (error) {putname (s);return ERR_PTR (error); } + *parent = nd.path; + *last = nd.last; + *type = nd.last_type;return s; }
@@ -3630,14 +3637,17 @@ static long do_rmdir(int dfd, const char __user *pathname)int error =0 ;struct filename *name;struct dentry *dentry; -struct nameidata nd; +struct path path; +struct qstr last; +int type;unsigned int lookup_flags =0 ; retry: - name =user_path_parent (dfd, pathname, &nd, lookup_flags); + name =user_path_parent (dfd, pathname, + &path, &last, &type, lookup_flags);if (IS_ERR (name))return PTR_ERR (name); -switch (nd.last_type) { +switch (type) {case LAST_DOTDOT : error = -ENOTEMPTY ; goto exit1;
@@ -3649,13 +3659,12 @@ retry: goto exit1; } - nd.flags &= ~LOOKUP_PARENT ; - error =mnt_want_write (nd.path.mnt); + error =mnt_want_write (path.mnt);if (error) goto exit1; -mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); +mutex_lock_nested (&path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); + dentry =__lookup_hash (&last, path.dentry, lookup_flags); error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2;
@@ -3663,17 +3672,17 @@ retry: error = -ENOENT ; goto exit3; } - error =security_path_rmdir (&nd.path, dentry); + error =security_path_rmdir (&path, dentry);if (error) goto exit3; - error =vfs_rmdir (nd.path.dentry->d_inode, dentry); + error =vfs_rmdir (path.dentry->d_inode, dentry); exit3:dput (dentry); exit2: -mutex_unlock (&nd.path.dentry->d_inode->i_mutex); -mnt_drop_write (nd.path.mnt); +mutex_unlock (&path.dentry->d_inode->i_mutex); +mnt_drop_write (path.mnt); exit1: -path_put (&nd.path); +path_put (&path);putname (name);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ;
@@ -3756,43 +3765,45 @@ static long do_unlinkat(int dfd, const char __user *pathname)int error;struct filename *name;struct dentry *dentry; -struct nameidata nd; +struct path path; +struct qstr last; +int type;struct inode *inode =NULL ;struct inode *delegated_inode =NULL ;unsigned int lookup_flags =0 ; retry: - name =user_path_parent (dfd, pathname, &nd, lookup_flags); + name =user_path_parent (dfd, pathname, + &path, &last, &type, lookup_flags);if (IS_ERR (name))return PTR_ERR (name); error = -EISDIR ; -if (nd.last_type !=LAST_NORM ) +if (type !=LAST_NORM ) goto exit1; - nd.flags &= ~LOOKUP_PARENT ; - error =mnt_want_write (nd.path.mnt); + error =mnt_want_write (path.mnt);if (error) goto exit1; retry_deleg: -mutex_lock_nested (&nd.path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); - dentry =__lookup_hash (&nd.last, nd.path.dentry, nd.flags); +mutex_lock_nested (&path.dentry->d_inode->i_mutex,I_MUTEX_PARENT ); + dentry =__lookup_hash (&last, path.dentry, lookup_flags); error =PTR_ERR (dentry);if (!IS_ERR (dentry)) {/* Why not before? Because we want correct error value */ -if (nd.last.name[nd.last.len]) +if (last.name[last.len]) goto slashes; inode = dentry->d_inode;if (d_is_negative (dentry)) goto slashes;ihold (inode); - error =security_path_unlink (&nd.path, dentry); + error =security_path_unlink (&path, dentry);if (error) goto exit2; - error =vfs_unlink (nd.path.dentry->d_inode, dentry, &delegated_inode); + error =vfs_unlink (path.dentry->d_inode, dentry, &delegated_inode); exit2:dput (dentry); } -mutex_unlock (&nd.path.dentry->d_inode->i_mutex); +mutex_unlock (&path.dentry->d_inode->i_mutex);if (inode)iput (inode);/* truncate the inode here */ inode =NULL ;
@@ -3801,9 +3812,9 @@ exit2:if (!error) goto retry_deleg; } -mnt_drop_write (nd.path.mnt); +mnt_drop_write (path.mnt); exit1: -path_put (&nd.path); +path_put (&path);putname (name);if (retry_estale (error, lookup_flags)) { lookup_flags |=LOOKUP_REVAL ;
@@ -4233,14 +4244,15 @@ EXPORT_SYMBOL(vfs_rename); SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname, unsigned int, flags) { -struct dentry *old_dir, *new_dir;struct dentry *old_dentry, *new_dentry;struct dentry *trap; -struct nameidata oldnd, newnd; +struct path old_path, new_path; +struct qstr old_last, new_last; +int old_type, new_type;struct inode *delegated_inode =NULL ;struct filename *from;struct filename *to; -unsigned int lookup_flags =0 ; +unsigned int lookup_flags =0 , target_flags =LOOKUP_RENAME_TARGET ;bool should_retry = false;int error;
@@ -4254,47 +4266,45 @@ SYSCALL_DEFINE5(renameat2, int, olddfd, const char __user *, oldname,if ((flags &RENAME_WHITEOUT ) && !capable (CAP_MKNOD ))return -EPERM ; +if (flags &RENAME_EXCHANGE ) + target_flags =0 ; + retry: - from =user_path_parent (olddfd, oldname, &oldnd, lookup_flags); + from =user_path_parent (olddfd, oldname, + &old_path, &old_last, &old_type, lookup_flags);if (IS_ERR (from)) { error =PTR_ERR (from); goto exit; } - to =user_path_parent (newdfd, newname, &newnd, lookup_flags); + to =user_path_parent (newdfd, newname, + &new_path, &new_last, &new_type, lookup_flags);if (IS_ERR (to)) { error =PTR_ERR (to); goto exit1; } error = -EXDEV ; -if (oldnd.path.mnt != newnd.path.mnt) +if (old_path.mnt != new_path.mnt) goto exit2; - old_dir = oldnd.path.dentry; error = -EBUSY ; -if (oldnd.last_type !=LAST_NORM ) +if (old_type !=LAST_NORM ) goto exit2; - new_dir = newnd.path.dentry;if (flags &RENAME_NOREPLACE ) error = -EEXIST ; -if (newnd.last_type !=LAST_NORM ) +if (new_type !=LAST_NORM ) goto exit2; - error =mnt_want_write (oldnd.path.mnt); + error =mnt_want_write (old_path.mnt);if (error) goto exit2; - oldnd.flags &= ~LOOKUP_PARENT ; - newnd.flags &= ~LOOKUP_PARENT ; -if (!(flags &RENAME_EXCHANGE )) - newnd.flags |=LOOKUP_RENAME_TARGET ; - retry_deleg: - trap =lock_rename (new_dir, old_dir); + trap =lock_rename (new_path.dentry, old_path.dentry); - old_dentry =__lookup_hash (&oldnd.last, oldnd.path.dentry, oldnd.flags); + old_dentry =__lookup_hash (&old_last, old_path.dentry, lookup_flags); error =PTR_ERR (old_dentry);if (IS_ERR (old_dentry)) goto exit3;
@@ -4302,7 +4312,7 @@ retry_deleg: error = -ENOENT ;if (d_is_negative (old_dentry)) goto exit4; - new_dentry =__lookup_hash (&newnd.last, newnd.path.dentry, newnd.flags); + new_dentry =__lookup_hash (&new_last, new_path.dentry, lookup_flags | target_flags); error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto exit4;
@@ -4316,16 +4326,16 @@ retry_deleg:if (!d_is_dir (new_dentry)) { error = -ENOTDIR ; -if (newnd.last.name[newnd.last.len]) +if (new_last.name[new_last.len]) goto exit5; } }/* unless the source is a directory trailing slashes give -ENOTDIR */ if (!d_is_dir (old_dentry)) { error = -ENOTDIR ; -if (oldnd.last.name[oldnd.last.len]) +if (old_last.name[old_last.len]) goto exit5; -if (!(flags &RENAME_EXCHANGE ) && newnd.last.name[newnd.last.len]) +if (!(flags &RENAME_EXCHANGE ) && new_last.name[new_last.len]) goto exit5; }/* source should not be ancestor of target */
@@ -4338,32 +4348,32 @@ retry_deleg:if (new_dentry == trap) goto exit5; - error =security_path_rename (&oldnd.path, old_dentry, - &newnd.path, new_dentry, flags); + error =security_path_rename (&old_path, old_dentry, + &new_path, new_dentry, flags);if (error) goto exit5; - error =vfs_rename (old_dir->d_inode, old_dentry, - new_dir->d_inode, new_dentry, + error =vfs_rename (old_path.dentry->d_inode, old_dentry, + new_path.dentry->d_inode, new_dentry, &delegated_inode, flags); exit5:dput (new_dentry); exit4:dput (old_dentry); exit3: -unlock_rename (new_dir, old_dir); +unlock_rename (new_path.dentry, old_path.dentry);if (delegated_inode) { error =break_deleg_wait (&delegated_inode);if (!error) goto retry_deleg; } -mnt_drop_write (oldnd.path.mnt); +mnt_drop_write (old_path.mnt); exit2:if (retry_estale (error, lookup_flags)) should_retry = true; -path_put (&newnd.path); +path_put (&new_path);putname (to); exit1: -path_put (&oldnd.path); +path_put (&old_path);putname (from);if (should_retry) { should_retry = false;
Signature · 1 line
2.1.4
Al Viro
maintainerPATCH v3 28/110 namei: lift nameidata into filename_mountpoint()
In reply to Al ViroFrom: Al Viro <[email protected]>
when we go for on-demand allocation of saved state in link_path_walk(), we'll want nameidata to stay around for all 3 calls of path_mountpoint().
--- fs/namei.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
fs/namei.c +13 -15
@@ -2344,31 +2344,28 @@ out:*/ static int path_mountpoint (int dfd,const struct filename *name,struct path *path, -unsigned int flags) +struct nameidata *nd,unsigned int flags) { -struct nameidata nd; -int err; - - err =path_init (dfd, name, flags, &nd); +int err =path_init (dfd, name, flags, nd);if (unlikely (err)) goto out; - err =mountpoint_last (&nd, path); + err =mountpoint_last (nd, path);while (err >0 ) {void *cookie;struct path link = *path; - err =may_follow_link (&link, &nd); + err =may_follow_link (&link, nd);if (unlikely (err))break ; - nd.flags |=LOOKUP_PARENT ; - err =follow_link (&link, &nd, &cookie); + nd->flags |=LOOKUP_PARENT ; + err =follow_link (&link, nd, &cookie);if (err)break ; - err =mountpoint_last (&nd, path); -put_link (&nd, &link, cookie); + err =mountpoint_last (nd, path); +put_link (nd, &link, cookie); } out: -path_cleanup (&nd); +path_cleanup (nd);return err; }
@@ -2376,14 +2373,15 @@ static int filename_mountpoint(int dfd, struct filename *name, struct path *path, unsigned int flags) { + struct nameidata nd;int error;if (IS_ERR (name))return PTR_ERR (name); - error =path_mountpoint (dfd, name, path, flags |LOOKUP_RCU ); + error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_RCU );if (unlikely (error == -ECHILD )) - error =path_mountpoint (dfd, name, path, flags); + error =path_mountpoint (dfd, name, path, &nd, flags);if (unlikely (error == -ESTALE )) - error =path_mountpoint (dfd, name, path, flags |LOOKUP_REVAL ); + error =path_mountpoint (dfd, name, path, &nd, flags |LOOKUP_REVAL );if (likely (!error))audit_inode (name, path->dentry,0 );putname (name);
Signature · 1 line
2.1.4