From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PULL 17/29] blkdebug: Implement bdrv_refresh_filename()
Date: Fri, 22 Aug 2014 16:51:41 +0200 [thread overview]
Message-ID: <1408719113-5316-18-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1408719113-5316-1-git-send-email-kwolf@redhat.com>
From: Max Reitz <mreitz@redhat.com>
Because blkdebug cannot simply create a configuration file, simply
refuse to reconstruct a plain filename and only generate an options
QDict from the rules instead.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/blkdebug.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 1586ed9..95b7244 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -26,6 +26,10 @@
#include "qemu/config-file.h"
#include "block/block_int.h"
#include "qemu/module.h"
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qstring.h"
typedef struct BDRVBlkdebugState {
int state;
@@ -706,6 +710,98 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
return bdrv_getlength(bs->file);
}
+static void blkdebug_refresh_filename(BlockDriverState *bs)
+{
+ BDRVBlkdebugState *s = bs->opaque;
+ struct BlkdebugRule *rule;
+ QDict *opts;
+ QList *inject_error_list = NULL, *set_state_list = NULL;
+ QList *suspend_list = NULL;
+ int event;
+
+ if (!bs->file->full_open_options) {
+ /* The config file cannot be recreated, so creating a plain filename
+ * is impossible */
+ return;
+ }
+
+ opts = qdict_new();
+ qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
+
+ QINCREF(bs->file->full_open_options);
+ qdict_put_obj(opts, "image", QOBJECT(bs->file->full_open_options));
+
+ for (event = 0; event < BLKDBG_EVENT_MAX; event++) {
+ QLIST_FOREACH(rule, &s->rules[event], next) {
+ if (rule->action == ACTION_INJECT_ERROR) {
+ QDict *inject_error = qdict_new();
+
+ qdict_put_obj(inject_error, "event", QOBJECT(qstring_from_str(
+ BlkdebugEvent_lookup[rule->event])));
+ qdict_put_obj(inject_error, "state",
+ QOBJECT(qint_from_int(rule->state)));
+ qdict_put_obj(inject_error, "errno", QOBJECT(qint_from_int(
+ rule->options.inject.error)));
+ qdict_put_obj(inject_error, "sector", QOBJECT(qint_from_int(
+ rule->options.inject.sector)));
+ qdict_put_obj(inject_error, "once", QOBJECT(qbool_from_int(
+ rule->options.inject.once)));
+ qdict_put_obj(inject_error, "immediately",
+ QOBJECT(qbool_from_int(
+ rule->options.inject.immediately)));
+
+ if (!inject_error_list) {
+ inject_error_list = qlist_new();
+ }
+
+ qlist_append_obj(inject_error_list, QOBJECT(inject_error));
+ } else if (rule->action == ACTION_SET_STATE) {
+ QDict *set_state = qdict_new();
+
+ qdict_put_obj(set_state, "event", QOBJECT(qstring_from_str(
+ BlkdebugEvent_lookup[rule->event])));
+ qdict_put_obj(set_state, "state",
+ QOBJECT(qint_from_int(rule->state)));
+ qdict_put_obj(set_state, "new_state", QOBJECT(qint_from_int(
+ rule->options.set_state.new_state)));
+
+ if (!set_state_list) {
+ set_state_list = qlist_new();
+ }
+
+ qlist_append_obj(set_state_list, QOBJECT(set_state));
+ } else if (rule->action == ACTION_SUSPEND) {
+ QDict *suspend = qdict_new();
+
+ qdict_put_obj(suspend, "event", QOBJECT(qstring_from_str(
+ BlkdebugEvent_lookup[rule->event])));
+ qdict_put_obj(suspend, "state",
+ QOBJECT(qint_from_int(rule->state)));
+ qdict_put_obj(suspend, "tag", QOBJECT(qstring_from_str(
+ rule->options.suspend.tag)));
+
+ if (!suspend_list) {
+ suspend_list = qlist_new();
+ }
+
+ qlist_append_obj(suspend_list, QOBJECT(suspend));
+ }
+ }
+ }
+
+ if (inject_error_list) {
+ qdict_put_obj(opts, "inject-error", QOBJECT(inject_error_list));
+ }
+ if (set_state_list) {
+ qdict_put_obj(opts, "set-state", QOBJECT(set_state_list));
+ }
+ if (suspend_list) {
+ qdict_put_obj(opts, "suspend", QOBJECT(suspend_list));
+ }
+
+ bs->full_open_options = opts;
+}
+
static BlockDriver bdrv_blkdebug = {
.format_name = "blkdebug",
.protocol_name = "blkdebug",
@@ -715,6 +811,7 @@ static BlockDriver bdrv_blkdebug = {
.bdrv_file_open = blkdebug_open,
.bdrv_close = blkdebug_close,
.bdrv_getlength = blkdebug_getlength,
+ .bdrv_refresh_filename = blkdebug_refresh_filename,
.bdrv_aio_readv = blkdebug_aio_readv,
.bdrv_aio_writev = blkdebug_aio_writev,
--
1.8.3.1
next prev parent reply other threads:[~2014-08-22 14:52 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-22 14:51 [Qemu-devel] [PULL 00/29] Block patches Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 01/29] block: Use g_new() & friends where that makes obvious sense Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 02/29] block: Use g_new() & friends to avoid multiplying sizes Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 03/29] qemu-io-cmds: g_renew() can't fail, bury dead error handling Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 04/29] block: Drop some superfluous casts from void * Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 05/29] runner: Add an argument for test duration Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 06/29] runner: Kill a program under test by time-out Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 07/29] qcow2: Constant cache size in bytes Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 08/29] qcow2: Use g_try_new0() for cache array Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 09/29] qcow2: Add runtime options for cache sizes Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 10/29] iotests: Add test for qcow2's cache options Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 11/29] test-coroutine: test cost introduced by coroutine Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 12/29] qemu-iotests: Fix 028 reference output for qed Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 13/29] block: acquire AioContext in qmp_block_resize() Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 14/29] virtio-blk: allow block_resize with dataplane Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 15/29] virtio-blk: fix reference a pointer which might be freed Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 16/29] block: Add bdrv_refresh_filename() Kevin Wolf
2014-08-22 14:51 ` Kevin Wolf [this message]
2014-08-22 14:51 ` [Qemu-devel] [PULL 18/29] blkverify: Implement bdrv_refresh_filename() Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 19/29] nbd: " Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 20/29] quorum: " Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 21/29] iotests: Add test for image filename construction Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 22/29] block/vvfat.c: remove debugging code to reinit stderr if NULL Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 23/29] block/iscsi: fix memory corruption on iscsi resize Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 24/29] raw-posix: fix O_DIRECT short reads Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 25/29] qemu-iotests: add test case 101 for short file I/O Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 26/29] blkdebug: Delete BH in bdrv_aio_cancel Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 27/29] vmdk: Use bdrv_nb_sectors() where sectors, not bytes are wanted Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 28/29] qemu-img: Allow source cache mode specification Kevin Wolf
2014-08-22 14:51 ` [Qemu-devel] [PULL 29/29] qemu-img: Allow cache mode specification for amend Kevin Wolf
2014-08-22 15:09 ` [Qemu-devel] [PULL 00/29] Block patches Daniel H Barboza
2014-08-22 16:23 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408719113-5316-18-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).