[RFC PATCH 14/19] btrfs: allow reading compressed encrypted extents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Mark Harmstone <mark@xxxxxxxxxxxxx>
---
 fs/btrfs/compression.c | 22 ++++++++++++++++++++++
 fs/btrfs/compression.h |  7 +++++++
 2 files changed, 29 insertions(+)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 2955a4ea2fa8..55d7b97a7dc9 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -26,6 +26,7 @@
 #include "compression.h"
 #include "extent_io.h"
 #include "extent_map.h"
+#include "encryption.h"
 
 static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" };
 
@@ -139,6 +140,20 @@ static void end_compressed_bio_read(struct bio *bio)
 	if (ret)
 		goto csum_failed;
 
+	if (cb->key_number != 0) {
+		struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+		unsigned int i;
+
+		for (i = 0; i < cb->nr_pages; i++) {
+			ret = btrfs_decrypt_page(fs_info,
+				cb->compressed_pages[i], cb->key_number,
+				cb->iv);
+
+			if (ret)
+				goto csum_failed;
+		}
+	}
+
 	/* ok, we're the last bio for this extent, lets start
 	 * the decompression.
 	 */
@@ -568,6 +583,13 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 	em_len = em->len;
 	em_start = em->start;
 
+	if (em->encrypt_type == BTRFS_ENCRYPTION_NONE) {
+		cb->key_number = 0;
+	} else {
+		cb->key_number = em->key_number;
+		memcpy(cb->iv, em->iv, BTRFS_ENCRYPTION_BLOCK_LENGTH);
+	}
+
 	free_extent_map(em);
 	em = NULL;
 
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index ddda9b80bf20..86a536d8cd5f 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -7,6 +7,7 @@
 #define BTRFS_COMPRESSION_H
 
 #include <linux/sizes.h>
+#include <linux/btrfs_tree.h>
 
 /*
  * We want to make sure that amount of RAM required to uncompress an extent is
@@ -54,6 +55,12 @@ struct compressed_bio {
 	int errors;
 	int mirror_num;
 
+	/* encryption key number */
+	u64 key_number;
+
+	/* encryption initialization vector */
+	char iv[BTRFS_ENCRYPTION_BLOCK_LENGTH];
+
 	/* for reads, this is the bio we are copying the data into */
 	struct bio *orig_bio;
 
-- 
2.19.2




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux