mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 10:35:20 +00:00
util: storage: Add JSON parser for new options in iSCSI protocol
Starting from qemu 2.9, more granular options are supported. Add parser for the relevant bits. With this patch libvirt is able to parse the host and target IQN of from the JSON pseudo-protocol specification. This corresponds to BlockdevOptionsIscsi in qemu qapi.
This commit is contained in:
parent
299aff7e0c
commit
b24bc54080
@ -2935,18 +2935,73 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
|
|||||||
virJSONValuePtr json,
|
virJSONValuePtr json,
|
||||||
int opaque ATTRIBUTE_UNUSED)
|
int opaque ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
|
const char *transport = virJSONValueObjectGetString(json, "transport");
|
||||||
|
const char *portal = virJSONValueObjectGetString(json, "portal");
|
||||||
|
const char *target = virJSONValueObjectGetString(json, "target");
|
||||||
const char *uri;
|
const char *uri;
|
||||||
|
char *port;
|
||||||
|
unsigned int lun = 0;
|
||||||
|
char *fulltarget = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
/* legacy URI based syntax passed via 'filename' option */
|
/* legacy URI based syntax passed via 'filename' option */
|
||||||
if ((uri = virJSONValueObjectGetString(json, "filename")))
|
if ((uri = virJSONValueObjectGetString(json, "filename")))
|
||||||
return virStorageSourceParseBackingJSONUriStr(src, uri,
|
return virStorageSourceParseBackingJSONUriStr(src, uri,
|
||||||
VIR_STORAGE_NET_PROTOCOL_ISCSI);
|
VIR_STORAGE_NET_PROTOCOL_ISCSI);
|
||||||
|
|
||||||
/* iSCSI currently supports only URI syntax passed in as filename */
|
src->type = VIR_STORAGE_TYPE_NETWORK;
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
|
||||||
_("missing iSCSI URI in JSON backing volume definition"));
|
|
||||||
|
|
||||||
return -1;
|
if (VIR_ALLOC(src->hosts) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
src->nhosts = 1;
|
||||||
|
|
||||||
|
if (STRNEQ_NULLABLE(transport, "tcp")) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("only TCP transport is supported for iSCSI volumes"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
|
||||||
|
|
||||||
|
if (!portal) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("missing 'portal' address in iSCSI backing definition"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!target) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("missing 'target' in iSCSI backing definition"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_STRDUP(src->hosts->name, portal) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if ((port = strchr(src->hosts->name, ':'))) {
|
||||||
|
if (VIR_STRDUP(src->hosts->port, port + 1) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (strlen(src->hosts->port) == 0)
|
||||||
|
VIR_FREE(src->hosts->port);
|
||||||
|
|
||||||
|
*port = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
ignore_value(virJSONValueObjectGetNumberUint(json, "lun", &lun));
|
||||||
|
|
||||||
|
if (virAsprintf(&fulltarget, "%s/%u", target, lun) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(src->path, fulltarget);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(fulltarget);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1502,6 +1502,25 @@ mymain(void)
|
|||||||
"\"driver\": \"file\","
|
"\"driver\": \"file\","
|
||||||
"\"filename\": \"/path/to/file\" } } }",
|
"\"filename\": \"/path/to/file\" } } }",
|
||||||
"<source file='/path/to/file'/>\n");
|
"<source file='/path/to/file'/>\n");
|
||||||
|
TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\","
|
||||||
|
"\"transport\":\"tcp\","
|
||||||
|
"\"portal\":\"test.org\","
|
||||||
|
"\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\""
|
||||||
|
"}"
|
||||||
|
"}",
|
||||||
|
"<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/0'>\n"
|
||||||
|
" <host name='test.org'/>\n"
|
||||||
|
"</source>\n");
|
||||||
|
TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\","
|
||||||
|
"\"transport\":\"tcp\","
|
||||||
|
"\"portal\":\"test.org:1234\","
|
||||||
|
"\"target\":\"iqn.2016-12.com.virttest:emulated-iscsi-noauth.target\","
|
||||||
|
"\"lun\":6"
|
||||||
|
"}"
|
||||||
|
"}",
|
||||||
|
"<source protocol='iscsi' name='iqn.2016-12.com.virttest:emulated-iscsi-noauth.target/6'>\n"
|
||||||
|
" <host name='test.org' port='1234'/>\n"
|
||||||
|
"</source>\n");
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
/* Final cleanup */
|
/* Final cleanup */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user