[PATCH][RESEND] processMonitorEOFEvent:fix delet Domain object about the new VM in processMonitorEOFEvent()

2022-04-26 Thread Yi Wang
From: 王鹏钧10288409 <10288409@zte.in...@lin-184c297bae7.zte.com.cn>

Virsh shutdown is executed firstly, virsh destroy is executed later,
and VM is recreated again. In this process, due to will delet Domain
object about the new VM in processMonitorEOFEvent(), which
virDomainObjListRemove is called to remove objlist, the new VM
cannot be found through virsh list command and qemu process is still
running. Therefore, add virDomainObjListFindByName function checks
to avoid delet Domain object about the new VM in objlist.

This process chart of problem is as follows

 shutdown   |  destroy |   create
+==+===
  qemuMonitorIO |  |
qemuProcessHandleMonitorEOF |  |
| virDomainDestroy |
|  qemuProcessStop |
|  | qemuDomainCreateXML
|  | qemuProcessInit
 processMonitorEOFEvent |  |
   qemuDomainRemoveInactive |  |
|  |   qemuProcessLaunch

Signed-off-by: Wang PengJun 
Signed-off-by: Yi Wang 
---
 src/qemu/qemu_driver.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ee0963c30d..a504f89724 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4024,6 +4024,7 @@ processMonitorEOFEvent(virQEMUDriver *driver,
 const char *auditReason = "shutdown";
 unsigned int stopFlags = 0;
 virObjectEvent *event = NULL;
+virDomainObj *obj;
 
 if (qemuProcessBeginStopJob(driver, vm, VIR_JOB_DESTROY, true) < 0)
 return;
@@ -4055,7 +4056,12 @@ processMonitorEOFEvent(virQEMUDriver *driver,
 virObjectEventStateQueue(driver->domainEventState, event);
 
  endjob:
-qemuDomainRemoveInactive(driver, vm);
+virObjectUnlock(vm);
+obj = virDomainObjListFindByName(driver->domains, vm->def->name);
+if (vm == obj)
+qemuDomainRemoveInactive(driver, vm);
+virDomainObjEndAPI();
+virObjectLock(vm);
 qemuDomainObjEndJob(vm);
 }
 
-- 
2.27.0



[PATCH] processMonitorEOFEvent:fix delet Domain object about the new VM in processMonitorEOFEvent()

2022-04-11 Thread Yi Wang
From: 王鹏钧10288409 <10288409@zte.in...@lin-184c297bae7.zte.com.cn>

Virsh shutdown is executed firstly, virsh destroy is executed later,
and VM is recreated again. In this process, due to will delet Domain
object about the new VM in processMonitorEOFEvent(), which
virDomainObjListRemove is called to remove objlist, the new VM
cannot be found through virsh list command and qemu process is still
running. Therefore, add virDomainObjListFindByName function checks
to avoid delet Domain object about the new VM in objlist.

This process chart of problem is as follows

 shutdown   |  destroy |   create
+==+===
  qemuMonitorIO |  |
qemuProcessHandleMonitorEOF |  |
| virDomainDestroy |
|  qemuProcessStop |
|  | qemuDomainCreateXML
|  | qemuProcessInit
 processMonitorEOFEvent |  |
   qemuDomainRemoveInactive |  |
|  |   qemuProcessLaunch

Signed-off-by: Wang PengJun 
Signed-off-by: Yi Wang 
---
 src/qemu/qemu_driver.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8c0e36e9b2..c16e9a9795 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4024,6 +4024,7 @@ processMonitorEOFEvent(virQEMUDriver *driver,
 const char *auditReason = "shutdown";
 unsigned int stopFlags = 0;
 virObjectEvent *event = NULL;
+virDomainObj *obj;
 
 if (qemuProcessBeginStopJob(driver, vm, VIR_JOB_DESTROY, true) < 0)
 return;
@@ -4055,8 +4056,17 @@ processMonitorEOFEvent(virQEMUDriver *driver,
 virObjectEventStateQueue(driver->domainEventState, event);
 
  endjob:
-qemuDomainRemoveInactive(driver, vm);
-qemuDomainObjEndJob(vm);
+virObjectUnlock(vm);
+obj = virDomainObjListFindByName(driver->domains, vm->def->name);
+if (vm == obj) {
+qemuDomainRemoveInactive(driver, vm);
+qemuDomainObjEndJob(vm);
+}
+virDomainObjEndAPI();
+if (vm != NULL) {
+virObjectLock(vm);
+qemuDomainObjEndJob(vm);
+}
 }
 
 
-- 
2.27.0



[PATCH] virNetDevOpenvswitchUpdateVlan: fix vlan tag update error

2022-02-08 Thread Yi Wang
From: tuqiang 

We try to update vlan tag by running virsh update-device command,
libvirtd will report ovs-vsctl arguments error. Vlan tag update
funtion does't consider the xml with no vlan configured circumstances.

The steps to reproduce the problem:
1 define and start domain with its vlan configured as:

  
  
  

  
  
  
  
  
  

2 define and run virsh update-device command with no vlan configured as:

  
  
  
  
  
  
  

   #virsh update-device dom-id novlan.xml
3 virsh command returned error, and we got an error in libvirtd.log:
  error : virCommandWait:2584 : internal error: exit status 1: ovs-vsctl: 'set' 
command requires at least 3 arguments
  . Child process (ovs-vsctl --timeout=5 -- --if-exists clear Port vnet4.0 tag 
-- --if-exists clear Port vnet4.0 trunk
  -- --if-exists clear Port vnet4.0 vlan_mode -- --if-exists set Port vnet4.0) 
unexpected
  error : virNetDevOpenvswitchUpdateVlan:540 : internal error: Unable to set 
vlan configuration on port vnet4.0

Signed-off-by: Tu Qiang 
Signed-off-by: Yi Wang 
---
 src/util/virnetdevopenvswitch.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index bcdb7c4..227c040 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -605,8 +605,10 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname,
 virCommandAddArgList(cmd,
  "--", "--if-exists", "clear", "Port", ifname, "tag",
  "--", "--if-exists", "clear", "Port", ifname, "trunk",
- "--", "--if-exists", "clear", "Port", ifname, 
"vlan_mode",
- "--", "--if-exists", "set", "Port", ifname, NULL);
+ "--", "--if-exists", "clear", "Port", ifname, 
"vlan_mode", NULL);
+
+   if (virtVlan && virtVlan->nTags > 0)
+   virCommandAddArgList(cmd, "--", "--if-exists", "set", "Port", 
ifname, NULL);
 
 virNetDevOpenvswitchConstructVlans(cmd, virtVlan);
 
-- 
1.8.3.1




[PATCH] util: virExec may blocked by reading pipe if grandchild prematurely exit

2021-11-23 Thread Yi Wang
From: Xu Chao 

When VIR_EXEC_DAEMON is set, if virPidFileAcquirePath/virSetInherit failed,
then pipesync[0] can not be closed when granchild process exit, because
pipesync[1] still opened in child process. and then saferead in child
process may blocked forever, and left grandchild process in defunct state.

Signed-off-by: Xu Chao 
Signed-off-by: Yi Wang 
---
 src/util/vircommand.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index fead373729..fa71f40d81 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -782,6 +782,9 @@ virExec(virCommand *cmd)
 }
 
 if (pid > 0) {
+/* close pipe[1], then the pipe can be closed if grandchild
+ * died prematurely */
+VIR_FORCE_CLOSE(pipesync[1]);
 /* The parent expect us to have written the pid file before
  * exiting. Wait here for the child to write it and signal us. */
 if (cmd->pidfile &&
-- 
2.27.0




[PATCH] util: fix: duplicated index at nested loop in virNVMeDeviceListCreateReAttachList

2021-07-28 Thread Yi Wang
From: Jia Zhou 

When loop in function virNVMeDeviceListCreateReAttachList() there may be
reused index @i, this patch fix this by using a new @j.

Signed-off-by: Jia Zhou 
Signed-off-by: Yi Wang 
---
 src/util/virnvme.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/virnvme.c b/src/util/virnvme.c
index 49102e3..b54a195 100644
--- a/src/util/virnvme.c
+++ b/src/util/virnvme.c
@@ -399,7 +399,7 @@ virNVMeDeviceListCreateReAttachList(virNVMeDeviceListPtr 
activeList,
 virNVMeDeviceListPtr toReAttachList)
 {
 g_autoptr(virPCIDeviceList) pciDevices = NULL;
-size_t i;
+size_t i, j;
 
 if (!(pciDevices = virPCIDeviceListNew()))
 return NULL;
@@ -412,8 +412,8 @@ virNVMeDeviceListCreateReAttachList(virNVMeDeviceListPtr 
activeList,
 /* Check if there is any other NVMe device with the same PCI address as
  * @d. To simplify this, let's just count how many NVMe devices with
  * the same PCI address there are on the @activeList. */
-for (i = 0; i < activeList->count; i++) {
-virNVMeDevicePtr other = activeList->devs[i];
+for (j = 0; j < activeList->count; j++) {
+virNVMeDevicePtr other = activeList->devs[j];
 
 if (!virPCIDeviceAddressEqual(>address, >address))
 continue;
-- 
1.8.3.1

[PATCH] qemu: Fix error returned value in qemuGetProcessInfo when fscanf execute failed

2021-07-15 Thread Yi Wang
From: Long YunJian 

If fscanf execute failed, qemuGetProcessInfo shuld return -1,
but it return 0 at the end. Zero means success for the caller,
so we shuld return -1 in the case of failure.

Signed-off-by: Long YunJian 
Signed-off-by: Yi Wang 
---
 src/qemu/qemu_driver.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index df44c3fbd0..4c3785fa36 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1442,11 +1442,13 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int 
*lastCpu, long *vm_rss,
 return -1;
 
 pidinfo = fopen(proc, "r");
+if (!pidinfo) {
+return -1;
+}
 
 /* See 'man proc' for information about what all these fields are. We're
  * only interested in a very few of them */
-if (!pidinfo ||
-fscanf(pidinfo,
+if (fscanf(pidinfo,
/* pid -> stime */
"%*d (%*[^)]) %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu 
%llu"
/* cutime -> endcode */
@@ -1455,6 +1457,8 @@ qemuGetProcessInfo(unsigned long long *cpuTime, int 
*lastCpu, long *vm_rss,
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
, , , ) != 4) {
 VIR_WARN("cannot parse process status data");
+VIR_FORCE_FCLOSE(pidinfo);
+return -1;
 }
 
 /* We got jiffies
-- 
2.18.1

[PATCH] conf: Remove superfluous breaks

2020-07-16 Thread Yi Wang
From: Liao Pingfang 

Remove superfluous breaks, as there is a "return" before them.

Signed-off-by: Liao Pingfang 
Signed-off-by: Yi Wang 
---
 src/conf/domain_conf.c |  6 --
 src/conf/network_conf.c| 12 
 src/conf/nwfilter_params.c |  4 
 3 files changed, 22 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bcebfc6..355aa74 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1840,7 +1840,6 @@ const char *virDomainInputDefGetPath(virDomainInputDefPtr 
input)
 case VIR_DOMAIN_INPUT_TYPE_KBD:
 case VIR_DOMAIN_INPUT_TYPE_LAST:
 return NULL;
-break;
 
 case VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH:
 return input->source.evdev;
@@ -2728,7 +2727,6 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef 
*src,
 case VIR_DOMAIN_CHR_TYPE_DEV:
 case VIR_DOMAIN_CHR_TYPE_PIPE:
 return STREQ_NULLABLE(src->data.file.path, tgt->data.file.path);
-break;
 case VIR_DOMAIN_CHR_TYPE_NMDM:
 return STREQ_NULLABLE(src->data.nmdm.master, tgt->data.nmdm.master) &&
 STREQ_NULLABLE(src->data.nmdm.slave, tgt->data.nmdm.slave);
@@ -8425,7 +8423,6 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr 
sourcenode,
_("Invalid hostdev protocol '%s'"),

virDomainHostdevSubsysSCSIHostProtocolTypeToString(hostsrc->protocol));
 return -1;
-break;
 }
 
 return 0;
@@ -18139,13 +18136,11 @@ virDomainChrEquals(virDomainChrDefPtr src,
 case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_XEN:
 case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
 return STREQ_NULLABLE(src->target.name, tgt->target.name);
-break;
 case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
 if (!src->target.addr || !tgt->target.addr)
 return src->target.addr == tgt->target.addr;
 return memcmp(src->target.addr, tgt->target.addr,
   sizeof(*src->target.addr)) == 0;
-break;
 
 case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_NONE:
 case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST:
@@ -18163,7 +18158,6 @@ virDomainChrEquals(virDomainChrDefPtr src,
 case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
 case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
 return src->target.port == tgt->target.port;
-break;
 case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
 /* shouldn't happen */
 break;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 0fd68a7..4221623 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -3682,48 +3682,36 @@ virNetworkDefUpdateSection(virNetworkDefPtr def,
 switch (section) {
 case VIR_NETWORK_SECTION_BRIDGE:
 return virNetworkDefUpdateBridge(def, command, parentIndex, ctxt, 
flags);
-break;
 
 case VIR_NETWORK_SECTION_DOMAIN:
 return virNetworkDefUpdateDomain(def, command, parentIndex, ctxt, 
flags);
-break;
 case VIR_NETWORK_SECTION_IP:
 return virNetworkDefUpdateIP(def, command, parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_IP_DHCP_HOST:
 return virNetworkDefUpdateIPDHCPHost(def, command,
  parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_IP_DHCP_RANGE:
 return virNetworkDefUpdateIPDHCPRange(def, command,
   parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_FORWARD:
 return virNetworkDefUpdateForward(def, command,
   parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_FORWARD_INTERFACE:
 return virNetworkDefUpdateForwardInterface(def, command,
parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_FORWARD_PF:
 return virNetworkDefUpdateForwardPF(def, command,
 parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_PORTGROUP:
 return virNetworkDefUpdatePortGroup(def, command,
 parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_DNS_HOST:
 return virNetworkDefUpdateDNSHost(def, command,
   parentIndex, ctxt, flags);
-break;
 case VIR_NETWORK_SECTION_DNS_TXT:
 return virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, 
flags);
-break;
 case VIR_NETWORK_SECTION_DNS_SRV:
 return virNetworkDefUpdateDNSSrv(def, command, parentIndex, ctxt, 
flags);
-break;
 default:
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("

[PATCH] qemu: Remove superfluous breaks

2020-07-16 Thread Yi Wang
From: Liao Pingfang 

Remove superfluous breaks, as there is a "return" before them.

Signed-off-by: Liao Pingfang 
Signed-off-by: Yi Wang 
---
 src/qemu/qemu_firmware.c | 1 -
 src/qemu/qemu_hostdev.c  | 1 -
 2 files changed, 2 deletions(-)

diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c
index bd251c0..2edc0ef 100644
--- a/src/qemu/qemu_firmware.c
+++ b/src/qemu/qemu_firmware.c
@@ -,7 +,6 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver,
_("domain has SMM turned off "
  "but chosen firmware requires it"));
 return -1;
-break;
 case VIR_TRISTATE_SWITCH_ABSENT:
 VIR_DEBUG("Enabling SMM feature");
 def->features[VIR_DOMAIN_FEATURE_SMM] = VIR_TRISTATE_SWITCH_ON;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index fb63da2..d39f9d7 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -202,7 +202,6 @@ 
qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("host doesn't support legacy PCI passthrough"));
 return false;
-break;
 
 case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
 case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
-- 
2.9.5



[PATCH] security: Remove the superfluous break

2020-07-16 Thread Yi Wang
From: Liao Pingfang 

Remove the superfuous break, as there is a 'return' before it.

Signed-off-by: Liao Pingfang 
Signed-off-by: Yi Wang 
---
 src/security/security_apparmor.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 3f6a213..eea37dc 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -699,7 +699,6 @@ AppArmorSetMemoryLabel(virSecurityManagerPtr mgr,
 return -1;
 }
 return reload_profile(mgr, def, mem->nvdimmPath, true);
-break;
 case VIR_DOMAIN_MEMORY_MODEL_NONE:
 case VIR_DOMAIN_MEMORY_MODEL_DIMM:
 case VIR_DOMAIN_MEMORY_MODEL_LAST:
-- 
2.9.5



[PATCH] domain_conf: Replace the name string with 'vcpu' if it is 'vcpus'

2020-07-01 Thread Yi Wang
From: Liao Pingfang 

If the name is 'vcpus', we will get 'vcpussched' instead of 'vcpusched'
in the error message as following:

... 19155 : vcpussched attributes 'vcpus' must not overlap

So we use 'vcpu' to replace 'vcpus'.

Signed-off-by: Liao Pingfang 
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0c883cd..5dcc836 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20050,7 +20050,7 @@ virDomainThreadSchedParseHelper(xmlNodePtr node,
 if (sched->policy != VIR_PROC_POLICY_NONE) {
 virReportError(VIR_ERR_XML_DETAIL,
_("%ssched attributes 'vcpus' must not overlap"),
-   name);
+   STREQ(name, "vcpus") ? "vcpu" : name);
 return -1;
 }
 
-- 
2.9.5



[PATCH] qemu: Correct the log name for qemu_security.c

2020-06-23 Thread Yi Wang
From: Liao Pingfang 

Correct the log name for qemu_security.c to qemu.qemu_security
instead of qemu.qemu_process.

Signed-off-by: Liao Pingfang 
---
 src/qemu/qemu_security.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c
index f49c089..3b6d6e9 100644
--- a/src/qemu/qemu_security.c
+++ b/src/qemu/qemu_security.c
@@ -26,7 +26,7 @@
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
-VIR_LOG_INIT("qemu.qemu_process");
+VIR_LOG_INIT("qemu.qemu_security");
 
 
 int
-- 
2.9.5



[PATCH] qemu: hotplug: Fix the condition check for net->downscript

2020-05-29 Thread Yi Wang
From: Liao Pingfang 

According to the context, here we are checking net->downscript's validity,

Signed-off-by: Liao Pingfang 
---
 src/qemu/qemu_hotplug.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index d1a2be1..8c99dfc 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4672,9 +4672,8 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
 virDomainNetReleaseActualDevice(conn, vm->def, net);
 else
 VIR_WARN("Unable to release network device '%s'", 
NULLSTR(net->ifname));
-} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET) {
-if (net->script)
-   virNetDevRunEthernetScript(net->ifname, net->downscript);
+} else if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET && net->downscript) {
+virNetDevRunEthernetScript(net->ifname, net->downscript);
 }
 virDomainNetDefFree(net);
 return 0;
-- 
2.9.5



[PATCH v2] README.rst: Replace the installation instructions with link to compiling.html.

2020-05-18 Thread Yi Wang
From: Liao Pingfang 

Remove the installation instructions from README.rst, and
add the link to compiling.html.

Signed-off-by: Liao Pingfang 
---
Changes in v2: use compiling.html replace the installation instructions

 README.rst | 26 ++
 1 file changed, 2 insertions(+), 24 deletions(-)

diff --git a/README.rst b/README.rst
index cdcc97b..5d6ca55 100644
--- a/README.rst
+++ b/README.rst
@@ -45,31 +45,9 @@ and ``COPYING`` for full license terms & conditions.
 Installation
 
 
-Libvirt uses the GNU Autotools build system, so in general can be built
-and installed with the usual commands, however, we mandate to have the
-build directory different than the source directory. For example, to build
-in a manner that is suitable for installing as root, use:
-
-::
-
-  $ mkdir build && cd build
-  $ ../configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
-  $ make
-  $ sudo make install
-
-While to build & install as an unprivileged user
-
-::
-
-  $ mkdir build && cd build
-  $ ../configure --prefix=$HOME/usr
-  $ make
-  $ make install
-
-The libvirt code relies on a large number of 3rd party libraries. These will
-be detected during execution of the ``configure`` script and a summary printed
-which lists any missing (optional) dependencies.
+Instructions on building and installing libvirt can be found on the website:
 
+https://libvirt.org/compiling.html
 
 Contributing
 
-- 
2.9.5



[PATCH] README: Replace "configure" with "autogen.sh" for correct installation

2020-05-15 Thread Yi Wang
From: LiaoPingfang 

First of all, there is no "configure" file.
We need use autogen.sh at first to create "configure" file.
Then in autogen.sh "configure" will be executed according to
user as root or non-root.

Signed-off-by: Liao Pingfang 
---
 README.rst | 4 ++--
 autogen.sh | 4 
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/README.rst b/README.rst
index cdcc97b..82b4b31 100644
--- a/README.rst
+++ b/README.rst
@@ -53,7 +53,7 @@ in a manner that is suitable for installing as root, use:
 ::
 
   $ mkdir build && cd build
-  $ ../configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
+  $ ../autogen.sh
   $ make
   $ sudo make install
 
@@ -62,7 +62,7 @@ While to build & install as an unprivileged user
 ::
 
   $ mkdir build && cd build
-  $ ../configure --prefix=$HOME/usr
+  $ ../autogen.sh
   $ make
   $ make install
 
diff --git a/autogen.sh b/autogen.sh
index 4e1bbce..3c119e1 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -27,6 +27,10 @@ if test "x$1" = "x--system"; then
   libdir=$prefix/lib64
 fi
 EXTRA_ARGS="--prefix=$prefix --sysconfdir=$sysconfdir 
--localstatedir=$localstatedir --libdir=$libdir"
+if [ "$HOME" != "/root" ]; then
+   prefix=$HOME/usr
+   EXTRA_ARGS="--prefix=$prefix"
+fi
 fi
 
 cd "$olddir"
-- 
2.9.5



[PATCH] util: Prevent a NULl pointer from being accessed

2020-02-12 Thread Yi Wang
From: Huang Zijiang 

virJSONValueObjectGetObject maybe return NULL if the key is
missing or if value is not the correct TYPE, so we have to prevent
a NULl pointer from being accessed.

Signed-off-by: Huang Zijiang 
Signed-off-by: Yi Wang 
---
 src/util/virqemu.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index f3a233a..29fbe4e 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -257,6 +257,11 @@ virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
 const char *type = virJSONValueObjectGetString(objprops, "qom-type");
 const char *alias = virJSONValueObjectGetString(objprops, "id");
 virJSONValuePtr props = virJSONValueObjectGetObject(objprops, "props");
+if (!props) {
+virReportError(VIR_ERR_INVALID_ARG, "%s",
+   _("reply was missing return props data"));
+return -1;
+}
 
 return virQEMUBuildObjectCommandlineFromJSONInternal(buf, type, alias, 
props);
 }
-- 
1.9.1




[libvirt] [PATCH] create a thread to handle MigrationParamReset to avoid deadlock

2019-12-23 Thread Yi Wang
From: Li XueLei 

Libvirtd no longer receives external requests, after I do the following.

Steps to reproduce:
1.Virsh tool initiates a non-p2p migrations.
2.After the phase of qemuDomainMigratePerform3 and before the phase of
  qemuDomainMigrateConfirm3, kill the virsh client which initiated the
  migration.

What happens:
Libvirtd will be blocked in the next call stack because it can't
get the condition variables, and it will not be able to receive new
requests.

Thread 1 (Thread 0x7f36a7b9f8c0 (LWP 27556)):
#0  0x7f36a45799f5 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/lib64/libpthread.so.0
#1  0x7f36a6e7a97e in virCondWait () from /lib64/libvirt.so.0
#2  0x7f3679c6a1b3 in qemuMonitorSend () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#3  0x7f3679c837de in qemuMonitorJSONCommandWithFd () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#4  0x7f3679c93c5a in qemuMonitorJSONSetMigrationCapabilities () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#5  0x7f3679c786ed in qemuMonitorSetMigrationCapabilities () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#6  0x7f3679c67857 in qemuMigrationParamsApply () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#7  0x7f3679c67eff in qemuMigrationParamsReset () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#8  0x7f3679c5198a in qemuMigrationSrcCleanup () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#9  0x7f36a6dcd862 in virCloseCallbacksRun () from /lib64/libvirt.so.0
#10 0x7f3679cc28f6 in qemuConnectClose () from 
/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so
#11 0x7f36a70a0870 in virConnectDispose () from /lib64/libvirt.so.0
#12 0x7f36a6e3f43b in virObjectUnref () from /lib64/libvirt.so.0
#13 0x7f36a70a55c4 in virConnectClose () from /lib64/libvirt.so.0
#14 0x56058a206f92 in remoteClientFree ()
#15 0x7f36a6fa49a0 in virNetServerClientDispose () from /lib64/libvirt.so.0
#16 0x7f36a6e3f43b in virObjectUnref () from /lib64/libvirt.so.0
#17 0x7f36a6e3fd21 in virObjectFreeCallback () from /lib64/libvirt.so.0
#18 0x7f36a6f9942e in virNetSocketEventFree () from /lib64/libvirt.so.0
#19 0x7f36a6de8439 in virEventPollCleanupHandles () from /lib64/libvirt.so.0
#20 0x7f36a6de9ab6 in virEventPollRunOnce () from /lib64/libvirt.so.0
#21 0x7f36a6de817a in virEventRunDefaultImpl () from /lib64/libvirt.so.0
#22 0x7f36a6faadb5 in virNetDaemonRun () from /lib64/libvirt.so.0
#23 0x56058a1c5cc1 in main ()

Here's a patch to solve this bug, that is to create a thread to do
MigrationParamReset.

Signed-off-by: Li XueLei 
Signed-off-by: Yi Wang 

---
 src/remote/remote_daemon_dispatch.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c 
b/src/remote/remote_daemon_dispatch.c
index 76c676c..3962ee3 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -1741,9 +1741,10 @@ remoteClientFreePrivateCallbacks(struct 
daemonClientPrivate *priv)
  * We keep the libvirt connection open until any async
  * jobs have finished, then clean it up elsewhere
  */
-void remoteClientFree(void *data)
+
+static void remoteClientFreeFun(void *opaque)
 {
-struct daemonClientPrivate *priv = data;
+struct daemonClientPrivate *priv = opaque;
 
 if (priv->conn)
 virConnectClose(priv->conn);
@@ -1760,7 +1761,16 @@ void remoteClientFree(void *data)
 if (priv->storageConn)
 virConnectClose(priv->storageConn);
 
-VIR_FREE(priv);
+VIR_FREE(priv);
+}
+
+void remoteClientFree(void *data)
+{
+virThread thread;
+
+if (virThreadCreate(, false, remoteClientFreeFun, data) < 0) {
+VIR_ERROR("Unable to create remoteClientFreeFun thread");
+}
 }
 
 
-- 
1.8.3.1


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



[libvirt] [PATCH] fix memleak in virNodeDeviceGetPCISRIOVCaps

2019-09-12 Thread Yi Wang
From: Jiang Kun 

it always alloc new memory when get dumpxml of pf device,but never free it.
Now free the old first,then alloc new memory.

Signed-off-by: Jiang kun 
---
 src/conf/node_device_conf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index e51371d..618ce8e 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2509,6 +2509,7 @@ virNodeDeviceGetPCISRIOVCaps(const char *sysfsPath,
 for (i = 0; i < pci_dev->num_virtual_functions; i++)
VIR_FREE(pci_dev->virtual_functions[i]);
 VIR_FREE(pci_dev->virtual_functions);
+VIR_FREE(pci_dev->physical_function);
 pci_dev->num_virtual_functions = 0;
 pci_dev->max_virtual_functions = 0;
 pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
-- 
1.8.3.1

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


[libvirt] [PATCH v2] qemu: fix vcpupin fail as no vcpu tid set

2019-02-25 Thread Yi Wang
vcpupin will fail when maxvcpus is larger than current
vcpu:

virsh vcpupin win7 --vcpu 0 --cpulist 5-6
error: Requested operation is not valid: cpu affinity is not supported

win7 xml in the command above is like below:
...
8
...

The reason is vcpu[3] and vcpu[4] have zero tids and should not been
compared as valid situation in qemuDomainRefreshVcpuInfo().

This issue is introduced by commit 34f7743, which fix recording of vCPU
pids for MTTCG.

Signed-off-by: Yi Wang 
---
v2: stop considering zero TIDs as duplicate. Thanks to Jano.
---
 src/qemu/qemu_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ac01e86..c70d3f3 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -10708,7 +10708,7 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
 }
 
 for (j = 0; j < i; j++) {
-if (info[i].tid == info[j].tid) {
+if (0 != info[i].tid && info[i].tid == info[j].tid) {
 VIR_DEBUG("vCPU[%zu] PID %llu duplicates vCPU[%zu]",
   i, (unsigned long long)info[i].tid, j);
 validTIDs = false;
-- 
1.8.3.1

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


[libvirt] [PATCH] conf: fix starting a domain with cpuset=""

2018-09-15 Thread Yi Wang
Domain fails to start when its config xml including:
  64

  # virsh create vm.xml
  error: Failed to create domain from vm.xml
  error: invalid argument: Failed to parse bitmap ''

This patch fixes this.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8619962..bacafb2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18553,7 +18553,7 @@ virDomainVcpuParse(virDomainDefPtr def,
 
 if (def->placement_mode != VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) {
 tmp = virXMLPropString(vcpuNode, "cpuset");
-if (tmp) {
+if (tmp && strlen(tmp) != 0) {
 if (virBitmapParse(tmp, >cpumask, VIR_DOMAIN_CPUMASK_LEN) 
< 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 v7] qemu: Introduce state_lock_timeout to qemu.conf

2018-09-13 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:

"Timed out during operation: cannot acquire state change lock"

Well, sometimes it's not a problem and users want to continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v7:
- fix multiplication issue in BeginJobInternal

changes in v6:
- modify the description in qemu.conf
- move the multiplication to BeginJobInternal

changes in v5:
- adjust position of state lock in aug file
- fix state lock time got from conf file from milliseconds to
  seconds

changes in v4:
- fix syntax-check error

changes in v3:
- add user-friendly description and nb of state lock
- check validity of stateLockTimeout

changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()
---
 src/qemu/libvirtd_qemu.aug |  1 +
 src/qemu/qemu.conf |  7 +++
 src/qemu/qemu_conf.c   | 14 ++
 src/qemu/qemu_conf.h   |  2 ++
 src/qemu/qemu_domain.c |  5 +
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
 6 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..a5601e1 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -100,6 +100,7 @@ module Libvirtd_qemu =
  | str_entry "lock_manager"
 
let rpc_entry = int_entry "max_queued"
+ | int_entry "state_lock_timeout"
  | int_entry "keepalive_interval"
  | int_entry "keepalive_count"
 
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..f5e34f1 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -667,6 +667,13 @@
 #
 #max_queued = 0
 
+
+# It is strongly recommended to not touch this setting
+#
+# Default is 30
+#
+#state_lock_timeout = 60
+
 ###
 # Keepalive protocol:
 # This allows qemu driver to detect broken connections to remote
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..5be37dc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
@@ -1055,6 +1063,12 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg)
 return -1;
 }
 
+if (cfg->stateLockTimeout <= 0) {
+virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+   _("state_lock_timeout must be larger than zero"));
+return -1;
+}
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..4dea85f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+then = now + cfg->stateLockTimeout * 1000;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..8e072d0 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -82,6 +82,7 @@ module Test_libvirtd_qemu 

[libvirt] [PATCH] qemu: Introduce state_lock_timeout to qemu.conf

2018-09-12 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:

"Timed out during operation: cannot acquire state change lock"

Well, sometimes it's not a problem and users want to continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v6:
- modify the description in qemu.conf
- move the multiplication to BeginJobInternal

changes in v5:
- adjust position of state lock in aug file
- fix state lock time got from conf file from milliseconds to
  seconds

changes in v4:
- fix syntax-check error

changes in v3:
- add user-friendly description and nb of state lock
- check validity of stateLockTimeout

changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()
---
 src/qemu/libvirtd_qemu.aug |  1 +
 src/qemu/qemu.conf |  7 +++
 src/qemu/qemu_conf.c   | 14 ++
 src/qemu/qemu_conf.h   |  2 ++
 src/qemu/qemu_domain.c |  7 +++
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
 6 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..a5601e1 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -100,6 +100,7 @@ module Libvirtd_qemu =
  | str_entry "lock_manager"
 
let rpc_entry = int_entry "max_queued"
+ | int_entry "state_lock_timeout"
  | int_entry "keepalive_interval"
  | int_entry "keepalive_count"
 
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..f5e34f1 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -667,6 +667,13 @@
 #
 #max_queued = 0
 
+
+# It is strongly recommended to not touch this setting
+#
+# Default is 30
+#
+#state_lock_timeout = 60
+
 ###
 # Keepalive protocol:
 # This allows qemu driver to detect broken connections to remote
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..5be37dc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
@@ -1055,6 +1063,12 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg)
 return -1;
 }
 
+if (cfg->stateLockTimeout <= 0) {
+virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+   _("state_lock_timeout must be larger than zero"));
+return -1;
+}
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..306772a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,9 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+
+cfg->stateLockTimeout *= 1000;
+then = now + cfg->stateLockTimeout;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..8e072d0 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -82,6 +82,7 @@ module Test_libvirtd_qemu =
 { "relaxed_acs_che

[libvirt] [PATCH v5] qemu: Introduce state_lock_timeout to qemu.conf

2018-09-05 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:
"Timed out during operation: cannot acquire state change lock"
Well, sometimes it's not a problem and users want to continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v5:
- adjust position of state lock in aug file
- fix state lock time got from conf file from milliseconds to
  seconds

changes in v4:
- fix syntax-check error

changes in v3:
- add user-friendly description and nb of state lock
- check validity of stateLockTimeout

changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()
---
 src/qemu/libvirtd_qemu.aug |  1 +
 src/qemu/qemu.conf | 10 ++
 src/qemu/qemu_conf.c   | 15 +++
 src/qemu/qemu_conf.h   |  2 ++
 src/qemu/qemu_domain.c |  5 +
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
 6 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..a5601e1 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -100,6 +100,7 @@ module Libvirtd_qemu =
  | str_entry "lock_manager"
 
let rpc_entry = int_entry "max_queued"
+ | int_entry "state_lock_timeout"
  | int_entry "keepalive_interval"
  | int_entry "keepalive_count"
 
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..8920a1a 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -667,6 +667,16 @@
 #
 #max_queued = 0
 
+
+# When two or more threads want to work with the same domain they use a
+# job lock to mutually exclude each other. However, waiting for the lock
+# is limited up to state_lock_timeout seconds.
+# NB, strong recommendation to set the timeout longer than 30 seconds.
+#
+# Default is 30
+#
+#state_lock_timeout = 60
+
 ###
 # Keepalive protocol:
 # This allows qemu driver to detect broken connections to remote
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..012f4d1 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (1000ull * 30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,10 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+cfg->stateLockTimeout *= 1000;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
@@ -1055,6 +1064,12 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg)
 return -1;
 }
 
+if (cfg->stateLockTimeout <= 0) {
+virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+   _("state_lock_timeout should larger than zero"));
+return -1;
+}
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..5a2ca52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+then = now + cfg->stateLockTimeout;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..8e072d0 100644
--- a/src/qemu/test_libvirtd_qemu.a

[libvirt] [PATCH v4] qemu: Introduce state_lock_timeout to qemu.conf

2018-08-28 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:
"Timed out during operation: cannot acquire state change lock"
Well, sometimes it's not a problem and users wanner continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v4:
- fox syntax-check error

changes in v3:
- add user-friendly description and nb of state lock
- check validity of stateLockTimeout

changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()

v4

Signed-off-by: Yi Wang 
---
 src/qemu/libvirtd_qemu.aug |  1 +
 src/qemu/qemu.conf | 10 ++
 src/qemu/qemu_conf.c   | 14 ++
 src/qemu/qemu_conf.h   |  2 ++
 src/qemu/qemu_domain.c |  5 +
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
 6 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..f7287ae 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -93,6 +93,7 @@ module Libvirtd_qemu =
  | limits_entry "max_core"
  | bool_entry "dump_guest_core"
  | str_entry "stdio_handler"
+ | int_entry "state_lock_timeout"
 
let device_entry = bool_entry "mac_filter"
  | bool_entry "relaxed_acs_check"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..8920a1a 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -667,6 +667,16 @@
 #
 #max_queued = 0
 
+
+# When two or more threads want to work with the same domain they use a
+# job lock to mutually exclude each other. However, waiting for the lock
+# is limited up to state_lock_timeout seconds.
+# NB, strong recommendation to set the timeout longer than 30 seconds.
+#
+# Default is 30
+#
+#state_lock_timeout = 60
+
 ###
 # Keepalive protocol:
 # This allows qemu driver to detect broken connections to remote
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..c761cae 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (1000ull * 30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
@@ -1055,6 +1063,12 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg)
 return -1;
 }
 
+if (cfg->stateLockTimeout <= 0) {
+virReportError(VIR_ERR_CONF_SYNTAX, "%s",
+   _("state_lock_timeout should larger than zero"));
+return -1;
+}
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..5a2ca52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+then = now + cfg->stateLockTimeout;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..dc5de96 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -105,3 +105,4 @@ module Test_libvir

[libvirt] [PATCH v3] qemu: Introduce state_lock_timeout to qemu.conf

2018-08-27 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:
"Timed out during operation: cannot acquire state change lock"
Well, sometimes it's not a problem and users wanner continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v3:
- add user-friendly description and nb of state lock
- check validity of stateLockTimeout

changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()
---
 src/qemu/libvirtd_qemu.aug |  1 +
 src/qemu/qemu.conf | 10 ++
 src/qemu/qemu_conf.c   | 14 ++
 src/qemu/qemu_conf.h   |  2 ++
 src/qemu/qemu_domain.c |  5 +
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
 6 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..f7287ae 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -93,6 +93,7 @@ module Libvirtd_qemu =
  | limits_entry "max_core"
  | bool_entry "dump_guest_core"
  | str_entry "stdio_handler"
+ | int_entry "state_lock_timeout"
 
let device_entry = bool_entry "mac_filter"
  | bool_entry "relaxed_acs_check"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..8920a1a 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -667,6 +667,16 @@
 #
 #max_queued = 0
 
+
+# When two or more threads want to work with the same domain they use a
+# job lock to mutually exclude each other. However, waiting for the lock
+# is limited up to state_lock_timeout seconds.
+# NB, strong recommendation to set the timeout longer than 30 seconds.
+#
+# Default is 30
+#
+#state_lock_timeout = 60
+
 ###
 # Keepalive protocol:
 # This allows qemu driver to detect broken connections to remote
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..5fb962f 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (1000ull * 30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
@@ -1055,6 +1063,12 @@ virQEMUDriverConfigValidate(virQEMUDriverConfigPtr cfg)
 return -1;
 }
 
+if (cfg->stateLockTimeout <= 0) {
+virReportError(VIR_ERR_CONF_SYNTAX,
+   _("state_lock_timeout should larger than zero"));
+return -1;
+}
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..5a2ca52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+then = now + cfg->stateLockTimeout;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..dc5de96 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -105,3 +105,4 @@ module Test_libvirtd_qemu =
 { "pr_helper" = "/usr/bin/qemu-pr-helper" }
 { "swtpm_user" = "tss" }
 { "swtpm_group" = "tss" }
+{ "state_lock_timeout" = "60" }
-- 
1.8.3.1

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


[libvirt] [PATCH v2] qemu: Introduce state_lock_timeout to qemu.conf

2018-08-27 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:
"Timed out during operation: cannot acquire state change lock"
Well, sometimes it's not a problem and users wanner continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
changes in v2:
- change default value to 30 in qemu.conf
- set the default value in virQEMUDriverConfigNew()
---
 src/qemu/libvirtd_qemu.aug | 1 +
 src/qemu/qemu.conf | 6 ++
 src/qemu/qemu_conf.c   | 8 
 src/qemu/qemu_conf.h   | 2 ++
 src/qemu/qemu_domain.c | 5 +
 src/qemu/test_libvirtd_qemu.aug.in | 1 +
 6 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..f7287ae 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -93,6 +93,7 @@ module Libvirtd_qemu =
  | limits_entry "max_core"
  | bool_entry "dump_guest_core"
  | str_entry "stdio_handler"
+ | int_entry "state_lock_timeout"
 
let device_entry = bool_entry "mac_filter"
  | bool_entry "relaxed_acs_check"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..4284786 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -813,3 +813,9 @@
 #
 #swtpm_user = "tss"
 #swtpm_group = "tss"
+
+# The timeout (in seconds) waiting for acquiring state lock.
+#
+# Default is 30
+#
+#state_lock_timeout = 60
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..31e0013 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -129,6 +129,9 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
 #endif
 
 
+/* Give up waiting for mutex after 30 seconds */
+#define QEMU_JOB_WAIT_TIME (1000ull * 30)
+
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
 {
 virQEMUDriverConfigPtr cfg;
@@ -346,6 +349,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 cfg->glusterDebugLevel = 4;
 cfg->stdioLogD = true;
 
+cfg->stateLockTimeout = QEMU_JOB_WAIT_TIME;
+
 if (!(cfg->namespaces = virBitmapNew(QEMU_DOMAIN_NS_LAST)))
 goto error;
 
@@ -863,6 +868,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..5a2ca52 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6652,9 +6652,6 @@ qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
  priv->job.agentActive == QEMU_AGENT_JOB_NONE));
 }
 
-/* Give up waiting for mutex after 30 seconds */
-#define QEMU_JOB_WAIT_TIME (1000ull * 30)
-
 /**
  * qemuDomainObjBeginJobInternal:
  * @driver: qemu driver
@@ -6714,7 +6711,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+then = now + cfg->stateLockTimeout;
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..dc5de96 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -105,3 +105,4 @@ module Test_libvirtd_qemu =
 { "pr_helper" = "/usr/bin/qemu-pr-helper" }
 { "swtpm_user" = "tss" }
 { "swtpm_group" = "tss" }
+{ "state_lock_timeout" = "60" }
-- 
1.8.3.1

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


[libvirt] [PATCH] qemu: Introduce state_lock_timeout to qemu.conf

2018-08-27 Thread Yi Wang
When doing some job holding state lock for a long time,
we may come across error:
"Timed out during operation: cannot acquire state change lock"
Well, sometimes it's not a problem and users wanner continue
to wait, and this patch allow users decide how long time they
can wait the state lock.

Signed-off-by: Yi Wang 
Reviewed-by: Xi Xu 
---
 src/qemu/libvirtd_qemu.aug | 1 +
 src/qemu/qemu.conf | 6 ++
 src/qemu/qemu_conf.c   | 3 +++
 src/qemu/qemu_conf.h   | 2 ++
 src/qemu/qemu_domain.c | 6 +-
 src/qemu/test_libvirtd_qemu.aug.in | 1 +
 6 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index ddc4bbf..f7287ae 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -93,6 +93,7 @@ module Libvirtd_qemu =
  | limits_entry "max_core"
  | bool_entry "dump_guest_core"
  | str_entry "stdio_handler"
+ | int_entry "state_lock_timeout"
 
let device_entry = bool_entry "mac_filter"
  | bool_entry "relaxed_acs_check"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index cd57b3c..e88db3f 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -813,3 +813,9 @@
 #
 #swtpm_user = "tss"
 #swtpm_group = "tss"
+
+# Override the timeout (in seconds) for acquiring state lock.
+#
+# Default is 0
+#
+#state_lock_timeout = 60
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a4f545e..f452714 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -863,6 +863,9 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 if (virConfGetValueUInt(conf, "keepalive_count", >keepAliveCount) < 0)
 goto cleanup;
 
+if (virConfGetValueInt(conf, "state_lock_timeout", >stateLockTimeout) 
< 0)
+goto cleanup;
+
 if (virConfGetValueInt(conf, "seccomp_sandbox", >seccompSandbox) < 0)
 goto cleanup;
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index a8d84ef..97cf2e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -190,6 +190,8 @@ struct _virQEMUDriverConfig {
 int keepAliveInterval;
 unsigned int keepAliveCount;
 
+int stateLockTimeout;
+
 int seccompSandbox;
 
 char *migrateHost;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 886e3fb..d375a73 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6714,7 +6714,11 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 }
 
 priv->jobs_queued++;
-then = now + QEMU_JOB_WAIT_TIME;
+if (cfg->stateLockTimeout > 0)
+then = now + cfg->stateLockTimeout;
+else
+then = now + QEMU_JOB_WAIT_TIME;
+
 
  retry:
 if ((!async && job != QEMU_JOB_DESTROY) &&
diff --git a/src/qemu/test_libvirtd_qemu.aug.in 
b/src/qemu/test_libvirtd_qemu.aug.in
index f1e8806..dc5de96 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -105,3 +105,4 @@ module Test_libvirtd_qemu =
 { "pr_helper" = "/usr/bin/qemu-pr-helper" }
 { "swtpm_user" = "tss" }
 { "swtpm_group" = "tss" }
+{ "state_lock_timeout" = "60" }
-- 
1.8.3.1

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


[libvirt] [PATCH v2] vcpupin: add clear feature

2018-02-12 Thread Yi Wang
We can't clear vcpupin settings of XML once we did vcpupin
command, this is not convenient under some condition such
as migration to a host with less CPUs.

This patch introduces clear feature, which can clear vcpuin
setting of XML using a 'c' option.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
Signed-off-by: Xi Xu <xu@zte.com.cn>
---
 include/libvirt/libvirt-domain.h | 11 +++
 src/qemu/qemu_driver.c   | 32 
 tools/virsh-domain.c |  5 -
 tools/virsh.pod  |  1 +
 4 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 4048acf..46f4e77 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1847,6 +1847,17 @@ int virDomainSetVcpusFlags  
(virDomainPtr domain,
 int virDomainGetVcpusFlags  (virDomainPtr domain,
  unsigned int flags);
 
+/* Flags for controlling virtual CPU pinning.  */
+typedef enum {
+/* See virDomainModificationImpact for these flags.  */
+VIR_DOMAIN_VCPU_PIN_CURRENT = VIR_DOMAIN_AFFECT_CURRENT,
+VIR_DOMAIN_VCPU_PIN_LIVE= VIR_DOMAIN_AFFECT_LIVE,
+VIR_DOMAIN_VCPU_PIN_CONFIG  = VIR_DOMAIN_AFFECT_CONFIG,
+
+/* Additionally, these flags may be bitwise-OR'd in.  */
+VIR_DOMAIN_VCPU_PIN_CLEAR = (1 << 2), /* Clear vcpus pin info */
+} virDomainVcpuPinFlags;
+
 int virDomainPinVcpu(virDomainPtr domain,
  unsigned int vcpu,
  unsigned char *cpumap,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bbce5bd..fe1f62f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5056,7 +5056,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
   int vcpu,
   virQEMUDriverPtr driver,
   virQEMUDriverConfigPtr cfg,
-  virBitmapPtr cpumap)
+  virBitmapPtr cpumap,
+  bool clear)
 {
 virBitmapPtr tmpmap = NULL;
 virDomainVcpuDefPtr vcpuinfo;
@@ -5069,6 +5070,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
 int eventNparams = 0;
 int eventMaxparams = 0;
 int ret = -1;
+virBitmapPtr targetMap = NULL;
 
 if (!qemuDomainHasVcpuPids(vm)) {
 virReportError(VIR_ERR_OPERATION_INVALID,
@@ -5083,10 +5085,15 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
 goto cleanup;
 }
 
-if (!(tmpmap = virBitmapNewCopy(cpumap)))
-goto cleanup;
+if (clear) {
+targetMap = virHostCPUGetOnlineBitmap();
+} else {
+targetMap = cpumap;
+if (!(tmpmap = virBitmapNewCopy(cpumap)))
+goto cleanup;
+}
 
-if (!(str = virBitmapFormat(cpumap)))
+if (!(str = virBitmapFormat(targetMap)))
 goto cleanup;
 
 if (vcpuinfo->online) {
@@ -5095,11 +5102,11 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
 if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, vcpu,
false, _vcpu) < 0)
 goto cleanup;
-if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0)
+if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, targetMap) < 0)
 goto cleanup;
 }
 
-if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), cpumap) < 0)
+if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), targetMap) < 
0)
 goto cleanup;
 }
 
