Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into st…
Browse files Browse the repository at this point in the history
…aging

* remotes/qmp-unstable/queue/qmp: (43 commits)
  monitor: protect event emission
  monitor: protect outbuf and mux_out with mutex
  qemu-char: make writes thread-safe
  qemu-char: move pty_chr_update_read_handler around
  qemu-char: do not call chr_write directly
  qemu-char: introduce qemu_chr_alloc
  qapi event: clean up
  qapi event: convert QUORUM events
  qapi event: convert GUEST_PANICKED
  qapi event: convert BALLOON_CHANGE
  qmp: convert ACPI_DEVICE_OST event
  qapi event: convert SPICE events
  qapi event: convert VNC events
  qapi event: convert NIC_RX_FILTER_CHANGED
  qapi event: convert other BLOCK_JOB events
  qapi event: convert BLOCK_IMAGE_CORRUPTED
  qapi event: convert BLOCK_IO_ERROR and BLOCK_JOB_ERROR
  qapi event: convert DEVICE_TRAY_MOVED
  qapi event: convert DEVICE_DELETED
  qapi event: convert WATCHDOG
  ...

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Jun 24, 2014
2 parents 27acb9d + d622cb5 commit 089a394
Show file tree
Hide file tree
Showing 75 changed files with 2,050 additions and 1,316 deletions.
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ endif
endif

GENERATED_HEADERS = config-host.h qemu-options.def
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c
GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-event.h
GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-event.c

GENERATED_HEADERS += trace/generated-events.h
GENERATED_SOURCES += trace/generated-events.c
Expand Down Expand Up @@ -202,7 +202,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
# Build libraries

libqemustub.a: $(stub-obj-y)
libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o qapi-event.o

block-modules = $(foreach o,$(block-obj-m),"$(basename $(subst /,-,$o))",) NULL
util/module.o-cflags = -D'CONFIG_BLOCK_MODULES=$(block-modules)'
Expand Down Expand Up @@ -246,18 +246,27 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(gen-out-type) -o qga/qapi-generated -p "qga-" -i $<, \
" GEN $@")

qapi-modules = $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/qapi/common.json \
$(SRC_PATH)/qapi/block.json $(SRC_PATH)/qapi/block-core.json \
$(SRC_PATH)/qapi-event.json

qapi-types.c qapi-types.h :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
$(qapi-modules) $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py \
$(gen-out-type) -o "." -b -i $<, \
" GEN $@")
qapi-visit.c qapi-visit.h :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(qapi-modules) $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py \
$(gen-out-type) -o "." -b -i $<, \
" GEN $@")
qapi-event.c qapi-event.h :\
$(qapi-modules) $(SRC_PATH)/scripts/qapi-event.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-event.py \
$(gen-out-type) -o "." -b -i $<, \
" GEN $@")
qmp-commands.h qmp-marshal.c :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(qapi-modules) $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py \
$(gen-out-type) -o "." -m -i $<, \
" GEN $@")
Expand Down
2 changes: 1 addition & 1 deletion Makefile.objs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ block-obj-y += main-loop.o iohandler.o qemu-timer.o
block-obj-$(CONFIG_POSIX) += aio-posix.o
block-obj-$(CONFIG_WIN32) += aio-win32.o
block-obj-y += block/
block-obj-y += qapi-types.o qapi-visit.o
block-obj-y += qapi-types.o qapi-visit.o qapi-event.o
block-obj-y += qemu-io-cmds.o

block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
Expand Down
2 changes: 1 addition & 1 deletion backends/baum.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ CharDriverState *chr_baum_init(void)
int tty;

baum = g_malloc0(sizeof(BaumDriverState));
baum->chr = chr = g_malloc0(sizeof(CharDriverState));
baum->chr = chr = qemu_chr_alloc();

chr->opaque = baum;
chr->chr_write = baum_write;
Expand Down
2 changes: 1 addition & 1 deletion backends/msmouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void)
{
CharDriverState *chr;

chr = g_malloc0(sizeof(CharDriverState));
chr = qemu_chr_alloc();
chr->chr_write = msmouse_chr_write;
chr->chr_close = msmouse_chr_close;
chr->explicit_be_open = true;
Expand Down
13 changes: 0 additions & 13 deletions balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ static int qemu_balloon_status(BalloonInfo *info)
return 1;
}

void qemu_balloon_changed(int64_t actual)
{
QObject *data;

data = qobject_from_jsonf("{ 'actual': %" PRId64 " }",
actual);

monitor_protocol_event(QEVENT_BALLOON_CHANGE, data);

qobject_decref(data);
}


BalloonInfo *qmp_query_balloon(Error **errp)
{
BalloonInfo *info;
Expand Down
73 changes: 21 additions & 52 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "config-host.h"
#include "qemu-common.h"
#include "trace.h"
#include "monitor/monitor.h"
#include "block/block_int.h"
#include "block/blockjob.h"
#include "qemu/module.h"
Expand All @@ -35,6 +34,7 @@
#include "block/qapi.h"
#include "qmp-commands.h"
#include "qemu/timer.h"
#include "qapi-event.h"

#ifdef CONFIG_BSD
#include <sys/types.h>
Expand Down Expand Up @@ -2132,59 +2132,20 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
bs->dev_opaque = opaque;
}

void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
enum MonitorEvent ev,
BlockErrorAction action, bool is_read)
{
QObject *data;
const char *action_str;

switch (action) {
case BDRV_ACTION_REPORT:
action_str = "report";
break;
case BDRV_ACTION_IGNORE:
action_str = "ignore";
break;
case BDRV_ACTION_STOP:
action_str = "stop";
break;
default:
abort();
}

data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
bdrv->device_name,
action_str,
is_read ? "read" : "write");
monitor_protocol_event(ev, data);

qobject_decref(data);
}

static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
{
QObject *data;

data = qobject_from_jsonf("{ 'device': %s, 'tray-open': %i }",
bdrv_get_device_name(bs), ejected);
monitor_protocol_event(QEVENT_DEVICE_TRAY_MOVED, data);

qobject_decref(data);
}

static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
{
if (bs->dev_ops && bs->dev_ops->change_media_cb) {
bool tray_was_closed = !bdrv_dev_is_tray_open(bs);
bs->dev_ops->change_media_cb(bs->dev_opaque, load);
if (tray_was_closed) {
/* tray open */
bdrv_emit_qmp_eject_event(bs, true);
qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
true, &error_abort);
}
if (load) {
/* tray close */
bdrv_emit_qmp_eject_event(bs, false);
qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
false, &error_abort);
}
}
}
Expand Down Expand Up @@ -3606,13 +3567,14 @@ BlockErrorAction bdrv_get_error_action(BlockDriverState *bs, bool is_read, int e

switch (on_err) {
case BLOCKDEV_ON_ERROR_ENOSPC:
return (error == ENOSPC) ? BDRV_ACTION_STOP : BDRV_ACTION_REPORT;
return (error == ENOSPC) ?
BLOCK_ERROR_ACTION_STOP : BLOCK_ERROR_ACTION_REPORT;
case BLOCKDEV_ON_ERROR_STOP:
return BDRV_ACTION_STOP;
return BLOCK_ERROR_ACTION_STOP;
case BLOCKDEV_ON_ERROR_REPORT:
return BDRV_ACTION_REPORT;
return BLOCK_ERROR_ACTION_REPORT;
case BLOCKDEV_ON_ERROR_IGNORE:
return BDRV_ACTION_IGNORE;
return BLOCK_ERROR_ACTION_IGNORE;
default:
abort();
}
Expand All @@ -3627,7 +3589,7 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
{
assert(error >= 0);

if (action == BDRV_ACTION_STOP) {
if (action == BLOCK_ERROR_ACTION_STOP) {
/* First set the iostatus, so that "info block" returns an iostatus
* that matches the events raised so far (an additional error iostatus
* is fine, but not a lost one).
Expand All @@ -3643,10 +3605,16 @@ void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
* also ensures that the STOP/RESUME pair of events is emitted.
*/
qemu_system_vmstop_request_prepare();
bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
action, &error_abort);
qemu_system_vmstop_request(RUN_STATE_IO_ERROR);
} else {
bdrv_emit_qmp_error_event(bs, QEVENT_BLOCK_IO_ERROR, action, is_read);
qapi_event_send_block_io_error(bdrv_get_device_name(bs),
is_read ? IO_OPERATION_TYPE_READ :
IO_OPERATION_TYPE_WRITE,
action, &error_abort);
}
}

Expand Down Expand Up @@ -5216,7 +5184,8 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag)
}

if (bs->device_name[0] != '\0') {
bdrv_emit_qmp_eject_event(bs, eject_flag);
qapi_event_send_device_tray_moved(bdrv_get_device_name(bs),
eject_flag, &error_abort);
}
}

Expand Down
2 changes: 1 addition & 1 deletion block/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static void coroutine_fn backup_run(void *opaque)
/* Depending on error action, fail now or retry cluster */
BlockErrorAction action =
backup_error_action(job, error_is_read, -ret);
if (action == BDRV_ACTION_REPORT) {
if (action == BLOCK_ERROR_ACTION_REPORT) {
break;
} else {
start--;
Expand Down
9 changes: 5 additions & 4 deletions block/mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void mirror_write_complete(void *opaque, int ret)

bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
action = mirror_error_action(s, false, -ret);
if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
s->ret = ret;
}
}
Expand All @@ -135,7 +135,7 @@ static void mirror_read_complete(void *opaque, int ret)

