All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -V8 0/9] Generic name to handle and open by handle syscalls
@ 2010-05-17  5:33 Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 1/9] exportfs: Return the minimum required handle size Aneesh Kumar K.V
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel

Hi,

The below set of patches implement open by handle support using exportfs
operations. This allows user space application to map a file name to file 
handle and later open the file using handle. This should be usable
for userspace NFS [1] and 9P server [2]. XFS already support this with the ioctls
XFS_IOC_PATH_TO_HANDLE and XFS_IOC_OPEN_BY_HANDLE.

[1] http://nfs-ganesha.sourceforge.net/
[2] http://thread.gmane.org/gmane.comp.emulators.qemu/68992

Changes from V7:
a) open_by_handle now use mountdirfd to identify the vfsmount.
b) We don't validate the UUID passed as a part of file handle in open_by_handle.
   UUID is provided as a part of file handle as an easy way for userspace to
   use the kernel returned handle as it is. It also helps in finding the 16 byte
   filessytem UUID in userspace without using file system specific libraries to
   read file system superblock. If a particular file system doesn't support UUID
   or any form of unique id this field in the file handle will be zero filled.
c) drop freadlink syscall. Instead use readlinkat with NULL pathname to indicate
   read the link target name of the link pointed by fd. This is similar to
   sys_utimensat
d) Instead of opencoding all the open flag related check use helper functions.
   Did finish_open_by_handle similar to finish_open.
c) Fix may_open to not return ELOOP for symlink when we are called from handle open.
   open(2) still returns error as expected. 

Changes from V6:
a) Add uuid to vfsmount lookup and drop uuid to superblock lookup
b) Return -EOPNOTSUPP in sys_name_to_handle if the file system returned uuid
   doesn't give the same vfsmount on lookup. This ensure that we fail
   sys_name_to_handle when we have multiple file system returning same UUID.

Changes from V5:
a) added sys_name_to_handle_at syscall which takes AT_SYMLINK_NOFOLLOW flag 
   instead of two syscalls sys_name_to_handle and sys_lname_to_handle.
b) addressed review comments from Niel Brown
c) rebased to b91ce4d14a21fc04d165be30319541e0f9204f15
d) Add compat_sys_open_by_handle

Chages from V4:
a) Changed the syscal arguments so that we don't need compat syscalls
   as suggested by Christoph
c) Added two new syscall sys_lname_to_handle and sys_freadlink to work with
   symlinks
d) Changed open_by_handle to work with all file types
e) Add ext3 support

Changes from V3:
a) Code cleanup suggested by Andreas
b) x86_64 syscall support
c) add compat syscall

Chages from V2:
a) Support system wide unique handle.

Changes from v1:
a) handle size is now specified in bytes
b) returns -EOVERFLOW if the handle size is small
c) dropped open_handle syscall and added open_by_handle_at syscall
   open_by_handle_at takes mount_fd as the directory fd of the mount point
   containing the file
e) handle will only be unique in a given file system. So for an NFS server
   exporting multiple file system, NFS server will have to internally track the
   mount point to which a file handle belongs to. We should be able to do it much
   easily than expecting kernel to give a system wide unique file handle. System
   wide unique file handle would need much larger changes to the exportfs or VFS
   interface and I was not sure whether we really need to do that in the kernel or
   in the user space
f) open_handle_at now only check for DAC_OVERRIDE capability


Example program: (x86_32). (x86_64 would need a different syscall number)
---
CC -D_GNU_SOURCE <source.c>
----
#include <stdio.h>
#include <stdlib.h>

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>

struct uuid {
	unsigned char uuid[16];
};

struct file_handle {
        int handle_size;
        int handle_type;
	struct uuid fsid;
        unsigned char handle[0];
};

#define AT_FDCWD		-100
#define AT_SYMLINK_FOLLOW	0x400

static int name_to_handle(const char *name, struct file_handle  *fh)
{
	return syscall(338, AT_FDCWD, name, fh, AT_SYMLINK_FOLLOW);
}

static int lname_to_handle(const char *name, struct file_handle  *fh)
{
	return syscall(338, AT_FDCWD, name, fh, 0);
}

static int open_by_handle(int mountfd, struct file_handle *fh,  int flags)
{
	return syscall(339, mountfd, fh, flags);
}

#define BUFSZ 100
int main(int argc, char *argv[])
{
        int fd;
        int ret;
	int mountfd;
	int handle_sz;
	struct stat bufstat;
        char buf[BUFSZ];
        struct file_handle *fh = NULL;;
	if (argc != 3 ) {
		printf("Usage: %s <filename> <mount-dir-name>\n", argv[0]);
		exit(1);
	}
again:
	if (fh && fh->handle_size) {
		handle_sz = fh->handle_size;
		free(fh);
		fh = malloc(sizeof(struct file_handle) + handle_sz);
		fh->handle_size = handle_sz;
	} else {
		fh = malloc(sizeof(struct file_handle));
		fh->handle_size = 0;
	}
        errno  = 0;
        ret = lname_to_handle(argv[1], fh);
        if (ret && errno == EOVERFLOW) {
		printf("Found the handle size needed to be %d\n", fh->handle_size);
		goto again;
        } else if (ret) {
                perror("Error:");
		exit(1);
	}
	printf("Waiting for input");
	getchar();
	mountfd = open(argv[2], O_RDONLY | O_DIRECTORY);
	if (mountfd <= 0) {
                perror("Error:");
                exit(1);
        }
        fd = open_by_handle(mountfd, fh, O_RDWR);
        if (fd <= 0 ) {
                perror("Error:");
                exit(1);
        }
	printf("Reading the content now \n");
	fstat(fd, &bufstat);
	ret = S_ISLNK(bufstat.st_mode);
	if (ret) {
		memset(buf, 0 , BUFSZ);
		readlinkat(fd, NULL, buf, BUFSZ);
		printf("%s is a symlink pointing to %s\n", argv[1], buf);
	}
        memset(buf, 0 , BUFSZ);
	while (1) {
		ret = read(fd, buf, BUFSZ -1);
		if (ret <= 0)
			break;
		buf[ret] = '\0';
                printf("%s", buf);
                memset(buf, 0 , BUFSZ);
        }
        return 0;
}

-aneesh


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH -V8 1/9] exportfs: Return the minimum required handle size
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 2/9] vfs: Add name to file handle conversion support Aneesh Kumar K.V
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

The exportfs encode handle function should return the minimum required
handle size. This helps user to find out the handle size by passing 0
handle size in the first step and then redoing to the call again with
the returned handle size value.

Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/btrfs/export.c             |    8 ++++++--
 fs/exportfs/expfs.c           |    9 +++++++--
 fs/fat/inode.c                |    4 +++-
 fs/fuse/inode.c               |    4 +++-
 fs/gfs2/export.c              |    8 ++++++--
 fs/isofs/export.c             |    8 ++++++--
 fs/ocfs2/export.c             |    8 +++++++-
 fs/reiserfs/inode.c           |    7 ++++++-
 fs/udf/namei.c                |    7 ++++++-
 fs/xfs/linux-2.6/xfs_export.c |    4 +++-
 mm/shmem.c                    |    4 +++-
 11 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 951ef09..5f8ee5a 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -21,9 +21,13 @@ static int btrfs_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
 	int len = *max_len;
 	int type;
 
