[libvirt] [PATCH] virsh: Enhance the detailed output of domblklist for networked source
Lin Ma
lma at suse.com
Thu Sep 3 12:54:37 UTC 2015
在 2015年09月02日 23:59, Michal Privoznik 写道:
> On 31.08.2015 05:13, Lin Ma wrote:
>> Format & Output more detailed information about networked source
>>
>> e.g: The output without the patch:
>> $ virsh domblklist $DOMAIN --details
>> Type Device Target Source
>> ------------------------------------------------
>> network disk vda test-pool/image
>> network disk vdb iqn.2015-08.org.example:sn01/0
>> network disk vdc /image.raw
>> network disk vdd -
>> network disk vde -
>> network disk vdf image1
>> network disk vdg test-volume/image.raw
>>
>> The output with the patch:
>> $ virsh domblklist $DOMAIN --details
>> Type Device Target Source
>> ------------------------------------------------
>> network disk vda rbd://monitor1.example.org:6321/test-pool/image
>> network disk vdb iscsi://192.168.124.200:3260/iqn.2015-08.org.example:sn01/0
>> network disk vdc http://192.168.124.200:80/image.raw
>> network disk vdd nbd+unix:///var/run/nbdsock
>> network disk vde nbd://192.168.124.200:12345
>> network disk vdf sheepdog://192.168.124.200:6000/image1
>> network disk vdg gluster://192.168.124.200/test-volume/image.raw
>>
>> Signed-off-by: Lin Ma <lma at suse.com>
>> ---
>> tools/virsh-domain-monitor.c | 60 ++++++++++++++++++++++++++++++++++++++++----
>> 1 file changed, 55 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
>> index 340a8e2..9188b42 100644
>> --- a/tools/virsh-domain-monitor.c
>> +++ b/tools/virsh-domain-monitor.c
>> @@ -518,6 +518,12 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
>> for (i = 0; i < ndisks; i++) {
>> char *type = NULL;
>> char *device = NULL;
>> + char *protocol = NULL;
>> + char *transport = NULL;
>> + char *host_name = NULL;
>> + char *host_port = NULL;
>> + char *socket = NULL;
>> + char *name = NULL;
>> char *target;
>> char *source;
>>
>> @@ -541,11 +547,55 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
>> VIR_FREE(device);
>> goto cleanup;
>> }
>> - source = virXPathString("string(./source/@file"
>> - "|./source/@dev"
>> - "|./source/@dir"
>> - "|./source/@name"
>> - "|./source/@volume)", ctxt);
>> + if (type && STREQ(type, "network")) {
>> + protocol = virXPathString("string(./source/@protocol)", ctxt);
>> + name = virXPathString("string(./source/@name)", ctxt);
>> + transport = virXPathString("string(./source/host/@transport)", ctxt);
>> + socket = virXPathString("string(./source/host/@socket)", ctxt);
>> + host_name = virXPathString("string(./source/host/@name)", ctxt);
>> + host_port = virXPathString("string(./source/host/@port)", ctxt);
>> + if (VIR_STRDUP(source, protocol) < 0)
>> + goto cleanup;
>> + VIR_FREE(protocol);
>> + if(transport) {
>> + if(virAsprintf(&source, "%s+%s", source, transport) < 0)
> This will leak the original @source. I think we need to use virBuffer
> for this ...
>
>> + goto cleanup;
> Moreover, if one of these virAsprintf()-s fails, the rest of strings is
> leaked.
>
>> + VIR_FREE(transport);
>> + }
>> + if(virAsprintf(&source, "%s://", source) < 0)
>> + goto cleanup;
>> + if(host_name) {
>> + if(virAsprintf(&source, "%s%s", source, host_name) < 0)
>> + goto cleanup;
>> + VIR_FREE(host_name);
>> + if(host_port) {
>> + if(virAsprintf(&source, "%s:%s", source, host_port) < 0)
>> + goto cleanup;
>> + VIR_FREE(host_port);
>> + }
>> + }
>> + if(name) {
>> + if(!STRPREFIX(name, "/"))
>> + if(virAsprintf(&source, "%s/", source) < 0)
>> + goto cleanup;
>> + if(virAsprintf(&source, "%s%s", source, name) < 0)
>> + goto cleanup;
>> + VIR_FREE(name);
>> + } else if(socket) {
>> + if(!STRPREFIX(socket, "/"))
>> + if(virAsprintf(&source, "%s/", source) < 0)
>> + goto cleanup;
>> + if(virAsprintf(&source, "%s%s", source, socket) < 0)
>> + goto cleanup;
>> + VIR_FREE(socket);
>> + }
>> + } else {
>> + source = virXPathString("string(./source/@file"
>> + "|./source/@dev"
>> + "|./source/@dir"
>> + "|./source/@name"
>> + "|./source/@volume)", ctxt);
>> + }
>> if (details) {
>> vshPrint(ctl, "%-10s %-10s %-10s %s\n", type, device,
>> target, source ? source : "-");
>>
> Let me respin the patches:
>
> https://www.redhat.com/archives/libvir-list/2015-September/msg00053.html
Thanks for your time!
More information about the libvir-list
mailing list