@@ -5128,6 +5135,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
 virCgroupFree(_vcpu);
 VIR_FREE(str);
 qemuDomainEventQueue(driver, event);
+if (clear)
+virBitmapFree(targetMap);
 return ret;
 }
 
@@ -5148,9 +5157,11 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 virBitmapPtr pcpumap = NULL;
 virDomainVcpuDefPtr vcpuinfo = NULL;
 virQEMUDriverConfigPtr cfg = NULL;
+bool clear = false;
 
 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
-  VIR_DOMAIN_AFFECT_CONFIG, -1);
+  VIR_DOMAIN_AFFECT_CONFIG |
+  VIR_DOMAIN_VCPU_PIN_CLEAR, -1);
 
 cfg = virQEMUDriverGetConfig(driver);
 
@@ -5166,6 +5177,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 if (virDomainObjGetDefs(vm, flags, , ) < 0)
 goto endjob;
 
+clear = !!(flags & VIR_DOMAIN_VCPU_PIN_CLEAR);
+
 if ((def && def->virtType == VIR_DOMAIN_VIRT_QEMU) ||
 (persistentDef && persistentDef->virtType == VIR_DOMAIN_VIRT_QEMU)) {
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -5191,7 +5204,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 }
 
 if (def &&
-qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0)
+qemuDomainPinVcpuLive(vm, de

[libvirt] [PATCH] [PATCH] vcpupin: add clear feature

2018-01-04 Thread Yi Wang
We can't clear vcpupin settings of XML once we did vcpupin
command, this is not convenient under some condition such
as migration.

This patch introduces clear feature, which can clear vcpuin
setting of XML.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
Signed-off-by: Xi Xu <xu@zte.com.cn>
---
 include/libvirt/libvirt-domain.h |  1 +
 src/qemu/qemu_driver.c   | 24 +++-
 tools/virsh-domain.c |  5 -
 tools/virsh.pod  |  1 +
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 4048acf..7b171df 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -1837,6 +1837,7 @@ typedef enum {
 VIR_DOMAIN_VCPU_MAXIMUM = (1 << 2), /* Max rather than current count */
 VIR_DOMAIN_VCPU_GUEST   = (1 << 3), /* Modify state of the cpu in the 
guest */
 VIR_DOMAIN_VCPU_HOTPLUGGABLE = (1 << 4), /* Make vcpus added 
hot(un)pluggable */
+VIR_DOMAIN_VCPU_CLEAR = (1 << 5), /* Clear vcpus pin info */
 } virDomainVcpuFlags;
 
 int virDomainSetVcpus   (virDomainPtr domain,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 97b194b..9e8759f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5001,7 +5001,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
   int vcpu,
   virQEMUDriverPtr driver,
   virQEMUDriverConfigPtr cfg,
-  virBitmapPtr cpumap)
+  virBitmapPtr cpumap, bool clear)
 {
 virBitmapPtr tmpmap = NULL;
 virDomainVcpuDefPtr vcpuinfo;
@@ -5049,7 +5049,12 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
 }
 
 virBitmapFree(vcpuinfo->cpumask);
