Re: [libvirt] [PATCH 14/17] qemu: support type='hostdev' network devices at domain start

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This patch makes sure that each network device (interface) of
 type='hostdev' appears on both the hostdevs list and the nets list of
 the virDomainDef, and it modifies the qemu driver startup code so that
 these devices will be presented to qemu on the commandline as hostdevs
 rather than as network devices.
 
 It does not add support for hotplug of these type of devices, or code
 to honor the mac address or virtualport given in the config (both
 of those will be done in separate patches).
 
 Once each device is placed on both lists, much of what this patch does
 is modify places in the code that traverse all the device lists so
 that these hybrid devices are only acted on once - either along with
 the other hostdevs, or along with the other interfaces. (In many
 cases, only one of the lists is traversed / a specific operation is
 performed on only one type of device. In those instances, the code can
 remain unchanged.)
 
 There is one special case - when building the commandline, interfaces
 are allowed to proceed all the way through
 networkAllocateActualDevice() before deciding to skip - this is so
 that (once we have support for networks with pools of hostdev devices)
 we can get the actual device allocated, then rely on the loop
 processing all hostdevs to generate the correct commandline.
 ---
 New patch in V2.
 
  src/conf/domain_conf.c |   54 
 +---
  src/qemu/qemu_command.c|   36 --
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.args |7 +++
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |7 ---
  tests/qemuxml2argvtest.c   |2 +
  5 files changed, 88 insertions(+), 18 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.args
 

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 14/17] qemu: support type='hostdev' network devices at domain start

2012-02-28 Thread Laine Stump
This patch makes sure that each network device (interface) of
type='hostdev' appears on both the hostdevs list and the nets list of
the virDomainDef, and it modifies the qemu driver startup code so that
these devices will be presented to qemu on the commandline as hostdevs
rather than as network devices.

It does not add support for hotplug of these type of devices, or code
to honor the mac address or virtualport given in the config (both
of those will be done in separate patches).

Once each device is placed on both lists, much of what this patch does
is modify places in the code that traverse all the device lists so
that these hybrid devices are only acted on once - either along with
the other hostdevs, or along with the other interfaces. (In many
cases, only one of the lists is traversed / a specific operation is
performed on only one type of device. In those instances, the code can
remain unchanged.)

There is one special case - when building the commandline, interfaces
are allowed to proceed all the way through
networkAllocateActualDevice() before deciding to skip - this is so
that (once we have support for networks with pools of hostdev devices)
we can get the actual device allocated, then rely on the loop
processing all hostdevs to generate the correct commandline.
---
New patch in V2.

 src/conf/domain_conf.c |   54 +---
 src/qemu/qemu_command.c|   36 --
 .../qemuxml2argvdata/qemuxml2argv-net-hostdev.args |7 +++
 .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |7 ---
 tests/qemuxml2argvtest.c   |2 +
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.args

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 70e9224..7135024 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1463,6 +1463,16 @@ void virDomainDefFree(virDomainDefPtr def)
 if (!def)
 return;
 
+/* hostdevs must be freed before nets (or any future intelligent
+ * hostdevs) because the pointer to the hostdev is really
+ * pointing into the middle of the higher level device's object,
+ * so the original object must still be available during the call
+ * to virDomainHostdevDefFree().
+ */
+for (i = 0 ; i  def-nhostdevs ; i++)
+virDomainHostdevDefFree(def-hostdevs[i]);
+VIR_FREE(def-hostdevs);
+
 for (i = 0 ; i  def-nleases ; i++)
 virDomainLeaseDefFree(def-leases[i]);
 VIR_FREE(def-leases);
@@ -1519,10 +1529,6 @@ void virDomainDefFree(virDomainDefPtr def)
 virDomainVideoDefFree(def-videos[i]);
 VIR_FREE(def-videos);
 
-for (i = 0 ; i  def-nhostdevs ; i++)
-virDomainHostdevDefFree(def-hostdevs[i]);
-VIR_FREE(def-hostdevs);
-
 for (i = 0 ; i  def-nhubs ; i++)
 virDomainHubDefFree(def-hubs[i]);
 VIR_FREE(def-hubs);
@@ -7061,6 +7067,10 @@ int virDomainNetInsert(virDomainDefPtr def, 
virDomainNetDefPtr net)
 return -1;
 def-nets[def-nnets]  = net;
 def-nnets++;
+if (net-type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+/* hostdev net devices must also exist in the hostdevs array */
+return virDomainHostdevInsert(def, net-data.hostdev.def);
+}
 return 0;
 }
 
@@ -7076,6 +7086,23 @@ int virDomainNetIndexByMac(virDomainDefPtr def, const 
unsigned char *mac)
 
 static void virDomainNetRemove(virDomainDefPtr def, size_t i)
 {
+virDomainNetDefPtr net = def-nets[i];
+
+if (net-type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+/* hostdev net devices are normally also be in the hostdevs
+ * array, but might have already been removed by the time we
+ * get here.
+ */
+virDomainHostdevDefPtr hostdev = net-data.hostdev.def;
+size_t h;
+
+for (h = 0; h  def-nhostdevs; h++) {
+if (def-hostdevs[h] == hostdev) {
+virDomainHostdevRemove(def, h);
+break;
+}
+}
+}
 if (def-nnets  1) {
 memmove(def-nets + i,
 def-nets + i + 1,
@@ -8086,6 +8113,12 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 goto error;
 
 def-nets[def-nnets++] = net;
+
+/* interface type='hostdev' must also be in the hostdevs array */
+if ((net-type == VIR_DOMAIN_NET_TYPE_HOSTDEV) 
+(virDomainHostdevInsert(def, net-data.hostdev.def)  0)) {
+goto no_memory;
+}
 }
 VIR_FREE(nodes);
 
@@ -8412,7 +8445,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 if ((n = virXPathNodeSet(./devices/hostdev, ctxt, nodes))  0) {
 goto error;
 }
-if (n  VIR_ALLOC_N(def-hostdevs, n)  0)
+if (n  VIR_REALLOC_N(def-hostdevs, def-nhostdevs + n)  0)
 goto no_memory;
 for (i = 0 ; i  n ; i++) {
 virDomainHostdevDefPtr hostdev;
@@ -12374,9 +12407,16 @@