From patchwork Tue Jan 7 05:16:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Rosenberg X-Patchwork-Id: 11320425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A87C9930 for ; Tue, 7 Jan 2020 05:17:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7D2BC2080A for ; Tue, 7 Jan 2020 05:17:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gmGSXP1s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727317AbgAGFRD (ORCPT ); Tue, 7 Jan 2020 00:17:03 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:54086 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727258AbgAGFQ6 (ORCPT ); Tue, 7 Jan 2020 00:16:58 -0500 Received: by mail-pl1-f202.google.com with SMTP id m4so7582263pls.20 for ; Mon, 06 Jan 2020 21:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qZKTiM0GgbzZ03KCdWEEy+bquFa7svd20YuVXdrJ9Jc=; b=gmGSXP1sDv+b5gDsfsxnX0ArY8xw7Iuo9GKFryzLErAWxPPnWfJzLTmPmTHOHRO8BZ h7zRbQCPKhorVfCsy8RHuG5WcY7hdOSLhTohP5kA2kTl28Zy8/xjzx6ftH3rAfL6nz1T BWzXYE0UQCuSHeGMonUw9RwG2xIF9xcT+LHY9asuyyUoYBTenPAg+GeyPn0PdcfjAE7R bQffCDlG6+YC5yKmcD6Kos4zeYNRpXIpND059lUluxw6j8Iw6AxNcScbXTeP470V654i R5Dbr7Xk6ShjOgi/2QOYlY3uKnmHdARiIEG3wn9hWdLilv1NpKMk4zlotV45zTQMCAXt GlPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qZKTiM0GgbzZ03KCdWEEy+bquFa7svd20YuVXdrJ9Jc=; b=j+nBYi8DNzh3ahorE7QFQzpJ8nGXau0dj0xrkbXktD9Lmhgx9OkHwgbgNaium6yRlQ LqFtt5ccf8HMj9wtfN+dR7x/kE7tLLBbQ99jHJif2qmNGQfrPB4VYYbn8i3sMbTSZuwW oa2DQevoROfkeQlfcUXJDv0VwB0TUrcZee720FItZoY14MpMEl0UwMy3HshtLfXPGlBt 1k3d9+asnQanR2Ev3soc8PdW1AkPcvSDCDBlZ1XgsnC/YsbfIpOzMO7NPh6AERNGMG52 xShxb8PKLh2ydVzm68OibY+0gOMDT2ISgHG3gaB4uX7bIGaYnYKHvvUkSB3++OpiZEjm 5lGA== X-Gm-Message-State: APjAAAXtQ46Vpr14HVa5ZoCn8QqcZ1259T1TBr+SIw1cPfaD94zMVQC7 9UAJxLNUJ+6I8HYsCnylzK77jAcLpe0= X-Google-Smtp-Source: APXvYqwri5zPKZ9xGUrAZ7jmFUidYrANr8unDkP8dJbTZ/IMR9jp15B7J+8QxkR8zUhYRCbjJIqyp/WA0q4= X-Received: by 2002:a63:b4d:: with SMTP id a13mr111634235pgl.388.1578374217613; Mon, 06 Jan 2020 21:16:57 -0800 (PST) Date: Mon, 6 Jan 2020 21:16:36 -0800 In-Reply-To: <20200107051638.40893-1-drosen@google.com> Message-Id: <20200107051638.40893-5-drosen@google.com> Mime-Version: 1.0 References: <20200107051638.40893-1-drosen@google.com> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog Subject: [PATCH v2 4/6] ext4: Use struct super_blocks' casefold data From: Daniel Rosenberg To: "Theodore Ts'o" , linux-ext4@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Alexander Viro Cc: Andreas Dilger , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi , kernel-team@android.com, Daniel Rosenberg Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Switch over to using the struct entries added to the VFS Signed-off-by: Daniel Rosenberg --- fs/ext4/dir.c | 47 ----------------------------------------------- fs/ext4/ext4.h | 4 ---- fs/ext4/hash.c | 2 +- fs/ext4/namei.c | 20 ++++++++------------ fs/ext4/super.c | 15 +++++---------- 5 files changed, 14 insertions(+), 74 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 9f00fc0bf21d2..f70b3bb57c48c 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -667,50 +667,3 @@ const struct file_operations ext4_dir_operations = { .release = ext4_release_dir, }; -#ifdef CONFIG_UNICODE -static int ext4_d_compare(const struct dentry *dentry, unsigned int len, - const char *str, const struct qstr *name) -{ - struct qstr qstr = {.name = str, .len = len }; - struct inode *inode = dentry->d_parent->d_inode; - - if (!IS_CASEFOLDED(inode) || !EXT4_SB(inode->i_sb)->s_encoding) { - if (len != name->len) - return -1; - return memcmp(str, name->name, len); - } - - return ext4_ci_compare(inode, name, &qstr, false); -} - -static int ext4_d_hash(const struct dentry *dentry, struct qstr *str) -{ - const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb); - const struct unicode_map *um = sbi->s_encoding; - unsigned char *norm; - int len, ret = 0; - - if (!IS_CASEFOLDED(dentry->d_inode) || !um) - return 0; - - norm = kmalloc(PATH_MAX, GFP_ATOMIC); - if (!norm) - return -ENOMEM; - - len = utf8_casefold(um, str, norm, PATH_MAX); - if (len < 0) { - if (ext4_has_strict_mode(sbi)) - ret = -EINVAL; - goto out; - } - str->hash = full_name_hash(dentry, norm, len); -out: - kfree(norm); - return ret; -} - -const struct dentry_operations ext4_dentry_ops = { - .d_hash = ext4_d_hash, - .d_compare = ext4_d_compare, -}; -#endif diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index f8578caba40d5..3162ef2e53d46 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1430,10 +1430,6 @@ struct ext4_sb_info { struct kobject s_kobj; struct completion s_kobj_unregister; struct super_block *s_sb; -#ifdef CONFIG_UNICODE - struct unicode_map *s_encoding; - __u16 s_encoding_flags; -#endif /* Journaling */ struct journal_s *s_journal; diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c index 3e133793a5a34..143b0073b3f46 100644 --- a/fs/ext4/hash.c +++ b/fs/ext4/hash.c @@ -275,7 +275,7 @@ int ext4fs_dirhash(const struct inode *dir, const char *name, int len, struct dx_hash_info *hinfo) { #ifdef CONFIG_UNICODE - const struct unicode_map *um = EXT4_SB(dir->i_sb)->s_encoding; + const struct unicode_map *um = dir->i_sb->s_encoding; int r, dlen; unsigned char *buff; struct qstr qstr = {.name = name, .len = len }; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 1cb42d9407847..7f4e625ab2f9b 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1282,8 +1282,8 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) int ext4_ci_compare(const struct inode *parent, const struct qstr *name, const struct qstr *entry, bool quick) { - const struct ext4_sb_info *sbi = EXT4_SB(parent->i_sb); - const struct unicode_map *um = sbi->s_encoding; + const struct super_block *sb = parent->i_sb; + const struct unicode_map *um = sb->s_encoding; int ret; if (quick) @@ -1295,7 +1295,7 @@ int ext4_ci_compare(const struct inode *parent, const struct qstr *name, /* Handle invalid character sequence as either an error * or as an opaque byte sequence. */ - if (ext4_has_strict_mode(sbi)) + if (sb_has_enc_strict_mode(sb)) return -EINVAL; if (name->len != entry->len) @@ -1312,7 +1312,7 @@ void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, { int len; - if (!IS_CASEFOLDED(dir) || !EXT4_SB(dir->i_sb)->s_encoding) { + if (!needs_casefold(dir)) { cf_name->name = NULL; return; } @@ -1321,7 +1321,7 @@ void ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, if (!cf_name->name) return; - len = utf8_casefold(EXT4_SB(dir->i_sb)->s_encoding, + len = utf8_casefold(dir->i_sb->s_encoding, iname, cf_name->name, EXT4_NAME_LEN); if (len <= 0) { @@ -1358,7 +1358,7 @@ static inline bool ext4_match(const struct inode *parent, #endif #ifdef CONFIG_UNICODE - if (EXT4_SB(parent->i_sb)->s_encoding && IS_CASEFOLDED(parent)) { + if (needs_casefold(parent)) { if (fname->cf_name.name) { struct qstr cf = {.name = fname->cf_name.name, .len = fname->cf_name.len}; @@ -2164,9 +2164,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, struct buffer_head *bh = NULL; struct ext4_dir_entry_2 *de; struct super_block *sb; -#ifdef CONFIG_UNICODE - struct ext4_sb_info *sbi; -#endif struct ext4_filename fname; int retval; int dx_fallback=0; @@ -2183,9 +2180,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, return -EINVAL; #ifdef CONFIG_UNICODE - sbi = EXT4_SB(sb); - if (ext4_has_strict_mode(sbi) && IS_CASEFOLDED(dir) && - sbi->s_encoding && utf8_validate(sbi->s_encoding, &dentry->d_name)) + if (sb_has_enc_strict_mode(sb) && IS_CASEFOLDED(dir) && + sb->s_encoding && utf8_validate(sb->s_encoding, &dentry->d_name)) return -EINVAL; #endif diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2937a8873fe13..11584bdc3e237 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1056,7 +1056,7 @@ static void ext4_put_super(struct super_block *sb) kfree(sbi->s_blockgroup_lock); fs_put_dax(sbi->s_daxdev); #ifdef CONFIG_UNICODE - utf8_unload(sbi->s_encoding); + utf8_unload(sb->s_encoding); #endif kfree(sbi); } @@ -3850,7 +3850,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount; #ifdef CONFIG_UNICODE - if (ext4_has_feature_casefold(sb) && !sbi->s_encoding) { + if (ext4_has_feature_casefold(sb) && !sb->s_encoding) { const struct ext4_sb_encodings *encoding_info; struct unicode_map *encoding; __u16 encoding_flags; @@ -3881,8 +3881,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) "%s-%s with flags 0x%hx", encoding_info->name, encoding_info->version?:"\b", encoding_flags); - sbi->s_encoding = encoding; - sbi->s_encoding_flags = encoding_flags; + sb->s_encoding = encoding; + sb->s_encoding_flags = encoding_flags; } #endif @@ -4497,11 +4497,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount4; } -#ifdef CONFIG_UNICODE - if (sbi->s_encoding) - sb->s_d_op = &ext4_dentry_ops; -#endif - sb->s_root = d_make_root(root); if (!sb->s_root) { ext4_msg(sb, KERN_ERR, "get root dentry failed"); @@ -4684,7 +4679,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) crypto_free_shash(sbi->s_chksum_driver); #ifdef CONFIG_UNICODE - utf8_unload(sbi->s_encoding); + utf8_unload(sb->s_encoding); #endif #ifdef CONFIG_QUOTA