From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07876C433DB for ; Tue, 23 Mar 2021 22:15:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C7FB601FC for ; Tue, 23 Mar 2021 22:15:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C7FB601FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EF4556B0285; Tue, 23 Mar 2021 18:15:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA49D6B0287; Tue, 23 Mar 2021 18:15:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6C7E6B0289; Tue, 23 Mar 2021 18:15:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id BBDA16B0285 for ; Tue, 23 Mar 2021 18:15:06 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6D1FC99B4 for ; Tue, 23 Mar 2021 22:15:06 +0000 (UTC) X-FDA: 77952545412.21.B4E8A2C Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf15.hostedemail.com (Postfix) with ESMTP id 78787A000843 for ; Tue, 23 Mar 2021 22:15:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 567541F454D0 From: Gabriel Krisman Bertazi To: =?utf-8?Q?Andr=C3=A9?= Almeida Cc: Hugh Dickins , Andrew Morton , Alexander Viro , smcv@collabora.com, kernel@collabora.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Rosenberg Subject: Re: [RFC PATCH 3/4] mm: shmem: Add IOCTL support for tmpfs Organization: Collabora References: <20210323195941.69720-1-andrealmeid@collabora.com> <20210323195941.69720-4-andrealmeid@collabora.com> Date: Tue, 23 Mar 2021 18:15:01 -0400 In-Reply-To: <20210323195941.69720-4-andrealmeid@collabora.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Tue, 23 Mar 2021 16:59:40 -0300") Message-ID: <87tup1bjq2.fsf@collabora.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: umt6h9jpuas4nzqse7g7rpy9p7thi1a5 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 78787A000843 Received-SPF: none (collabora.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=bhuna.collabora.co.uk; client-ip=46.235.227.227 X-HE-DKIM-Result: none/none X-HE-Tag: 1616537704-685086 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Andr=C3=A9 Almeida writes: > Implement IOCTL operations for files to set/get file flags. Implement > the only supported flag by now, that is S_CASEFOLD. > > Signed-off-by: Andr=C3=A9 Almeida > --- > include/linux/shmem_fs.h | 4 ++ > mm/shmem.c | 84 +++++++++++++++++++++++++++++++++++++++- > 2 files changed, 87 insertions(+), 1 deletion(-) > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > index 29ee64352807..2c89c5a66508 100644 > --- a/include/linux/shmem_fs.h > +++ b/include/linux/shmem_fs.h > @@ -140,4 +140,8 @@ extern int shmem_mfill_zeropage_pte(struct mm_struct = *dst_mm, > dst_addr) ({ BUG(); 0; }) > #endif >=20=20 > +#define TMPFS_CASEFOLD_FL 0x40000000 /* Casefolded file */ > +#define TMPFS_USER_FLS TMPFS_CASEFOLD_FL /* Userspace supported flags */ > +#define TMPFS_FLS S_CASEFOLD /* Kernel supported flags */ Minor nit: FLS? _FLAGS is short enough :). > + > #endif > diff --git a/mm/shmem.c b/mm/shmem.c > index 20df81763995..2f2c996d215b 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -258,6 +258,7 @@ static inline void shmem_inode_unacct_blocks(struct i= node *inode, long pages) > static const struct super_operations shmem_ops; > const struct address_space_operations shmem_aops; > static const struct file_operations shmem_file_operations; > +static const struct file_operations shmem_dir_operations; > static const struct inode_operations shmem_inode_operations; > static const struct inode_operations shmem_dir_inode_operations; > static const struct inode_operations shmem_special_inode_operations; > @@ -2347,7 +2348,7 @@ static struct inode *shmem_get_inode(struct super_b= lock *sb, const struct inode > /* Some things misbehave if size =3D=3D 0 on a directory */ > inode->i_size =3D 2 * BOGO_DIRENT_SIZE; > inode->i_op =3D &shmem_dir_inode_operations; > - inode->i_fop =3D &simple_dir_operations; > + inode->i_fop =3D &shmem_dir_operations; > break; > case S_IFLNK: > /* > @@ -2838,6 +2839,76 @@ static long shmem_fallocate(struct file *file, int= mode, loff_t offset, > return error; > } >=20=20 > +static long shmem_ioctl(struct file *file, unsigned int cmd, unsigned lo= ng arg) > +{ > + int ret; > + u32 fsflags =3D 0, old, new =3D 0; > + struct inode *inode =3D file_inode(file); > + struct shmem_sb_info *sbinfo =3D SHMEM_SB(inode->i_sb); > + > + switch (cmd) { > + case FS_IOC_GETFLAGS: > + if ((inode->i_flags & S_CASEFOLD) && S_ISDIR(inode->i_mode)) > + fsflags |=3D TMPFS_CASEFOLD_FL; > + > + if (put_user(fsflags, (int __user *)arg)) > + return -EFAULT; > + > + return 0; > + > + case FS_IOC_SETFLAGS: > + if (get_user(fsflags, (int __user *)arg)) > + return -EFAULT; > + > + old =3D inode->i_flags; > + > + if (fsflags & ~TMPFS_USER_FLS) > + return -EINVAL; > + > + if (fsflags & TMPFS_CASEFOLD_FL) { > + if (!sbinfo->casefold) { > + pr_err("tmpfs: casefold disabled at this mount point\n"); Minor nit: no point in logging an error here. The user has simply not enabled casefolding. The error returned below should be enough. > + return -EOPNOTSUPP; > + } > + > + if (!S_ISDIR(inode->i_mode)) > + return -ENOTDIR; > + > + if (!simple_empty(file_dentry(file))) > + return -ENOTEMPTY; > + > + new |=3D S_CASEFOLD; > + } else if (old & S_CASEFOLD) { > + if (!simple_empty(file_dentry(file))) > + return -ENOTEMPTY; > + } > + > + ret =3D mnt_want_write_file(file); > + if (ret) > + return ret; > + > + inode_lock(inode); > + > + ret =3D vfs_ioc_setflags_prepare(inode, old, new); > + if (ret) { > + inode_unlock(inode); > + mnt_drop_write_file(file); > + return ret; > + } > + > + inode_set_flags(inode, new, TMPFS_FLS); > + > + inode_unlock(inode); > + mnt_drop_write_file(file); > + return 0; > + > + default: > + return -ENOTTY; > + } > + > + return 0; > +} > + > static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf) > { > struct shmem_sb_info *sbinfo =3D SHMEM_SB(dentry->d_sb); > @@ -3916,6 +3987,7 @@ static const struct file_operations shmem_file_oper= ations =3D { > .splice_read =3D generic_file_splice_read, > .splice_write =3D iter_file_splice_write, > .fallocate =3D shmem_fallocate, > + .unlocked_ioctl =3D shmem_ioctl, > #endif > }; >=20=20 > @@ -3928,6 +4000,16 @@ static const struct inode_operations shmem_inode_o= perations =3D { > #endif > }; >=20=20 > +static const struct file_operations shmem_dir_operations =3D { > + .open =3D dcache_dir_open, > + .release =3D dcache_dir_close, > + .llseek =3D dcache_dir_lseek, > + .read =3D generic_read_dir, > + .iterate_shared =3D dcache_readdir, > + .fsync =3D noop_fsync, > + .unlocked_ioctl =3D shmem_ioctl, > +}; > + > static const struct inode_operations shmem_dir_inode_operations =3D { > #ifdef CONFIG_TMPFS > .create =3D shmem_create, --=20 Gabriel Krisman Bertazi