diff options
author | Anthony Liguori <aliguori@us.ibm.com> | 2013-04-22 08:08:22 -0500 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-04-22 08:08:22 -0500 |
commit | f1ab7a5acf08dcc11638b22660ed87d5f6d633c2 (patch) | |
tree | 4feebf5c7cb407a13225d4c3cf1870914140a719 /block/blkdebug.c | |
parent | 25690739f1f067b6d8b2e616d87b1d976db0db92 (diff) | |
parent | 7da94ca741e01a80afd65e107cc2cee160d1b2d2 (diff) |
Merge remote-tracking branch 'kwolf/for-anthony' into staging
# By Kevin Wolf (16) and Stefan Hajnoczi (4)
# Via Kevin Wolf
* kwolf/for-anthony:
qemu-iotests: add 053 unaligned compressed image size test
block: Allow overriding backing.file.filename
block: Remove filename parameter from .bdrv_file_open()
vvfat: Use bdrv_open options instead of filename
sheepdog: Use bdrv_open options instead of filename
rbd: Use bdrv_open options instead of filename
iscsi: Use bdrv_open options instead of filename
gluster: Use bdrv_open options instead of filename
curl: Use bdrv_open options instead of filename
blkverify: Use bdrv_open options instead of filename
blkdebug: Use bdrv_open options instead of filename
raw-win32: Use bdrv_open options instead of filename
raw-posix: Use bdrv_open options instead of filename
block: Enable filename option
block: Add driver-specific options for backing files
block: Fail gracefully when using a format driver on protocol level
qemu-iotests: Fix _filter_qemu
qemu-img: do not zero-pad the compressed write buffer
qcow: allow sub-cluster compressed write to last cluster
qcow2: allow sub-cluster compressed write to last cluster
Message-id: 1366630294-18984-1-git-send-email-kwolf@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block/blkdebug.c')
-rw-r--r-- | block/blkdebug.c | 113 |
1 files changed, 81 insertions, 32 deletions
diff --git a/block/blkdebug.c b/block/blkdebug.c index 37cfbc7fc8..71f99e4067 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -273,11 +273,6 @@ static int read_config(BDRVBlkdebugState *s, const char *filename) int ret; struct add_rule_data d; - /* Allow usage without config file */ - if (!*filename) { - return 0; - } - f = fopen(filename, "r"); if (f == NULL) { return -errno; @@ -304,44 +299,98 @@ fail: } /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */ -static int blkdebug_open(BlockDriverState *bs, const char *filename, - QDict *options, int flags) +static void blkdebug_parse_filename(const char *filename, QDict *options, + Error **errp) { - BDRVBlkdebugState *s = bs->opaque; - int ret; - char *config, *c; + const char *c; /* Parse the blkdebug: prefix */ - if (strncmp(filename, "blkdebug:", strlen("blkdebug:"))) { - return -EINVAL; + if (!strstart(filename, "blkdebug:", &filename)) { + error_setg(errp, "File name string must start with 'blkdebug:'"); + return; } - filename += strlen("blkdebug:"); - /* Read rules from config file */ + /* Parse config file path */ c = strchr(filename, ':'); if (c == NULL) { - return -EINVAL; + error_setg(errp, "blkdebug requires both config file and image path"); + return; } - config = g_strdup(filename); - config[c - filename] = '\0'; - ret = read_config(s, config); - g_free(config); - if (ret < 0) { - return ret; + if (c != filename) { + QString *config_path; + config_path = qstring_from_substr(filename, 0, c - filename - 1); + qdict_put(options, "config", config_path); } + + /* TODO Allow multi-level nesting and set file.filename here */ filename = c + 1; + qdict_put(options, "x-image", qstring_from_str(filename)); +} + +static QemuOptsList runtime_opts = { + .name = "blkdebug", + .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), + .desc = { + { + .name = "config", + .type = QEMU_OPT_STRING, + .help = "Path to the configuration file", + }, + { + .name = "x-image", + .type = QEMU_OPT_STRING, + .help = "[internal use only, will be removed]", + }, + { /* end of list */ } + }, +}; + +static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags) +{ + BDRVBlkdebugState *s = bs->opaque; + QemuOpts *opts; + Error *local_err = NULL; + const char *filename, *config; + int ret; + + opts = qemu_opts_create_nofail(&runtime_opts); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + ret = -EINVAL; + goto fail; + } + + /* Read rules from config file */ + config = qemu_opt_get(opts, "config"); + if (config) { + ret = read_config(s, config); + if (ret < 0) { + goto fail; + } + } /* Set initial state */ s->state = 1; /* Open the backing file */ + filename = qemu_opt_get(opts, "x-image"); + if (filename == NULL) { + ret = -EINVAL; + goto fail; + } + ret = bdrv_file_open(&bs->file, filename, NULL, flags); if (ret < 0) { - return ret; + goto fail; } - return 0; + ret = 0; +fail: + qemu_opts_del(opts); + return ret; } static void error_callback_bh(void *opaque) @@ -569,17 +618,17 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) } static BlockDriver bdrv_blkdebug = { - .format_name = "blkdebug", - .protocol_name = "blkdebug", - - .instance_size = sizeof(BDRVBlkdebugState), + .format_name = "blkdebug", + .protocol_name = "blkdebug", + .instance_size = sizeof(BDRVBlkdebugState), - .bdrv_file_open = blkdebug_open, - .bdrv_close = blkdebug_close, - .bdrv_getlength = blkdebug_getlength, + .bdrv_parse_filename = blkdebug_parse_filename, + .bdrv_file_open = blkdebug_open, + .bdrv_close = blkdebug_close, + .bdrv_getlength = blkdebug_getlength, - .bdrv_aio_readv = blkdebug_aio_readv, - .bdrv_aio_writev = blkdebug_aio_writev, + .bdrv_aio_readv = blkdebug_aio_readv, + .bdrv_aio_writev = blkdebug_aio_writev, .bdrv_debug_event = blkdebug_debug_event, .bdrv_debug_breakpoint = blkdebug_debug_breakpoint, |