From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Aneesh Kumar K.V" Subject: [PATCH -V5 0/8] Generic name to handle and open by handle syscalls Date: Mon, 26 Apr 2010 23:03:58 +0530 Message-ID: <1272303246-25570-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Cc: linux-fsdevel@vger.kernel.org, sfrench@us.ibm.com To: hch@infradead.org, viro@zeniv.linux.org.uk, adilger@sun.com, corbet@lwn.net, serue@us.ibm.com, neilb@suse.de Return-path: Received: from e23smtp03.au.ibm.com ([202.81.31.145]:50797 "EHLO e23smtp03.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751658Ab0DZReQ (ORCPT ); Mon, 26 Apr 2010 13:34:16 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp03.au.ibm.com (8.14.3/8.13.1) with ESMTP id o3QHUuvn013257 for ; Tue, 27 Apr 2010 03:30:56 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o3QHRRXT1618106 for ; Tue, 27 Apr 2010 03:27:27 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o3QHYDWm010978 for ; Tue, 27 Apr 2010 03:34:13 +1000 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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. 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) ---------------- #include #include #include #include #include #include #include #include struct uuid { char uuid[16]; }; struct file_handle { int handle_size; int handle_type; struct uuid fsid; char handle[0]; }; static int name_to_handle(const char *name, struct file_handle *fh) { return syscall(338, name, fh); } static int lname_to_handle(const char *name, struct file_handle *fh) { return syscall(339, name, fh); } static int open_by_handle(struct file_handle *fh, int flags) { return syscall(340, fh, flags); } static int freadlink(int fd, char *buf, size_t bufsiz) { return syscall(341, fd, buf, bufsiz); } #define BUFSZ 100 int main(int argc, char *argv[]) { int ret; int handle_sz; struct stat bufstat; int fd, dirfd; char buf[BUFSZ]; struct file_handle *fh = NULL;; 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) { 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); } fstat(fd, &bufstat); ret = S_ISLNK(bufstat.st_mode); if (ret) { memset(buf, 0 , BUFSZ); freadlink(fd, 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