bcachefs: Remove bch2_enable_encryption() and bch2_disable_encryption()
PATCH 1/1 bcachefs: Remove bch2_enable_encryption() and bch2_disable_encryption()
From: Eric Biggers <[email protected]>
These functions are never called, so remove them.
--- fs/bcachefs/checksum.c | 90 ------------------------------------------ fs/bcachefs/checksum.h | 3 -- 2 files changed, 93 deletions(-)
fs/bcachefs/checksum.c +0 -90
@@ -8,11 +8,10 @@#include <linux/crc32c.h> #include <linux/crypto.h> #include <linux/xxhash.h> #include <linux/key.h> -#include <linux/random.h> #include <linux/ratelimit.h> #include <linux/scatterlist.h> #include <crypto/algapi.h> #include <crypto/chacha.h> #include <crypto/hash.h>
@@ -691,99 +690,10 @@ static int bch2_alloc_ciphers(struct bch_fs *c) c->chacha20 = chacha20; c->poly1305 = poly1305;return 0 ; } -int bch2_disable_encryption (struct bch_fs *c) -{ -struct bch_sb_field_crypt *crypt; -struct bch_key key; -int ret = -EINVAL ; - -mutex_lock (&c->sb_lock); - - crypt =bch2_sb_field_get (c->disk_sb.sb, crypt); -if (!crypt) - goto out; - -/* is key encrypted? */ - ret =0 ; -if (bch2_key_is_encrypted (&crypt->key)) - goto out; - - ret =bch2_decrypt_sb_key (c, crypt, &key); -if (ret) - goto out; - - crypt->key.magic =cpu_to_le64 (BCH_KEY_MAGIC ); - crypt->key.key = key; - -SET_BCH_SB_ENCRYPTION_TYPE (c->disk_sb.sb,0 ); -bch2_write_super (c); -out: -mutex_unlock (&c->sb_lock); - -return ret; -} - -int bch2_enable_encryption (struct bch_fs *c,bool keyed) -{ -struct bch_encrypted_key key; -struct bch_key user_key; -struct bch_sb_field_crypt *crypt; -int ret = -EINVAL ; - -mutex_lock (&c->sb_lock); - -/* Do we already have an encryption key? */ -if (bch2_sb_field_get (c->disk_sb.sb, crypt)) - goto err; - - ret =bch2_alloc_ciphers (c); -if (ret) - goto err; - - key.magic =cpu_to_le64 (BCH_KEY_MAGIC ); -get_random_bytes (&key.key,sizeof (key.key)); - -if (keyed) { - ret =bch2_request_key (c->disk_sb.sb, &user_key); -if (ret) { -bch_err (c,"error requesting encryption key: %s" ,bch2_err_str (ret)); - goto err; - } - - ret =bch2_chacha_encrypt_key (&user_key,bch2_sb_key_nonce (c), - &key,sizeof (key)); -if (ret) - goto err; - } - - ret =crypto_skcipher_setkey (&c->chacha20->base, - (void *) &key.key,sizeof (key.key)); -if (ret) - goto err; - - crypt =bch2_sb_field_resize (&c->disk_sb, crypt, -sizeof (*crypt) /sizeof (u64)); -if (!crypt) { - ret = -BCH_ERR_ENOSPC_sb_crypt; - goto err; - } - - crypt->key = key; - -/* write superblock */ -SET_BCH_SB_ENCRYPTION_TYPE (c->disk_sb.sb,1 ); -bch2_write_super (c); -err: -mutex_unlock (&c->sb_lock); -memzero_explicit (&user_key,sizeof (user_key)); -memzero_explicit (&key,sizeof (key)); -return ret; -} -void bch2_fs_encryption_exit (struct bch_fs *c) {if (c->poly1305)crypto_free_shash (c->poly1305);if (c->chacha20)
fs/bcachefs/checksum.h +0 -3
@@ -101,13 +101,10 @@ static inline int bch2_encrypt_bio(struct bch_fs *c, unsigned type,extern const struct bch_sb_field_ops bch_sb_field_ops_crypt;int bch2_decrypt_sb_key (struct bch_fs *,struct bch_sb_field_crypt *,struct bch_key *); -int bch2_disable_encryption (struct bch_fs *); -int bch2_enable_encryption (struct bch_fs *,bool ); -void bch2_fs_encryption_exit (struct bch_fs *);int bch2_fs_encryption_init (struct bch_fs *);static inline enum bch_csum_type bch2_csum_opt_to_type (enum bch_csum_opt type,bool data)
base-commit: da920b7df701770e006928053672147075587fb2
Signature · 1 line
2.49.0
Quoted 3 lines · Eric Biggers
From: Eric Biggers <[email protected]>
These functions are never called, so remove them.
I've had requests for enabling encryption on an existing filesystem, and I think that is something we should allow - I wrote the code and didn't hook it up at the time because I wanted to think about safety issues more.
So I'd rather just #if 0 it out, if the issue was that it was going to need to be updated for your other cleanups.
bch2_disable_encryption seems to be duplicating code that also exists in userspace, I don't see any reason for the userspace version to exist, this one looks cleaner, so let's also not delete that.
I'm applying this instead:
From a5331b44ab612f1609ee980389a8ea677e194d46 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <[email protected]>
Date: Sun, 16 Mar 2025 13:39:14 -0400
Subject: [PATCH] bcachefs: #if 0 out (enable|disable)_encryption()
These weren't hooked up, but they probably should be - add some comments for context.
fs/bcachefs/checksum.c +13 -0
@@ -693,6 +693,14 @@ static int bch2_alloc_ciphers(struct bch_fs *c)return 0 ; } +#if 0 + +/* +* This seems to be duplicating code in cmd_remove_passphrase() in +* bcachefs-tools, but we might want to switch userspace to use this - and +* perhaps add an ioctl for calling this at runtime, so we can take the +* passphrase off of a mounted filesystem (which has come up). +*/ int bch2_disable_encryption (struct bch_fs *c) {struct bch_sb_field_crypt *crypt;
@@ -725,6 +733,10 @@ int bch2_disable_encryption(struct bch_fs *c)return ret; } +/* +* For enabling encryption on an existing filesystem: not hooked up yet, but it +* should be +*/ int bch2_enable_encryption (struct bch_fs *c,bool keyed) {struct bch_encrypted_key key;
@@ -781,6 +793,7 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed)memzero_explicit (&key,sizeof (key)); return ret; } +#endif void bch2_fs_encryption_exit (struct bch_fs *c) {
fs/bcachefs/checksum.h +2 -0
@@ -103,8 +103,10 @@ extern const struct bch_sb_field_ops bch_sb_field_ops_crypt;int bch2_decrypt_sb_key (struct bch_fs *,struct bch_sb_field_crypt *,struct bch_key *); +#if 0 int bch2_disable_encryption (struct bch_fs *);int bch2_enable_encryption (struct bch_fs *,bool ); +#endif void bch2_fs_encryption_exit (struct bch_fs *);int bch2_fs_encryption_init (struct bch_fs *);