[libvirt] [PATCH] cpu: Let explicit features override model features

2013-07-21 Thread Jiri Denemark
Until now CPU features inherited from a specified CPU model could only
be overridden with 'disable' policy. With this patch, any explicitly
specified feature always overrides the same feature inherited from a CPU
model regardless on the specified policy.

The CPU in x86-exact-force-Haswell.xml would previously be incompatible
with x86-host-SandyBridge.xml CPU even though x86-host-SandyBridge.xml
provides all features required by x86-exact-force-Haswell.xml.
---
 src/cpu/cpu_x86.c |  5 +
 tests/cputest.c   |  1 +
 tests/cputestdata/x86-exact-force-Haswell.xml | 15 +++
 tests/cputestdata/x86-host-SandyBridge.xml|  6 ++
 4 files changed, 27 insertions(+)
 create mode 100644 tests/cputestdata/x86-exact-force-Haswell.xml
 create mode 100644 tests/cputestdata/x86-host-SandyBridge.xml

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 4564bd4..a388f0f 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1223,6 +1223,11 @@ x86Compute(virCPUDefPtr host,
 goto out;
 }
 
+/* first remove features that were inherited from the CPU model and were
+ * explicitly forced, disabled, or made optional
+ */
+x86DataSubtract(cpu_require-data, cpu_force-data);
+x86DataSubtract(cpu_require-data, cpu_optional-data);
 x86DataSubtract(cpu_require-data, cpu_disable-data);
 result = x86ModelCompare(host_model, cpu_require);
 if (result == SUBSET || result == UNRELATED) {
diff --git a/tests/cputest.c b/tests/cputest.c
index d3865c4..803e395 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -581,6 +581,7 @@ mymain(void)
 DO_TEST_COMPARE(x86, host, pentium3-amd, 
VIR_CPU_COMPARE_INCOMPATIBLE);
 DO_TEST_COMPARE(x86, host-amd, pentium3-amd, 
VIR_CPU_COMPARE_SUPERSET);
 DO_TEST_COMPARE(x86, host-worse, nehalem-force, 
VIR_CPU_COMPARE_IDENTICAL);
+DO_TEST_COMPARE(x86, host-SandyBridge, exact-force-Haswell, 
VIR_CPU_COMPARE_IDENTICAL);
 
 /* guest updates for migration
  * automatically compares host CPU with the result */
diff --git a/tests/cputestdata/x86-exact-force-Haswell.xml 
b/tests/cputestdata/x86-exact-force-Haswell.xml
new file mode 100644
index 000..614ed7e
--- /dev/null
+++ b/tests/cputestdata/x86-exact-force-Haswell.xml
@@ -0,0 +1,15 @@
+cpu mode='custom' match='exact'
+  model fallback='allow'Haswell/model
+  feature policy='force' name='pcid'/
+  feature policy='force' name='rtm'/
+  feature policy='force' name='invpcid'/
+  feature policy='force' name='erms'/
+  feature policy='force' name='bmi2'/
+  feature policy='optional' name='smep'/
+  feature policy='optional' name='avx2'/
+  feature policy='optional' name='hle'/
+  feature policy='force' name='bmi1'/
+  feature policy='force' name='fsgsbase'/
+  feature policy='disable' name='movbe'/
+  feature policy='disable' name='fma'/
+/cpu
diff --git a/tests/cputestdata/x86-host-SandyBridge.xml 
b/tests/cputestdata/x86-host-SandyBridge.xml
new file mode 100644
index 000..7f26b7b
--- /dev/null
+++ b/tests/cputestdata/x86-host-SandyBridge.xml
@@ -0,0 +1,6 @@
+cpu
+  archx86_64/arch
+  modelSandyBridge/model
+  vendorIntel/vendor
+  topology sockets='1' cores='2' threads='2'/
+/cpu
-- 
1.8.3.2

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


[libvirt] [PATCH 4/3] Remove arch parameter from cpuHasFeature()

2013-07-21 Thread Jiri Denemark
---
This patch should be squashed in 3/3.

 src/cpu/cpu.c| 10 --
 src/cpu/cpu.h|  3 +--
 src/qemu/qemu_command.c  |  4 ++--
 src/vmware/vmware_conf.c |  6 +++---
 tests/cputest.c  |  2 +-
 5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index a4e1840..4124354 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -418,22 +418,20 @@ cpuUpdate(virCPUDefPtr guest,
 }
 
 int
-cpuHasFeature(virArch arch,
-  const virCPUDataPtr data,
+cpuHasFeature(const virCPUDataPtr data,
   const char *feature)
 {
 struct cpuArchDriver *driver;
 
-VIR_DEBUG(arch=%s, data=%p, feature=%s,
-  virArchToString(arch), data, feature);
+VIR_DEBUG(data=%p, feature=%s, data, feature);
 
-if ((driver = cpuGetSubDriver(arch)) == NULL)
+if ((driver = cpuGetSubDriver(data-arch)) == NULL)
 return -1;
 
 if (driver-hasFeature == NULL) {
 virReportError(VIR_ERR_NO_SUPPORT,
_(cannot check guest CPU data for %s architecture),
-   virArchToString(arch));
+   virArchToString(data-arch));
 return -1;
 }
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 1feca82..4003435 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -162,8 +162,7 @@ cpuUpdate   (virCPUDefPtr guest,
  const virCPUDefPtr host);
 
 extern int
-cpuHasFeature(virArch arch,
-  const virCPUDataPtr data,
+cpuHasFeature(const virCPUDataPtr data,
   const char *feature);
 
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a7c978f..602bdec 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5712,7 +5712,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
 /* Only 'svm' requires --enable-nesting. The nested
  * 'vmx' patches now simply hook off the CPU features
  */
-hasSVM = cpuHasFeature(host-arch, data, svm);
+hasSVM = cpuHasFeature(data, svm);
 if (hasSVM  0)
 goto cleanup;
 *hasHwVirt = hasSVM  0 ? true : false;
@@ -9907,7 +9907,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
   NULL, NULL, NULL, NULL)  0)
 goto cleanup;
 
-is_32bit = (cpuHasFeature(VIR_ARCH_X86_64, cpuData, lm) != 1);
+is_32bit = (cpuHasFeature(cpuData, lm) != 1);
 cpuDataFree(cpuData);
 } else if (model) {
 is_32bit = STREQ(model, qemu32);
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 6ef02a9..7734872 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -97,9 +97,9 @@ vmwareCapsInit(void)
  *  - Host CPU is x86_64 with virtualization extensions
  */
 if (caps-host.arch == VIR_ARCH_X86_64 ||
-(cpuHasFeature(caps-host.arch, data, lm) 
- (cpuHasFeature(caps-host.arch, data, vmx) ||
-  cpuHasFeature(caps-host.arch, data, svm {
+(cpuHasFeature(data, lm) 
+ (cpuHasFeature(data, vmx) ||
+  cpuHasFeature(data, svm {
 
 if ((guest = virCapabilitiesAddGuest(caps,
  hvm,
diff --git a/tests/cputest.c b/tests/cputest.c
index 803e395..2e5f0cd 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -426,7 +426,7 @@ cpuTestHasFeature(const void *arg)
   NULL, NULL, NULL, NULL)  0)
 goto cleanup;
 
-result = cpuHasFeature(host-arch, hostData, data-name);
+result = cpuHasFeature(hostData, data-name);
 if (data-result == -1)
 virResetLastError();
 
-- 
1.8.3.2

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


[libvirt] [PATCH 5/3] vmware: Fix bogus CPU arch copy

2013-07-21 Thread Jiri Denemark
---
 src/vmware/vmware_conf.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 7734872..23da92d 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -80,10 +80,7 @@ vmwareCapsInit(void)
 if (VIR_ALLOC(cpu)  0)
 goto error;
 
-if (!(cpu-arch = caps-host.arch)) {
-virReportOOMError();
-goto error;
-}
+cpu-arch = caps-host.arch;
 cpu-type = VIR_CPU_TYPE_HOST;
 
 if (!(data = cpuNodeData(cpu-arch))
-- 
1.8.3.2

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


Re: [libvirt] [test-API][PATCH V2] Modify repos/network/network_list.py and add network_list case to conf

2013-07-21 Thread Guannan Ren

On 07/17/2013 04:46 PM, hongming zhang wrote:

Modify the old network_list.py. The new network_list.py covers all
flags of listAllNetworks and the following api. and add network_list to
basic_network.conf.
virNetwork:
name()
bridgeName()
isActive()
isPersistent()
virConnect:
listAllNetworks()
Changes from V2 to V1 as follows
1.Change the flag in conf from digit to string
2.Remove the checking method using the result of virsh with flags
3.Add checking method via checking network autostart dir
4.Modify the basic_network.conf
---
  cases/basic_network.conf  |   35 -
  repos/network/network_list.py |  277 ++---
  2 files changed, 148 insertions(+), 164 deletions(-)

diff --git a/cases/basic_network.conf b/cases/basic_network.conf
index 991ad99..91d7f21 100644
--- a/cases/basic_network.conf
+++ b/cases/basic_network.conf
@@ -14,10 +14,18 @@ network:define
  netmode
  nat
  
+network:network_list

+flags
+   inactive
+
  network:start
  networkname
  $defaultnetname
  
+network:network_list

+flags
+   active
+
  network:autostart
  networkname
$defaultnetname
@@ -28,6 +36,10 @@ network:destroy
  networkname
  $defaultnetname
  
+network:network_list

+flags
+   default
+
  network:undefine
  networkname
  $defaultnetname
@@ -48,6 +60,10 @@ network:create
  netmode
  nat
  
+network:network_list

+flags
+transient
+
  network:destroy
  networkname
  $defaultnetname
@@ -68,6 +84,10 @@ network:define
  netmode
  route
  
+network:network_list

+flags
+   persistent
+
  network:start
  networkname
  $defaultnetname
@@ -106,7 +126,6 @@ network:destroy
  networkname
  $defaultnetname
  
-

  network:define
  networkname
  $defaultnetname
@@ -127,12 +146,20 @@ network:start
  networkname
  $defaultnetname
  
+network:network_list

+flags
+   noautostart
+
  network:autostart
  networkname
  $defaultnetname
  autostart
  enable
  
+network:network_list

+flags
+   autostart
+
  network:destroy
  networkname
  $defaultnetname
@@ -141,7 +168,6 @@ network:undefine
  networkname
  $defaultnetname
  
-

  network:create
  networkname
  $defaultnetname
@@ -162,8 +188,3 @@ network:destroy
  networkname
  $defaultnetname
  
-

-
-
-
-
diff --git a/repos/network/network_list.py b/repos/network/network_list.py
index 7c34f69..175d6fa 100644
--- a/repos/network/network_list.py
+++ b/repos/network/network_list.py
@@ -1,184 +1,147 @@
  #!/usr/bin/env python
  # To test virsh net-list command
  
-import os

-import sys
-import re
-import commands
-
  import libvirt
  from libvirt import libvirtError
  
  from src import sharedmod

  from utils import utils
  
-required_params = ('netlistopt',)

+required_params = ('flags',)
  optional_params = {}
  
-VIRSH_QUIET_NETLIST = virsh --quiet net-list %s|awk '{print $1}'

-VIRSH_NETLIST = virsh net-list %s
-GET_BRIDGE_IP = /sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk '{print 
$1}'
-CONFIG_DIR = /etc/libvirt/qemu/networks/
-
-def get_option_list(params):
-return options we need to test
-
-logger = params['logger']
-option_list=[]
-
-value = params['netlistopt']
-
-if value == 'all':
-option_list = [' ', '--all', '--inactive']
-elif value == '--all' or value == '--inactive':
-option_list.append(value)
+VIRSH_NETWORK_LIST = virsh net-list %s|sed -n '3,$'p|awk '{print $1}'
+GET_BRIDGE_IP = /sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk \
+'{print $1}'
+LS_NETWORK_DIR = ls /etc/libvirt/qemu/networks/
+LS_AUTOSTART_NET = ls /etc/libvirt/qemu/networks/autostart/
+
+def check_bridge_ip(bridgename):
+ Check if the bridge has ip 
+
+(status, output) = utils.exec_cmd(GET_BRIDGE_IP % bridgename,\
+   shell=True)
+if not status and utils.do_ping(output[0], 50):
+logger.info(Bridge %s is active % bridgename)
+logger.info(%s has ip: %s % (bridgename, output[0]))


GET_BRIDGE_IP is not a common solution to extract ip
In fedora, it is inet xxx.xxx.xxx.xxx which is not the same as inet addr: 
xxx.xxx.xxx.xxx on RHEL



+return True
  else:
-logger.error(value %s is not supported % value)
-return 1, option_list
-
-return 0, option_list
+logger.error(Bridge %s has no ip or fails to ping % bridgename)
+return False
  
-def get_output(logger, command, flag):

-execute shell command
+def check_persistent_netxml(networkname):
  
-status, ret = commands.getstatusoutput(command)
-if not flag and status:
-logger.error(executing + \ +  command  + \ +  failed)
-logger.error(ret)
-return status, ret
-
-def check_all_option(conn, logger):
-check the output of virsh net-list