modify boot order of guest, and take effect after rebooting
v3 cover modify boot order of guest, and take effect after rebooting
From: Gonglei <[email protected]>
Sometimes, we want to modify boot order of a guest, but no need to shutdown it. We can call dynamic changing bootindex of a guest, which can be assured taking effect just after the guest rebooting.
For example, in P2V scene, we boot a guest and then attach a new system disk, for copying some thing. We want to assign the new disk as the booting disk, which means its bootindex=1.
Different nics can be assigen different bootindex dynamically also make sense.
The patchsets add one qmp interface, and add an fw_cfg_machine_reset() to achieve it.
Steps of testing:
./qemu-system-x86_64 -enable-kvm -m 4096 -smp 4 -name redhat6.2 -drive \
file=/home/redhat6.2.img,if=none,id=drive-ide0-0-0 \
-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
-drive file=/home/RH-DVD1.iso,if=none,id=drive-ide0-0-1 \
-device ide-cd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,bootindex=4 \
-vnc 0.0.0.0:10 -netdev type=user,id=net0 \
-device virtio-net-pci,netdev=net0,bootindex=3,id=nic1 \
-netdev type=user,id=net1 -device e1000,netdev=net1,bootindex=2,id=nic2 -monitor stdio QEMU 2.0.93 monitor - type 'help' for more information
(qemu) set-bootindex ide0-0-1 1
The bootindex 1 has already been used
(qemu) set-bootindex ide0-0-1 5 "/disk@1"
(qemu) set-bootindex ide0-0-1 0
(qemu) system_reset
(qemu) set-bootindex ide0-0-1 1
The bootindex 1 has already been used
(qemu) set-bootindex nic2 0
The bootindex 0 has already been used
(qemu) set-bootindex ide0-0-1 -1
(qemu) set-bootindex nic2 0
(qemu) system_reset
(qemu)
Changes since v1:
*rework by Gerd's suggestion:
- split modify and del fw_boot_order for single function.
- change modify bootindex's realization which simply lookup the device and modify the bootindex. if the new bootindex has already used by another device just throw an error.
- change to del_boot_device_path(DeviceState *dev) and simply delete all entries belonging to the device.
Changes since v2:
*address Gerd's reviewing suggestion:
- use the old entry's suffix, if the caller do not pass it in.
- call del_boot_device_path() from device_finalize() instead of placing it into each individual device.
Thanks Gerd.
Gonglei (7):
bootindex: add modify_boot_device_path function
bootindex: add del_boot_device_path function
fw_cfg: add fw_cfg_machine_reset function
bootindex: delete bootindex when device is removed
qmp: add set-bootindex command
qemu-monitor: HMP set-bootindex wrapper
spapr: fix possible memory leak
hmp-commands.hx | 15 ++++++++++ hmp.c | 13 ++++++++ hmp.h | 1 + hw/core/qdev.c | 2 ++ hw/nvram/fw_cfg.c | 54 +++++++++++++++++++++++++++++----- hw/ppc/spapr.c | 1 + include/hw/nvram/fw_cfg.h | 2 ++ include/sysemu/sysemu.h | 3 ++ qapi-schema.json | 16 ++++++++++ qmp-commands.hx | 24 +++++++++++++++ qmp.c | 17 +++++++++++ vl.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 216 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.12.4
PATCH v3 1/7 bootindex: add modify_boot_device_path function
From: Gonglei <[email protected]>
When we want to change one device's bootindex, we should lookup the device and change the bootindex. it is simply that remove it from the global boot list, then re-add it, sorted by new bootindex. If the new bootindex has already used by another device just throw an error.
--- include/sysemu/sysemu.h | 2 ++ vl.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
include/sysemu/sysemu.h +2 -0
@@ -209,6 +209,8 @@ void usb_info(Monitor *mon, const QDict *qdict);void add_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix); +void modify_boot_device_path (int32_t bootindex,DeviceState *dev, +const char *suffix);char *get_boot_devices_list (size_t *size,bool ignore_suffixes);DeviceState *get_boot_device (uint32_t position);
vl.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v3 1/7] bootindex: add modify_boot_device_path function
Hi
Quoted 13 lines
vl.c +13
-0+if (bootindex >=0 ) { + node =g_malloc0 (sizeof (FWBootEntry)); + node->bootindex = bootindex; +if (suffix) { + node->suffix =g_strdup (suffix); + }else if (old_entry) { + node->suffix =g_strdup (old_entry->suffix); + }else { + node->suffix =NULL ; + } + node->dev = dev; + +/* add to the global boot list */
vl.c void add_boot_device_path(int32_t bootindex, DeviceState *dev, · line 1300
Quoted 10 lines
vl.c +10
-0+ QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->bootindex < bootindex) { +continue ; + } +QTAILQ_INSERT_BEFORE (i, node, link); + goto out; + } + +QTAILQ_INSERT_TAIL (&fw_boot_order, node, link); + }
this code can be simply like this:
suffix = suffix ? suffix : old_entry->suffix ? old_entry->suffix : NULL;
add_boot_device_path(boot_index, dev, suffix)
Best regards
Chen Liang
Re: [Qemu-devel] [PATCH v3 1/7] bootindex: add modify_boot_device_path function
Quoted 33 lines
-----Original Message-----
From: 陈梁 [mailto:[email protected]]
Sent: Sunday, July 27, 2014 11:51 AM
Subject: Re: [Qemu-devel] [PATCH v3 1/7] bootindex: addmodify_boot_device_pathfunctionHi
Quoted 13 lines
vl.c +13
-0+if (bootindex >=0 ) { + node =g_malloc0 (sizeof (FWBootEntry)); + node->bootindex = bootindex; +if (suffix) { + node->suffix =g_strdup (suffix); + }else if (old_entry) { + node->suffix =g_strdup (old_entry->suffix); + }else { + node->suffix =NULL ; + } + node->dev = dev; + +/* add to the global boot list */ vl.c void add_boot_device_path(int32_t bootindex, DeviceState *dev, · line 1300
Quoted 10 lines
vl.c +10
-0+ QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->bootindex < bootindex) { +continue ; + } +QTAILQ_INSERT_BEFORE (i, node, link); + goto out; + } + +QTAILQ_INSERT_TAIL (&fw_boot_order, node, link); + }this code can be simply like this:
Quoted 4 lines
suffix = suffix ? suffix :
old_entry->suffix?old_entry->suffix: NULL;
add_boot_device_path(boot_index, dev, suffix)
Nice, thanks.
Best regards,
-Gonglei
PATCH v3 2/7 bootindex: add del_boot_device_path function
In reply to [email protected]From: Gonglei <[email protected]>
Introduce a del_boot_device_path() cleanup fw_cfg content when hot-unplugging devcie refer to bootindex.
--- include/sysemu/sysemu.h | 1 + vl.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
include/sysemu/sysemu.h +1 -0
@@ -209,6 +209,7 @@ void usb_info(Monitor *mon, const QDict *qdict);void add_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix); +void del_boot_device_path (DeviceState *dev);void modify_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix);char *get_boot_devices_list (size_t *size,bool ignore_suffixes);
vl.c +17 -0
@@ -1248,6 +1248,23 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,QTAILQ_INSERT_TAIL (&fw_boot_order, node, link); } +void del_boot_device_path (DeviceState *dev) +{ +FWBootEntry *i; + +assert (dev !=NULL ); + + QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->dev->id && dev->id && !strcmp (i->dev->id, dev->id)) { +/* remove all entries of the assigend dev */ +QTAILQ_REMOVE (&fw_boot_order, i, link); +g_free (i->suffix); +g_free (i); +break ; + } + } +} +void modify_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix) {
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v3 2/7] bootindex: add del_boot_device_path function
Quoted 4 lines · On 07/25/2014 10:45 PM, [email protected] wrote:
From: Gonglei <[email protected]>
Introduce a
del_boot_device_path()cleanupfw_cfgcontent when hot-unplugging devcie refer to bootindex.
s/devcie/device/
sounds odd; maybe:
Introduce del_boot_device_path() to clean up fw_cfg content when hot-unplugging a device that refers to a bootindex.
vl.c void add_boot_device_path(int32_t bootindex, DeviceState *dev, · line 1259
Quoted 4 lines
vl.c +4
-0+ + QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->dev->id && dev->id && !strcmp (i->dev->id, dev->id)) { +/* remove all entries of the assigend dev */
s/assigend/assigned/
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/7] bootindex: add del_boot_device_path function
Hi,
Quoted 10 lines
Quoted 2 lines
Introduce a
del_boot_device_path()cleanupfw_cfgcontent when hot-unplugging devcie refer to bootindex.s/devcie/device/
sounds odd; maybe:
Introduce
del_boot_device_path()to clean upfw_cfgcontent when hot-unplugging a device that refers to a bootindex.
OK. Thanks, Eric.
Quoted 7 lines
vl.c void add_boot_device_path(int32_t bootindex, DeviceState *dev, · line 1259
Quoted 4 lines
vl.c +4
-0+ + QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->dev->id && dev->id && !strcmp (i->dev->id, dev->id)) { +/* remove all entries of the assigend dev */ s/assigend/assigned/
OK.
Quoted 4 lines
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Best regards,
-Gonglei
Re: [Qemu-devel] [PATCH v3 2/7] bootindex: add del_boot_device_path function
In reply to [email protected]Quoted 30 lines · On Sat, Jul 26, 2014 at 12:45:28PM +0800, [email protected] wrote:
From: Gonglei <[email protected]>
Introduce a
del_boot_device_path()cleanupfw_cfgcontent when hot-unplugging devcie refer to bootindex.Signed-off-by Gonglei <[email protected]>Signed-off-by Chenliang <[email protected]>--- include/sysemu/sysemu.h | 1 + vl.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)include/sysemu/sysemu.h +1
-0@@ -209,6 +209,7 @@ void usb_info(Monitor *mon, const QDict *qdict);void add_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix); +void del_boot_device_path (DeviceState *dev);void modify_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix);char *get_boot_devices_list (size_t *size,bool ignore_suffixes);vl.c +0
-0@@ -1248,6 +1248,23 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev,QTAILQ_INSERT_TAIL (&fw_boot_order, node, link);
vl.c void add_boot_device_path(int32_t bootindex, DeviceState *dev, · line 1258
Quoted 10 lines
vl.c +8
-0} +void del_boot_device_path (DeviceState *dev) +{ +FWBootEntry *i; + +assert (dev !=NULL ); + + QTAILQ_FOREACH(i, &fw_boot_order, link) { +if (i->dev->id && dev->id && !strcmp (i->dev->id, dev->id)) {
What if the device doesn't have any ID set? I don't see anything on add_boot_device_path() ensuring that dev->id is always set.
Why you don't just check if i->dev == dev?
Quoted 17 lines
vl.c +9
-0+/* remove all entries of the assigend dev */ +QTAILQ_REMOVE (&fw_boot_order, i, link); +g_free (i->suffix); +g_free (i); +break ; + } + } +} +void modify_boot_device_path (int32_t bootindex,DeviceState *dev,const char *suffix) {Signature · 1 line
1.7.12.4
Signature · 1 line
Eduardo
PATCH v3 3/7 fw_cfg: add fw_cfg_machine_reset function
In reply to [email protected]From: Gonglei <[email protected]>
We must assure that the changed bootindex can take effect when guest is rebooted. So we introduce fw_cfg_machine_reset(), which change the fw_cfg file's bootindex data using the new global fw_boot_order list.
--- hw/nvram/fw_cfg.c | 54 +++++++++++++++++++++++++++++++++++++++++------ include/hw/nvram/fw_cfg.h | 2 ++ 2 files changed, 49 insertions(+), 7 deletions(-)
hw/nvram/fw_cfg.c +47 -7
@@ -56,7 +56,6 @@ struct FWCfgState {FWCfgFiles *files;uint16_t cur_entry;uint32_t cur_offset; -Notifier machine_ready; };#define JPG_FILE 0
@@ -402,6 +401,26 @@ static void fw_cfg_add_bytes_read_callback(FWCfgState *s, uint16_t key, s->entries[arch][key].callback_opaque = callback_opaque; } +static void *fw_cfg_modify_bytes_read (FWCfgState *s,uint16_t key, +void *data,size_t len) +{ +void *ptr; +int arch = !!(key &FW_CFG_ARCH_LOCAL ); + + key &=FW_CFG_ENTRY_MASK ; + +assert (key <FW_CFG_MAX_ENTRY && len <UINT32_MAX ); + +/* return the old data to the function caller, avoid memory leak */ + ptr = s->entries[arch][key].data; + s->entries[arch][key].data = data; + s->entries[arch][key].len = len; + s->entries[arch][key].callback_opaque =NULL ; + s->entries[arch][key].callback =NULL ; + +return ptr; +} +void fw_cfg_add_bytes (FWCfgState *s,uint16_t key,void *data,size_t len) {fw_cfg_add_bytes_read_callback (s, key,NULL ,NULL , data, len);
@@ -499,13 +518,36 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename,fw_cfg_add_file_callback (s, filename,NULL ,NULL , data, len); } -static void fw_cfg_machine_ready (struct Notifier *n,void *data) +void *fw_cfg_modify_file (FWCfgState *s,const char *filename, +void *data,size_t len) +{ +int i, index; + +assert (s->files); + + index =be32_to_cpu (s->files->count); +assert (index <FW_CFG_FILE_SLOTS ); + +for (i =0 ; i < index; i++) { +if (strcmp (filename, s->files->f[i].name) ==0 ) { +return fw_cfg_modify_bytes_read (s,FW_CFG_FILE_FIRST + i, + data, len); + } + } +/* add new one */ +fw_cfg_add_file_callback (s, filename,NULL ,NULL , data, len); +return NULL ; +} + +static void fw_cfg_machine_reset (void *opaque) { +void *ptr;size_t len; -FWCfgState *s =container_of (n, FWCfgState, machine_ready); +FWCfgState *s = opaque;char *bootindex =get_boot_devices_list (&len, false); -fw_cfg_add_file (s,"bootorder" , (uint8_t *)bootindex, len); + ptr =fw_cfg_modify_file (s,"bootorder" , (uint8_t *)bootindex, len); +g_free (ptr); } FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
@@ -542,9 +584,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,fw_cfg_bootsplash (s);fw_cfg_reboot (s); - s->machine_ready.notify = fw_cfg_machine_ready; -qemu_add_machine_init_done_notifier (&s->machine_ready); - +qemu_register_reset (fw_cfg_machine_reset, s);return s; }
include/hw/nvram/fw_cfg.h +2 -0
@@ -76,6 +76,8 @@ void fw_cfg_add_file(FWCfgState *s, const char *filename, void *data,void fw_cfg_add_file_callback (FWCfgState *s,const char *filename,FWCfgReadCallback callback,void *callback_opaque,void *data,size_t len); +void *fw_cfg_modify_file (FWCfgState *s,const char *filename,void *data, +size_t len);FWCfgState *fw_cfg_init (uint32_t ctl_port,uint32_t data_port,hwaddr crl_addr,hwaddr data_addr);
Signature · 1 line
1.7.12.4
PATCH v3 4/7 bootindex: delete bootindex when device is removed
In reply to [email protected]From: Gonglei <[email protected]>
Device should be removed from global boot list when it is hot-unplugged.
--- hw/core/qdev.c | 2 ++ 1 file changed, 2 insertions(+)
hw/core/qdev.c +2 -0
@@ -975,6 +975,8 @@ static void device_finalize(Object *obj)if (dev->opts) {qemu_opts_del (dev->opts); } +/* remove device's bootindex from global boot order list */ +del_boot_device_path (dev); QLIST_FOREACH_SAFE(ngl, &dev->gpios, node, next) {QLIST_REMOVE (ngl, node);
Signature · 1 line
1.7.12.4
PATCH v3 5/7 qmp: add set-bootindex command
In reply to [email protected]From: Gonglei <[email protected]>
Adds "set-bootindex id=xx,bootindex=xx,suffix=xx" QMP command.
Example QMP command:
-> { "execute": "set-bootindex", "arguments": { "id": "ide0-0-1", "bootindex": 1, "suffix": "/disk@0"}} <- { "return": {} }
--- qapi-schema.json | 16 ++++++++++++++++ qmp-commands.hx | 24 ++++++++++++++++++++++++ qmp.c | 17 +++++++++++++++++ 3 files changed, 57 insertions(+)
qapi-schema.json +16 -0
@@ -1704,6 +1704,22 @@ { 'command': 'device_del', 'data': {'id': 'str'} } ## +# @set-bootindex: +# +# set bootindex of a devcie +# +# @id: the name of the device +# @bootindex: the bootindex of the device +# @suffix: #optional a suffix of the device +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# +# Since: 2.2 +## +{ 'command': 'set-bootindex', 'data': {'id': 'str', 'bootindex': 'int', '*suffix': 'str'} } + +## # @DumpGuestMemoryFormat: # # An enumeration of guest-memory-dump's format.
qmp-commands.hx +24 -0
@@ -330,6 +330,30 @@ Example: <- { "return": {} } EQMP + { + .name = "set-bootindex", + .args_type = "id:s,bootindex:l,suffix:s?", + .mhandler.cmd_new = qmp_marshal_input_set_bootindex, + }, + +SQMP +set-bootindex +-------------------- + +Set bootindex of a device + +Arguments: + +- "id": the device's ID (json-string) +- "bootindex": the device's bootindex (json-int) +- "suffix": the device's suffix in global boot list (json-string, optional) + +Example: + +-> { "execute": "set-bootindex", "arguments": { "id": "ide0-0-1", "bootindex": 1, "suffix": "/disk@0"}} +<- { "return": {} } + +EQMP { .name = "send-key",
qmp.c +17 -0
@@ -684,6 +684,23 @@ void qmp_object_del(const char *id, Error **errp)object_unparent (obj); } +void qmp_set_bootindex (const char *id,int64_t bootindex, +bool has_suffix,const char *suffix,Error **errp) +{ +DeviceState *dev; + + dev =qdev_find_recursive (sysbus_get_default (), id); +if (NULL == dev) { +error_set (errp,QERR_DEVICE_NOT_FOUND , id); +return ; + } +if (has_suffix) { +modify_boot_device_path (bootindex, dev, suffix); + }else { +modify_boot_device_path (bootindex, dev,NULL ); + } +} +MemoryDeviceInfoList *qmp_query_memory_devices (Error **errp) {MemoryDeviceInfoList *head =NULL ;
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH v3 5/7] qmp: add set-bootindex command
Quoted 21 lines · On 07/25/2014 10:45 PM, [email protected] wrote:
From: Gonglei <[email protected]>
Adds "set-bootindex id=xx,bootindex=xx,suffix=xx" QMP command.
Example QMP command:
-> { "execute": "set-bootindex", "arguments": { "id": "ide0-0-1", "bootindex": 1, "suffix": "/disk@0"}} <- { "return": {} }Signed-off-by Gonglei <[email protected]>Signed-off-by Chenliang <[email protected]>--- qapi-schema.json | 16 ++++++++++++++++ qmp-commands.hx | 24 ++++++++++++++++++++++++ qmp.c | 17 +++++++++++++++++ 3 files changed, 57 insertions(+)qapi-schema.json +0
-0
qapi-schema.json line 1709
Quoted 6 lines
qapi-schema.json +3
-0@@ -1704,6 +1704,22 @@ { 'command': 'device_del', 'data': {'id': 'str'} } ## +# @set-bootindex: +# +# set bootindex of a devcie
s/devcie/device/
Just to make sure this command is not write-only, it would be nice to mention which query-* command can be used to learn a device's current bootindex.
qapi-schema.json line 1720
Quoted 11 lines
qapi-schema.json +11
-0+# +# @id: the name of the device +# @bootindex: the bootindex of the device +# @suffix: #optional a suffix of the device +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# +# Since: 2.2 +## +{ 'command': 'set-bootindex', 'data': {'id': 'str', 'bootindex': 'int', '*suffix': 'str'} }
Long line; wrap it to stay in 80 columns.
qapi-schema.json line 1724
Quoted 4 lines
qapi-schema.json +4
-0+ +SQMP +set-bootindex +--------------------
Match the ---- length to the command name.
qapi-schema.json void qmp_object_del(const char *id, Error **errp) · line 688
Quoted 7 lines
qapi-schema.json +3
-0+++ b/qmp.c@@ -684,6 +684,23 @@ void qmp_object_del(const char *id, Error **errp) object_unparent(obj); } +void qmp_set_bootindex(const char *id, int64_t bootindex, + bool has_suffix, const char *suffix, Error **errp)
Indentation is off.
qapi-schema.json void qmp_object_del(const char *id, Error **errp) · line 693
Quoted 5 lines
qapi-schema.json +5
-0+{ + DeviceState *dev; + + dev = qdev_find_recursive(sysbus_get_default(), id); + if (NULL == dev) {
Code like Yoda we do not. This is more idiomatically written 'if (!dev)' or 'if (dev == NULL)'.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 5/7] qmp: add set-bootindex command
Hi,
Quoted 30 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: Thursday, July 31, 2014 6:37 AM
Subject: Re: [PATCH v3 5/7] qmp: add set-bootindex commandQuoted 6 lines · On 07/25/2014 10:45 PM, [email protected] wrote:
From: Gonglei <[email protected]>
Adds "set-bootindex id=xx,bootindex=xx,suffix=xx" QMP command.
Example QMP command:
-> { "execute": "set-bootindex", "arguments": { "id": "ide0-0-1", "bootindex":1, "suffix": "/disk@0"}}
Quoted 17 lines
<- { "return": {} }
Signed-off-by Gonglei <[email protected]>Signed-off-by Chenliang <[email protected]>--- qapi-schema.json | 16 ++++++++++++++++ qmp-commands.hx | 24 ++++++++++++++++++++++++ qmp.c | 17 +++++++++++++++++ 3 files changed, 57 insertions(+)qapi-schema.json +0
-0@@ -1704,6 +1704,22 @@ { 'command': 'device_del', 'data': {'id': 'str'} }
Quoted 7 lines
qapi-schema.json line 1709
Quoted 4 lines
qapi-schema.json +3
-0## +# @set-bootindex: +# +# set bootindex of a devcies/devcie/device/
OK.
Quoted 4 lines
Just to make sure this command is not write-only, it would be nice to mention which query-* command can be used to learn a device's current bootindex.
Yes. I am thinking about introducing a query-bootindex command, which can show a device's current bootindex and bootindex's suffix.
Quoted 13 lines
qapi-schema.json
Quoted 11 lines
qapi-schema.json +11
-0+# +# @id: the name of the device +# @bootindex: the bootindex of the device +# @suffix: #optional a suffix of the device +# +# Returns: Nothing on success +# If @id is not a valid device, DeviceNotFound +# +# Since: 2.2 +## +{ 'command': 'set-bootindex', 'data': {'id': 'str', 'bootindex': 'int', '*suffix':'str'} }
Quoted 2 lines
Long line; wrap it to stay in 80 columns.
OK.
Quoted 8 lines
qapi-schema.json line 1724
Quoted 5 lines
qapi-schema.json +4
-0+ +SQMP +set-bootindex +--------------------Match the ---- length to the command name.
OK.
Quoted 10 lines
qapi-schema.json void qmp_object_del(const char *id, Error **errp) · line 688
Quoted 7 lines
qapi-schema.json +3
-0+++ b/qmp.c@@ -684,6 +684,23 @@ void qmp_object_del(const char *id, Error **errp) object_unparent(obj); } +void qmp_set_bootindex(const char *id, int64_t bootindex, + bool has_suffix, const char *suffix, Error **errp)Indentation is off.
OK.
Quoted 9 lines
qapi-schema.json void qmp_object_del(const char *id, Error **errp) · line 693
Quoted 5 lines
qapi-schema.json +5
-0+{ + DeviceState *dev; + + dev = qdev_find_recursive(sysbus_get_default(), id); + if (NULL == dev) {Code like Yoda we do not. This is more idiomatically written 'if (!dev)' or 'if (dev == NULL)'.
OK.
Thanks for your careful reviewing, Eric.
I will fix those problems in the next version.
Quoted 3 lines
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Best regards,
-Gonglei
PATCH v3 6/7 qemu-monitor: HMP set-bootindex wrapper
In reply to [email protected]From: Gonglei <[email protected]>
Add HMP set-bootindex wrapper to allow setting
devcie's bootindex via monitor.
--- hmp-commands.hx | 15 +++++++++++++++ hmp.c | 13 +++++++++++++ hmp.h | 1 + 3 files changed, 29 insertions(+)
hmp-commands.hx +15 -0
@@ -688,6 +688,21 @@ Remove device @var{id}. ETEXI { + .name = "set-bootindex", + .args_type = "id:s,bootindex:l,suffix:s?", + .params = "device bootindex [suffix]", + .help = "set bootindex of a device(e.g. set-bootindex disk0 1 '/disk@0')", + .mhandler.cmd = hmp_set_bootindex, + }, + +STEXI +@item set-bootindex @var{id} @var{bootindex} +@findex set-bootindex + +Set bootindex of a device. +ETEXI + + { .name = "cpu", .args_type = "index:i", .params = "index",
hmp.c +13 -0
@@ -1714,3 +1714,16 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)monitor_printf (mon,"\n" ); } + +void hmp_set_bootindex (Monitor *mon,const QDict *qdict) +{ +Error *err =NULL ; + +const char *id =qdict_get_str (qdict,"id" ); +int64_t bootindex =qdict_get_int (qdict,"bootindex" ); +bool has_suffix =qdict_haskey (qdict,"suffix" ); +const char *suffix =qdict_get_try_str (qdict,"suffix" ); + +qmp_set_bootindex (id, bootindex, has_suffix, suffix, &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);void hmp_object_add (Monitor *mon,const QDict *qdict);void hmp_object_del (Monitor *mon,const QDict *qdict);void hmp_info_memdev (Monitor *mon,const QDict *qdict); +void hmp_set_bootindex (Monitor *mon,const QDict *qdict);void object_add_completion (ReadLineState *rs,int nb_args,const char *str);void object_del_completion (ReadLineState *rs,int nb_args,const char *str);void device_add_completion (ReadLineState *rs,int nb_args,const char *str);
Signature · 1 line
1.7.12.4
PATCH v3 7/7 spapr: fix possible memory leak
In reply to [email protected]From: Gonglei <[email protected]>
get_boot_devices_list() will malloc memory, spapr_finalize_fdt doesn't free it.
--- hw/ppc/spapr.c | 1 + 1 file changed, 1 insertion(+)
hw/ppc/spapr.c +1 -0
@@ -745,6 +745,7 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,cpu_physical_memory_write (fdt_addr, fdt,fdt_totalsize (fdt)); +g_free (bootlist);g_free (fdt); }
Signature · 1 line
1.7.12.4