Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp653973lqp; Fri, 5 Apr 2024 05:14:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuGs8BXZeElD4Z9k+kvmg/hIftm/x7Q0z1NSEBpsDH0lNn8AK38lJ/eN33NYvRn1pctNXq+dNUQR7FuF2hGeP34jbMK7vCx9a3v7NPmg== X-Google-Smtp-Source: AGHT+IGWgD5T5PnXuvAq6amg40n8mLJAENPJ1bGsvIdHijw636KDLdeLzK2LTyZaYQOzAyfcr7yN X-Received: by 2002:a17:90b:3d6:b0:2a2:7dd2:a58a with SMTP id go22-20020a17090b03d600b002a27dd2a58amr1038208pjb.45.1712319277316; Fri, 05 Apr 2024 05:14:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712319277; cv=pass; d=google.com; s=arc-20160816; b=QLPLEue7Ps7bmW+/VL5tOCUeMpzW4SoUMQcARGUu65DCrYP8ssHEhMKKEFkNPL6h0y 4KMAGT6yUAEtS1ZJdd5yRKVG/Cdj+X5sFqycVO22UA8Uj9vw6xXxyGJL/MYAL+i2I29o ISDfqYjDHTIFomGLxgbDE/efeu0jj0WJ86JITPGOqk3uy5DCPm6OW9IOEYBcVJQOEtNq sV95dOdOKMmRnse8BQoGDym1SX6OOJXyj2N3O/2FKZeuLDAVFaUtbHEU8OAn/mO8eXHg DcQI1N692KgVUgobQ42SNBqceOPnz0bUF7V5FI8+7IrMgZ1O7b1fS4uBpFZz56vWau8a vBBA== 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=wWooyawhqTUZk7HmSdAH5/5eWaSQil3bMdJX8giP/0g=; fh=i4fiMUBCQXbDZMdyre5oEqz49aLUEO6D1+7NN548JDQ=; b=g7vwWTSd8+Km/A/E8nUfYLcUSPO/3jHomRlH39Ut1NrXTGygnOI7HKJOMFReSjQwgF 0rKW/LcfxbBQ7kC8WAG5z6knH8uiDTbDTeauRX5YRSlxtluqdcYIx9M0Htma99oFZNcR UGPHDVgaIb7o7UMepjoUpgdyoj3KAB0RJSq9izRrS2oOvSamMl0narAaQ+OIEOyA3hOD 2EVGUTWVdABbG975mFBU6HVbaGrac7Nf5Sb+A7EEYfcwQNEXdUIAP5Nx20ak5DNkx2P/ PclrCu59zh2fCpN1QNHdiHJy/koJJP2zhcWyEVMshGlhbvGFnxIOkatxllzAZxA3UrWc 3rIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=koisWkNi; 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-1886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1886-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f2-20020a17090a120200b002a330a7b1d4si1232185pja.173.2024.04.05.05.14.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 05:14:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=koisWkNi; 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-1886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1886-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 77107B22345 for ; Fri, 5 Apr 2024 12:14:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79E9916D326; Fri, 5 Apr 2024 12:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="koisWkNi" 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 53B89161330; Fri, 5 Apr 2024 12:14:05 +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=1712319247; cv=none; b=SoWvHo76YmlS/lZsBr/EQqo74CWsf5QVOxVqxgocUeJqvfMoAeV8jfw8dJBIedQSSoYGdENthI43RpkePztxNl5QUbAwS26E+PPfywXDOcTJQBYf+HK5ZwKRIg/Zh3+MIF0EHR16/kw5qEMDcwEkKvKaxXY6VustbSYnZoy3bGw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712319247; c=relaxed/simple; bh=iIf4UZ9JI6uynWIZ1rettGGo6aQjNP/VRVMVUi0YrzY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nJB/xsXG17EmyS119xT1IhbvQCyUpvdKeb0osAsNZJTItuG5u/H39ZeTVyaPmuW8DFPmoMiXqpxYfA7yiNGcqFYrBYXc56a0tYQQWDyxFlNjxbB9nhlBKCwK4SO2BQWlY1cczplKZBK+BNxwHN//Pqlyrzy6OKlqmw7JudRH1Qs= 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=koisWkNi; 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=1712319243; bh=iIf4UZ9JI6uynWIZ1rettGGo6aQjNP/VRVMVUi0YrzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=koisWkNiM1GbZWp0+UeURFnwnTbomze9gQgUZ+NR8BDRS4Eju6QfhGmwtzDwqgBvb 06kG4xAW0eLcZQAaGYLui809ITYkSnKngQHuTBQpizKDJXC0A0UzX24j0RmHp5tVEG qyhgnRc0Bx5EZz/4jbEIoE8/XJyZrdJwLuJuo0JOPob8hhW7nXQf57oyI/fdn37wLw 35JTpfhCkcZ07hejMSLwtt7LNhwl22cGvU9sMWr9a4oKJMbnotD8MbfSqF1a8THboN 5d4EH3Q/yf/4pVIIgKovNC/U+PAt8aYsZIRSVGxx3EcBemxV6rc7qWijupqfeszJWx 8uKh8VUyKV0mg== Received: from eugen-station.. (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 78CFE3782131; Fri, 5 Apr 2024 12:14:02 +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, ebiggers@kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v16 2/9] f2fs: Simplify the handling of cached insensitive names Date: Fri, 5 Apr 2024 15:13:25 +0300 Message-Id: <20240405121332.689228-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-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 | 53 ++++++++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 16 +++++++++++++- fs/f2fs/recovery.c | 9 +------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 02c9355176d3..bdf980e25adb 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -42,35 +42,49 @@ 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; + + 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) @@ -142,12 +156,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 +244,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 fced2b7652f4..119769240ffb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -531,7 +531,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 }; @@ -3533,8 +3533,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 e7bf15b8240a..00c396973c8a 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -46,10 +46,6 @@ static struct kmem_cache *fsync_entry_slab; -#if IS_ENABLED(CONFIG_UNICODE) -extern struct kmem_cache *f2fs_cf_name_slab; -#endif - bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi) { s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count); @@ -153,11 +149,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