-	if ((len < BTRFS_FID_SIZE_NON_CONNECTABLE) ||
-	    (connectable && len < BTRFS_FID_SIZE_CONNECTABLE))
+	if (connectable && (len < BTRFS_FID_SIZE_CONNECTABLE)) {
+		*max_len = BTRFS_FID_SIZE_CONNECTABLE;
 		return 255;
+	} else if (len < BTRFS_FID_SIZE_NON_CONNECTABLE) {
+		*max_len = BTRFS_FID_SIZE_NON_CONNECTABLE;
+		return 255;
+	}
 
 	len  = BTRFS_FID_SIZE_NON_CONNECTABLE;
 	type = FILEID_BTRFS_WITHOUT_PARENT;
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index e9e1759..cfee0f0 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -319,9 +319,14 @@ static int export_encode_fh(struct dentry *dentry, struct fid *fid,
 	struct inode * inode = dentry->d_inode;
 	int len = *max_len;
 	int type = FILEID_INO32_GEN;
-	
-	if (len < 2 || (connectable && len < 4))
+
+	if (connectable && (len < 4)) {
+		*max_len = 4;
+		return 255;
+	} else if (len < 2) {
+		*max_len = 2;
 		return 255;
+	}
 
 	len = 2;
 	fid->i32.ino = inode->i_ino;
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 0ce143b..6f83bc7 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -738,8 +738,10 @@ fat_encode_fh(struct dentry *de, __u32 *fh, int *lenp, int connectable)
 	struct inode *inode =  de->d_inode;
 	u32 ipos_h, ipos_m, ipos_l;
 
-	if (len < 5)
+	if (len < 5) {
+		*lenp = 5;
 		return 255; /* no room */
+	}
 
 	ipos_h = MSDOS_I(inode)->i_pos >> 8;
 	ipos_m = (MSDOS_I(inode)->i_pos & 0xf0) << 24;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index ec14d19..beaea69 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -638,8 +638,10 @@ static int fuse_encode_fh(struct dentry *dentry, u32 *fh, int *max_len,
 	u64 nodeid;
 	u32 generation;
 
-	if (*max_len < len)
+	if (*max_len < len) {
+		*max_len = len;
 		return  255;
+	}
 
 	nodeid = get_fuse_inode(inode)->nodeid;
 	generation = inode->i_generation;
diff --git a/fs/gfs2/export.c b/fs/gfs2/export.c
index c22c211..d022236 100644
--- a/fs/gfs2/export.c
+++ b/fs/gfs2/export.c
@@ -36,9 +36,13 @@ static int gfs2_encode_fh(struct dentry *dentry, __u32 *p, int *len,
 	struct super_block *sb = inode->i_sb;
 	struct gfs2_inode *ip = GFS2_I(inode);
 
-	if (*len < GFS2_SMALL_FH_SIZE ||
-	    (connectable && *len < GFS2_LARGE_FH_SIZE))
+	if (connectable && (*len < GFS2_LARGE_FH_SIZE)) {
+		*len = GFS2_LARGE_FH_SIZE;
 		return 255;
+	} else if (*len < GFS2_SMALL_FH_SIZE) {
+		*len = GFS2_SMALL_FH_SIZE;
+		return 255;
+	}
 
 	fh[0] = cpu_to_be32(ip->i_no_formal_ino >> 32);
 	fh[1] = cpu_to_be32(ip->i_no_formal_ino & 0xFFFFFFFF);
diff --git a/fs/isofs/export.c b/fs/isofs/export.c
index ed752cb..dd4687f 100644
--- a/fs/isofs/export.c
+++ b/fs/isofs/export.c
@@ -124,9 +124,13 @@ isofs_export_encode_fh(struct dentry *dentry,
 	 * offset of the inode and the upper 16 bits of fh32[1] to
 	 * hold the offset of the parent.
 	 */
-
-	if (len < 3 || (connectable && len < 5))
+	if (connectable && (len < 5)) {
+		*max_len = 5;
+		return 255;
+	} else if (len < 3) {
+		*max_len = 3;
 		return 255;
+	}
 
 	len = 3;
 	fh32[0] = ei->i_iget5_block;
diff --git a/fs/ocfs2/export.c b/fs/ocfs2/export.c
index 19ad145..250a347 100644
--- a/fs/ocfs2/export.c
+++ b/fs/ocfs2/export.c
@@ -201,8 +201,14 @@ static int ocfs2_encode_fh(struct dentry *dentry, u32 *fh_in, int *max_len,
 		   dentry->d_name.len, dentry->d_name.name,
 		   fh, len, connectable);
 
-	if (len < 3 || (connectable && len < 6)) {
+	if (connectable && (len < 6)) {
 		mlog(ML_ERROR, "fh buffer is too small for encoding\n");
+		*max_len = 6;
+		type = 255;
+		goto bail;
+	} else if (len < 3) {
+		mlog(ML_ERROR, "fh buffer is too small for encoding\n");
+		*max_len = 3;
 		type = 255;
 		goto bail;
 	}
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index dc2c65e..5fff1e2 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -1588,8 +1588,13 @@ int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
 	struct inode *inode = dentry->d_inode;
 	int maxlen = *lenp;
 
-	if (maxlen < 3)
+	if (need_parent && (maxlen < 5)) {
+		*lenp = 5;
 		return 255;
+	} else if (maxlen < 3) {
+		*lenp = 3;
+		return 255;
+	}
 
 	data[0] = inode->i_ino;
 	data[1] = le32_to_cpu(INODE_PKEY(inode)->k_dir_id);
diff --git a/fs/udf/namei.c b/fs/udf/namei.c
index 7581602..37ce713 100644
--- a/fs/udf/namei.c
+++ b/fs/udf/namei.c
@@ -1360,8 +1360,13 @@ static int udf_encode_fh(struct dentry *de, __u32 *fh, int *lenp,
 	struct fid *fid = (struct fid *)fh;
 	int type = FILEID_UDF_WITHOUT_PARENT;
 
-	if (len < 3 || (connectable && len < 5))
+	if (connectable && (len < 5)) {
+		*lenp = 5;
+		return 255;
+	} else if (len < 3) {
+		*lenp = 3;
 		return 255;
+	}
 
 	*lenp = 3;
 	fid->udf.block = location.logicalBlockNum;
diff --git a/fs/xfs/linux-2.6/xfs_export.c b/fs/xfs/linux-2.6/xfs_export.c
index 846b75a..82c0553 100644
--- a/fs/xfs/linux-2.6/xfs_export.c
+++ b/fs/xfs/linux-2.6/xfs_export.c
@@ -81,8 +81,10 @@ xfs_fs_encode_fh(
 	 * seven combinations work.  The real answer is "don't use v2".
 	 */
 	len = xfs_fileid_length(fileid_type);
-	if (*max_len < len)
+	if (*max_len < len) {
+		*max_len = len
 		return 255;
+	}
 	*max_len = len;
 
 	switch (fileid_type) {
diff --git a/mm/shmem.c b/mm/shmem.c
index eef4ebe..bbeda1c 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2125,8 +2125,10 @@ static int shmem_encode_fh(struct dentry *dentry, __u32 *fh, int *len,
 {
 	struct inode *inode = dentry->d_inode;
 
-	if (*len < 3)
+	if (*len < 3) {
+		*len = 3;
 		return 255;
+	}
 
 	if (hlist_unhashed(&inode->i_hash)) {
 		/* Unfortunately insert_inode_hash is not idempotent,
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 1/9] exportfs: Return the minimum required handle size Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-18  2:33   ` J. R. Okajima
  2010-05-17  5:33 ` [PATCH -V8 3/9] vfs: Add open by file handle support Aneesh Kumar K.V
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

This patch add a new superblock operations get_fsid that returns the
UUID mapping for the file system. The UUID returned is used to
identify the file system apart of file_handle


Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/open.c          |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |   15 +++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index 74e5cd9..f63550b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -30,6 +30,7 @@
 #include <linux/falloc.h>
 #include <linux/fs_struct.h>
 #include <linux/ima.h>
+#include <linux/exportfs.h>
 
 #include "internal.h"
 
@@ -1206,3 +1207,88 @@ int nonseekable_open(struct inode *inode, struct file *filp)
 }
 
 EXPORT_SYMBOL(nonseekable_open);
+
+/* limit the handle size to some value */
+#define MAX_HANDLE_SZ 4096
+static long do_sys_name_to_handle(struct path *path,
+			struct file_handle __user *ufh)
+{
+	int retval;
+	int handle_size;
+	struct super_block *sb;
+	struct uuid this_fs_id;
+	struct file_handle f_handle;
+	struct file_handle *handle = NULL;
+
+	if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
+		retval = -EFAULT;
+		goto err_out;
+	}
+	if (f_handle.handle_size > MAX_HANDLE_SZ) {
+		retval = -EINVAL;
+		goto err_out;
+	}
+	handle = kzalloc(sizeof(struct file_handle) + f_handle.handle_size,
+			GFP_KERNEL);
+	if (!handle) {
+		retval = -ENOMEM;
+		goto err_out;
+	}
+	handle_size = f_handle.handle_size;
+
+	/* we ask for a non connected handle */
+	retval = exportfs_encode_fh(path->dentry,
+				(struct fid *)handle->f_handle,
+				&handle_size,  0);
+	/* convert handle size to bytes */
+	handle_size *= sizeof(u32);
+	handle->handle_type = retval;
+	handle->handle_size = handle_size;
+	if (handle_size <= f_handle.handle_size) {
+		/* get the uuid */
+		sb = path->mnt->mnt_sb;
+		if (sb->s_op->get_fsid) {
+			retval = sb->s_op->get_fsid(sb, &this_fs_id);
+			if (!retval)
+				memcpy(handle->fsid.uuid,
+					this_fs_id.uuid,
+					sizeof(handle->fsid.uuid));
+		}
+	} else {
+		/*
+		 * set the handle_size to zero so we copy only
+		 * non variable part of the file_handle
+		 */
+		handle_size = 0;
+		retval = -EOVERFLOW;
+	}
+	if (copy_to_user(ufh, handle,
+				sizeof(struct file_handle) + handle_size))
+		retval = -EFAULT;
+
+	kfree(handle);
+err_out:
+	return retval;
+}
+
+SYSCALL_DEFINE4(name_to_handle_at, int, dfd, const char __user *, name,
+		struct file_handle __user *, handle, int, flag)
+{
+	int follow;
+	long ret = -EINVAL;
+	struct path path;
+
+	if ((flag & ~AT_SYMLINK_FOLLOW) != 0)
+		goto err_out;
+
+	follow = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0;
+	ret = user_path_at(dfd, name, follow, &path);
+	if (ret)
+		goto err_out;
+	ret = do_sys_name_to_handle(&path, handle);
+	path_put(&path);
+err_out:
+	/* avoid REGPARM breakage on x86: */
+	asmlinkage_protect(4, ret, dfd, name, handle, flag);
+	return ret;
+}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 44f35ae..055734c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -948,6 +948,20 @@ struct file {
 	unsigned long f_mnt_write_state;
 #endif
 };
+
+struct uuid {
+	unsigned char uuid[16];
+};
+
+struct file_handle {
+	int handle_size;
+	int handle_type;
+	/* File system identifier */
+	struct uuid fsid;
+	/* file identifier */
+	unsigned char f_handle[0];
+};
+
 extern spinlock_t files_lock;
 #define file_list_lock() spin_lock(&files_lock);
 #define file_list_unlock() spin_unlock(&files_lock);
@@ -1580,6 +1594,7 @@ struct super_operations {
 	ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
 #endif
 	int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
+	int (*get_fsid)(struct super_block *, struct uuid *);
 };
 
 /*
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 3/9] vfs: Add open by file handle support
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 1/9] exportfs: Return the minimum required handle size Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 2/9] vfs: Add name to file handle conversion support Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 4/9] vfs: Allow handle based open on symlinks Aneesh Kumar K.V
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/namei.c         |   50 +++++++++++++++
 fs/open.c          |  171 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |    3 +-
 3 files changed, 223 insertions(+), 1 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index a7dce91..1fe4ee9 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1556,6 +1556,56 @@ static int open_will_truncate(int flag, struct inode *inode)
 	return (flag & O_TRUNC);
 }
 
+struct file *finish_open_handle(struct path *path,
+			int open_flag, int acc_mode)
+{
+	int error;
+	struct file *filp;
+	int will_truncate;
+
+	will_truncate = open_will_truncate(open_flag, path->dentry->d_inode);
+	if (will_truncate) {
+		error = mnt_want_write(path->mnt);
+		if (error)
+			goto exit;
+	}
+	error = may_open(path, acc_mode, open_flag);
+	if (error) {
+		if (will_truncate)
+			mnt_drop_write(path->mnt);
+		goto exit;
+	}
+	filp = dentry_open(path->dentry, path->mnt, open_flag, current_cred());
+	if (!IS_ERR(filp)) {
+		error = ima_file_check(filp, acc_mode);
+		if (error) {
+			fput(filp);
+			filp = ERR_PTR(error);
+		}
+	}
+	if (!IS_ERR(filp)) {
+		if (will_truncate) {
+			error = handle_truncate(path);
+			if (error) {
+				fput(filp);
+				filp = ERR_PTR(error);
+			}
+		}
+	}
+	/*
+	 * It is now safe to drop the mnt write
+	 * because the filp has had a write taken
+	 * on its behalf.
+	 */
+	if (will_truncate)
+		mnt_drop_write(path->mnt);
+	return filp;
+
+exit:
+	path_put(path);
+	return ERR_PTR(error);
+}
+
 static struct file *finish_open(struct nameidata *nd,
 				int open_flag, int acc_mode)
 {
diff --git a/fs/open.c b/fs/open.c
index f63550b..0bd49b3 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1292,3 +1292,174 @@ err_out:
 	asmlinkage_protect(4, ret, dfd, name, handle, flag);
 	return ret;
 }
+
+static struct vfsmount *get_vfsmount_from_fd(int fd)
+{
+	int fput_needed;
+	struct path *path;
+	struct file *filep;
+
+	if (fd == AT_FDCWD) {
+		struct fs_struct *fs = current->fs;
+		read_lock(&fs->lock);
+		path = &fs->pwd;
+		mntget(path->mnt);
+		read_unlock(&fs->lock);
+	} else {
+		filep = fget_light(fd, &fput_needed);
+		if (!filep)
+			return ERR_PTR(-EBADF);
+		path = &filep->f_path;
+		mntget(path->mnt);
+		fput_light(filep, fput_needed);
+	}
+	return path->mnt;
+}
+
+static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
+{
+	return 1;
+}
+
+static struct path *handle_to_path(int mountdirfd, struct file_handle *handle)
+{
+	int retval;
+	int handle_size;
+	struct path *path;
+
+	path = kmalloc(sizeof(struct path), GFP_KERNEL);
+	if (!path)
+		return ERR_PTR(-ENOMEM);
+
+	path->mnt = get_vfsmount_from_fd(mountdirfd);
+	if (IS_ERR(path->mnt)) {
+		retval = PTR_ERR(path->mnt);
+		goto out_err;
+	}
+	/* change the handle size to multiple of sizeof(u32) */
+	handle_size = handle->handle_size >> 2;
+	path->dentry = exportfs_decode_fh(path->mnt,
+					(struct fid *)handle->f_handle,
+					handle_size, handle->handle_type,
+					vfs_dentry_acceptable, NULL);
+	if (IS_ERR(path->dentry)) {
+		retval = PTR_ERR(path->dentry);
+		goto out_mnt;
+	}
+	return path;
+out_mnt:
+	mntput(path->mnt);
+out_err:
+	kfree(path);
+	return ERR_PTR(retval);
+}
+
+static long do_sys_open_by_handle(int mountdirfd,
+				struct file_handle __user *ufh, int open_flag)
+{
+	int acc_mode;
+	int fd, retval = 0;
+	struct file *filp;
+	struct path *path;
+	struct file_handle f_handle;
+	struct file_handle *handle = NULL;
+
+	/* can't use O_CREATE with open_by_handle */
+	if (open_flag & O_CREAT) {
+		retval = -EINVAL;
+		goto out_err;
+	}
+	if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
+		retval = -EFAULT;
+		goto out_err;
+	}
+	if ((f_handle.handle_size > MAX_HANDLE_SZ) ||
+		(f_handle.handle_size <= 0)) {
+		retval =  -EINVAL;
+		goto out_err;
+	}
+	if (!capable(CAP_DAC_OVERRIDE)) {
+		retval = -EPERM;
+		goto out_err;
+	}
+	handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_size,
+			GFP_KERNEL);
+	if (!handle) {
+		retval =  -ENOMEM;
+		goto out_err;
+	}
+	/* copy the full handle */
+	if (copy_from_user(handle, ufh,
+				sizeof(struct file_handle) +
+				f_handle.handle_size)) {
+		retval = -EFAULT;
+		goto out_handle;
+	}
+	path = handle_to_path(mountdirfd, handle);
+	if (IS_ERR(path)) {
+		retval = PTR_ERR(path);
+		goto out_handle;
+	}
+	/*
+	 * O_SYNC is implemented as __O_SYNC|O_DSYNC.  As many places only
+	 * check for O_DSYNC if the need any syncing at all we enforce it's
+	 * always set instead of having to deal with possibly weird behaviour
+	 * for malicious applications setting only __O_SYNC.
+	 */
+	if (open_flag & __O_SYNC)
+		open_flag |= O_DSYNC;
+
+	acc_mode = MAY_OPEN | ACC_MODE(open_flag);
+
+	/* O_TRUNC implies we need access checks for write permissions */
+	if (open_flag & O_TRUNC)
+		acc_mode |= MAY_WRITE;
+	/*
+	 * Allow the LSM permission hook to distinguish append
+	 * access from general write access.
+	 */
+	if (open_flag & O_APPEND)
+		acc_mode |= MAY_APPEND;
+
+	fd = get_unused_fd_flags(open_flag);
+	if (fd < 0) {
+		retval = fd;
+		goto out_path;
+	}
+	filp = finish_open_handle(path, open_flag, acc_mode);
+	if (IS_ERR(filp)) {
+		put_unused_fd(fd);
+		retval =  PTR_ERR(filp);
+	} else {
+		retval = fd;
+		fsnotify_open(filp->f_path.dentry);
+		fd_install(fd, filp);
+	}
+	kfree(path);
+	kfree(handle);
+	return retval;
+
+out_path:
+	path_put(path);
+	kfree(path);
+out_handle:
+	kfree(handle);
+out_err:
+	return retval;
+}
+
+SYSCALL_DEFINE3(open_by_handle, int, mountdirfd,
+		struct file_handle __user *, handle,
+		int, flags)
+{
+	long ret;
+
+	if (force_o_largefile())
+		flags |= O_LARGEFILE;
+
+	ret = do_sys_open_by_handle(mountdirfd, handle, flags);
+
+	/* avoid REGPARM breakage on x86: */
+	asmlinkage_protect(3, ret, mountdirfd, handle, flags);
+	return ret;
+}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 055734c..c73e1a0 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2144,7 +2144,8 @@ extern int may_open(struct path *, int, int);
 
 extern int kernel_read(struct file *, loff_t, char *, unsigned long);
 extern struct file * open_exec(const char *);
- 
+extern struct file *finish_open_handle(struct path *, int, int);
+
 /* fs/dcache.c -- generic fs support functions */
 extern int is_subdir(struct dentry *, struct dentry *);
 extern int path_is_under(struct path *, struct path *);
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 4/9] vfs: Allow handle based open on symlinks
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (2 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 3/9] vfs: Add open by file handle support Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 5/9] vfs: Support null pathname in readlink Aneesh Kumar K.V
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

The patch update may_open to allow handle based open on symlinks.
The file handle based API use file descritor returned from open_by_handle_at
to do different file system operations. To find the link target name we
need to get a file descriptor on symlinks.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/namei.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 1fe4ee9..6edb9af 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1421,7 +1421,7 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
 	return error;
 }
 
-int may_open(struct path *path, int acc_mode, int flag)
+static int __may_open(struct path *path, int acc_mode, int flag, int handle)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -1432,7 +1432,13 @@ int may_open(struct path *path, int acc_mode, int flag)
 
 	switch (inode->i_mode & S_IFMT) {
 	case S_IFLNK:
-		return -ELOOP;
+		/*
+		 * For file handle based open we should allow
+		 * open of symlink.
+		 */
+		if (!handle)
+			return -ELOOP;
+		break;
 	case S_IFDIR:
 		if (acc_mode & MAY_WRITE)
 			return -EISDIR;
@@ -1472,6 +1478,11 @@ int may_open(struct path *path, int acc_mode, int flag)
 	return break_lease(inode, flag);
 }
 
+int may_open(struct path *path, int acc_mode, int flag)
+{
+	return __may_open(path, acc_mode, flag, 0);
+}
+
 static int handle_truncate(struct path *path)
 {
 	struct inode *inode = path->dentry->d_inode;
@@ -1569,7 +1580,7 @@ struct file *finish_open_handle(struct path *path,
 		if (error)
 			goto exit;
 	}
-	error = may_open(path, acc_mode, open_flag);
+	error = __may_open(path, acc_mode, open_flag, 1);
 	if (error) {
 		if (will_truncate)
 			mnt_drop_write(path->mnt);
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 5/9] vfs: Support null pathname in readlink
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (3 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 4/9] vfs: Allow handle based open on symlinks Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 6/9] ext4: Add get_fsid callback Aneesh Kumar K.V
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

From: NeilBrown <neilb@suse.de>

This enables to use readlink to get the link target name
from a file descriptor point to the link. This can be used
with open_by_handle syscall that returns a file descriptor for a link.
We can then use this file descriptor to get the target name.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/stat.c |   30 ++++++++++++++++++++++--------
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/fs/stat.c b/fs/stat.c
index c4ecd52..49b95a7 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -284,26 +284,40 @@ SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf)
 SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,
 		char __user *, buf, int, bufsiz)
 {
-	struct path path;
-	int error;
+	int error = 0;
+	struct path path, *pp;
+	struct file *file = NULL;
 
 	if (bufsiz <= 0)
 		return -EINVAL;
 
-	error = user_path_at(dfd, pathname, 0, &path);
+	if (pathname == NULL && dfd != AT_FDCWD) {
+		file = fget(dfd);
+
+		if (file)
+			pp = &file->f_path;
+		else
+			error = -EBADF;
+	} else {
+		error = user_path_at(dfd, pathname, 0, &path);
+		pp = &path;
+	}
 	if (!error) {
-		struct inode *inode = path.dentry->d_inode;
+		struct inode *inode = pp->dentry->d_inode;
 
 		error = -EINVAL;
 		if (inode->i_op->readlink) {
-			error = security_inode_readlink(path.dentry);
+			error = security_inode_readlink(pp->dentry);
 			if (!error) {
-				touch_atime(path.mnt, path.dentry);
-				error = inode->i_op->readlink(path.dentry,
+				touch_atime(pp->mnt, pp->dentry);
+				error = inode->i_op->readlink(pp->dentry,
 							      buf, bufsiz);
 			}
 		}
-		path_put(&path);
+		if (file)
+			fput(file);
+		else
+			path_put(&path);
 	}
 	return error;
 }
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 6/9] ext4: Add get_fsid callback
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (4 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 5/9] vfs: Support null pathname in readlink Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 7/9] x86: Add new syscalls for x86_32 Aneesh Kumar K.V
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/ext4/super.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e14d22c..fc7d464 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1049,6 +1049,19 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
 	return try_to_free_buffers(page);
 }
 
