bdrv: Use "Error" for creating images

Add an Error ** parameter to BlockDriver.bdrv_create to allow more
specific error messages.

Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Max Reitz 2013-09-05 14:26:05 +02:00 committed by Kevin Wolf
parent 015a1036a7
commit d5124c00d8
17 changed files with 34 additions and 18 deletions

View File

@ -401,7 +401,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
CreateCo *cco = opaque; CreateCo *cco = opaque;
assert(cco->drv); assert(cco->drv);
cco->ret = cco->drv->bdrv_create(cco->filename, cco->options); cco->ret = cco->drv->bdrv_create(cco->filename, cco->options, NULL);
} }
int bdrv_create(BlockDriver *drv, const char* filename, int bdrv_create(BlockDriver *drv, const char* filename,

View File

@ -295,7 +295,8 @@ static void cow_close(BlockDriverState *bs)
{ {
} }
static int cow_create(const char *filename, QEMUOptionParameter *options) static int cow_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
struct cow_header_v2 cow_header; struct cow_header_v2 cow_header;
struct stat st; struct stat st;

View File

@ -357,7 +357,7 @@ out:
} }
static int qemu_gluster_create(const char *filename, static int qemu_gluster_create(const char *filename,
QEMUOptionParameter *options) QEMUOptionParameter *options, Error **errp)
{ {
struct glfs *glfs; struct glfs *glfs;
struct glfs_fd *fd; struct glfs_fd *fd;

View File

@ -1238,7 +1238,8 @@ static int iscsi_has_zero_init(BlockDriverState *bs)
return 0; return 0;
} }
static int iscsi_create(const char *filename, QEMUOptionParameter *options) static int iscsi_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int ret = 0; int ret = 0;
int64_t total_size = 0; int64_t total_size = 0;

View File

@ -659,7 +659,8 @@ static void qcow_close(BlockDriverState *bs)
error_free(s->migration_blocker); error_free(s->migration_blocker);
} }
static int qcow_create(const char *filename, QEMUOptionParameter *options) static int qcow_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int header_size, backing_filename_len, l1_size, shift, i; int header_size, backing_filename_len, l1_size, shift, i;
QCowHeader header; QCowHeader header;

View File

@ -1468,7 +1468,8 @@ out:
return ret; return ret;
} }
static int qcow2_create(const char *filename, QEMUOptionParameter *options) static int qcow2_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
const char *backing_file = NULL; const char *backing_file = NULL;
const char *backing_fmt = NULL; const char *backing_fmt = NULL;

View File

@ -604,7 +604,8 @@ out:
return ret; return ret;
} }
static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options) static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
uint64_t image_size = 0; uint64_t image_size = 0;
uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE; uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE;

View File

@ -1041,7 +1041,8 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
return (int64_t)st.st_blocks * 512; return (int64_t)st.st_blocks * 512;
} }
static int raw_create(const char *filename, QEMUOptionParameter *options) static int raw_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int fd; int fd;
int result = 0; int result = 0;
@ -1506,7 +1507,8 @@ static coroutine_fn BlockDriverAIOCB *hdev_aio_discard(BlockDriverState *bs,
cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV); cb, opaque, QEMU_AIO_DISCARD|QEMU_AIO_BLKDEV);
} }
static int hdev_create(const char *filename, QEMUOptionParameter *options) static int hdev_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int fd; int fd;
int ret = 0; int ret = 0;

View File

@ -422,7 +422,8 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
return st.st_size; return st.st_size;
} }
static int raw_create(const char *filename, QEMUOptionParameter *options) static int raw_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int fd; int fd;
int64_t total_size = 0; int64_t total_size = 0;

View File

@ -130,7 +130,8 @@ static int raw_has_zero_init(BlockDriverState *bs)
return bdrv_has_zero_init(bs->file); return bdrv_has_zero_init(bs->file);
} }
static int raw_create(const char *filename, QEMUOptionParameter *options) static int raw_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
return bdrv_create_file(filename, options); return bdrv_create_file(filename, options);
} }

View File

@ -287,7 +287,8 @@ static int qemu_rbd_set_conf(rados_t cluster, const char *conf)
return ret; return ret;
} }
static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options) static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int64_t bytes = 0; int64_t bytes = 0;
int64_t objsize; int64_t objsize;

View File

@ -1438,7 +1438,8 @@ out:
return ret; return ret;
} }
static int sd_create(const char *filename, QEMUOptionParameter *options) static int sd_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int ret = 0; int ret = 0;
uint32_t vid = 0, base_vid = 0; uint32_t vid = 0, base_vid = 0;

View File

@ -651,7 +651,8 @@ static QEMUOptionParameter ssh_create_options[] = {
{ NULL } { NULL }
}; };
static int ssh_create(const char *filename, QEMUOptionParameter *options) static int ssh_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int r, ret; int r, ret;
Error *local_err = NULL; Error *local_err = NULL;

View File

@ -645,7 +645,8 @@ static int vdi_co_write(BlockDriverState *bs,
return ret; return ret;
} }
static int vdi_create(const char *filename, QEMUOptionParameter *options) static int vdi_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int fd; int fd;
int result = 0; int result = 0;

View File

@ -1552,7 +1552,8 @@ static int filename_decompose(const char *filename, char *path, char *prefix,
return VMDK_OK; return VMDK_OK;
} }
static int vmdk_create(const char *filename, QEMUOptionParameter *options) static int vmdk_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
int fd, idx = 0; int fd, idx = 0;
char desc[BUF_SIZE]; char desc[BUF_SIZE];

View File

@ -684,7 +684,8 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t total_size)
return ret; return ret;
} }
static int vpc_create(const char *filename, QEMUOptionParameter *options) static int vpc_create(const char *filename, QEMUOptionParameter *options,
Error **errp)
{ {
uint8_t buf[1024]; uint8_t buf[1024];
struct vhd_footer *footer = (struct vhd_footer *) buf; struct vhd_footer *footer = (struct vhd_footer *) buf;

View File

@ -90,7 +90,8 @@ struct BlockDriver {
const uint8_t *buf, int nb_sectors); const uint8_t *buf, int nb_sectors);
void (*bdrv_close)(BlockDriverState *bs); void (*bdrv_close)(BlockDriverState *bs);
void (*bdrv_rebind)(BlockDriverState *bs); void (*bdrv_rebind)(BlockDriverState *bs);
int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options,
Error **errp);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
int (*bdrv_make_empty)(BlockDriverState *bs); int (*bdrv_make_empty)(BlockDriverState *bs);
/* aio */ /* aio */