From: Gonglei <arei.gong...@huawei.com> 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. This patch series do belows works: 1. add an fw_cfg_machine_reset() assure re-read global fw_boot_order list during vm rebooting. 2. switch the property from qdev to qom, then use the set callback to also update the fw_cfg file. Note: - Do not support change pci option rom's bootindex. - Do not handle those devices which don't have use the bootindex property. changes since v8: - fix wrong rebase on PATCH 14/30 and 15/30. changes since v7: - IDE unit's value is set too later, so change IDE to not use device_add_bootindex_property(). IDE has its own getter/setter and a call to add_boot_device_path() on realize(). PATCH 25/30, 28/30 (Eduardo) - rewrite PATCH 5/30 using g_strcmp0. (Eduardo) - set 'ide_device_type_info.instance_init = ide_dev_instance_init' for all ide devices. PATCH 25/30 (Eduardo) - set 'scsi_device_type_info.instance_init = scsi_dev_instance_init' for all scsi devices. PATCH 24/30 - initialize bootindex property to -1 in device_add_bootindex_property, so there is no need to duplicate the call to init bootindex with -1 in all devices. (Gerd) Thanks for review! changes since v6: - move all bootindex/boot-device code to a new file, named bootdevice.c. - introduce a getter/setter wrapper for all device. - call add_boot_device_path in setter bootindx callback function. - call del_boot_device_path in finalize bootindex qom callback function. - other bugfixes. Thanks for Eduardo's good suggestion! And other guys, thanks too! changes since v5: rework by Gerd and Markus's suggestion(Thanks a lot): - Set/update bootindex on reset instead of realize/init. - Switch the property from qdev to qom, then use the set callback to also update the fw_cfg file. - using qom-set instead of 'set-bootindex' qmp interface, remove it. This is a huge change relative to the previous version. Changes since v4: - using error_setg() instead of qerror_report() in patch 1/8. - call del_boot_device_path() from device_finalize() instead of placing it into each individual device in patch 4/8. Changes since v3: - rework del_* and modify_* function, because of virtio devices' specialation. For example, virtio-net's id is NULL, and its parent virtio-net-pci's id was assigned. Though the global fw_boot_order stored the virtio-net device. - call dell_boot_device_path in each individual device avoiding waste resouce. - introduce qmp "query-bootindex" command - introcude hmp "info bootindex" command - Fixes by Eric's reviewing comments, thanks. 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. 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. For Convenience of testing, my test case based on Andreas's patch series: [PATCH qom-next 0/4] qom: HMP commands to replace info qtree http://thread.gmane.org/gmane.comp.emulators.qemu/271513 However, there is no direct relation with this bootindex patch series. This series based on my patch posted yestoday: [PATCH v2 0/9] virtio: fix virtio child recount in transports http://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01601.html ./qemu-system-x86_64 -enable-kvm -m 4096 -smp 4 -name redhat6.2 -drive \ file=/home/win7_32_2U,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/rhel-server-7.0-x86_64-dvd.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 \ -drive file=/mnt/sdb/gonglei/image/virtio-win-1.5.3.vfd,if=none,id=drive-fdc0-0-0,format=raw \ -device isa-fdc,driveA=drive-fdc0-0-0,bootindexA=5,id=floppy1 -qmp unix:/tmp/qmp,server,nowait \ -monitor stdio -netdev type=user,id=net1 -device e1000,netdev=net1,bootindex=2,id=nic \ -boot menu=on -device virtio-scsi-pci,id=scsi0 -drive file=/home/suse11_sp3_32,if=none,\ id=drive-scsi0-0-0-0,format=raw,cache=none,aio=native \ -device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,drive=drive-scsi0-0-0-0,id=scsi0-0-0-0,bootindex=8 QEMU 2.1.50 monitor - type 'help' for more information (qemu) qom-get nic1 bootindex 3 (0x3) (qemu) qom-set nic1 bootindex 3 The bootindex 3 has already been used (qemu) qom-set nic1 bootindex 0 (qemu) qom-set floppy1 bootindexA 3 (qemu) system_reset (qemu) qom-get nic1 bootindex 0 (0x0) (qemu) qom-get scsi0-0-0-0 bootindex 8 (0x8) (qemu) qom-set scsi0-0-0-0 bootindex 0 The bootindex 0 has already been used (qemu) qom-set nic1 bootindex -1 (qemu) qom-set scsi0-0-0-0 bootindex 0 (qemu) qom-get scsi0-0-0-0 bootindex 0 (0x0) (qemu) Gonglei (30): bootdevice: move bootdevice related code to new file bootdevice.c bootindex: add check bootindex function bootindex: add del_boot_device_path function fw_cfg: add fw_cfg_machine_reset function bootindex: rework add_boot_device_path function bootindex: support to set a existent device's bootindex to -1 bootindex: add a setter/getter functions wrapper for bootindex property virtio-net: add bootindex to qom property e1000: add bootindex to qom property eepro100: add bootindex to qom property ne2000: add bootindex to qom property pcnet: add bootindex to qom property rtl8139: add bootindex to qom property spapr_lian: add bootindex to qom property vmxnet3: add bootindex to qom property usb-net: add bootindex to qom property net: remove bootindex property from qdev to qom virtio-net: alias bootindex property explicitly for virt-net-pci/ccw/s390 host-libusb: remove bootindex property from qdev to qom pci-assign: remove bootindex property from qdev to qom vfio: remove bootindex property from qdev to qom redirect: remove bootindex property from qdev to qom isa-fdc: remove bootindexA/B property from qdev to qom scsi: add bootindex to qom property ide: add bootindex to qom property virtio-blk: add bootindex to qom property block: remove bootindex property from qdev to qom ide: add calling add_boot_device_patch in bootindex setter function bootindex: move calling add_boot_device_patch to bootindex setter function bootindex: delete bootindex when device is removed Makefile.target | 2 +- bootdevice.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ hw/block/fdc.c | 18 ++- hw/block/virtio-blk.c | 5 +- hw/i386/kvm/pci-assign.c | 14 ++- hw/ide/qdev.c | 47 ++++++++ hw/misc/vfio.c | 13 ++- hw/net/e1000.c | 12 +- hw/net/eepro100.c | 13 ++- hw/net/lance.c | 12 ++ hw/net/ne2000.c | 14 ++- hw/net/pcnet-pci.c | 12 ++ hw/net/pcnet.c | 2 - hw/net/pcnet.h | 1 - hw/net/rtl8139.c | 12 +- hw/net/spapr_llan.c | 12 +- hw/net/virtio-net.c | 5 +- hw/net/vmxnet3.c | 10 +- hw/nvram/fw_cfg.c | 55 ++++++++- hw/s390x/s390-virtio-bus.c | 2 + hw/s390x/virtio-ccw.c | 2 + hw/scsi/scsi-bus.c | 11 ++ hw/scsi/scsi-disk.c | 2 - hw/scsi/scsi-generic.c | 4 - hw/usb/dev-network.c | 12 +- hw/usb/host-libusb.c | 13 ++- hw/usb/redirect.c | 13 ++- hw/virtio/virtio-pci.c | 2 + include/hw/block/block.h | 1 - include/hw/nvram/fw_cfg.h | 2 + include/net/net.h | 3 +- include/sysemu/sysemu.h | 6 + vl.c | 118 +------------------ 33 files changed, 562 insertions(+), 165 deletions(-) create mode 100644 bootdevice.c -- 1.7.12.4