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

vz: introduce vzsdk disk id function

Our intention is to use disk bus and disk target name pair
as disk id instead of name returned by PrlVmDev_GetFriendlyName.
We already have the code that extracts this pair from vzsdk
data. Let's factor it out into a function.
Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
上级 3583e75d
......@@ -485,6 +485,45 @@ prlsdkAddDomainVideoInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
return -1;
}
static int
prlsdkGetDiskId(PRL_HANDLE disk, bool isCt, int *bus, char **dst)
{
PRL_RESULT pret;
PRL_UINT32 pos, ifType;
pret = PrlVmDev_GetStackIndex(disk, &pos);
prlsdkCheckRetExit(pret, -1);
/* Let physical devices added to CT look like SATA disks */
if (isCt) {
ifType = PMS_SATA_DEVICE;
} else {
pret = PrlVmDev_GetIfaceType(disk, &ifType);
prlsdkCheckRetExit(pret, -1);
}
switch (ifType) {
case PMS_IDE_DEVICE:
*bus = VIR_DOMAIN_DISK_BUS_IDE;
*dst = virIndexToDiskName(pos, "hd");
break;
case PMS_SCSI_DEVICE:
*bus = VIR_DOMAIN_DISK_BUS_SCSI;
*dst = virIndexToDiskName(pos, "sd");
break;
case PMS_SATA_DEVICE:
*bus = VIR_DOMAIN_DISK_BUS_SATA;
*dst = virIndexToDiskName(pos, "sd");
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown disk bus: %X"), ifType);
return -1;
}
return 0;
}
static int
prlsdkGetDiskInfo(vzDriverPtr driver,
PRL_HANDLE prldisk,
......@@ -495,9 +534,8 @@ prlsdkGetDiskInfo(vzDriverPtr driver,
char *buf = NULL;
PRL_RESULT pret;
PRL_UINT32 emulatedType;
PRL_UINT32 ifType;
PRL_UINT32 pos;
virDomainDeviceDriveAddressPtr address;
int busIdx, devIdx;
int ret = -1;
pret = PrlVmDev_GetEmulatedType(prldisk, &emulatedType);
......@@ -530,50 +568,17 @@ prlsdkGetDiskInfo(vzDriverPtr driver,
if (virDomainDiskSetSource(disk, buf) < 0)
goto cleanup;
/* Let physical devices added to CT look like SATA disks */
if (isCt) {
ifType = PMS_SATA_DEVICE;
} else {
pret = PrlVmDev_GetIfaceType(prldisk, &ifType);
prlsdkCheckRetGoto(pret, cleanup);
}
pret = PrlVmDev_GetStackIndex(prldisk, &pos);
prlsdkCheckRetGoto(pret, cleanup);
address = &disk->info.addr.drive;
switch (ifType) {
case PMS_IDE_DEVICE:
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
disk->dst = virIndexToDiskName(pos, "hd");
address->bus = pos / 2;
address->target = 0;
address->unit = pos % 2;
break;
case PMS_SCSI_DEVICE:
disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
disk->dst = virIndexToDiskName(pos, "sd");
address->bus = 0;
address->target = 0;
address->unit = pos;
break;
case PMS_SATA_DEVICE:
disk->bus = VIR_DOMAIN_DISK_BUS_SATA;
disk->dst = virIndexToDiskName(pos, "sd");
address->bus = 0;
address->target = 0;
address->unit = pos;
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown disk bus: %X"), ifType);
if (prlsdkGetDiskId(prldisk, isCt, &disk->bus, &disk->dst) < 0)
goto cleanup;
break;
}
if (!disk->dst)
if (virDiskNameToBusDeviceIndex(disk, &busIdx, &devIdx) < 0)
goto cleanup;
address = &disk->info.addr.drive;
address->bus = busIdx;
address->target = 0;
address->unit = devIdx;
disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册