> I got the following error when I tried to compile it:
> blockdev.c: In function ‘qmp_blockdev_snapshot_sync’:
> blockdev.c:664: error: unknown field ‘blockdev_snapshot_sync’
> specified in initializer
> cc1: warnings being treated as errors
> blockdev.c:664: error: missing braces around initializer
> blockdev.c:664: error: (near initialization for ‘action.<anonymous>’)
> blockdev.c: In function ‘qmp_drive_mirror’:
> blockdev.c:688: error: unknown field ‘drive_mirror’ specified in
> initializer
> blockdev.c:688: error: missing braces around initializer
> blockdev.c:688: error: (near initialization for ‘action.<anonymous>’)
> blockdev.c:688: error: initialization from incompatible pointer type
> make: *** [blockdev.o] Error 1
> make: *** Waiting for unfinished jobs....
>
> It seems we need a name for the union to reference its member.
Ah, this is in the initializer. Please try the attached patch.
Paolo
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)