linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -V4] Generic name to handle and open by handle syscalls
@ 2010-04-23 11:38 Aneesh Kumar K.V
  2010-04-23 11:38 ` [PATCH -V4 1/6] exportfs: Return the minimum required handle size Aneesh Kumar K.V
                   ` (5 more replies)
  0 siblings, 6 replies; 19+ messages in thread
From: Aneesh Kumar K.V @ 2010-04-23 11:38 UTC (permalink / raw)
  To: hch, viro, adilger, corbet, serue; +Cc: linux-fsdevel, sfrench

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://lists.gnu.org/archive/html/qemu-devel/2010-03/msg01087.html

TODO:
I guess we would need to optimize how we get the vfsmount for the filesystem
uuid specified. Searching the file system list and task name space may be a big
overhead for each open by handle call.

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)
----------------
#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 {
	char uuid[16];
};
struct file_handle {
        int handle_size;
        int handle_type;
	struct uuid fsid;
        void *handle;
};

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

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

int main(int argc, char *argv[])
{
        int ret;
        int fd, dirfd;
        char buf[100];
        struct file_handle fh;
        fh.handle_size = 0;
again:
	if (fh.handle_size)
        	fh.handle = malloc(fh.handle_size);
        fh.handle_type = 0;
        errno  = 0;
        ret = name_to_handle(argv[1], &fh);
        if (ret) {
                perror("Error:");
		printf("Found the handle size needed to be %d\n", fh.handle_size);
		printf("Trying again..\n");
		goto again;
                exit(1);
        }
        fd = open_by_handle(&fh, O_RDONLY);
        if (fd <= 0 ) {
                perror("Error:");
                exit(1);
        }
        memset(buf, 0 , 100);
        while (read(fd, buf, 100) > 0) {
                printf("%s", buf);
                memset(buf, 0 , 100);
        }
        return 0;
}

-aneesh


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

end of thread, other threads:[~2010-04-27 13:28 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-23 11:38 [PATCH -V4] Generic name to handle and open by handle syscalls Aneesh Kumar K.V
2010-04-23 11:38 ` [PATCH -V4 1/6] exportfs: Return the minimum required handle size Aneesh Kumar K.V
2010-04-23 11:38 ` [PATCH -V4 2/6] vfs: Add name to file handle conversion support Aneesh Kumar K.V
2010-04-23 22:02   ` Andreas Dilger
2010-04-26  9:52     ` Christoph Hellwig
2010-04-26 10:14       ` Aneesh Kumar K. V
2010-04-26 10:12     ` Aneesh Kumar K. V
2010-04-26 17:57       ` J. Bruce Fields
2010-04-27  6:13         ` Aneesh Kumar K. V
2010-04-27 13:28           ` J. Bruce Fields
2010-04-23 11:38 ` [PATCH -V4 3/6] vfs: Add open by file handle support Aneesh Kumar K.V
2010-04-23 11:38 ` [PATCH -V4 4/6] ext4: Add get_fsid callback Aneesh Kumar K.V
2010-04-23 11:38 ` [PATCH -V4 5/6] x86: Add new syscalls for x86_32 Aneesh Kumar K.V
2010-04-23 11:38 ` [PATCH -V4 6/6] x86: Add new syscalls for x86_64 Aneesh Kumar K.V
2010-04-23 22:09   ` Andreas Dilger
2010-04-25 18:28     ` Aneesh Kumar K. V
2010-04-26  9:53       ` Christoph Hellwig
2010-04-26 17:59         ` Andreas Dilger
2010-04-27  6:25         ` Aneesh Kumar K. V

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).