From: Gonglei <arei.gong...@huawei.com> Adds "query-bootindex" QMP command.
Example QMP command: -> { "execute": "query-bootindex"} <- { "return":[ { "id":"ide0-0-0", "bootindex":1, "suffix":"/disk@0" }, { "id":"nic1", "bootindex":2, "suffix":"/ethernet-phy@0" } ] } Signed-off-by: Gonglei <arei.gong...@huawei.com> Signed-off-by: Chenliang <chenlian...@huawei.com> --- qapi-schema.json | 29 +++++++++++++++++++++++++++++ qmp-commands.hx | 41 +++++++++++++++++++++++++++++++++++++++++ vl.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/qapi-schema.json b/qapi-schema.json index 30bd6ad..680cbc5 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1704,6 +1704,33 @@ { 'command': 'device_del', 'data': {'id': 'str'} } ## +# @BootindexInfo: +# +# Information about devcie's bootindex. +# +# @id: the name of a device owning the bootindex +# +# @bootindex: the bootindex number +# +# @suffix: the suffix a device's bootindex +# +# Since: 2.2 +## +{ 'type': 'BootindexInfo', + 'data': {'id': 'str', 'bootindex': 'int', 'suffix': 'str'} } + +## +# @query-bootindex: +# +# Returns information about bootindex +# +# Returns: a list of @BootindexInfo for existing device +# +# Since: 2.2 +## +{ 'command': 'query-bootindex', 'returns': ['BootindexInfo'] } + +## # @set-bootindex: # # set bootindex of a device @@ -1715,6 +1742,8 @@ # Returns: Nothing on success # If @id is not a valid device, DeviceNotFound # +# Note: suffix can be gotten by query-bootindex command +# # Since: 2.2 ## { 'command': 'set-bootindex', diff --git a/qmp-commands.hx b/qmp-commands.hx index 19cc3b8..6ab9325 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -337,6 +337,47 @@ EQMP }, SQMP +query-bootindex +--------------- + +Show VM bootindex information. + +The returned value is a json-array of all device configured +bootindex property. Each bootindex is represented by a json-object. + +The bootindex json-object contains the following: + +- "id": the name of a device owning the bootindex (json-string) +- "bootindex": the bootindex number (json-int) +- "suffix": the suffix a device's bootindex (json-string) + +Example: + +-> { "execute": "query-bootindex" } +<- { + "return":[ + { + "id":"ide0-0-0", + "bootindex":1, + "suffix":"/disk@0" + }, + { + "id":"nic1", + "bootindex":2, + "suffix":"/ethernet-phy@0" + } + ] + } + +EQMP + + { + .name = "query-bootindex", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_bootindex, + }, + +SQMP set-bootindex ------------- diff --git a/vl.c b/vl.c index 49328df..52e4d9a 100644 --- a/vl.c +++ b/vl.c @@ -1219,6 +1219,37 @@ static void restore_boot_order(void *opaque) g_free(normal_boot_order); } +BootindexInfoList *qmp_query_bootindex(Error **errp) +{ + BootindexInfoList *booindex_list = NULL; + BootindexInfoList *info; + FWBootEntry *i; + + QTAILQ_FOREACH(i, &fw_boot_order, link) { + info = g_new0(BootindexInfoList, 1); + info->value = g_new0(BootindexInfo, 1); + + if (i->dev->id) { + info->value->id = g_strdup(i->dev->id); + } else { + /* For virtio devices, we should get id from they parent */ + if (i->dev->parent_bus) { + DeviceState *dev = i->dev->parent_bus->parent; + info->value->id = g_strdup(dev->id); + } else { + info->value->id = g_strdup(""); + } + } + info->value->bootindex = i->bootindex; + info->value->suffix = g_strdup(i->suffix); + + info->next = booindex_list; + booindex_list = info; + } + + return booindex_list; +} + void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix) { -- 1.7.12.4