mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Switch the virsh XML generation to use virBuffer instead of virAsprintf
The code generating XML for storage pool source discovery is hardcoded to only allow a hostname and optional port number. Refactor this code to make it easier to add support for extra parameters. * tools/virsh.c: Refactor XML generator
This commit is contained in:
parent
1da8c5672f
commit
1bae28e49b
@ -5826,7 +5826,6 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
if (host) {
|
if (host) {
|
||||||
size_t hostlen = strlen(host);
|
size_t hostlen = strlen(host);
|
||||||
char *port = vshCommandOptString(cmd, "port", &found);
|
char *port = vshCommandOptString(cmd, "port", &found);
|
||||||
int ret;
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
port = strrchr(host, ':');
|
port = strrchr(host, ':');
|
||||||
if (port) {
|
if (port) {
|
||||||
@ -5836,23 +5835,18 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
port = NULL;
|
port = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret = port ?
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
virAsprintf(&srcSpec,
|
virBufferAddLit(&buf, "<source>\n");
|
||||||
"<source><host name='%.*s' port='%s'/></source>",
|
virBufferVSprintf(&buf, " <host name='%.*s'",(int)hostlen, host);
|
||||||
(int)hostlen, host, port) :
|
if (port)
|
||||||
virAsprintf(&srcSpec,
|
virBufferVSprintf(&buf, " port='%s'", port);
|
||||||
"<source><host name='%.*s'/></source>",
|
virBufferAddLit(&buf, "/>\n");
|
||||||
(int)hostlen, host);
|
virBufferAddLit(&buf, "</source>\n");
|
||||||
if (ret < 0) {
|
if (virBufferError(&buf)) {
|
||||||
switch (errno) {
|
vshError(ctl, "%s", _("Out of memory"));
|
||||||
case ENOMEM:
|
|
||||||
vshError(ctl, "%s", _("Out of memory"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
vshError(ctl, _("virAsprintf failed (errno %d)"), errno);
|
|
||||||
}
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
srcSpec = virBufferContentAndReset(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
|
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user