bdrv_set_dirty(source, op->sector_num, op->nb_sectors);
action = mirror_error_action(s, true, -ret);
if (action == BDRV_ACTION_REPORT && s->ret >= 0) {
if (action == BLOCK_ERROR_ACTION_REPORT && s->ret >= 0) {
s->ret = ret;
}

Expand Down Expand Up @@ -415,7 +415,8 @@ static void coroutine_fn mirror_run(void *opaque)
trace_mirror_before_flush(s);
ret = bdrv_flush(s->target);
if (ret < 0) {
if (mirror_error_action(s, false, -ret) == BDRV_ACTION_REPORT) {
if (mirror_error_action(s, false, -ret) ==
BLOCK_ERROR_ACTION_REPORT) {
goto immediate_exit;
}
} else {
Expand All @@ -426,7 +427,7 @@ static void coroutine_fn mirror_run(void *opaque)
*/
s->common.offset = end * BDRV_SECTOR_SIZE;
if (!s->synced) {
block_job_ready(&s->common);
block_job_event_ready(&s->common);
s->synced = true;
}

Expand Down
14 changes: 8 additions & 6 deletions block/qcow2-refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "block/qcow2.h"
#include "qemu/range.h"
#include "qapi/qmp/types.h"
#include "qapi-event.h"

static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size);
static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
Expand Down Expand Up @@ -1807,7 +1808,6 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
} else if (ret > 0) {
int metadata_ol_bitnr = ffs(ret) - 1;
char *message;
QObject *data;

assert(metadata_ol_bitnr < QCOW2_OL_MAX_BITNR);

Expand All @@ -1816,12 +1816,14 @@ int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset,
metadata_ol_names[metadata_ol_bitnr]);
message = g_strdup_printf("Prevented %s overwrite",
metadata_ol_names[metadata_ol_bitnr]);
data = qobject_from_jsonf("{ 'device': %s, 'msg': %s, 'offset': %"
PRId64 ", 'size': %" PRId64 " }", bs->device_name, message,
offset, size);
monitor_protocol_event(QEVENT_BLOCK_IMAGE_CORRUPTED, data);
qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs),
message,
true,
offset,
true,
size,
&error_abort);
g_free(message);
qobject_decref(data);

qcow2_mark_corrupt(bs);
bs->drv = NULL; /* make BDS unusable */
Expand Down
25 changes: 8 additions & 17 deletions block/quorum.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <gnutls/crypto.h>
#include "block/block_int.h"
#include "qapi/qmp/qjson.h"
#include "qapi-event.h"

#define HASH_LENGTH 32

Expand Down Expand Up @@ -198,32 +199,22 @@ static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,

static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
{
QObject *data;
assert(node_name);
data = qobject_from_jsonf("{ 'node-name': %s"
", 'sector-num': %" PRId64
", 'sectors-count': %d }",
node_name, acb->sector_num, acb->nb_sectors);
const char *msg = NULL;
if (ret < 0) {
QDict *dict = qobject_to_qdict(data);
qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
msg = strerror(-ret);
}
monitor_protocol_event(QEVENT_QUORUM_REPORT_BAD, data);
qobject_decref(data);
qapi_event_send_quorum_report_bad(!!msg, msg, node_name,
acb->sector_num, acb->nb_sectors, &error_abort);
}

static void quorum_report_failure(QuorumAIOCB *acb)
{
QObject *data;
const char *reference = acb->common.bs->device_name[0] ?
acb->common.bs->device_name :
acb->common.bs->node_name;
data = qobject_from_jsonf("{ 'reference': %s"
", 'sector-num': %" PRId64
", 'sectors-count': %d }",
reference, acb->sector_num, acb->nb_sectors);
monitor_protocol_event(QEVENT_QUORUM_FAILURE, data);
qobject_decref(data);

qapi_event_send_quorum_failure(reference, acb->sector_num,
acb->nb_sectors, &error_abort);
}

static int quorum_vote_error(QuorumAIOCB *acb);
Expand Down
4 changes: 2 additions & 2 deletions block/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ static void coroutine_fn stream_run(void *opaque)
BlockErrorAction action =
block_job_error_action(&s->common, s->common.bs, s->on_error,
true, -ret);
if (action == BDRV_ACTION_STOP) {
if (action == BLOCK_ERROR_ACTION_STOP) {
n = 0;
continue;
}
if (error == 0) {
error = ret;
}
if (action == BDRV_ACTION_REPORT) {
if (action == BLOCK_ERROR_ACTION_REPORT) {
break;
}
}
Expand Down
Loading

0 comments on commit 089a394

Please sign in to comment.