render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c1c534
From 9356d615ccbbb556a11d70a01941964b1af7d503 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <9356d615ccbbb556a11d70a01941964b1af7d503@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Wed, 31 Jan 2018 12:51:00 +0100
c1c534
Subject: [PATCH] util: storage: Parse 'lun' for iSCSI protocol from JSON as
c1c534
 string or number
c1c534
c1c534
While the QEMU QAPI schema describes 'lun' as a number, the code dealing
c1c534
with JSON strings does not strictly adhere to this schema and thus
c1c534
formats the number back as a string. Use the new helper to retrieve both
c1c534
possibilities.
c1c534
c1c534
Note that the formatting code is okay and qemu will accept it as an int.
c1c534
c1c534
Tweak also one of the test strings to verify that both formats work
c1c534
with libvirt.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1540290
c1c534
(cherry picked from commit f46d6e22f2dc352cd43480c1d148222f4e62b8e6)
c1c534
---
c1c534
 src/util/virstoragefile.c | 13 +++++--------
c1c534
 tests/virstoragetest.c    |  2 +-
c1c534
 2 files changed, 6 insertions(+), 9 deletions(-)
c1c534
c1c534
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
c1c534
index d1e356a121..69deaea7c5 100644
c1c534
--- a/src/util/virstoragefile.c
c1c534
+++ b/src/util/virstoragefile.c
c1c534
@@ -2966,10 +2966,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
c1c534
     const char *transport = virJSONValueObjectGetString(json, "transport");
c1c534
     const char *portal = virJSONValueObjectGetString(json, "portal");
c1c534
     const char *target = virJSONValueObjectGetString(json, "target");
c1c534
+    const char *lun = virJSONValueObjectGetStringOrNumber(json, "lun");
c1c534
     const char *uri;
c1c534
     char *port;
c1c534
-    unsigned int lun = 0;
c1c534
-    char *fulltarget = NULL;
c1c534
     int ret = -1;
c1c534
 
c1c534
     /* legacy URI based syntax passed via 'filename' option */
c1c534
@@ -2980,6 +2979,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
c1c534
     src->type = VIR_STORAGE_TYPE_NETWORK;
c1c534
     src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
c1c534
 
c1c534
+    if (!lun)
c1c534
+        lun = "0";
c1c534
+
c1c534
     if (VIR_ALLOC(src->hosts) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
@@ -3015,17 +3017,12 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
c1c534
         *port = '\0';
c1c534
     }
c1c534
 
c1c534
-    ignore_value(virJSONValueObjectGetNumberUint(json, "lun", &lun));
c1c534
-
c1c534
-    if (virAsprintf(&fulltarget, "%s/%u", target, lun) < 0)
c1c534
+    if (virAsprintf(&src->path, "%s/%s", target, lun) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-    VIR_STEAL_PTR(src->path, fulltarget);
c1c534
-
c1c534
     ret = 0;
c1c534
 
c1c534
  cleanup:
c1c534
-    VIR_FREE(fulltarget);
c1c534
     return ret;
c1c534
 }
c1c534
 
c1c534
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
c1c534
index bdd0829c21..b7f2eeb96d 100644
c1c534
--- a/tests/virstoragetest.c
c1c534
+++ b/tests/virstoragetest.c
c1c534
@@ -1572,7 +1572,7 @@ mymain(void)
c1c534
                                        "\"transport\":\"tcp\","
c1c534
                                        "\"portal\":\"test.org:1234\","
c1c534
                                        "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\","
c1c534
-                                       "\"lun\":6"
c1c534
+                                       "\"lun\":\"6\""
c1c534
                                       "}"
c1c534
                             "}",
c1c534
                        "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
c1c534
-- 
c1c534
2.16.1
c1c534