diff --git a/blockdev.c b/blockdev.c index 9480dbb..df8ce14 100644 --- a/blockdev.c +++ b/blockdev.c @@ -709,6 +709,18 @@ void qmp_drive_reopen(const char *device, const char *new_image_file, has_format ? format : "qcow2", errp); } +static void blockdev_do_action(int kind, void *data, Error **errp) +{ + BlockdevAction action; + BlockdevActionList list; + + action.kind = kind; + action.data = data; + list.value = &action; + list.next = NULL; + qmp_transaction(&list, errp); +} + void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, bool has_format, const char *format, bool has_mode, enum NewImageMode mode, @@ -722,16 +734,8 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, .has_mode = has_mode, .mode = mode, }; - BlockdevAction action = { - .kind = BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, - .blockdev_snapshot_sync = &snapshot, - }; - BlockdevActionList list = { - .value = &action, - .next = NULL - }; - - qmp_transaction(&list, errp); + blockdev_do_action(BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC, &snapshot, + errp); } void qmp_drive_mirror(const char *device, const char *target, @@ -746,16 +750,7 @@ void qmp_drive_mirror(const char *device, const char *target, .has_mode = has_mode, .mode = mode, }; - BlockdevAction action = { - .kind = BLOCKDEV_ACTION_KIND_DRIVE_MIRROR, - .drive_mirror = &mirror, - }; - BlockdevActionList list = { - .value = &action, - .next = NULL - }; - - qmp_transaction(&list, errp); + blockdev_do_action(BLOCKDEV_ACTION_KIND_DRIVE_MIRROR, &mirror, errp); } diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 6968e7f..727fb77 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -117,6 +117,7 @@ struct %(name)s { %(name)sKind kind; union { + void *data; ''', name=name)