From patchwork Tue Mar 10 17:22:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 5979691 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9C18A9F2A9 for ; Tue, 10 Mar 2015 17:24:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9555820220 for ; Tue, 10 Mar 2015 17:24:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 609C92021F for ; Tue, 10 Mar 2015 17:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753708AbbCJRWP (ORCPT ); Tue, 10 Mar 2015 13:22:15 -0400 Received: from forward-corp1f.mail.yandex.net ([95.108.130.40]:36377 "EHLO forward-corp1f.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752652AbbCJRWL (ORCPT ); Tue, 10 Mar 2015 13:22:11 -0400 Received: from smtpcorp1m.mail.yandex.net (smtpcorp1m.mail.yandex.net [77.88.61.150]) by forward-corp1f.mail.yandex.net (Yandex) with ESMTP id D1F9D2420303; Tue, 10 Mar 2015 20:22:06 +0300 (MSK) Received: from smtpcorp1m.mail.yandex.net (localhost [127.0.0.1]) by smtpcorp1m.mail.yandex.net (Yandex) with ESMTP id 9CEAC2CA043C; Tue, 10 Mar 2015 20:22:06 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:408:a45e:343f:b17c:8d0d]) by smtpcorp1m.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 8EfQ81DAKS-M6o8IYw8; Tue, 10 Mar 2015 20:22:06 +0300 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1426008126; bh=D78HmkX/b9qULD6V3aUpK5pOXMNInE4F81U+0++zqrE=; h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References: User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ZVcpbnt/JBai5ASYdfl9oX/M8G/k62yccgRVYWc6yXW/FnKv5btk1Nxddru+y6eQA 3QH/hqZ8uQiRxw0QuLdHWCLvNY6Orx1Tx+6VaLRLEjQRQgVONFzL8OKOzrxs5PyJPG ms6IJ6GsW21cU3aEvXrwkPseSsOBFAHHJLaCJAfY= Authentication-Results: smtpcorp1m.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH RFC v2 1/6] fs: vfs ioctls for managing project id From: Konstantin Khlebnikov To: linux-fsdevel@vger.kernel.org, Dave Chinner , Jan Kara , linux-ext4@vger.kernel.org, Theodore Ts'o Cc: Dmitry Monakhov , Andy Lutomirski , linux-kernel@vger.kernel.org, Li Xi Date: Tue, 10 Mar 2015 20:22:05 +0300 Message-ID: <20150310172205.23081.67263.stgit@buzz> In-Reply-To: <20150310171133.23081.49616.stgit@buzz> References: <20150310171133.23081.49616.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds generic vfs interface for project id and related super-block methods. Two new ioctls: int ioctl(fd, FS_IOC_GETPROJECT, unsigned *project); int ioctl(fd, FS_IOC_SETPROJECT, unsigned *project); Signed-off-by: Konstantin Khlebnikov --- Documentation/filesystems/Locking | 4 +++ Documentation/filesystems/vfs.txt | 8 +++++ fs/compat_ioctl.c | 2 + fs/ioctl.c | 58 +++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 + include/uapi/linux/fs.h | 3 ++ 6 files changed, 77 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index f91926f2f482..7a01e2b606d0 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -126,6 +126,8 @@ prototypes: ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); + kprojid_t (*get_project) (struct inode *); + int (*set_project) (struct inode *, kprojid_t); locking rules: All may block [not true, see below] @@ -147,6 +149,8 @@ show_options: no (namespace_sem) quota_read: no (see below) quota_write: no (see below) bdev_try_to_free_page: no (see below) +get_project no +set_project no (i_mutex) ->statfs() has s_umount (shared) when called by ustat(2) (native or compat), but that's an accident of bad API; s_umount is used to pin diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index 966b22829f3b..aeff3c54021b 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -230,6 +230,8 @@ struct super_operations { ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); int (*nr_cached_objects)(struct super_block *); void (*free_cached_objects)(struct super_block *, int); + kprojid_t (*get_project)(struct inode *); + int (*set_project)(struct inode *, kprojid_t); }; All methods are called without any locks being held, unless otherwise @@ -319,6 +321,12 @@ or bottom half). implementations will cause holdoff problems due to large scan batch sizes. + get_project: called by the ioctl and quota code to get project id of an inode. + Method should return INVALID_PROJID if feature isn't supported. + + set_project: called by the ioctl to set project id for an inode. + This is called with i_mutex held. + Whoever sets up the inode is responsible for filling in the "i_op" field. This is a pointer to a "struct inode_operations" which describes the methods that can be performed on individual inodes. diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index afec6450450f..9a24e4038377 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c @@ -889,6 +889,8 @@ COMPATIBLE_IOCTL(FIOASYNC) COMPATIBLE_IOCTL(FIONBIO) COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */ COMPATIBLE_IOCTL(FS_IOC_FIEMAP) +COMPATIBLE_IOCTL(FS_IOC_GETPROJECT) +COMPATIBLE_IOCTL(FS_IOC_SETPROJECT) /* 0x00 */ COMPATIBLE_IOCTL(FIBMAP) COMPATIBLE_IOCTL(FIGETBSZ) diff --git a/fs/ioctl.c b/fs/ioctl.c index 5d01d2638ca5..d351576d95c8 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -545,6 +546,57 @@ static int ioctl_fsthaw(struct file *filp) return thaw_super(sb); } +static int ioctl_getproject(struct file *filp, projid_t __user *argp) +{ + struct user_namespace *ns = current_user_ns(); + struct inode *inode = file_inode(filp); + struct super_block *sb = inode->i_sb; + kprojid_t kprojid; + projid_t projid; + + if (!sb->s_op->get_project) + return -EOPNOTSUPP; + kprojid = sb->s_op->get_project(inode); + if (!projid_valid(kprojid)) + return -EOPNOTSUPP; + projid = from_kprojid(ns, kprojid); + if (projid == (projid_t)-1) + return -EACCES; + return put_user(projid, argp); +} + +static int ioctl_setproject(struct file *filp, projid_t __user *argp) +{ + struct user_namespace *ns = current_user_ns(); + struct inode *inode = file_inode(filp); + struct super_block *sb = inode->i_sb; + kprojid_t kprojid; + projid_t projid; + int ret; + + if (!sb->s_op->set_project) + return -EOPNOTSUPP; + if (ns != &init_user_ns) + return -EPERM; + ret = get_user(projid, argp); + if (ret) + return ret; + kprojid = make_kprojid(ns, projid); + if (!projid_valid(kprojid)) + return -EACCES; + ret = mnt_want_write_file(filp); + if (ret) + return ret; + mutex_lock(&inode->i_mutex); + if (inode_owner_or_capable(inode)) + ret = sb->s_op->set_project(inode, kprojid); + else + ret = -EPERM; + mutex_unlock(&inode->i_mutex); + mnt_drop_write_file(filp); + return ret; +} + /* * When you add any new common ioctls to the switches above and below * please update compat_sys_ioctl() too. @@ -597,6 +649,12 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, case FS_IOC_FIEMAP: return ioctl_fiemap(filp, arg); + case FS_IOC_GETPROJECT: + return ioctl_getproject(filp, argp); + + case FS_IOC_SETPROJECT: + return ioctl_setproject(filp, argp); + case FIGETBSZ: return put_user(inode->i_sb->s_blocksize, argp); diff --git a/include/linux/fs.h b/include/linux/fs.h index b4d71b5e1ff2..42156801739e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1655,6 +1655,8 @@ struct super_operations { struct shrink_control *); long (*free_cached_objects)(struct super_block *, struct shrink_control *); + kprojid_t (*get_project)(struct inode *); + int (*set_project)(struct inode *, kprojid_t); }; /* diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 9b964a5920af..144426326e15 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -170,6 +170,9 @@ struct inodes_stat_t { #define FS_IOC32_GETVERSION _IOR('v', 1, int) #define FS_IOC32_SETVERSION _IOW('v', 2, int) +#define FS_IOC_GETPROJECT _IOR('f', 20, unsigned) +#define FS_IOC_SETPROJECT _IOW('f', 21, unsigned) + /* * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) */