提交 c7ba6200 编写于 作者: N Nikolay Shirokovskiy 提交者: Maxim Nestratov

vz: fix detach disk to use new disk id

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: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
上级 bc5f2aab
......@@ -3335,6 +3335,47 @@ static int prlsdkAddDisk(vzDriverPtr driver,
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(vzDriverPtr driver,
virDomainObjPtr dom,
......@@ -3361,70 +3402,35 @@ prlsdkAttachVolume(vzDriverPtr driver,
return ret;
}
static int
prlsdkGetDiskIndex(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk)
{
int idx = -1;
char *buf = NULL;
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);
if (!(buf = prlsdkGetStringParamVar(PrlVmDev_GetFriendlyName, hdd)))
goto 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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册