9ae3a8
From 3ba5256b9642a3313b9ffaf8abc0f6302e3e39e6 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:32:10 +0100
9ae3a8
Subject: [PATCH 17/87] bdrv: Use "Error" for creating images
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-20-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55319
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 19/43] bdrv: Use "Error" for creating images
9ae3a8
Bugzilla: 1026524
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
BZ: 1026524
9ae3a8
9ae3a8
Add an Error ** parameter to BlockDriver.bdrv_create to allow more
9ae3a8
specific error messages.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
(cherry picked from commit d5124c00d80b4d948509f2c7f6b54228d9981f75)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	block/raw.c
9ae3a8
	block/raw_bsd.c
9ae3a8
9ae3a8
Conflicts because raw_bsd.c does not exist downstream; instead, there is
9ae3a8
raw.c.
9ae3a8
---
9ae3a8
 block.c                   | 2 +-
9ae3a8
 block/cow.c               | 3 ++-
9ae3a8
 block/gluster.c           | 2 +-
9ae3a8
 block/iscsi.c             | 3 ++-
9ae3a8
 block/qcow.c              | 3 ++-
9ae3a8
 block/qcow2.c             | 3 ++-
9ae3a8
 block/qed.c               | 3 ++-
9ae3a8
 block/raw-posix.c         | 6 ++++--
9ae3a8
 block/raw-win32.c         | 3 ++-
9ae3a8
 block/raw.c               | 3 ++-
9ae3a8
 block/rbd.c               | 3 ++-
9ae3a8
 block/sheepdog.c          | 3 ++-
9ae3a8
 block/ssh.c               | 3 ++-
9ae3a8
 block/vdi.c               | 3 ++-
9ae3a8
 block/vmdk.c              | 3 ++-
9ae3a8
 block/vpc.c               | 3 ++-
9ae3a8
 include/block/block_int.h | 3 ++-
9ae3a8
 17 files changed, 34 insertions(+), 18 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c                   |    2 +-
9ae3a8
 block/cow.c               |    3 ++-
9ae3a8
 block/gluster.c           |    2 +-
9ae3a8
 block/iscsi.c             |    3 ++-
9ae3a8
 block/qcow.c              |    3 ++-
9ae3a8
 block/qcow2.c             |    3 ++-
9ae3a8
 block/qed.c               |    3 ++-
9ae3a8
 block/raw-posix.c         |    6 ++++--
9ae3a8
 block/raw-win32.c         |    3 ++-
9ae3a8
 block/raw.c               |    3 ++-
9ae3a8
 block/rbd.c               |    3 ++-
9ae3a8
 block/sheepdog.c          |    3 ++-
9ae3a8
 block/ssh.c               |    3 ++-
9ae3a8
 block/vdi.c               |    3 ++-
9ae3a8
 block/vmdk.c              |    3 ++-
9ae3a8
 block/vpc.c               |    3 ++-
9ae3a8
 include/block/block_int.h |    3 ++-
9ae3a8
 17 files changed, 34 insertions(+), 18 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 921fa33..0cb5ac9 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -373,7 +373,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
9ae3a8
     CreateCo *cco = opaque;
9ae3a8
     assert(cco->drv);
9ae3a8
 
9ae3a8
-    cco->ret = cco->drv->bdrv_create(cco->filename, cco->options);
9ae3a8
+    cco->ret = cco->drv->bdrv_create(cco->filename, cco->options, NULL);
9ae3a8
 }
9ae3a8
 