+static int ext4_get_fsid(struct super_block *sb, struct uuid *fsid)
+{
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
+	struct ext4_super_block *es = sbi->s_es;
+
+	memcpy(fsid->uuid, es->s_uuid, sizeof(fsid->uuid));
+	/*
+	 * We may want to make sure we return error if the s_uuid is not
+	 * exactly unique
+	 */
+	return 0;
+}
+
 #ifdef CONFIG_QUOTA
 #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
 #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
@@ -1109,6 +1122,7 @@ static const struct super_operations ext4_sops = {
 	.quota_write	= ext4_quota_write,
 #endif
 	.bdev_try_to_free_page = bdev_try_to_free_page,
+	.get_fsid	= ext4_get_fsid,
 };
 
 static const struct super_operations ext4_nojournal_sops = {
@@ -1128,6 +1142,7 @@ static const struct super_operations ext4_nojournal_sops = {
 	.quota_write	= ext4_quota_write,
 #endif
 	.bdev_try_to_free_page = bdev_try_to_free_page,
+	.get_fsid	= ext4_get_fsid,
 };
 
 static const struct export_operations ext4_export_ops = {
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 7/9] x86: Add new syscalls for x86_32
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (5 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 6/9] ext4: Add get_fsid callback Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 8/9] x86: Add new syscalls for x86_64 Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 9/9] ext3: Add get_fsid callback Aneesh Kumar K.V
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

