From 0e7e1989f7fced8e39f140e1958f0557b60d4532 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Mon, 18 May 2009 16:42:10 +0200 Subject: 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 Signed-off-by: Anthony Liguori --- block/raw-posix.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'block/raw-posix.c') diff --git a/block/raw-posix.c b/block/raw-posix.c index f3a9476..86e3067 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -823,13 +823,18 @@ again: } #endif -static int raw_create(const char *filename, int64_t total_size, - const char *backing_file, int flags) +static int raw_create(const char *filename, QEMUOptionParameter *options) { int fd; + int64_t total_size = 0; - if (flags || backing_file) - return -ENOTSUP; + /* Read out options */ + while (options && options->name) { + if (!strcmp(options->name, BLOCK_OPT_SIZE)) { + total_size = options->value.n / 512; + } + options++; + } fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); @@ -846,6 +851,12 @@ static void raw_flush(BlockDriverState *bs) fsync(s->fd); } + +static QEMUOptionParameter raw_create_options[] = { + { BLOCK_OPT_SIZE, OPT_SIZE }, + { NULL } +}; + static BlockDriver bdrv_raw = { .format_name = "raw", .instance_size = sizeof(BDRVRawState), @@ -866,6 +877,8 @@ static BlockDriver bdrv_raw = { .bdrv_truncate = raw_truncate, .bdrv_getlength = raw_getlength, + + .create_options = raw_create_options, }; /***********************************************/ @@ -1364,15 +1377,20 @@ static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs, #endif /* !linux && !FreeBSD */ #if defined(__linux__) || defined(__FreeBSD__) -static int hdev_create(const char *filename, int64_t total_size, - const char *backing_file, int flags) +static int hdev_create(const char *filename, QEMUOptionParameter *options) { int fd; int ret = 0; struct stat stat_buf; + int64_t total_size = 0; - if (flags || backing_file) - return -ENOTSUP; + /* Read out options */ + while (options && options->name) { + if (!strcmp(options->name, "size")) { + total_size = options->value.n / 512; + } + options++; + } fd = open(filename, O_WRONLY | O_BINARY); if (fd < 0) @@ -1391,8 +1409,7 @@ static int hdev_create(const char *filename, int64_t total_size, #else /* !(linux || freebsd) */ -static int hdev_create(const char *filename, int64_t total_size, - const char *backing_file, int flags) +static int hdev_create(const char *filename, QEMUOptionParameter *options) { return -ENOTSUP; } -- cgit v1.1