From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 27B0E3F7AAD for ; Wed, 13 May 2026 08:56:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778662618; cv=none; b=o5dztrJlCTORZSR+TN4gpzg0BvMFtVSOlKriur91h6wUiqK3DGwf/0dUCUrdMShwTDWpTUd5/IAha++vlgHF5k29F2WaXtLIfPT49ZlMXwEYzqFtb64ArUxwUIylz4AYC+oCNdtEx4VyFxMZYhTrXztZj8DYY4DhsCJU664sjmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778662618; c=relaxed/simple; bh=esIb391sZGRZSHZilGwTjYpzvTY2uRldxrINHdARghY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rHesuG8z8n7Ie2wVdJuaikVngGui4wWHkzz2o5AQDe7WVMj2jdLbtPeN1SkLSyVlr4VWpYtOqcmtHNI29WyTa3K+y/nKNqo2zE/tk7Wd8y6rLNklQUep5gtxjlG3B7RmvVhXFFJH4K84SfVYmeRi7VnkoG3ONSF78S2TUKN/kxo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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-out2.suse.de (Postfix) with ESMTPS id E516976666; Wed, 13 May 2026 08:54:46 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 C4054593A9; Wed, 13 May 2026 08:54:46 +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 cOM7L1Y8BGpERwAAD6G6ig (envelope-from ); Wed, 13 May 2026 08:54:46 +0000 From: Daniel Vacek To: Chris Mason , Josef Bacik , Eric Biggers , "Theodore Y. Ts'o" , Jaegeuk Kim , Jens Axboe , David Sterba Cc: linux-block@vger.kernel.org, Daniel Vacek , linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 40/43] btrfs: support encryption with log replay Date: Wed, 13 May 2026 10:53:14 +0200 Message-ID: <20260513085340.3673127-41-neelx@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260513085340.3673127-1-neelx@suse.com> References: <20260513085340.3673127-1-neelx@suse.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Rspamd-Queue-Id: E516976666 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Rspamd-Action: no action From: Josef Bacik Log replay needs a few tweaks in order to make sure everything works with encryption. 1. Copy in the fscrypt context if we find one in the log. 2. Set NEEDS_FULL_SYNC when we update the inode context so all of the items are copied into the log at fsync time. This makes replay of encrypted files work properly. Signed-off-by: Josef Bacik Signed-off-by: Daniel Vacek --- No changes in v7. v6 changes: * Adapted to the redesigned encryption context storing. - No need to specially handle the extent item now. It is not any different to before and the new context items are simply copied. v5: https://lore.kernel.org/linux-btrfs/d1ada7ac632c2ab554a840c7ba29b53a93b9855f.1706116485.git.josef@toxicpanda.com/ --- fs/btrfs/fscrypt.c | 1 + fs/btrfs/tree-log.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/fscrypt.c b/fs/btrfs/fscrypt.c index a972c8eadfef..b57d2b0ca9fa 100644 --- a/fs/btrfs/fscrypt.c +++ b/fs/btrfs/fscrypt.c @@ -145,6 +145,7 @@ static int btrfs_fscrypt_set_context(struct inode *inode, const void *ctx, goto out_err; } + set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &BTRFS_I(inode)->runtime_flags); leaf = path->nodes[0]; ptr = btrfs_item_ptr_offset(leaf, path->slots[0]); diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index f3b839950855..4336f90e3223 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -2929,7 +2929,9 @@ static int replay_one_buffer(struct extent_buffer *eb, continue; /* these keys are simply copied */ - if (wc->log_key.type == BTRFS_XATTR_ITEM_KEY) { + if (wc->log_key.type == BTRFS_XATTR_ITEM_KEY || + wc->log_key.type == BTRFS_FSCRYPT_INODE_CTX_KEY || + wc->log_key.type == BTRFS_FSCRYPT_CTX_KEY) { ret = overwrite_item(wc); if (ret) break; -- 2.53.0