Commit 6b255391 authored by Al Viro's avatar Al Viro

replace ->follow_link() with new method that could stay in RCU mode

new method: ->get_link(); replacement of ->follow_link().  The differences
are:
	* inode and dentry are passed separately
	* might be called both in RCU and non-RCU mode;
the former is indicated by passing it a NULL dentry.
	* when called that way it isn't allowed to block
and should return ERR_PTR(-ECHILD) if it needs to be called
in non-RCU mode.

It's a flagday change - the old method is gone, all in-tree instances
converted.  Conversion isn't hard; said that, so far very few instances
do not immediately bail out when called in RCU mode.  That'll change
in the next commits.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 21fc61c7
......@@ -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 **);
const char *(*get_link) (struct dentry *, struct inode *, void **);
void (*put_link) (struct inode *, void *);
void (*truncate) (struct inode *);
int (*permission) (struct inode *, int, unsigned int);
......@@ -83,7 +83,7 @@ rmdir: yes (both) (see below)
rename: yes (all) (see below)
rename2: yes (all) (see below)
readlink: no
follow_link: no
get_link: no
put_link: no
setattr: yes
permission: no (may not block if called in rcu-walk mode)
......
......@@ -509,3 +509,9 @@ in your dentry operations instead.
any symlink that might use page_follow_link_light/page_put_link() must
have inode_nohighmem(inode) called before anything might start playing with
its pagecache.
--
[mandatory]
->follow_link() is replaced with ->get_link(); same API, except that
* ->get_link() gets inode as a separate argument
* ->get_link() may be called in RCU mode - in that case NULL
dentry is passed
......@@ -118,12 +118,14 @@ static int ll_readlink_internal(struct inode *inode,
return rc;
}
static const char *ll_follow_link(struct dentry *dentry, void **cookie)
static const char *ll_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct inode *inode = d_inode(dentry);
struct ptlrpc_request *request = NULL;
int rc;
char *symname = NULL;
if (!dentry)
return ERR_PTR(-ECHILD);
CDEBUG(D_VFSTRACE, "VFS Op\n");
ll_inode_size_lock(inode);
......@@ -149,7 +151,7 @@ static void ll_put_link(struct inode *unused, void *cookie)
struct inode_operations ll_fast_symlink_inode_operations = {
.readlink = generic_readlink,
.setattr = ll_setattr,
.follow_link = ll_follow_link,
.get_link = ll_get_link,
.put_link = ll_put_link,
.getattr = ll_getattr,
.permission = ll_inode_permission,
......
......@@ -1223,18 +1223,25 @@ ino_t v9fs_qid2ino(struct p9_qid *qid)
}
/**
* v9fs_vfs_follow_link - follow a symlink path
* v9fs_vfs_get_link - follow a symlink path
* @dentry: dentry for symlink
* @inode: inode for symlink
* @cookie: place to pass the data to put_link()
*/
static const char *v9fs_vfs_follow_link(struct dentry *dentry, void **cookie)
static const char *v9fs_vfs_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct v9fs_session_info *v9ses = v9fs_dentry2v9ses(dentry);
struct p9_fid *fid = v9fs_fid_lookup(dentry);
struct v9fs_session_info *v9ses;
struct p9_fid *fid;
struct p9_wstat *st;
char *res;
if (!dentry)
return ERR_PTR(-ECHILD);
v9ses = v9fs_dentry2v9ses(dentry);
fid = v9fs_fid_lookup(dentry);
p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
if (IS_ERR(fid))
......@@ -1452,7 +1459,7 @@ static const struct inode_operations v9fs_file_inode_operations = {
static const struct inode_operations v9fs_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = v9fs_vfs_follow_link,
.get_link = v9fs_vfs_get_link,
.put_link = kfree_put_link,
.getattr = v9fs_vfs_getattr,
.setattr = v9fs_vfs_setattr,
......
......@@ -899,20 +899,26 @@ v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, umode_t omode,
}
/**
* v9fs_vfs_follow_link_dotl - follow a symlink path
* v9fs_vfs_get_link_dotl - follow a symlink path
* @dentry: dentry for symlink
* @inode: inode for symlink
* @cookie: place to pass the data to put_link()
*/
static const char *
v9fs_vfs_follow_link_dotl(struct dentry *dentry, void **cookie)
v9fs_vfs_get_link_dotl(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct p9_fid *fid = v9fs_fid_lookup(dentry);
struct p9_fid *fid;
char *target;
int retval;
if (!dentry)
return ERR_PTR(-ECHILD);
p9_debug(P9_DEBUG_VFS, "%pd\n", dentry);
fid = v9fs_fid_lookup(dentry);
if (IS_ERR(fid))
return ERR_CAST(fid);
retval = p9_client_readlink(fid, &target);
......@@ -984,7 +990,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,
.get_link = v9fs_vfs_get_link_dotl,
.put_link = kfree_put_link,
.getattr = v9fs_vfs_getattr_dotl,
.setattr = v9fs_vfs_setattr_dotl,
......
......@@ -20,7 +20,7 @@ static int affs_symlink_readpage(struct file *file, struct page *page)
char c;
char lc;
pr_debug("follow_link(ino=%lu)\n", inode->i_ino);
pr_debug("get_link(ino=%lu)\n", inode->i_ino);
bh = affs_bread(inode->i_sb, inode->i_ino);
if (!bh)
......@@ -71,7 +71,7 @@ const struct address_space_operations affs_symlink_aops = {
const struct inode_operations affs_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.setattr = affs_notify_change,
};
......@@ -12,10 +12,15 @@
#include "autofs_i.h"
static const char *autofs4_follow_link(struct dentry *dentry, void **cookie)
static const char *autofs4_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
struct autofs_info *ino = autofs4_dentry_ino(dentry);
struct autofs_sb_info *sbi;
struct autofs_info *ino;
if (!dentry)
return ERR_PTR(-ECHILD);
sbi = autofs4_sbi(dentry->d_sb);
ino = autofs4_dentry_ino(dentry);
if (ino && !autofs4_oz_mode(sbi))
ino->last_used = jiffies;
return d_inode(dentry)->i_private;
......@@ -23,5 +28,5 @@ static const char *autofs4_follow_link(struct dentry *dentry, void **cookie)
const struct inode_operations autofs4_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = autofs4_follow_link
.get_link = autofs4_get_link
};
......@@ -10096,7 +10096,7 @@ static const struct inode_operations btrfs_special_inode_operations = {
};
static const struct inode_operations btrfs_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.getattr = btrfs_getattr,
.setattr = btrfs_setattr,
......
......@@ -1756,7 +1756,7 @@ void __ceph_do_pending_vmtruncate(struct inode *inode)
*/
static const struct inode_operations ceph_symlink_iops = {
.readlink = generic_readlink,
.follow_link = simple_follow_link,
.get_link = simple_get_link,
.setattr = ceph_setattr,
.getattr = ceph_getattr,
.setxattr = ceph_setxattr,
......
......@@ -900,7 +900,7 @@ const struct inode_operations cifs_file_inode_ops = {
const struct inode_operations cifs_symlink_inode_ops = {
.readlink = generic_readlink,
.follow_link = cifs_follow_link,
.get_link = cifs_get_link,
.put_link = kfree_put_link,
.permission = cifs_permission,
/* BB add the following two eventually */
......
......@@ -120,9 +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);
extern int cifs_readlink(struct dentry *direntry, char __user *buffer,
int buflen);
extern const char *cifs_get_link(struct dentry *, struct inode *, void **);
extern int cifs_symlink(struct inode *inode, struct dentry *direntry,
const char *symname);
extern int cifs_removexattr(struct dentry *, const char *);
......
......@@ -627,9 +627,8 @@ cifs_hardlink(struct dentry *old_file, struct inode *inode,
}
const char *
cifs_follow_link(struct dentry *direntry, void **cookie)
cifs_get_link(struct dentry *direntry, struct inode *inode, void **cookie)
{
struct inode *inode = d_inode(direntry);
int rc = -ENOMEM;
unsigned int xid;
char *full_path = NULL;
......@@ -639,6 +638,9 @@ cifs_follow_link(struct dentry *direntry, void **cookie)
struct cifs_tcon *tcon;
struct TCP_Server_Info *server;
if (!direntry)
return ERR_PTR(-ECHILD);
xid = get_xid();
tlink = cifs_sb_tlink(cifs_sb);
......
......@@ -18,7 +18,7 @@ static inline int coda_fideq(struct CodaFid *fid1, struct CodaFid *fid2)
static const struct inode_operations coda_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.setattr = coda_setattr,
};
......
......@@ -279,11 +279,16 @@ static int configfs_getlink(struct dentry *dentry, char * path)
}
static const char *configfs_follow_link(struct dentry *dentry, void **cookie)
static const char *configfs_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
unsigned long page = get_zeroed_page(GFP_KERNEL);
unsigned long page;
int error;
if (!dentry)
return ERR_PTR(-ECHILD);
page = get_zeroed_page(GFP_KERNEL);
if (!page)
return ERR_PTR(-ENOMEM);
......@@ -297,7 +302,7 @@ static const char *configfs_follow_link(struct dentry *dentry, void **cookie)
}
const struct inode_operations configfs_symlink_inode_operations = {
.follow_link = configfs_follow_link,
.get_link = configfs_get_link,
.readlink = generic_readlink,
.put_link = free_page_put_link,
.setattr = configfs_setattr,
......
......@@ -1734,7 +1734,7 @@ static unsigned d_flags_for_inode(struct inode *inode)
}
if (unlikely(!(inode->i_opflags & IOP_NOFOLLOW))) {
if (unlikely(inode->i_op->follow_link)) {
if (unlikely(inode->i_op->get_link)) {
add_flags = DCACHE_SYMLINK_TYPE;
goto type_determined;
}
......
......@@ -674,10 +674,16 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
return rc ? ERR_PTR(rc) : buf;
}
static const char *ecryptfs_follow_link(struct dentry *dentry, void **cookie)
static const char *ecryptfs_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
size_t len;
char *buf = ecryptfs_readlink_lower(dentry, &len);
char *buf;
if (!dentry)
return ERR_PTR(-ECHILD);
buf = ecryptfs_readlink_lower(dentry, &len);
if (IS_ERR(buf))
return buf;
fsstack_copy_attr_atime(d_inode(dentry),
......@@ -1095,7 +1101,7 @@ static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
const struct inode_operations ecryptfs_symlink_iops = {
.readlink = generic_readlink,
.follow_link = ecryptfs_follow_link,
.get_link = ecryptfs_get_link,
.put_link = kfree_put_link,
.permission = ecryptfs_permission,
.setattr = ecryptfs_setattr,
......
......@@ -22,7 +22,7 @@
const struct inode_operations ext2_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.setattr = ext2_setattr,
#ifdef CONFIG_EXT2_FS_XATTR
......@@ -35,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 = simple_follow_link,
.get_link = simple_get_link,
.setattr = ext2_setattr,
#ifdef CONFIG_EXT2_FS_XATTR
.setxattr = generic_setxattr,
......
......@@ -23,17 +23,20 @@
#include "xattr.h"
#ifdef CONFIG_EXT4_FS_ENCRYPTION
static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cookie)
static const char *ext4_encrypted_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct page *cpage = NULL;
char *caddr, *paddr = NULL;
struct ext4_str cstr, pstr;
struct inode *inode = d_inode(dentry);
struct ext4_encrypted_symlink_data *sd;
loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
int res;
u32 plen, max_size = inode->i_sb->s_blocksize;
if (!dentry)
return ERR_PTR(-ECHILD);
res = ext4_get_encryption_info(inode);
if (res)
return ERR_PTR(res);
......@@ -87,7 +90,7 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook
const struct inode_operations ext4_encrypted_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = ext4_encrypted_follow_link,
.get_link = ext4_encrypted_get_link,
.put_link = kfree_put_link,
.setattr = ext4_setattr,
.setxattr = generic_setxattr,
......@@ -99,7 +102,7 @@ const struct inode_operations ext4_encrypted_symlink_inode_operations = {
const struct inode_operations ext4_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.setattr = ext4_setattr,
.setxattr = generic_setxattr,
......@@ -110,7 +113,7 @@ const struct inode_operations ext4_symlink_inode_operations = {
const struct inode_operations ext4_fast_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = simple_follow_link,
.get_link = simple_get_link,
.setattr = ext4_setattr,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
......
......@@ -315,9 +315,10 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
return err;
}
static const char *f2fs_follow_link(struct dentry *dentry, void **cookie)
static const char *f2fs_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
const char *link = page_follow_link_light(dentry, cookie);
const char *link = page_get_link(dentry, inode, cookie);
if (!IS_ERR(link) && !*link) {
/* this is broken symlink case */
page_put_link(NULL, *cookie);
......@@ -924,18 +925,21 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
}
#ifdef CONFIG_F2FS_FS_ENCRYPTION
static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookie)
static const char *f2fs_encrypted_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct page *cpage = NULL;
char *caddr, *paddr = NULL;
struct f2fs_str cstr;
struct f2fs_str pstr = FSTR_INIT(NULL, 0);
struct inode *inode = d_inode(dentry);
struct f2fs_encrypted_symlink_data *sd;
loff_t size = min_t(loff_t, i_size_read(inode), PAGE_SIZE - 1);
u32 max_size = inode->i_sb->s_blocksize;
int res;
if (!dentry)
return ERR_PTR(-ECHILD);
res = f2fs_get_encryption_info(inode);
if (res)
return ERR_PTR(res);
......@@ -994,7 +998,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = f2fs_encrypted_follow_link,
.get_link = f2fs_encrypted_get_link,
.put_link = kfree_put_link,
.getattr = f2fs_getattr,
.setattr = f2fs_setattr,
......@@ -1030,7 +1034,7 @@ const struct inode_operations f2fs_dir_inode_operations = {
const struct inode_operations f2fs_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = f2fs_follow_link,
.get_link = f2fs_get_link,
.put_link = page_put_link,
.getattr = f2fs_getattr,
.setattr = f2fs_setattr,
......
......@@ -1365,14 +1365,17 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)
return err;
}
static const char *fuse_follow_link(struct dentry *dentry, void **cookie)
static const char *fuse_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct inode *inode = d_inode(dentry);
struct fuse_conn *fc = get_fuse_conn(inode);
FUSE_ARGS(args);
char *link;
ssize_t ret;
if (!dentry)
return ERR_PTR(-ECHILD);
link = (char *) __get_free_page(GFP_KERNEL);
if (!link)
return ERR_PTR(-ENOMEM);
......@@ -1909,7 +1912,7 @@ static const struct inode_operations fuse_common_inode_operations = {
static const struct inode_operations fuse_symlink_inode_operations = {
.setattr = fuse_setattr,
.follow_link = fuse_follow_link,
.get_link = fuse_get_link,
.put_link = free_page_put_link,
.readlink = generic_readlink,
.getattr = fuse_getattr,
......
......@@ -1712,24 +1712,29 @@ static int gfs2_rename2(struct inode *odir, struct dentry *odentry,
}
/**
* gfs2_follow_link - Follow a symbolic link
* gfs2_get_link - Follow a symbolic link
* @dentry: The dentry of the link
* @nd: Data that we pass to vfs_follow_link()
* @inode: The inode of the link
* @cookie: place to store the information for ->put_link()
*
* This can handle symlinks of any size.
*
* Returns: 0 on success or error code
*/
static const char *gfs2_follow_link(struct dentry *dentry, void **cookie)
static const char *gfs2_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
struct gfs2_inode *ip = GFS2_I(d_inode(dentry));
struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_holder i_gh;
struct buffer_head *dibh;
unsigned int size;
char *buf;
int error;
if (!dentry)
return ERR_PTR(-ECHILD);
gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
error = gfs2_glock_nq(&i_gh);
if (error) {
......@@ -2132,7 +2137,7 @@ const struct inode_operations gfs2_dir_iops = {
const struct inode_operations gfs2_symlink_iops = {
.readlink = generic_readlink,
.follow_link = gfs2_follow_link,
.get_link = gfs2_get_link,
.put_link = kfree_put_link,
.permission = gfs2_permission,
.setattr = gfs2_setattr,
......
......@@ -892,9 +892,13 @@ static const struct inode_operations hostfs_dir_iops = {
.setattr = hostfs_setattr,
};
static const char *hostfs_follow_link(struct dentry *dentry, void **cookie)
static const char *hostfs_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
char *link = __getname();
char *link;
if (!dentry)
return ERR_PTR(-ECHILD);
link = __getname();
if (link) {
char *path = dentry_name(dentry);
int err = -ENOMEM;
......@@ -922,7 +926,7 @@ static void hostfs_put_link(struct inode *unused, void *cookie)
static const struct inode_operations hostfs_link_iops = {
.readlink = generic_readlink,
.follow_link = hostfs_follow_link,
.get_link = hostfs_get_link,
.put_link = hostfs_put_link,
};
......
......@@ -14,7 +14,7 @@
const struct inode_operations jffs2_symlink_inode_operations =
{
.readlink = generic_readlink,
.follow_link = simple_follow_link,
.get_link = simple_get_link,
.setattr = jffs2_setattr,
.setxattr = jffs2_setxattr,
.getxattr = jffs2_getxattr,
......
......@@ -23,7 +23,7 @@
const struct inode_operations jfs_fast_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = simple_follow_link,
.get_link = simple_get_link,
.setattr = jfs_setattr,
.setxattr = jfs_setxattr,
.getxattr = jfs_getxattr,
......@@ -33,7 +33,7 @@ const struct inode_operations jfs_fast_symlink_inode_operations = {
const struct inode_operations jfs_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.setattr = jfs_setattr,
.setxattr = jfs_setxattr,
......
......@@ -112,10 +112,15 @@ static int kernfs_getlink(struct dentry *dentry, char *path)
return error;
}
static const char *kernfs_iop_follow_link(struct dentry *dentry, void **cookie)
static const char *kernfs_iop_get_link(struct dentry *dentry,
struct inode *inode, void **cookie)
{
int error = -ENOMEM;
unsigned long page = get_zeroed_page(GFP_KERNEL);
unsigned long page;
if (!dentry)
return ERR_PTR(-ECHILD);
page = get_zeroed_page(GFP_KERNEL);
if (!page)
return ERR_PTR(-ENOMEM);
error = kernfs_getlink(dentry, (char *)page);
......@@ -132,7 +137,7 @@ const struct inode_operations kernfs_symlink_iops = {
.getxattr = kernfs_iop_getxattr,
.listxattr = kernfs_iop_listxattr,
.readlink = generic_readlink,
.follow_link = kernfs_iop_follow_link,
.get_link = kernfs_iop_get_link,
.put_link = free_page_put_link,
.setattr = kernfs_iop_setattr,
.getattr = kernfs_iop_getattr,
......
......@@ -1092,14 +1092,15 @@ 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)
const char *simple_get_link(struct dentry *dentry, struct inode *inode,
void **cookie)
{
return d_inode(dentry)->i_link;
return inode->i_link;
}
EXPORT_SYMBOL(simple_follow_link);
EXPORT_SYMBOL(simple_get_link);
const struct inode_operations simple_symlink_inode_operations = {
.follow_link = simple_follow_link,
.get_link = simple_get_link,
.readlink = generic_readlink
};
EXPORT_SYMBOL(simple_symlink_inode_operations);
......
......@@ -435,7 +435,7 @@ static const struct address_space_operations minix_aops = {
static const struct inode_operations minix_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,
.get_link = page_get_link,
.put_link = page_put_link,
.getattr = minix_getattr,
};
......
......@@ -842,7 +842,7 @@ static inline void path_to_nameidata(const struct path *path,
}
/*
* Helper to directly jump to a known parsed path from ->follow_link,
* Helper to directly jump to a known parsed path from ->get_link,
* caller must have taken a reference to path beforehand.
*/
void nd_jump_link(struct path *path)
......@@ -1005,10 +1005,18 @@ const char *get_link(struct nameidata *nd)
res = inode->i_link;
if (!res) {
if (nd->flags & LOOKUP_RCU) {
if (unlikely(unlazy_walk(nd, NULL, 0)))
return ERR_PTR(-ECHILD);
res = inode->i_op->get_link(NULL, inode,
&last->cookie);
if (res == ERR_PTR(-ECHILD)) {
if (unlikely(unlazy_walk(nd, NULL, 0)))
return ERR_PTR(-ECHILD);
res = inode->i_op->get_link(dentry, inode,
&last->cookie);
}
} else {
res = inode->i_op->get_link(dentry, inode,
&last->cookie);
}
res = inode->i_op->follow_link(dentry, &last->cookie);
if (IS_ERR_OR_NULL(res)) {
last->cookie = NULL;
return res;
......@@ -4495,8 +4503,8 @@ EXPORT_SYMBOL(readlink_copy);
/*
* A helper for ->readlink(). This should be used *ONLY* for symlinks that
* have ->follow_link() touching nd only in nd_set_link(). Using (or not
* using) it for any given inode is up to filesystem.
* have ->get_link() not calling nd_jump_link(). Using (or not using) it
* for any given inode is up to filesystem.
*/
int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
{
......@@ -4506,7 +4514,7 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
int res;
if (!link) {
link = inode->i_op->follow_link(dentry, &cookie);
link = inode->i_op->get_link(dentry, inode, &cookie);
if (IS_ERR(link))
return PTR_ERR(link);
}
......@@ -4518,26 +4526,27 @@ int generic_readlink(struct dentry *dentry, char __user *buffer, int buflen)
EXPORT_SYMBOL(generic_readlink);
/* get the link contents into pagecache */
static const char *page_getlink(struct dentry * dentry, void **cookie)
const char *page_get_link(struct dentry *dentry, struct inode *inode,
void **cookie)
{
char *kaddr;
struct page *page;
struct address_space *mapping = dentry->d_inode->i_mapping;
struct address_space *mapping = inode->i_mapping;
if (!dentry)
return ERR_PTR(-ECHILD);
page = read_mapping_page(mapping, 0, NULL);
if (IS_ERR(page))
return (char*)page;
*cookie = page;
BUG_ON(mapping_gfp_mask(mapping) & __GFP_HIGHMEM);
kaddr = page_address(page);
nd_terminate_link(kaddr, dentry->d_inode->i_size, PAGE_SIZE - 1);
nd_terminate_link(kaddr, inode->i_size, PAGE_SIZE - 1);
return kaddr;
}
const char *page_follow_link_light(struct dentry *dentry, void **cookie)
{
return page_getlink(dentry, cookie);
}
EXPORT_SYMBOL(page_follow_link_light);
EXPORT_SYMBOL(page_get_link);
void page_put_link(struct inode *unused, void *cookie)
{
......@@ -4549,7 +4558,9 @@ EXPORT_SYMBOL(page_put_link);
int page_readlink(struct dentry *dentry, char __user *buffer, int buflen)
{
void *cookie = NULL;
int res = readlink_copy(buffer, buflen, page_getlink(dentry, &cookie));
int res = readlink_copy(buffer, buflen,
page_get_link(dentry, d_inode(dentry),
&cookie));
if (cookie)
page_put_link(NULL, cookie);
return res;
......@@ -4600,7 +4611,7 @@ EXPORT_SYMBOL(page_symlink);
const struct inode_operations page_symlink_inode_operations = {
.readlink = generic_readlink,
.follow_link = page_follow_link_light,