[libvirt] [PATCH v5] openvswitch: Add new port VLAN mode "802.1ad"

2019-02-24 Thread ZhiPeng LU
This patch adds functionality to allow libvirt to configure the '802.1ad'
modes(802.1ad double-tagged) on openvswitch networks.
For example:
  



  


  




  

Signed-off-by: ZhiPeng Lu 
---
v1->v2:
  1. Fix "make syntax-check" failure
v2->v3:
  1. remove other_config when updating vlan
v3->v4:
  1. add commit message that has a brief description of the new
  feature
  2. add tests for 'dot1q-tunnel' vlan mode
v4->v5:
  1. modify some description and format

v4-resend:
  https://www.redhat.com/archives/libvir-list/2019-February/msg00988.html

 docs/formatdomain.html.in  | 33 +++---
 docs/formatnetwork.html.in | 26 ++---
 docs/schemas/networkcommon.rng |  1 +
 src/conf/netdev_vlan_conf.c|  2 +-
 src/util/virnetdevopenvswitch.c|  7 +
 src/util/virnetdevvlan.h   |  1 +
 tests/networkxml2xmlin/openvswitch-net.xml |  9 ++
 tests/networkxml2xmlout/openvswitch-net.xml|  9 ++
 .../openvswitch-net-modified.xml   |  9 ++
 .../openvswitch-net-more-portgroups.xml|  9 ++
 .../openvswitch-net-without-alice.xml  |  9 ++
 11 files changed, 94 insertions(+), 21 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index b848e53..253f329 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -6097,6 +6097,13 @@ qemu-kvm -net nic,model=? /dev/null
 /vlan
 ...
   /interface
+  interface type='bridge'
+vlan trunk='yes'
+  tag id='42'/
+  tag id='555' nativeMode='802.1ad'/
+/vlan
+...
+  /interface
 /devices
 ...
 
@@ -6132,16 +6139,22 @@ qemu-kvm -net nic,model=? /dev/null
 
 
   For network connections using Open vSwitch it is also possible
-  to configure 'native-tagged' and 'native-untagged' VLAN modes
-  Since 1.1.0. This is done with the
-  optional nativeMode attribute on
-  the tag subelement: nativeMode
-  may be set to 'tagged' or 'untagged'. The id
-  attribute of the tag subelement
-  containing nativeMode sets which VLAN is considered
-  to be the "native" VLAN for this interface, and
-  the nativeMode attribute determines whether or not
-  traffic for that VLAN will be tagged.
+  to configure the following VLAN modes:
+
+  
+'tagged' Since 1.1.0.
+'untagged' Since 1.1.0.
+'802.1ad' Since 5.1.0.
+  
+
+  This is done with the optional nativeMode attribute
+  on the tag subelement. The attribute may be
+  set to a string from the above list. The id attribute
+  of the tag subelement containing
+  nativeMode sets which VLAN is considered to be the
+  "native" VLAN for this interface and the nativeMode
+  attribute determines whether or not traffic for that VLAN will be
+  tagged or 802.1ad double tagged.
 
 
 Modifying virtual link state
diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in
index 509cca9..eea86f4 100644
--- a/docs/formatnetwork.html.in
+++ b/docs/formatnetwork.html.in
@@ -705,16 +705,22 @@
 
 
   For network connections using Open vSwitch it is also possible
-  to configure 'native-tagged' and 'native-untagged' VLAN modes
-  Since 1.1.0. This is done with the
-  optional nativeMode attribute on
-  the tag subelement: nativeMode
-  may be set to 'tagged' or 'untagged'. The id
-  attribute of the tag subelement
-  containing nativeMode sets which VLAN is considered
-  to be the "native" VLAN for this interface, and
-  the nativeMode attribute determines whether or not
-  traffic for that VLAN will be tagged.
+  to configure the following VLAN modes:
+
+  
+'tagged' Since 1.1.0.
+'untagged' Since 1.1.0.
+'802.1ad' Since 5.1.0.
+  
+
+  This is done with the optional nativeMode attribute
+  on the tag subelement. The attribute may be
+  set to a string from the above list. The id attribute
+  of the tag subelement containing
+  nativeMode sets which VLAN is considered to be the
+  "native" VLAN for this interface and the nativeMode
+  attribute determines whether or not traffic for that VLAN will be
+  tagged or 802.1ad double tagged.
 
 
   vlan elements can also be specified in
diff --git a/docs/schemas/networkcommon.rng b/docs/schemas/networkcommon.rng
index 2699555..7262783 100644
--- a/docs/schemas/networkcommon.rng
+++ b/docs/schemas/networkcommon.rng
@@ -223,6 +223,7 @@
   
 tagged
 untagged
+802.1ad
   
 
   
diff --git a/src/conf/netdev_vlan_conf.c b/src/conf/netdev_vlan_conf.c
index 57d73ed..5

[libvirt] [PATCHv4 RESEND] vhost-user: add support reconnect for vhost-user ports

2018-01-17 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
v1->v2:
 - modify xml format
v2->v3:
 - fix commit message syntax
 - reimplemente functions and the struct about reconnect
v3->v4:
 - revert reimplemente functions and the struct about reconnect
---
 docs/formatdomain.html.in|   7 +-
 docs/schemas/domaincommon.rng|  26 ++--
 src/conf/domain_conf.c   | 158 +--
 tests/qemuxml2argvdata/net-vhostuser-multiq.args |  12 +-
 tests/qemuxml2argvdata/net-vhostuser-multiq.xml  |  11 +-
 5 files changed, 127 insertions(+), 87 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d272cc1..f0f9f4b 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5832,7 +5832,9 @@ qemu-kvm -net nic,model=? /dev/null
   /interface
   interface type='vhostuser'
 mac address='52:54:00:3b:83:1b'/
-source type='unix' path='/tmp/vhost2.sock' mode='client'/
+source type='unix' path='/tmp/vhost2.sock' mode='client'
+  reconnect enabled='yes' timeout='10'/
+/source 
 model type='virtio'/
 driver queues='5'/
   /interface
@@ -5848,6 +5850,9 @@ qemu-kvm -net nic,model=? /dev/null
   are supported.
   vhost-user requires the virtio model type, thus the
   model element is mandatory.
+  Since 3.10.0 the element has an optional
+  attribute reconnect which configures reconnect timeout
+  (in seconds) if the connection is lost.
 
 
 Traffic filtering with NWFilter
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index f22c932..9258c7d 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2399,6 +2399,18 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
 
   

[libvirt] [PATCH] virsh: domifstat: clarify description of --help option

2017-11-17 Thread ZhiPeng Lu
 can be the interface target by
name or MAC address. So clarify description of --help option

Signed-off-by:ZhiPeng Lu 
---
 tools/virsh-domain-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 960fd37..4e8fc46 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -995,7 +995,7 @@ static const vshCmdOptDef opts_domifstat[] = {
 {.name = "interface",
  .type = VSH_OT_DATA,
  .flags = VSH_OFLAG_REQ,
- .help = N_("interface device")
+ .help = N_("interface device (MAC Address)")
 },
 {.name = NULL}
 };
-- 
1.8.3.1

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


[libvirt] [PATCH v4] vhost-user: add support reconnect for vhost-user ports

2017-11-12 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
v1->v2:
 - modify xml format 
