From nobody Fri Dec 19 06:37:42 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B61BE229126 for ; Fri, 20 Dec 2024 17:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734715326; cv=none; b=g+8gMDBFbGX3A7KxCWjPupWal9lBacoeUjt1aBO5o80W3cmiQRdfsjN79kZRw+l8zK0h0+F/F/OP+fD2JD2FT8E6Q831fVwMWpNAXPKzNM+BuA6rCQrdCBkk8C6iIPnOK+R6tOX3GOOHWRn7jZ90B21KSsXZKqesf8tdAZTTBHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734715326; c=relaxed/simple; bh=U4ln+HA5RSgu1CHawzT3bet6RKhzaN9YNxqy4EI7Iac=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=dXLuMGhZzWo8qIgDoLsuwvTlA6TmvrFtB/ikm1XuBOoL1BWS9OSPrE+vpk2ErYwFkFCfyJ9gLzEZpgfpf5CF5AosUvxk1kygbmsWR5un7taUPCpE3Q8/ZsLtIL8U2gp0AKhqoKtc+Gzcr41noNuopiT0zpMPnaFl0g4sD7UnPZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--chullee.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pKoxmaM4; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--chullee.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pKoxmaM4" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-725cf25d47bso2007430b3a.2 for ; Fri, 20 Dec 2024 09:22:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734715324; x=1735320124; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=P9Low56i6kWFMERnPlXDnXQsrHpNmKP0VHgnNh47lzM=; b=pKoxmaM4LjpJ/aHfDNPEU9SdpitP5fzolsGQDsOCWghXlaRrbV0tioqeAP4pHY6Y4a qaj3fn7c90iV5G9vUzsNhbJHVtqb8Hr9n+NJ4TLE1UOa05/kXDFS1z2mnnN5yUUE1t4M cAsNWPUYA4oD2gclJnZeK4buaTRsgNHPo01xk6lwUfaKGLZ6TSo9mKFS7blAacuhGIQx obtr2Z1I25/Q5lZV6UH4kgJXp3rK6DECyR0faKIsMPOWNsTJWI5ZnFkbDaiquNbRtOoi fOLGJHz2mOzizq0yERfkUM63yNBBNpF9izEuA23t1pzrB0l5EA6Z/s+Go1MD7+7zPWhD uAhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734715324; x=1735320124; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=P9Low56i6kWFMERnPlXDnXQsrHpNmKP0VHgnNh47lzM=; b=HqzzwvdOmshxvCGgW5BoMCuWnQ0IoBEiSmt4NK/au8ac5RC3nH+1kgEjWBTHZpbAEP us6ajsfBVnFYRz8/ia0y0gZw0SSEc58Z4w9y5Rv04Ritn7kwqlzhaGeSht7e+SNb3w/Z MqFpohXjXkYir5G4RRfcdnDy/yw5ljmyOQLVhRQqRUYhW3ZiOadE/25l34GjToGaBZGQ /6wcQUHBqeBc2xB6kpTyF+rpvLCjMSFizHg3FwlL0jnTvrThsh0zH3ClLtVnMniqkyPo Wksggn4M/zxB2QikzIAXC83/uy6gGzZE4sJgsMMvYlQiGmNGA6qhR2lqIS9YZVu4Sp1k raQQ== X-Forwarded-Encrypted: i=1; AJvYcCXBc+2nBEN6teEeNGBv3aw/zSwuSpDt51+FmPmONbcNvNOKX+YsWc0sGXib+WwXKgkefY6t9FD8V8qB3wU=@vger.kernel.org X-Gm-Message-State: AOJu0YxgITV4gE+EB+O317ivlJv5yYlc47ORgerI2NhUWZkwrQQ9M8dM Ma387BVaGyrlA5r3pkJumYf57vqWyj31r5EqvDxbHpi2zDX3xFI2YIOwv6bIScNAfZ1rHN3ZbYM TgtkrkA== X-Google-Smtp-Source: AGHT+IHOSurQEe7cBvOXyFMYUvOQ+el07sIHHf1mWVWO5u52tZNW1gMZCYlmhRBTb0opBuFfeBlaey9ha1Qq X-Received: from pfwz30.prod.google.com ([2002:a05:6a00:1d9e:b0:725:df7a:f4e3]) (user=chullee job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:ac5:b0:726:41e:b310 with SMTP id d2e1a72fcca58-72abdec84b4mr4229289b3a.12.1734715323924; Fri, 20 Dec 2024 09:22:03 -0800 (PST) Date: Fri, 20 Dec 2024 09:21:36 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220172136.1028811-1-chullee@google.com> Subject: [PATCH v2] f2fs: Introduce linear search for dentries From: Daniel Lee To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Daniel Lee Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch addresses an issue where some files in case-insensitive directories become inaccessible due to changes in how the kernel function, utf8_casefold(), generates case-folded strings from the commit 5c26d2f1d3f5 ("unicode: Don't special case ignorable code points"). F2FS uses these case-folded names to calculate hash values for locating dentries and stores them on disk. Since utf8_casefold() can produce different output across kernel versions, stored hash values and newly calculated hash values may differ. This results in affected files no longer being found via the hash-based lookup. To resolve this, the patch introduces a linear search fallback. If the initial hash-based search fails, F2FS will sequentially scan the directory entries. Fixes: 5c26d2f1d3f5 ("unicode: Don't special case ignorable code points") Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D219586 Signed-off-by: Daniel Lee --- v2: - Only update chash if use_hash is true fs/f2fs/dir.c | 40 +++++++++++++++++++++++++++++----------- fs/f2fs/f2fs.h | 6 ++++-- fs/f2fs/inline.c | 5 +++-- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 47a5c806cf16..3e8e5ddf9dbc 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -175,7 +175,8 @@ static unsigned long dir_block_index(unsigned int level, static struct f2fs_dir_entry *find_in_block(struct inode *dir, struct page *dentry_page, const struct f2fs_filename *fname, - int *max_slots) + int *max_slots, + bool use_hash) { struct f2fs_dentry_block *dentry_blk; struct f2fs_dentry_ptr d; @@ -183,7 +184,7 @@ static struct f2fs_dir_entry *find_in_block(struct inod= e *dir, dentry_blk =3D (struct f2fs_dentry_block *)page_address(dentry_page); =20 make_dentry_ptr_block(dir, &d, dentry_blk); - return f2fs_find_target_dentry(&d, fname, max_slots); + return f2fs_find_target_dentry(&d, fname, max_slots, use_hash); } =20 static inline int f2fs_match_name(const struct inode *dir, @@ -208,7 +209,8 @@ static inline int f2fs_match_name(const struct inode *d= ir, } =20 struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_pt= r *d, - const struct f2fs_filename *fname, int *max_slots) + const struct f2fs_filename *fname, int *max_slots, + bool use_hash) { struct f2fs_dir_entry *de; unsigned long bit_pos =3D 0; @@ -231,7 +233,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const st= ruct f2fs_dentry_ptr *d, continue; } =20 - if (de->hash_code =3D=3D fname->hash) { + if (!use_hash || de->hash_code =3D=3D fname->hash) { res =3D f2fs_match_name(d->inode, fname, d->filename[bit_pos], le16_to_cpu(de->name_len)); @@ -258,11 +260,12 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const = struct f2fs_dentry_ptr *d, static struct f2fs_dir_entry *find_in_level(struct inode *dir, unsigned int level, const struct f2fs_filename *fname, - struct page **res_page) + struct page **res_page, + bool use_hash) { int s =3D GET_DENTRY_SLOTS(fname->disk_name.len); unsigned int nbucket, nblock; - unsigned int bidx, end_block; + unsigned int bidx, end_block, bucket_no; struct page *dentry_page; struct f2fs_dir_entry *de =3D NULL; pgoff_t next_pgofs; @@ -272,8 +275,11 @@ static struct f2fs_dir_entry *find_in_level(struct ino= de *dir, nbucket =3D dir_buckets(level, F2FS_I(dir)->i_dir_level); nblock =3D bucket_blocks(level); =20 + bucket_no =3D use_hash ? le32_to_cpu(fname->hash) % nbucket : 0; + +start_find_bucket: bidx =3D dir_block_index(level, F2FS_I(dir)->i_dir_level, - le32_to_cpu(fname->hash) % nbucket); + bucket_no); end_block =3D bidx + nblock; =20 while (bidx < end_block) { @@ -290,7 +296,7 @@ static struct f2fs_dir_entry *find_in_level(struct inod= e *dir, } } =20 - de =3D find_in_block(dir, dentry_page, fname, &max_slots); + de =3D find_in_block(dir, dentry_page, fname, &max_slots, use_hash); if (IS_ERR(de)) { *res_page =3D ERR_CAST(de); de =3D NULL; @@ -307,7 +313,10 @@ static struct f2fs_dir_entry *find_in_level(struct ino= de *dir, bidx++; } =20 - if (!de && room && F2FS_I(dir)->chash !=3D fname->hash) { + if (!use_hash && !de && ++bucket_no < nbucket) + goto start_find_bucket; + + if (use_hash && !de && room && F2FS_I(dir)->chash !=3D fname->hash) { F2FS_I(dir)->chash =3D fname->hash; F2FS_I(dir)->clevel =3D level; } @@ -323,11 +332,13 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode= *dir, struct f2fs_dir_entry *de =3D NULL; unsigned int max_depth; unsigned int level; + bool use_hash =3D true; =20 *res_page =3D NULL; =20 +start_find_entry: if (f2fs_has_inline_dentry(dir)) { - de =3D f2fs_find_in_inline_dir(dir, fname, res_page); + de =3D f2fs_find_in_inline_dir(dir, fname, res_page, use_hash); goto out; } =20 @@ -343,11 +354,18 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode= *dir, } =20 for (level =3D 0; level < max_depth; level++) { - de =3D find_in_level(dir, level, fname, res_page); + de =3D find_in_level(dir, level, fname, res_page, use_hash); if (de || IS_ERR(*res_page)) break; } + out: +#if IS_ENABLED(CONFIG_UNICODE) + if (IS_CASEFOLDED(dir) && !de && use_hash) { + use_hash =3D false; + goto start_find_entry; + } +#endif /* This is to increase the speed of f2fs_create */ if (!de) F2FS_I(dir)->task =3D current; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f523dd302bf6..1afebb9c4061 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3588,7 +3588,8 @@ int f2fs_prepare_lookup(struct inode *dir, struct den= try *dentry, struct f2fs_filename *fname); void f2fs_free_filename(struct f2fs_filename *fname); struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_pt= r *d, - const struct f2fs_filename *fname, int *max_slots); + const struct f2fs_filename *fname, int *max_slots, + bool use_hash); int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, unsigned int start_pos, struct fscrypt_str *fstr); void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, @@ -4224,7 +4225,8 @@ int f2fs_write_inline_data(struct inode *inode, struc= t folio *folio); int f2fs_recover_inline_data(struct inode *inode, struct page *npage); struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, const struct f2fs_filename *fname, - struct page **res_page); + struct page **res_page, + bool use_hash); int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, struct page *ipage); int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *f= name, diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index cbd2a0d34804..3e3c35d4c98b 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -352,7 +352,8 @@ int f2fs_recover_inline_data(struct inode *inode, struc= t page *npage) =20 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, const struct f2fs_filename *fname, - struct page **res_page) + struct page **res_page, + bool use_hash) { struct f2fs_sb_info *sbi =3D F2FS_SB(dir->i_sb); struct f2fs_dir_entry *de; @@ -369,7 +370,7 @@ struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct i= node *dir, inline_dentry =3D inline_data_addr(dir, ipage); =20 make_dentry_ptr_inline(dir, &d, inline_dentry); - de =3D f2fs_find_target_dentry(&d, fname, NULL); + de =3D f2fs_find_target_dentry(&d, fname, NULL, use_hash); unlock_page(ipage); if (IS_ERR(de)) { *res_page =3D ERR_CAST(de); --=20 2.47.1.613.gc27f4b7a9f-goog