-vcpuinfo->cpumask = tmpmap;
+if (clear) {
+virBitmapFree(tmpmap);
+vcpuinfo->cpumask = NULL;
+} else {
+vcpuinfo->cpumask = tmpmap;
+}
 tmpmap = NULL;
 
 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 
0)
@@ -5093,9 +5098,11 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 virBitmapPtr pcpumap = NULL;
 virDomainVcpuDefPtr vcpuinfo = NULL;
 virQEMUDriverConfigPtr cfg = NULL;
+bool clear = false;
 
 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
-  VIR_DOMAIN_AFFECT_CONFIG, -1);
+  VIR_DOMAIN_AFFECT_CONFIG |
+  VIR_DOMAIN_VCPU_CLEAR, -1);
 
 cfg = virQEMUDriverGetConfig(driver);
 
@@ -5111,6 +5118,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 if (virDomainObjGetDefs(vm, flags, , ) < 0)
 goto endjob;
 
+clear = !!(flags & VIR_DOMAIN_VCPU_CLEAR);
+
 if ((def && def->virtType == VIR_DOMAIN_VIRT_QEMU) ||
 (persistentDef && persistentDef->virtType == VIR_DOMAIN_VIRT_QEMU)) {
 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -5136,12 +5145,17 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 }
 
 if (def &&
-qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap) < 0)
+qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumap, clear) < 0)
 goto endjob;
 
 if (persistentDef) {
 virBitmapFree(vcpuinfo->cpumask);
-vcpuinfo->cpumask = pcpumap;
+if (clear) {
+virBitmapFree(pcpumap);
+vcpuinfo->cpumask = NULL;
+} else {
+vcpuinfo->cpumask = pcpumap;
+}
 pcpumap = NULL;
 
 ret = virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 93cb020..4bad9e7 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6860,7 +6860,7 @@ virshParseCPUList(vshControl *ctl, int *cpumaplen,
 unsigned char *cpumap = NULL;
 virBitmapPtr map = NULL;
 
-if (cpulist[0] == 'r') {
+if (cpulist[0] == 'r' || STREQ("clear", cpulist)) {
 if (!(map = virBitmapNew(maxcpu)))
 return NULL;
 virBitmapSetAll(map);
@@ -6938,6 +6938,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
 goto cleanup;
 }
 
+if (STREQ(cpulist, "clear"))
+flags |= VIR_DOMAIN_VCPU_CLEAR;
+
 /* Pin mode: pinning specified vcpu to specified physical cpus*/
 if (!(cpumap = virshParseCPUList(ctl, , cpulist, maxcpu)))
 goto cleanup;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 69cc423..caaa230 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2857,6 +2857,7 @@ I is a list of physical CPU numbers. Its syntax 
is a comma
 separated list and a special markup using '-' and '^' (ex. '0-4', '0-3,^2') can
 also be allowed. The '-' denotes the range and the '^' denotes exclusive.
 For pinning the I to all physical cpus specify 'r' as a I.
+For clearing pinning info, specify 'clear' as a I.
 If 

[libvirt] [PATCH] qemu: fix migration fail of an auto-placement vm after attached memory to it

2017-07-23 Thread Yi Wang
This patch fix this condition:
  -vm has the "auto" placement in vcpu
  -hot-plug memory with source node "1-3" through attach-device command
  -migrate the vm to a host with only 2 numa node
And the migration will fail with error:
"error: unsupported configuration: NUMA node 2 is unavailable"

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
Signed-off-by: Xi Xu <xu@zte.com.cn>
---
 src/qemu/qemu_process.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7b708be..dcc564c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5259,6 +5259,16 @@ qemuProcessPrepareDomain(virConnectPtr conn,
 goto cleanup;
 }
 
+VIR_DEBUG("Updating memory source nodes");
+for (i = 0; i < vm->def->nmems; i++) {
+virDomainMemoryDefPtr mem = vm->def->mems[i];
+if (priv->autoNodeset && mem && mem->sourceNodes) {
+virBitmapFree(mem->sourceNodes);
+if (!(mem->sourceNodes = virBitmapNewCopy(priv->autoNodeset)))
+goto cleanup;
+}
+}
+
 /* Whether we should use virtlogd as stdio handler for character
  * devices source backend. */
 if (cfg->stdioLogD &&
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: undefine is not allowed during domain starting up

2017-07-23 Thread Yi Wang
Start a domain whilst undefine it, if starting failed duing ProcessLaunch,
on which period qemu exited unexpectedly, the operation will lead to failure
of undefine the domain until libvirtd restarted. The reason is that libvirtd
will unlock vm during qemuProcessStart, qemuDomainUndefineFlags can get the
lock and set vm->persistent 0 but not remove the "active" domain.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/conf/domain_conf.h  | 1 +
 src/qemu/qemu_driver.c  | 6 ++
 src/qemu/qemu_process.c | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index af15ee8..f339f84 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2468,6 +2468,7 @@ struct _virDomainObj {
 virDomainSnapshotObjPtr current_snapshot;
 
 bool hasManagedSave;
+bool starting;
 
 void *privateData;
 void (*privateDataFreeFunc)(void *);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6568def..5d9acfc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7317,6 +7317,12 @@ qemuDomainUndefineFlags(virDomainPtr dom,
 if (!(vm = qemuDomObjFromDomain(dom)))
 return -1;
 
+if (vm->starting) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   "%s", _("cannot undefine during domain starting up"));
+goto cleanup;
+}
+
 cfg = virQEMUDriverGetConfig(driver);
 
 if (virDomainUndefineFlagsEnsureACL(dom->conn, vm->def) < 0)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 525521a..7b708be 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5847,6 +5847,8 @@ qemuProcessStart(virConnectPtr conn,
 if (!migrateFrom && !snapshot)
 flags |= VIR_QEMU_PROCESS_START_NEW;
 
+vm->starting = true;
+
 if (qemuProcessInit(driver, vm, updatedCPU,
 asyncJob, !!migrateFrom, flags) < 0)
 goto cleanup;
@@ -5892,6 +5894,7 @@ qemuProcessStart(virConnectPtr conn,
 ret = 0;
 
  cleanup:
+vm->starting = false;
 qemuProcessIncomingDefFree(incoming);
 return ret;
 
-- 
1.8.3.1


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


[libvirt] [PATCH RESEND] qemu: Remove inactive vm when failed to start it

2017-06-25 Thread Yi Wang
Libvirt forgets to remove inactive vm when failed to start a defined vm.
That may result in residual domain in driver->domains on such condition:
during the process of starting a vm, undefine it, and qemu exit because
of some exception. As we undefined the vm successfully, the vm->persistent
was set to 0, we will always fail to undefine it until restart libvirtd.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/qemu/qemu_driver.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cdb727b..af8afab 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7185,6 +7185,8 @@ qemuDomainCreateWithFlags(virDomainPtr dom, unsigned int 
flags)
 
  endjob:
 qemuProcessEndJob(driver, vm);
+if (ret < 0)
+qemuDomainRemoveInactive(driver, vm);
 
  cleanup:
 virDomainObjEndAPI();
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: Remove inactive vm when failed to start it

2017-06-15 Thread Yi Wang
Libvirt forgets to remove inactive vm when failed to start a defined vm.
That may result in residual domain in driver->domains on such condition:
during the process of starting a vm, undefine it, and qemu exit because
of some exception. As we undefined the vm successfully, the vm->persistent
was set to 0, we will always fail to undefine it until restart libvirtd.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/qemu/qemu_driver.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ba1dba5..581f02f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7185,6 +7185,8 @@ qemuDomainCreateWithFlags(virDomainPtr dom, unsigned int 
flags)
 
  endjob:
 qemuProcessEndJob(driver, vm);
+if (ret < 0)
+qemuDomainRemoveInactive(driver, vm);
 
  cleanup:
 virDomainObjEndAPI();
-- 
1.8.3.1


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


[libvirt] [PATCH] fix memory leak in qemuMonitorJSONAttachCharDevCommand

2017-06-11 Thread Yi Wang
The @tlsalias allocated in qemuAliasTLSObjFromSrcAlias may lost
 when append string to json.

Signed-off-by: Xi Xu 
---
 src/qemu/qemu_monitor_json.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f208dd0..773de0f 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6487,6 +6487,7 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 
 if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 
0)
 goto error;
+VIR_FREE(tlsalias);
 }
 break;
 
-- 
1.8.3.1


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


[libvirt] [PATCH] fix memory leak in daemonUnixSocketPaths

2017-06-11 Thread Yi Wang
The @rundir is allocated in virGetUserRuntimeDirectory, may lost
when virFileMakePath failed.

Signed-off-by: Xi Xu 
---
 daemon/libvirtd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index bac4bc1..d17a694 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -288,6 +288,7 @@ daemonUnixSocketPaths(struct daemonConfig *config,
 old_umask = umask(077);
 if (virFileMakePath(rundir) < 0) {
 umask(old_umask);
+VIR_FREE(rundir);
 goto error;
 }
 umask(old_umask);
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: Starting a domain with custom model and allowed-fallback failed when host lacks some CPU features

2017-06-06 Thread Yi Wang
An attemp to start a domain requesting a custom CPU model, core2duo, for
example, will fail if some feature that the model needs doesn't exist in that
host, even though fallback attibute is set allow:
"error: the CPU is incompatible with host CPU: Host CPU does not provide
required features: monitor"
Of course we can start that domain through forbidding that feature, but
that may not be flexible.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/qemu/qemu_process.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 32ba8e3..1bb65d3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5324,7 +5324,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
 virCPUCompare(caps->host.arch,
   virQEMUCapsGetHostModel(qemuCaps, def->virtType,
   VIR_QEMU_CAPS_HOST_CPU_FULL),
-  def->cpu, true) < 0)
+  def->cpu,
+  def->cpu->fallback != VIR_CPU_FALLBACK_ALLOW) < 0)
 return -1;
 
 if (virCPUUpdate(def->os.arch, def->cpu,
-- 
1.8.3.1


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


[libvirt] [PATCH] fix memory leak in daemonUnixSocketPaths and qemuMonitorJSONAttachCharDevCommand

2017-05-26 Thread Yi Wang
From: Xi Xu 

The @rundir is allocated in virGetUserRuntimeDirectory, may lost
when virFileMakePath failed.

The tlsalias allocated in qemuAliasTLSObjFromSrcAlias may lost
when append string to json.
---
 daemon/libvirtd.c| 1 +
 src/qemu/qemu_monitor_json.c | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 891238b..2447d78 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -288,6 +288,7 @@ daemonUnixSocketPaths(struct daemonConfig *config,
 old_umask = umask(077);
 if (virFileMakePath(rundir) < 0) {
 umask(old_umask);
+VIR_FREE(rundir);
 goto error;
 }
 umask(old_umask);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 0837290..66f3f87 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6481,6 +6481,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
 
 if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 
0)
 goto error;
+
+VIR_FREE(tlsalias);
 }
 break;
 
-- 
1.8.3.1


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


[libvirt] [PATCH] node_device: fix memory leak in nodeDeviceSysfsGetSCSIHostCaps

2017-05-25 Thread Yi Wang
The @tmp is allocated in virVHBAGetConfig in virVHBAIsVportCapable
condition, it will lost when virVHBAGetConfig called again.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/node_device/node_device_linux_sysfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/node_device/node_device_linux_sysfs.c 
b/src/node_device/node_device_linux_sysfs.c
index 1b7aa94..a9c7c9c 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -95,7 +95,8 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr 
scsi_host)
 goto cleanup;
 }
 
- if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
+VIR_FREE(tmp);
+if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
   "npiv_vports_inuse"))) {
 VIR_WARN("Failed to read npiv_vports_inuse for host%d",
  scsi_host->host);
-- 
1.8.3.1


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


[libvirt] [PATCH] util: fix memory leak in virSocketAddrFormatFull

2017-05-25 Thread Yi Wang
The @ipv6_host allocated in virAsprintf may be lost when virAsprintf
addrstr failed.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/util/virsocketaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 9dffbc7..95b5274 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -417,8 +417,10 @@ virSocketAddrFormatFull(const virSocketAddr *addr,
 
 if (virAsprintf(, "%s%s%s",
 ipv6_host ? ipv6_host : host,
-separator ? separator : ":", port) == -1)
+separator ? separator : ":", port) == -1) {
+VIR_FREE(ipv6_host);
 goto error;
+}
 
 VIR_FREE(ipv6_host);
 } else {
-- 
1.8.3.1


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


[libvirt] [PATCH] qemu: Fix memory leak in qemuDomainUpdateMemoryDeviceInfo

2017-05-24 Thread Yi Wang
The @meminfo allocated in qemuMonitorGetMemoryDeviceInfo may be lost when
exit monitor failed. Luckily we can free it according to rc.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/qemu/qemu_domain.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c8dc748..c34ec5a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5767,8 +5767,11 @@ qemuDomainUpdateMemoryDeviceInfo(virQEMUDriverPtr driver,
 
 rc = qemuMonitorGetMemoryDeviceInfo(priv->mon, );
 
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
+if (qemuDomainObjExitMonitor(driver, vm) < 0) {
+if (0 == rc)
+virHashFree(meminfo);
 return -1;
+}
 
 /* if qemu doesn't support the info request, just carry on */
 if (rc == -2)
-- 
1.8.3.1


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


[libvirt] [PATCH] [PATCH] rpc: fix keep alive timer segfault

2017-04-18 Thread Yi Wang
ka maybe have been freeed in virObjectUnref, application using
virKeepAliveTimer will segfault when unlock ka. We should keep
ka's refs positive before using it.

Signed-off-by: Yi Wang <wang.y...@zte.com.cn>
---
 src/rpc/virkeepalive.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c
index c9faf88..4f666fd 100644
--- a/src/rpc/virkeepalive.c
+++ b/src/rpc/virkeepalive.c
@@ -160,17 +160,17 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void 
*opaque)
 bool dead;
 void *client;
 
+virObjectRef(ka);
 virObjectLock(ka);
 
 client = ka->client;
 dead = virKeepAliveTimerInternal(ka, );
 
+virObjectUnlock(ka);
+
 if (!dead && !msg)
 goto cleanup;
 
-virObjectRef(ka);
-virObjectUnlock(ka);
-
 if (dead) {
 ka->deadCB(client);
 } else if (ka->sendCB(client, msg) < 0) {
@@ -178,11 +178,8 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
 virNetMessageFree(msg);
 }
 
-virObjectLock(ka);
-virObjectUnref(ka);
-
  cleanup:
-virObjectUnlock(ka);
+virObjectUnref(ka);
 }
 
 
-- 
1.8.3.1


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