Actually using disk PrlVmDev_GetFriendlyName as id on detaching volumes is not a problem. We can only detach hard disks and these can not have empty friendly names. But upcoming update device functionality for cdroms can not use disk source as id at all as update operation typically change this same source value. Thus we will need to use cdrom bus and cdrom target name as cdrom id. So in attempt to use same id scheme for all purpuses lets fix hard disk detach function to use new id. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/vz/vz_sdk.c | 114 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 423b20b..e85c30e 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -3384,6 +3384,47 @@ static int prlsdkAddDisk(vzConnPtr privconn, return ret; } +static PRL_HANDLE +prlsdkGetDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk, bool isCt) +{ + PRL_RESULT pret; + PRL_UINT32 hddCount; + size_t i; + PRL_HANDLE hdd = PRL_INVALID_HANDLE; + int bus; + char *dst = NULL; + + pret = PrlVmCfg_GetHardDisksCount(sdkdom, &hddCount); + prlsdkCheckRetGoto(pret, error); + + for (i = 0; i < hddCount; ++i) { + pret = PrlVmCfg_GetHardDisk(sdkdom, i, &hdd); + prlsdkCheckRetGoto(pret, error); + + if (prlsdkGetDiskId(hdd, isCt, &bus, &dst) < 0) + goto error; + + if (disk->bus == bus && STREQ(disk->dst, dst)) { + VIR_FREE(dst); + return hdd; + } + + PrlHandle_Free(hdd); + hdd = PRL_INVALID_HANDLE; + VIR_FREE(dst); + } + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("No disk with bus '%s' and target '%s'"), + virDomainDiskBusTypeToString(disk->bus), disk->dst); + return PRL_INVALID_HANDLE; + + error: + VIR_FREE(dst); + PrlHandle_Free(hdd); + return PRL_INVALID_HANDLE; +} + int prlsdkAttachVolume(vzConnPtr privconn, virDomainObjPtr dom, @@ -3410,78 +3451,35 @@ prlsdkAttachVolume(vzConnPtr privconn, return ret; } -static int -prlsdkGetDiskIndex(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk) -{ - int idx = -1; - char *buf = NULL; - PRL_UINT32 buflen = 0; - PRL_RESULT pret; - PRL_UINT32 hddCount; - PRL_UINT32 i; - PRL_HANDLE hdd = PRL_INVALID_HANDLE; - - pret = PrlVmCfg_GetHardDisksCount(sdkdom, &hddCount); - prlsdkCheckRetGoto(pret, cleanup); - - for (i = 0; i < hddCount; ++i) { - - pret = PrlVmCfg_GetHardDisk(sdkdom, i, &hdd); - prlsdkCheckRetGoto(pret, cleanup); - - buflen = 0; - pret = PrlVmDev_GetFriendlyName(hdd, 0, &buflen); - prlsdkCheckRetGoto(pret, cleanup); - - if (VIR_ALLOC_N(buf, buflen) < 0) - goto cleanup; - - pret = PrlVmDev_GetFriendlyName(hdd, buf, &buflen); - prlsdkCheckRetGoto(pret, cleanup); - - if (STRNEQ(disk->src->path, buf)) { - - PrlHandle_Free(hdd); - hdd = PRL_INVALID_HANDLE; - VIR_FREE(buf); - continue; - } - - VIR_FREE(buf); - idx = i; - break; - } - - cleanup: - PrlHandle_Free(hdd); - return idx; -} - int prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk) { - int ret = -1, idx; + int ret = -1; vzDomObjPtr privdom = dom->privateData; PRL_HANDLE job = PRL_INVALID_HANDLE; + PRL_HANDLE sdkdisk; + PRL_RESULT pret; - idx = prlsdkGetDiskIndex(privdom->sdkdom, disk); - if (idx < 0) + sdkdisk = prlsdkGetDisk(privdom->sdkdom, disk, IS_CT(dom->def)); + if (sdkdisk == PRL_INVALID_HANDLE) goto cleanup; job = PrlVm_BeginEdit(privdom->sdkdom); if (PRL_FAILED(waitJob(job))) goto cleanup; - ret = prlsdkDelDisk(privdom->sdkdom, idx); - if (ret == 0) { - job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE); - if (PRL_FAILED(waitJob(job))) { - ret = -1; - goto cleanup; - } - } + pret = PrlVmDev_Remove(sdkdisk); + prlsdkCheckRetGoto(pret, cleanup); + + job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE); + if (PRL_FAILED(waitJob(job))) + goto cleanup; + + ret = 0; cleanup: + + PrlHandle_Free(sdkdisk); return ret; } -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list