v2->v3:
 - fix commit message syntax
 - reimplemente functions and the struct about reconnect
v3->v4:
 - revert reimplemente functions and the struct about reconnect

 docs/formatdomain.html.in  |   7 +-
 docs/schemas/domaincommon.rng  |  26 ++--
 src/conf/domain_conf.c | 158 -
 .../qemuxml2argv-net-vhostuser-multiq.args |  12 +-
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  11 +-
 5 files changed, 127 insertions(+), 87 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 92e14a9..7ea72ed 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5756,7 +5756,9 @@ qemu-kvm -net nic,model=? /dev/null
   /interface
   interface type='vhostuser'
 mac address='52:54:00:3b:83:1b'/
-source type='unix' path='/tmp/vhost2.sock' mode='client'/
+source type='unix' path='/tmp/vhost2.sock' mode='client'
+  reconnect enabled='yes' timeout='10'/
+/source 
 model type='virtio'/
 driver queues='5'/
   /interface
@@ -5772,6 +5774,9 @@ qemu-kvm -net nic,model=? /dev/null
   are supported.
   vhost-user requires the virtio model type, thus the
   model element is mandatory.
+  Since 3.10.0 the element has an optional
+  attribute reconnect which configures reconnect timeout
+  (in seconds) if the connection is lost.
 
 
 Traffic filtering with NWFilter
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 9cec1a0..66b9758 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2399,6 +2399,18 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
 
   

[libvirt] [PATCH] Add output of local time when adding the option of "--pretty" for virsh domtime

2017-10-22 Thread ZhiPeng Lu
Add more human-friendly output of domain's system time.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
Reviewed-by: Jiyun Fan <fan.ji...@zte.com.cn>
---
 tools/virsh-domain-monitor.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 35d04b2..d9520ff 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1384,17 +1384,22 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
 goto cleanup;
 
 if (pretty) {
-char timestr[100];
+char timestr[100], localtimestr[100];
 time_t cur_time = seconds;
-struct tm time_info;
+struct tm time_info, local_time_info;
 
 if (!gmtime_r(_time, _info)) {
 vshError(ctl, _("Unable to format time"));
 goto cleanup;
 }
+if (!localtime_r(_time, _time_info)) {
+vshError(ctl, _("Unable to format local time"));
+goto cleanup;
+}
 strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", 
_info);
+strftime(localtimestr, sizeof(localtimestr), "%Y-%m-%d %H:%M:%S", 
_time_info);
 
-vshPrint(ctl, _("Time: %s"), timestr);
+vshPrint(ctl, _("Time: %s\n Local time: %s"), timestr, 
localtimestr);
 } else {
 vshPrint(ctl, _("Time: %lld"), seconds);
 }
-- 
1.8.3.1

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


[libvirt] [PATCH v3 RESEND] vhost-user: add support reconnect for vhost-user ports

2017-10-08 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 docs/schemas/domaincommon.rng  | 26 --
 src/conf/domain_conf.c | 40 ++
 src/conf/domain_conf.h | 10 +++---
 src/qemu/qemu_command.c|  2 +-
 src/qemu/qemu_domain.c |  2 +-
 src/qemu/qemu_monitor_json.c   |  2 +-
 .../qemuxml2argv-net-vhostuser-multiq.args |  4 +--
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  8 +++--
 8 files changed, 65 insertions(+), 29 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 76852ab..3f4ed82 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2327,6 +2327,18 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
 
   

[libvirt] [PATCH v3 RESEND] vhost-user: add support reconnect for vhost-user ports

2017-09-29 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 docs/schemas/domaincommon.rng  | 26 --
 src/conf/domain_conf.c | 40 ++
 src/conf/domain_conf.h | 10 +++---
 src/qemu/qemu_command.c|  2 +-
 src/qemu/qemu_domain.c |  2 +-
 src/qemu/qemu_monitor_json.c   |  2 +-
 .../qemuxml2argv-net-vhostuser-multiq.args |  4 +--
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  8 +++--
 8 files changed, 65 insertions(+), 29 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 76852ab..3f4ed82 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2327,6 +2327,18 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
 
   

[libvirt] [PATCH] nwfilter: Don't leak @val

2017-09-26 Thread ZhiPeng Lu
In virNWFilterIPAddrMapAddIPAddr the @val may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/conf/nwfilter_ipaddrmap.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c
index 446f3de..5242f05 100644
--- a/src/conf/nwfilter_ipaddrmap.c
+++ b/src/conf/nwfilter_ipaddrmap.c
@@ -61,7 +61,10 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
 if (!val)
 goto cleanup;
 ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
-goto cleanup;
+if (ret < 0) {
+virNWFilterVarValueFree(val);
+goto cleanup;
+}
 } else {
 if (virNWFilterVarValueAddValue(val, addr) < 0)
 goto cleanup;
-- 
1.8.3.1

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


[libvirt] [PATCH v3] nwfilter: Don't leak @inetaddr

2017-09-26 Thread ZhiPeng Lu
In learnIPAddressThread()the @inetaddr may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/nwfilter/nwfilter_learnipaddr.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
b/src/nwfilter/nwfilter_learnipaddr.c
index cfd92d9..0cadf73 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -605,6 +605,7 @@ learnIPAddressThread(void *arg)
 
 if (req->status == 0) {
 int ret;
+int mapipret = -1;
 virSocketAddr sa;
 sa.len = sizeof(sa.data.inet4);
 sa.data.inet4.sin_family = AF_INET;
@@ -622,7 +623,7 @@ learnIPAddressThread(void *arg)
 virNWFilterUnlockIface(req->ifname);
 
 if ((inetaddr = virSocketAddrFormat()) != NULL) {
-if (virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr) < 0) {
+if ((mapipret = virNWFilterIPAddrMapAddIPAddr(req->ifname, 
inetaddr)) < 0) {
 VIR_ERROR(_("Failed to add IP address %s to IP address "
   "cache for interface %s"), inetaddr, req->ifname);
 }
@@ -637,6 +638,9 @@ learnIPAddressThread(void *arg)
req->filterparams);
 VIR_DEBUG("Result from applying firewall rules on "
   "%s with IP addr %s : %d", req->ifname, inetaddr, ret);
+if (mapipret < 0)
+VIR_FREE(inetaddr);
+
 }
 } else {
 if (showError)
-- 
1.8.3.1

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


[libvirt] [PATCH v2] nwfilter: Don't leak @inetaddr

2017-09-26 Thread ZhiPeng Lu
In learnIPAddressThread()the @inetaddr may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/nwfilter/nwfilter_learnipaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
b/src/nwfilter/nwfilter_learnipaddr.c
index cfd92d9..5dc212e 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -625,6 +625,7 @@ learnIPAddressThread(void *arg)
 if (virNWFilterIPAddrMapAddIPAddr(req->ifname, inetaddr) < 0) {
 VIR_ERROR(_("Failed to add IP address %s to IP address "
   "cache for interface %s"), inetaddr, req->ifname);
+VIR_FREE(inetaddr);
 }
 
 ret = virNWFilterInstantiateFilterLate(req->driver,
@@ -636,7 +637,8 @@ learnIPAddressThread(void *arg)
req->filtername,
req->filterparams);
 VIR_DEBUG("Result from applying firewall rules on "
-  "%s with IP addr %s : %d", req->ifname, inetaddr, ret);
+  "%s with IP addr %s : %d", req->ifname, 
NULLSTR(inetaddr), ret);
+
 }
 } else {
 if (showError)
-- 
1.8.3.1

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


[libvirt] [PATCH] nwfilter: Don't leak @inetaddr

2017-09-26 Thread ZhiPeng Lu
In learnIPAddressThread()the @inetaddr may be leaked.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/nwfilter/nwfilter_learnipaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/nwfilter/nwfilter_learnipaddr.c 
b/src/nwfilter/nwfilter_learnipaddr.c
index cfd92d9..018f20f 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -627,6 +627,7 @@ learnIPAddressThread(void *arg)
   "cache for interface %s"), inetaddr, req->ifname);
 }
 
