Re: [PATCH v3 11/12] parallels: add cdroms support

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

 



18.11.2014 16:17, Dmitry Guryanov пишет:
Get cdrom devices list from parallels server in
prlsdkLoadDomains and add ability to define a domain
with cdroms.

Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx>
---
  src/parallels/parallels_sdk.c | 70 ++++++++++++++++++++++++++++++++++++++-----
  1 file changed, 63 insertions(+), 7 deletions(-)

diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index d1a8ebf..85193f1 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -446,7 +446,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;
@@ -461,11 +462,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);
@@ -543,7 +552,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);
@@ -563,6 +572,43 @@ prlsdkAddDomainHardDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
  }
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)
  {
      char macstr[VIR_MAC_STRING_BUFLEN];
@@ -781,6 +827,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;
@@ -2081,9 +2130,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;
      }
@@ -2393,7 +2444,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);
@@ -2403,7 +2457,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;
ack

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]