2010-02-18 17:48:12 +01:00
|
|
|
/*
|
|
|
|
* Block protocol for I/O error injection
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-18 19:01:42 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2016-03-20 18:16:19 +01:00
|
|
|
#include "qemu/cutils.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/config-file.h"
|
2012-12-17 18:19:44 +01:00
|
|
|
#include "block/block_int.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/module.h"
|
2014-07-18 20:24:57 +02:00
|
|
|
#include "qapi/qmp/qbool.h"
|
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qmp/qint.h"
|
|
|
|
#include "qapi/qmp/qstring.h"
|
2015-11-30 12:44:44 +01:00
|
|
|
#include "sysemu/qtest.h"
|
2010-02-18 17:48:12 +01:00
|
|
|
|
|
|
|
typedef struct BDRVBlkdebugState {
|
2012-06-06 08:10:42 +02:00
|
|
|
int state;
|
2012-09-28 17:23:00 +02:00
|
|
|
int new_state;
|
2016-06-24 00:37:13 +02:00
|
|
|
int align;
|
2012-12-06 14:32:57 +01:00
|
|
|
|
2016-08-15 15:29:25 +02:00
|
|
|
/* For blkdebug_refresh_filename() */
|
|
|
|
char *config_file;
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG__MAX];
|
2012-06-06 08:10:42 +02:00
|
|
|
QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
|
2012-12-06 14:32:57 +01:00
|
|
|
QLIST_HEAD(, BlkdebugSuspendedReq) suspended_reqs;
|
2010-02-18 17:48:12 +01:00
|
|
|
} BDRVBlkdebugState;
|
|
|
|
|
2010-02-19 16:24:35 +01:00
|
|
|
typedef struct BlkdebugAIOCB {
|
2014-10-07 13:59:14 +02:00
|
|
|
BlockAIOCB common;
|
2010-02-19 16:24:35 +01:00
|
|
|
int ret;
|
|
|
|
} BlkdebugAIOCB;
|
|
|
|
|
2012-12-06 14:32:57 +01:00
|
|
|
typedef struct BlkdebugSuspendedReq {
|
|
|
|
Coroutine *co;
|
|
|
|
char *tag;
|
|
|
|
QLIST_ENTRY(BlkdebugSuspendedReq) next;
|
|
|
|
} BlkdebugSuspendedReq;
|
|
|
|
|
2010-03-15 17:27:00 +01:00
|
|
|
enum {
|
|
|
|
ACTION_INJECT_ERROR,
|
|
|
|
ACTION_SET_STATE,
|
2012-12-06 14:32:57 +01:00
|
|
|
ACTION_SUSPEND,
|
2010-03-15 17:27:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct BlkdebugRule {
|
2015-11-18 09:52:54 +01:00
|
|
|
BlkdebugEvent event;
|
2010-03-15 17:27:00 +01:00
|
|
|
int action;
|
|
|
|
int state;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int error;
|
|
|
|
int immediately;
|
|
|
|
int once;
|
2016-11-04 21:13:45 +01:00
|
|
|
int64_t offset;
|
2010-03-15 17:27:00 +01:00
|
|
|
} inject;
|
|
|
|
struct {
|
|
|
|
int new_state;
|
|
|
|
} set_state;
|
2012-12-06 14:32:57 +01:00
|
|
|
struct {
|
|
|
|
char *tag;
|
|
|
|
} suspend;
|
2010-03-15 17:27:00 +01:00
|
|
|
} options;
|
|
|
|
QLIST_ENTRY(BlkdebugRule) next;
|
2012-06-06 08:10:42 +02:00
|
|
|
QSIMPLEQ_ENTRY(BlkdebugRule) active_next;
|
2010-03-15 17:27:00 +01:00
|
|
|
} BlkdebugRule;
|
|
|
|
|
|
|
|
static QemuOptsList inject_error_opts = {
|
|
|
|
.name = "inject-error",
|
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(inject_error_opts.head),
|
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "event",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "errno",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
2012-06-06 08:10:43 +02:00
|
|
|
{
|
|
|
|
.name = "sector",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
|
|
|
.name = "once",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "immediately",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static QemuOptsList set_state_opts = {
|
|
|
|
.name = "set-state",
|
2010-06-30 17:40:42 +02:00
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head),
|
2010-03-15 17:27:00 +01:00
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "event",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "new_state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static QemuOptsList *config_groups[] = {
|
|
|
|
&inject_error_opts,
|
|
|
|
&set_state_opts,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2015-11-18 09:52:54 +01:00
|
|
|
static int get_event_by_name(const char *name, BlkdebugEvent *event)
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
for (i = 0; i < BLKDBG__MAX; i++) {
|
2015-11-18 09:52:54 +01:00
|
|
|
if (!strcmp(BlkdebugEvent_lookup[i], name)) {
|
2010-03-15 17:27:00 +01:00
|
|
|
*event = i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct add_rule_data {
|
|
|
|
BDRVBlkdebugState *s;
|
|
|
|
int action;
|
|
|
|
};
|
|
|
|
|
2015-03-13 13:35:14 +01:00
|
|
|
static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
|
|
|
struct add_rule_data *d = opaque;
|
|
|
|
BDRVBlkdebugState *s = d->s;
|
|
|
|
const char* event_name;
|
2015-11-18 09:52:54 +01:00
|
|
|
BlkdebugEvent event;
|
2010-03-15 17:27:00 +01:00
|
|
|
struct BlkdebugRule *rule;
|
2016-11-04 21:13:45 +01:00
|
|
|
int64_t sector;
|
2010-03-15 17:27:00 +01:00
|
|
|
|
|
|
|
/* Find the right event for the rule */
|
|
|
|
event_name = qemu_opt_get(opts, "event");
|
2014-09-20 10:55:52 +02:00
|
|
|
if (!event_name) {
|
2015-03-13 13:38:42 +01:00
|
|
|
error_setg(errp, "Missing event name for rule");
|
2014-09-20 10:55:52 +02:00
|
|
|
return -1;
|
|
|
|
} else if (get_event_by_name(event_name, &event) < 0) {
|
2015-03-13 13:38:42 +01:00
|
|
|
error_setg(errp, "Invalid event name \"%s\"", event_name);
|
2010-03-15 17:27:00 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set attributes common for all actions */
|
2011-08-21 05:09:37 +02:00
|
|
|
rule = g_malloc0(sizeof(*rule));
|
2010-03-15 17:27:00 +01:00
|
|
|
*rule = (struct BlkdebugRule) {
|
|
|
|
.event = event,
|
|
|
|
.action = d->action,
|
|
|
|
.state = qemu_opt_get_number(opts, "state", 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse action-specific options */
|
|
|
|
switch (d->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
|
|
|
rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);
|
|
|
|
rule->options.inject.once = qemu_opt_get_bool(opts, "once", 0);
|
|
|
|
rule->options.inject.immediately =
|
|
|
|
qemu_opt_get_bool(opts, "immediately", 0);
|
2016-11-04 21:13:45 +01:00
|
|
|
sector = qemu_opt_get_number(opts, "sector", -1);
|
|
|
|
rule->options.inject.offset =
|
|
|
|
sector == -1 ? -1 : sector * BDRV_SECTOR_SIZE;
|
2010-03-15 17:27:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SET_STATE:
|
|
|
|
rule->options.set_state.new_state =
|
|
|
|
qemu_opt_get_number(opts, "new_state", 0);
|
|
|
|
break;
|
2012-12-06 14:32:57 +01:00
|
|
|
|
|
|
|
case ACTION_SUSPEND:
|
|
|
|
rule->options.suspend.tag =
|
|
|
|
g_strdup(qemu_opt_get(opts, "tag"));
|
|
|
|
break;
|
2010-03-15 17:27:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Add the rule */
|
|
|
|
QLIST_INSERT_HEAD(&s->rules[event], rule, next);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 14:32:56 +01:00
|
|
|
static void remove_rule(BlkdebugRule *rule)
|
|
|
|
{
|
|
|
|
switch (rule->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
|
|
|
case ACTION_SET_STATE:
|
|
|
|
break;
|
2012-12-06 14:32:57 +01:00
|
|
|
case ACTION_SUSPEND:
|
|
|
|
g_free(rule->options.suspend.tag);
|
|
|
|
break;
|
2012-12-06 14:32:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QLIST_REMOVE(rule, next);
|
|
|
|
g_free(rule);
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:28:07 +01:00
|
|
|
static int read_config(BDRVBlkdebugState *s, const char *filename,
|
|
|
|
QDict *options, Error **errp)
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
2013-12-20 19:28:06 +01:00
|
|
|
FILE *f = NULL;
|
2010-03-15 17:27:00 +01:00
|
|
|
int ret;
|
|
|
|
struct add_rule_data d;
|
2013-12-20 19:28:07 +01:00
|
|
|
Error *local_err = NULL;
|
2010-03-15 17:27:00 +01:00
|
|
|
|
2013-12-20 19:28:06 +01:00
|
|
|
if (filename) {
|
|
|
|
f = fopen(filename, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
error_setg_errno(errp, errno, "Could not read blkdebug config file");
|
|
|
|
return -errno;
|
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
|
2013-12-20 19:28:06 +01:00
|
|
|
ret = qemu_config_parse(f, config_groups, filename);
|
|
|
|
if (ret < 0) {
|
|
|
|
error_setg(errp, "Could not parse blkdebug config file");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:28:07 +01:00
|
|
|
qemu_config_parse_qdict(options, config_groups, &local_err);
|
2014-01-30 15:07:28 +01:00
|
|
|
if (local_err) {
|
2013-12-20 19:28:07 +01:00
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-03-15 17:27:00 +01:00
|
|
|
d.s = s;
|
|
|
|
d.action = ACTION_INJECT_ERROR;
|
2015-03-13 13:38:42 +01:00
|
|
|
qemu_opts_foreach(&inject_error_opts, add_rule, &d, &local_err);
|
2014-09-20 10:55:52 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
|
|
|
|
d.action = ACTION_SET_STATE;
|
2015-03-13 13:38:42 +01:00
|
|
|
qemu_opts_foreach(&set_state_opts, add_rule, &d, &local_err);
|
2014-09-20 10:55:52 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
fail:
|
2010-06-30 17:42:23 +02:00
|
|
|
qemu_opts_reset(&inject_error_opts);
|
|
|
|
qemu_opts_reset(&set_state_opts);
|
2013-12-20 19:28:06 +01:00
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
|
2013-04-10 13:37:33 +02:00
|
|
|
static void blkdebug_parse_filename(const char *filename, QDict *options,
|
|
|
|
Error **errp)
|
2010-02-18 17:48:12 +01:00
|
|
|
{
|
2013-04-10 13:37:33 +02:00
|
|
|
const char *c;
|
2010-02-18 17:48:12 +01:00
|
|
|
|
2010-03-15 17:27:00 +01:00
|
|
|
/* Parse the blkdebug: prefix */
|
2013-04-10 13:37:33 +02:00
|
|
|
if (!strstart(filename, "blkdebug:", &filename)) {
|
2013-12-20 19:28:02 +01:00
|
|
|
/* There was no prefix; therefore, all options have to be already
|
|
|
|
present in the QDict (except for the filename) */
|
|
|
|
qdict_put(options, "x-image", qstring_from_str(filename));
|
2013-04-10 13:37:33 +02:00
|
|
|
return;
|
2010-02-18 17:48:12 +01:00
|
|
|
}
|
|
|
|
|
2013-04-10 13:37:33 +02:00
|
|
|
/* Parse config file path */
|
2010-03-15 17:27:00 +01:00
|
|
|
c = strchr(filename, ':');
|
|
|
|
if (c == NULL) {
|
2013-04-10 13:37:33 +02:00
|
|
|
error_setg(errp, "blkdebug requires both config file and image path");
|
|
|
|
return;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
2013-04-10 13:37:33 +02:00
|
|
|
if (c != filename) {
|
|
|
|
QString *config_path;
|
|
|
|
config_path = qstring_from_substr(filename, 0, c - filename - 1);
|
|
|
|
qdict_put(options, "config", config_path);
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
2013-04-10 13:37:33 +02:00
|
|
|
|
|
|
|
/* TODO Allow multi-level nesting and set file.filename here */
|
2010-03-15 17:27:00 +01:00
|
|
|
filename = c + 1;
|
2013-04-10 13:37:33 +02:00
|
|
|
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]",
|
|
|
|
},
|
2014-01-14 13:44:35 +01:00
|
|
|
{
|
|
|
|
.name = "align",
|
|
|
|
.type = QEMU_OPT_SIZE,
|
|
|
|
.help = "Required alignment in bytes",
|
|
|
|
},
|
2013-04-10 13:37:33 +02:00
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-09-05 14:22:29 +02:00
|
|
|
static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
|
Error **errp)
|
2013-04-10 13:37:33 +02:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
QemuOpts *opts;
|
|
|
|
Error *local_err = NULL;
|
2014-01-14 13:44:35 +01:00
|
|
|
uint64_t align;
|
2013-04-10 13:37:33 +02:00
|
|
|
int ret;
|
|
|
|
|
2014-01-02 03:49:17 +01:00
|
|
|
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
2013-04-10 13:37:33 +02:00
|
|
|
qemu_opts_absorb_qdict(opts, options, &local_err);
|
2014-01-30 15:07:28 +01:00
|
|
|
if (local_err) {
|
2013-10-10 15:44:03 +02:00
|
|
|
error_propagate(errp, local_err);
|
2013-04-10 13:37:33 +02:00
|
|
|
ret = -EINVAL;
|
2014-02-08 09:53:22 +01:00
|
|
|
goto out;
|
2013-04-10 13:37:33 +02:00
|
|
|
}
|
|
|
|
|
2013-12-20 19:28:07 +01:00
|
|
|
/* Read rules from config file or command line options */
|
2016-08-15 15:29:25 +02:00
|
|
|
s->config_file = g_strdup(qemu_opt_get(opts, "config"));
|
|
|
|
ret = read_config(s, s->config_file, options, errp);
|
2013-12-20 19:28:06 +01:00
|
|
|
if (ret) {
|
2014-02-08 09:53:22 +01:00
|
|
|
goto out;
|
2013-04-10 13:37:33 +02:00
|
|
|
}
|
2010-03-15 17:27:00 +01:00
|
|
|
|
2010-06-30 17:43:40 +02:00
|
|
|
/* Set initial state */
|
2012-06-06 08:10:42 +02:00
|
|
|
s->state = 1;
|
2010-06-30 17:43:40 +02:00
|
|
|
|
2015-10-16 12:46:04 +02:00
|
|
|
/* Open the image file */
|
2015-06-16 14:19:22 +02:00
|
|
|
bs->file = bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "image",
|
|
|
|
bs, &child_file, false, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
ret = -EINVAL;
|
2013-10-10 15:44:03 +02:00
|
|
|
error_propagate(errp, local_err);
|
2014-02-08 09:53:22 +01:00
|
|
|
goto out;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
2014-01-14 13:44:35 +01:00
|
|
|
/* Set request alignment */
|
2016-06-24 00:37:13 +02:00
|
|
|
align = qemu_opt_get_size(opts, "align", 0);
|
|
|
|
if (align < INT_MAX && is_power_of_2(align)) {
|
|
|
|
s->align = align;
|
|
|
|
} else if (align) {
|
2014-01-14 13:44:35 +01:00
|
|
|
error_setg(errp, "Invalid alignment");
|
|
|
|
ret = -EINVAL;
|
2014-02-08 09:53:22 +01:00
|
|
|
goto fail_unref;
|
2014-01-14 13:44:35 +01:00
|
|
|
}
|
|
|
|
|
2013-04-10 13:37:33 +02:00
|
|
|
ret = 0;
|
2014-02-08 09:53:22 +01:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
fail_unref:
|
2015-06-16 14:19:22 +02:00
|
|
|
bdrv_unref_child(bs, bs->file);
|
2014-02-08 09:53:22 +01:00
|
|
|
out:
|
2016-08-15 15:29:25 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
g_free(s->config_file);
|
|
|
|
}
|
2013-04-10 13:37:33 +02:00
|
|
|
qemu_opts_del(opts);
|
|
|
|
return ret;
|
2010-02-18 17:48:12 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
static int inject_error(BlockDriverState *bs, BlkdebugRule *rule)
|
2010-02-19 16:24:35 +01:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 08:10:42 +02:00
|
|
|
int error = rule->options.inject.error;
|
blkdebug: fix "once" rule
Background:
The blkdebug scripts are currently engineered so that when a debug
event occurs, a prefilter browses a master list of parsed rules for a
certain event and adds them to an "active list" of rules to be used for
the forthcoming action, provided the events and state numbers match.
Then, once the request is received, the last active rule is used to
inject an error if certain parameters match.
This active list is cleared every time the prefilter injects a new
rule for the first time during a debug event.
The "once" rule currently causes the error injection, if it is
triggered, to only clear the active list. This is insufficient for
preventing future injections of the same rule.
Remedy:
This patch /deletes/ the rule from the list that the prefilter
browses, so it is gone for good. In V2, we remove only the rule of
interest from the active list instead of allowing the "once" rule to
clear the entire list of active rules.
Impact:
This affects iotests 026. Several ENOSPC tests that used "once" can
be seen to have output that shows multiple failure messages. After
this patch, the error messages tend to be smaller and less severe, but
the injection can still be seen to be working. I have patched the
expected output to expect the smaller error messages.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423257977-25630-1-git-send-email-jsnow@redhat.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2015-02-06 22:26:17 +01:00
|
|
|
bool immediately = rule->options.inject.immediately;
|
2010-02-19 16:24:35 +01:00
|
|
|
|
2012-06-06 08:10:42 +02:00
|
|
|
if (rule->options.inject.once) {
|
blkdebug: fix "once" rule
Background:
The blkdebug scripts are currently engineered so that when a debug
event occurs, a prefilter browses a master list of parsed rules for a
certain event and adds them to an "active list" of rules to be used for
the forthcoming action, provided the events and state numbers match.
Then, once the request is received, the last active rule is used to
inject an error if certain parameters match.
This active list is cleared every time the prefilter injects a new
rule for the first time during a debug event.
The "once" rule currently causes the error injection, if it is
triggered, to only clear the active list. This is insufficient for
preventing future injections of the same rule.
Remedy:
This patch /deletes/ the rule from the list that the prefilter
browses, so it is gone for good. In V2, we remove only the rule of
interest from the active list instead of allowing the "once" rule to
clear the entire list of active rules.
Impact:
This affects iotests 026. Several ENOSPC tests that used "once" can
be seen to have output that shows multiple failure messages. After
this patch, the error messages tend to be smaller and less severe, but
the injection can still be seen to be working. I have patched the
expected output to expect the smaller error messages.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1423257977-25630-1-git-send-email-jsnow@redhat.com
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2015-02-06 22:26:17 +01:00
|
|
|
QSIMPLEQ_REMOVE(&s->active_rules, rule, BlkdebugRule, active_next);
|
|
|
|
remove_rule(rule);
|
2010-02-19 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
if (!immediately) {
|
2017-02-13 14:52:26 +01:00
|
|
|
aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
|
2016-11-04 21:13:45 +01:00
|
|
|
qemu_coroutine_yield();
|
2010-02-19 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
return -error;
|
2010-02-19 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
static int coroutine_fn
|
|
|
|
blkdebug_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
|
|
|
QEMUIOVector *qiov, int flags)
|
2010-02-18 17:48:12 +01:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 08:10:43 +02:00
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
2016-11-04 21:13:45 +01:00
|
|
|
uint64_t inject_offset = rule->options.inject.offset;
|
|
|
|
|
|
|
|
if (inject_offset == -1 ||
|
|
|
|
(inject_offset >= offset && inject_offset < offset + bytes))
|
|
|
|
{
|
2012-06-06 08:10:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 16:24:35 +01:00
|
|
|
|
2012-06-06 08:10:42 +02:00
|
|
|
if (rule && rule->options.inject.error) {
|
2016-11-04 21:13:45 +01:00
|
|
|
return inject_error(bs, rule);
|
2010-02-19 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
|
2010-02-18 17:48:12 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
static int coroutine_fn
|
|
|
|
blkdebug_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
|
|
|
|
QEMUIOVector *qiov, int flags)
|
2010-02-18 17:48:12 +01:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 08:10:43 +02:00
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
2016-11-04 21:13:45 +01:00
|
|
|
uint64_t inject_offset = rule->options.inject.offset;
|
|
|
|
|
|
|
|
if (inject_offset == -1 ||
|
|
|
|
(inject_offset >= offset && inject_offset < offset + bytes))
|
|
|
|
{
|
2012-06-06 08:10:43 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 16:24:35 +01:00
|
|
|
|
2012-06-06 08:10:42 +02:00
|
|
|
if (rule && rule->options.inject.error) {
|
2016-11-04 21:13:45 +01:00
|
|
|
return inject_error(bs, rule);
|
2010-02-19 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
|
2010-02-18 17:48:12 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
static int blkdebug_co_flush(BlockDriverState *bs)
|
2014-08-04 23:11:02 +02:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
2016-11-04 21:13:45 +01:00
|
|
|
if (rule->options.inject.offset == -1) {
|
2014-08-04 23:11:02 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rule && rule->options.inject.error) {
|
2016-11-04 21:13:45 +01:00
|
|
|
return inject_error(bs, rule);
|
2014-08-04 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
return bdrv_co_flush(bs->file->bs);
|
2014-08-04 23:11:02 +02:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:32:57 +01:00
|
|
|
|
2010-02-18 17:48:12 +01:00
|
|
|
static void blkdebug_close(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2010-03-15 17:27:00 +01:00
|
|
|
BlkdebugRule *rule, *next;
|
|
|
|
int i;
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
for (i = 0; i < BLKDBG__MAX; i++) {
|
2010-03-15 17:27:00 +01:00
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
2012-12-06 14:32:56 +01:00
|
|
|
remove_rule(rule);
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
}
|
2016-08-15 15:29:25 +02:00
|
|
|
|
|
|
|
g_free(s->config_file);
|
2010-02-18 17:48:12 +01:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:32:57 +01:00
|
|
|
static void suspend_request(BlockDriverState *bs, BlkdebugRule *rule)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugSuspendedReq r;
|
|
|
|
|
|
|
|
r = (BlkdebugSuspendedReq) {
|
|
|
|
.co = qemu_coroutine_self(),
|
|
|
|
.tag = g_strdup(rule->options.suspend.tag),
|
|
|
|
};
|
|
|
|
|
|
|
|
remove_rule(rule);
|
|
|
|
QLIST_INSERT_HEAD(&s->suspended_reqs, &r, next);
|
|
|
|
|
2015-11-30 12:44:44 +01:00
|
|
|
if (!qtest_enabled()) {
|
|
|
|
printf("blkdebug: Suspended request '%s'\n", r.tag);
|
|
|
|
}
|
2012-12-06 14:32:57 +01:00
|
|
|
qemu_coroutine_yield();
|
2015-11-30 12:44:44 +01:00
|
|
|
if (!qtest_enabled()) {
|
|
|
|
printf("blkdebug: Resuming request '%s'\n", r.tag);
|
|
|
|
}
|
2012-12-06 14:32:57 +01:00
|
|
|
|
|
|
|
QLIST_REMOVE(&r, next);
|
|
|
|
g_free(r.tag);
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:10:42 +02:00
|
|
|
static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
|
2012-09-28 17:23:00 +02:00
|
|
|
bool injected)
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
|
|
|
|
/* Only process rules for the current state */
|
2012-09-28 17:23:00 +02:00
|
|
|
if (rule->state && rule->state != s->state) {
|
2012-06-06 08:10:42 +02:00
|
|
|
return injected;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Take the action */
|
|
|
|
switch (rule->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
2012-06-06 08:10:42 +02:00
|
|
|
if (!injected) {
|
|
|
|
QSIMPLEQ_INIT(&s->active_rules);
|
|
|
|
injected = true;
|
|
|
|
}
|
|
|
|
QSIMPLEQ_INSERT_HEAD(&s->active_rules, rule, active_next);
|
2010-03-15 17:27:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SET_STATE:
|
2012-09-28 17:23:00 +02:00
|
|
|
s->new_state = rule->options.set_state.new_state;
|
2010-03-15 17:27:00 +01:00
|
|
|
break;
|
2012-12-06 14:32:57 +01:00
|
|
|
|
|
|
|
case ACTION_SUSPEND:
|
|
|
|
suspend_request(bs, rule);
|
|
|
|
break;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
2012-06-06 08:10:42 +02:00
|
|
|
return injected;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
2015-11-18 09:52:54 +01:00
|
|
|
static void blkdebug_debug_event(BlockDriverState *bs, BlkdebugEvent event)
|
2010-03-15 17:27:00 +01:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-12-06 14:32:57 +01:00
|
|
|
struct BlkdebugRule *rule, *next;
|
2012-06-06 08:10:42 +02:00
|
|
|
bool injected;
|
2010-03-15 17:27:00 +01:00
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
assert((int)event >= 0 && event < BLKDBG__MAX);
|
2010-03-15 17:27:00 +01:00
|
|
|
|
2012-06-06 08:10:42 +02:00
|
|
|
injected = false;
|
2012-09-28 17:23:00 +02:00
|
|
|
s->new_state = s->state;
|
2012-12-06 14:32:57 +01:00
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[event], next, next) {
|
2012-09-28 17:23:00 +02:00
|
|
|
injected = process_rule(bs, rule, injected);
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
2012-09-28 17:23:00 +02:00
|
|
|
s->state = s->new_state;
|
2010-03-15 17:27:00 +01:00
|
|
|
}
|
|
|
|
|
2012-12-06 14:32:57 +01:00
|
|
|
static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
|
|
|
|
const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
struct BlkdebugRule *rule;
|
2015-11-18 09:52:54 +01:00
|
|
|
BlkdebugEvent blkdebug_event;
|
2012-12-06 14:32:57 +01:00
|
|
|
|
|
|
|
if (get_event_by_name(event, &blkdebug_event) < 0) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rule = g_malloc(sizeof(*rule));
|
|
|
|
*rule = (struct BlkdebugRule) {
|
|
|
|
.event = blkdebug_event,
|
|
|
|
.action = ACTION_SUSPEND,
|
|
|
|
.state = 0,
|
|
|
|
.options.suspend.tag = g_strdup(tag),
|
|
|
|
};
|
|
|
|
|
|
|
|
QLIST_INSERT_HEAD(&s->rules[blkdebug_event], rule, next);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2013-12-13 08:25:12 +01:00
|
|
|
BlkdebugSuspendedReq *r, *next;
|
2012-12-06 14:32:57 +01:00
|
|
|
|
2013-12-13 08:25:12 +01:00
|
|
|
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) {
|
2012-12-06 14:32:57 +01:00
|
|
|
if (!strcmp(r->tag, tag)) {
|
coroutine: move entry argument to qemu_coroutine_create
In practice the entry argument is always known at creation time, and
it is confusing that sometimes qemu_coroutine_enter is used with a
non-NULL argument to re-enter a coroutine (this happens in
block/sheepdog.c and tests/test-coroutine.c). So pass the opaque value
at creation time, for consistency with e.g. aio_bh_new.
Mostly done with the following semantic patch:
@ entry1 @
expression entry, arg, co;
@@
- co = qemu_coroutine_create(entry);
+ co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry2 @
expression entry, arg;
identifier co;
@@
- Coroutine *co = qemu_coroutine_create(entry);
+ Coroutine *co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry3 @
expression entry, arg;
@@
- qemu_coroutine_enter(qemu_coroutine_create(entry), arg);
+ qemu_coroutine_enter(qemu_coroutine_create(entry, arg));
@ reentry @
expression co;
@@
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
except for the aforementioned few places where the semantic patch
stumbled (as expected) and for test_co_queue, which would otherwise
produce an uninitialized variable warning.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2016-07-04 19:10:01 +02:00
|
|
|
qemu_coroutine_enter(r->co);
|
2012-12-06 14:32:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-11-20 03:01:54 +01:00
|
|
|
static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
|
|
|
|
const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2013-12-13 08:25:12 +01:00
|
|
|
BlkdebugSuspendedReq *r, *r_next;
|
2013-11-20 03:01:54 +01:00
|
|
|
BlkdebugRule *rule, *next;
|
|
|
|
int i, ret = -ENOENT;
|
|
|
|
|
qapi: Don't let implicit enum MAX member collide
Now that we guarantee the user doesn't have any enum values
beginning with a single underscore, we can use that for our
own purposes. Renaming ENUM_MAX to ENUM__MAX makes it obvious
that the sentinel is generated.
This patch was mostly generated by applying a temporary patch:
|diff --git a/scripts/qapi.py b/scripts/qapi.py
|index e6d014b..b862ec9 100644
|--- a/scripts/qapi.py
|+++ b/scripts/qapi.py
|@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
| max_index = c_enum_const(name, 'MAX', prefix)
| ret += mcgen('''
| [%(max_index)s] = NULL,
|+// %(max_index)s
| };
| ''',
| max_index=max_index)
then running:
$ cat qapi-{types,event}.c tests/test-qapi-types.c |
sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
$ git grep -l _MAX | xargs sed -i -f list
The only things not generated are the changes in scripts/qapi.py.
Rejecting enum members named 'MAX' is now useless, and will be dropped
in the next patch.
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
[Rebased to current master, commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-11-18 09:52:57 +01:00
|
|
|
for (i = 0; i < BLKDBG__MAX; i++) {
|
2013-11-20 03:01:54 +01:00
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
|
|
|
if (rule->action == ACTION_SUSPEND &&
|
|
|
|
!strcmp(rule->options.suspend.tag, tag)) {
|
|
|
|
remove_rule(rule);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 08:25:12 +01:00
|
|
|
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) {
|
2013-11-20 03:01:54 +01:00
|
|
|
if (!strcmp(r->tag, tag)) {
|
coroutine: move entry argument to qemu_coroutine_create
In practice the entry argument is always known at creation time, and
it is confusing that sometimes qemu_coroutine_enter is used with a
non-NULL argument to re-enter a coroutine (this happens in
block/sheepdog.c and tests/test-coroutine.c). So pass the opaque value
at creation time, for consistency with e.g. aio_bh_new.
Mostly done with the following semantic patch:
@ entry1 @
expression entry, arg, co;
@@
- co = qemu_coroutine_create(entry);
+ co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry2 @
expression entry, arg;
identifier co;
@@
- Coroutine *co = qemu_coroutine_create(entry);
+ Coroutine *co = qemu_coroutine_create(entry, arg);
...
- qemu_coroutine_enter(co, arg);
+ qemu_coroutine_enter(co);
@ entry3 @
expression entry, arg;
@@
- qemu_coroutine_enter(qemu_coroutine_create(entry), arg);
+ qemu_coroutine_enter(qemu_coroutine_create(entry, arg));
@ reentry @
expression co;
@@
- qemu_coroutine_enter(co, NULL);
+ qemu_coroutine_enter(co);
except for the aforementioned few places where the semantic patch
stumbled (as expected) and for test_co_queue, which would otherwise
produce an uninitialized variable warning.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2016-07-04 19:10:01 +02:00
|
|
|
qemu_coroutine_enter(r->co);
|
2013-11-20 03:01:54 +01:00
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-06 14:32:57 +01:00
|
|
|
|
|
|
|
static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugSuspendedReq *r;
|
|
|
|
|
|
|
|
QLIST_FOREACH(r, &s->suspended_reqs, next) {
|
|
|
|
if (!strcmp(r->tag, tag)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:10:41 +02:00
|
|
|
static int64_t blkdebug_getlength(BlockDriverState *bs)
|
|
|
|
{
|
2015-06-16 14:19:22 +02:00
|
|
|
return bdrv_getlength(bs->file->bs);
|
2012-06-06 08:10:41 +02:00
|
|
|
}
|
|
|
|
|
2015-04-14 16:32:45 +02:00
|
|
|
static int blkdebug_truncate(BlockDriverState *bs, int64_t offset)
|
|
|
|
{
|
2017-02-16 18:39:03 +01:00
|
|
|
return bdrv_truncate(bs->file, offset);
|
2015-04-14 16:32:45 +02:00
|
|
|
}
|
|
|
|
|
2015-04-27 13:50:54 +02:00
|
|
|
static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
|
2014-07-18 20:24:57 +02:00
|
|
|
{
|
2016-08-15 15:29:25 +02:00
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2014-07-18 20:24:57 +02:00
|
|
|
QDict *opts;
|
2014-11-11 10:23:44 +01:00
|
|
|
const QDictEntry *e;
|
|
|
|
bool force_json = false;
|
|
|
|
|
2015-04-27 13:50:54 +02:00
|
|
|
for (e = qdict_first(options); e; e = qdict_next(options, e)) {
|
2014-11-11 10:23:44 +01:00
|
|
|
if (strcmp(qdict_entry_key(e), "config") &&
|
2015-04-27 13:50:54 +02:00
|
|
|
strcmp(qdict_entry_key(e), "x-image"))
|
2014-11-11 10:23:44 +01:00
|
|
|
{
|
|
|
|
force_json = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-07-18 20:24:57 +02:00
|
|
|
|
2015-06-16 14:19:22 +02:00
|
|
|
if (force_json && !bs->file->bs->full_open_options) {
|
2014-07-18 20:24:57 +02:00
|
|
|
/* The config file cannot be recreated, so creating a plain filename
|
|
|
|
* is impossible */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-16 14:19:22 +02:00
|
|
|
if (!force_json && bs->file->bs->exact_filename[0]) {
|
2014-11-11 10:23:44 +01:00
|
|
|
snprintf(bs->exact_filename, sizeof(bs->exact_filename),
|
2016-08-15 15:29:25 +02:00
|
|
|
"blkdebug:%s:%s", s->config_file ?: "",
|
2015-06-16 14:19:22 +02:00
|
|
|
bs->file->bs->exact_filename);
|
2014-11-11 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
2014-07-18 20:24:57 +02:00
|
|
|
opts = qdict_new();
|
|
|
|
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
|
|
|
|
|
2015-06-16 14:19:22 +02:00
|
|
|
QINCREF(bs->file->bs->full_open_options);
|
|
|
|
qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options));
|
2014-07-18 20:24:57 +02:00
|
|
|
|
2015-04-27 13:50:54 +02:00
|
|
|
for (e = qdict_first(options); e; e = qdict_next(options, e)) {
|
|
|
|
if (strcmp(qdict_entry_key(e), "x-image")) {
|
2014-11-11 10:23:44 +01:00
|
|
|
qobject_incref(qdict_entry_value(e));
|
|
|
|
qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e));
|
2014-07-18 20:24:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bs->full_open_options = opts;
|
|
|
|
}
|
|
|
|
|
2016-06-24 00:37:13 +02:00
|
|
|
static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
|
|
|
|
if (s->align) {
|
2016-06-24 00:37:24 +02:00
|
|
|
bs->bl.request_alignment = s->align;
|
2016-06-24 00:37:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:22:27 +01:00
|
|
|
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
|
|
|
|
BlockReopenQueue *queue, Error **errp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-18 17:48:12 +01:00
|
|
|
static BlockDriver bdrv_blkdebug = {
|
2013-04-10 13:37:33 +02:00
|
|
|
.format_name = "blkdebug",
|
|
|
|
.protocol_name = "blkdebug",
|
|
|
|
.instance_size = sizeof(BDRVBlkdebugState),
|
2010-02-18 17:48:12 +01:00
|
|
|
|
2013-04-10 13:37:33 +02:00
|
|
|
.bdrv_parse_filename = blkdebug_parse_filename,
|
|
|
|
.bdrv_file_open = blkdebug_open,
|
|
|
|
.bdrv_close = blkdebug_close,
|
2015-10-29 15:22:27 +01:00
|
|
|
.bdrv_reopen_prepare = blkdebug_reopen_prepare,
|
2016-12-15 12:28:58 +01:00
|
|
|
.bdrv_child_perm = bdrv_filter_default_perms,
|
|
|
|
|
2013-04-10 13:37:33 +02:00
|
|
|
.bdrv_getlength = blkdebug_getlength,
|
2015-04-14 16:32:45 +02:00
|
|
|
.bdrv_truncate = blkdebug_truncate,
|
2014-07-18 20:24:57 +02:00
|
|
|
.bdrv_refresh_filename = blkdebug_refresh_filename,
|
2016-06-24 00:37:13 +02:00
|
|
|
.bdrv_refresh_limits = blkdebug_refresh_limits,
|
2010-02-18 17:48:12 +01:00
|
|
|
|
2016-11-04 21:13:45 +01:00
|
|
|
.bdrv_co_preadv = blkdebug_co_preadv,
|
|
|
|
.bdrv_co_pwritev = blkdebug_co_pwritev,
|
|
|
|
.bdrv_co_flush_to_disk = blkdebug_co_flush,
|
2010-03-15 17:27:00 +01:00
|
|
|
|
2012-12-06 14:32:57 +01:00
|
|
|
.bdrv_debug_event = blkdebug_debug_event,
|
|
|
|
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
|
2013-11-20 03:01:54 +01:00
|
|
|
.bdrv_debug_remove_breakpoint
|
|
|
|
= blkdebug_debug_remove_breakpoint,
|
2012-12-06 14:32:57 +01:00
|
|
|
.bdrv_debug_resume = blkdebug_debug_resume,
|
|
|
|
.bdrv_debug_is_suspended = blkdebug_debug_is_suspended,
|
2010-02-18 17:48:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bdrv_blkdebug_init(void)
|
|
|
|
{
|
|
|
|
bdrv_register(&bdrv_blkdebug);
|
|
|
|
}
|
|
|
|
|
|
|
|
block_init(bdrv_blkdebug_init);
|