From patchwork Mon Oct 21 16:37:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13844444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC398D15DBB for ; Mon, 21 Oct 2024 16:38:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A7826B009A; Mon, 21 Oct 2024 12:38:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6570C6B009B; Mon, 21 Oct 2024 12:38:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 520186B009C; Mon, 21 Oct 2024 12:38:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 33AA16B009A for ; Mon, 21 Oct 2024 12:38:17 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ECEAE12064D for ; Mon, 21 Oct 2024 16:38:02 +0000 (UTC) X-FDA: 82698166572.30.EAA5BBE Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf17.hostedemail.com (Postfix) with ESMTP id 8CAF840014 for ; Mon, 21 Oct 2024 16:38:03 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=ssz0k7vO; spf=pass (imf17.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729528618; a=rsa-sha256; cv=none; b=tIvIXCisx4tDwE3MdE5PEZUZ/K1esHK+IYnU19qtXzB9f3nETMZ80SBsqIbys386H2M7dB aFasjbOUpkmOnn8JLiasQ7o4FLQCiOiuSTkZ0LEemlhjan7rZARwIXA08gtlRjEaJaIA1L 5GiZ+RAcZLAekS+8mdWRpIz4kAU1g00= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=ssz0k7vO; spf=pass (imf17.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729528618; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q02ijIMJQIrChEbtR3X8eciq/6AW4aNz0epCTvb52no=; b=2cdCNEYhlW61QLtaOxStDi2kIhkPjEUTvdRFLcazs5zeaFfxTxW6YyHz0/doMLQ7r+OV7b FuDcXtDBOnVqkHa+V76M8ARmF/9gj0YdQPDFFulpYBnDPMNoKxG0aOZ5z3xCSRkXeROlK/ etN+2M7kvE4q3Hg+Y6cicMDGCL8kai0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=q02ijIMJQIrChEbtR3X8eciq/6AW4aNz0epCTvb52no=; b=ssz0k7vOogf/9lEXxWRLIbMC5m 40jx4wEKB2ZtppeN9mWGSaUBES5N5lWdcKfi0hwIOJgHsvASvu5gPHgDrFaAVBTQ6YkkzXKH3ZAXK 6C56v9dkdm8F8B6ifSxy93lAyBcQ9tAi+lAnmf8WqLGyYF2RlwB7g7DjF+9Y53d5tubzSwaHaPKGy 9zz04KLihV1oNnW7o4YG6j0R/Lg6LTuJg1uBMupZrF3+QfPlfu0Ya6rr6g+uG70qT+3iwnQshutQK leTL/FWI3B08fsxeZNbECooKTflrDqrm8LQdBO0eftBeBz67ztuJne0g/1pNTuwkGxDqvn1U6tGxs l4Hnu3aA==; Received: from [191.204.195.205] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t2vQ2-00DECf-G9; Mon, 21 Oct 2024 18:38:10 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Mon, 21 Oct 2024 13:37:23 -0300 Subject: [PATCH v8 7/9] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs MIME-Version: 1.0 Message-Id: <20241021-tonyk-tmpfs-v8-7-f443d5814194@igalia.com> References: <20241021-tonyk-tmpfs-v8-0-f443d5814194@igalia.com> In-Reply-To: <20241021-tonyk-tmpfs-v8-0-f443d5814194@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Gabriel Krisman Bertazi , Gabriel Krisman Bertazi , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 X-Stat-Signature: een98jxtxtfenejgyd8mikuexgjmomkp X-Rspamd-Queue-Id: 8CAF840014 X-Rspam-User: X-Rspam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v4XNK8kaw/6cCRe/akBy+B1l99gWThxu2GLroYYyFkMbZ8dvYJ18LKHrIuK8dRSzp/XaylSFAVGYmjdf2tCcyxQnNPpdThUoo0mUKijcxZginn3+t7CdyYMkVkoQs4FBkLkvNylbcvWZWEi152FA/bgjBABIshxNzFCkJ5S7UxRfB4GaidakRb6KVewx1zSaGUrgpF65ZiKMbQyRKKsv2cjawtosRcseL40PdrvsDX23sPObi22aff6VbTl4TWdLwqldvYhfvCORjWY1uDZmgiL3BHWBKnZNXj3m4MXJyyMs6qHO1/W5THFqVH9iIpF3frM1RHixXpB090Fr01mrsTK9gcGuQyGQwZadmiZyHuF8iGcmUOcbc3O7DJp1PJ+vhT7e3ZP50= 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: List-Subscribe: List-Unsubscribe: Enable setting flag FS_CASEFOLD_FL for tmpfs directories, when tmpfs is mounted with casefold support. A special check is need for this flag, since it can't be set for non-empty directories. Reviewed-by: Gabriel Krisman Bertazi Reviewed-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida --- Changes from v2: - Fixed bug when adding a non-casefold flag in a non-empty dir --- include/linux/shmem_fs.h | 6 ++--- mm/shmem.c | 70 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 515a9a6a3c6f82c55952d821887514217a6a00d1..018da28c01e7d71b8fb00bfb23c000248c8a83f4 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -42,10 +42,10 @@ struct shmem_inode_info { struct inode vfs_inode; }; -#define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE +#define SHMEM_FL_USER_VISIBLE (FS_FL_USER_VISIBLE | FS_CASEFOLD_FL) #define SHMEM_FL_USER_MODIFIABLE \ - (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) -#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) + (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) struct shmem_quota_limits { qsize_t usrquota_bhardlimit; /* Default user quota block hard limit */ diff --git a/mm/shmem.c b/mm/shmem.c index f26488ff3d6ae1abb9b63d55ca74909249dbf4eb..ea01628e443423d82d44277e085b867ab9bf4b28 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2757,13 +2757,62 @@ static int shmem_file_open(struct inode *inode, struct file *file) #ifdef CONFIG_TMPFS_XATTR static int shmem_initxattrs(struct inode *, const struct xattr *, void *); +#if IS_ENABLED(CONFIG_UNICODE) +/* + * shmem_inode_casefold_flags - Deal with casefold file attribute flag + * + * The casefold file attribute needs some special checks. I can just be added to + * an empty dir, and can't be removed from a non-empty dir. + */ +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + unsigned int old = inode->i_flags; + struct super_block *sb = inode->i_sb; + + if (fsflags & FS_CASEFOLD_FL) { + if (!(old & S_CASEFOLD)) { + if (!sb->s_encoding) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + *i_flags = *i_flags | S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + return 0; +} +#else +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + if (fsflags & FS_CASEFOLD_FL) + return -EOPNOTSUPP; + + return 0; +} +#endif + /* * chattr's fsflags are unrelated to extended attributes, * but tmpfs has chosen to enable them under the same config option. */ -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { unsigned int i_flags = 0; + int ret; + + ret = shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags); + if (ret) + return ret; if (fsflags & FS_NOATIME_FL) i_flags |= S_NOATIME; @@ -2774,10 +2823,12 @@ static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) /* * But FS_NODUMP_FL does not require any action in i_flags. */ - inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE); + inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE | S_CASEFOLD); + + return 0; } #else -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { } #define shmem_initxattrs NULL @@ -2824,7 +2875,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, info->fsflags = (dir == NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; if (info->fsflags) - shmem_set_inode_flags(inode, info->fsflags); + shmem_set_inode_flags(inode, info->fsflags, NULL); INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); simple_xattrs_init(&info->xattrs); @@ -3931,16 +3982,23 @@ static int shmem_fileattr_set(struct mnt_idmap *idmap, { struct inode *inode = d_inode(dentry); struct shmem_inode_info *info = SHMEM_I(inode); + int ret, flags; if (fileattr_has_fsx(fa)) return -EOPNOTSUPP; if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) return -EOPNOTSUPP; - info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | + flags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | (fa->flags & SHMEM_FL_USER_MODIFIABLE); - shmem_set_inode_flags(inode, info->fsflags); + ret = shmem_set_inode_flags(inode, flags, dentry); + + if (ret) + return ret; + + info->fsflags = flags; + inode_set_ctime_current(inode); inode_inc_iversion(inode); return 0;