9ae3a8
 int bdrv_create(BlockDriver *drv, const char* filename,
9ae3a8
diff --git a/block/cow.c b/block/cow.c
9ae3a8
index ce8deb8..c1d2dc8 100644
9ae3a8
--- a/block/cow.c
9ae3a8
+++ b/block/cow.c
9ae3a8
@@ -295,7 +295,8 @@ static void cow_close(BlockDriverState *bs)
9ae3a8
 {
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int cow_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int cow_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     struct cow_header_v2 cow_header;
9ae3a8
     struct stat st;
9ae3a8
diff --git a/block/gluster.c b/block/gluster.c
9ae3a8
index fa46b6f..bf39264 100644
9ae3a8
--- a/block/gluster.c
9ae3a8
+++ b/block/gluster.c
9ae3a8
@@ -366,7 +366,7 @@ out:
9ae3a8
 }
9ae3a8
 
9ae3a8
 static int qemu_gluster_create(const char *filename,
9ae3a8
-        QEMUOptionParameter *options)
9ae3a8
+        QEMUOptionParameter *options, Error **errp)
9ae3a8
 {
9ae3a8
     struct glfs *glfs;
9ae3a8
     struct glfs_fd *fd;
9ae3a8
diff --git a/block/iscsi.c b/block/iscsi.c
9ae3a8
index 8d49e35..ac35caa 100644
9ae3a8
--- a/block/iscsi.c
9ae3a8
+++ b/block/iscsi.c
9ae3a8
@@ -1249,7 +1249,8 @@ static int iscsi_has_zero_init(BlockDriverState *bs)
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int iscsi_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int iscsi_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                        Error **errp)
9ae3a8
 {
9ae3a8
     int ret = 0;
9ae3a8
     int64_t total_size = 0;
9ae3a8
diff --git a/block/qcow.c b/block/qcow.c
9ae3a8
index b8887f0..1a6926f 100644
9ae3a8
--- a/block/qcow.c
9ae3a8
+++ b/block/qcow.c
9ae3a8
@@ -659,7 +659,8 @@ static void qcow_close(BlockDriverState *bs)
9ae3a8
     error_free(s->migration_blocker);
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int qcow_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int qcow_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                       Error **errp)
9ae3a8
 {
9ae3a8
     int header_size, backing_filename_len, l1_size, shift, i;
9ae3a8
     QCowHeader header;
9ae3a8
diff --git a/block/qcow2.c b/block/qcow2.c
9ae3a8
index 2e7e9f5..b6e50af 100644
9ae3a8
--- a/block/qcow2.c
9ae3a8
+++ b/block/qcow2.c
9ae3a8
@@ -1467,7 +1467,8 @@ out:
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int qcow2_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int qcow2_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                        Error **errp)
9ae3a8
 {
9ae3a8
     const char *backing_file = NULL;
9ae3a8
     const char *backing_fmt = NULL;
9ae3a8
diff --git a/block/qed.c b/block/qed.c
9ae3a8
index d49e0cd..c56b5e2 100644
9ae3a8
--- a/block/qed.c
9ae3a8
+++ b/block/qed.c
9ae3a8
@@ -604,7 +604,8 @@ out:
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                           Error **errp)
9ae3a8
 {
9ae3a8
     uint64_t image_size = 0;
9ae3a8
     uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE;
9ae3a8
diff --git a/block/raw-posix.c b/block/raw-posix.c
9ae3a8
index 5f4e824..249bffb 100644
9ae3a8
--- a/block/raw-posix.c
9ae3a8
+++ b/block/raw-posix.c
9ae3a8
@@ -1041,7 +1041,8 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
9ae3a8
     return (int64_t)st.st_blocks * 512;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int raw_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int raw_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     int fd;
9ae3a8
     int result = 0;
9ae3a8
@@ -1505,7 +1506,8 @@ static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
9ae3a8
                        cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int hdev_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int hdev_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                       Error **errp)
9ae3a8
 {
9ae3a8
     int fd;
9ae3a8
     int ret = 0;
9ae3a8
diff --git a/block/raw-win32.c b/block/raw-win32.c
9ae3a8
index 1cfec65..9ebb083 100644
9ae3a8
--- a/block/raw-win32.c
9ae3a8
+++ b/block/raw-win32.c
9ae3a8
@@ -421,7 +421,8 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
9ae3a8
     return st.st_size;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int raw_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int raw_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     int fd;
9ae3a8
     int64_t total_size = 0;
9ae3a8
diff --git a/block/raw.c b/block/raw.c
9ae3a8
index 801591d..f92c04e 100644
9ae3a8
--- a/block/raw.c
9ae3a8
+++ b/block/raw.c
9ae3a8
@@ -105,7 +105,8 @@ static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs,
9ae3a8
    return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque);
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int raw_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int raw_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     return bdrv_create_file(filename, options);
9ae3a8
 }
