Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp302860lqs; Tue, 5 Mar 2024 02:28:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWConUPd1kN6c9KdBUmbzzlZhinIMgGmBn86dwRu3QzF6XdOv3nRMzH+OVDNJBU9xfbfLzzEKppqZeKBc9GnjSyXt3hLt7vTbtK526Xxg== X-Google-Smtp-Source: AGHT+IHnFxEhEWa2uvyRVgG1qWnElppXAgAkI16dRwb+Jxhsl4Ipq3HmEHI+nVKe+sdvhouOQDCO X-Received: by 2002:a05:622a:350:b0:42e:ecab:582 with SMTP id r16-20020a05622a035000b0042eecab0582mr1632033qtw.68.1709634494603; Tue, 05 Mar 2024 02:28:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709634494; cv=pass; d=google.com; s=arc-20160816; b=H2s5JjV81ZFZKaIT+Q0pEEv/0AgsevG0ujXIDqY/1zmfYy+7b7uPj1Id4diI7N5EjN VxuXGNOq9u5K1cuiUKklFWgpGn+Vk84Pxn39TTjYJ381CYeNvO4P+0e6jnT5FPaCWGVB 8/KRRIgJHzd5X+PNDPQ3x6fncjb7pNxNP0iABA7IeJXQ0tzP9XqsRxOVi0psxQwmTDtY yyYr4AI/eRj4f7FT/xTTuPDxHE20+C2syOzektaHxP4Lfs0zzD3zPfqZA9l1/By5vPzt xDsGJBfz+E2UJMTZFWkVtQ4zjGZ24Dv0ZZWzlkWGW6V96UaXnALC/xyfTRMA1jAtcNbz fQ3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Y+576T2zlJf/T96ttCw1wYW3ds7cfnnF4NUeK+n5QJk=; fh=zf0NNkRrVzzNLxoWnmq9qpFBuYVKEQmjRPQIjT6JsCY=; b=04r3CWDltXG3s0QX0ofrHoD1OugljzVkous1uriXj1vG71Qn+t651ZHZIk3tfIYTLq af9s/16RtVQTdYJ8MLVntXa542YeH3zF1dw5k4pJoJf2wm7mag3Weyvv4f1l0Qb1GZzT YfSyi0FvZsQfLccqhBVubVEsWsDsUfLQ4grpKhnnzEYhTa/K9y6RyeOfCIv3pVToptaG pDU7OWZAHwyXeWC2mSn3DXlbZokxEr4jrEwKY/d0WN0cOO4t3dLfRZNZFSvr/5wTSXqV a23reEWsxSuvYqM8pMsjqB0ypiMDWcrMJ1B1Z9yMljTqJtbvLaSTmYNmRgLXznFpudW5 HV3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yHfXeb9v; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-ext4+bounces-1510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n3-20020a05622a11c300b0042ec4b2f237si7200668qtk.669.2024.03.05.02.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 02:28:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yHfXeb9v; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-ext4+bounces-1510-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1510-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4A7091C2195E for ; Tue, 5 Mar 2024 10:28:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 99765634E3; Tue, 5 Mar 2024 10:16:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="yHfXeb9v" X-Original-To: linux-ext4@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 8B1C3633ED; Tue, 5 Mar 2024 10:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709633795; cv=none; b=A+NuPCvPC/LmIIWYKypD8vLLMwEZOK3mX127253DAEHBaS4xOvlQdnOZ1Xw9YxjOiiJfQ4CWCU9me/dJPlGkPA4hDgOf5lK9QS7H27n2Q7SVoV3GiSi84Hljtao/a1VnN+7fzypvLcbqBRPoXs15ed56fiZqd2nSWkLjY5PRLko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709633795; c=relaxed/simple; bh=a7kWb5e0su0761d+6CdvJvWCOKmDe94YCWGARHADOUc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CskgPcFaWzP2VflIElDJqLQ2uBYro3OdeHxXhzIfyjnaTNVeg8mRXC/ZXnCPsbjMTyGt4JmXrAzEJRQ/yhMZDFTv8ke9G37PiqOP6bg7iwpQyzTmThGXTujeRDpDHI5wBdYRGSEjZBxK/W3V1spVWMXSptZKfvQYQCKzZBkW8B0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=yHfXeb9v; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709633791; bh=a7kWb5e0su0761d+6CdvJvWCOKmDe94YCWGARHADOUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yHfXeb9vM1uwBAPt120Ay9uAEm5rAxd+qoxfWi7QzUO1oU7vjyWoA2SmtIpEXJg2W 5KOj2C3xP64hAf5ceUCRS6N+BnZNCiX7abF9Tg2TYqelrQaMNZk0/oZjl7sTQ+nQtr Rxr8e7J/6763SVa2ZjhRc7OpYGMmK4JKg+QYZEMTYUHuCmdi+TvTMHjFvkedWhzpR9 kKIYT6HIc4DTvhUClDLn7o6cg7/I1y2CHGOhlZ5vXGHMXm/n8hdC9kLQP5hxiw4HPf VIIgN/ASQH+sKMLMYb/zUyZyPJOFJdrZZgLx063ujD85/AU3B81XSDshQJn75EO88h Re6JA9i61UUXg== Received: from eugen-station.domain.com (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B6E6C37820AF; Tue, 5 Mar 2024 10:16:27 +0000 (UTC) From: Eugen Hristev To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@collabora.com, eugen.hristev@collabora.com, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, krisman@suse.de, Gabriel Krisman Bertazi Subject: [PATCH v13 2/9] f2fs: Simplify the handling of cached insensitive names Date: Tue, 5 Mar 2024 12:16:01 +0200 Message-Id: <20240305101608.67943-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240305101608.67943-1-eugen.hristev@collabora.com> References: <20240305101608.67943-1-eugen.hristev@collabora.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Gabriel Krisman Bertazi Keeping it as qstr avoids the unnecessary conversion in f2fs_match Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3 and minor changes] Signed-off-by: Eugen Hristev --- fs/f2fs/dir.c | 51 +++++++++++++++++++++++++--------------------- fs/f2fs/f2fs.h | 16 ++++++++++++++- fs/f2fs/recovery.c | 5 +---- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 042593aed1ec..266279b82afc 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -42,35 +42,47 @@ static unsigned int bucket_blocks(unsigned int level) return 4; } +#if IS_ENABLED(CONFIG_UNICODE) /* If @dir is casefolded, initialize @fname->cf_name from @fname->usr_fname. */ int f2fs_init_casefolded_name(const struct inode *dir, struct f2fs_filename *fname) { -#if IS_ENABLED(CONFIG_UNICODE) struct super_block *sb = dir->i_sb; + unsigned char *buf; + int len; if (IS_CASEFOLDED(dir) && !is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) { - fname->cf_name.name = f2fs_kmem_cache_alloc(f2fs_cf_name_slab, - GFP_NOFS, false, F2FS_SB(sb)); - if (!fname->cf_name.name) + buf = f2fs_kmem_cache_alloc(f2fs_cf_name_slab, + GFP_NOFS, false, F2FS_SB(sb)); + if (!buf) return -ENOMEM; - fname->cf_name.len = utf8_casefold(sb->s_encoding, - fname->usr_fname, - fname->cf_name.name, - F2FS_NAME_LEN); - if ((int)fname->cf_name.len <= 0) { - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; + + len = utf8_casefold(sb->s_encoding, fname->usr_fname, + buf, F2FS_NAME_LEN); + if (len <= 0) { + kmem_cache_free(f2fs_cf_name_slab, buf); if (sb_has_strict_encoding(sb)) return -EINVAL; /* fall back to treating name as opaque byte sequence */ + return 0; } + fname->cf_name.name = buf; + fname->cf_name.len = len; } -#endif + return 0; } +void f2fs_free_casefolded_name(struct f2fs_filename *fname) +{ + unsigned char *buf = (unsigned char *)fname->cf_name.name; + + kmem_cache_free(f2fs_cf_name_slab, buf); + fname->cf_name.name = NULL; +} +#endif /* CONFIG_UNICODE */ + static int __f2fs_setup_filename(const struct inode *dir, const struct fscrypt_name *crypt_name, struct f2fs_filename *fname) @@ -142,12 +154,7 @@ void f2fs_free_filename(struct f2fs_filename *fname) kfree(fname->crypto_buf.name); fname->crypto_buf.name = NULL; #endif -#if IS_ENABLED(CONFIG_UNICODE) - if (fname->cf_name.name) { - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; - } -#endif + f2fs_free_casefolded_name(fname); } static unsigned long dir_block_index(unsigned int level, @@ -235,11 +242,9 @@ static inline int f2fs_match_name(const struct inode *dir, struct fscrypt_name f; #if IS_ENABLED(CONFIG_UNICODE) - if (fname->cf_name.name) { - struct qstr cf = FSTR_TO_QSTR(&fname->cf_name); - - return f2fs_match_ci_name(dir, &cf, de_name, de_name_len); - } + if (fname->cf_name.name) + return f2fs_match_ci_name(dir, &fname->cf_name, + de_name, de_name_len); #endif f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 65294e3b0bef..4f68c58718fb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -524,7 +524,7 @@ struct f2fs_filename { * internal operation where usr_fname is also NULL. In all these cases * we fall back to treating the name as an opaque byte sequence. */ - struct fscrypt_str cf_name; + struct qstr cf_name; #endif }; @@ -3528,8 +3528,22 @@ int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir, /* * dir.c */ +#if IS_ENABLED(CONFIG_UNICODE) int f2fs_init_casefolded_name(const struct inode *dir, struct f2fs_filename *fname); +void f2fs_free_casefolded_name(struct f2fs_filename *fname); +#else +static inline int f2fs_init_casefolded_name(const struct inode *dir, + struct f2fs_filename *fname) +{ + return 0; +} + +static inline void f2fs_free_casefolded_name(struct f2fs_filename *fname) +{ +} +#endif /* CONFIG_UNICODE */ + int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, int lookup, struct f2fs_filename *fname); int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index d0f24ccbd1ac..7e53abf6d216 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -153,11 +153,8 @@ static int init_recovered_filename(const struct inode *dir, if (err) return err; f2fs_hash_filename(dir, fname); -#if IS_ENABLED(CONFIG_UNICODE) /* Case-sensitive match is fine for recovery */ - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + f2fs_free_casefolded_name(fname); } else { f2fs_hash_filename(dir, fname); } -- 2.34.1