From patchwork Mon Sep 2 22:55:08 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: 13787776 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 04321CA0ED3 for ; Mon, 2 Sep 2024 22:55:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8675C8D0118; Mon, 2 Sep 2024 18:55:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EF216B03B6; Mon, 2 Sep 2024 18:55:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 691B58D0118; Mon, 2 Sep 2024 18:55:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 414DC6B03B5 for ; Mon, 2 Sep 2024 18:55:54 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BB1D7140473 for ; Mon, 2 Sep 2024 22:55:53 +0000 (UTC) X-FDA: 82521307386.11.EC12252 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf20.hostedemail.com (Postfix) with ESMTP id 1A7971C0002 for ; Mon, 2 Sep 2024 22:55:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=MUkc6dP8; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf20.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725317647; 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=/2i9Fi4oBPYgwH3vxA7dodmgTyqTZhVfRjdU73qonMA=; b=EFt1Qlkp6Z01tpN3kFC14tFzR4z9XIvgWrEGm6LMD3oMZpsLC2aiKj4U7fu5Kue+Wbcdv9 wjuGR/QdPox+GRRQJmnHxoyxH+BjpNAWrvH3XUPwixDrFuApbSgG6NN6On4az0u5fUwDaM 2x9qXMyuQTibXAzFJ4SvDmdNzADdA4Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725317647; a=rsa-sha256; cv=none; b=IcQVIbh5IiuQaQLthLd+CXZkM3s6SWlI1TOklxw/hdis8n7Re70f052QOiTTN2NhLAiJ3f 8NwUmdKQhhRYfiJTNyg+tTOpK8X7r5rx026nxmCC4JPM2FIdpE0FEohoHKJzFA6Gt7z7Cw MuPIULH7RfV/zoNL9+pvqoEdhjbXc5c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=MUkc6dP8; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf20.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=/2i9Fi4oBPYgwH3vxA7dodmgTyqTZhVfRjdU73qonMA=; b=MUkc6dP85J2EBxkw+6Qhzqiask MAcs/wENfzy2vgBdutdU+tLIzXJHJWvEXb+YKkQW4Cx1+KivoxLgdp3qtjc/V+dl5Mw+sg5vM6Mrm g05+BAjToGNLTCLlRVR6RBSyAhwVC+4Dz+00uGwTlQFGMCk1Apd3HRWvIsSOKYt02cbWaM19ftwbV iE8x2tByMFC1mef3SLSQ0rErkGSYtUhHFaKVr9ZE2fPU7zbzRMfWkP9bXEohOWSrK9t+1b00v1OYc 21dU82fo9APqJY4Sqr+jD5E6+XiS76JLMSuod904d+98gnOSPV+8ajywtt96wblst17BIJ9tonnyZ wEL0cOGA==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1slFxY-008VrL-95; Tue, 03 Sep 2024 00:55:44 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 6/8] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Mon, 2 Sep 2024 19:55:08 -0300 Message-ID: <20240902225511.757831-7-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240902225511.757831-1-andrealmeid@igalia.com> References: <20240902225511.757831-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1A7971C0002 X-Stat-Signature: 4wqm3tg3ekfb43yi5u9afteirkp7x6np X-Rspam-User: X-HE-Tag: 1725317751-411507 X-HE-Meta: U2FsdGVkX1+5CN9amgiADrS6jW8Wm4yCPBoBe+AlWzcGCC3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hchnVGgCMEv/Dq6ixUMCw1O2DZeZQLwsaBfr+dILL8wn4nEVdH3+hCQHj88fPhmRaoywNFzlxUpCPnrng8AWfzX92cLt3UkQFURWnkTPnArqokR4HXpSFSP6N2WI6L4a2l3mfjbMNkonTE6/Yb+GybSqLZPiQlxYPdDnQ5imEXPEMS4JPO+DgDb+aRg/VWjC49Lq4mBpT25tCUbJ2CG3zChCKhBNpMtw0Y4ckuglWNEpHb2OA= 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. Signed-off-by: André Almeida --- include/linux/shmem_fs.h | 6 +++--- mm/shmem.c | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1d06b1e5408a..8367ca2b99d9 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 0f918010bc54..9a0fc7636629 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2617,9 +2617,26 @@ static int shmem_initxattrs(struct inode *, const struct xattr *, void *); * 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; + unsigned int i_flags = 0, old = inode->i_flags; + struct super_block *sb = inode->i_sb; + + if (fsflags & FS_CASEFOLD_FL) { + if (!sb->s_encoding) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + + i_flags |= S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } if (fsflags & FS_NOATIME_FL) i_flags |= S_NOATIME; @@ -2630,10 +2647,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 @@ -2680,7 +2699,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); @@ -3790,16 +3809,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;