Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp731874pxf; Thu, 25 Mar 2021 12:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxQiL02omeMEXKIA5uFWEY5mP4sGdADS53TiOlPO8YtzbPPDdSCbf692VxObrZyyEpUc+8 X-Received: by 2002:a17:906:1d4e:: with SMTP id o14mr11136556ejh.549.1616701401220; Thu, 25 Mar 2021 12:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616701401; cv=none; d=google.com; s=arc-20160816; b=L98Iu6tt7dhqjG7fHy9w0zpc6qSSGDyopyFQEyYpFCnDISvMCqQZmlkB50bfBoTTrO anpsaRVoHL8b3mdPG3d/m2250bQZ6Rh1FepS8VV6hxRuxK69n4fV9H0Ao8Ky/S2qNW4Q kiX1oWH76I+M2WsCcXT9rb4RDQq7Y13EZEVanYXCdFcQ9izrGzGRZbd/q0tjmdzEhZuL d8qx2fQY3DgTo9BlGb/ki+g6rtXeC1HtoTZ+Fgbx7+R0jPVAkDuXaIriihHHGevG+jmB eWur68HI6+Uvx1rfrLv2BueWrRiDqiT8In5c00GlZMLRwYv8703AG+4iwy8nCgpc1aZR RH1w== 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=/7NIBk6La/dqb6C44uocZQB5NEP7IgsPWWcJ4ROLNwg=; b=inENE/vllsxeqrre+t+PAI2DgGtgmBSBznm9KuyDLslDyt41dsJ9M2LZqPZR6r0K1y 2sCLOvlG0wUA7hHBDTB0ilUZyeI6OknII/WvrMv8gXuIo1oLr7CODU0uEsduE07zAPW1 8WlkvgEVLt0dN3FHlHOeYKa4SmI9pDJR1muuD5Gf9Mo+2n/sKa9SZYVhxEyFnY7zL5kp g7wyKQsWXe0L3PenAXjv/EkAi7RzhepYu7fUHNNkZyV02eX9tV16duAH8ypeV3jLHbWG T4b24B1Ov20FI0jZJAa02PmusilqGyA/xxqQIlTiY1ClNPF0IUHwU683bZbIdwC/E/5f 8J6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=USGMXRbY; 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 s10si5132415edi.563.2021.03.25.12.42.58; Thu, 25 Mar 2021 12:43:21 -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=USGMXRbY; 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 S231172AbhCYTjD (ORCPT + 99 others); Thu, 25 Mar 2021 15:39:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45074 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbhCYTiS (ORCPT ); Thu, 25 Mar 2021 15:38:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616701098; 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=/7NIBk6La/dqb6C44uocZQB5NEP7IgsPWWcJ4ROLNwg=; b=USGMXRbYkwNOkik8t1nE/DYZ6GQDZ6E1nKt9hG8YPc27xk5e7+YGKb/KiseiCE05fZdwCM 10r9mUCSgKAYMQ05w3icySjNO0iR1AJxKHkwu7rCdEGqyC34wVtqlMLm0HFiVYsbw0TnpO 7eh79p0A31DXTaRpLWNrhGYMPGR8kh8= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-4D8icafQMDm7Sk5ynGN4wQ-1; Thu, 25 Mar 2021 15:38:16 -0400 X-MC-Unique: 4D8icafQMDm7Sk5ynGN4wQ-1 Received: by mail-ej1-f70.google.com with SMTP id sa29so3069088ejb.4 for ; Thu, 25 Mar 2021 12:38:15 -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=/7NIBk6La/dqb6C44uocZQB5NEP7IgsPWWcJ4ROLNwg=; b=l5fWkIxoQME0chA1fNiEbtzY1pmImBuJRVfvkD07rmUKwmoXimKP3ou40cLkNG8uno gexQ5li1D36DseJuuZ9TsWOfwRbEPV1DbHzkfhfLzp6wvhKkNMlj21oJni+ZSbGRhXKV SbYIuL8QMQ+surZ6Rh5mf09KuliKt00PPBs3X8x4fciuH8xBFVDe3lTcEczL7KVik8gr A1zW9yAUUXZbCl0j+hmyxnYudq0FJXL/SlsEGCbUJroPN2DOwSaCBWmUyMLsZLxiNB13 xThn3D1M0r19u79KtGVOfQNsB/hCyBGfhf017sz/O0wmz8TgIl9SBbTJ5fra/F2xudF6 yZpQ== X-Gm-Message-State: AOAM533BKBkLqJLFqgK7zV8M01CRyCIBKDTGGq2TFq0YqEOnAVT3EB7M mJSUxUfkL0j6YI5SwcgkF1TegZenZStO5f9t0CpyRDDPJt01okzNK4kbNyuGeRLZFtWTNUCBXw6 W6oeyuAW9E/gtV3vuXPzIwo30 X-Received: by 2002:a17:906:f56:: with SMTP id h22mr11536018ejj.494.1616701094805; Thu, 25 Mar 2021 12:38:14 -0700 (PDT) X-Received: by 2002:a17:906:f56:: with SMTP id h22mr11535997ejj.494.1616701094600; Thu, 25 Mar 2021 12:38:14 -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 si7sm2881996ejb.84.2021.03.25.12.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 12:38:14 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Al Viro , linux-kernel@vger.kernel.org, Jan Kara Subject: [PATCH v3 16/18] reiserfs: convert to fileattr Date: Thu, 25 Mar 2021 20:37:53 +0100 Message-Id: <20210325193755.294925-17-mszeredi@redhat.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325193755.294925-1-mszeredi@redhat.com> References: <20210325193755.294925-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 fileattr API to let the VFS handle locking, permission checking and conversion. Signed-off-by: Miklos Szeredi Cc: Jan Kara --- fs/reiserfs/file.c | 2 + fs/reiserfs/ioctl.c | 121 +++++++++++++++++++---------------------- fs/reiserfs/namei.c | 2 + fs/reiserfs/reiserfs.h | 7 ++- fs/reiserfs/super.c | 2 +- 5 files changed, 64 insertions(+), 70 deletions(-) diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c index 1db0254bc38b..203a47232707 100644 --- a/fs/reiserfs/file.c +++ b/fs/reiserfs/file.c @@ -258,4 +258,6 @@ const struct inode_operations reiserfs_file_inode_operations = { .permission = reiserfs_permission, .get_acl = reiserfs_get_acl, .set_acl = reiserfs_set_acl, + .fileattr_get = reiserfs_fileattr_get, + .fileattr_set = reiserfs_fileattr_set, }; diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c index 4f1cbd930179..4b86ecf5817e 100644 --- a/fs/reiserfs/ioctl.c +++ b/fs/reiserfs/ioctl.c @@ -10,6 +10,59 @@ #include #include #include +#include + +int reiserfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) +{ + struct inode *inode = d_inode(dentry); + + if (!reiserfs_attrs(inode->i_sb)) + return -ENOTTY; + + fileattr_fill_flags(fa, REISERFS_I(inode)->i_attrs); + + return 0; +} + +int reiserfs_fileattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct fileattr *fa) +{ + struct inode *inode = d_inode(dentry); + unsigned int flags = fa->flags; + int err; + + reiserfs_write_lock(inode->i_sb); + + err = -ENOTTY; + if (!reiserfs_attrs(inode->i_sb)) + goto unlock; + + err = -EOPNOTSUPP; + if (fileattr_has_fsx(fa)) + goto unlock; + + /* + * Is it quota file? Do not allow user to mess with it + */ + err = -EPERM; + if (IS_NOQUOTA(inode)) + goto unlock; + + if ((flags & REISERFS_NOTAIL_FL) && S_ISREG(inode->i_mode)) { + err = reiserfs_unpack(inode); + if (err) + goto unlock; + } + sd_attrs_to_i_attrs(flags, inode); + REISERFS_I(inode)->i_attrs = flags; + inode->i_ctime = current_time(inode); + mark_inode_dirty(inode); + err = 0; +unlock: + reiserfs_write_unlock(inode->i_sb); + + return err; +} /* * reiserfs_ioctl - handler for ioctl for inode @@ -23,7 +76,6 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct inode *inode = file_inode(filp); - unsigned int flags; int err = 0; reiserfs_write_lock(inode->i_sb); @@ -32,7 +84,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case REISERFS_IOC_UNPACK: if (S_ISREG(inode->i_mode)) { if (arg) - err = reiserfs_unpack(inode, filp); + err = reiserfs_unpack(inode); } else err = -ENOTTY; break; @@ -40,63 +92,6 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) * following two cases are taken from fs/ext2/ioctl.c by Remy * Card (card@masi.ibp.fr) */ - case REISERFS_IOC_GETFLAGS: - if (!reiserfs_attrs(inode->i_sb)) { - err = -ENOTTY; - break; - } - - flags = REISERFS_I(inode)->i_attrs; - err = put_user(flags, (int __user *)arg); - break; - case REISERFS_IOC_SETFLAGS:{ - if (!reiserfs_attrs(inode->i_sb)) { - err = -ENOTTY; - break; - } - - err = mnt_want_write_file(filp); - if (err) - break; - - if (!inode_owner_or_capable(&init_user_ns, inode)) { - err = -EPERM; - goto setflags_out; - } - if (get_user(flags, (int __user *)arg)) { - err = -EFAULT; - goto setflags_out; - } - /* - * Is it quota file? Do not allow user to mess with it - */ - if (IS_NOQUOTA(inode)) { - err = -EPERM; - goto setflags_out; - } - err = vfs_ioc_setflags_prepare(inode, - REISERFS_I(inode)->i_attrs, - flags); - if (err) - goto setflags_out; - if ((flags & REISERFS_NOTAIL_FL) && - S_ISREG(inode->i_mode)) { - int result; - - result = reiserfs_unpack(inode, filp); - if (result) { - err = result; - goto setflags_out; - } - } - sd_attrs_to_i_attrs(flags, inode); - REISERFS_I(inode)->i_attrs = flags; - inode->i_ctime = current_time(inode); - mark_inode_dirty(inode); -setflags_out: - mnt_drop_write_file(filp); - break; - } case REISERFS_IOC_GETVERSION: err = put_user(inode->i_generation, (int __user *)arg); break; @@ -138,12 +133,6 @@ long reiserfs_compat_ioctl(struct file *file, unsigned int cmd, case REISERFS_IOC32_UNPACK: cmd = REISERFS_IOC_UNPACK; break; - case REISERFS_IOC32_GETFLAGS: - cmd = REISERFS_IOC_GETFLAGS; - break; - case REISERFS_IOC32_SETFLAGS: - cmd = REISERFS_IOC_SETFLAGS; - break; case REISERFS_IOC32_GETVERSION: cmd = REISERFS_IOC_GETVERSION; break; @@ -165,7 +154,7 @@ int reiserfs_commit_write(struct file *f, struct page *page, * Function try to convert tail from direct item into indirect. * It set up nopack attribute in the REISERFS_I(inode)->nopack */ -int reiserfs_unpack(struct inode *inode, struct file *filp) +int reiserfs_unpack(struct inode *inode) { int retval = 0; int index; diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c index e6eb05e2b2f1..017db70d0f48 100644 --- a/fs/reiserfs/namei.c +++ b/fs/reiserfs/namei.c @@ -1660,6 +1660,8 @@ const struct inode_operations reiserfs_dir_inode_operations = { .permission = reiserfs_permission, .get_acl = reiserfs_get_acl, .set_acl = reiserfs_set_acl, + .fileattr_get = reiserfs_fileattr_get, + .fileattr_set = reiserfs_fileattr_set, }; /* diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h index 0ca2ac62e534..3aa928ec527a 100644 --- a/fs/reiserfs/reiserfs.h +++ b/fs/reiserfs/reiserfs.h @@ -18,8 +18,6 @@ /* the 32 bit compat definitions with int argument */ #define REISERFS_IOC32_UNPACK _IOW(0xCD, 1, int) -#define REISERFS_IOC32_GETFLAGS FS_IOC32_GETFLAGS -#define REISERFS_IOC32_SETFLAGS FS_IOC32_SETFLAGS #define REISERFS_IOC32_GETVERSION FS_IOC32_GETVERSION #define REISERFS_IOC32_SETVERSION FS_IOC32_SETVERSION @@ -3408,7 +3406,10 @@ __u32 r5_hash(const signed char *msg, int len); #define SPARE_SPACE 500 /* prototypes from ioctl.c */ +int reiserfs_fileattr_get(struct dentry *dentry, struct fileattr *fa); +int reiserfs_fileattr_set(struct user_namespace *mnt_userns, + struct dentry *dentry, struct fileattr *fa); long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long reiserfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); -int reiserfs_unpack(struct inode *inode, struct file *filp); +int reiserfs_unpack(struct inode *inode); diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c index 1b9c7a387dc7..3ffafc73acf0 100644 --- a/fs/reiserfs/super.c +++ b/fs/reiserfs/super.c @@ -2408,7 +2408,7 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, * IO to work */ if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) { - err = reiserfs_unpack(inode, NULL); + err = reiserfs_unpack(inode); if (err) { reiserfs_warning(sb, "super-6520", "Unpacking tail of quota file failed" -- 2.30.2