From patchwork Fri Aug 23 17:33:30 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: 13775614 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 E75D8C5321D for ; Fri, 23 Aug 2024 17:33:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CB69800B8; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27DB9800B4; Fri, 23 Aug 2024 13:33:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F27F6800B8; Fri, 23 Aug 2024 13:33:57 -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 DAABE800B4 for ; Fri, 23 Aug 2024 13:33:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 892C5140E13 for ; Fri, 23 Aug 2024 17:33:57 +0000 (UTC) X-FDA: 82484208114.05.E5912D0 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf05.hostedemail.com (Postfix) with ESMTP id C7413100023 for ; Fri, 23 Aug 2024 17:33:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="ahX/SCZP"; spf=pass (imf05.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724434326; 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=8fGDhDblxpiWpLMEgOVUHiirq5YHZlp3LvTsoH5n4cY=; b=7qNDgP6O0EwEWUxxEMYO9+ew+PmRbTjBVX/sg2qiqseY4bSUapi3bEXRLuxTot6p0cqCq0 i5b2QjycZxt9RafZECgkTl8MnFRgwWbDGnpy3oAopFoVc2KJX8LqMk6iQB1EB3XqLprwVJ FHX80001Ozy5ZFWWUkOmKWdFEUM4upk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="ahX/SCZP"; spf=pass (imf05.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724434326; a=rsa-sha256; cv=none; b=zUAYeegH/0k4pe4pc6IHk7vJrTtfCXKRE5QXsoaK3OPxWEmMfH8ZdOZyqIc1/giweeleOY LCZk8u/xBAqYTzz2mRNGb1wklS70tDcdijxuUew9bBdw1BXzW2gcgQspmDpPQ4jV/WdW83 V2DnW+jmHJYTEk1amTqLvSgetYvuYWE= 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_Almeida?= 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?= =?utf-8?q?=C3=A9_Almeida?= 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> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C7413100023 X-Stat-Signature: wsgx3uyygzsporoz3yezpfjh4x9xt9ik X-Rspam-User: X-HE-Tag: 1724434435-568743 X-HE-Meta: U2FsdGVkX1/4PmcahR9+ZcyjD0l5Xyl0YUpSxy+qKdiRTCmxMzf1UOLHR7aYNutehTHTOPP0K9zmVLO/95AW974EWxZ/nao5SjZXJbGf/2XcMq2Z8y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hbnVT12QzXba2X9v6ms+dyjJ78ce1QkmZaX0nyL707UkP8PdyuwnWfaaQzC2J0hExbZp3QTlP0LhhSq2LLhpm+wlhbg8bYOyZDlXWe9HimzNBVx9p/a 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: 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=utf8-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=utf8-12.1.0,strict_encoding fs_name mount_dir/ 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é 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, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -4133,9 +4135,67 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { 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), {} }; +#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[] = { + {1, "%d.%d.%d"}, + {0, NULL} + }; + + strscpy(version_string, version, sizeof(version_string)); + + if (match_token(version_string, token, args) != 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_parameter *param) +{ + struct shmem_options *ctx = 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 = 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 = UNICODE_AGE(maj, min, rev); + encoding = 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 = encoding; + + return 0; +} +#else +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *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 *param) { struct shmem_options *ctx = fc->fs_private; @@ -4294,6 +4354,11 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) "Group quota inode hardlimit too large."); ctx->qlimits.grpquota_ihardlimit = size; break; + case Opt_casefold: + return shmem_parse_opt_casefold(fc, param); + case Opt_strict_encoding: + ctx->strict_encoding = true; + break; } return 0;