From nobody Mon Feb 9 07:57:23 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8F62192D6E; Fri, 23 Aug 2024 17:33:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434435; cv=none; b=glYazH4aR07Ne8xj7PrTLWr3qbpFcYZa2gc+jiriHvJDUqdqwWCm5ss4faoDho2jfPV14T8R9sD8bvbkerN9xEaB0bDIpnOwjSC/o80vDmdZtiKneeMg0PFau+T9qlPxEpFq1V62MMP3Zp1Z190jqC9Gga4AgX0nSRLQw29Nsxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434435; c=relaxed/simple; bh=AruGVonuzSs4DUN+CPHVatkIT6NULghpsW4KvVqvfuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=b2v/1FHcL2oCKaiwurTJpPKkSHcI1shrD0kJxSUdseyhcyCznWJlMlG8iZkh0HRNbkkmTHDqS/5xNeYc5vzZEp4ZhcWQqRKt2tWeNfuLkSR+IaEGAtWnZHba9N1DvXpazPc901SP4EYijdPhKz5i/bWNkGT31aMt1RYcF9+hQ1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=pwiLiZ0j; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="pwiLiZ0j" 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=y9QOgUnGmMfOXt3imEXMFmKZoYcPek4W3U8ViHPXL9E=; b=pwiLiZ0jOOthH9F2SeGr7Suney P0Qx8u9N4jscQ8YEczpVwDus5CS5wSiBL8Q9JsZhhRGxJRkTX8IiRtNuQFZszoxBK03p4c1oSyO3s g4yUreFx0v96lY3zFE7qXYo8AX3nJhsPHPruhMF0sZGug7HQDKPfggxEmM+NFMM8rFc9MkUpAN6nk LmoJGYx0+rsiURnMC6sIdfZN0J4JMV31wPv+kreX3IYbO57f3UBjGJw5GTJrWztr6FCQR+bwveXV4 w9xbxxMZzi9mpFMK/8maAtNIi7nebYcTsBC/mFVqnktHaptQjcHwYl79abuigeUzxB1H02SMuQdXv IqpaWIaA==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAP-0048Ww-Nr; Fri, 23 Aug 2024 19:33:41 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 1/5] tmpfs: Add casefold lookup support Date: Fri, 23 Aug 2024 14:33:28 -0300 Message-ID: <20240823173332.281211-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Enable casefold lookup in tmpfs, based on the enconding defined by userspace. That means that instead of comparing byte per byte a file name, it compares to a case-insensitive equivalent of the Unicode string. * dcache handling There's a special need when dealing with case-insensitive dentries. First of all, we currently invalidated every negative casefold dentries. That happens because currently VFS code has no proper support to deal with that, giving that it could incorrectly reuse a previous filename for a new file that has a casefold match. For instance, this could happen: $ mkdir DIR $ rm -r DIR $ mkdir dir $ ls DIR/ And would be perceived as inconsistency from userspace point of view, because even that we match files in a case-insensitive manner, we still honor whatever is the initial filename. Along with that, tmpfs stores only the first equivalent name dentry used in the dcache, preventing duplications of dentries in the dcache. The d_compare() version for casefold files stores a normalized string, and before every lookup, the filename is normalized as well, achieving a casefolded lookup. Signed-off-by: Andr=C3=A9 Almeida --- include/linux/shmem_fs.h | 1 + mm/shmem.c | 63 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1d06b1e5408a..1a1196b077a6 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -73,6 +73,7 @@ struct shmem_sb_info { struct list_head shrinklist; /* List of shinkable inodes */ unsigned long shrinklist_len; /* Length of shrinklist */ struct shmem_quota_limits qlimits; /* Default quota limits */ + bool casefold; }; =20 static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index 5a77acf6ac6a..aa272c62f811 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "swap.h" =20 static struct vfsmount *shm_mnt __ro_after_init; @@ -123,6 +125,8 @@ struct shmem_options { bool noswap; unsigned short quota_types; struct shmem_quota_limits qlimits; + struct unicode_map *encoding; + bool strict_encoding; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 @@ -3427,6 +3431,12 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *d= ir, if (IS_ERR(inode)) return PTR_ERR(inode); =20 +#if IS_ENABLED(CONFIG_UNICODE) + if (sb_has_strict_encoding(dir->i_sb) && IS_CASEFOLDED(dir) && + dir->i_sb->s_encoding && utf8_validate(dir->i_sb->s_encoding, &dentry= ->d_name)) + return -EINVAL; +#endif + error =3D simple_acl_create(dir, inode); if (error) goto out_iput; @@ -3435,6 +3445,9 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *di= r, if (error && error !=3D -EOPNOTSUPP) goto out_iput; =20 + if (IS_CASEFOLDED(dir)) + d_add(dentry, NULL); + error =3D simple_offset_add(shmem_get_offset_ctx(dir), dentry); if (error) goto out_iput; @@ -3526,6 +3539,9 @@ static int shmem_link(struct dentry *old_dentry, stru= ct inode *dir, goto out; } =20 + if (IS_CASEFOLDED(dir)) + d_add(dentry, NULL); + dir->i_size +=3D BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode))); @@ -3553,6 +3569,14 @@ static int shmem_unlink(struct inode *dir, struct de= ntry *dentry) inode_inc_iversion(dir); drop_nlink(inode); dput(dentry); /* Undo the count from "create" - does all the work */ + + /* + * For now, VFS can't deal with case-insensitive negative dentries, so + * we destroy them + */ + if (IS_CASEFOLDED(dir)) + d_invalidate(dentry); + return 0; } =20 @@ -3697,6 +3721,8 @@ static int shmem_symlink(struct mnt_idmap *idmap, str= uct inode *dir, dir->i_size +=3D BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); inode_inc_iversion(dir); + if (IS_CASEFOLDED(dir)) + d_add(dentry, NULL); d_instantiate(dentry, inode); dget(dentry); return 0; @@ -4471,6 +4497,11 @@ static void shmem_put_super(struct super_block *sb) { struct shmem_sb_info *sbinfo =3D SHMEM_SB(sb); =20 +#if IS_ENABLED(CONFIG_UNICODE) + if (sbinfo->casefold) + utf8_unload(sb->s_encoding); +#endif + #ifdef CONFIG_TMPFS_QUOTA shmem_disable_quotas(sb); #endif @@ -4515,6 +4546,17 @@ static int shmem_fill_super(struct super_block *sb, = struct fs_context *fc) } sb->s_export_op =3D &shmem_export_ops; sb->s_flags |=3D SB_NOSEC | SB_I_VERSION; + +#if IS_ENABLED(CONFIG_UNICODE) + if (ctx->encoding) { + sb->s_encoding =3D ctx->encoding; + generic_set_sb_d_ops(sb); + if (ctx->strict_encoding) + sb->s_encoding_flags =3D SB_ENC_STRICT_MODE_FL; + sbinfo->casefold =3D true; + } +#endif + #else sb->s_flags |=3D SB_NOUSER; #endif @@ -4704,11 +4746,28 @@ static const struct inode_operations shmem_inode_op= erations =3D { #endif }; =20 +static struct dentry *shmem_lookup(struct inode *dir, struct dentry *dentr= y, unsigned int flags) +{ + if (dentry->d_name.len > NAME_MAX) + return ERR_PTR(-ENAMETOOLONG); + + /* + * For now, VFS can't deal with case-insensitive negative dentries, so + * we prevent them from being created + */ + if (IS_CASEFOLDED(dir)) + return NULL; + + d_add(dentry, NULL); + + return NULL; +} + static const struct inode_operations shmem_dir_inode_operations =3D { #ifdef CONFIG_TMPFS .getattr =3D shmem_getattr, .create =3D shmem_create, - .lookup =3D simple_lookup, + .lookup =3D shmem_lookup, .link =3D shmem_link, .unlink =3D shmem_unlink, .symlink =3D shmem_symlink, @@ -4791,6 +4850,8 @@ int shmem_init_fs_context(struct fs_context *fc) ctx->uid =3D current_fsuid(); ctx->gid =3D current_fsgid(); =20 + ctx->encoding =3D NULL; + fc->fs_private =3D ctx; fc->ops =3D &shmem_fs_context_ops; return 0; --=20 2.46.0 From nobody Mon Feb 9 07:57:23 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0508819340F; Fri, 23 Aug 2024 17:33:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434438; cv=none; b=bFYQQYDEWS4QvBMqZtsomIHc34BYrnFANzpPaqY6ZRyu+eHE6xOJ/kilwtY+W7VvEtnuYrZ8R4iREyqK4a3/qpc8mbaWyGM3WEMo6zEpF7qzJ1GCYiAAgYvi17OS9xmADSDpBenPGnIKStOLG9uwg/FgeCyGGJVPLWudCeAAWtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434438; c=relaxed/simple; bh=iQpoigWzX/rCtHnlrNJZvORb33k7MxgvPTAPsaqq3PE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZUEEcHQTSSaJ6KceKHhyYfaSncrhGfpXjwRFNiytv3BUpssi6PJxFyH3+Mz2NXwy5s75C0z3ZAvxCCLM3i5Uz3q8CJVoCP7e2b9JxejXoaviKbeMYRou+T07hPcDiloDjSxiY2p6AZm8zaSU/AImNG5N2wqRW7aukU2Yc1ufwnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=rgKiTFkM; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="rgKiTFkM" 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=kaq/p7WWGkDPfkYXS5iXH7ESr86fZs1bSaN+LK5hniQ=; b=rgKiTFkMBobH15FQLLakWX0RAP BzP7Bp1kevVfr/cme/57GIHDALcfZ1lGwmnKxIOM8WrPIuby9AUXJoXDxgvGKgXGCC4Tg00Mn+AoA MRwGNdt7ymV7BBzymaAUEy+K4L/XWHkOfS2vHUhT01/y29VxGZB2kQzsZ+r0Rh2DWs1MtmEx5cINo m9Qwyn8bOOMGlztD8IvEGcPOaG9zZAZ3C88BD6FJiA0XbC5/Fn0JrT1l8HcxCWzaV/B1wKTyC6FHx QnbSrwG7cY3a8z8U1I/DStbyOAsUzfEDxqYSNaQfB7UIK6RD6zfcc6pgfwJgZUZndopllnDW7+VVS Znx9VXCg==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAT-0048Ww-Do; Fri, 23 Aug 2024 19:33:45 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 2/5] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Fri, 23 Aug 2024 14:33:29 -0300 Message-ID: <20240823173332.281211-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=A9 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 1a1196b077a6..acec92564122 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; }; =20 -#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_CASEF= OLD_FL) +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) =20 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 aa272c62f811..67b6ab580ca2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2617,9 +2617,26 @@ static int shmem_initxattrs(struct inode *, const st= ruct 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 fsflag= s) +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags= , struct dentry *dentry) { - unsigned int i_flags =3D 0; + unsigned int i_flags =3D 0, old =3D inode->i_flags; + struct shmem_sb_info *sbinfo =3D SHMEM_SB(inode->i_sb); + + if (fsflags & FS_CASEFOLD_FL) { + if (!sbinfo->casefold) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + + i_flags |=3D S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } =20 if (fsflags & FS_NOATIME_FL) i_flags |=3D S_NOATIME; @@ -2630,10 +2647,12 @@ static void shmem_set_inode_flags(struct inode *ino= de, 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_CA= SEFOLD); + + return 0; } #else -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflag= s) +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflag= s, struct dentry *dentry) { } #define shmem_initxattrs NULL @@ -2680,7 +2699,7 @@ static struct inode *__shmem_get_inode(struct mnt_idm= ap *idmap, info->fsflags =3D (dir =3D=3D 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); @@ -3788,16 +3807,23 @@ static int shmem_fileattr_set(struct mnt_idmap *idm= ap, { struct inode *inode =3D d_inode(dentry); struct shmem_inode_info *info =3D SHMEM_I(inode); + int ret, flags; =20 if (fileattr_has_fsx(fa)) return -EOPNOTSUPP; if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) return -EOPNOTSUPP; =20 - info->fsflags =3D (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | + flags =3D (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | (fa->flags & SHMEM_FL_USER_MODIFIABLE); =20 - shmem_set_inode_flags(inode, info->fsflags); + ret =3D shmem_set_inode_flags(inode, flags, dentry); + + if (ret) + return ret; + + info->fsflags =3D flags; + inode_set_ctime_current(inode); inode_inc_iversion(inode); return 0; --=20 2.46.0 From nobody Mon Feb 9 07:57:23 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CE82193414; Fri, 23 Aug 2024 17:33:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434439; cv=none; b=IGKexgUAZmpGCLaEheHwYi3cGETXwd2HSiYTOtAjscjjaxmljrlc/86vwUvwbdsoEuoMZr4OSQpjBXg8YqDPODDI+CZPrHlrGWeDv407iWsl/KW/OtgbTOlklwenBRNPuC6iJDI7oWmLP3QH7Bzbv851cgI2HJi/fF2qU3dc/J4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434439; c=relaxed/simple; bh=oAkC2gyEvYqie2BMaBkOi+Q3ObXHcVC5/ivUbijOClQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qZRuncdbpYe55kaCks6pH3qOGG76erjM+eteQAMe/E7nuf4CEv46XIu24K8xTpnV04+yuc7IpOQqZ/N4NKPgHMExlrNLxwjjGWBNipyo/d7ZSC7m0x3Qr5O+qjrzk7QpaWLfpy4SYowfS6ke7eERN+BFjsoL1eUAPd1cOLHEmMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ahX/SCZP; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ahX/SCZP" 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=8fGDhDblxpiWpLMEgOVUHiirq5YHZlp3LvTsoH5n4cY=; b=ahX/SCZPOOraUkYBrU/yJolT6B Kaff1CccaDHutwJ9fMceTjyx8yuoufIaCaSXL4xLmYLVu4Ez7dQW4SgRl1UX9kBjwJDz/csOehy2U 2PLh06v/HDwbslSyxxYPnjW9iFO/fRPxH+3yRnP9tzLA97V7wyfigHZCPaLAOYmap67CMl+cAf/Hr k0mPm5XcFUDm4G95UQzuKEKhDVaDMKnqS+ZZEPQuaSb0073EAbelrlCU5MXEQkXoBOtRuL5jj6PgG Xx0bNvwyYLrQ1BkNMqP/KAVd/YO9auXgQEg00LEbCQKYOPATfIhN5QBeZBa6ymMaIfap3YL9tbNqU yROXwNDw==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAX-0048Ww-3i; Fri, 23 Aug 2024 19:33:49 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 3/5] tmpfs: Create casefold mount options Date: Fri, 23 Aug 2024 14:33:30 -0300 Message-ID: <20240823173332.281211-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Most filesystems have their data stored in disk, so casefold option need to be enabled when building a filesystem on a device (via mkfs). However, as tmpfs is a RAM backed filesystem, there's no disk information and thus no mkfs to store information about casefold. For tmpfs, create casefold options for mounting. Userspace can then enable casefold support for a mount point using: $ mount -t tmpfs -o casefold=3Dutf8-12.1.0 fs_name mount_dir/ Userspace must set what Unicode standard is aiming to. The available options depends on what the kernel Unicode subsystem supports. And for strict encoding: $ mount -t tmpfs -o casefold=3Dutf8-12.1.0,strict_encoding fs_name mount_di= r/ Strict encoding means that tmpfs will refuse to create invalid UTF-8 sequences. When this option is not enabled, any invalid sequence will be treated as an opaque byte sequence, ignoring the encoding thus not being able to be looked up in a case-insensitive way. Signed-off-by: Andr=C3=A9 Almeida --- mm/shmem.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 67b6ab580ca2..5c77b4e73204 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4102,6 +4102,8 @@ enum shmem_param { Opt_usrquota_inode_hardlimit, Opt_grpquota_block_hardlimit, Opt_grpquota_inode_hardlimit, + Opt_casefold, + Opt_strict_encoding, }; =20 static const struct constant_table shmem_param_enums_huge[] =3D { @@ -4133,9 +4135,67 @@ const struct fs_parameter_spec shmem_fs_parameters[]= =3D { fsparam_string("grpquota_block_hardlimit", Opt_grpquota_block_hardlimit), fsparam_string("grpquota_inode_hardlimit", Opt_grpquota_inode_hardlimit), #endif + fsparam_string("casefold", Opt_casefold), + fsparam_flag ("strict_encoding", Opt_strict_encoding), {} }; =20 +#if IS_ENABLED(CONFIG_UNICODE) +static int utf8_parse_version(const char *version, unsigned int *maj, + unsigned int *min, unsigned int *rev) +{ + substring_t args[3]; + char version_string[12]; + static const struct match_token token[] =3D { + {1, "%d.%d.%d"}, + {0, NULL} + }; + + strscpy(version_string, version, sizeof(version_string)); + + if (match_token(version_string, token, args) !=3D 1) + return -EINVAL; + + if (match_int(&args[0], maj) || match_int(&args[1], min) || + match_int(&args[2], rev)) + return -EINVAL; + + return 0; +} + +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_param= eter *param) +{ + struct shmem_options *ctx =3D fc->fs_private; + unsigned int maj, min, rev, version_number; + char version[10]; + int ret; + struct unicode_map *encoding; + + if (strncmp(param->string, "utf8-", 5)) + return invalfc(fc, "Only utf8 encondings are supported"); + ret =3D strscpy(version, param->string + 5, sizeof(version)); + if (ret < 0) + return invalfc(fc, "Invalid enconding argument: %s", + param->string); + + utf8_parse_version(version, &maj, &min, &rev); + version_number =3D UNICODE_AGE(maj, min, rev); + encoding =3D utf8_load(version_number); + if (IS_ERR(encoding)) + return invalfc(fc, "Invalid utf8 version: %s", version); + pr_info("tmpfs: Using encoding provided by mount options: %s\n", + param->string); + ctx->encoding =3D encoding; + + return 0; +} +#else +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_param= eter *param) +{ + return invalfc(fc, "tmpfs: No kernel support for casefold filesystems\n"); +} +#endif + static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *par= am) { struct shmem_options *ctx =3D fc->fs_private; @@ -4294,6 +4354,11 @@ static int shmem_parse_one(struct fs_context *fc, st= ruct fs_parameter *param) "Group quota inode hardlimit too large."); ctx->qlimits.grpquota_ihardlimit =3D size; break; + case Opt_casefold: + return shmem_parse_opt_casefold(fc, param); + case Opt_strict_encoding: + ctx->strict_encoding =3D true; + break; } return 0; =20 --=20 2.46.0 From nobody Mon Feb 9 07:57:23 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A67E194A49; Fri, 23 Aug 2024 17:34:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434443; cv=none; b=FpwSBpnj9LqViBhRTmNA63fiZIePipT6Sx9u9EmOl3OcSFAXjzr5HBRerZl4XdoL7B4lqgzAx2+BEc/bQfj3owQfWxkiB61kchAqwlq5TjS1xGlzklAWG4L3EmuGwwVoQ46gtV5tgpm2nEPOdzTpJCe/cM4yWrJJUwBF9Mu8vIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434443; c=relaxed/simple; bh=GuM/my+ueJwwiTYUV31nvUyJgTzMIZtZX3DKI/64XoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gYtN+3bKqlMIs91L8KKPXVk6QQdgknLGOIHnyTXtEOcys+xKjk+qp9wZWwo7JcrFVQc04hKzRcpBxZhbayOhuSSPbWpfVraMEyG+D0zSTltzJfgr3G6YCf/oRFCS8d386EkGjv8tEPzWvLK76y106hDM0x3Wm82lA7NMem8vJNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ma3Xhzs3; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ma3Xhzs3" 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=zap4iol6rqGSjG5PpDRAFuTwCuOL01NSJqIIbGm2kbw=; b=ma3Xhzs3EwKomj3mpglFRwcABm abpsMnv+HGliRBrfAeREW4zYsafdnHo80mfj+l0CnjSX0kFp/aBnkN8w8WfuU/be7Rfj4RXbN4UiT gIBa9vYSVbaAHcRm60M3BeSNazFmJtScWkAV4emfUMWDIocYFhxQ0Yo32MR1/xvsGg4q77vk2kFaT wuVBFl4Z0Vy6wWRk8cgnfivmp3BEQHW/cDf2xwKHWFmhIosfhPZpDDxzEvOs/cD0QMWf+v2VB9+kg rq2TOD5vgs/K6zW7MmrTryws+94SffwMgyL21J5JMcLrd+rBnEPavyd0LNxej8vw5mE/rYY00xTKx fMbvGxGw==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAa-0048Ww-Pr; Fri, 23 Aug 2024 19:33:52 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 4/5] tmpfs: Expose filesystem features via sysfs Date: Fri, 23 Aug 2024 14:33:31 -0300 Message-ID: <20240823173332.281211-5-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Expose filesystem features through sysfs, so userspace can query if tmpfs support casefold. This follows the same setup as defined by ext4 and f2fs to expose casefold support to userspace. Signed-off-by: Andr=C3=A9 Almeida --- mm/shmem.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 5c77b4e73204..f6e19b88d647 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5384,3 +5384,40 @@ struct page *shmem_read_mapping_page_gfp(struct addr= ess_space *mapping, return page; } EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp); + +#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) +#if IS_ENABLED(CONFIG_UNICODE) +DEVICE_STRING_ATTR_RO(casefold, 0444, "supported"); +#endif + +static struct attribute *tmpfs_attributes[] =3D { +#if IS_ENABLED(CONFIG_UNICODE) + &dev_attr_casefold.attr.attr, +#endif + NULL +}; + +static const struct attribute_group tmpfs_attribute_group =3D { + .attrs =3D tmpfs_attributes, + .name =3D "features" +}; + +static struct kobject *tmpfs_kobj; + +static int __init tmpfs_sysfs_init(void) +{ + int ret; + + tmpfs_kobj =3D kobject_create_and_add("tmpfs", fs_kobj); + if (!tmpfs_kobj) + return -ENOMEM; + + ret =3D sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group); + if (ret) + kobject_put(tmpfs_kobj); + + return ret; +} + +fs_initcall(tmpfs_sysfs_init); +#endif /* CONFIG_SYSFS && CONFIG_TMPFS */ --=20 2.46.0 From nobody Mon Feb 9 07:57:23 2026 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF6E9194ACF; Fri, 23 Aug 2024 17:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434446; cv=none; b=dB6kF+4Rf24kpC5qjOB7m+ricXIHHpaN2q4KK9HSoYkMyXrh87C8cDlSL8hHhuRF6NdjmxwfrKAJ6T4a3pc8nr3GQFB/SLbwL4jSOuuYmfwLG7JWgxeJS6nGlvy0fSwUWseXDXcFircuHUVRG0EbXmpC0cFVlIPsmlGXVYw/tg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724434446; c=relaxed/simple; bh=SGEJQAX7zN+2ZikPoQ/1/lVDHKXUFqezT0IpKco/jLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ukI+61NALA8nTABzb0PgTSPPf56lx1gOC283jZqW/OCtyynPNyZVnC41GOxvfVtcZsBMWLspbgJYHcApnvrguxPcYVETWAlOSVVuFtN6X2lk1d9zuq3YhDj32RQKxUutjfHwVvHfGvnfr0GOO6IIK69j+5uBlYT8JUUfJ2lmvds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=e8//f4fU; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="e8//f4fU" 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=2uckVKN0pdzCghR0p6/g82d2/8anRVmY8PvlKYt2nuo=; b=e8//f4fU6MKCA9/tuu/dsGqQQ3 10S/BJHzanaeCer9+DrWQVreL3F7xlH9HYJd0vxHwUaIRtL/OucvWMqQwlqWVqrCvj3VSIUVSlitE UbhWC8PtfsjPdD39u5eU6XrL+u0fb99yGwGCoVh01Uf1P2QOX/PSQ2OZfivbUlOBF+vgNq+pe3TD4 MSoXXhtt7JjGQd4gTbRCq+hDgqxXWCqY21pgTTEKwILl5CDL2g38xAca75f4hbuj2TOcKjXvKnnzV LLezTv2tJ49sZBQKp2/u0m6i+E8bKg2Avu4NtztNs8tb1rnOLjECeS6kcvVsXYCS07oBAweVfjgOe 2iDDM1Qw==; Received: from [179.118.186.198] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1shYAe-0048Ww-Fj; Fri, 23 Aug 2024 19:33:56 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, krisman@kernel.org, Daniel Rosenberg , smcv@collabora.com, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH 5/5] docs: tmpfs: Add casefold options Date: Fri, 23 Aug 2024 14:33:32 -0300 Message-ID: <20240823173332.281211-6-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240823173332.281211-1-andrealmeid@igalia.com> References: <20240823173332.281211-1-andrealmeid@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Document mounting options for casefold support in tmpfs. Signed-off-by: Andr=C3=A9 Almeida --- Documentation/filesystems/tmpfs.rst | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystem= s/tmpfs.rst index 56a26c843dbe..ce24fb16979a 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -241,6 +241,41 @@ So 'mount -t tmpfs -o size=3D10G,nr_inodes=3D10k,mode= =3D700 tmpfs /mytmpfs' will give you tmpfs instance on /mytmpfs which can allocate 10GB RAM/SWAP in 10240 inodes and it is only accessible by root. =20 +tmpfs has the following mounting options for case-insesitive lookups suppo= rt: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +casefold Enable casefold support at this mount point using the gi= ven + argument as the encoding standard. Currently only utf8 + encodings are supported. +strict_encoding Enable strict encoding at this mount point (disabled by + default). This means that invalid sequences will be reje= cted + by the file system. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +Note that this option doesn't enable casefold by default; one needs to set +casefold flag per directory, setting the +F attribute in an empty director= y. New +directories within a casefolded one will inherit the flag. + +Example:: + + $ mount -t tmpfs -o casefold=3Dutf8-12.1.0,cf_strict fs_name /mytmpfs + $ cd /mytmpfs # case-sensitive by default + $ touch a; touch A + $ ls + A a + $ mkdir B + $ cd b + cd: The directory 'b' does not exist + $ mkdir casefold_dir + $ chattr +F casefold_dir/ # marking it as case-insensitive + $ cd + $ touch dir/a; touch dir/A + $ ls dir + a + $ mkdir B + $ cd b + $ pwd + /home/user/mytmpfs/casefold_dir/B =20 :Author: Christoph Rohland , 1.12.01 @@ -250,3 +285,5 @@ RAM/SWAP in 10240 inodes and it is only accessible by r= oot. KOSAKI Motohiro, 16 Mar 2010 :Updated: Chris Down, 13 July 2020 +:Updated: + Andr=C3=A9 Almeida, 23 Aug 2024 --=20 2.46.0