[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCHv2 45/62] qemu: hotplug: Implement removable media change for -blockdev



[...]

> +static int
> +qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
> +                              virDomainObjPtr vm,
> +                              virDomainDiskDefPtr disk,
> +                              virStorageSourcePtr newsrc,
> +                              bool force)
> +{
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +    qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
> +    qemuHotplugDiskSourceDataPtr newbackend = NULL;
> +    qemuHotplugDiskSourceDataPtr oldbackend = NULL;
> +    virStorageSourcePtr oldsrc = disk->src;
> +    char *nodename = NULL;
> +    int rc;
> +    int ret = -1;
> +
> +    if (!virStorageSourceIsEmpty(disk->src) &&
> +        !(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, priv->qemuCaps)))
> +        goto cleanup;
> +
> +    disk->src = newsrc;
> +    if (!virStorageSourceIsEmpty(disk->src)) {
> +        if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk,
> +                                                              priv->qemuCaps)))
> +            goto cleanup;
> +
> +        if (qemuDomainDiskGetBackendAlias(disk, priv->qemuCaps, &nodename) < 0)

Coverity notes @nodename is leaked at cleanup:

John

BTW: Only 2 Coverity whines for a large series and you got rid of one of
my false positives by removing the detach->info.alias creation done in
qemuDomainDetachVirtioDiskDevice. Something similar I suppose could be
done for qemuDomainDetachControllerDevice using the same reasoning.


> +            goto cleanup;
> +    }
> +
> +    if (diskPriv->tray && disk->tray_status != VIR_DOMAIN_DISK_TRAY_OPEN) {
> +        qemuDomainObjEnterMonitor(driver, vm);
> +        rc = qemuMonitorBlockdevTrayOpen(priv->mon, diskPriv->backendQomName, force);
> +        if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
> +            goto cleanup;
> +
> +        if (!force && qemuHotplugWaitForTrayEject(vm, disk) < 0)
> +            goto cleanup;
> +    }
> +
> +    qemuDomainObjEnterMonitor(driver, vm);
> +
> +    rc = qemuMonitorBlockdevMediumRemove(priv->mon, diskPriv->backendQomName);
> +
> +    if (rc == 0 && oldbackend)
> +        qemuHotplugDiskSourceRemove(priv->mon, oldbackend);
> +
> +    if (newbackend && nodename) {
> +        if (rc == 0)
> +            rc = qemuHotplugDiskSourceAttach(priv->mon, newbackend);
> +
> +        if (rc == 0)
> +            rc = qemuMonitorBlockdevMediumInsert(priv->mon,
> +                                                 diskPriv->backendQomName,
> +                                                 nodename);
> +    }
> +
> +    if (rc == 0)
> +        rc = qemuMonitorBlockdevTrayClose(priv->mon, diskPriv->backendQomName);
> +
> +    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
> +        goto cleanup;
> +
> +    ret = 0;
> +
> + cleanup:
> +    qemuHotplugDiskSourceDataFree(newbackend);
> +    qemuHotplugDiskSourceDataFree(oldbackend);
> +    /* caller handles correct exchange of sources */
> +    disk->src = oldsrc;
> +    return ret;
> +}
> +
> +

[...]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]