+inetaddr = NULL;
 ret = virNWFilterInstantiateFilterLate(req->driver,
NULL,
req->ifname,
@@ -636,7 +637,8 @@ learnIPAddressThread(void *arg)
req->filtername,
req->filterparams);
 VIR_DEBUG("Result from applying firewall rules on "
-  "%s with IP addr %s : %d", req->ifname, inetaddr, ret);
+  "%s with IP addr %s : %d", req->ifname, 
NULLSTR(inetaddr), ret);
+VIR_FREE(inetaddr);
 }
 } else {
 if (showError)
-- 
1.8.3.1

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


[libvirt] [PATCH v3] vhost-user: add support reconnect for vhost-user ports

2017-09-26 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashes or restarts, the QEMU process should be reconnected to
OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 docs/schemas/domaincommon.rng  | 26 --
 src/conf/domain_conf.c | 40 ++
 src/conf/domain_conf.h | 10 +++---
 src/qemu/qemu_command.c|  2 +-
 src/qemu/qemu_domain.c |  2 +-
 src/qemu/qemu_monitor_json.c   |  2 +-
 .../qemuxml2argv-net-vhostuser-multiq.args |  4 +--
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  8 +++--
 8 files changed, 65 insertions(+), 29 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 76852ab..3f4ed82 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2327,6 +2327,18 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
 
   

[libvirt] [PATCH] vhost-user: add support reconnect for vhost-user ports

2017-09-21 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashed or restart, QEMU shoule be reconnect to OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
v1->v2:
 - modify xml format
---
---
 docs/schemas/domaincommon.rng  | 12 ++
 src/conf/domain_conf.c | 26 ++
 .../qemuxml2argv-net-vhostuser-multiq.args |  4 ++--
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  8 +--
 4 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 76852ab..bf015ca 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2388,6 +2388,18 @@
   client
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+   
+  
   
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cc5e79b..d121a9e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -83,6 +83,13 @@ struct _virDomainXMLOption {
 /* Private data for save image stored in snapshot XML */
 virSaveCookieCallbacks saveCookie;
 };
+static int
+virDomainChrSourceReconnectDefParseXML(virDomainChrSourceReconnectDefPtr def,
+   xmlNodePtr node,
+   xmlXPathContextPtr ctxt);
+static void
+virDomainChrSourceReconnectDefFormat(virBufferPtr buf,
+ virDomainChrSourceReconnectDefPtr def);
 
 #define VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS \
 (VIR_DOMAIN_DEF_FORMAT_SECURE |\
@@ -10245,6 +10252,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 virNWFilterHashTablePtr filterparams = NULL;
 virDomainActualNetDefPtr actual = NULL;
 xmlNodePtr oldnode = ctxt->node;
+virDomainChrSourceReconnectDef reconnect = {0};
 int rv, val;
 
 if (VIR_ALLOC(def) < 0)
@@ -10331,6 +10339,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 vhostuser_type = virXMLPropString(cur, "type");
 vhostuser_path = virXMLPropString(cur, "path");
 vhostuser_mode = virXMLPropString(cur, "mode");
+if (virDomainChrSourceReconnectDefParseXML(, cur, 
ctxt) < 0)
+goto error;
 } else if (!def->virtPortProfile
&& virXMLNodeNameEqual(cur, "virtualport")) {
 if (def->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -10552,8 +10562,17 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 
 if (STREQ(vhostuser_mode, "server")) {
 def->data.vhostuser->data.nix.listen = true;
+if (reconnect.enabled != VIR_TRISTATE_BOOL_ABSENT) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("'reconnect' attribute  unsupported "
+ "'server' mode for "));
+goto error;
+   }
 } else if (STREQ(vhostuser_mode, "client")) {
 def->data.vhostuser->data.nix.listen = false;
+def->data.vhostuser->data.nix.reconnect.enabled = 
reconnect.enabled;
+def->data.vhostuser->data.nix.reconnect.timeout = 
reconnect.timeout;
+reconnect.enabled = VIR_TRISTATE_BOOL_ABSENT;
 } else {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Wrong  'mode' attribute "
@@ -22984,6 +23003,13 @@ virDomainNetDefFormat(virBufferPtr buf,
   def->data.vhostuser->data.nix.listen ?
   "server"  : "client");
 sourceLines++;
+if (def->data.vhostuser->data.nix.reconnect.enabled != 
VIR_TRISTATE_BOOL_ABSENT) {
+virBufferAddLit(buf, ">\n");
+sourceLines++;
+virBufferAdjustIndent(buf, 2);
+virDomainChrSourceReconnectDefFormat(buf, 
>data.vhostuser->data.nix.reconnect);
+virBufferAdjustIndent(buf, -2);
+}
 }
 break;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args 
b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args
index b69ebd8..0b08f44 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-vhostuser-multiq.args
@@ -25,14 +25,14 @@ server,nowait \
 -netdev vhost-user,chardev=char

[libvirt] [PATCH v2] qemu: handle reconnect on chardev hotplug

2017-09-12 Thread ZhiPeng Lu
The patch passes the reconnect timeout to QEMU by monitor on chardev hotplug.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
v1->v2:
 - Fix syntax errors about Curly brackets
---
 src/qemu/qemu_monitor_json.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index df5fb7c..290a037 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6444,6 +6444,17 @@ int qemuMonitorJSONGetTPMTypes(qemuMonitorPtr mon,
 return qemuMonitorJSONGetStringArray(mon, "query-tpm-types", tpmtypes);
 }
 
+static int
+qemuMonitorJSONBuildChrChardevReconnect(virJSONValuePtr object,
+const virDomainChrSourceReconnectDef 
*def)
+{
+int ret = 0;
+
+if (def->enabled == VIR_TRISTATE_BOOL_YES)
+ret = virJSONValueObjectAppendNumberUint(object, "reconnect", 
def->timeout);
+return ret;
+}
+
 static virJSONValuePtr
 qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 const virDomainChrSourceDef *chr)
@@ -6508,6 +6519,9 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 
0)
 goto cleanup;
 }
+
+if (qemuMonitorJSONBuildChrChardevReconnect(data, 
>data.tcp.reconnect) < 0)
+goto cleanup;
 break;
 
 case VIR_DOMAIN_CHR_TYPE_UDP:
@@ -6545,6 +6559,9 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 ||
 virJSONValueObjectAppendBoolean(data, "server", 
chr->data.nix.listen) < 0)
 goto cleanup;
