aboutsummaryrefslogtreecommitdiff
path: root/block/cow.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2009-05-18 16:42:10 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-05-22 10:50:31 -0500
commit0e7e1989f7fced8e39f140e1958f0557b60d4532 (patch)
tree76bbcc1c26a05f4f6e430f9f844f9b3b350c13ba /block/cow.c
parentd3f243676addaef6c8d818934565292c698f91cc (diff)
Convert all block drivers to new bdrv_create
Now we can make use of the newly introduced option structures. Instead of having bdrv_create carry more and more parameters (which are format specific in most cases), just pass a option structure as defined by the driver itself. bdrv_create2() contains an emulation of the old interface to simplify the transition. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block/cow.c')
-rw-r--r--block/cow.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/block/cow.c b/block/cow.c
index 94b3549389..41d292aac2 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -202,15 +202,23 @@ static void cow_close(BlockDriverState *bs)
close(s->fd);
}
-static int cow_create(const char *filename, int64_t image_sectors,
- const char *image_filename, int flags)
+static int cow_create(const char *filename, QEMUOptionParameter *options)
{
int fd, cow_fd;
struct cow_header_v2 cow_header;
struct stat st;
-
- if (flags)
- return -ENOTSUP;
+ int64_t image_sectors = 0;
+ const char *image_filename = NULL;
+
+ /* Read out options */
+ while (options && options->name) {
+ if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
+ image_sectors = options->value.n / 512;
+ } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
+ image_filename = options->value.s;
+ }
+ options++;
+ }
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -253,6 +261,12 @@ static void cow_flush(BlockDriverState *bs)
fsync(s->fd);
}
+static QEMUOptionParameter cow_create_options[] = {
+ { BLOCK_OPT_SIZE, OPT_SIZE },
+ { BLOCK_OPT_BACKING_FILE, OPT_STRING },
+ { NULL }
+};
+
static BlockDriver bdrv_cow = {
.format_name = "cow",
.instance_size = sizeof(BDRVCowState),
@@ -264,6 +278,8 @@ static BlockDriver bdrv_cow = {
.bdrv_create = cow_create,
.bdrv_flush = cow_flush,
.bdrv_is_allocated = cow_is_allocated,
+
+ .create_options = cow_create_options,
};
static void bdrv_cow_init(void)