This patch adds sys_name_to_handle_at and sys_open_by_handle_at
syscalls to x86_32

Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 arch/x86/include/asm/unistd_32.h   |    4 +++-
 arch/x86/kernel/syscall_table_32.S |    2 ++
 2 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/unistd_32.h b/arch/x86/include/asm/unistd_32.h
index beb9b5f..ca792fb 100644
--- a/arch/x86/include/asm/unistd_32.h
+++ b/arch/x86/include/asm/unistd_32.h
@@ -343,10 +343,12 @@
 #define __NR_rt_tgsigqueueinfo	335
 #define __NR_perf_event_open	336
 #define __NR_recvmmsg		337
+#define __NR_name_to_handle_at	338
+#define __NR_open_by_handle     339
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 338
+#define NR_syscalls 340
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
index 8b37293..399b49e 100644
--- a/arch/x86/kernel/syscall_table_32.S
+++ b/arch/x86/kernel/syscall_table_32.S
@@ -337,3 +337,5 @@ ENTRY(sys_call_table)
 	.long sys_rt_tgsigqueueinfo	/* 335 */
 	.long sys_perf_event_open
 	.long sys_recvmmsg
+	.long sys_name_to_handle_at
+	.long sys_open_by_handle	/* 339 */
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 8/9] x86: Add new syscalls for x86_64
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (6 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 7/9] x86: Add new syscalls for x86_32 Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  2010-05-17  5:33 ` [PATCH -V8 9/9] ext3: Add get_fsid callback Aneesh Kumar K.V
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

Add sys_name_to_handle_at and sys_open_by_handle_at syscalls
for x86_64

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 arch/x86/ia32/ia32entry.S        |    2 ++
 arch/x86/include/asm/unistd_64.h |    4 ++++
 fs/compat.c                      |   11 +++++++++++
 fs/open.c                        |    4 ++--
 include/linux/fs.h               |    1 +
 5 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index e790bc1..74552bc 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -842,4 +842,6 @@ ia32_sys_call_table:
 	.quad compat_sys_rt_tgsigqueueinfo	/* 335 */
 	.quad sys_perf_event_open
 	.quad compat_sys_recvmmsg
+	.quad sys_name_to_handle_at
+	.quad compat_sys_open_by_handle		/* 339 */
 ia32_syscall_end:
diff --git a/arch/x86/include/asm/unistd_64.h b/arch/x86/include/asm/unistd_64.h
index ff4307b..a5c3622 100644
--- a/arch/x86/include/asm/unistd_64.h
+++ b/arch/x86/include/asm/unistd_64.h
@@ -663,6 +663,10 @@ __SYSCALL(__NR_rt_tgsigqueueinfo, sys_rt_tgsigqueueinfo)
 __SYSCALL(__NR_perf_event_open, sys_perf_event_open)
 #define __NR_recvmmsg				299
 __SYSCALL(__NR_recvmmsg, sys_recvmmsg)
+#define __NR_name_to_handle_at			300
+__SYSCALL(__NR_name_to_handle, sys_name_to_handle)
+#define __NR_open_by_handle			301
+__SYSCALL(__NR_open_by_handle, sys_open_by_handle)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
diff --git a/fs/compat.c b/fs/compat.c
index 4b6ed03..5e2f191 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -2310,3 +2310,14 @@ asmlinkage long compat_sys_timerfd_gettime(int ufd,
 }
 
 #endif /* CONFIG_TIMERFD */
+
+/*
+ * Exactly like fs/open.c:sys_open_by_handle_at(), except that it
+ * doesn't set the O_LARGEFILE flag.
+ */
+asmlinkage long
+compat_sys_open_by_handle(int mountdirfd,
+			struct file_handle __user *handle, int flags)
+{
+	return do_sys_open_by_handle(mountdirfd, handle, flags);
+}
diff --git a/fs/open.c b/fs/open.c
index 0bd49b3..b21f4e6 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1354,8 +1354,8 @@ out_err:
 	return ERR_PTR(retval);
 }
 
-static long do_sys_open_by_handle(int mountdirfd,
-				struct file_handle __user *ufh, int open_flag)
+long do_sys_open_by_handle(int mountdirfd,
+			struct file_handle __user *ufh, int open_flag)
 {
 	int acc_mode;
 	int fd, retval = 0;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c73e1a0..2f63a17 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1933,6 +1933,7 @@ extern struct file * dentry_open(struct dentry *, struct vfsmount *, int,
 				 const struct cred *);
 extern int filp_close(struct file *, fl_owner_t id);
 extern char * getname(const char __user *);
+extern long do_sys_open_by_handle(int, struct file_handle __user *, int);
 
 /* fs/ioctl.c */
 
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH -V8 9/9] ext3: Add get_fsid callback
  2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
                   ` (7 preceding siblings ...)
  2010-05-17  5:33 ` [PATCH -V8 8/9] x86: Add new syscalls for x86_64 Aneesh Kumar K.V
@ 2010-05-17  5:33 ` Aneesh Kumar K.V
  8 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2010-05-17  5:33 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue, neilb
  Cc: linux-fsdevel, sfrench, philippe.deniel, linux-kernel, Aneesh Kumar K.V

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/ext3/super.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 1bee604..63c322e 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -734,6 +734,15 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
 	return try_to_free_buffers(page);
 }
 
