On 07/18/2011 04:05 PM, Michal Privoznik wrote:
---
src/conf/domain_conf.c | 3 ++
src/conf/network_conf.c | 3 ++
src/libvirt_private.syms | 1 +
src/util/network.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/network.h | 4 ++
5 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0d8c7e7..7bc6c1a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8839,6 +8839,9 @@ virDomainNetDefFormat(virBufferPtr buf,
virBufferAddLit(buf, "</tune>\n");
}
+ if (virBandwidrhDefFormat(buf,&def->bandwidth, " ")< 0)
Why the strange spelling here? ("Bandwidrh")? I'm guessing it's a typo
(since r and t are right next to each other); fortunately you're
consistent about it, and have committed the same typo everywhere :-)
ACK with the typo fixed (although as I said in an earlier patch, I think
several of these can be combined into one)
+ return -1;
+
if (virDomainDeviceInfoFormat(buf,&def->info, flags)< 0)
return -1;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index c9929e2..43145b1 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1093,6 +1093,9 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
if (virNetworkDNSDefFormat(&buf, def->dns)< 0)
goto error;
+ if (virBandwidrhDefFormat(&buf,&def->bandwidth, " ")< 0)
+ goto error;
+
for (ii = 0; ii< def->nips; ii++) {
if (virNetworkIpDefFormat(&buf,&def->ips[ii])< 0)
goto error;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 12db3d7..1cc9bca 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -700,6 +700,7 @@ nlComm;
# network.h
+virBandwidrhDefFormat;
virBandwidthDefParseNode;
virSocketAddrBroadcast;
virSocketAddrBroadcastByPrefix;
diff --git a/src/util/network.c b/src/util/network.c
index ce949c7..58c0492 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -786,3 +786,75 @@ virBandwidthDefParseNode(xmlNodePtr node, virBandwidthPtr def)
cleanup:
return ret;
}
+
+static int
+virBandwidthChildDefFormat(virBufferPtr buf,
+ virRatePtr def,
+ const char *elem_name)
+{
+ if (!buf || !def || !elem_name)
+ return -1;
+
+ if (def->average) {
+ virBufferAsprintf(buf, "<%s average='%lu'", elem_name, def->average);
+
+ if (def->peak)
+ virBufferAsprintf(buf, " peak='%lu'", def->peak);
+
+ if (def->burst)
+ virBufferAsprintf(buf, " burst='%lu'", def->burst);
+ virBufferAddLit(buf, "/>\n");
+ }
+
+ return 0;
+}
+
+/**
+ * virBandwidrhDefFormat:
+ * @buf: Buffer to print to
+ * @def: Data source
+ * @indent: prepend all lines printed with this
+ *
+ * Formats bandwidth and prepend each line with @indent.
+ * Passing NULL to @indent is equivalent passing "".
+ *
+ * Returns 0 on success, else -1.
+ */
+int
+virBandwidrhDefFormat(virBufferPtr buf,
+ virBandwidthPtr def,
+ const char *indent)
+{
+ int ret = -1;
+
+ if (!buf || !def)
+ goto cleanup;
+
+ if (!indent)
+ indent = "";
+
+ if (!def->in.average&& !def->out.average) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ virBufferAsprintf(buf, "%s<bandwidth>\n", indent);
+ if (def->in.average) {
+ virBufferAsprintf(buf, "%s ", indent);
+ if (virBandwidthChildDefFormat(buf,&def->in, "inbound")< 0)
+ goto cleanup;
+ }
+
+ if (def->out.average) {
+ virBufferAsprintf(buf, "%s ", indent);
+ if (virBandwidthChildDefFormat(buf,&def->out, "outbound")< 0)
+ goto cleanup;
+ }
+
+ virBufferAsprintf(buf, "%s</bandwidth>\n", indent);
+
+ ret = 0;
+
+cleanup:
+ return ret;
+}
diff --git a/src/util/network.h b/src/util/network.h
index 54f7aad..98e3082 100644
--- a/src/util/network.h
+++ b/src/util/network.h
@@ -21,6 +21,7 @@
# include<netdb.h>
# include<netinet/in.h>
# include "xml.h"
+# include "buf.h"
typedef struct {
union {
@@ -106,4 +107,7 @@ int virSocketAddrPrefixToNetmask(unsigned int prefix,
int family);
int virBandwidthDefParseNode(xmlNodePtr node, virBandwidthPtr def);
+int virBandwidrhDefFormat(virBufferPtr buf,
+ virBandwidthPtr def,
+ const char *indent);
#endif /* __VIR_NETWORK_H__ */
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list