[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V4 02/30] qcow2: Add deduplication structures and fiel
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V4 02/30] qcow2: Add deduplication structures and fields. |
Date: |
Wed, 2 Jan 2013 17:16:05 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index 718b52b..637c86a 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -58,6 +58,50 @@
#define DEFAULT_CLUSTER_SIZE 65536
+#define HASH_LENGTH 32
+
+typedef enum {
+ QCOW_HASH_SHA256 = 0,
+ QCOW_HASH_SHA3 = 1,
+ QCOW_HASH_SKEIN = 2,
+} QCowHashAlgo;
+
+typedef struct {
+ uint8_t data[HASH_LENGTH]; /* 32 bytes hash of a given cluster */
+} QCowHash;
+
+/* Used to keep a single precomputed hash between the calls of the dedup
+ * function
+ */
+typedef struct {
+ QCowHash hash;
+ bool reuse; /* The hash is precomputed reuse it */
+} QcowPersistantHash;
+
+/* deduplication node */
+typedef struct {
+ QCowHash hash;
+ uint64_t physical_sect; /* where the cluster is stored on disk */
+ uint64_t first_logical_sect; /* logical sector of the first occurence of
+ * this cluster
+ */
+} QCowHashNode;
+
+/* Undedupable hashes that must be written later to disk */
+typedef struct QCowHashElement {
+ QCowHash hash;
+ QTAILQ_ENTRY(QCowHashElement) next;
+} QCowHashElement;
+
+typedef struct {
+ QcowPersistantHash phash; /* contains a hash persisting between calls of
+ * qcow2_dedup()
+ */
+ QTAILQ_HEAD(, QCowHashElement) undedupables;
+ int nb_clusters_processed;
+ int nb_undedupable_sectors;
+} QCowDedupState;
+
typedef struct QCowHeader {
uint32_t magic;
uint32_t version;
@@ -114,8 +158,10 @@ enum {
enum {
QCOW2_INCOMPAT_DIRTY_BITNR = 0,
QCOW2_INCOMPAT_DIRTY = 1 << QCOW2_INCOMPAT_DIRTY_BITNR,
+ QCOW2_INCOMPAT_DEDUP_BITNR = 1,
+ QCOW2_INCOMPAT_DEDUP = 1 << QCOW2_INCOMPAT_DEDUP_BITNR,
- QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY,
+ QCOW2_INCOMPAT_MASK = QCOW2_INCOMPAT_DIRTY | QCOW2_INCOMPAT_DEDUP,
};
/* Compatible feature bits */
@@ -138,6 +184,7 @@ typedef struct BDRVQcowState {
int cluster_sectors;
int l2_bits;
int l2_size;
+ int hash_block_size;
int l1_size;
int l1_vm_state_index;
int csize_shift;
@@ -148,6 +195,7 @@ typedef struct BDRVQcowState {
Qcow2Cache* l2_table_cache;
Qcow2Cache* refcount_block_cache;
+ Qcow2Cache *dedup_cluster_cache;
uint8_t *cluster_cache;
uint8_t *cluster_data;
@@ -160,6 +208,13 @@ typedef struct BDRVQcowState {
int64_t free_cluster_index;
int64_t free_byte_offset;
+ bool has_dedup;
+ QCowHashAlgo dedup_hash_algo;
+ uint64_t *dedup_table;
+ uint64_t dedup_table_offset;
+ int32_t dedup_table_size;
+ GTree *dedup_tree_by_hash;
+ GTree *dedup_tree_by_sect;
CoMutex lock;
uint32_t crypt_method; /* current crypt method, 0 if no key yet */
--
1.7.10.4
- [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 02/30] qcow2: Add deduplication structures and fields.,
Benoît Canet <=
- [Qemu-devel] [RFC V4 04/30] qcow2: Make update_refcount public., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 05/30] qcow2: Create a way to link to l2 tables when deduplicating., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 03/30] qcow2: Add qcow2_de dup_read_missing_and_concatenate, Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 07/30] qcow2: Add qcow2_dedup_store_new_hashes., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 08/30] qcow2: Implement qcow2_compute_cluster_hash., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 09/30] qcow2: Extract qcow2_dedup_grow_table, Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 10/30] qcow2: Add qcow2_dedup_grow_table and use it., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 14/30] qcow2-cache: Allow to choose table size at creation., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 15/30] qcow2: Add qcow2_dedup_init and qcow2_dedup_close., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 17/30] block: Add qemu-img dedup create option., Benoît Canet, 2013/01/02