Generate the example for the iSCSI auth/password-secret similar to what's done for RBD. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/util/virstoragefile.c | 30 ++++++++++++++++++++++++++++++ tests/virstoragetest.c | 15 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 39cda9c89..38aa77f44 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -2937,10 +2937,13 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, const char *transport = virJSONValueObjectGetString(json, "transport"); const char *portal = virJSONValueObjectGetString(json, "portal"); const char *target = virJSONValueObjectGetString(json, "target"); + const char *user = virJSONValueObjectGetString(json, "user"); + const char *secret = virJSONValueObjectGetString(json, "password-secret"); const char *uri; char *port; unsigned int lun = 0; char *fulltarget = NULL; + virStorageAuthDefPtr authdef = NULL; int ret = -1; /* legacy URI based syntax passed via 'filename' option */ @@ -2993,10 +2996,37 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, VIR_STEAL_PTR(src->path, fulltarget); + if (user) { + if (!secret) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing 'password-secret' in iSCSI backing " + "definition for user '%s'"), user); + goto cleanup; + } + + /* formulate authdef for src->auth */ + if (VIR_ALLOC(authdef) < 0) + goto cleanup; + + if (VIR_STRDUP(authdef->username, user) < 0) + goto cleanup; + + if (VIR_STRDUP(authdef->secrettype, + virSecretUsageTypeToString(VIR_SECRET_USAGE_TYPE_ISCSI)) < 0) + goto cleanup; + src->auth = authdef; + authdef = NULL; + + /* Cannot formulate a secretType (eg, usage or uuid) given + * what is provided. + */ + } + ret = 0; cleanup: VIR_FREE(fulltarget); + virStorageAuthDefFree(authdef); return ret; } diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 46d12c0e6..1d3fc36c3 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1577,6 +1577,21 @@ mymain(void) "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n" " <host name='test.org' port='1234'/>\n" "</source>\n"); + TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\"," + "\"transport\":\"tcp\"," + "\"portal\":\"test.org:1234\"," + "\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-auth.target\"," + "\"lun\":6," + "\"user\":\"myname\"," + "\"password-secret\":\"virtio-disk1-secret0\"" + "}" + "}", + "<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-auth.target/6'>\n" + " <host name='test.org' port='1234'/>\n" + " <auth username='myname'>\n" + " <secret type='iscsi'/>\n" + " </auth>\n" + "</source>\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"sheepdog\"," "\"vdi\":\"test\"," "\"server\":{ \"type\":\"inet\"," -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list