render / rpms / libvirt

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