Skip to content

Commit

Permalink
new ->follow_link() and ->put_link() calling conventions
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed May 11, 2015
1 parent 46afd6f commit 680baac
Show file tree
Hide file tree
Showing 31 changed files with 195 additions and 273 deletions.
4 changes: 2 additions & 2 deletions Documentation/filesystems/Locking
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Documentation/filesystems/vfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
11 changes: 5 additions & 6 deletions drivers/staging/lustre/lustre/llite/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static int ll_readlink_internal(struct inode *inode,
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;
Expand All @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions fs/9p/vfs_inode_dotl.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,8 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
*
*/

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;
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions fs/autofs4/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
35 changes: 16 additions & 19 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/cifsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 13 additions & 15 deletions fs/cifs/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
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;
Expand All @@ -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);

Expand All @@ -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
Expand Down
28 changes: 12 additions & 16 deletions fs/configfs/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 3 additions & 5 deletions fs/ecryptfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,16 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
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;
}

/**
Expand Down
9 changes: 4 additions & 5 deletions fs/ext4/symlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 7 additions & 11 deletions fs/f2fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,15 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
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_follow_link_light(dentry, nd);

if (IS_ERR_OR_NULL(page))
return page;

/* this is broken symlink case */
if (*nd_get_link(nd) == 0) {
page_put_link(dentry, nd, 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,
Expand Down
Loading

0 comments on commit 680baac

Please sign in to comment.