+
+if (qemuMonitorJSONBuildChrChardevReconnect(data, 
>data.nix.reconnect) < 0)
+goto cleanup;
 break;
 
 case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
-- 
1.8.3.1

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


[libvirt] [PATCH] qemu: handle reconnect on chardev hotplug

2017-09-11 Thread ZhiPeng Lu
The patch passes the reconnect timeout to QEMU by monitor on chardev hotplug.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_monitor_json.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index df5fb7c..4169cd5 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6444,6 +6444,17 @@ int qemuMonitorJSONGetTPMTypes(qemuMonitorPtr mon,
 return qemuMonitorJSONGetStringArray(mon, "query-tpm-types", tpmtypes);
 }
 
+static int
+qemuMonitorJSONBuildChrChardevReconnect(virJSONValuePtr object,
+const virDomainChrSourceReconnectDef 
*def)
+{
+int ret = 0;
+if (def->enabled == VIR_TRISTATE_BOOL_YES) {
+ret = virJSONValueObjectAppendNumberUint(object, "reconnect", 
def->timeout);
+}
+return ret;
+}
+
 static virJSONValuePtr
 qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 const virDomainChrSourceDef *chr)
@@ -6508,6 +6519,10 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 
0)
 goto cleanup;
 }
+
+if (qemuMonitorJSONBuildChrChardevReconnect(data, 
>data.tcp.reconnect) < 0) {
+goto cleanup;
+}
 break;
 
 case VIR_DOMAIN_CHR_TYPE_UDP:
@@ -6545,6 +6560,10 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 ||
 virJSONValueObjectAppendBoolean(data, "server", 
chr->data.nix.listen) < 0)
 goto cleanup;
+
+if (qemuMonitorJSONBuildChrChardevReconnect(data, 
>data.nix.reconnect) < 0) {
+goto cleanup;
+}
 break;
 
 case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
-- 
1.8.3.1

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


[libvirt] [PATCH] vhost-user: add support reconnect for vhost-user ports

2017-09-08 Thread ZhiPeng Lu
For vhost-user ports, Open vSwitch acts as the server and QEMU the client.
When OVS crashed or restart, QEMU shoule be reconnect to OVS.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 docs/formatdomain.html.in  |  6 +++--
 docs/schemas/domaincommon.rng  |  5 
 src/conf/domain_conf.c | 28 --
 .../qemuxml2argv-net-vhostuser-multiq.args |  2 +-
 .../qemuxml2argv-net-vhostuser-multiq.xml  |  2 +-
 5 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..ffe45c2 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5660,7 +5660,7 @@ qemu-kvm -net nic,model=? /dev/null
   /interface
   interface type='vhostuser'
 mac address='52:54:00:3b:83:1b'/
-source type='unix' path='/tmp/vhost2.sock' mode='client'/
+source type='unix' path='/tmp/vhost2.sock' mode='client' 
reconnect='10'/
 model type='virtio'/
 driver queues='5'/
   /interface
@@ -5675,7 +5675,9 @@ qemu-kvm -net nic,model=? /dev/null
   Both mode='server' and mode='client'
   are supported.
   vhost-user requires the virtio model type, thus the
-  model element is mandatory.
+  model element is mandatory. reconnect
+  is an optional element,which configures reconnect timeout if the
+  connection is lost.
 
 
 Traffic filtering with NWFilter
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 06c5a91..82f30ae 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2383,6 +2383,11 @@
 client
   
 
+
+  
+
+  
+
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2fc1fc3..f9c3b35 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10176,6 +10176,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 char *vhostuser_mode = NULL;
 char *vhostuser_path = NULL;
 char *vhostuser_type = NULL;
+char *vhostuser_reconnect = NULL;
 char *trustGuestRxFilters = NULL;
 char *vhost_path = NULL;
 virNWFilterHashTablePtr filterparams = NULL;
@@ -10262,11 +10263,12 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 goto error;
 }
 } else if (!vhostuser_path && !vhostuser_mode && !vhostuser_type
-   && def->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER &&
-   virXMLNodeNameEqual(cur, "source")) {
+   && !vhostuser_reconnect && def->type == 
VIR_DOMAIN_NET_TYPE_VHOSTUSER
+   && virXMLNodeNameEqual(cur, "source")) {
 vhostuser_type = virXMLPropString(cur, "type");
 vhostuser_path = virXMLPropString(cur, "path");
 vhostuser_mode = virXMLPropString(cur, "mode");
+vhostuser_reconnect = virXMLPropString(cur, "reconnect");
 } else if (!def->virtPortProfile
&& virXMLNodeNameEqual(cur, "virtualport")) {
 if (def->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -10478,6 +10480,11 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
  "type='vhostuser'/>"));
 goto error;
 }
+if (vhostuser_reconnect != NULL && STREQ(vhostuser_mode, "server")) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("'reconnect' attribute  unsupported "
+ "'server' mode for "));
+}
 
 if (VIR_ALLOC(def->data.vhostuser) < 0)
 goto error;
