提交 a7ed488d 编写于 作者: D Dmitry Guryanov 提交者: Peter Krempa

parallels: add cdroms support

Get cdrom devices list from parallels server in
prlsdkLoadDomains and add ability to define a domain
with cdroms.
Signed-off-by: NDmitry Guryanov <dguryanov@parallels.com>
上级 038a5a53
......@@ -452,7 +452,8 @@ prlsdkAddDomainVideoInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
static int
prlsdkGetDiskInfo(PRL_HANDLE prldisk,
virDomainDiskDefPtr disk)
virDomainDiskDefPtr disk,
bool isCdrom)
{
char *buf = NULL;
PRL_UINT32 buflen = 0;
......@@ -467,11 +468,19 @@ prlsdkGetDiskInfo(PRL_HANDLE prldisk,
prlsdkCheckRetGoto(pret, cleanup);
if (emulatedType == PDT_USE_IMAGE_FILE) {
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE);
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_PLOOP);
if (isCdrom)
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_AUTO);
else
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_PLOOP);
} else {
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
}
if (isCdrom)
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
else
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
pret = PrlVmDev_GetFriendlyName(prldisk, NULL, &buflen);
prlsdkCheckRetGoto(pret, cleanup);
......@@ -549,7 +558,7 @@ prlsdkAddDomainHardDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
if (!(disk = virDomainDiskDefNew()))
goto error;
if (prlsdkGetDiskInfo(hdd, disk) < 0)
if (prlsdkGetDiskInfo(hdd, disk, false) < 0)
goto error;
PrlHandle_Free(hdd);
......@@ -568,6 +577,43 @@ prlsdkAddDomainHardDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
return -1;
}
static int
prlsdkAddDomainOpticalDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
{
PRL_RESULT pret;
PRL_UINT32 cdromsCount;
PRL_UINT32 i;
PRL_HANDLE cdrom = PRL_INVALID_HANDLE;
virDomainDiskDefPtr disk = NULL;
pret = PrlVmCfg_GetOpticalDisksCount(sdkdom, &cdromsCount);
prlsdkCheckRetGoto(pret, error);
for (i = 0; i < cdromsCount; ++i) {
pret = PrlVmCfg_GetOpticalDisk(sdkdom, i, &cdrom);
prlsdkCheckRetGoto(pret, error);
if (!(disk = virDomainDiskDefNew()))
goto error;
if (prlsdkGetDiskInfo(cdrom, disk, true) < 0)
goto error;
PrlHandle_Free(cdrom);
cdrom = PRL_INVALID_HANDLE;
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
goto error;
}
return 0;
error:
PrlHandle_Free(cdrom);
virDomainDiskDefFree(disk);
return -1;
}
static int
prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt)
{
......@@ -787,6 +833,9 @@ prlsdkAddDomainHardware(PRL_HANDLE sdkdom, virDomainDefPtr def)
if (prlsdkAddDomainHardDisksInfo(sdkdom, def) < 0)
goto error;
if (prlsdkAddDomainOpticalDisksInfo(sdkdom, def) < 0)
goto error;
if (prlsdkAddDomainNetInfo(sdkdom, def) < 0)
goto error;
......@@ -2091,9 +2140,11 @@ static int prlsdkCheckNetUnsupportedParams(virDomainNetDefPtr net)
static int prlsdkCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
{
if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK &&
disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only hard disks are supported "
_("Only hard disks and cdroms are supported "
"supported by parallels driver."));
return -1;
}
......@@ -2399,7 +2450,10 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk)
if (prlsdkCheckDiskUnsupportedParams(disk) < 0)
return -1;
pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_HARD_DISK, &sdkdisk);
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK)
pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_HARD_DISK, &sdkdisk);
else
pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_OPTICAL_DISK, &sdkdisk);
prlsdkCheckRetGoto(pret, cleanup);
pret = PrlVmDev_SetEnabled(sdkdisk, 1);
......@@ -2409,7 +2463,9 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk)
prlsdkCheckRetGoto(pret, cleanup);
if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
if (virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_PLOOP) {
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_PLOOP) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid disk format: %d"), disk->src->type);
goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册