[libvirt] [PATCH 8/8] qemu: support updating disk with boot index

John Ferlan jferlan at redhat.com
Tue Feb 3 01:41:52 UTC 2015



On 01/05/2015 02:29 AM, Wang Rui wrote:
> QEMU supported to set device's boot index online recently(since QEMU 2.2.0).
> This patch implements the disk's boot index update lively.

Description needs some more beef... The usage of "update lively" doesn't
translate well.  I think you're talking about being able to make an
'online update' of a disk's bootIndex.  Essentially this allows us to
change an existing from "2" to "3" perhaps and then add a new "2" - is
that correct?   What happens if you have 1, 2, 3 ... try to change 3 to
2 - will be an error?  The clearing of index in order to remove it needs
to be made clearer on the formatdomain.html.in and/or virsh.pod.

All this needs to be done via XML editing - prone to errors...  Perhaps
consider adding a virsh option... Makes it a whole lot easier to adjust
things rather than attempting to generate XML to modify things. Trying
to figure out the magic incantation required to "remove" the index
"live" by only providing some XML to a virsh command can be a challenge.
Sure you understand it and I'm beginning to, but how would one "use"
this feature is not described anywhere.

John


> 
> If boot order is not specified in the new xml, we take it as canceling boot
> index. So pass "value":-1 to qmp command("qom-set") to cancel boot index.
> 
> Signed-off-by: Wang Rui <moon.wangrui at huawei.com>
> Signed-off-by: Zhou Yimin <zhouyimin at huawei.com>
> ---
>  src/qemu/qemu_driver.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 55 insertions(+), 9 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 673d8a6..9615fe4 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -7048,6 +7048,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
>  {
>      virDomainDiskDefPtr disk = dev->data.disk;
>      virDomainDiskDefPtr orig_disk = NULL;
> +    int oldBootIndex = -1;
>      int ret = -1;
>  
>      if (virStorageTranslateDiskSourcePool(conn, disk) < 0)
> @@ -7056,16 +7057,25 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
>      if (qemuDomainDetermineDiskChain(driver, vm, disk, false, true) < 0)
>          goto end;
>  
> +    if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
> +                                                   disk->bus, disk->dst))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("No device with bus '%s' and target '%s'"),
> +                       virDomainDiskBusTypeToString(disk->bus),
> +                       disk->dst);
> +        goto end;
> +    }
> +
>      switch (disk->device) {
>      case VIR_DOMAIN_DISK_DEVICE_CDROM:
>      case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
> -        if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
> -                                                       disk->bus, disk->dst))) {
> -            virReportError(VIR_ERR_INTERNAL_ERROR,
> -                           _("No device with bus '%s' and target '%s'"),
> -                           virDomainDiskBusTypeToString(disk->bus),
> -                           disk->dst);
> -            goto end;
> +        if (orig_disk->info.bootIndex != disk->info.bootIndex) {
> +            oldBootIndex = orig_disk->info.bootIndex;
> +            if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
> +                                          disk->info.bootIndex ?
> +                                          disk->info.bootIndex : -1) < 0)
> +                goto end;
> +            orig_disk->info.bootIndex = disk->info.bootIndex;
>          }
>  
>          /* Add the new disk src into shared disk hash table */
> @@ -7075,6 +7085,16 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
>          if (qemuDomainChangeEjectableMedia(driver, conn, vm,
>                                             orig_disk, dev->data.disk->src, force) < 0) {
>              ignore_value(qemuRemoveSharedDisk(driver, dev->data.disk, vm->def->name));
> +
> +            /* Change media failed. Boot index should be changed back to original. */
> +            if (oldBootIndex >= 0) {
> +                if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
> +                                              oldBootIndex ? oldBootIndex : -1) < 0) {
> +                    VIR_WARN("Change Boot index back to original failed");
> +                    goto end;
> +                }
> +                orig_disk->info.bootIndex = oldBootIndex;
> +            }
>              goto end;
>          }
>  
> @@ -7082,6 +7102,22 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
>          ret = 0;
>          break;
>  
> +    case VIR_DOMAIN_DISK_DEVICE_DISK:
> +        if (orig_disk->info.bootIndex != disk->info.bootIndex) {
> +            if (qemuDomainChangeBootIndex(driver, vm, &orig_disk->info,
> +                                          disk->info.bootIndex ?
> +                                          disk->info.bootIndex : -1) < 0)
> +                goto end;
> +            orig_disk->info.bootIndex = disk->info.bootIndex;
> +            ret = 0;
> +            break;
> +        } else {
> +            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                           _("disk bus '%s' cannot be updated except boot index."),
> +                           virDomainDiskBusTypeToString(disk->bus));
> +            goto end;
> +        }
> +
>      default:
>          virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                         _("disk bus '%s' cannot be updated."),
> @@ -7413,8 +7449,17 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
>              return -1;
>          }
>          orig = vmdef->disks[pos];
> -        if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
> -            !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
> +        if (orig->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
> +            if (orig->info.bootIndex != disk->info.bootIndex) {
> +                orig->info.bootIndex = disk->info.bootIndex;
> +                break;
> +            } else {
> +                virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> +                               _("this disk doesn't support update except boot index"));
> +                return -1;
> +            }
> +        } else if (!(orig->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
> +                   !(orig->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)) {
>              virReportError(VIR_ERR_INVALID_ARG, "%s",
>                             _("this disk doesn't support update"));
>              return -1;
> @@ -7436,6 +7481,7 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
>              orig->src->format = disk->src->format;
>          disk->src->path = NULL;
>          orig->startupPolicy = disk->startupPolicy;
> +        orig->info.bootIndex = disk->info.bootIndex;
>          break;
>  
>      case VIR_DOMAIN_DEVICE_GRAPHICS:
> 




More information about the libvir-list mailing list