From patchwork Wed Feb 7 06:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 197765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2042333dyb; Tue, 6 Feb 2024 22:44:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQZS6YRiguywSG7M7avq+TygoKNOaWVdXr24Lr8juPwrMR/rvCO1AuJAS2CPfT652LeOZK X-Received: by 2002:a17:906:e244:b0:a38:45fc:1f01 with SMTP id gq4-20020a170906e24400b00a3845fc1f01mr2100566ejb.45.1707288263206; Tue, 06 Feb 2024 22:44:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707288263; cv=pass; d=google.com; s=arc-20160816; b=LvuXdqwleB779t/bqs8oXoajv+pFtauii5Pe4PE6X8Ga99Ag8MnSv7Z0lmf7tbgziL MMk808bXlXGGxfEEGyTu9H3Oi7tylnx5XFcx/PVvYNn7n5IU93ivd558zJA8Cz9S0j6k ZajTNM9olKEaeCprZIRuqgQVbZJtoNewMtwfAxL17RWO0Xe7f+Co//BKo4rfwqCVD1+O SD4e1JrEJVY5rjaPbvtCGh9QNKpHMbhC7P36QE2kB4nRECWmIsjIEsSxjoRIfU2/Vdpp ygJkuvNYGE4boYT0bAbZAvsCK4kccH6fhXtvocyCe3Z5aV2BZWpphuiqe9pJU8+67Olb 6gOQ== 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=bLj6BkOOj6QP6flSGLrMwh8Bhh9dmUPrqQK2TTtbiVo=; fh=GLNWDaRFWlK9v6L++M5AOwdri8tApuIekh+zdPbYBsk=; b=j7QjlVpaJOuw5sr71Ia570NG1k/8ecKFh3l+2uyijghx2SlgykVSjVkA5pIsfp6m+m qE4QkoAlMz1vB9uokdiZg5AlG31KfZAzHDAMl1hOUVf1Y2T83Fqu/TdNWSA7yvVng2uF lFk+AhcQq4OrfKw5YrTH2K8rwN/1KSyK7twbOP0eZx/2O8/FYgnQxTNIvapRgr+XB15/ /DeFGqsIlT5/7pZOB5I2NFFWAPpbnFV4YEQQWuZ33T8NB+1lb0xUILCTu7NaErpNLdp/ bVuogB+V2k6wUjLtTlGKPNbgFXeMtpszDrLWjH4k+4NJJHDcbYpoILXyUyhsViCNBftG wVng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=0ZmrO1VO; 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-kernel+bounces-56028-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56028-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com X-Forwarded-Encrypted: i=2; AJvYcCXul0mr1JFAidqNRtz3emGZbcHXLF+tkH3s6gF43JhdtviqYWH5J5jKrXQBjr1jWXXudKNTszh6KGnqAnQneCQ9gQgvYg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u14-20020a1709060b0e00b00a37e5573019si476597ejg.652.2024.02.06.22.44.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 22:44:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56028-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=0ZmrO1VO; 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-kernel+bounces-56028-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56028-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id A54D31F27019 for ; Wed, 7 Feb 2024 06:44:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B0A71F94B; Wed, 7 Feb 2024 06:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="0ZmrO1VO" 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 5309C17BA3; Wed, 7 Feb 2024 06:43:42 +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=1707288224; cv=none; b=AMCeTjjY4o6LeLhSPRyv5pRzEDjX5ic17tK/AQAZxZ71Xy0OhwpQDk/kKLjFPDJBVcbtwzonLrsw/tMaKZ+2uQromLUzDo2hvAn1JH3SJX7TWxdl0JETaW+BU6aY1843ylIQibziOWVC2oNxncoqBnClk1QUR3wFIW2Ie1UuvrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707288224; c=relaxed/simple; bh=sYUTU/89PFPnPBoR5kfzfYqhAM5p15Bl509BAaBxeuk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Bcdcx+aCuVcVRlc4RALuhe3WMp1qrtCOk37UnZzMRjY/v6I5SX77E1YHDB7ZF1pjmjCer3+v1ConPCNu4WfgVcwj+EfkwDKMRqyWUKigl5LFVU8us7eHiIOx1lRX0iWHvmEd8Otwm8PHliKQv4SZQzqDf1GpLCy/rFlQ42EZLF0= 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=0ZmrO1VO; 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=1707288219; bh=sYUTU/89PFPnPBoR5kfzfYqhAM5p15Bl509BAaBxeuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0ZmrO1VOAw4pQq6H3dURVbvt4b44qK+PfK7EAijDa333nF+w4d74QKrKuW9ghoOu/ hybkEXhLvEHWYjDYA+eQoUbIfdTzZ30hVANGUPWMqMKsPnLCiPn02LqZUcN6NPPs0G C4GyOxU93O2t6Owgy7BZ9RDjUXl+kUkln0nNylk4huut4D5JdUzE5e65RewB8SgU4a l2MHw2UgavU9C+SQPZL3VGlHL9fTLRXHze2Vzg/qMXjH1jf6SpWbW7BJDWhVKabt3K nuUoPeE6uezQcmlsIRsWhqbEajMqe5KyzapK1OXEwoUeURxnsYwMuSL1m8LeGEakKr ytD2PlqBybZ9A== 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 BC20E3781F7D; Wed, 7 Feb 2024 06:43:36 +0000 (UTC) From: Eugen Hristev To: tytso@mit.edu, jaegeuk@kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: chao@kernel.org, adilger.kernel@dilger.ca, linux-kernel@vger.kernel.org, kernel@collabora.com, eugen.hristev@collabora.com, Gabriel Krisman Bertazi , Eric Biggers Subject: [RESEND PATCH v9 1/2] ext4: Simplify the handling of cached insensitive names Date: Wed, 7 Feb 2024 08:43:01 +0200 Message-Id: <20240207064302.221060-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207064302.221060-1-eugen.hristev@collabora.com> References: <20240207064302.221060-1-eugen.hristev@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790221498064154528 X-GMAIL-MSGID: 1790221498064154528 From: Gabriel Krisman Bertazi Keeping it as qstr avoids the unnecessary conversion in ext4_match Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3] Signed-off-by: Eugen Hristev --- fs/ext4/ext4.h | 2 +- fs/ext4/namei.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 023571f8dd1b..932bae88b4a7 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2508,7 +2508,7 @@ struct ext4_filename { struct fscrypt_str crypto_buf; #endif #if IS_ENABLED(CONFIG_UNICODE) - struct fscrypt_str cf_name; + struct qstr cf_name; #endif }; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 05b647e6bc19..e554c5a62ba9 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1445,7 +1445,8 @@ static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { - struct fscrypt_str *cf_name = &name->cf_name; + struct qstr *cf_name = &name->cf_name; + unsigned char *buf; struct dx_hash_info *hinfo = &name->hinfo; int len; @@ -1455,18 +1456,18 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, return 0; } - cf_name->name = kmalloc(EXT4_NAME_LEN, GFP_NOFS); - if (!cf_name->name) + buf = kmalloc(EXT4_NAME_LEN, GFP_NOFS); + if (!buf) return -ENOMEM; - len = utf8_casefold(dir->i_sb->s_encoding, - iname, cf_name->name, - EXT4_NAME_LEN); + len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN); if (len <= 0) { - kfree(cf_name->name); - cf_name->name = NULL; + kfree(buf); + buf = NULL; } + cf_name->name = buf; cf_name->len = (unsigned) len; + if (!IS_ENCRYPTED(dir)) return 0; @@ -1503,8 +1504,6 @@ static bool ext4_match(struct inode *parent, if (IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { if (fname->cf_name.name) { - struct qstr cf = {.name = fname->cf_name.name, - .len = fname->cf_name.len}; if (IS_ENCRYPTED(parent)) { if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || fname->hinfo.minor_hash != @@ -1513,8 +1512,8 @@ static bool ext4_match(struct inode *parent, return false; } } - return !ext4_ci_compare(parent, &cf, de->name, - de->name_len, true); + return !ext4_ci_compare(parent, &fname->cf_name, + de->name, de->name_len, true); } return !ext4_ci_compare(parent, fname->usr_fname, de->name, de->name_len, false); From patchwork Wed Feb 7 06:43:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 197766 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2042418dyb; Tue, 6 Feb 2024 22:44:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJAUx+S7g08XncxIOnM+ocZguacmMx+0opsKRroDcq+JJhEIj12TJbH+/AvimlIqjUYzda X-Received: by 2002:a05:6402:782:b0:55f:fad8:4635 with SMTP id d2-20020a056402078200b0055ffad84635mr3188933edy.27.1707288277390; Tue, 06 Feb 2024 22:44:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707288277; cv=pass; d=google.com; s=arc-20160816; b=q8E8YRcwEvL/XNlL2VEZSU4b2HkJJrrJg2UNWh6jc6kaUCxk6a9tx3DdR69PEOGkxq G+dQdyovbo2WJhWSyUBd5XXnbRo/o6i65ZX19VEv9aR9/3T7/32R1zyNQheRcrNLThmC yOBR0bYKU5yfgrVveQ3ME8lWWgWmwFte3DEQOVoDLRh4lH0DQgXT2TZVZudUiKDQtAau RlepbOPw6jfv1n8ng1IU+A4AXTdeaicZphbf+oRgND6wRu9McfnZRx8kTme4hG4mylFX JjfdYNTvANckZ5HNCotRlNoJwxGzhDmpEBkzECnFOozykgXaXPDW+dGgQNbGYgQfrkJ/ oqEA== 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=2RNHw9ShUImcdCNGojHYJhqBtOYAchjd6ZrKf3FHhVI=; fh=DEZfytQq2GsEEskr/649qZC2R2P9AAJVwyy1tMXNFv0=; b=cXYaZXuFbie9VK3lmo8Lu4DSLlIf/+O7wkA/Hw0yakgLPHkZ7tj8mNiyxNrJQXcV9R D1QIsoR5S8KQ2iiFDPOT/0IQAO03b8v7pN9r8hOdGlcNJgM0PfccWhtdfF6hAG5nm3MU 5u17MjKLUmYIQzmhRI/CptOfe3haJm2dT60FkWNo5GGaS9yFyi7QNUHuZ+xrJ48rnepr 2LMzs1JP2rH5tfanBU714FPVGBp0FBGwDWrG1Z8megiUjFq7cCgyL5pOKCNXIEKO/qOm sQ+5b+XcFQiq4SQCoFWx885h8pMuiab9agAwHWP53c/JSA3UXVdZpvQ4wVWFZh4jHMOR 5LBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=du6jkm69; 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-kernel+bounces-56029-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56029-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com X-Forwarded-Encrypted: i=2; AJvYcCXoXbU9LFLKIV2NcTyFl0vyAIWdIM1p4H71l9uZUH50qrl1hUdiirLMqv+op6pxzLwNPWgcDrL1cR7tb7z1LnTdX2TsyQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u10-20020a50c04a000000b0056053b3aba2si462465edd.651.2024.02.06.22.44.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 22:44:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56029-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=du6jkm69; 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-kernel+bounces-56029-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56029-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id CF1321F2701B for ; Wed, 7 Feb 2024 06:44:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08133200CD; Wed, 7 Feb 2024 06:43:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="du6jkm69" 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 3B94B1B95B; Wed, 7 Feb 2024 06:43:44 +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=1707288226; cv=none; b=A0vGjpGrTgwr6uTPFZYzHGCDurdOjG/FnKcAMpdtTWhbpXOSyRBxe2/REog7DYX7uU9fCFNtOzTgTNqILvmHTUDZO7twXKYs5xIgR7kZAGaZfB1h8OmDl+a7SMufpsKkDIsifRrwgKrkRMwoeICmHqu5MzfgCcC+8ZOzZB4HUdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707288226; c=relaxed/simple; bh=ZmbHA48mdcAgo9rPreneBpGW4T17Nyg3IwTQS03RZdo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MZTU8BRB06faabAXhbJmsD65rt2L60eCQABsXWuIwTy9g/Yd6KD2tBQ8t2WhTz7EWoIxZZp20rb9qmnfQoYzGQCEeON09v81/I/Jg6yz9ZkHpykS+jH3/Wkv9Rv8+z63puDfPwL5eZaB9C0vXMcZePZc7zQmLWsn1WPTaLQUxPI= 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=du6jkm69; 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=1707288223; bh=ZmbHA48mdcAgo9rPreneBpGW4T17Nyg3IwTQS03RZdo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=du6jkm69GxYU0EjUc9tQojLR2xZ0SU3kzmuzOMf+hvJKsYSWvdOSZR3inWOk+Poza W4gl7mSB2Vhh/ro0tnzXbyc1HqrdZXnmFSFro3sodaLrRc0mr9E/pp0WLeBMjISnem FhXYa19MSJW3r1iOmwyqCjJXuhmaoi0rY6Spc0nzFK78bIwbskBWN0RZB74qWBRyU7 yNz2glHtpj1CCitnNMsJsjbGrlI6LK/nbIcaWRumjslht8ANQGUk8VwTtkTysAZAZA axz34oqkvjdcYhW2gN7YEm/X7S35TO3i3vYgoHEbZomeIlkEp+z6QIeW2YrIEyZ+c7 grE64MgSj4Jag== 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 8981E378209A; Wed, 7 Feb 2024 06:43:40 +0000 (UTC) From: Eugen Hristev To: tytso@mit.edu, jaegeuk@kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: chao@kernel.org, adilger.kernel@dilger.ca, linux-kernel@vger.kernel.org, kernel@collabora.com, eugen.hristev@collabora.com, Gabriel Krisman Bertazi , Eric Biggers Subject: [RESEND PATCH v9 2/2] f2fs: Simplify the handling of cached insensitive names Date: Wed, 7 Feb 2024 08:43:02 +0200 Message-Id: <20240207064302.221060-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240207064302.221060-1-eugen.hristev@collabora.com> References: <20240207064302.221060-1-eugen.hristev@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790221512715194262 X-GMAIL-MSGID: 1790221512715194262 From: Gabriel Krisman Bertazi Keeping it as qstr avoids the unnecessary conversion in f2fs_match Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3] Signed-off-by: Eugen Hristev --- fs/f2fs/dir.c | 53 ++++++++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 17 ++++++++++++++- fs/f2fs/recovery.c | 5 +---- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 3f20d94e12f9..f5b65cf36393 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 84c9fead3ad4..2ff8e52642ec 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -530,7 +530,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,23 @@ int f2fs_get_tmpfile(struct mnt_idmap *idmap, 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 aad1d1a9b3d6..8e8501a3a8e0 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); }