+static int ext3_get_fsid(struct super_block *sb, struct uuid *fsid)
+{
+	struct ext3_sb_info *sbi = EXT3_SB(sb);
+	struct ext3_super_block *es = sbi->s_es;
+
+	memcpy(fsid->uuid, es->s_uuid, sizeof(fsid->uuid));
+	return 0;
+}
+
 #ifdef CONFIG_QUOTA
 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
 #define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
@@ -791,6 +800,7 @@ static const struct super_operations ext3_sops = {
 	.quota_write	= ext3_quota_write,
 #endif
 	.bdev_try_to_free_page = bdev_try_to_free_page,
+	.get_fsid	= ext3_get_fsid,
 };
 
 static const struct export_operations ext3_export_ops = {
-- 
1.7.1.78.g212f0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-17  5:33 ` [PATCH -V8 2/9] vfs: Add name to file handle conversion support Aneesh Kumar K.V
@ 2010-05-18  2:33   ` J. R. Okajima
  2010-05-18  5:40     ` Aneesh Kumar K. V
  0 siblings, 1 reply; 20+ messages in thread
From: J. R. Okajima @ 2010-05-18  2:33 UTC (permalink / raw)
  To: Aneesh Kumar K.V
  Cc: hch, viro, adilger, corbet, serue, neilb, linux-fsdevel, sfrench,
	philippe.deniel, linux-kernel


"Aneesh Kumar K.V":
> This patch add a new superblock operations get_fsid that returns the
> UUID mapping for the file system. The UUID returned is used to
> identify the file system apart of file_handle

I am afraid get_fsid in s_op may conflict with "fsid=" option in /etc/exports.
Generally all FSs have UUID or device number and they can return "fsid"
correctly. But some of them may not have such id, or users may assign
different fsid for them.
Is "fsid=" value passed to superblock and can FS return it? Otherwise
they cannot implement ->get_fsid().


J. R. Okajima

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18  2:33   ` J. R. Okajima
@ 2010-05-18  5:40     ` Aneesh Kumar K. V
  2010-05-18  6:18       ` J. R. Okajima
  2010-05-18  6:43       ` Dave Chinner
  0 siblings, 2 replies; 20+ messages in thread
From: Aneesh Kumar K. V @ 2010-05-18  5:40 UTC (permalink / raw)
  To: J. R. Okajima
  Cc: hch, viro, adilger, corbet, serue, neilb, linux-fsdevel, sfrench,
	philippe.deniel, linux-kernel

On Tue, 18 May 2010 11:33:50 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> 
> "Aneesh Kumar K.V":
> > This patch add a new superblock operations get_fsid that returns the
> > UUID mapping for the file system. The UUID returned is used to
> > identify the file system apart of file_handle
> 
> I am afraid get_fsid in s_op may conflict with "fsid=" option in /etc/exports.
> Generally all FSs have UUID or device number and they can return "fsid"
> correctly. But some of them may not have such id, or users may assign
> different fsid for them.
> Is "fsid=" value passed to superblock and can FS return it? Otherwise
> they cannot implement ->get_fsid().

The file_handle I mentioned above is the file handle returned by
sys_name_to_handle_at syscall. NFS kernel server won't be using the
interface.

If file system doesn't support a unique identifier then they can leave
->get_fsid callback NULL. The UUID part of the file_handle will be zero
filled. For a NFS userspace server, the server can update handle.fsid with
what ever value is configured for fsid. The only requirement is later
when provided with the same handle NFS server should be able to map the
handle.fsid to a mountdirfd which can be used with sys_open_by_handle_at.

-aneesh

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18  5:40     ` Aneesh Kumar K. V
@ 2010-05-18  6:18       ` J. R. Okajima
  2010-05-18  6:58         ` Aneesh Kumar K. V
  2010-05-18  6:43       ` Dave Chinner
  1 sibling, 1 reply; 20+ messages in thread
From: J. R. Okajima @ 2010-05-18  6:18 UTC (permalink / raw)
  To: Aneesh Kumar K. V
  Cc: hch, viro, adilger, corbet, serue, neilb, linux-fsdevel, sfrench,
	philippe.deniel, linux-kernel


"Aneesh Kumar K. V":
> The file_handle I mentioned above is the file handle returned by
> sys_name_to_handle_at syscall. NFS kernel server won't be using the
> interface.

Thanx clarifying.
I think I should read the notes in the first description (0/9) before
posting.
It says UUID is just for userspace.

Reading all 9 patches, I noticed handle_to_path() calls
exportfs_decode_fh() inconditionally.
Since exportfs_decode_fh() calls s_export_op->fh_to_dentry()
inconditionally too, handle_to_path() will crash when the target FS
doesn't support NFS-exporting, won't it?


J. R. Okajima

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18  5:40     ` Aneesh Kumar K. V
  2010-05-18  6:18       ` J. R. Okajima
@ 2010-05-18  6:43       ` Dave Chinner
  2010-05-18 10:17         ` Aneesh Kumar K. V
  1 sibling, 1 reply; 20+ messages in thread
From: Dave Chinner @ 2010-05-18  6:43 UTC (permalink / raw)
  To: Aneesh Kumar K. V
  Cc: J. R. Okajima, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel

On Tue, May 18, 2010 at 11:10:38AM +0530, Aneesh Kumar K. V wrote:
> On Tue, 18 May 2010 11:33:50 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> > 
> > "Aneesh Kumar K.V":
> > > This patch add a new superblock operations get_fsid that returns the
> > > UUID mapping for the file system. The UUID returned is used to
> > > identify the file system apart of file_handle
> > 
> > I am afraid get_fsid in s_op may conflict with "fsid=" option in /etc/exports.
> > Generally all FSs have UUID or device number and they can return "fsid"
> > correctly. But some of them may not have such id, or users may assign
> > different fsid for them.
> > Is "fsid=" value passed to superblock and can FS return it? Otherwise
> > they cannot implement ->get_fsid().
> 
> The file_handle I mentioned above is the file handle returned by
> sys_name_to_handle_at syscall. NFS kernel server won't be using the
> interface.
> 
> If file system doesn't support a unique identifier then they can leave
> ->get_fsid callback NULL. The UUID part of the file_handle will be zero
> filled.

If it is returning a UUID, then perhaps the call should be
->get_uuid to avoid any confusion with existing uses of "fsid".

Alternatively, why do we even need a method for this? Why not just put a
struct uuid into the struct super_block and have filesystems fill it
out inside their fill_super callback to get_sb()? If it is not
filled out, then it is zero, and the code that puts it into the file
handle can just do an unconditional copy at that point...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18  6:18       ` J. R. Okajima
@ 2010-05-18  6:58         ` Aneesh Kumar K. V
  0 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K. V @ 2010-05-18  6:58 UTC (permalink / raw)
  To: J. R. Okajima
  Cc: hch, viro, adilger, corbet, serue, neilb, linux-fsdevel, sfrench,
	philippe.deniel, linux-kernel

On Tue, 18 May 2010 15:18:28 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> 
> "Aneesh Kumar K. V":
> > The file_handle I mentioned above is the file handle returned by
> > sys_name_to_handle_at syscall. NFS kernel server won't be using the
> > interface.
> 
> Thanx clarifying.
> I think I should read the notes in the first description (0/9) before
> posting.
> It says UUID is just for userspace.
> 
> Reading all 9 patches, I noticed handle_to_path() calls
> exportfs_decode_fh() inconditionally.
> Since exportfs_decode_fh() calls s_export_op->fh_to_dentry()
> inconditionally too, handle_to_path() will crash when the target FS
> doesn't support NFS-exporting, won't it?
> 

I guess we should fix exprtfs_decode_fh to return -ESTALE if
fh_to_dentry is NULL

-aneesh

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18  6:43       ` Dave Chinner
@ 2010-05-18 10:17         ` Aneesh Kumar K. V
  2010-05-19  7:15           ` J. R. Okajima
  0 siblings, 1 reply; 20+ messages in thread
From: Aneesh Kumar K. V @ 2010-05-18 10:17 UTC (permalink / raw)
  To: Dave Chinner
  Cc: J. R. Okajima, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel

On Tue, 18 May 2010 16:43:36 +1000, Dave Chinner <david@fromorbit.com> wrote:
> On Tue, May 18, 2010 at 11:10:38AM +0530, Aneesh Kumar K. V wrote:
> > On Tue, 18 May 2010 11:33:50 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> > > 
> > > "Aneesh Kumar K.V":
> > > > This patch add a new superblock operations get_fsid that returns the
> > > > UUID mapping for the file system. The UUID returned is used to
> > > > identify the file system apart of file_handle
> > > 
> > > I am afraid get_fsid in s_op may conflict with "fsid=" option in /etc/exports.
> > > Generally all FSs have UUID or device number and they can return "fsid"
> > > correctly. But some of them may not have such id, or users may assign
> > > different fsid for them.
> > > Is "fsid=" value passed to superblock and can FS return it? Otherwise
> > > they cannot implement ->get_fsid().
> > 
> > The file_handle I mentioned above is the file handle returned by
> > sys_name_to_handle_at syscall. NFS kernel server won't be using the
> > interface.
> > 
> > If file system doesn't support a unique identifier then they can leave
> > ->get_fsid callback NULL. The UUID part of the file_handle will be zero
> > filled.
> 
> If it is returning a UUID, then perhaps the call should be
> ->get_uuid to avoid any confusion with existing uses of "fsid".
> 
> Alternatively, why do we even need a method for this? Why not just put a
> struct uuid into the struct super_block and have filesystems fill it
> out inside their fill_super callback to get_sb()? If it is not
> filled out, then it is zero, and the code that puts it into the file
> handle can just do an unconditional copy at that point...
> 

Now that we are not doing UUID based vfsmount lookup this make
sense. Will update in the next iteration with UUID to be part of
super_block.

-aneesh

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-18 10:17         ` Aneesh Kumar K. V
@ 2010-05-19  7:15           ` J. R. Okajima
  2010-05-19  8:52             ` Aneesh Kumar K. V
  0 siblings, 1 reply; 20+ messages in thread
From: J. R. Okajima @ 2010-05-19  7:15 UTC (permalink / raw)
  To: Aneesh Kumar K. V
  Cc: Dave Chinner, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel


"Aneesh Kumar K. V":
> Now that we are not doing UUID based vfsmount lookup this make
> sense. Will update in the next iteration with UUID to be part of
> super_block.

Because this UUID is just for some FS's userspace helpers (in other
words, returning UUID is FS specific behaviour), I am afraid it is not a
good ideat to put the array into generic super_block.

About the design or approach, this might have been discussed earlier,
but I'd like to suggest to clarify some points here.
- While these new systemcalls provide generic features, the
  implementation depends upon s_export_op, ie. NFS-exporting.
  It means there are two requirements for these systemcalls, enabling
  CONFIG_EXPORTFS and FS has to set s_export_op.
  Is this acceptable?

- exportfs_encode_fh() supports the default encoding
  export_encode_fh(), but exportfs_decode_fh() doesn't.
  The latest patch series modifes exportfs_decode_fh() to return ESTALE,
  but I'd suggest to make the caller of export_encode_fh() to check
  s_export_op->fh_to_dentry() and return ENOSYS.
  Or implement the default decode routine as a contrast of
  export_encode_fh().

- Some FS (or its userspace helper) may want to put UUID into the
  handle. If those FS already have UUID in their fs private_data, then
  putting a pointer (instead of an array) is better.
  Or creating two new operations in s_op to encode/decode handle
  may be good too (regardless CONFIG_EXPORTFS). The generic
  implementations should be provided, and when these function pointers
  in s_op are not set, they should be called as default. These generic
  implementaions will be able to be used by expfs.c too. And UUID in
  super_block will be unnecessary.

If my English is broken and hard to understand, please let me know.


J. R. Okajima

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-19  7:15           ` J. R. Okajima
@ 2010-05-19  8:52             ` Aneesh Kumar K. V
  2010-05-19  9:26               ` Aneesh Kumar K. V
  0 siblings, 1 reply; 20+ messages in thread
From: Aneesh Kumar K. V @ 2010-05-19  8:52 UTC (permalink / raw)
  To: J. R. Okajima
  Cc: Dave Chinner, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel

On Wed, 19 May 2010 16:15:51 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> 
> "Aneesh Kumar K. V":
> > Now that we are not doing UUID based vfsmount lookup this make
> > sense. Will update in the next iteration with UUID to be part of
> > super_block.
> 
> Because this UUID is just for some FS's userspace helpers (in other
> words, returning UUID is FS specific behaviour), I am afraid it is not a
> good ideat to put the array into generic super_block.

