Skip to contentSkip to conversation

stop using uio in the readlink code

PATCH In review Christoph Hellwig 2 participants 3 messages Jul 29, 2007 – Aug 1, 2007 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 stop using uio in the readlink code

Simplify the readlink code to get rid of the last user of uio.

fs/xfs/linux-2.6/xfs_iops.c +13 -37
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_iops.c
===================================================================
@@ -542,50 +542,26 @@ xfs_vn_follow_link(
 	struct dentry		*dentry,
 	struct nameidata	*nd)
 {
-	bhv_vnode_t		*vp;
-	uio_t			*uio;
-	iovec_t			iov;
-	int			error;
+	bhv_vnode_t		*vp = vn_from_inode(dentry->d_inode);
 	char			*link;
-
-	ASSERT(dentry);
-	ASSERT(nd);
+	int			error = -ENOMEM;
 
 	link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
-	if (!link) {
-		nd_set_link(nd, ERR_PTR(-ENOMEM));
-		return NULL;
-	}
-
-	uio = kmalloc(sizeof(uio_t), GFP_KERNEL);
-	if (!uio) {
-		kfree(link);
-		nd_set_link(nd, ERR_PTR(-ENOMEM));
-		return NULL;
-	}
+	if (!link)
+		goto out_err;
 
-	vp = vn_from_inode(dentry->d_inode);
-
-	iov.iov_base = link;
-	iov.iov_len = MAXPATHLEN;
-
-	uio->uio_iov = &iov;
-	uio->uio_offset = 0;
-	uio->uio_segflg = UIO_SYSSPACE;
-	uio->uio_resid = MAXPATHLEN;
-	uio->uio_iovcnt = 1;
-
-	error = bhv_vop_readlink(vp, uio, 0, NULL);
-	if (unlikely(error)) {
-		kfree(link);
-		link = ERR_PTR(-error);
-	} else {
-		link[MAXPATHLEN - uio->uio_resid] = '\0';
-	}
-	kfree(uio);
+	error = -bhv_vop_readlink(vp, link);
+	if (unlikely(error))
+		goto out_kfree;
 
 	nd_set_link(nd, link);
 	return NULL;
+
+ out_kfree:
+	kfree(link);
+ out_err:
+	nd_set_link(nd, ERR_PTR(error));
+	return NULL;
 }
 
 STATIC void
fs/xfs/linux-2.6/xfs_vnode.h +3 -5
Index: linux-2.6-xfs/fs/xfs/linux-2.6/xfs_vnode.h
===================================================================
@@ -18,7 +18,6 @@
 #ifndef __XFS_VNODE_H__
 #define __XFS_VNODE_H__
 
-struct uio;
 struct file;
 struct bhv_vfs;
 struct bhv_vattr;
@@ -168,8 +167,7 @@ typedef int	(*vop_readdir_t)(bhv_desc_t 
 				 xfs_off_t *offset, filldir_t filldir);
 typedef int	(*vop_symlink_t)(bhv_desc_t *, bhv_vname_t *, struct bhv_vattr*,
 				char *, bhv_vnode_t **, struct cred *);
-typedef int	(*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
-				struct cred *);
+typedef int	(*vop_readlink_t)(bhv_desc_t *, char *);
 typedef int	(*vop_fsync_t)(bhv_desc_t *, int, struct cred *,
 				xfs_off_t, xfs_off_t);
 typedef int	(*vop_inactive_t)(bhv_desc_t *, struct cred *);
@@ -280,8 +278,8 @@ typedef struct bhv_vnodeops {
 		VOP(vop_readdir, vp)(VNHEAD(vp),dirent,bufsize,offset,filldir)
 #define	bhv_vop_symlink(dvp,d,vap,tnm,vpp,cr)				\
 		VOP(vop_symlink, dvp)(VNHEAD(dvp),d,vap,tnm,vpp,cr)
-#define	bhv_vop_readlink(vp,uiop,fl,cr)					\
-		VOP(vop_readlink, vp)(VNHEAD(vp),uiop,fl,cr)
+#define	bhv_vop_readlink(vp,link)					\
+		VOP(vop_readlink, vp)(VNHEAD(vp), link)
 #define	bhv_vop_fsync(vp,f,cr,b,e)	VOP(vop_fsync, vp)(VNHEAD(vp),f,cr,b,e)
 #define bhv_vop_inactive(vp,cr)		VOP(vop_inactive, vp)(VNHEAD(vp),cr)
 #define bhv_vop_release(vp)		VOP(vop_release, vp)(VNHEAD(vp))
fs/xfs/xfs_vnodeops.c +60 -72

163 lines not on this page · raw message

fs/xfs/linux-2.6/xfs_ioctl.c +45 -18

93 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Christoph Hellwig

Simplify the readlink code to get rid of the last user of uio.

.....

Quoted 20 lines
fs/xfs/linux-2.6/xfs_ioctl.c +14 -0
@@ -349,19 +349,44 @@ xfs_open_by_handle(
 	return new_fd;
 }
 
+/*
+ * This is a copy from fs/namei.c:vfs_readlink(), except for removing it's
+ * unused first argument.
+ */
+STATIC int
+do_readlink(
+	char __user		*buffer,
+	int			buflen,
+	const char		*link)
+{
+        int len;
+
+	len = PTR_ERR(link);
+	if (IS_ERR(link))

fs/xfs/linux-2.6/xfs_ioctl.c xfs_open_by_handle( · line 375

Quoted 10 lines
fs/xfs/linux-2.6/xfs_ioctl.c +10 -0
+		goto out;
+
+	len = strlen(link);
+	if (len > (unsigned) buflen)
+		len = buflen;
+	if (copy_to_user(buffer, link, len))
+		len = -EFAULT;
+ out:
+	return len;
+}

Do we really need to copy this code? I guess it doesn't really matter that much but it would be nice not to have to copy an exported vfs function just because we don't have a dentry...

Cheers,

Dave.

Signature · 3 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group
#2 lore raw
Quoted 3 lines · David Chinner

Do we really need to copy this code? I guess it doesn't really matter that much but it would be nice not to have to copy an exported vfs function just because we don't have a dentry...

I was wondering whether to send a patch to fix and export the VFS function afterwards, but I really don't want a an xfs patch like this to have a VFS change depency to start with. Especially as I want to change the name of the helper in namei.c aswell - the vfs_ prefix is completely wrong.