9ae3a8
diff --git a/block/rbd.c b/block/rbd.c
9ae3a8
index 8d4ae9f..169d3cf 100644
9ae3a8
--- a/block/rbd.c
9ae3a8
+++ b/block/rbd.c
9ae3a8
@@ -286,7 +286,8 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                           Error **errp)
9ae3a8
 {
9ae3a8
     int64_t bytes = 0;
9ae3a8
     int64_t objsize;
9ae3a8
diff --git a/block/sheepdog.c b/block/sheepdog.c
9ae3a8
index a8ce933..952d703 100644
9ae3a8
--- a/block/sheepdog.c
9ae3a8
+++ b/block/sheepdog.c
9ae3a8
@@ -1455,7 +1455,8 @@ out:
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int sd_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int sd_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                     Error **errp)
9ae3a8
 {
9ae3a8
     int ret = 0;
9ae3a8
     uint32_t vid = 0, base_vid = 0;
9ae3a8
diff --git a/block/ssh.c b/block/ssh.c
9ae3a8
index f950fcc..fa3c78d 100644
9ae3a8
--- a/block/ssh.c
9ae3a8
+++ b/block/ssh.c
9ae3a8
@@ -651,7 +651,8 @@ static QEMUOptionParameter ssh_create_options[] = {
9ae3a8
     { NULL }
9ae3a8
 };
9ae3a8
 
9ae3a8
-static int ssh_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int ssh_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     int r, ret;
9ae3a8
     Error *local_err = NULL;
9ae3a8
diff --git a/block/vdi.c b/block/vdi.c
9ae3a8
index 661c3f0..84860fe 100644
9ae3a8
--- a/block/vdi.c
9ae3a8
+++ b/block/vdi.c
9ae3a8
@@ -645,7 +645,8 @@ static int vdi_co_write(BlockDriverState *bs,
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int vdi_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int vdi_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     int fd;
9ae3a8
     int result = 0;
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index d9e2545..fa64f05 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -1552,7 +1552,8 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
9ae3a8
     return VMDK_OK;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int vmdk_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int vmdk_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                       Error **errp)
9ae3a8
 {
9ae3a8
     int fd, idx = 0;
9ae3a8
     char desc[BUF_SIZE];
9ae3a8
diff --git a/block/vpc.c b/block/vpc.c
9ae3a8
index cf5e751..5d65756 100644
9ae3a8
--- a/block/vpc.c
9ae3a8
+++ b/block/vpc.c
9ae3a8
@@ -684,7 +684,8 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size)
9ae3a8
     return ret;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int vpc_create(const char *filename, QEMUOptionParameter *options)
9ae3a8
+static int vpc_create(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                      Error **errp)
9ae3a8
 {
9ae3a8
     uint8_t buf[1024];
9ae3a8
     struct vhd_footer *footer = (struct vhd_footer *) buf;
9ae3a8
diff --git a/include/block/block_int.h b/include/block/block_int.h
9ae3a8
index 3450b46..696bbb9 100644
9ae3a8
--- a/include/block/block_int.h
9ae3a8
+++ b/include/block/block_int.h
9ae3a8
@@ -96,7 +96,8 @@ struct BlockDriver {
9ae3a8
                       const uint8_t *buf, int nb_sectors);
9ae3a8
     void (*bdrv_close)(BlockDriverState *bs);
9ae3a8
     void (*bdrv_rebind)(BlockDriverState *bs);
9ae3a8
-    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
9ae3a8
+    int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
9ae3a8
+                       Error **errp);
9ae3a8
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
9ae3a8
     int (*bdrv_make_empty)(BlockDriverState *bs);
9ae3a8
     /* aio */
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8