mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Fix readlink(2)
This patch addresses three issues related to symlinks. 1) Revert the zfs_follow_link() function to a modified version of the original zfs_readlink(). The only changes from the original OpenSolaris version relate to using Linux types. For the moment this means no vnode's and no zfsvfs_t. The caller zpl_follow_link() was also updated accordingly. This change was reverted because it was slightly gratuitious. 2) Update zpl_follow_link() to use local variables for the link buffer. I'd forgotten that iov.iov_base is updated by uiomove() so after the call to zfs_readlink() it can not longer be used. We need our own private copy of the link pointer. 3) Allocate MAXPATHLEN instead of MAXPATHLEN+1. By default MAXPATHLEN is 4096 bytes which is a full page, adding one to it pushes it slightly over a page. That means you'll likely end up allocating 2 pages which is wasteful of memory and possibly slightly slower.
This commit is contained in:
+28
-3
@@ -245,8 +245,33 @@ out:
|
||||
static void *
|
||||
zpl_follow_link(struct dentry *dentry, struct nameidata *nd)
|
||||
{
|
||||
(void) zfs_follow_link(dentry, nd);
|
||||
return NULL;
|
||||
struct inode *ip = dentry->d_inode;
|
||||
struct iovec iov;
|
||||
uio_t uio;
|
||||
char *link;
|
||||
cred_t *cr;
|
||||
int error;
|
||||
|
||||
cr = (cred_t *)get_current_cred();
|
||||
|
||||
iov.iov_len = MAXPATHLEN;
|
||||
iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
|
||||
|
||||
uio.uio_iov = &iov;
|
||||
uio.uio_iovcnt = 1;
|
||||
uio.uio_resid = (MAXPATHLEN - 1);
|
||||
uio.uio_segflg = UIO_SYSSPACE;
|
||||
|
||||
error = zfs_readlink(ip, &uio, cr);
|
||||
if (error) {
|
||||
kmem_free(link, MAXPATHLEN);
|
||||
nd_set_link(nd, ERR_PTR(error));
|
||||
} else {
|
||||
nd_set_link(nd, link);
|
||||
}
|
||||
|
||||
put_cred(cr);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -256,7 +281,7 @@ zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
|
||||
|
||||
link = nd_get_link(nd);
|
||||
if (!IS_ERR(link))
|
||||
kmem_free(link, MAXPATHLEN + 1);
|
||||
kmem_free(link, MAXPATHLEN);
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
Reference in New Issue
Block a user