[PATCH 1/4] vz: introduce vzsdk disk id function

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

 



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.
---
 src/vz/vz_sdk.c | 89 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 47 insertions(+), 42 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index c006517..423b20b 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -466,6 +466,45 @@ prlsdkAddDomainVideoInfo(PRL_HANDLE sdkdom, virDomainDefPtr def)
 }
 
 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(vzConnPtr privconn,
                   PRL_HANDLE prldisk,
                   virDomainDiskDefPtr disk,
@@ -476,9 +515,8 @@ prlsdkGetDiskInfo(vzConnPtr privconn,
     PRL_UINT32 buflen = 0;
     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);
@@ -517,50 +555,17 @@ prlsdkGetDiskInfo(vzConnPtr privconn,
     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;
-- 
1.8.3.1

--
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]