From patchwork Fri Apr 29 14:18:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 8983251 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C7910BF29F for ; Fri, 29 Apr 2016 14:18:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A007E201DD for ; Fri, 29 Apr 2016 14:18:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CA2D201CE for ; Fri, 29 Apr 2016 14:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753809AbcD2OSx (ORCPT ); Fri, 29 Apr 2016 10:18:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59979 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753803AbcD2OSx (ORCPT ); Fri, 29 Apr 2016 10:18:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F00663455AC; Fri, 29 Apr 2016 14:18:52 +0000 (UTC) Received: from nux.redhat.com (vpn1-6-50.ams2.redhat.com [10.36.6.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3TEIcEd022068; Fri, 29 Apr 2016 10:18:51 -0400 From: Andreas Gruenbacher To: Alexander Viro Cc: Andreas Gruenbacher , linux-fsdevel@vger.kernel.org Subject: [PATCH 5/5] sockfs: Get rid of getxattr iop Date: Fri, 29 Apr 2016 16:18:37 +0200 Message-Id: <1461939517-15497-6-git-send-email-agruenba@redhat.com> In-Reply-To: <1461939517-15497-1-git-send-email-agruenba@redhat.com> References: <1461939517-15497-1-git-send-email-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 If we allow pseudo-filesystems created with mount_pseudo to have xattr handlers, we can replace sockfs_getxattr with a sockfs_xattr_get handler to use the xattr handler name parsing. In this case, the improvement is only a small one, though. Signed-off-by: Andreas Gruenbacher --- arch/ia64/kernel/perfmon.c | 4 ++-- drivers/gpu/drm/drm_drv.c | 1 + fs/aio.c | 2 +- fs/anon_inodes.c | 2 +- fs/block_dev.c | 2 +- fs/btrfs/tests/btrfs-tests.c | 2 +- fs/libfs.c | 3 ++- fs/nsfs.c | 2 +- fs/pipe.c | 2 +- include/linux/fs.h | 1 + net/socket.c | 48 ++++++++++++++++++++++++++------------------ 11 files changed, 41 insertions(+), 28 deletions(-) diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c index 9cd607b..782cddb 100644 --- a/arch/ia64/kernel/perfmon.c +++ b/arch/ia64/kernel/perfmon.c @@ -611,8 +611,8 @@ static const struct dentry_operations pfmfs_dentry_operations; static struct dentry * pfmfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { - return mount_pseudo(fs_type, "pfm:", NULL, &pfmfs_dentry_operations, - PFMFS_MAGIC); + return mount_pseudo(fs_type, "pfm:", NULL, NULL, + &pfmfs_dentry_operations, PFMFS_MAGIC); } static struct file_system_type pfm_fs_type = { diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 167c8d3..3512bb8 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -509,6 +509,7 @@ static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags, return mount_pseudo(fs_type, "drm:", &drm_fs_sops, + NULL, &drm_fs_dops, 0x010203ff); } diff --git a/fs/aio.c b/fs/aio.c index 155f842..6f1387f 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -239,7 +239,7 @@ static struct dentry *aio_mount(struct file_system_type *fs_type, static const struct dentry_operations ops = { .d_dname = simple_dname, }; - return mount_pseudo(fs_type, "aio:", NULL, &ops, AIO_RING_MAGIC); + return mount_pseudo(fs_type, "aio:", NULL, NULL, &ops, AIO_RING_MAGIC); } /* aio_setup diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c index 80ef38c..5e1aeea1 100644 --- a/fs/anon_inodes.c +++ b/fs/anon_inodes.c @@ -41,7 +41,7 @@ static const struct dentry_operations anon_inodefs_dentry_operations = { static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { - return mount_pseudo(fs_type, "anon_inode:", NULL, + return mount_pseudo(fs_type, "anon_inode:", NULL, NULL, &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC); } diff --git a/fs/block_dev.c b/fs/block_dev.c index 3172c4e..8c605ff 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -576,7 +576,7 @@ static struct dentry *bd_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { struct dentry *dent; - dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC); + dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, NULL, BDEVFS_MAGIC); if (dent) dent->d_sb->s_iflags |= SB_I_CGROUPWB; return dent; diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c index f54bf45..ebecf33 100644 --- a/fs/btrfs/tests/btrfs-tests.c +++ b/fs/btrfs/tests/btrfs-tests.c @@ -40,7 +40,7 @@ static struct dentry *btrfs_test_mount(struct file_system_type *fs_type, void *data) { return mount_pseudo(fs_type, "btrfs_test:", &btrfs_test_super_ops, - NULL, BTRFS_TEST_MAGIC); + NULL, NULL, BTRFS_TEST_MAGIC); } static struct file_system_type test_type = { diff --git a/fs/libfs.c b/fs/libfs.c index 03332f4..2a820bb 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -209,7 +209,7 @@ static const struct super_operations simple_super_operations = { * will never be mountable) */ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name, - const struct super_operations *ops, + const struct super_operations *ops, const struct xattr_handler **xattr, const struct dentry_operations *dops, unsigned long magic) { struct super_block *s; @@ -226,6 +226,7 @@ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name, s->s_blocksize_bits = PAGE_SHIFT; s->s_magic = magic; s->s_op = ops ? ops : &simple_super_operations; + s->s_xattr = xattr; s->s_time_gran = 1; root = new_inode(s); if (!root) diff --git a/fs/nsfs.c b/fs/nsfs.c index 8f20d60..e151cc3 100644 --- a/fs/nsfs.c +++ b/fs/nsfs.c @@ -154,7 +154,7 @@ static const struct super_operations nsfs_ops = { static struct dentry *nsfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { - return mount_pseudo(fs_type, "nsfs:", &nsfs_ops, + return mount_pseudo(fs_type, "nsfs:", &nsfs_ops, NULL, &ns_dentry_operations, NSFS_MAGIC); } static struct file_system_type nsfs = { diff --git a/fs/pipe.c b/fs/pipe.c index ab8dad3..60a9180 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1143,7 +1143,7 @@ static const struct super_operations pipefs_ops = { static struct dentry *pipefs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { - return mount_pseudo(fs_type, "pipe:", &pipefs_ops, + return mount_pseudo(fs_type, "pipe:", &pipefs_ops, NULL, &pipefs_dentry_operations, PIPEFS_MAGIC); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 1b5fcae..3489609 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2030,6 +2030,7 @@ struct super_block *sget(struct file_system_type *type, int flags, void *data); extern struct dentry *mount_pseudo(struct file_system_type *, char *, const struct super_operations *ops, + const struct xattr_handler **xattr, const struct dentry_operations *dops, unsigned long); diff --git a/net/socket.c b/net/socket.c index 23fdd83..3ef77ab 100644 --- a/net/socket.c +++ b/net/socket.c @@ -320,11 +320,38 @@ static const struct dentry_operations sockfs_dentry_operations = { .d_dname = sockfs_dname, }; +static int sockfs_xattr_get(const struct xattr_handler *handler, + struct dentry *dentry, struct inode *inode, + const char *suffix, void *value, size_t size) +{ + if (value) { + if (dentry->d_name.len + 1 > size) + return -ERANGE; + memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); + } + return dentry->d_name.len + 1; +} + +#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname" +#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX) +#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1) + +static const struct xattr_handler sockfs_xattr_handler = { + .name = XATTR_NAME_SOCKPROTONAME, + .get = sockfs_xattr_get, +}; + +static const struct xattr_handler *sockfs_xattr_handlers[] = { + &sockfs_xattr_handler, + NULL +}; + static struct dentry *sockfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { return mount_pseudo(fs_type, "socket:", &sockfs_ops, - &sockfs_dentry_operations, SOCKFS_MAGIC); + sockfs_xattr_handlers, + &sockfs_dentry_operations, SOCKFS_MAGIC); } static struct vfsmount *sock_mnt __read_mostly; @@ -463,23 +490,6 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) return NULL; } -#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname" -#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX) -#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1) -static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode, - const char *name, void *value, size_t size) -{ - if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) { - if (value) { - if (dentry->d_name.len + 1 > size) - return -ERANGE; - memcpy(value, dentry->d_name.name, dentry->d_name.len + 1); - } - return dentry->d_name.len + 1; - } - return -EOPNOTSUPP; -} - static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, size_t size) { @@ -509,7 +519,7 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer, } static const struct inode_operations sockfs_inode_ops = { - .getxattr = sockfs_getxattr, + .getxattr = generic_getxattr, .listxattr = sockfs_listxattr, };