Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3500735pxf; Mon, 22 Mar 2021 07:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRAPtsLypOy5EbxQOVOnPBwo3f6+Ihkz288voqkSfmQzCm39H5FzukJYnZ10WLruu0AI+v X-Received: by 2002:a17:906:4a50:: with SMTP id a16mr157069ejv.256.1616424790132; Mon, 22 Mar 2021 07:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616424790; cv=none; d=google.com; s=arc-20160816; b=taGLUWqdCAOi5OnWDnWpqG8suHoLNcykL7X5y5cEXDPV1f/FK4lrsuNsasgdlfjEJv rycxfL3gVwJiQdhYWaQ7jASH3UaX9yF3toyjFd4iAbM426QR4yAUyVlBpsSgRrWbp4ZK hfG5+ybzR3NTVdiBJOV0kZCBq7IcqlJ3KB2SdikrPfRkHW4Dhmxx/mhSDSyMpczLjgAK e2nJBD/uUDsBQgcDP6SVBv3s3IY+uTgao9o+7azCKdvXhrk0Fws1yoHUzONYO4Nl9DVu OLvpvJbjt5YUD7QOWLjTjMBIaVKtgxy/YiQ9O4tOlIhwkikko1PaKscmXirt0IjTlo7w cxlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bCOf3n4s8BDA0zcLoGv9fPeTWUpDxjyRHJ+1bBL4q8A=; b=zUq3qZ2v9vhpw4PD9lcUcs8/eAqL8rw35RW+u4FYJrhxteiqhpYYAhgys2NoFaxk2E 8yFNXn6ss6d02TZO+SW5U+o4wCMcxG8mFCTJkK4WPM3OXQfzDMT/RUC5thmTWUchFfZr tLred9QCmvnYK84+6uHbnEb5JTD1nwOmVNA3E2vfbKBoXf0LqkjYhYx+X3Do4Q7zDlzu cCyulnzHtQgDp+js37edqarNhwhdAYJ+1yUrZ+P2tWIcAF/Ay9scL72QXpSHTouIWeE7 HDw68Hp5O0DEGrzc04bJtBgC+u2vrqUTZqdf035nHHguAXB68gTcJICmApLLf3OKaqEw 8wWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GaEyKRxQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w25si11874473eju.430.2021.03.22.07.52.48; Mon, 22 Mar 2021 07:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GaEyKRxQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231327AbhCVOvj (ORCPT + 99 others); Mon, 22 Mar 2021 10:51:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42742 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbhCVOti (ORCPT ); Mon, 22 Mar 2021 10:49:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616424577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bCOf3n4s8BDA0zcLoGv9fPeTWUpDxjyRHJ+1bBL4q8A=; b=GaEyKRxQVYw99FbofABf232fEPNws14C5ofu/C2od15hQazQjLZ177ml6iSAi/6tVGtlAF nVmras3KDXqCFkVG0XvBxxSOOI3uv0zt8cHM9fpFEo4S/2RFWeGxit4Gwo/DOyci9ZnzYR 0FQbm7T67GuLgtuGK7MyQ5kfS8bWdEY= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-N7klv2xtOjSzZMVv6B2jUg-1; Mon, 22 Mar 2021 10:49:35 -0400 X-MC-Unique: N7klv2xtOjSzZMVv6B2jUg-1 Received: by mail-ed1-f69.google.com with SMTP id y10so15195819edr.20 for ; Mon, 22 Mar 2021 07:49:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bCOf3n4s8BDA0zcLoGv9fPeTWUpDxjyRHJ+1bBL4q8A=; b=NTIYgH8ubKY3jiELcyTtK1DbmOwi/uNhh21tVANKafAxudtlv2aIe6KIZuEln/nmTq zrArM2vfwGtvfweRskrpb9ywna/EwMdeeHhV3BXT7BFJEc0xNjXCGY8MhTlAlIRt3vxp 7XT1au+l3JPRrJqr/ETE/OzDzbgHe+78mdHW6eSChfUq89o7Z33aC/S/xciRKCH+dOMv jNP3ctg8RPZY2yTZPnnyiNa0s0PBBBVKf6goe53RtcBfWnHa42Sfj8GZ4VejOGp/ddfj 71RGZdZ4MuyimUaT0wKAhXFIQC5Yx2Z5krm5YQR2lYA9B4ZRQuLjBpbyJkdNCtBgWPcM zw1Q== X-Gm-Message-State: AOAM531ZeoSVOdVifqMr5Wl/VSHx5EK/P8uYd5/r5C8+otFANsRhbuEL nhkyXw3yji7yA3z0pCvQtor6GwMtO1d0r6hV+LmLMN0yBbCItvTZo81S7sytK1hAhjgq37omq8c 0eeJ15gQ+gW+pyIZnDdF2WTxp X-Received: by 2002:a17:907:2062:: with SMTP id qp2mr75740ejb.397.1616424574532; Mon, 22 Mar 2021 07:49:34 -0700 (PDT) X-Received: by 2002:a17:907:2062:: with SMTP id qp2mr75726ejb.397.1616424574396; Mon, 22 Mar 2021 07:49:34 -0700 (PDT) Received: from miu.piliscsaba.redhat.com (catv-86-101-169-67.catv.broadband.hu. [86.101.169.67]) by smtp.gmail.com with ESMTPSA id r4sm9793117ejd.125.2021.03.22.07.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 07:49:33 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Al Viro , linux-kernel@vger.kernel.org, Christoph Hellwig , Dave Kleikamp Subject: [PATCH v2 13/18] jfs: convert to miscattr Date: Mon, 22 Mar 2021 15:49:11 +0100 Message-Id: <20210322144916.137245-14-mszeredi@redhat.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210322144916.137245-1-mszeredi@redhat.com> References: <20210322144916.137245-1-mszeredi@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the miscattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi Cc: Dave Kleikamp --- fs/jfs/file.c | 6 +-- fs/jfs/ioctl.c | 105 ++++++++++++++------------------------------ fs/jfs/jfs_dinode.h | 7 --- fs/jfs/jfs_inode.h | 4 +- fs/jfs/namei.c | 6 +-- 5 files changed, 43 insertions(+), 85 deletions(-) diff --git a/fs/jfs/file.c b/fs/jfs/file.c index 28b70e7c7dd4..05ecbb1d2193 100644 --- a/fs/jfs/file.c +++ b/fs/jfs/file.c @@ -130,6 +130,8 @@ int jfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, const struct inode_operations jfs_file_inode_operations = { .listxattr = jfs_listxattr, .setattr = jfs_setattr, + .miscattr_get = jfs_miscattr_get, + .miscattr_set = jfs_miscattr_set, #ifdef CONFIG_JFS_POSIX_ACL .get_acl = jfs_get_acl, .set_acl = jfs_set_acl, @@ -147,7 +149,5 @@ const struct file_operations jfs_file_operations = { .fsync = jfs_fsync, .release = jfs_release, .unlocked_ioctl = jfs_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = jfs_compat_ioctl, -#endif + .compat_ioctl = compat_ptr_ioctl, }; diff --git a/fs/jfs/ioctl.c b/fs/jfs/ioctl.c index 2581d4db58ff..55de6203d6d9 100644 --- a/fs/jfs/ioctl.c +++ b/fs/jfs/ioctl.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "jfs_filsys.h" #include "jfs_debug.h" @@ -56,69 +57,50 @@ static long jfs_map_ext2(unsigned long flags, int from) return mapped; } +int jfs_miscattr_get(struct dentry *dentry, struct miscattr *ma) +{ + struct jfs_inode_info *jfs_inode = JFS_IP(d_inode(dentry)); + unsigned int flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE; -long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) + miscattr_fill_flags(ma, jfs_map_ext2(flags, 0)); + + return 0; +} + +int jfs_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma) { - struct inode *inode = file_inode(filp); + struct inode *inode = d_inode(dentry); struct jfs_inode_info *jfs_inode = JFS_IP(inode); unsigned int flags; - switch (cmd) { - case JFS_IOC_GETFLAGS: - flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE; - flags = jfs_map_ext2(flags, 0); - return put_user(flags, (int __user *) arg); - case JFS_IOC_SETFLAGS: { - unsigned int oldflags; - int err; - - err = mnt_want_write_file(filp); - if (err) - return err; - - if (!inode_owner_or_capable(&init_user_ns, inode)) { - err = -EACCES; - goto setflags_out; - } - if (get_user(flags, (int __user *) arg)) { - err = -EFAULT; - goto setflags_out; - } + if (miscattr_has_xattr(ma)) + return -EOPNOTSUPP; - flags = jfs_map_ext2(flags, 1); - if (!S_ISDIR(inode->i_mode)) - flags &= ~JFS_DIRSYNC_FL; + flags = jfs_map_ext2(ma->flags, 1); + if (!S_ISDIR(inode->i_mode)) + flags &= ~JFS_DIRSYNC_FL; - /* Is it quota file? Do not allow user to mess with it */ - if (IS_NOQUOTA(inode)) { - err = -EPERM; - goto setflags_out; - } + /* Is it quota file? Do not allow user to mess with it */ + if (IS_NOQUOTA(inode)) + return -EPERM; - /* Lock against other parallel changes of flags */ - inode_lock(inode); + flags = flags & JFS_FL_USER_MODIFIABLE; + flags |= jfs_inode->mode2 & ~JFS_FL_USER_MODIFIABLE; + jfs_inode->mode2 = flags; - oldflags = jfs_map_ext2(jfs_inode->mode2 & JFS_FL_USER_VISIBLE, - 0); - err = vfs_ioc_setflags_prepare(inode, oldflags, flags); - if (err) { - inode_unlock(inode); - goto setflags_out; - } + jfs_set_inode_flags(inode); + inode->i_ctime = current_time(inode); + mark_inode_dirty(inode); - flags = flags & JFS_FL_USER_MODIFIABLE; - flags |= jfs_inode->mode2 & ~JFS_FL_USER_MODIFIABLE; - jfs_inode->mode2 = flags; - - jfs_set_inode_flags(inode); - inode_unlock(inode); - inode->i_ctime = current_time(inode); - mark_inode_dirty(inode); -setflags_out: - mnt_drop_write_file(filp); - return err; - } + return 0; +} + +long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + switch (cmd) { case FITRIM: { struct super_block *sb = inode->i_sb; @@ -156,22 +138,3 @@ long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return -ENOTTY; } } - -#ifdef CONFIG_COMPAT -long jfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) -{ - /* While these ioctl numbers defined with 'long' and have different - * numbers than the 64bit ABI, - * the actual implementation only deals with ints and is compatible. - */ - switch (cmd) { - case JFS_IOC_GETFLAGS32: - cmd = JFS_IOC_GETFLAGS; - break; - case JFS_IOC_SETFLAGS32: - cmd = JFS_IOC_SETFLAGS; - break; - } - return jfs_ioctl(filp, cmd, arg); -} -#endif diff --git a/fs/jfs/jfs_dinode.h b/fs/jfs/jfs_dinode.h index 5fa9fd594115..d6af79e94263 100644 --- a/fs/jfs/jfs_dinode.h +++ b/fs/jfs/jfs_dinode.h @@ -160,11 +160,4 @@ struct dinode { #define JFS_FL_USER_MODIFIABLE 0x03F80000 #define JFS_FL_INHERIT 0x03C80000 -/* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */ -#define JFS_IOC_GETFLAGS _IOR('f', 1, long) -#define JFS_IOC_SETFLAGS _IOW('f', 2, long) - -#define JFS_IOC_GETFLAGS32 _IOR('f', 1, int) -#define JFS_IOC_SETFLAGS32 _IOW('f', 2, int) - #endif /*_H_JFS_DINODE */ diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h index 01daa0cb0ae5..9b0872141a08 100644 --- a/fs/jfs/jfs_inode.h +++ b/fs/jfs/jfs_inode.h @@ -9,8 +9,10 @@ struct fid; extern struct inode *ialloc(struct inode *, umode_t); extern int jfs_fsync(struct file *, loff_t, loff_t, int); +extern int jfs_miscattr_get(struct dentry *dentry, struct miscattr *ma); +extern int jfs_miscattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct miscattr *ma); extern long jfs_ioctl(struct file *, unsigned int, unsigned long); -extern long jfs_compat_ioctl(struct file *, unsigned int, unsigned long); extern struct inode *jfs_iget(struct super_block *, unsigned long); extern int jfs_commit_inode(struct inode *, int); extern int jfs_write_inode(struct inode *, struct writeback_control *); diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c index 9abed0d750e5..7cfb19b5a1cc 100644 --- a/fs/jfs/namei.c +++ b/fs/jfs/namei.c @@ -1522,6 +1522,8 @@ const struct inode_operations jfs_dir_inode_operations = { .rename = jfs_rename, .listxattr = jfs_listxattr, .setattr = jfs_setattr, + .miscattr_get = jfs_miscattr_get, + .miscattr_set = jfs_miscattr_set, #ifdef CONFIG_JFS_POSIX_ACL .get_acl = jfs_get_acl, .set_acl = jfs_set_acl, @@ -1533,9 +1535,7 @@ const struct file_operations jfs_dir_operations = { .iterate = jfs_readdir, .fsync = jfs_fsync, .unlocked_ioctl = jfs_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = jfs_compat_ioctl, -#endif + .compat_ioctl = compat_ptr_ioctl, .llseek = generic_file_llseek, }; -- 2.30.2