@@ -10490,6 +10497,17 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 def->data.vhostuser->data.nix.listen = true;
 } else if (STREQ(vhostuser_mode, "client")) {
 def->data.vhostuser->data.nix.listen = false;
+if (vhostuser_reconnect != NULL) {
+def->data.vhostuser->data.nix.reconnect.enabled = true;
+if (virStrToLong_ui(vhostuser_reconnect, NULL, 0,
+   
>data.vhostuser->data.nix.reconnect.timeout) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("vhost-user reconnect attribute is 
invalid"));
+vhostuser_reconnect = NULL;
+def->data.vhostuser->data.nix.reconnect.enabled = false;
+goto error;
+  

[libvirt] [PATCH] mpath: Fix memory leak in virStorageBackendCreateVols

2017-07-18 Thread ZhiPeng Lu
@map_device, allocated by virAsprintf in virStorageBackendCreateVols,
was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 src/storage/storage_backend_mpath.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/storage/storage_backend_mpath.c 
b/src/storage/storage_backend_mpath.c
index 606b399..434a477 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -200,6 +200,7 @@ virStorageBackendCreateVols(virStoragePoolObjPtr pool,
 
 retval = 0;
  out:
+VIR_FREE(map_device);
 return retval;
 }
 
-- 
1.8.3.1


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


[libvirt] [PATCH RESEND] phyp: Fix memory leak in phypUUIDTable_Push

2017-07-18 Thread ZhiPeng Lu
@remote_file, allocated by virAsprintf, was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 src/phyp/phyp_driver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 9121581..662e2f7 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -568,6 +568,7 @@ phypUUIDTable_Push(virConnectPtr conn)
 ret = 0;
 
  cleanup:
+VIR_FREE(remote_file);
 if (channel) {
 libssh2_channel_send_eof(channel);
 libssh2_channel_wait_eof(channel);
-- 
1.8.3.1


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


[libvirt] [PATCH] phyp: Fix memory leak in phypUUIDTable_Push

2017-07-17 Thread ZhiPeng Lu
@remote_file, allocated by virAsprintf, was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 src/phyp/phyp_driver.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 9121581..662e2f7 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -568,6 +568,7 @@ phypUUIDTable_Push(virConnectPtr conn)
 ret = 0;
 
  cleanup:
+VIR_FREE(remote_file);
 if (channel) {
 libssh2_channel_send_eof(channel);
 libssh2_channel_wait_eof(channel);
-- 
1.8.3.1


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


[libvirt] [PATCH RESEND] virpcimock: Fix memory leak in pci_driver_new

2017-07-14 Thread ZhiPeng Lu
@driverpath, allocated by virAsprintfQuiet, was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 tests/virpcimock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index e9408aa..dec9e01 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -480,6 +480,7 @@ pci_driver_new(const char *name, int fail, ...)
 
 if (VIR_APPEND_ELEMENT_QUIET(pciDrivers, nPCIDrivers, driver) < 0)
 ABORT_OOM();
+VIR_FREE(driverpath);
 }
 
 static struct pciDriver *
-- 
1.8.3.1


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


[libvirt] [PATCH] virpcimock: Fix memory leak in pci_driver_new

2017-07-13 Thread ZhiPeng Lu
@driverpath, allocated by virAsprintfQuiet, was not freed and leaked.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 tests/virpcimock.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index e9408aa..dec9e01 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -480,6 +480,7 @@ pci_driver_new(const char *name, int fail, ...)
 
 if (VIR_APPEND_ELEMENT_QUIET(pciDrivers, nPCIDrivers, driver) < 0)
 ABORT_OOM();
+VIR_FREE(driverpath);
 }
 
 static struct pciDriver *
-- 
1.8.3.1


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


[libvirt] [PATCH v2] network: allow to specify buffer size for netlink socket

2017-07-11 Thread ZhiPeng Lu
This patchs allow to set the buffer size for netlink socket in
the libvirtd configuration file. The default buffer size remain
as before at 128k.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
---
 daemon/libvirtd-config.c|  6 ++
 daemon/libvirtd-config.h|  2 ++
 daemon/libvirtd.aug |  1 +
 daemon/libvirtd.c   | 12 
 daemon/libvirtd.conf|  3 +++
 daemon/test_libvirtd.aug.in |  1 +
 src/libvirt_private.syms|  1 +
 src/util/virnetlink.c   | 19 ++-
 src/util/virnetlink.h   |  7 ++-
 9 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 6c0f00e..b2bda28 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -33,6 +33,7 @@
 #include "remote/remote_protocol.h"
 #include "remote/remote_driver.h"
 #include "util/virnetdevopenvswitch.h"
+#include "util/virnetlink.h"
 #include "virstring.h"
 #include "virutil.h"
 
@@ -172,6 +173,8 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED)
 data->admin_keepalive_count = 5;
 
 data->ovs_timeout = VIR_NETDEV_OVS_DEFAULT_TIMEOUT;
+
+data->netlink_sock_buffer_size = VIRT_NETLINK_SOCK_BUFFER_SIZE;
 
 localhost = virGetHostname();
 if (localhost == NULL) {
@@ -394,6 +397,9 @@ daemonConfigLoadOptions(struct daemonConfig *data,
 if (virConfGetValueUInt(conf, "ovs_timeout", >ovs_timeout) < 0)
 goto error;
 
+if (virConfGetValueUInt(conf, "netlink_sock_buffer_size", 
>netlink_sock_buffer_size) < 0)
+goto error;
+
 return 0;
 
  error:
diff --git a/daemon/libvirtd-config.h b/daemon/libvirtd-config.h
index 1edf5fa..22befd1 100644
--- a/daemon/libvirtd-config.h
+++ b/daemon/libvirtd-config.h
@@ -94,6 +94,8 @@ struct daemonConfig {
 unsigned int admin_keepalive_count;
 
 unsigned int ovs_timeout;
+
+unsigned int netlink_sock_buffer_size;
 };
 
 
diff --git a/daemon/libvirtd.aug b/daemon/libvirtd.aug
index 24fdf44..84ea00a 100644
--- a/daemon/libvirtd.aug
+++ b/daemon/libvirtd.aug
@@ -89,6 +89,7 @@ module Libvirtd =
let misc_entry = str_entry "host_uuid"
   | str_entry "host_uuid_source"
   | int_entry "ovs_timeout"
+  | int_entry "netlink_sock_buffer_size"
 
(* Each enty in the config is one of the following three ... *)
let entry = network_entry
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index a558458..34db23a 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -648,6 +648,16 @@ daemonSetupNetDevOpenvswitch(struct daemonConfig *config)
 
 
 /*
+ * Set up the netlink socket  buffer size
+ */
+static void
+daemonSetupNetLink(struct daemonConfig *config)
+{
+virNetLinkSetBufferSize(config->netlink_sock_buffer_size);
+}
+
+
+/*
  * Set up the logging environment
  * By default if daemonized all errors go to the logfile libvirtd.log,
  * but if verbose or error debugging is asked for then also output
@@ -1257,6 +1267,8 @@ int main(int argc, char **argv) {
 exit(EXIT_FAILURE);
 }
 
+daemonSetupNetLink(config);
+
 daemonSetupNetDevOpenvswitch(config);
 
 if (daemonSetupAccessManager(config) < 0) {
diff --git a/daemon/libvirtd.conf b/daemon/libvirtd.conf
index e83e9a1..b174767 100644
--- a/daemon/libvirtd.conf
+++ b/daemon/libvirtd.conf
@@ -476,3 +476,6 @@
 # potential infinite waits blocking libvirt.
 #
 #ovs_timeout = 5
+
+# This allow to specify buffer size for netlink socket.
+#netlink_sock_buffer_size = 131072
diff --git a/daemon/test_libvirtd.aug.in b/daemon/test_libvirtd.aug.in
index 1200952..0a1207f 100644
--- a/daemon/test_libvirtd.aug.in
+++ b/daemon/test_libvirtd.aug.in
@@ -64,3 +64,4 @@ module Test_libvirtd =
 { "admin_keepalive_interval" = "5" }
 { "admin_keepalive_count" = "5" }
 { "ovs_timeout" = "5" }
+{ "netlink_sock_buffer_size" = "131072" }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 888412a..83be39d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2248,6 +2248,7 @@ virNetlinkEventServiceStart;
 virNetlinkEventServiceStop;
 virNetlinkEventServiceStopAll;
 virNetlinkGetErrorCode;
+virNetLinkSetBufferSize;
 virNetlinkShutdown;
 virNetlinkStartup;
 
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index d732fe8..0a549b7 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -49,6 +49,7 @@ VIR_LOG_INIT("util.netlink");
 
 #define NETLINK_ACK_TIMEOUT_S  (2*1000)
 
+
 #if defined(__linux__) && defined(HAVE_LIBNL)
 /* State for a single netlink event handle */
 struct virNetlinkEventHandle {
@@ -104,6 +105,22 @@ static int nextWatch = 1;
 static virNetlinkEventSrvPrivatePtr server[MAX_LINKS] = {NU

[libvirt] [PATCH] util: increase libnl buffer size to 1M

2017-06-29 Thread ZhiPeng Lu
nl_recv() returns the error "No buffer space available"
when using virsh destroy domain with 240 or more
passhthrough network interfaces.
The patch increases libnl sock receive buffer size to 1M,
and nl_recv() doesn't return error when destroying domain
with 512 network interfaces.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/util/virnetlink.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index 92ecf77..bb56c54 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -189,10 +189,10 @@ virNetlinkCreateSocket(int protocol)
 goto error;
 }
 
-if (virNetlinkSetBufferSize(nlhandle, 131702, 0) < 0) {
+if (virNetlinkSetBufferSize(nlhandle, 1048576, 0) < 0) {
 virReportSystemError(errno, "%s",
  _("cannot set netlink socket buffer "
-   "size to 128k"));
+   "size to 1M"));
 goto error;
 }
 nl_socket_enable_msg_peek(nlhandle);
-- 
1.8.3.1


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


[libvirt] [v2 RESEND PATCH] qemu: reduce packet loss rate for vm with macvtap passthrough mode in migration

2017-06-13 Thread ZhiPeng Lu
Before libvirt that calls virNetDevMacVLanCreateWithVPortProfile sets mac 
address
or vlan of a Virtual Function(VF) linked to a macvtap passthrough device of 
migration
destination host in migration start step. If we ping the migrating vm,
we get the network does not pass. Because VFs of migration source and 
destination
have the same MAC address. The patch later calling 
qemuMigrationVPAssociatePortProfiles
sets mac address of VF in migration finish step instead of start step.
The patch aims to reduce packet loss rate.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_migration.c   | 18 --
 src/util/virnetdevmacvlan.c | 17 +++--
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 09adb04..795ed71 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5004,7 +5004,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
 }
 
 static int
-qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
+qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def, const char *stateDir)
 {
 size_t i;
 int last_good_net = -1;
@@ -5013,6 +5013,20 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
 for (i = 0; i < def->nnets; i++) {
 net = def->nets[i];
 if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+if ((!virDomainNetGetActualVirtPortProfile(net) || 
(virDomainNetGetActualVirtPortProfile(net) &&
+ virDomainNetGetActualVirtPortProfile(net)->virtPortType != 
VIR_NETDEV_VPORT_PROFILE_8021QBG &&
+virDomainNetGetActualVirtPortProfile(net)->virtPortType != 
VIR_NETDEV_VPORT_PROFILE_8021QBH)) &&
+virDomainNetGetActualDirectMode(net) ==
+ VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
+if (virNetDevSaveNetConfig(virDomainNetGetActualDirectDev(net),
+-1, stateDir, false) < 0) {
+goto err_exit;
+}
+if (virNetDevSetNetConfig(virDomainNetGetActualDirectDev(net),
+-1, NULL, virDomainNetGetActualVlan(net), >mac, 
false) < 0) {
+goto err_exit;
+}
+}
 if (virNetDevVPortProfileAssociate(net->ifname,

virDomainNetGetActualVirtPortProfile(net),
>mac,
@@ -5187,7 +5201,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
 goto endjob;
 }
 
-if (qemuMigrationVPAssociatePortProfiles(vm->def) < 0)
+if (qemuMigrationVPAssociatePortProfiles(vm->def, cfg->stateDir) < 0)
 goto endjob;
 
 if (mig->network && qemuDomainMigrateOPDRelocate(driver, vm, mig) < 0)
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 7222b0f..682dcd1 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -1020,12 +1020,17 @@ virNetDevMacVLanCreateWithVPortProfile(const char 
*ifnameRequested,
  */
 setVlan = false;
 }
-
-if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0)
-   return -1;
-
-if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress, 
setVlan) < 0)
-   return -1;
+if (vmOp != VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START &&
+virtPortProfile && (virtPortProfile->virtPortType == 
VIR_NETDEV_VPORT_PROFILE_8021QBH ||
+virtPortProfile->virtPortType == 
VIR_NETDEV_VPORT_PROFILE_8021QBG)) {
+if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0) {
+return -1;
+}
+if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress,
+setVlan) < 0) {
+return -1;
+}
+}
 }
 
 if (ifnameRequested) {
-- 
1.8.3.1


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


[libvirt] [PATCH v2] qemu: reduce packet loss rate for vm with macvtap passthrough mode in migration

2017-05-11 Thread ZhiPeng Lu
Before libvirt that calls virNetDevMacVLanCreateWithVPortProfile sets mac 
address
or vlan of a Virtual Function(VF) linked to a macvtap passthrough device of 
migration
destination host in migration start step. If we ping the migrating vm,
we get the network does not pass. Because VFs of migration source and 
destination
have the same MAC address. The patch later calling 
qemuMigrationVPAssociatePortProfiles
sets mac address of VF in migration finish step instead of start step.
The patch aims to reduce packet loss rate.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_migration.c   | 18 --
 src/util/virnetdevmacvlan.c | 17 +++--
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 09adb04..795ed71 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5004,7 +5004,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
 }
 
 static int
-qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
+qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def, const char *stateDir)
 {
 size_t i;
 int last_good_net = -1;
@@ -5013,6 +5013,20 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
 for (i = 0; i < def->nnets; i++) {
 net = def->nets[i];
 if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+if ((!virDomainNetGetActualVirtPortProfile(net) || 
(virDomainNetGetActualVirtPortProfile(net) &&
+ virDomainNetGetActualVirtPortProfile(net)->virtPortType != 
VIR_NETDEV_VPORT_PROFILE_8021QBG &&
+virDomainNetGetActualVirtPortProfile(net)->virtPortType != 
VIR_NETDEV_VPORT_PROFILE_8021QBH)) &&
+virDomainNetGetActualDirectMode(net) ==
+ VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
+if (virNetDevSaveNetConfig(virDomainNetGetActualDirectDev(net),
+-1, stateDir, false) < 0) {
+goto err_exit;
+}
+if (virNetDevSetNetConfig(virDomainNetGetActualDirectDev(net),
+-1, NULL, virDomainNetGetActualVlan(net), >mac, 
false) < 0) {
+goto err_exit;
+}
+}
 if (virNetDevVPortProfileAssociate(net->ifname,

virDomainNetGetActualVirtPortProfile(net),
>mac,
@@ -5187,7 +5201,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
 goto endjob;
 }
 
-if (qemuMigrationVPAssociatePortProfiles(vm->def) < 0)
+if (qemuMigrationVPAssociatePortProfiles(vm->def, cfg->stateDir) < 0)
 goto endjob;
 
 if (mig->network && qemuDomainMigrateOPDRelocate(driver, vm, mig) < 0)
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 7222b0f..682dcd1 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -1020,12 +1020,17 @@ virNetDevMacVLanCreateWithVPortProfile(const char 
*ifnameRequested,
  */
 setVlan = false;
 }
-
-if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0)
-   return -1;
-
-if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress, 
setVlan) < 0)
-   return -1;
+if (vmOp != VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START &&
+virtPortProfile && (virtPortProfile->virtPortType == 
VIR_NETDEV_VPORT_PROFILE_8021QBH ||
+virtPortProfile->virtPortType == 
VIR_NETDEV_VPORT_PROFILE_8021QBG)) {
+if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0) {
+return -1;
+}
+if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress,
+setVlan) < 0) {
+return -1;
+}
+}
 }
 
 if (ifnameRequested) {
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: reduce packet loss rate for vm with macvtap passthrough mode in migration

2017-05-11 Thread ZhiPeng Lu
Before libvirt that calls virNetDevMacVLanCreateWithVPortProfile sets mac 
address
or vlan of a Virtual Function(VF) linked to a macvtap passthrough device of 
migration
destination host in migration start step. If we ping the migrating vm,
we get the network does not pass. Because VFs of migration source and 
destination
have the same MAC address. The patch later calling 
qemuMigrationVPAssociatePortProfiles
sets mac address of VF in migration finish step instead of start step.
The patch aims to reduce packet loss rate.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_migration.c   | 17 +++--
 src/util/virnetdevmacvlan.c | 17 +++--
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 09adb04..0308043 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5004,7 +5004,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
 }
 
 static int
-qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
+qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def, const char *stateDir)
 {
 size_t i;
 int last_good_net = -1;
@@ -5013,6 +5013,19 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
 for (i = 0; i < def->nnets; i++) {
 net = def->nets[i];
 if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
+if (virDomainNetGetActualVirtPortProfile(net) != 
VIR_NETDEV_VPORT_PROFILE_8021QBG &&
+virDomainNetGetActualVirtPortProfile(net) != 
VIR_NETDEV_VPORT_PROFILE_8021QBH &&
+(virDomainNetGetActualDirectMode(net) ==
+ VIR_NETDEV_MACVLAN_MODE_PASSTHRU)) {
+if (virNetDevSaveNetConfig(virDomainNetGetActualDirectDev(net),
+-1, stateDir, false) < 0) {
+goto err_exit;
+}
+if (virNetDevSetNetConfig(virDomainNetGetActualDirectDev(net),
+-1, NULL, virDomainNetGetActualVlan(net), >mac, 
false) < 0) {
+goto err_exit;
+}
+}
 if (virNetDevVPortProfileAssociate(net->ifname,

virDomainNetGetActualVirtPortProfile(net),
>mac,
@@ -5187,7 +5200,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
 goto endjob;
 }
 
-if (qemuMigrationVPAssociatePortProfiles(vm->def) < 0)
+if (qemuMigrationVPAssociatePortProfiles(vm->def, cfg->stateDir) < 0)
 goto endjob;
 
 if (mig->network && qemuDomainMigrateOPDRelocate(driver, vm, mig) < 0)
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 7222b0f..fc08c43 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -1020,12 +1020,17 @@ virNetDevMacVLanCreateWithVPortProfile(const char 
*ifnameRequested,
  */
 setVlan = false;
 }
-
-if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0)
-   return -1;
-
-if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress, 
setVlan) < 0)
-   return -1;
+if (vmOp != VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_START &&
+(virtPortProfile == VIR_NETDEV_VPORT_PROFILE_8021QBH ||
+virtPortProfile == VIR_NETDEV_VPORT_PROFILE_8021QBG)) {
+if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0) {
+return -1;
+}
+if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress,
+setVlan) < 0) {
+return -1;
+}
+}
 }
 
 if (ifnameRequested) {
-- 
1.8.3.1


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


[libvirt] [PATCH] nodedev_udev: Fix missing events when kernel report lots of udev events within a short time

2017-05-08 Thread ZhiPeng Lu
From: "ning.bo" 

When create Virtual Function for Inter XL710 use below commands:
for i in `seq 0 1`; do
echo 63 > 
/sys/devices/pci:00/:00:03.2/:07:00.$i/sriov_numvfs
done
for i in `seq 0 3`; do
echo 31 > 
/sys/devices/pci:80/:80:02.2/:82:00.$i/sriov_numvfs
done

The libvirtd will missing some udev events, the result of libvirt-python API
listDevices('pci') will not list all pci devices.
The reason is that the buffer of udev monitor default size cann't save all udev
events reported by kernel.
So we need change buffer size so that we can receive as much events as possible
whitin a short time.

Signed-off-by: ning.bo 
---
 src/node_device/node_device_udev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index 6e706a1..d813206 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1564,6 +1564,7 @@ static int nodeStateInitialize(bool privileged,
 }
 
 udev_monitor_enable_receiving(priv->udev_monitor);
+udev_monitor_set_receive_buffer_size(priv->udev_monitor, 128 * 1024 * 
1024);
 
 /* We register the monitor with the event callback so we are
  * notified by udev of device changes before we enumerate existing
-- 
2.8.3


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


[libvirt] [PATCH v2] qemu: clean up network interfaces before qemuProcessKill is called in qemuProcessStop

2017-05-08 Thread ZhiPeng Lu
In qemuProcessStop we explicitly remove the port from the openvswitch bridge 
after
qemuProcessKill is called. But there is a certain interval of time between
deleting tap device and removing it from bridge. The problem occurs when two vms
start and shutdown with the same name's network interface attached to the same
openvswitch bridge. When one vm with the nic named "vnet0" stopping, it deleted
tap device without timely removing the port from bridge.
At this time, another vm created the tap device named "vnet0" and added port to 
the
same bridge. Then, the first vm removed the port from the same bridge.
Finally, the tap device of the second vm did not attached to the bridge.
We need to delete the bridge port before deleting the tap device instead of 
after.
So what's needed is to move the loop in qemuProcessStop that cleans up
network interfaces so that it happens before qemuProcessKill is called.

Signed-off-by: Zhipeng Lu <lu.zhip...@zte.com.cn>
Signed-off-by: Laine Stump <la...@laine.org>
---
 src/qemu/qemu_process.c | 99 -
 1 file changed, 49 insertions(+), 50 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 53170d7..f76ced1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6253,56 +6253,6 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 qemuProcessCleanupChardevDevice,
 NULL));
 
-
-/* shut it off for sure */
-ignore_value(qemuProcessKill(vm,
- VIR_QEMU_PROCESS_KILL_FORCE|
- VIR_QEMU_PROCESS_KILL_NOCHECK));
-
-qemuDomainCleanupRun(driver, vm);
-
-/* Stop autodestroy in case guest is restarted */
-qemuProcessAutoDestroyRemove(driver, vm);
-
-/* now that we know it's stopped call the hook if present */
-if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
-char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
-
-/* we can't stop the operation even if the script raised an error */
-ignore_value(virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
- VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END,
- NULL, xml, NULL));
-VIR_FREE(xml);
-}
-
-/* Reset Security Labels unless caller don't want us to */
-if (!(flags & VIR_QEMU_PROCESS_STOP_NO_RELABEL))
-qemuSecurityRestoreAllLabel(driver, vm,
-!!(flags & 
VIR_QEMU_PROCESS_STOP_MIGRATED));
-
-qemuSecurityReleaseLabel(driver->securityManager, vm->def);
-
-for (i = 0; i < vm->def->ndisks; i++) {
-virDomainDeviceDef dev;
-virDomainDiskDefPtr disk = vm->def->disks[i];
-
-dev.type = VIR_DOMAIN_DEVICE_DISK;
-dev.data.disk = disk;
-ignore_value(qemuRemoveSharedDevice(driver, , vm->def->name));
-}
-
-/* Clear out dynamically assigned labels */
-for (i = 0; i < vm->def->nseclabels; i++) {
-if (vm->def->seclabels[i]->type == VIR_DOMAIN_SECLABEL_DYNAMIC)
-VIR_FREE(vm->def->seclabels[i]->label);
-VIR_FREE(vm->def->seclabels[i]->imagelabel);
-}
-
-virStringListFree(priv->qemuDevices);
-priv->qemuDevices = NULL;
-
-qemuHostdevReAttachDomainDevices(driver, vm->def);
-
 def = vm->def;
 for (i = 0; i < def->nnets; i++) {
 virDomainNetDefPtr net = def->nets[i];
@@ -6360,6 +6310,55 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 networkReleaseActualDevice(vm->def, net);
 }
 