UUID should be looked at as the file system identifier and IMHO struct
super_block is the right place to hold it. For ex: ext*  put then in
ext*_super_block. File system that doesn't support UUID can leave the
superblock field zero filled.


> 
> About the design or approach, this might have been discussed earlier,
> but I'd like to suggest to clarify some points here.
> - While these new systemcalls provide generic features, the
>   implementation depends upon s_export_op, ie. NFS-exporting.
>   It means there are two requirements for these systemcalls, enabling
>   CONFIG_EXPORTFS and FS has to set s_export_op.
>   Is this acceptable?


I think exportfs is the right interface we want to depend on for
generating a handle. We should not be having another parallel interface for file
handle generation. But agreed that we should return -EOPNOTSUPP in case
EXPORTFS is disabled.


> 
> - exportfs_encode_fh() supports the default encoding
>   export_encode_fh(), but exportfs_decode_fh() doesn't.
>   The latest patch series modifes exportfs_decode_fh() to return ESTALE,
>   but I'd suggest to make the caller of export_encode_fh() to check
>   s_export_op->fh_to_dentry() and return ENOSYS.

I will fix to make the syscall return EOPNOTSUPP in case fh_to_dentry is
not supported. But i guess we still need to keep the change in
exportfs_decode_fh to return -ESTALE in case these operations are not definied.



