aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-11-14 15:09:46 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2011-11-21 14:58:48 -0600
commit06d9260ffa9dfa0e96e015501e43480ab66f96f6 (patch)
tree9bdc46875d7d17cd87c615e87486675450084c78
parent0f15423c3234335ca0dbeeae6d19db4699faca07 (diff)
downloadqemu-06d9260ffa9dfa0e96e015501e43480ab66f96f6.zip
qemu-06d9260ffa9dfa0e96e015501e43480ab66f96f6.tar.gz
qemu-06d9260ffa9dfa0e96e015501e43480ab66f96f6.tar.bz2
qcow2: implement bdrv_invalidate_cache (v2)
We don't reopen the actual file, but instead invoke the close and open routines. We specifically ignore the backing file since it's contents are read-only and therefore immutable. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--block/qcow2.c34
-rw-r--r--block/qcow2.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 5c784ee..d7805ce 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -240,6 +240,7 @@ static int qcow2_open(BlockDriverState *bs, int flags)
s->cluster_data = qemu_blockalign(bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size
+ 512);
s->cluster_cache_offset = -1;
+ s->flags = flags;
ret = qcow2_refcount_init(bs);
if (ret != 0) {
@@ -632,6 +633,37 @@ static void qcow2_close(BlockDriverState *bs)
qcow2_refcount_close(bs);
}
+static void qcow2_invalidate_cache(BlockDriverState *bs)
+{
+ BDRVQcowState *s = bs->opaque;
+ int flags = s->flags;
+ AES_KEY aes_encrypt_key;
+ AES_KEY aes_decrypt_key;
+ uint32_t crypt_method = 0;
+
+ /*
+ * Backing files are read-only which makes all of their metadata immutable,
+ * that means we don't have to worry about reopening them here.
+ */
+
+ if (s->crypt_method) {
+ crypt_method = s->crypt_method;
+ memcpy(&aes_encrypt_key, &s->aes_encrypt_key, sizeof(aes_encrypt_key));
+ memcpy(&aes_decrypt_key, &s->aes_decrypt_key, sizeof(aes_decrypt_key));
+ }
+
+ qcow2_close(bs);
+
+ memset(s, 0, sizeof(BDRVQcowState));
+ qcow2_open(bs, flags);
+
+ if (crypt_method) {
+ s->crypt_method = crypt_method;
+ memcpy(&s->aes_encrypt_key, &aes_encrypt_key, sizeof(aes_encrypt_key));
+ memcpy(&s->aes_decrypt_key, &aes_decrypt_key, sizeof(aes_decrypt_key));
+ }
+}
+
/*
* Updates the variable length parts of the qcow2 header, i.e. the backing file
* name and all extensions. qcow2 was not designed to allow such changes, so if
@@ -1269,6 +1301,8 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_change_backing_file = qcow2_change_backing_file,
+ .bdrv_invalidate_cache = qcow2_invalidate_cache,
+
.create_options = qcow2_create_options,
.bdrv_check = qcow2_check,
};
diff --git a/block/qcow2.h b/block/qcow2.h
index 531af39..4e44eea 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -125,6 +125,8 @@ typedef struct BDRVQcowState {
int snapshots_size;
int nb_snapshots;
QCowSnapshot *snapshots;
+
+ int flags;
} BDRVQcowState;
/* XXX: use std qcow open function ? */