+/* shut it off for sure */
+ignore_value(qemuProcessKill(vm,
+ VIR_QEMU_PROCESS_KILL_FORCE|
+ VIR_QEMU_PROCESS_KILL_NOCHECK));
+
+qemuDomainCleanupRun(driver, vm);
+
+/* Stop autodestroy in case guest is restarted */
+qemuProcessAutoDestroyRemove(driver, vm);
+
+/* now that we know it's stopped call the hook if present */
+if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
+char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
+
+/* we can't stop the operation even if the script raised an error */
+ignore_value(virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
+ VIR_HOOK_QEMU_OP_STOPPED, VIR_HOOK_SUBOP_END,
+ NULL, xml, NULL));
+VIR_FREE(xml);
+}
+
+/* Reset Security Labels unless caller don't want us to */
+if (!(flags & VIR_QEMU_PROCESS_STOP_NO_RELABEL))
+qemuSecurityRestoreAllLabel(driver, vm,
+!!(flags & 
VIR_QEMU_PROCESS_STOP_MIGRATED));
+
+qemuSecurityReleaseLabel(driver->securityManager, vm->def);
+
+for (i = 0; i < vm->def->ndisks; i+

[libvirt] [PATCH] qemu: change the name of tap device for a tap and bridge network

2017-04-28 Thread ZhiPeng Lu
Creating tap device and adding the device to bridge are not atomic operation.
Similarly deleting tap device and removing it from bridge are not atomic 
operation.
The Problem occurs when two vms start and shutdown. When one vm with the nic
named "vnet0" stopping, it deleted tap device but not removing port from bridge.
At this time, another vm created the tap device named "vnet0" and added port to 
the
same bridge. Then, the first vm deleted the tap device from the same bridge.
Finally, the tap device of the second vm don't attached to the bridge.
So, we can add domid to vm's nic name. For example, the vm's domid is 1 and 
vnet0
is renamed to vnet1.0.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_interface.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index d0850c0..17d40a7 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -512,6 +512,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
 bool template_ifname = false;
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 const char *tunpath = "/dev/net/tun";
+char *domIdPlusIndex = NULL;
 
 if (net->backend.tap) {
 tunpath = net->backend.tap;
@@ -531,8 +532,13 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
 STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
 strchr(net->ifname, '%')) {
 VIR_FREE(net->ifname);
-if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_PREFIX "%d") < 0)
+if (virAsprintf(, "%s%d.%s",
+   VIR_NET_GENERATED_PREFIX, def->id, "%d") < 0) {
+goto cleanup;
+}
+if (VIR_STRDUP(net->ifname, domIdPlusIndex) < 0) {
 goto cleanup;
+}
 /* avoid exposing vnet%d in getXMLDesc or error outputs */
 template_ifname = true;
 }
@@ -594,6 +600,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
 ret = 0;
 
  cleanup:
+VIR_FREE(domIdPlusIndex);
 if (ret < 0) {
 size_t i;
 for (i = 0; i < *tapfdSize && tapfd[i] >= 0; i++)
-- 
1.8.3.1


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


[libvirt] [PATCH] virsh-domain: update attach-interface to support bridge type

2017-04-25 Thread ZhiPeng Lu
Adding this feature will allow users to attach a network to linux bridge
or openvswitch. The interface can be attached using --brtype=linux or
--brtype=openvswitch. If --brtype is not set, the network is attached
to linux bridge.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 tools/virsh-domain.c | 23 +--
 tools/virsh.pod  |  3 +++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index db8accf..2690689 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -766,6 +766,10 @@ static const vshCmdOptDef opts_attach_interface[] = {
  .type = VSH_OT_BOOL,
  .help = N_("libvirt will automatically detach/attach the device from/to 
host")
 },
+{.name = "brtype",
+ .type = VSH_OT_STRING,
+ .help = N_("Bridge type: linux / openvswitch")
+},
 {.name = NULL}
 };
 
@@ -819,7 +823,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
 virDomainPtr dom = NULL;
 const char *mac = NULL, *target = NULL, *script = NULL,
*type = NULL, *source = NULL, *model = NULL,
-   *inboundStr = NULL, *outboundStr = NULL;
+   *inboundStr = NULL, *outboundStr = NULL,
+   *brtype = NULL;
 virNetDevBandwidthRate inbound, outbound;
 virDomainNetType typ;
 int ret;
@@ -850,7 +855,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
 vshCommandOptStringReq(ctl, cmd, "script", ) < 0 ||
 vshCommandOptStringReq(ctl, cmd, "model", ) < 0 ||
 vshCommandOptStringReq(ctl, cmd, "inbound", ) < 0 ||
-vshCommandOptStringReq(ctl, cmd, "outbound", ) < 0)
+vshCommandOptStringReq(ctl, cmd, "outbound", ) < 0 ||
+vshCommandOptStringReq(ctl, cmd, "brtype", ) < 0)
 goto cleanup;
 
 /* check interface type */
@@ -946,6 +952,19 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
 if (model != NULL)
 virBufferAsprintf(, "\n", model);
 
+if ((brtype != NULL)) {
+if (STRNEQ(brtype , "linux") && STRNEQ(brtype , "openvswitch")) {
+vshError(ctl, _("bridge type is incorrect, should be linux "
+"or openvswitch"));
+goto cleanup;
+}
+if (typ != VIR_DOMAIN_NET_TYPE_BRIDGE) {
+vshError(ctl, _("No support for %s with bridge type"), type);
+goto cleanup;
+}
+if (STREQ(brtype , "openvswitch"))
+virBufferAsprintf(, "  \n");
+}
 if (inboundStr || outboundStr) {
 virBufferAddLit(, "\n");
 virBufferAdjustIndent(, 2);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e16f62f..3cd0490 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2935,6 +2935,9 @@ B<--managed> is usable only for I type and tells 
libvirt
 that the interface should be managed, which means detached and reattached
 from/to the host by libvirt.
 
+B<--brtype> is usable only for I type and tells libvirt
+that the interface attached to bridge type (linux bridge or openvswitch).
+
 If B<--print-xml> is specified, then the XML of the interface that would be
 attached is printed instead.
 
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: fix argument of virDomainNetGetActualDirectMode

2017-04-25 Thread ZhiPeng Lu
it should be a comparison of modes between new and old devices. So 
the argument of the second virDomainNetGetActualDirectMode should be 
newdev.

Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
---
 src/qemu/qemu_hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 120bcdc..eec99af 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3273,7 +3273,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
 
 if (STRNEQ_NULLABLE(virDomainNetGetActualDirectDev(olddev),
 virDomainNetGetActualDirectDev(newdev)) ||
-virDomainNetGetActualDirectMode(olddev) != 
virDomainNetGetActualDirectMode(olddev) ||
+virDomainNetGetActualDirectMode(olddev) != 
virDomainNetGetActualDirectMode(newdev) ||
 
!virNetDevVPortProfileEqual(virDomainNetGetActualVirtPortProfile(olddev),
 
virDomainNetGetActualVirtPortProfile(newdev)) ||
 !virNetDevVlanEqual(virDomainNetGetActualVlan(olddev),
-- 
1.8.3.1


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