From: Nikolay Shirokovskiy <nshirokovs...@virtuozzo.com>

vz sdk supports setting serial number only for disk devices.
Getting serial upon cdrom(for example) is error however
setting is just ignored. Let's check for disk device
explicitly for clarity in both cases.

Setting serial number for other devices is ignored
with an info note just as before.

We need usual conversion from "" to NULL in direction
vz sdk -> libvirt, because "" is not valid for libvirt
and "" means unspecifiend in vz sdk which is NULL for libvirt.

Signed-off-by: Nikolay Shirokovskiy <nshirokovs...@virtuozzo.com>
Signed-off-by: Maxim Nestratov <mnestra...@virtuozzo.com>
---
 src/vz/vz_sdk.c   | 21 +++++++++++++++++++++
 src/vz/vz_utils.c |  6 +++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 8178d3b..e14caa5 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -590,6 +590,7 @@ prlsdkGetDiskInfo(vzDriverPtr driver,
                   bool isCt)
 {
     char *buf = NULL;
+    char *serial = NULL;
     PRL_RESULT pret;
     PRL_UINT32 emulatedType;
     virDomainDeviceDriveAddressPtr address;
@@ -626,6 +627,20 @@ prlsdkGetDiskInfo(vzDriverPtr driver,
     if (*buf != '\0' && virDomainDiskSetSource(disk, buf) < 0)
         goto cleanup;
 
+    if (!isCdrom) {
+        serial = prlsdkGetStringParamVar(PrlVmDevHd_GetSerialNumber, prldisk);
+        if (serial) {
+            if (virSafeSerialParamValue(serial) < 0)
+                goto cleanup;
+
+            if (*serial == '\0')
+                VIR_FREE(serial);
+            else
+                disk->serial = serial;
+            serial = NULL;
+        }
+    }
+
     if (prlsdkGetDiskId(prldisk, &disk->bus, &disk->dst) < 0)
         goto cleanup;
 
@@ -646,6 +661,7 @@ prlsdkGetDiskInfo(vzDriverPtr driver,
 
  cleanup:
     VIR_FREE(buf);
+    VIR_FREE(serial);
     return ret;
 }
 
@@ -3495,6 +3511,11 @@ static int prlsdkConfigureDisk(vzDriverPtr driver,
     pret = PrlVmDev_SetStackIndex(sdkdisk, idx);
     prlsdkCheckRetGoto(pret, cleanup);
 
+    if (devType == PDE_HARD_DISK) {
+        pret = PrlVmDevHd_SetSerialNumber(sdkdisk, disk->serial);
+        prlsdkCheckRetGoto(pret, cleanup);
+    }
+
     return 0;
  cleanup:
     PrlHandle_Free(sdkdisk);
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index eaf09f2..81429d2 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -323,9 +323,9 @@ vzCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
         return -1;
     }
 
-    if (disk->serial) {
-        VIR_INFO("%s", _("Setting disk serial number is not "
-                         "supported by vz driver."));
+    if (disk->serial && disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
+        VIR_INFO("%s", _("Setting disk serial number is "
+                         "supported only for disk devices."));
     }
 
     if (disk->wwn) {
-- 
2.4.11

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

Reply via email to