Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1895924iob; Thu, 19 May 2022 18:12:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP1AabSYiSzwCMBTI6yyZ6NxoiZoWIhfWU1eyKPNes96hvFiq4BZZykZ//B0bdiwL8bp3Z X-Received: by 2002:a17:903:41d0:b0:161:bec6:b33b with SMTP id u16-20020a17090341d000b00161bec6b33bmr7129056ple.21.1653009137257; Thu, 19 May 2022 18:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653009137; cv=none; d=google.com; s=arc-20160816; b=VMhZADi7sdUqLZXIPCb0pQsVmYLz92gwZujk9paKHS61wl0uUXmgyQKUQi3W0iKY2C jeN7zXXKOxSd/qCG/WSV5u7YrEscFscd5jNjVTYGjFzn7DkOBwtGJRHJpTZH9Y5EwYe9 0lNx63pFposAupQOcLIzM7rKKZbRr/gKxr+mLqn5SQX/zR5McnIil4rALyhqYpOJwAYU OhEIsPBhiEyqjtFA0Lx1m6pYjyP7jlHyR+3Rxy2ndKXJ7AH3gLGf3z1O/ozAoQcDh7cR fzSvpiyXFfwvG1chQy123M8jyK2dUfguPe3uVL4wRhPqGpzCAUql4MBlTN3TiExNpoKX zqFA== 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=KIYUXnUyKb9VI8UEwboCDwLHps3xzxEAcxBqmKrxHIU=; b=vw0RNeSFGFN1HMXZ2RG7oD1Ltp9PEFF+/RQWs/BjvVe6fGIwdpHuhDdTlSjR/NwW2T ehquIOtPL7KvOg1/qqVqDHeV6AK7Np6CCZWOjGgHp7j/o5T3gqcyer2vwJN0jNNXtEgm dPgp/FMRYIjuuxU1WFBBPF5lfg74zWT/nLM5OaegQKgzzmVVfTB7WaHi7Mdu5dgZIezT hL1ND4CK34LtcPm6T4vN3J6qCP52hN1Pb2AvO8/Gb03g/phg+P766LFfMSUdHYqU/Bqx mBzfHjEApLbyEmze8MkjLQAFme0eYli8zX+klzMfwGW9bmm2dOv2tLcvVrlTuXsK5Bk7 EL4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ILMEZO5t; 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 z12-20020a63190c000000b003c6c145ef3esi8647844pgl.84.2022.05.19.18.12.01; Thu, 19 May 2022 18:12:17 -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=ILMEZO5t; 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 S242760AbiESVYd (ORCPT + 99 others); Thu, 19 May 2022 17:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241079AbiESVYc (ORCPT ); Thu, 19 May 2022 17:24:32 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B12DAED8F0 for ; Thu, 19 May 2022 14:24:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 6107F1F45F74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652995469; bh=S6queVANKLkR6rGNVZjZSlibWPKGEIm13teUWj2MnUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILMEZO5tqFHa32A7CL4nY01QPtLA7O5LgvfZ+e41+huPlXpi+kQ2s7Q5b+PBL7J9F Fy2dtvbOLHOrJD6zKeI1hBHTSQr5dlbYUo3HdVximPazv0YrUHzAbcp3Gi+KuSVOeJ x8Xd6GcyGlaHQg7L4jzjMp2vWX0eqxkn6IrugdFhecl5kLILV0lzUUEKFwHtmIk7md GSBWUcT98Ubte6rIHihA4I5vqzJDp/SnlpVe+BbwPVA3MA088w/fmq3kfCEZ1iyzQC d89E2Gl67uedNZDf07Dp1Zu+uoAZP5DvHbIR/b383WO33l8s/1OFQS7rP5GcACzCGl usxDvokHpUUqA== 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 v8 7/8] ext4: Move CONFIG_UNICODE defguards into the code flow Date: Thu, 19 May 2022 17:23:58 -0400 Message-Id: <20220519212359.19442-8-krisman@collabora.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519212359.19442-1-krisman@collabora.com> References: <20220519212359.19442-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_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 Instead of a bunch of ifdefs, make the unicode built checks part of the code flow where possible, as requested by Torvalds. Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi --- Changes since v5: - Drop err variable (eric) Changes since v4: - Create stub for !CONFIG_UNICODE case (eric) --- fs/ext4/ext4.h | 47 +++++++++++++++++++++++------------------------ fs/ext4/namei.c | 15 ++++++--------- fs/ext4/super.c | 4 +--- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 93a28fcb2e22..4bc3649e3385 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2727,8 +2727,24 @@ ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); #if IS_ENABLED(CONFIG_UNICODE) extern int ext4_fname_setup_ci_filename(struct inode *dir, - const struct qstr *iname, - struct ext4_filename *fname); + const struct qstr *iname, + struct ext4_filename *fname); + +static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname) +{ + kfree(fname->cf_name.name); + fname->cf_name.name = NULL; +} +#else +static inline int ext4_fname_setup_ci_filename(struct inode *dir, + const struct qstr *iname, + struct ext4_filename *fname) +{ + return 0; +} +static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname) +{ +} #endif #ifdef CONFIG_FS_ENCRYPTION @@ -2758,10 +2774,7 @@ static inline int ext4_fname_setup_filename(struct inode *dir, ext4_fname_from_fscrypt_name(fname, &name); -#if IS_ENABLED(CONFIG_UNICODE) - err = ext4_fname_setup_ci_filename(dir, iname, fname); -#endif - return err; + return ext4_fname_setup_ci_filename(dir, iname, fname); } static inline int ext4_fname_prepare_lookup(struct inode *dir, @@ -2777,10 +2790,7 @@ static inline int ext4_fname_prepare_lookup(struct inode *dir, ext4_fname_from_fscrypt_name(fname, &name); -#if IS_ENABLED(CONFIG_UNICODE) - err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); -#endif - return err; + return ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); } static inline void ext4_fname_free_filename(struct ext4_filename *fname) @@ -2794,10 +2804,7 @@ static inline void ext4_fname_free_filename(struct ext4_filename *fname) fname->usr_fname = NULL; fname->disk_name.name = NULL; -#if IS_ENABLED(CONFIG_UNICODE) - kfree(fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + ext4_fname_free_ci_filename(fname); } #else /* !CONFIG_FS_ENCRYPTION */ static inline int ext4_fname_setup_filename(struct inode *dir, @@ -2805,16 +2812,11 @@ static inline int ext4_fname_setup_filename(struct inode *dir, int lookup, struct ext4_filename *fname) { - int err = 0; fname->usr_fname = iname; fname->disk_name.name = (unsigned char *) iname->name; fname->disk_name.len = iname->len; -#if IS_ENABLED(CONFIG_UNICODE) - err = ext4_fname_setup_ci_filename(dir, iname, fname); -#endif - - return err; + return ext4_fname_setup_ci_filename(dir, iname, fname); } static inline int ext4_fname_prepare_lookup(struct inode *dir, @@ -2826,10 +2828,7 @@ static inline int ext4_fname_prepare_lookup(struct inode *dir, static inline void ext4_fname_free_filename(struct ext4_filename *fname) { -#if IS_ENABLED(CONFIG_UNICODE) - kfree(fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + ext4_fname_free_ci_filename(fname); } #endif /* !CONFIG_FS_ENCRYPTION */ diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 708c241b23ec..6a46851675d2 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1765,8 +1765,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi } } -#if IS_ENABLED(CONFIG_UNICODE) - if (!inode && IS_CASEFOLDED(dir)) { + if (IS_ENABLED(CONFIG_UNICODE) && !inode && IS_CASEFOLDED(dir)) { /* Eventually we want to call d_add_ci(dentry, NULL) * for negative dentries in the encoding case as * well. For now, prevent the negative dentry @@ -1774,7 +1773,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi */ return NULL; } -#endif + return d_splice_alias(inode, dentry); } @@ -3091,16 +3090,14 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) ext4_fc_track_unlink(handle, dentry); retval = ext4_mark_inode_dirty(handle, dir); -#if IS_ENABLED(CONFIG_UNICODE) /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ - if (IS_CASEFOLDED(dir)) + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) d_invalidate(dentry); -#endif end_rmdir: brelse(bh); @@ -3196,16 +3193,16 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) retval = __ext4_unlink(handle, dir, &dentry->d_name, d_inode(dentry)); if (!retval) ext4_fc_track_unlink(handle, dentry); -#if IS_ENABLED(CONFIG_UNICODE) + /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ - if (IS_CASEFOLDED(dir)) + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) d_invalidate(dentry); -#endif + if (handle) ext4_journal_stop(handle); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 1847b46af808..fa0004459dd6 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3645,14 +3645,12 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly) return 0; } -#if !IS_ENABLED(CONFIG_UNICODE) - if (ext4_has_feature_casefold(sb)) { + if (!IS_ENABLED(CONFIG_UNICODE) && ext4_has_feature_casefold(sb)) { ext4_msg(sb, KERN_ERR, "Filesystem with casefold feature cannot be " "mounted without CONFIG_UNICODE"); return 0; } -#endif if (readonly) return 1; -- 2.36.1