cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-change-default-of-.has_zero_init-to-0.patch.patch

9ae3a8
From c8cc35838d42aa286242772d97e3a9be7bb786ba Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Date: Mon, 9 Dec 2013 14:08:49 +0100
9ae3a8
Subject: [PATCH 01/50] block: change default of .has_zero_init to 0
9ae3a8
9ae3a8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: <1386598178-11845-4-git-send-email-pbonzini@redhat.com>
9ae3a8
Patchwork-id: 56040
9ae3a8
O-Subject: [RHEL 7.0 qemu-kvm PATCH 03/52] block: change default of .has_zero_init to 0
9ae3a8
Bugzilla: 1007815
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Peter Lieven <pl@kamp.de>
9ae3a8
9ae3a8
.has_zero_init defaults to 1 for all formats and protocols.
9ae3a8
9ae3a8
this is a dangerous default since this means that all
9ae3a8
new added drivers need to manually overwrite it to 0 if
9ae3a8
they do not ensure that a device is zero initialized
9ae3a8
after bdrv_create().
9ae3a8
9ae3a8
if a driver needs to explicitly set this value to
9ae3a8
1 its easier to verify the correctness in the review process.
9ae3a8
9ae3a8
during review of the existing drivers it turned out
9ae3a8
that ssh and gluster had a wrong default of 1.
9ae3a8
both protocols support host_devices as backend
9ae3a8
which are not by default zero initialized. this
9ae3a8
wrong assumption will lead to possible corruption
9ae3a8
if qemu-img convert is used to write to such a backend.
9ae3a8
9ae3a8
vpc and vmdk also defaulted to 1 altough they support
9ae3a8
fixed respectively flat extends. this has to be addresses
9ae3a8
in separate patches. both formats as well as the mentioned
9ae3a8
ssh and gluster are turned to the default of 0 with this
9ae3a8
patch for safety.
9ae3a8
9ae3a8
a similar problem with the wrong default existed for
9ae3a8
iscsi most likely because the driver developer did
9ae3a8
oversee the default value of 1.
9ae3a8
9ae3a8
Signed-off-by: Peter Lieven <pl@kamp.de>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 3ac216270a62418519c08e88c17005a8f1539cf2)
9ae3a8
9ae3a8
Conflicts: [due to get_block_status going in RHEL7 before this patch]
9ae3a8
	block/qcow2.c
9ae3a8
	block/qed.c
9ae3a8
	block/raw-posix.c
9ae3a8
	block/vdi.c
9ae3a8
---
9ae3a8
 block.c               |  8 +++++++-
9ae3a8
 block/cow.c           |  1 +
9ae3a8
 block/qcow.c          |  1 +
9ae3a8
 block/qcow2.c         |  1 +
9ae3a8
 block/qed.c           |  1 +
9ae3a8
 block/raw-posix.c     | 10 +---------
9ae3a8
 block/raw-win32.c     |  7 +------
9ae3a8
 block/rbd.c           |  1 +
9ae3a8
 block/sheepdog.c      |  1 +
9ae3a8
 block/vdi.c           |  1 +
9ae3a8
 include/block/block.h |  1 +
9ae3a8
 11 files changed, 17 insertions(+), 16 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 block.c               |  8 +++++++-
9ae3a8
 block/cow.c           |  1 +
9ae3a8
 block/qcow.c          |  1 +
9ae3a8
 block/qcow2.c         |  1 +
9ae3a8
 block/qed.c           |  1 +
9ae3a8
 block/raw-posix.c     | 10 +---------
9ae3a8
 block/raw-win32.c     |  7 +------
9ae3a8
 block/rbd.c           |  1 +
9ae3a8
 block/sheepdog.c      |  1 +
9ae3a8
 block/vdi.c           |  1 +
9ae3a8
 include/block/block.h |  1 +
