Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7255506rwn; Tue, 13 Sep 2022 17:08:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR7S0gs6w/WmSXGmhuSzUkrYCy/SBcylozyEVPUPj9GERgyo28KTmRR2GUC2CHaw4aoycZp7 X-Received: by 2002:a05:6402:2b8d:b0:43a:5410:a9fc with SMTP id fj13-20020a0564022b8d00b0043a5410a9fcmr28610970edb.99.1663114124667; Tue, 13 Sep 2022 17:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663114124; cv=none; d=google.com; s=arc-20160816; b=E4929/L2UiLoy3WYTNsJIrMJscpKRSNHFHFRVy7dZ1/Qy6MhedjFLzBcQ2LQPlXoB+ FSs2SiJeSSmP9/Xi1S2kbx9baHwpArKytqIPkEKnMqRcMj0vRkS2Q23Hzf5mSg+G/QQ2 wEmEjtOSEggB3ldPM4AiOfE5MwFl2X83dAWtjqP4GY+06Lm6GguRmXuSC2GHd2z/0Qj8 2mzIkGiVfiNDgBzaYl/RUaMNCMbRWh4KrSBJ/qbkkce73DkXz4VSuXL8N0iKBskTGkoA mADl7yWAOBk4I6hLu1SibsUBD0cLmAzzh98DKhRj88aEIM0+zIxQXdcPVhQqxUKA77B2 lFrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nct0Xqx9xo6NxUTEV0FFU5XM/7Svdyzp7scuHFBx/bM=; b=e3IqJuoteEF7qQ33/JBzGXF/S+SxzJUVb2X1o1xeu6UKf8oirJrXIP3nQDqhflGAU6 2B33fv5WWfLOQbPQna0QUgmJkoqi22sXRO+k9eBQ/E3rFPJBqMYMF4kA4X15BXgTjKB5 lLeZyOaADxBRPXcSTq6H/eQyHYcXErCni5ALQUw4C0dSQ1rGMxHnOeuOF2p9PvZpXMJW ePJwnp3f8aChjTEU1SoCytDM+sfD5dD3sKZN1vBkPq76DAlDiKjESVmzoMRNwkGJpEW9 63MJ488NnZvJGDf2cOzLfizticubbdMLVO67SHZ9ebzXvI/R8CU42EZmeNug+NL6LwvR SZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GDxU+bzR; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a17090616c200b007418e87eea8si8271714ejd.770.2022.09.13.17.08.19; Tue, 13 Sep 2022 17:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GDxU+bzR; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229574AbiIMXmM (ORCPT + 99 others); Tue, 13 Sep 2022 19:42:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbiIMXmK (ORCPT ); Tue, 13 Sep 2022 19:42:10 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C96DA3F1FA for ; Tue, 13 Sep 2022 16:42:08 -0700 (PDT) Received: from localhost (modemcable141.102-20-96.mc.videotron.ca [96.20.102.141]) (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: krisman) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2D63E6601FF1; Wed, 14 Sep 2022 00:42:07 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663112527; bh=j78UN+kM/OR2Ug6pmweMA9wum9zMeWGj6iYav82N+RA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GDxU+bzRD2OyjECYsxQ70T5d1iGSlf97t7LFYwAI9DE5aIrrETDmYowz0TPPKfMBa cZ4pWF+K5t6ZcyjnGBh5t/opNqSZFVbLiXHcHvpW7J13rAP9z0wLtgVvGy1zL+nVhE FW1NWLPVchEDc4zdZvgVyfwiRPum96nuWVCctMszmnCoVUkQOEvClmknlliKzLv9cL xYVM6ucAuX6KW7KtTEuurBQdqjj5BGtQJsTtk6TAllADcdBGUY3ASn6fbMLmorc9YK XZBDlYF7Xtu6wlI097JyVcg1C0K2mUxDgE2TZaAz+4bbinNy/Jn4Fs5FakTbO5qeg4 HkGWOchksOI0g== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, ebiggers@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Gabriel Krisman Bertazi , kernel@collabora.com, Eric Biggers Subject: [PATCH v9 2/8] f2fs: Simplify the handling of cached insensitive names Date: Tue, 13 Sep 2022 19:41:44 -0400 Message-Id: <20220913234150.513075-3-krisman@collabora.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913234150.513075-1-krisman@collabora.com> References: <20220913234150.513075-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Keeping it as qstr avoids the unnecessary conversion in f2fs_match Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi --- Changes since v4: - Fix inconsistent return on error (eric) --- fs/f2fs/dir.c | 53 ++++++++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 15 ++++++++++++- fs/f2fs/recovery.c | 5 +---- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index d5bd7932fb64..98db333a1338 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -75,35 +75,49 @@ unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de) return DT_UNKNOWN; } +#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; + + if (buf) { + 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) @@ -175,12 +189,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, @@ -268,11 +277,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 3c7cdb70fe2e..2a0cc75665d6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -515,7 +515,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 }; @@ -3484,8 +3484,21 @@ int f2fs_get_tmpfile(struct user_namespace *mnt_userns, struct inode *dir, * dir.c */ unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); +#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 dcd0a1e35095..ead49ea25ae8 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.37.3