From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Aneesh Kumar K.V" Subject: [PATCH -V2] Generic name to handle and open by handle syscalls Date: Thu, 18 Mar 2010 22:39:01 +0530 Message-ID: <1268932144-14105-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Cc: linux-fsdevel@vger.kernel.org, adilger@sun.com, corbet@lwn.net To: hch@infradead.org, viro@zeniv.linux.org.uk Return-path: Received: from e23smtp07.au.ibm.com ([202.81.31.140]:41356 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753120Ab0CRRJU (ORCPT ); Thu, 18 Mar 2010 13:09:20 -0400 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp07.au.ibm.com (8.14.3/8.13.1) with ESMTP id o2IH9IGD024545 for ; Fri, 19 Mar 2010 04:09:18 +1100 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o2IH3LKf1581278 for ; Fri, 19 Mar 2010 04:03:21 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o2IH9HsD016513 for ; Fri, 19 Mar 2010 04:09:18 +1100 Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 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: ------------- cc -D_GNU_SOURCE ---------------- #include #include #include #include #include #include #include struct file_handle { int handle_size; int handle_type; void *handle; }; int main(int argc, char *argv[]) { int ret; int fd, dirfd; char buf[100]; struct file_handle fh; fh.handle_type = 0; fh.handle = malloc(100); fh.handle_size = 100; errno = 0; ret = syscall(338, argv[1], &fh); if (ret) { perror("Error:"); exit(1); } dirfd = open("/", O_RDONLY|O_DIRECTORY); fd = syscall(339, dirfd, &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; }