>   Or implement the default decode routine as a contrast of
>   export_encode_fh().
> 
> - Some FS (or its userspace helper) may want to put UUID into the
>   handle. If those FS already have UUID in their fs private_data, then
>   putting a pointer (instead of an array) is better.
>   Or creating two new operations in s_op to encode/decode handle
>   may be good too (regardless CONFIG_EXPORTFS). The generic
>   implementations should be provided, and when these function pointers
>   in s_op are not set, they should be called as default. These generic
>   implementaions will be able to be used by expfs.c too. And UUID in
>   super_block will be unnecessary.


IMHO that would be over design. We can depend on exportfs
interfaces and if not defined return EOPNOTSUPP.

-aneesh

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-19  8:52             ` Aneesh Kumar K. V
@ 2010-05-19  9:26               ` Aneesh Kumar K. V
  2010-05-19 13:50                 ` J. R. Okajima
  0 siblings, 1 reply; 20+ messages in thread
From: Aneesh Kumar K. V @ 2010-05-19  9:26 UTC (permalink / raw)
  To: J. R. Okajima
  Cc: Dave Chinner, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel

On Wed, 19 May 2010 14:22:22 +0530, "Aneesh Kumar K. V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> On Wed, 19 May 2010 16:15:51 +0900, "J. R. Okajima" <hooanon05@yahoo.co.jp> wrote:
> > 
> > "Aneesh Kumar K. V":
> > > Now that we are not doing UUID based vfsmount lookup this make
> > > sense. Will update in the next iteration with UUID to be part of
> > > super_block.
> > 
> > Because this UUID is just for some FS's userspace helpers (in other
> > words, returning UUID is FS specific behaviour), I am afraid it is not a
> > good ideat to put the array into generic super_block.
> 
> UUID should be looked at as the file system identifier and IMHO struct
> super_block is the right place to hold it. For ex: ext*  put then in
> ext*_super_block. File system that doesn't support UUID can leave the
> superblock field zero filled.
> 
> 
> > 
> > About the design or approach, this might have been discussed earlier,
> > but I'd like to suggest to clarify some points here.
> > - While these new systemcalls provide generic features, the
> >   implementation depends upon s_export_op, ie. NFS-exporting.
> >   It means there are two requirements for these systemcalls, enabling
> >   CONFIG_EXPORTFS and FS has to set s_export_op.
> >   Is this acceptable?
> 
> 
> I think exportfs is the right interface we want to depend on for
> generating a handle. We should not be having another parallel interface for file
> handle generation. But agreed that we should return -EOPNOTSUPP in case
> EXPORTFS is disabled.
> 
> 
> > 
> > - exportfs_encode_fh() supports the default encoding
> >   export_encode_fh(), but exportfs_decode_fh() doesn't.
> >   The latest patch series modifes exportfs_decode_fh() to return ESTALE,
> >   but I'd suggest to make the caller of export_encode_fh() to check
> >   s_export_op->fh_to_dentry() and return ENOSYS.
> 
> I will fix to make the syscall return EOPNOTSUPP in case fh_to_dentry is
> not supported. But i guess we still need to keep the change in
> exportfs_decode_fh to return -ESTALE in case these operations are not definied.
> 
> 
> 
> >   Or implement the default decode routine as a contrast of
> >   export_encode_fh().
> > 
> > - Some FS (or its userspace helper) may want to put UUID into the
> >   handle. If those FS already have UUID in their fs private_data, then
> >   putting a pointer (instead of an array) is better.
> >   Or creating two new operations in s_op to encode/decode handle
> >   may be good too (regardless CONFIG_EXPORTFS). The generic
> >   implementations should be provided, and when these function pointers
> >   in s_op are not set, they should be called as default. These generic
> >   implementaions will be able to be used by expfs.c too. And UUID in
> >   super_block will be unnecessary.
> 
> 
> IMHO that would be over design. We can depend on exportfs
> interfaces and if not defined return EOPNOTSUPP.
> 

How about the below patch ?

commit 5f421ffbe9dd7bb84c5992b1725c06b511bc76d8
Author: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Date:   Wed May 19 14:52:44 2010 +0530

    vfs: Return ENOSYS if CONFIG_EXPORTFS is not enabled
    
    Both the syscalls need exportfs support enabled. So if CONFIG_EXPORTFS
    is not enabled return ENOSYS. While converting name to handle check
    whether the filesystem support handle decode. If not return EOPNOTSUPP.
    We don't do a similar check in open by handle because exportfs_decode_fh
    will return ESTALE if file system doesn't support fh_to_dentry callback.
    
    Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

diff --git a/fs/open.c b/fs/open.c
index 14e6d3c..b5fc067 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -1274,6 +1274,9 @@ SYSCALL_DEFINE4(name_to_handle_at, int, dfd, const char __user *, name,
 	long ret = -EINVAL;
 	struct path path;
 
+#ifndef CONFIG_EXPORTFS
+	return -ENOSYS;
+#endif
 	if ((flag & ~AT_SYMLINK_FOLLOW) != 0)
 		goto err_out;
 
@@ -1281,6 +1284,14 @@ SYSCALL_DEFINE4(name_to_handle_at, int, dfd, const char __user *, name,
 	ret = user_path_at(dfd, name, follow, &path);
 	if (ret)
 		goto err_out;
+	/*
+	 * We need t make sure wether the file system
+	 * support decoding of the file handle
+	 */
+	if (!path.mnt->mnt_sb->s_export_op ||
+		!path.mnt->mnt_sb->s_export_op->fh_to_dentry)
+		return -EOPNOTSUPP;
+
 	ret = do_sys_name_to_handle(&path, handle);
 	path_put(&path);
 err_out:
@@ -1450,6 +1461,9 @@ SYSCALL_DEFINE3(open_by_handle, int, mountdirfd,
 {
 	long ret;
 
+#ifndef CONFIG_EXPORTFS
+	return -ENOSYS;
+#endif
 	if (force_o_largefile())
 		flags |= O_LARGEFILE;
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH -V8 2/9] vfs: Add name to file handle conversion support
  2010-05-19  9:26               ` Aneesh Kumar K. V
