linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Almeida" <andrealmeid@igalia.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>, Theodore Tso <tytso@mit.edu>,
	Gabriel Krisman Bertazi <krisman@kernel.org>,
	linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	kernel-dev@igalia.com
Subject: Re: [PATCH v5 4/9] ovl: Create ovl_casefold() to support casefolded strncmp()
Date: Fri, 22 Aug 2025 11:07:14 -0300	[thread overview]
Message-ID: <c1e1f4b3-e3a0-4a9a-982d-9fd6f6e96090@igalia.com> (raw)
In-Reply-To: <CAOQ4uxiX+ZURzvNdJw+UJw-2OTS5DRGr4LLr9YnHjjPKOv57TA@mail.gmail.com>

Em 17/08/2025 11:33, Amir Goldstein escreveu:
> On Thu, Aug 14, 2025 at 7:22 PM André Almeida <andrealmeid@igalia.com> wrote:
>>
>> To add overlayfs support casefold layers, create a new function
>> ovl_casefold(), to be able to do case-insensitive strncmp().
>>
>> ovl_casefold() allocates a new buffer and stores the casefolded version
>> of the string on it. If the allocation or the casefold operation fails,
>> fallback to use the original string.
>>
>> The case-insentive name is then used in the rb-tree search/insertion
>> operation. If the name is found in the rb-tree, the name can be
>> discarded and the buffer is freed. If the name isn't found, it's then
>> stored at struct ovl_cache_entry to be used later.
>>
>> Signed-off-by: André Almeida <andrealmeid@igalia.com>
>> ---
>> Changes from v4:
>>   - Move the consumer/free buffer logic out to the caller
>>   - s/aux/c_name
>>
>> Changes from v3:
>>   - Improve commit message text
>>   - s/OVL_NAME_LEN/NAME_MAX
>>   - drop #ifdef in favor of if(IS_ENABLED)
>>   - use new helper sb_encoding
>>   - merged patch "Store casefold name..." and "Create ovl_casefold()..."
>>   - Guard all the casefolding inside of IS_ENABLED(UNICODE)
>>
>> Changes from v2:
>> - Refactor the patch to do a single kmalloc() per rb_tree operation
>> - Instead of casefolding the cache entry name everytime per strncmp(),
>>    casefold it once and reuse it for every strncmp().
>> ---
>>   fs/overlayfs/readdir.c | 115 +++++++++++++++++++++++++++++++++++++++++--------
>>   1 file changed, 97 insertions(+), 18 deletions(-)
>>
>> diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
>> index b65cdfce31ce27172d28d879559f1008b9c87320..803ac6a7516d0156ae7793ee1ff884dbbf2e20b0 100644
>> --- a/fs/overlayfs/readdir.c
>> +++ b/fs/overlayfs/readdir.c
>> @@ -27,6 +27,8 @@ struct ovl_cache_entry {
>>          bool is_upper;
>>          bool is_whiteout;
>>          bool check_xwhiteout;
>> +       const char *cf_name;
>> +       int cf_len;
> 
> We should also change these member names to c_name
> Because they are the "compare/canonicalized" name, which
> may or may not be casefolded.
> 
>>          char name[];
>>   };
>>
>> @@ -45,6 +47,7 @@ struct ovl_readdir_data {
>>          struct list_head *list;
>>          struct list_head middle;
>>          struct ovl_cache_entry *first_maybe_whiteout;
>> +       struct unicode_map *map;
>>          int count;
>>          int err;
>>          bool is_upper;
>> @@ -66,6 +69,27 @@ static struct ovl_cache_entry *ovl_cache_entry_from_node(struct rb_node *n)
>>          return rb_entry(n, struct ovl_cache_entry, node);
>>   }
>>
>> +static int ovl_casefold(struct unicode_map *map, const char *str, int len, char **dst)
>> +{
>> +       const struct qstr qstr = { .name = str, .len = len };
>> +       int cf_len;
>> +
>> +       if (!IS_ENABLED(CONFIG_UNICODE) || !map || is_dot_dotdot(str, len))
>> +               return 0;
>> +
>> +       *dst = kmalloc(NAME_MAX, GFP_KERNEL);
>> +
>> +       if (dst) {
>> +               cf_len = utf8_casefold(map, &qstr, *dst, NAME_MAX);
>> +
>> +               if (cf_len > 0)
>> +                       return cf_len;
>> +       }
>> +
>> +       kfree(*dst);
>> +       return 0;
>> +}
>> +
>>   static bool ovl_cache_entry_find_link(const char *name, int len,
>>                                        struct rb_node ***link,
>>                                        struct rb_node **parent)
>> @@ -79,7 +103,7 @@ static bool ovl_cache_entry_find_link(const char *name, int len,
>>
>>                  *parent = *newp;
>>                  tmp = ovl_cache_entry_from_node(*newp);
>> -               cmp = strncmp(name, tmp->name, len);
>> +               cmp = strncmp(name, tmp->cf_name, tmp->cf_len);
>>                  if (cmp > 0)
>>                          newp = &tmp->node.rb_right;
>>                  else if (cmp < 0 || len < tmp->len)
> 
> This looks like a bug - should be len < tmp->c_len
> 
>> @@ -101,7 +125,7 @@ static struct ovl_cache_entry *ovl_cache_entry_find(struct rb_root *root,
>>          while (node) {
>>                  struct ovl_cache_entry *p = ovl_cache_entry_from_node(node);
>>
>> -               cmp = strncmp(name, p->name, len);
>> +               cmp = strncmp(name, p->cf_name, p->cf_len);
>>                  if (cmp > 0)
>>                          node = p->node.rb_right;
>>                  else if (cmp < 0 || len < p->len)
> 
> Same here.
> 
> But it's not the only bug, because this patch regresses 3 fstests without
> enabling any casefolding:
> 

That was due to the following change:

-               cmp = strncmp(name, p->name, len);
+               cmp = strncmp(name, p->cf_name, p->cf_len);

Keeping len (instead of p->cf_len) as the third argument fixed it. I 
will send a v6 with that and the other changes.

> overlay/038 12s ...  [14:16:39] [14:16:50]- output mismatch (see
> /results/overlay/results-large/overlay/038.out.bad)
>      --- tests/overlay/038.out 2025-05-25 08:52:54.000000000 +0000
>      +++ /results/overlay/results-large/overlay/038.out.bad 2025-08-17
> 14:16:50.549367654 +0000
>      @@ -1,2 +1,3 @@
>       QA output created by 038
>      +Merged dir: Invalid d_ino reported for ..
>       Silence is golden
> 
> overlay/041 11s ...  [14:16:54] [14:17:05]- output mismatch (see
> /results/overlay/results-large/overlay/041.out.bad)
>      --- tests/overlay/041.out 2025-05-25 08:52:54.000000000 +0000
>      +++ /results/overlay/results-large/overlay/041.out.bad 2025-08-17
> 14:17:05.275206922 +0000
>      @@ -1,2 +1,3 @@
>       QA output created by 041
>      +Merged dir: Invalid d_ino reported for ..
>       Silence is golden
> 
> overlay/077 19s ...  [14:17:08][  107.348626] WARNING: CPU: 3 PID:
> 5414 at fs/overlayfs/readdir.c:677 ovl_dir_read_impure+0x178/0x1c0
> [  107.354647] ---[ end trace 0000000000000000 ]---
> [  107.399525] WARNING: CPU: 2 PID: 5415 at fs/overlayfs/readdir.c:677
> ovl_dir_read_impure+0x178/0x1c0
> [  107.406826] ---[ end trace 0000000000000000 ]---
> _check_dmesg: something found in dmesg (see
> /results/overlay/results-large/overlay/077.dmesg)
>   [14:17:28]- output mismatch (see
> /results/overlay/results-large/overlay/077.out.bad)
>      --- tests/overlay/077.out 2025-05-25 08:52:54.000000000 +0000
>      +++ /results/overlay/results-large/overlay/077.out.bad 2025-08-17
> 14:17:28.762250671 +0000
>      @@ -1,2 +1,6 @@
>       QA output created by 077
>      +getdents: Input/output error
>      +Missing created file in impure upper dir (see
> /results/overlay/results-large/overlay/077.full for details)
>      +getdents: Input/output error
>      +Found unlinked file in impure upper dir (see
> /results/overlay/results-large/overlay/077.full for details)
>       Silence is golden
> 
> Thanks,
> Amir.


  reply	other threads:[~2025-08-22 14:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-14 17:22 [PATCH v5 0/9] ovl: Enable support for casefold layers André Almeida
2025-08-14 17:22 ` [PATCH v5 1/9] fs: Create sb_encoding() helper André Almeida
2025-08-14 17:22 ` [PATCH v5 2/9] fs: Create sb_same_encoding() helper André Almeida
2025-08-14 17:22 ` [PATCH v5 3/9] ovl: Prepare for mounting case-insensitive enabled layers André Almeida
2025-08-14 18:47   ` Amir Goldstein
2025-08-14 17:22 ` [PATCH v5 4/9] ovl: Create ovl_casefold() to support casefolded strncmp() André Almeida
2025-08-14 18:59   ` Amir Goldstein
2025-08-15 16:16   ` Amir Goldstein
2025-08-15 16:53     ` André Almeida
2025-08-17 14:33   ` Amir Goldstein
2025-08-22 14:07     ` André Almeida [this message]
2025-08-14 17:22 ` [PATCH v5 5/9] ovl: Ensure that all layers have the same encoding André Almeida
2025-08-14 17:22 ` [PATCH v5 6/9] ovl: Set case-insensitive dentry operations for ovl sb André Almeida
2025-08-15 11:52   ` kernel test robot
2025-08-14 17:22 ` [PATCH v5 7/9] ovl: Add S_CASEFOLD as part of the inode flag to be copied André Almeida
2025-08-14 17:22 ` [PATCH v5 8/9] ovl: Check for casefold consistency when creating new dentries André Almeida
2025-08-14 18:54   ` Amir Goldstein
2025-08-14 17:22 ` [PATCH v5 9/9] ovl: Support mounting case-insensitive enabled layers André Almeida
2025-08-14 18:48   ` Amir Goldstein
2025-08-14 17:30 ` [PATCH v5 0/9] ovl: Enable support for casefold layers André Almeida
2025-08-14 19:06   ` Amir Goldstein
2025-08-15 13:33     ` André Almeida
2025-08-15 13:50       ` Amir Goldstein
2025-08-17 15:03         ` Amir Goldstein
2025-08-22 14:15           ` André Almeida
2025-08-22 17:21             ` Amir Goldstein
2025-08-22 17:39               ` André Almeida

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1e1f4b3-e3a0-4a9a-982d-9fd6f6e96090@igalia.com \
    --to=andrealmeid@igalia.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=kernel-dev@igalia.com \
    --cc=krisman@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).