summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShradha Shah <sshah@solarflare.com>2011-12-14 10:50:40 +0000
committerEric Blake <eblake@redhat.com>2012-01-11 13:15:09 -0700
commit52d064f42dbc857f4096dc60c0335395ffac73aa (patch)
treede1945ad63b25e0fecf537d60ad25947b6f07994
parentFunctionality to implicitly get interface pool from SR-IOV PF. (diff)
downloadlibvirt-52d064f42dbc857f4096dc60c0335395ffac73aa.tar.gz
libvirt-52d064f42dbc857f4096dc60c0335395ffac73aa.tar.bz2
libvirt-52d064f42dbc857f4096dc60c0335395ffac73aa.zip
Added new option to virsh net-dumpxml called --inactive
The above option helps to differentiate between implicit and explicit interface pools.
-rw-r--r--include/libvirt/libvirt.h.in4
-rw-r--r--src/conf/network_conf.c7
-rw-r--r--src/conf/network_conf.h2
-rw-r--r--src/libvirt.c7
-rw-r--r--src/network/bridge_driver.c4
-rw-r--r--src/test/test_driver.c4
-rw-r--r--src/vbox/vbox_tmpl.c2
-rw-r--r--tests/networkxml2xmltest.c30
-rw-r--r--tools/virsh.c10
-rw-r--r--tools/virsh.pod4
10 files changed, 53 insertions, 21 deletions
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 0b564cf8f..e436f3c53 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1882,6 +1882,10 @@ int virNodeGetCellsFreeMemory(virConnectPtr conn,
* Virtual Networks API
*/
+typedef enum {
+ VIR_NETWORK_XML_INACTIVE = (1 << 0), /* dump inactive network information */
+} virNetworkXMLFlags;
+
/**
* virNetwork:
*
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index c3c70052d..c03ceafce 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1448,7 +1448,7 @@ virPortGroupDefFormat(virBufferPtr buf,
return 0;
}
-char *virNetworkDefFormat(const virNetworkDefPtr def)
+char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
@@ -1484,7 +1484,8 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
virBufferEscapeString(&buf, " <pf dev='%s'/>\n",
def->forwardPfs[0].dev);
- if (def->nForwardIfs) {
+ if (def->nForwardIfs &&
+ (!def->nForwardPfs || !(flags & VIR_NETWORK_XML_INACTIVE))) {
for (ii = 0; ii < def->nForwardIfs; ii++) {
virBufferEscapeString(&buf, " <interface dev='%s'/>\n",
def->forwardIfs[ii].dev);
@@ -1601,7 +1602,7 @@ int virNetworkSaveConfig(const char *configDir,
int ret = -1;
char *xml;
- if (!(xml = virNetworkDefFormat(def)))
+ if (!(xml = virNetworkDefFormat(def, 0)))
goto cleanup;
if (virNetworkSaveXML(configDir, def, xml))
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 0bcd3bf46..5cb396c42 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -227,7 +227,7 @@ virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
xmlNodePtr root);
-char *virNetworkDefFormat(const virNetworkDefPtr def);
+char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags);
static inline const char *
virNetworkDefForwardIf(const virNetworkDefPtr def, size_t n)
diff --git a/src/libvirt.c b/src/libvirt.c
index dbf02963c..a54042483 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -9835,11 +9835,16 @@ error:
/**
* virNetworkGetXMLDesc:
* @network: a network object
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virNetworkXMLFlags
*
* Provide an XML description of the network. The description may be reused
* later to relaunch the network with virNetworkCreateXML().
*
+ * Normally, if a network included a physical function, the output includes
+ * all virtual functions tied to that physical interface. If @flags includes
+ * VIR_NETWORK_XML_INACTIVE, then the expansion of virtual interfaces is
+ * not performed.
+ *
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
* the caller must free() the returned value.
*/
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 91ef229db..5d0d52874 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2533,7 +2533,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
virNetworkObjPtr network;
char *ret = NULL;
- virCheckFlags(0, NULL);
+ virCheckFlags(VIR_NETWORK_XML_INACTIVE, NULL);
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2545,7 +2545,7 @@ static char *networkGetXMLDesc(virNetworkPtr net,
goto cleanup;
}
- ret = virNetworkDefFormat(network->def);
+ ret = virNetworkDefFormat(network->def, flags);
cleanup:
if (network)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 0c88bcfc2..2a98e7ed3 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1,7 +1,7 @@
/*
* test.c: A "mock" hypervisor for use by application unit tests
*
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -3233,7 +3233,7 @@ static char *testNetworkGetXMLDesc(virNetworkPtr network,
goto cleanup;
}
- ret = virNetworkDefFormat(privnet->def);
+ ret = virNetworkDefFormat(privnet->def, flags);
cleanup:
if (privnet)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index b3267a901..22712d578 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8098,7 +8098,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
VBOX_UTF16_FREE(networkInterfaceNameUtf16);
VBOX_RELEASE(host);
- ret = virNetworkDefFormat(def);
+ ret = virNetworkDefFormat(def, 0);
cleanup:
virNetworkDefFree(def);
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 5cdbedb69..6cb9d900a 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -14,7 +14,8 @@
#include "testutilsqemu.h"
static int
-testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
+ unsigned int flags)
{
char *inXmlData = NULL;
char *outXmlData = NULL;
@@ -30,7 +31,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
if (!(dev = virNetworkDefParseString(inXmlData)))
goto fail;
- if (!(actual = virNetworkDefFormat(dev)))
+ if (!(actual = virNetworkDefFormat(dev, flags)))
goto fail;
if (STRNEQ(outXmlData, actual)) {
@@ -48,21 +49,27 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
return ret;
}
+struct testInfo {
+ const char *name;
+ unsigned int flags;
+};
+
static int
testCompareXMLToXMLHelper(const void *data)
{
+ const struct testInfo *info = data;
int result = -1;
char *inxml = NULL;
char *outxml = NULL;
if (virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml",
- abs_srcdir, (const char*)data) < 0 ||
+ abs_srcdir, info->name) < 0 ||
virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml",
- abs_srcdir, (const char*)data) < 0) {
+ abs_srcdir, info->name) < 0) {
goto cleanup;
}
- result = testCompareXMLToXMLFiles(inxml, outxml);
+ result = testCompareXMLToXMLFiles(inxml, outxml, info->flags);
cleanup:
free(inxml);
@@ -76,10 +83,14 @@ mymain(void)
{
int ret = 0;
-#define DO_TEST(name) \
- if (virtTestRun("Network XML-2-XML " name, \
- 1, testCompareXMLToXMLHelper, (name)) < 0) \
- ret = -1
+#define DO_TEST_FULL(name, flags) \
+ do { \
+ const struct testInfo info = {name, flags}; \
+ if (virtTestRun("Network XML-2-XML " name, \
+ 1, testCompareXMLToXMLHelper, &info) < 0) \
+ ret = -1; \
+ } while (0)
+#define DO_TEST(name) DO_TEST_FULL(name, 0)
DO_TEST("isolated-network");
DO_TEST("routed-network");
@@ -93,6 +104,7 @@ mymain(void)
DO_TEST("host-bridge-net");
DO_TEST("vepa-net");
DO_TEST("bandwidth-network");
+ DO_TEST_FULL("passthrough-pf", VIR_NETWORK_XML_INACTIVE);
return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tools/virsh.c b/tools/virsh.c
index f4c0063d9..3869d9d33 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7286,6 +7286,7 @@ static const vshCmdInfo info_network_dumpxml[] = {
static const vshCmdOptDef opts_network_dumpxml[] = {
{"network", VSH_OT_DATA, VSH_OFLAG_REQ, N_("network name or uuid")},
+ {"inactive", VSH_OT_BOOL, VSH_OFLAG_NONE, N_("network information of an inactive domain")},
{NULL, 0, 0, NULL}
};
@@ -7295,6 +7296,8 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network;
bool ret = true;
char *dump;
+ unsigned int flags = 0;
+ int inactive;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
@@ -7302,7 +7305,12 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return false;
- dump = virNetworkGetXMLDesc(network, 0);
+ inactive = vshCommandOptBool (cmd, "inactive");
+ if (inactive)
+ flags |= VIR_NETWORK_XML_INACTIVE;
+
+ dump = virNetworkGetXMLDesc(network, flags);
+
if (dump != NULL) {
vshPrint(ctl, "%s", dump);
VIR_FREE(dump);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1abf44896..f2793cdb1 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1523,9 +1523,11 @@ not instantiated.
Destroy (stop) a given virtual network specified by its name or UUID. This
takes effect immediately.
-=item B<net-dumpxml> I<network>
+=item B<net-dumpxml> I<network> [I<--inactive>]
Output the virtual network information as an XML dump to stdout.
+If I<--inactive> is specified, then physical functions are not
+expanded into their associated virtual functions.
=item B<net-edit> I<network>