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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable 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 E7120C433C1 for ; Tue, 23 Mar 2021 20:19:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB8F6619D2 for ; Tue, 23 Mar 2021 20:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233222AbhCWUTR convert rfc822-to-8bit (ORCPT ); Tue, 23 Mar 2021 16:19:17 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54200 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbhCWUSr (ORCPT ); Tue, 23 Mar 2021 16:18:47 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 988EC1F40FE7 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 2/4] mm: shmem: Support case-insensitive file name lookups Organization: Collabora References: <20210323195941.69720-1-andrealmeid@collabora.com> <20210323195941.69720-3-andrealmeid@collabora.com> Date: Tue, 23 Mar 2021 16:18:43 -0400 In-Reply-To: <20210323195941.69720-3-andrealmeid@collabora.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Tue, 23 Mar 2021 16:59:39 -0300") Message-ID: <877dlxd3oc.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: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org André Almeida writes: > This patch implements the support for case-insensitive file name lookups > in tmpfs, based on the encoding passed in the mount options. Thanks for doing this. > > +#ifdef CONFIG_UNICODE > +static const struct dentry_operations casefold_dentry_ops = { > + .d_hash = generic_ci_d_hash, > + .d_compare = generic_ci_d_compare, > +}; > +#endif Why not reuse struct generic_ci_dentry_ops ? > + > /* > * shmem_file_setup pre-accounts the whole fixed size of a VM object, > * for shared memory and for shared anonymous (/dev/zero) mappings > @@ -2859,8 +2869,18 @@ shmem_mknod(struct user_namespace *mnt_userns, struct inode *dir, > struct inode *inode; > int error = -ENOSPC; > > +#ifdef CONFIG_UNICODE > + struct super_block *sb = dir->i_sb; > + > + if (sb_has_strict_encoding(sb) && IS_CASEFOLDED(dir) && > + sb->s_encoding && utf8_validate(sb->s_encoding, &dentry->d_name)) > + return -EINVAL; > +#endif > + > inode = shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE); > if (inode) { > + inode->i_flags |= dir->i_flags; > + > error = simple_acl_create(dir, inode); > if (error) > goto out_iput; > @@ -2870,6 +2890,9 @@ shmem_mknod(struct user_namespace *mnt_userns, struct inode *dir, > if (error && error != -EOPNOTSUPP) > goto out_iput; > > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > + > error = 0; > dir->i_size += BOGO_DIRENT_SIZE; > dir->i_ctime = dir->i_mtime = current_time(dir); > @@ -2925,6 +2948,19 @@ static int shmem_create(struct user_namespace *mnt_userns, struct inode *dir, > return shmem_mknod(&init_user_ns, dir, dentry, mode | S_IFREG, 0); > } > > +static struct dentry *shmem_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) > +{ > + if (dentry->d_name.len > NAME_MAX) > + return ERR_PTR(-ENAMETOOLONG); > + > + if (IS_CASEFOLDED(dir)) > + return NULL; I think this deserves a comment explaining why it is necessary. > + > + d_add(dentry, NULL); > + > + return NULL; > +} > + > /* > * Link a file.. > */ > @@ -2946,6 +2982,9 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentr > goto out; > } > > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > + > dir->i_size += BOGO_DIRENT_SIZE; > inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); > inc_nlink(inode); > @@ -2967,6 +3006,10 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) > inode->i_ctime = dir->i_ctime = dir->i_mtime = current_time(inode); > drop_nlink(inode); > dput(dentry); /* Undo the count from "create" - this does all the work */ > + > + if (IS_CASEFOLDED(dir)) > + d_invalidate(dentry); > + > return 0; > } > > @@ -3128,6 +3171,8 @@ static int shmem_symlink(struct user_namespace *mnt_userns, struct inode *dir, > } > dir->i_size += BOGO_DIRENT_SIZE; > dir->i_ctime = dir->i_mtime = current_time(dir); > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > d_instantiate(dentry, inode); > dget(dentry); > return 0; > @@ -3364,6 +3409,8 @@ enum shmem_param { > Opt_uid, > Opt_inode32, > Opt_inode64, > + Opt_casefold, > + Opt_cf_strict, > }; > > static const struct constant_table shmem_param_enums_huge[] = { > @@ -3385,6 +3432,8 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { > fsparam_u32 ("uid", Opt_uid), > fsparam_flag ("inode32", Opt_inode32), > fsparam_flag ("inode64", Opt_inode64), > + fsparam_string("casefold", Opt_casefold), > + fsparam_flag ("cf_strict", Opt_cf_strict), > {} > }; > > @@ -3392,9 +3441,11 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) > { > struct shmem_options *ctx = fc->fs_private; > struct fs_parse_result result; > + struct unicode_map *encoding; > unsigned long long size; > + char version[10]; > char *rest; > - int opt; > + int opt, ret; > > opt = fs_parse(fc, shmem_fs_parameters, param, &result); > if (opt < 0) > @@ -3468,6 +3519,23 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) > ctx->full_inums = true; > ctx->seen |= SHMEM_SEEN_INUMS; > break; > + case Opt_casefold: > + if (strncmp(param->string, "utf8-", 5)) > + return invalfc(fc, "Only utf8 encondings are supported"); > + ret = strscpy(version, param->string + 5, sizeof(version)); Ugh. Now we are doing two strscpy for the parse api (in unicode_load). Can change the unicode_load api to reuse it? thanks, -- Gabriel Krisman Bertazi 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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 CB380C433C1 for ; Tue, 23 Mar 2021 20:18:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B5A8619A3 for ; Tue, 23 Mar 2021 20:18:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B5A8619A3 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 E658E8D001B; Tue, 23 Mar 2021 16:18:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E16C88D0017; Tue, 23 Mar 2021 16:18:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8F828D001B; Tue, 23 Mar 2021 16:18:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id A96F38D0017 for ; Tue, 23 Mar 2021 16:18:48 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 600422488 for ; Tue, 23 Mar 2021 20:18:48 +0000 (UTC) X-FDA: 77952252336.28.BE239F7 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by imf02.hostedemail.com (Postfix) with ESMTP id CA0DA407F8F7 for ; Tue, 23 Mar 2021 20:18:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 988EC1F40FE7 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 2/4] mm: shmem: Support case-insensitive file name lookups Organization: Collabora References: <20210323195941.69720-1-andrealmeid@collabora.com> <20210323195941.69720-3-andrealmeid@collabora.com> Date: Tue, 23 Mar 2021 16:18:43 -0400 In-Reply-To: <20210323195941.69720-3-andrealmeid@collabora.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Tue, 23 Mar 2021 16:59:39 -0300") Message-ID: <877dlxd3oc.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: igoth8mcqjo53u5gny8fd85oyy693qxw X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CA0DA407F8F7 Received-SPF: none (collabora.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=bhuna.collabora.co.uk; client-ip=46.235.227.227 X-HE-DKIM-Result: none/none X-HE-Tag: 1616530726-313606 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: > This patch implements the support for case-insensitive file name lookups > in tmpfs, based on the encoding passed in the mount options. Thanks for doing this. >=20=20 > +#ifdef CONFIG_UNICODE > +static const struct dentry_operations casefold_dentry_ops =3D { > + .d_hash =3D generic_ci_d_hash, > + .d_compare =3D generic_ci_d_compare, > +}; > +#endif Why not reuse struct generic_ci_dentry_ops ? > + > /* > * shmem_file_setup pre-accounts the whole fixed size of a VM object, > * for shared memory and for shared anonymous (/dev/zero) mappings > @@ -2859,8 +2869,18 @@ shmem_mknod(struct user_namespace *mnt_userns, str= uct inode *dir, > struct inode *inode; > int error =3D -ENOSPC; >=20=20 > +#ifdef CONFIG_UNICODE > + struct super_block *sb =3D dir->i_sb; > + > + if (sb_has_strict_encoding(sb) && IS_CASEFOLDED(dir) && > + sb->s_encoding && utf8_validate(sb->s_encoding, &dentry->d_name)) > + return -EINVAL; > +#endif > + > inode =3D shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE); > if (inode) { > + inode->i_flags |=3D dir->i_flags; > + > error =3D simple_acl_create(dir, inode); > if (error) > goto out_iput; > @@ -2870,6 +2890,9 @@ shmem_mknod(struct user_namespace *mnt_userns, stru= ct inode *dir, > if (error && error !=3D -EOPNOTSUPP) > goto out_iput; >=20=20 > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > + > error =3D 0; > dir->i_size +=3D BOGO_DIRENT_SIZE; > dir->i_ctime =3D dir->i_mtime =3D current_time(dir); > @@ -2925,6 +2948,19 @@ static int shmem_create(struct user_namespace *mnt= _userns, struct inode *dir, > return shmem_mknod(&init_user_ns, dir, dentry, mode | S_IFREG, 0); > } >=20=20 > +static struct dentry *shmem_lookup(struct inode *dir, struct dentry *den= try, unsigned int flags) > +{ > + if (dentry->d_name.len > NAME_MAX) > + return ERR_PTR(-ENAMETOOLONG); > + > + if (IS_CASEFOLDED(dir)) > + return NULL; I think this deserves a comment explaining why it is necessary. > + > + d_add(dentry, NULL); > + > + return NULL; > +} > + > /* > * Link a file.. > */ > @@ -2946,6 +2982,9 @@ static int shmem_link(struct dentry *old_dentry, st= ruct inode *dir, struct dentr > goto out; > } >=20=20 > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > + > dir->i_size +=3D BOGO_DIRENT_SIZE; > inode->i_ctime =3D dir->i_ctime =3D dir->i_mtime =3D current_time(inode= ); > inc_nlink(inode); > @@ -2967,6 +3006,10 @@ static int shmem_unlink(struct inode *dir, struct = dentry *dentry) > inode->i_ctime =3D dir->i_ctime =3D dir->i_mtime =3D current_time(inode= ); > drop_nlink(inode); > dput(dentry); /* Undo the count from "create" - this does all the work = */ > + > + if (IS_CASEFOLDED(dir)) > + d_invalidate(dentry); > + > return 0; > } >=20=20 > @@ -3128,6 +3171,8 @@ static int shmem_symlink(struct user_namespace *mnt= _userns, struct inode *dir, > } > dir->i_size +=3D BOGO_DIRENT_SIZE; > dir->i_ctime =3D dir->i_mtime =3D current_time(dir); > + if (IS_CASEFOLDED(dir)) > + d_add(dentry, NULL); > d_instantiate(dentry, inode); > dget(dentry); > return 0; > @@ -3364,6 +3409,8 @@ enum shmem_param { > Opt_uid, > Opt_inode32, > Opt_inode64, > + Opt_casefold, > + Opt_cf_strict, > }; >=20=20 > static const struct constant_table shmem_param_enums_huge[] =3D { > @@ -3385,6 +3432,8 @@ const struct fs_parameter_spec shmem_fs_parameters[= ] =3D { > fsparam_u32 ("uid", Opt_uid), > fsparam_flag ("inode32", Opt_inode32), > fsparam_flag ("inode64", Opt_inode64), > + fsparam_string("casefold", Opt_casefold), > + fsparam_flag ("cf_strict", Opt_cf_strict), > {} > }; >=20=20 > @@ -3392,9 +3441,11 @@ static int shmem_parse_one(struct fs_context *fc, = struct fs_parameter *param) > { > struct shmem_options *ctx =3D fc->fs_private; > struct fs_parse_result result; > + struct unicode_map *encoding; > unsigned long long size; > + char version[10]; > char *rest; > - int opt; > + int opt, ret; >=20=20 > opt =3D fs_parse(fc, shmem_fs_parameters, param, &result); > if (opt < 0) > @@ -3468,6 +3519,23 @@ static int shmem_parse_one(struct fs_context *fc, = struct fs_parameter *param) > ctx->full_inums =3D true; > ctx->seen |=3D SHMEM_SEEN_INUMS; > break; > + case Opt_casefold: > + if (strncmp(param->string, "utf8-", 5)) > + return invalfc(fc, "Only utf8 encondings are supported"); > + ret =3D strscpy(version, param->string + 5, sizeof(version)); Ugh. Now we are doing two strscpy for the parse api (in unicode_load). Can change the unicode_load api to reuse it? thanks, --=20 Gabriel Krisman Bertazi