9ae3a8
 11 files changed, 17 insertions(+), 16 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 8ef07bb..02994ec 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -3098,6 +3098,11 @@ int bdrv_flush_all(void)
9ae3a8
     return result;
9ae3a8
 }
9ae3a8
 
9ae3a8
+int bdrv_has_zero_init_1(BlockDriverState *bs)
9ae3a8
+{
9ae3a8
+    return 1;
9ae3a8
+}
9ae3a8
+
9ae3a8
 int bdrv_has_zero_init(BlockDriverState *bs)
9ae3a8
 {
9ae3a8
     assert(bs->drv);
9ae3a8
@@ -3111,7 +3116,8 @@ int bdrv_has_zero_init(BlockDriverState *bs)
9ae3a8
         return bs->drv->bdrv_has_zero_init(bs);
9ae3a8
     }
9ae3a8
 
9ae3a8
-    return 1;
9ae3a8
+    /* safe default */
9ae3a8
+    return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
 typedef struct BdrvCoGetBlockStatusData {
9ae3a8
diff --git a/block/cow.c b/block/cow.c
9ae3a8
index cd78129..cb9a3b0 100644
9ae3a8
--- a/block/cow.c
9ae3a8
+++ b/block/cow.c
9ae3a8
@@ -386,6 +386,7 @@ static BlockDriver bdrv_cow = {
9ae3a8
     .bdrv_open      = cow_open,
9ae3a8
     .bdrv_close     = cow_close,
9ae3a8
     .bdrv_create    = cow_create,
9ae3a8
+    .bdrv_has_zero_init     = bdrv_has_zero_init_1,
9ae3a8
 
9ae3a8
     .bdrv_read              = cow_co_read,
9ae3a8
     .bdrv_write             = cow_co_write,
9ae3a8
diff --git a/block/qcow.c b/block/qcow.c
9ae3a8
index 6d029cc..6bc2358 100644
9ae3a8
--- a/block/qcow.c
9ae3a8
+++ b/block/qcow.c
9ae3a8
@@ -906,6 +906,7 @@ static BlockDriver bdrv_qcow = {
9ae3a8
     .bdrv_close		= qcow_close,
9ae3a8
     .bdrv_reopen_prepare = qcow_reopen_prepare,
9ae3a8
     .bdrv_create	= qcow_create,
9ae3a8
+    .bdrv_has_zero_init     = bdrv_has_zero_init_1,
9ae3a8
 
9ae3a8
     .bdrv_co_readv          = qcow_co_readv,
9ae3a8
     .bdrv_co_writev         = qcow_co_writev,
9ae3a8
diff --git a/block/qcow2.c b/block/qcow2.c
9ae3a8
index 850d1c2..8de8892 100644
9ae3a8
--- a/block/qcow2.c
9ae3a8
+++ b/block/qcow2.c
9ae3a8
@@ -2034,6 +2034,7 @@ static BlockDriver bdrv_qcow2 = {
9ae3a8
     .bdrv_close         = qcow2_close,
9ae3a8
     .bdrv_reopen_prepare  = qcow2_reopen_prepare,
9ae3a8
     .bdrv_create        = qcow2_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_co_get_block_status = qcow2_co_get_block_status,
9ae3a8
     .bdrv_set_key       = qcow2_set_key,
9ae3a8
     .bdrv_make_empty    = qcow2_make_empty,
9ae3a8
diff --git a/block/qed.c b/block/qed.c
9ae3a8
index 7b13bb5..084dc0a 100644
9ae3a8
--- a/block/qed.c
9ae3a8
+++ b/block/qed.c
9ae3a8
@@ -1603,6 +1603,7 @@ static BlockDriver bdrv_qed = {
9ae3a8
     .bdrv_close               = bdrv_qed_close,
9ae3a8
     .bdrv_reopen_prepare      = bdrv_qed_reopen_prepare,
9ae3a8
     .bdrv_create              = bdrv_qed_create,
9ae3a8
+    .bdrv_has_zero_init       = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
9ae3a8
     .bdrv_make_empty          = bdrv_qed_make_empty,
9ae3a8
     .bdrv_aio_readv           = bdrv_qed_aio_readv,
9ae3a8
diff --git a/block/raw-posix.c b/block/raw-posix.c
9ae3a8
index eae1b40..c2b3dfd 100644
9ae3a8
--- a/block/raw-posix.c
9ae3a8
+++ b/block/raw-posix.c
9ae3a8
@@ -1220,6 +1220,7 @@ static BlockDriver bdrv_file = {
9ae3a8
     .bdrv_reopen_abort = raw_reopen_abort,
9ae3a8
     .bdrv_close = raw_close,
9ae3a8
     .bdrv_create = raw_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_co_get_block_status = raw_co_get_block_status,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv = raw_aio_readv,
9ae3a8
@@ -1563,11 +1564,6 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int hdev_has_zero_init(BlockDriverState *bs)
9ae3a8
-{
9ae3a8
-    return 0;
9ae3a8
-}
9ae3a8
-
9ae3a8
 static BlockDriver bdrv_host_device = {
9ae3a8
     .format_name        = "host_device",
9ae3a8
     .protocol_name        = "host_device",
9ae3a8
@@ -1580,7 +1576,6 @@ static BlockDriver bdrv_host_device = {
9ae3a8
     .bdrv_reopen_abort   = raw_reopen_abort,
9ae3a8
     .bdrv_create        = hdev_create,
9ae3a8
     .create_options     = raw_create_options,
9ae3a8
-    .bdrv_has_zero_init = hdev_has_zero_init,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv	= raw_aio_readv,
9ae3a8
     .bdrv_aio_writev	= raw_aio_writev,
9ae3a8
@@ -1711,7 +1706,6 @@ static BlockDriver bdrv_host_floppy = {
9ae3a8
     .bdrv_reopen_abort   = raw_reopen_abort,
9ae3a8
     .bdrv_create        = hdev_create,
9ae3a8
     .create_options     = raw_create_options,
9ae3a8
-    .bdrv_has_zero_init = hdev_has_zero_init,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv     = raw_aio_readv,
9ae3a8
     .bdrv_aio_writev    = raw_aio_writev,
9ae3a8
@@ -1821,7 +1815,6 @@ static BlockDriver bdrv_host_cdrom = {
9ae3a8
     .bdrv_reopen_abort   = raw_reopen_abort,
9ae3a8
     .bdrv_create        = hdev_create,
9ae3a8
     .create_options     = raw_create_options,
9ae3a8
-    .bdrv_has_zero_init = hdev_has_zero_init,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv     = raw_aio_readv,
9ae3a8
     .bdrv_aio_writev    = raw_aio_writev,
9ae3a8
@@ -1949,7 +1942,6 @@ static BlockDriver bdrv_host_cdrom = {
9ae3a8
     .bdrv_reopen_abort   = raw_reopen_abort,
9ae3a8
     .bdrv_create        = hdev_create,
9ae3a8
     .create_options     = raw_create_options,
9ae3a8
-    .bdrv_has_zero_init = hdev_has_zero_init,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv     = raw_aio_readv,
9ae3a8
     .bdrv_aio_writev    = raw_aio_writev,
9ae3a8
diff --git a/block/raw-win32.c b/block/raw-win32.c
9ae3a8
index 584790f..6ac3797 100644
9ae3a8
--- a/block/raw-win32.c
9ae3a8
+++ b/block/raw-win32.c
9ae3a8
@@ -465,6 +465,7 @@ static BlockDriver bdrv_file = {
9ae3a8
     .bdrv_file_open	= raw_open,
9ae3a8
     .bdrv_close		= raw_close,
9ae3a8
     .bdrv_create	= raw_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv     = raw_aio_readv,
9ae3a8
     .bdrv_aio_writev    = raw_aio_writev,
9ae3a8
@@ -600,11 +601,6 @@ done:
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int hdev_has_zero_init(BlockDriverState *bs)
9ae3a8
-{
9ae3a8
-    return 0;
9ae3a8
-}
9ae3a8
-
9ae3a8
 static BlockDriver bdrv_host_device = {
9ae3a8
     .format_name	= "host_device",
9ae3a8
     .protocol_name	= "host_device",
9ae3a8
@@ -612,7 +608,6 @@ static BlockDriver bdrv_host_device = {
9ae3a8
     .bdrv_probe_device	= hdev_probe_device,
9ae3a8
     .bdrv_file_open	= hdev_open,
9ae3a8
     .bdrv_close		= raw_close,
9ae3a8
-    .bdrv_has_zero_init = hdev_has_zero_init,
9ae3a8
 
9ae3a8
     .bdrv_aio_readv     = raw_aio_readv,
9ae3a8
     .bdrv_aio_writev    = raw_aio_writev,
9ae3a8
diff --git a/block/rbd.c b/block/rbd.c
9ae3a8
index 169d3cf..b870401 100644
9ae3a8
--- a/block/rbd.c
9ae3a8
+++ b/block/rbd.c
9ae3a8
@@ -974,6 +974,7 @@ static BlockDriver bdrv_rbd = {
9ae3a8
     .bdrv_file_open     = qemu_rbd_open,
9ae3a8
     .bdrv_close         = qemu_rbd_close,
9ae3a8
     .bdrv_create        = qemu_rbd_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_get_info      = qemu_rbd_getinfo,
9ae3a8
     .create_options     = qemu_rbd_create_options,
9ae3a8
     .bdrv_getlength     = qemu_rbd_getlength,
9ae3a8
diff --git a/block/sheepdog.c b/block/sheepdog.c
9ae3a8
index e7c4448..09203ad 100644
9ae3a8
--- a/block/sheepdog.c
9ae3a8
+++ b/block/sheepdog.c
9ae3a8
@@ -2411,6 +2411,7 @@ static BlockDriver bdrv_sheepdog_unix = {
9ae3a8
     .bdrv_file_open = sd_open,
9ae3a8
     .bdrv_close     = sd_close,
9ae3a8
     .bdrv_create    = sd_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_getlength = sd_getlength,
9ae3a8
     .bdrv_truncate  = sd_truncate,
9ae3a8
 
9ae3a8
diff --git a/block/vdi.c b/block/vdi.c
9ae3a8
index 84860fe..dcbc27c 100644
9ae3a8
--- a/block/vdi.c
9ae3a8
+++ b/block/vdi.c
9ae3a8
@@ -792,6 +792,7 @@ static BlockDriver bdrv_vdi = {
9ae3a8
     .bdrv_close = vdi_close,
9ae3a8
     .bdrv_reopen_prepare = vdi_reopen_prepare,
9ae3a8
     .bdrv_create = vdi_create,
9ae3a8
+    .bdrv_has_zero_init = bdrv_has_zero_init_1,
9ae3a8
     .bdrv_co_get_block_status = vdi_co_get_block_status,
9ae3a8
     .bdrv_make_empty = vdi_make_empty,
9ae3a8
 
9ae3a8
diff --git a/include/block/block.h b/include/block/block.h
9ae3a8
index 656570e..15ffbd2 100644
9ae3a8
--- a/include/block/block.h
9ae3a8
+++ b/include/block/block.h
9ae3a8
@@ -300,6 +300,7 @@ void bdrv_drain_all(void);
9ae3a8
 
9ae3a8
 int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
9ae3a8
 int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
9ae3a8
+int bdrv_has_zero_init_1(BlockDriverState *bs);
9ae3a8
 int bdrv_has_zero_init(BlockDriverState *bs);
9ae3a8
 int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
9ae3a8
                               int nb_sectors, int *pnum);
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8