Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB0B11FAF; Sat, 27 Jan 2024 00:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314229; cv=none; b=Ot8+BPbn4Jo0FNePnO8UvBSwg02ayQvH0cHCZAWmUpkI/teWhDsdZcjkcemjlX7+z58DWUYAim+ATnELifG0OGlrY6ITKLg5liu2MVZGqhkhchJ78nEcVKZ6kj0/qDYfYiPVnP7Fr5pJuLzMFff1uekO48kPbaVpKmOv+GI779E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706314229; c=relaxed/simple; bh=bqvR1ioSLEXM1TsuTdhMpzk64b5FBELlWtE3yTRwBsg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B29nCR5Tz7DKhSmBkeC2BcAVAIrNzXgrT9sjPat+Wt1ZWP38ogS7sIqU8AdSOAnMQsTXIU+BITbxOJs0h0C+oJaoXHRt8wwW1i8JLY/8G+nLaoYq51RVoFMYQg38zStBUwwtIqyKCKfs5DWN8aTrrcBbbKFPNw9TsQliVkoQVjE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jMMuXVkp; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=HRpyaj48; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=jMMuXVkp; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=HRpyaj48; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jMMuXVkp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="HRpyaj48"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="jMMuXVkp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="HRpyaj48" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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) by smtp-out1.suse.de (Postfix) with ESMTPS id D895F223A6; Sat, 27 Jan 2024 00:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706314225; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWLoWz7nxQVTABtxNVN2ddgKtqXgJeF/RFCQQ5mld/o=; b=jMMuXVkpSpbPSJxsV3MIjpN6PGjfubZ2/yXiclzMuEn0RJNV9FUELM/eMcRAhjLkAL9pTG IU7BYBF2OWVU6w2Vrl05xIiweBOS6zDsA9CSfLUvD3FnJjO5XLc+/uXs/T0Ex2fFUfQ6br XQGGlOF6kFKeS60bvyB14zgEnzj4dpU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706314225; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWLoWz7nxQVTABtxNVN2ddgKtqXgJeF/RFCQQ5mld/o=; b=HRpyaj48NjSzHXdDa6Gt0uYnYFpLRilg5TqLOPVIa1y18+WKa4LXJsYesyDmW017tzf4Eb DmE0jXrcLBbZ2rAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706314225; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWLoWz7nxQVTABtxNVN2ddgKtqXgJeF/RFCQQ5mld/o=; b=jMMuXVkpSpbPSJxsV3MIjpN6PGjfubZ2/yXiclzMuEn0RJNV9FUELM/eMcRAhjLkAL9pTG IU7BYBF2OWVU6w2Vrl05xIiweBOS6zDsA9CSfLUvD3FnJjO5XLc+/uXs/T0Ex2fFUfQ6br XQGGlOF6kFKeS60bvyB14zgEnzj4dpU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706314225; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NWLoWz7nxQVTABtxNVN2ddgKtqXgJeF/RFCQQ5mld/o=; b=HRpyaj48NjSzHXdDa6Gt0uYnYFpLRilg5TqLOPVIa1y18+WKa4LXJsYesyDmW017tzf4Eb DmE0jXrcLBbZ2rAA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (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) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3C87613998; Sat, 27 Jan 2024 00:10:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GC/iN/BJtGVWEQAAD6G6ig (envelope-from ); Sat, 27 Jan 2024 00:10:24 +0000 From: Gabriel Krisman Bertazi To: ebiggers@kernel.org, viro@zeniv.linux.org.uk, jaegeuk@kernel.org, tytso@mit.edu Cc: amir73il@gmail.com, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v4 02/12] fscrypt: Factor out a helper to configure the lookup dentry Date: Fri, 26 Jan 2024 21:10:02 -0300 Message-ID: <20240127001013.2845-3-krisman@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240127001013.2845-1-krisman@suse.de> References: <20240127001013.2845-1-krisman@suse.de> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: *** X-Spam-Score: 3.70 X-Spamd-Result: default: False [3.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[9]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com,vger.kernel.org,lists.sourceforge.net,suse.de]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[14.58%] X-Spam-Flag: NO Both fscrypt_prepare_lookup_dentry_partial and fscrypt_prepare_lookup_dentry will set DCACHE_NOKEY_NAME for dentries when the key is not available. Extract out a helper to set this flag in a single place, in preparation to also add the optimization that will disable ->d_revalidate if possible. Signed-off-by: Gabriel Krisman Bertazi --- fs/crypto/hooks.c | 18 ++++++++---------- include/linux/fscrypt.h | 10 ++++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c index 52504dd478d3..71463cef08f9 100644 --- a/fs/crypto/hooks.c +++ b/fs/crypto/hooks.c @@ -102,11 +102,8 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry, if (err && err != -ENOENT) return err; - if (fname->is_nokey_name) { - spin_lock(&dentry->d_lock); - dentry->d_flags |= DCACHE_NOKEY_NAME; - spin_unlock(&dentry->d_lock); - } + fscrypt_prepare_lookup_dentry(dentry, fname->is_nokey_name); + return err; } EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup); @@ -131,12 +128,13 @@ EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup); int fscrypt_prepare_lookup_partial(struct inode *dir, struct dentry *dentry) { int err = fscrypt_get_encryption_info(dir, true); + bool is_nokey_name = false; + + if (!err && !fscrypt_has_encryption_key(dir)) + is_nokey_name = true; + + fscrypt_prepare_lookup_dentry(dentry, is_nokey_name); - if (!err && !fscrypt_has_encryption_key(dir)) { - spin_lock(&dentry->d_lock); - dentry->d_flags |= DCACHE_NOKEY_NAME; - spin_unlock(&dentry->d_lock); - } return err; } EXPORT_SYMBOL_GPL(fscrypt_prepare_lookup_partial); diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h index 12f9e455d569..68ca8706483a 100644 --- a/include/linux/fscrypt.h +++ b/include/linux/fscrypt.h @@ -948,6 +948,16 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir, return 0; } +static inline void fscrypt_prepare_lookup_dentry(struct dentry *dentry, + bool is_nokey_name) +{ + if (is_nokey_name) { + spin_lock(&dentry->d_lock); + dentry->d_flags |= DCACHE_NOKEY_NAME; + spin_unlock(&dentry->d_lock); + } +} + /** * fscrypt_prepare_lookup() - prepare to lookup a name in a possibly-encrypted * directory -- 2.43.0