[libvirt] [PATCH 6/6] conf: Use virXMLFormatElement to format disk source network
John Ferlan
jferlan at redhat.com
Fri Sep 15 12:17:41 UTC 2017
On 09/15/2017 12:10 AM, Peter Krempa wrote:
> On Thu, Sep 14, 2017 at 14:03:10 -0400, John Ferlan wrote:
>> Commit id 'e02ff020cac' neglected to use the attrBuf and childBuf
>> in the virDomainDiskSourceFormatNetwork call.
>>
>> So make the necessary alterations to allow usage.
>>
>> Signed-off-by: John Ferlan <jferlan at redhat.com>
>> ---
>> src/conf/domain_conf.c | 34 ++++++++++++++--------------------
>> 1 file changed, 14 insertions(+), 20 deletions(-)
>>
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index 09c5bc1ae..a8771a3a4 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -21674,13 +21674,14 @@ virDomainSourceDefFormatSeclabel(virBufferPtr buf,
>>
>>
>> static int
>> -virDomainDiskSourceFormatNetwork(virBufferPtr buf,
>> +virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
>> + virBufferPtr childBuf,
>> virStorageSourcePtr src)
>> {
>> size_t n;
>> char *path = NULL;
>>
>> - virBufferAsprintf(buf, "<source protocol='%s'",
>> + virBufferAsprintf(attrBuf, " protocol='%s'",
>> virStorageNetProtocolTypeToString(src->protocol));
>>
>> if (src->volume) {
>> @@ -21688,36 +21689,29 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf,
>> return -1;
>> }
>>
>> - virBufferEscapeString(buf, " name='%s'", path ? path : src->path);
>> + virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path);
>>
>> VIR_FREE(path);
>>
>> - if (src->nhosts == 0 && !src->snapshot && !src->configFile) {
>> - virBufferAddLit(buf, "/>\n");
>> - } else {
>> - virBufferAddLit(buf, ">\n");
>> - virBufferAdjustIndent(buf, 2);
>> + if (src->nhosts > 0 || src->snapshot || src->configFile) {
>
> This condition isn't necessary as well after these adjustments, drop it
> and un-indent the block below.
>
Oh yeah right... The EscapeString's won't format NULL
Tks-
John
>>
>> for (n = 0; n < src->nhosts; n++) {
>> - virBufferAddLit(buf, "<host");
>> - virBufferEscapeString(buf, " name='%s'", src->hosts[n].name);
>> + virBufferAddLit(childBuf, "<host");
>> + virBufferEscapeString(childBuf, " name='%s'", src->hosts[n].name);
>>
>> if (src->hosts[n].port)
>> - virBufferAsprintf(buf, " port='%u'", src->hosts[n].port);
>> + virBufferAsprintf(childBuf, " port='%u'", src->hosts[n].port);
>>
>> if (src->hosts[n].transport)
>> - virBufferAsprintf(buf, " transport='%s'",
>> + virBufferAsprintf(childBuf, " transport='%s'",
>> virStorageNetHostTransportTypeToString(src->hosts[n].transport));
>>
>> - virBufferEscapeString(buf, " socket='%s'", src->hosts[n].socket);
>> - virBufferAddLit(buf, "/>\n");
>> + virBufferEscapeString(childBuf, " socket='%s'", src->hosts[n].socket);
>> + virBufferAddLit(childBuf, "/>\n");
>> }
>>
>> - virBufferEscapeString(buf, "<snapshot name='%s'/>\n", src->snapshot);
>> - virBufferEscapeString(buf, "<config file='%s'/>\n", src->configFile);
>> -
>> - virBufferAdjustIndent(buf, -2);
>> - virBufferAddLit(buf, "</source>\n");
>> + virBufferEscapeString(childBuf, "<snapshot name='%s'/>\n", src->snapshot);
>> + virBufferEscapeString(childBuf, "<config file='%s'/>\n", src->configFile);
>> }
>>
>> return 0;
>
> ACK with the tweak above.
>
More information about the libvir-list
mailing list