@ 2010-05-19 13:50                 ` J. R. Okajima
  0 siblings, 0 replies; 20+ messages in thread
From: J. R. Okajima @ 2010-05-19 13:50 UTC (permalink / raw)
  To: Aneesh Kumar K. V
  Cc: Dave Chinner, hch, viro, adilger, corbet, serue, neilb,
	linux-fsdevel, sfrench, philippe.deniel, linux-kernel


"Aneesh Kumar K. V":
> How about the below patch ?
>
> commit 5f421ffbe9dd7bb84c5992b1725c06b511bc76d8
> Author: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> Date:   Wed May 19 14:52:44 2010 +0530
>
>     vfs: Return ENOSYS if CONFIG_EXPORTFS is not enabled

Of course, I have no objection. :-)

Let me make sure some other issues.
If a malicious user passes altered dirfd or handle parameters, then
these things may happen.
- opens another file.
  But it should not be a security hole, because finish_open_handle()
  calls may_open() and the permission bits are tested expectedly.
- kernel crashes.
  If s_export_op->fh_to_dentry() expects the passed handle is always
  correct, then it may crash. But this is a problem of FS, instead of
  open_by_handle().
- returns an error.
  It is a matter of the application.
Right?

And the decode routine may return an anonymous (disconnected) dentry.
In this case, if LSM detects something wrong and produces a message,
then the filename will not be printed correctly.
This is not a problem of open_by_handle() either. Right?


J. R. Okajima

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-05-19 13:56 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-17  5:33 [PATCH -V8 0/9] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 1/9] exportfs: Return the minimum required handle size Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 2/9] vfs: Add name to file handle conversion support Aneesh Kumar K.V
2010-05-18  2:33   ` J. R. Okajima
2010-05-18  5:40     ` Aneesh Kumar K. V
2010-05-18  6:18       ` J. R. Okajima
2010-05-18  6:58         ` Aneesh Kumar K. V
2010-05-18  6:43       ` Dave Chinner
2010-05-18 10:17         ` Aneesh Kumar K. V
2010-05-19  7:15           ` J. R. Okajima
2010-05-19  8:52             ` Aneesh Kumar K. V
2010-05-19  9:26               ` Aneesh Kumar K. V
2010-05-19 13:50                 ` J. R. Okajima
2010-05-17  5:33 ` [PATCH -V8 3/9] vfs: Add open by file handle support Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 4/9] vfs: Allow handle based open on symlinks Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 5/9] vfs: Support null pathname in readlink Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 6/9] ext4: Add get_fsid callback Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 7/9] x86: Add new syscalls for x86_32 Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 8/9] x86: Add new syscalls for x86_64 Aneesh Kumar K.V
2010-05-17  5:33 ` [PATCH -V8 9/9] ext3: Add get_fsid callback Aneesh Kumar K.V

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.