mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
conf: simplify Buffer Indentation in virDomainNetDefFormat
This function has several calls to increase the buffer indent by 6, then decrease it again, then increase, then decrease. Additionally, there were several printfs that had 6 spaces at the beginning of the line. virDomainActualNetDefFormat, which is called by virDomainNetDefFormat, had similar ugliness. This patch changes both functions to just increase the indent at the beginning, decrease it at (well, just before*) the end, and remove all of the occurences of 6/8 spaces at the beginning of lines. *The indent had to be reset before the end of the function because virDomainDeviceInfoFormat assumes a 0 indent and is called from many other places, and I didn't want to do an overhaul of every caller of that function. A separate patch to switch all of domain_conf.c would be a useful exercise, but my current goal is unrelated to that, so I'll leave it for another day.
This commit is contained in:
parent
2841a0ad0f
commit
ff1efc0901
@ -11566,6 +11566,7 @@ virDomainActualNetDefFormat(virBufferPtr buf,
|
||||
}
|
||||
virBufferAddLit(buf, ">\n");
|
||||
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
switch (def->type) {
|
||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||
virBufferEscapeString(buf, "<source bridge='%s'/>\n",
|
||||
@ -11589,12 +11590,10 @@ virDomainActualNetDefFormat(virBufferPtr buf,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
||||
virBufferAdjustIndent(buf, 8);
|
||||
if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def,
|
||||
flags, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
virBufferAdjustIndent(buf, -8);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||
@ -11605,13 +11604,12 @@ virDomainActualNetDefFormat(virBufferPtr buf,
|
||||
return -1;
|
||||
}
|
||||
|
||||
virBufferAdjustIndent(buf, 8);
|
||||
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
|
||||
return -1;
|
||||
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
|
||||
return -1;
|
||||
virBufferAdjustIndent(buf, -8);
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</actual>\n");
|
||||
return 0;
|
||||
}
|
||||
@ -11636,6 +11634,7 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
}
|
||||
virBufferAddLit(buf, ">\n");
|
||||
|
||||
virBufferAdjustIndent(buf, 6);
|
||||
virBufferAsprintf(buf,
|
||||
"<mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
|
||||
def->mac.addr[0], def->mac.addr[1], def->mac.addr[2],
|
||||
@ -11664,20 +11663,22 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||
virBufferEscapeString(buf, "<source bridge='%s'/>\n",
|
||||
def->data.bridge.brname);
|
||||
if (def->data.bridge.ipaddr)
|
||||
if (def->data.bridge.ipaddr) {
|
||||
virBufferAsprintf(buf, "<ip address='%s'/>\n",
|
||||
def->data.bridge.ipaddr);
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
||||
case VIR_DOMAIN_NET_TYPE_MCAST:
|
||||
if (def->data.socket.address)
|
||||
if (def->data.socket.address) {
|
||||
virBufferAsprintf(buf, "<source address='%s' port='%d'/>\n",
|
||||
def->data.socket.address, def->data.socket.port);
|
||||
else
|
||||
} else {
|
||||
virBufferAsprintf(buf, "<source port='%d'/>\n",
|
||||
def->data.socket.port);
|
||||
}
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_INTERNAL:
|
||||
@ -11694,12 +11695,10 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
|
||||
virBufferAdjustIndent(buf, 6);
|
||||
if (virDomainHostdevSourceFormat(buf, &def->data.hostdev.def,
|
||||
flags, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
virBufferAdjustIndent(buf, -6);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_NET_TYPE_USER:
|
||||
@ -11707,19 +11706,15 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
break;
|
||||
}
|
||||
|
||||
virBufferAdjustIndent(buf, 6);
|
||||
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
|
||||
return -1;
|
||||
virBufferAdjustIndent(buf, -6);
|
||||
|
||||
virBufferEscapeString(buf, "<script path='%s'/>\n",
|
||||
def->script);
|
||||
if (def->ifname &&
|
||||
!((flags & VIR_DOMAIN_XML_INACTIVE) &&
|
||||
(STRPREFIX(def->ifname, VIR_NET_GENERATED_PREFIX)))) {
|
||||
/* Skip auto-generated target names for inactive config. */
|
||||
virBufferEscapeString(buf, " <target dev='%s'/>\n",
|
||||
def->ifname);
|
||||
virBufferEscapeString(buf, "<target dev='%s'/>\n", def->ifname);
|
||||
}
|
||||
if (def->model) {
|
||||
virBufferEscapeString(buf, "<model type='%s'/>\n",
|
||||
@ -11747,27 +11742,25 @@ virDomainNetDefFormat(virBufferPtr buf,
|
||||
}
|
||||
}
|
||||
if (def->filter) {
|
||||
virBufferAdjustIndent(buf, 6);
|
||||
if (virNWFilterFormatParamAttributes(buf, def->filterparams,
|
||||
def->filter) < 0)
|
||||
return -1;
|
||||
virBufferAdjustIndent(buf, -6);
|
||||
}
|
||||
|
||||
if (def->tune.sndbuf_specified) {
|
||||
virBufferAddLit(buf, "<tune>\n");
|
||||
virBufferAsprintf(buf, " <sndbuf>%lu</sndbuf>\n",
|
||||
def->tune.sndbuf);
|
||||
virBufferAsprintf(buf, " <sndbuf>%lu</sndbuf>\n", def->tune.sndbuf);
|
||||
virBufferAddLit(buf, "</tune>\n");
|
||||
}
|
||||
|
||||
if (def->linkstate)
|
||||
if (def->linkstate) {
|
||||
virBufferAsprintf(buf, "<link state='%s'/>\n",
|
||||
virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
|
||||
}
|
||||
|
||||
virBufferAdjustIndent(buf, 6);
|
||||
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
|
||||
return -1;
|
||||
|
||||
virBufferAdjustIndent(buf, -6);
|
||||
|
||||
if (virDomainDeviceInfoFormat(buf, &def->info,
|
||||
|
Loading…
x
Reference in New Issue
Block a user