[libvirt] [PATCH 00/34] network events feature v2
by Cédric Bosdonnat
This patch serie is replacing the previous one I sent. The improvements that
were made in between are:
* splitting the 2 huge commits into smaller reviewable ones.
* Get rid of the huge union in virDomainEvent and use virObjects instead.
* No domain events-related code in object_event.c. I left the network events
related code there as it would be pretty small in a separate set of files.
* Rebased on the python split repository
I saw something weird in the domain events code when working on this:
VIR_DOMAIN_EVENT_LAST is defined if VIR_ENUM_SENTINELS is defined, but is
generally used independently of it. I did the same for the VIR_NETWORK_EVENT_LAST
thought I'm not sure that's the correct thing to do.
These changes are all about bringing events for network object like the
ones existing for domains. This feature is needed for virt-manager to
refresh its UI when networks are started/destroyed/defined/undefined.
The network events are implemented in the test, bridge network and remote
drivers ATM.
Cédric Bosdonnat (34):
Added domain start/stop/define/undefine event unit tests
Rename virDomainEventCallback to virObjectEventCallback
Renamed virDomainMeta to virObjectMeta
Renamed virDomainEventQueue to virObjectEventQueue
Renamed virDomainEventState to virObjectEventState
Renamed virDomainEventCallbackList* to virObjectEventCallbackList*
Created virObjectEventStateRegisterID
virObject-ified virDomainEvent
Create virDomainEventLifecycle to start removing the huge union
Renamed virDomainEventNew* to virDomainEventLifecycleNew*
Renamed virDomainEventNewInternal to virDomainEventNew
Create virDomainEventRTCChange to get rid of the huge union
Created virDomainEventWatchdog to get rid of the huge union
Created virDomainEventIOError
Created virDomainEventGraphics
Created virDomainEventBlockJob
Create virDomainEventDiskChange
Created virDomainEventTrayChange
Created virDomainEventBalloonChange
Created virDomainEventDeviceRemoved and removed the huge union
Changed the remaining domain event creation methods results to void*
Removed virDomainEventPtr in favor of virObjectEventPtr
Add object event namespaces for the event IDs
Renamed virDomainEventTimer to virObjectEventTimer
Split the virObjectEvent and virDomainEvent* to separate them after
Extracted common parts of domain_event.[ch] to object_event.[ch]
Added virNetworkEventLifecycle object
Added API for network events similar to the one from Domain events
test driver: renamed testDomainEventQueue into testObjectEventQueue
test driver: implemented network events
Add network events unit tests
daemon/remote.c: renamed remoteDispatchDomainEventSend
Add network events to the remote driver
Added network events to the bridged network driver
.gitignore | 1 +
cfg.mk | 6 +-
daemon/libvirtd.h | 1 +
daemon/remote.c | 175 ++-
include/libvirt/libvirt.h.in | 86 ++
src/Makefile.am | 6 +
src/conf/domain_event.c | 1954 ++++++++++++++--------------------
src/conf/domain_event.h | 219 ++--
src/conf/object_event.c | 903 ++++++++++++++++
src/conf/object_event.h | 113 ++
src/conf/object_event_private.h | 113 ++
src/driver.h | 14 +
src/libvirt.c | 133 +++
src/libvirt_private.syms | 25 +-
src/libvirt_public.syms | 7 +
src/libxl/libxl_conf.h | 2 +-
src/libxl/libxl_driver.c | 46 +-
src/lxc/lxc_conf.h | 2 +-
src/lxc/lxc_driver.c | 54 +-
src/lxc/lxc_process.c | 20 +-
src/network/bridge_driver.c | 89 ++
src/network/bridge_driver_platform.h | 3 +
src/parallels/parallels_utils.h | 2 +-
src/qemu/qemu_conf.h | 2 +-
src/qemu/qemu_domain.c | 6 +-
src/qemu/qemu_domain.h | 2 +-
src/qemu/qemu_driver.c | 116 +-
src/qemu/qemu_hotplug.c | 10 +-
src/qemu/qemu_migration.c | 38 +-
src/qemu/qemu_process.c | 70 +-
src/remote/remote_driver.c | 178 +++-
src/remote/remote_protocol.x | 46 +-
src/test/test_driver.c | 197 ++--
src/uml/uml_conf.h | 2 +-
src/uml/uml_driver.c | 44 +-
src/vbox/vbox_tmpl.c | 22 +-
src/xen/xen_driver.c | 10 +-
src/xen/xen_driver.h | 4 +-
src/xen/xen_inotify.c | 10 +-
src/xen/xs_internal.c | 20 +-
tests/Makefile.am | 7 +
tests/objecteventtest.c | 407 +++++++
tests/qemuhotplugtest.c | 2 +-
43 files changed, 3525 insertions(+), 1642 deletions(-)
create mode 100644 src/conf/object_event.c
create mode 100644 src/conf/object_event.h
create mode 100644 src/conf/object_event_private.h
create mode 100644 tests/objecteventtest.c
--
1.8.4.2
11 years, 6 months
[libvirt] [resend] fix libvirt alignment on arm platforms
by Michele Paolino
With the changes added by the latest commits (e.g.
8a29ffcf9aee45b61a0a12ee45c656cfd52333e8) related to "new events feature
v2",
we are unable to compile libvirt on ARM target (OMAP5).
The error is due to alignment:
conf/domain_event.c: In function 'virDomainEventDispatchDefaultFunc':
conf/domain_event.c:1198:30: error: cast increases required alignment of
target type [-Werror=cast-align]
conf/domain_event.c:1314:34: error: cast increases required alignment of
target type [-Werror=cast-align]
cc1: all warnings being treated as errors
Using ATTRIBUTE_PACKED we force a structure to not follow architecture and
compiler best alignments.
---
src/conf/domain_event.c | 20 ++++++++++----------
src/conf/network_event.c | 2 +-
src/conf/object_event_private.h | 2 +-
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 64035f7..7d58367 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -76,7 +76,7 @@ struct _virDomainEventLifecycle {
int type;
int detail;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventLifecycle virDomainEventLifecycle;
typedef virDomainEventLifecycle *virDomainEventLifecyclePtr;
@@ -84,7 +84,7 @@ struct _virDomainEventRTCChange {
virDomainEvent parent;
long long offset;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventRTCChange virDomainEventRTCChange;
typedef virDomainEventRTCChange *virDomainEventRTCChangePtr;
@@ -92,7 +92,7 @@ struct _virDomainEventWatchdog {
virDomainEvent parent;
int action;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
@@ -103,7 +103,7 @@ struct _virDomainEventIOError {
char *devAlias;
int action;
char *reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventIOError virDomainEventIOError;
typedef virDomainEventIOError *virDomainEventIOErrorPtr;
@@ -113,7 +113,7 @@ struct _virDomainEventBlockJob {
char *path;
int type;
int status;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventBlockJob virDomainEventBlockJob;
typedef virDomainEventBlockJob *virDomainEventBlockJobPtr;
@@ -125,7 +125,7 @@ struct _virDomainEventGraphics {
virDomainEventGraphicsAddressPtr remote;
char *authScheme;
virDomainEventGraphicsSubjectPtr subject;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventGraphics virDomainEventGraphics;
typedef virDomainEventGraphics *virDomainEventGraphicsPtr;
@@ -136,7 +136,7 @@ struct _virDomainEventDiskChange {
char *newSrcPath;
char *devAlias;
int reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
@@ -145,7 +145,7 @@ struct _virDomainEventTrayChange {
char *devAlias;
int reason;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventTrayChange virDomainEventTrayChange;
typedef virDomainEventTrayChange *virDomainEventTrayChangePtr;
@@ -154,7 +154,7 @@ struct _virDomainEventBalloonChange {
/* In unit of 1024 bytes */
unsigned long long actual;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventBalloonChange virDomainEventBalloonChange;
typedef virDomainEventBalloonChange *virDomainEventBalloonChangePtr;
@@ -162,7 +162,7 @@ struct _virDomainEventDeviceRemoved {
virDomainEvent parent;
char *devAlias;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virDomainEventDeviceRemoved virDomainEventDeviceRemoved;
typedef virDomainEventDeviceRemoved *virDomainEventDeviceRemovedPtr;
diff --git a/src/conf/network_event.c b/src/conf/network_event.c
index 4a02523..1ffcf6c 100644
--- a/src/conf/network_event.c
+++ b/src/conf/network_event.c
@@ -32,7 +32,7 @@ struct _virNetworkEventLifecycle {
virObjectEvent parent;
int type;
-};
+} ATTRIBUTE_PACKED;
typedef struct _virNetworkEventLifecycle virNetworkEventLifecycle;
typedef virNetworkEventLifecycle *virNetworkEventLifecyclePtr;
diff --git a/src/conf/object_event_private.h b/src/conf/object_event_private.h
index f41f432..34cd902 100644
--- a/src/conf/object_event_private.h
+++ b/src/conf/object_event_private.h
@@ -73,7 +73,7 @@ struct _virObjectEvent {
virObject parent;
int eventID;
virObjectMeta meta;
-};
+}ATTRIBUTE_PACKED;
virClassPtr
virClassForObjectEvent(void);
--
1.7.9.5
11 years, 6 months
[libvirt] [PATCH] Bump version to 1.2.1 for new dev cycle
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Pushed per agreement at
https://www.redhat.com/archives/libvir-list/2013-December/msg00657.html
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 4465e01..bb92349 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library. If not, see
dnl <http://www.gnu.org/licenses/>.
-AC_INIT([libvirt], [1.2.0], [libvir-list(a)redhat.com], [], [http://libvirt.org])
+AC_INIT([libvirt], [1.2.1], [libvir-list(a)redhat.com], [], [http://libvirt.org])
AC_CONFIG_SRCDIR([src/libvirt.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
--
1.8.3.1
11 years, 6 months
[libvirt] [PATCH] Add missing % on %{_libdir} macro in RPM
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Pushed as build breaker fix
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
libvirt.spec.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 9b34f3f..e22c373 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1957,7 +1957,7 @@ exit 0
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
-{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
+%{_libdir}/%{name}/connection-driver/libvirt_driver_qemu.so
%endif
%if %{with_lxc}
--
1.8.3.1
11 years, 6 months
[libvirt] [PATCH 1/1] Make virtio as the default net device for PPC64
by Pradipta Kr. Banerjee
From: "Pradipta Kr. Banerjee" <bpradip(a)in.ibm.com>
Make virtio as the default net device for PPC64
Signed-off-by: Pradipta Kr. Banerjee <bpradip(a)in.ibm.com>
---
src/qemu/qemu_domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e964c75..db36eff 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -790,7 +790,8 @@ static const char *
qemuDomainDefaultNetModel(const virDomainDef *def)
{
if (def->os.arch == VIR_ARCH_S390 ||
- def->os.arch == VIR_ARCH_S390X)
+ def->os.arch == VIR_ARCH_S390X ||
+ def->os.arch == VIR_ARCH_PPC64)
return "virtio";
if (def->os.arch == VIR_ARCH_ARMV7L) {
--
1.8.3.1
11 years, 6 months
[libvirt] [PATCH 0/3] Reflect changes in kernel 3.12 in our cgroups code
by Martin Kletzander
To see what changed in the kernel, see explanation in PATCH 1/3.
First two patches make proper use of VIR_DOMAIN_MEMORY_PARAM_UNLIMITED,
the third one just fixes a "typo".
Martin Kletzander (3):
cgroups: Redefine what "unlimited" means wrt memory limits
qemu: Report VIR_DOMAIN_MEMORY_PARAM_UNLIMITED properly
qemu: Fix minor inconsistency in error message
src/qemu/qemu_driver.c | 27 ++++++++++++------------
src/util/vircgroup.c | 57 ++++++++++++++++++++++++++++++++++----------------
2 files changed, 53 insertions(+), 31 deletions(-)
--
1.8.4.4
11 years, 6 months
[libvirt] [PATCH] Read PCI class from sysfs class file instead of config space.
by Thadeu Lima de Souza Cascardo
When determining if a device is behind a PCI bridge, the PCI device
class is checked by reading the config space. However, there are some
devices which have the wrong class on the config space, but the class is
initialized by Linux correctly as a PCI BRIDGE. This class can be read
by the sysfs file '/sys/bus/pci/devices/xxxx:xx:xx.x/class'.
One example of such bridge is IBM PCI Bridge 1014:03b9, which is
identified as a Host Bridge when reading the config space.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo(a)linux.vnet.ibm.com>
---
src/util/virpci.c | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 8ec642f..8353411 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -344,6 +344,34 @@ virPCIDeviceRead32(virPCIDevicePtr dev, int cfgfd, unsigned int pos)
}
static int
+virPCIDeviceReadClass(virPCIDevicePtr dev, uint16_t *device_class)
+{
+ char *path = NULL;
+ char *id_str;
+ int ret = 0;
+ unsigned int value;
+
+ if (virPCIFile(&path, dev->name, "class") < 0)
+ return -1;
+
+ /* class string is '0xNNNNNN\n' ... i.e. 9 bytes */
+ if (virFileReadAll(path, 9, &id_str) < 0) {
+ VIR_FREE(path);
+ return -1;
+ }
+
+ VIR_FREE(path);
+
+ id_str[8] = '\0';
+ ret = virStrToLong_ui(id_str, NULL, 16, &value);
+ if (ret == 0)
+ *device_class = (value >> 8) & 0xFFFF;
+
+ VIR_FREE(id_str);
+ return ret;
+}
+
+static int
virPCIDeviceWrite(virPCIDevicePtr dev,
int cfgfd,
unsigned int pos,
@@ -645,8 +673,8 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevicePtr check, void *data)
return 0;
/* Is it a bridge? */
- device_class = virPCIDeviceRead16(check, fd, PCI_CLASS_DEVICE);
- if (device_class != PCI_CLASS_BRIDGE_PCI)
+ ret = virPCIDeviceReadClass(check, &device_class);
+ if (ret == -1 || device_class != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
/* Is it a plane? */
@@ -2110,6 +2138,7 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
unsigned int pos;
int fd;
int ret = 0;
+ uint16_t device_class;
if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
return -1;
@@ -2119,8 +2148,11 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
goto cleanup;
}
+ if (virPCIDeviceReadClass(dev, &device_class))
+ goto cleanup;
+
pos = dev->pcie_cap_pos;
- if (!pos || virPCIDeviceRead16(dev, fd, PCI_CLASS_DEVICE) != PCI_CLASS_BRIDGE_PCI)
+ if (!pos || device_class != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
flags = virPCIDeviceRead16(dev, fd, pos + PCI_EXP_FLAGS);
--
1.7.1
11 years, 6 months
[libvirt] RFC: Changing version number at start of dev cycle instead of end
by Daniel P. Berrange
Currently throughout the dev cycle we stick on the current release
number. The release number in configure.ac is only changed by DV
when he is actually cutting the release.
With the python bindings now being split out, this is causing us
problems. The python code aims to build against any libvirt version
that exists, so for example, the new network events APIs in libvirt
will be included with version 1.2.1. So the python binding does
#if LIBVIR_CHECK_VERSION(1, 2, 1)
static void
libvirt_virConnectNetworkEventFreeFunc(void *opaque)
{
PyObject *pyobj_conn = (PyObject*)opaque;
LIBVIRT_ENSURE_THREAD_STATE;
Py_DECREF(pyobj_conn);
LIBVIRT_RELEASE_THREAD_STATE;
}
...
This works fine if a python release is built against a libvirt
release. It does not work if a python git snapshot is built
against a libvirt git snapshot. This is bad because it prevents
us doing automated builds of GIT.
The solution here is fairly simple. We should increase the version
number in configure.ac at the *start* of each release cycle. This
means that libvirt-python can use the next version number and things
will 'just work'. I don't think this is a burden really - we already
encode the next version number in our source code when tagging new
APIs or driver methods. We're really just bringing autoconf's view
of the version number inline with the rest of the code.
So if no one objects, we should immediately change configure.ac to
be 1.2.1
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
11 years, 6 months
[libvirt] [test-API][PATCH] Add new cases for testing setSchedulerParametersFlags related API
by Xuesong Zhang
---
cases/sched_params.conf | 120 +++++++++++++++++++++++++++++++
repos/domain/sched_params.py | 136 ++++++++++++++++-------------------
repos/domain/sched_params_flag.py | 148 ++++++++++++++++++++++++++++++++++++++
3 files changed, 330 insertions(+), 74 deletions(-)
create mode 100755 cases/sched_params.conf
create mode 100644 repos/domain/sched_params_flag.py
diff --git a/cases/sched_params.conf b/cases/sched_params.conf
new file mode 100755
index 0000000..6f7acce
--- /dev/null
+++ b/cases/sched_params.conf
@@ -0,0 +1,120 @@
+domain:install_linux_cdrom
+ guestname
+ $defaultname
+ guestos
+ $defaultos
+ guestarch
+ $defaultarch
+ vcpu
+ $defaultvcpu
+ memory
+ $defaultmem
+ hddriver
+ $defaulthd
+ nicdriver
+ $defaultnic
+ imageformat
+ qcow2
+
+domain:sched_params
+ guestname
+ $defaultname
+ vcpuquota
+ 1000
+ vcpuperiod
+ 200000
+ emulatorperiod
+ 300000
+ emulatorquota
+ 4000
+ cpushares
+ 5000
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1001
+ vcpuperiod
+ 200001
+ emulatorperiod
+ 300001
+ emulatorquota
+ 4001
+ cpushares
+ 5001
+ flag
+ current
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1002
+ vcpuperiod
+ 200002
+ emulatorperiod
+ 300002
+ emulatorquota
+ 4002
+ cpushares
+ 5002
+ flag
+ live
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1003
+ vcpuperiod
+ 200003
+ emulatorperiod
+ 300003
+ emulatorquota
+ 4003
+ cpushares
+ 5003
+ flag
+ config
+
+domain:destroy
+ guestname
+ $defaultname
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1004
+ vcpuperiod
+ 200004
+ emulatorperiod
+ 300004
+ emulatorquota
+ 4004
+ cpushares
+ 5004
+ flag
+ current
+
+domain:sched_params_flag
+ guestname
+ $defaultname
+ vcpuquota
+ 1005
+ vcpuperiod
+ 200005
+ emulatorperiod
+ 300005
+ emulatorquota
+ 4005
+ cpushares
+ 5005
+ flag
+ config
+
+domain:undefine
+ guestname
+ $defaultname
+
diff --git a/repos/domain/sched_params.py b/repos/domain/sched_params.py
index 786e357..1be5986 100644
--- a/repos/domain/sched_params.py
+++ b/repos/domain/sched_params.py
@@ -1,95 +1,83 @@
#!/usr/bin/evn python
-# To test domain scheduler parameters
-
-import os
-import sys
-import time
-import commands
+# Set and show scheduler parameters
import libvirt
+from libvirt import libvirtError
from src import sharedmod
from utils import utils
-required_params = ('guestname', 'capshares',)
+import os
+
+required_params = ('guestname', 'vcpuquota', 'vcpuperiod', 'emulatorperiod', \
+ 'emulatorquota', 'cpushares',)
optional_params = {}
-def check_guest_status(domobj):
- """Check guest current status"""
- state = domobj.info()[0]
- if state == libvirt.VIR_DOMAIN_SHUTOFF or state == libvirt.VIR_DOMAIN_SHUTDOWN:
- domobj.create()
- time.sleep(30)
- # Add check function
- return True
+def check_sched_params(guestname, sched_params_after):
+ """Check scheduler parameters validity after setting
+ """
+
+ if os.path.exists("/cgroup"):
+ """ Add the judgment method, since the cgroup path is different on
+ rhel6 and rhel7.
+ if the folder cgroup is existed, it means the host os is rhel6,
+ if not existed, it means the the host of is rhel7
+ """
+
+ cgroup_path = "cat /cgroup/cpu/libvirt/qemu/%s/" % guestname
else:
- return True
-
-def check_sched_params(*args):
- """Check scheduler parameters validity after setting"""
- hypervisor, dicts, guestname, domobj = args
- sched_dict = {}
- if hypervisor == "xen":
- sched_dict = eval(commands.getoutput('xm sched-credit -d %s'
- % guestname))
- if sched_dict['weight'] == dicts['weight'] and \
- sched_dict['cap'] == dicts['cap']:
- return 0
- else:
+ cgroup_path = "cat /sys/fs/cgroup/cpu\,cpuacct/machine.slice/" \
+ "machine-qemu\\\\x2d%s.scope/" % guestname
+
+ sched_dicts = {'vcpu_quota': 'vcpu0/cpu.cfs_quota_us', \
+ 'vcpu_period': 'vcpu0/cpu.cfs_period_us', \
+ 'emulator_period': 'emulator/cpu.cfs_period_us', \
+ 'emulator_quota': 'emulator/cpu.cfs_quota_us', \
+ 'cpu_shares': 'cpu.shares'}
+
+ for sched_key in sched_dicts:
+ cmd = cgroup_path + sched_dicts[sched_key]
+ status, cmd_value = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to get ***%s*** value" % sched_key)
return 1
- if hypervisor == "kvm":
- sched_dict = domobj.schedulerParameters()
- if sched_dict['cpu_shares'] == dicts['cpu_shares']:
- return 0
- else:
+ sched_dicts[sched_key] = int(cmd_value[0])
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
return 1
+ logger.info("set scheduler parameters success")
+ return 0
+
def sched_params(params):
- """Setting scheduler parameters, argument params is a
- dictionary data type.which includes 'weight' and 'cap'
- keys, by assigning different value to 'weight' and 'cap'
- to verify validity of the result
+ """ Change and get the scheduler parameters
"""
- hypervisor = utils.get_hypervisor()
+ global logger
logger = params['logger']
guestname = params['guestname']
- conn = sharedmod.libvirtobj['conn']
-
- domobj = conn.lookupByName(guestname)
-
- if check_guest_status(domobj):
- sched_params = domobj.schedulerParameters()
- logger.info("original scheduler parameters: %s\n" % sched_params)
-
- if 'xen' in hypervisor:
- str_weight = params['weight']
- str_cap = params['cap']
- for wgt in eval(str_weight):
- for cap in eval(str_cap):
- dicts = {'weight': wgt, 'cap': cap}
- logger.info("setting scheduler parameters: %s" % dicts)
- domobj.setSchedulerParameters(dicts)
- sched_params = domobj.schedulerParameters()
- logger.info("current scheduler parameters: %s\n" % sched_params)
-
- retval = check_sched_params(hypervisor, dicts,
- guestname, domobj)
- if retval != 0:
- return 1
- elif 'kvm' in hypervisor:
- cpu_shares = int(params['cpushares'])
- dicts = {'cpu_shares': cpu_shares}
+ dicts = {'vcpu_quota': int(params['vcpuquota']), \
+ 'vcpu_period': int(params['vcpuperiod']), \
+ 'emulator_period': int(params['emulatorperiod']), \
+ 'emulator_quota': int(params['emulatorquota']), \
+ 'cpu_shares': int(params['cpushares'])}
+
+ try:
+ conn = sharedmod.libvirtobj['conn']
+ domobj = conn.lookupByName(guestname)
+
+ sched_type = str(domobj.schedulerType()[0])
+ logger.info("the scheduler type is: %s" % sched_type)
+ sched_params_original = domobj.schedulerParameters()
+ logger.info("original scheduler parameters: %s" % sched_params_original)
logger.info("setting scheduler parameters: %s" % dicts)
domobj.setSchedulerParameters(dicts)
- sched_params = domobj.schedulerParameters()
- logger.info("current scheduler parameters: %s\n" % sched_params)
- retval = check_sched_params(hypervisor, dicts,
- guestname, domobj)
- if retval != 0:
- return 1
- else:
- logger.error("unsupported hypervisor type: %s" % hypervisor)
- return 1
+ sched_params_after = domobj.schedulerParameters()
+ logger.info("current scheduler parameters: %s" % sched_params_after)
- return 0
+ ret = check_sched_params(guestname, sched_params_after)
+
+ return ret
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
diff --git a/repos/domain/sched_params_flag.py b/repos/domain/sched_params_flag.py
new file mode 100644
index 0000000..19bcb13
--- /dev/null
+++ b/repos/domain/sched_params_flag.py
@@ -0,0 +1,148 @@
+#!/usr/bin/evn python
+# Set and show scheduler parameters with flag, such as "--current", "--live"
+# and "--config"
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+from xml.dom import minidom
+import os
+
+required_params = ('guestname', 'vcpuquota', 'vcpuperiod', 'emulatorperiod', \
+ 'emulatorquota', 'cpushares', 'flag',)
+optional_params = {}
+
+def check_sched_params_flag(guestname, domobj, sched_params_after, domstate, \
+ flags_value):
+ """Check scheduler parameters validity after setting
+ """
+
+ if (domstate == 1) and ((flags_value == 0) or (flags_value == 1)):
+ """While the domain is running and the flag is "--live" or "--current",
+ the value can be checked with the cgroup value
+ As for the other condition, the value can be checked with the domain
+ config xml
+ """
+
+ if os.path.exists("/cgroup"):
+ """ Add the judgment method, since the cgroup path is different on
+ rhel6 and rhel7.
+ if the folder cgroup is existed, it means the host os is rhel6,
+ if not existed, it means the the host of is rhel7
+ """
+
+ cgroup_path = "cat /cgroup/cpu/libvirt/qemu/%s/" % guestname
+ else:
+ cgroup_path = "cat /sys/fs/cgroup/cpu\,cpuacct/machine.slice/" \
+ "machine-qemu\\\\x2d%s.scope/" % guestname
+
+ sched_dicts = {'vcpu_quota': 'vcpu0/cpu.cfs_quota_us', \
+ 'vcpu_period': 'vcpu0/cpu.cfs_period_us', \
+ 'emulator_period': 'emulator/cpu.cfs_period_us', \
+ 'emulator_quota': 'emulator/cpu.cfs_quota_us', \
+ 'cpu_shares': 'cpu.shares'}
+
+ for sched_key in sched_dicts:
+ cmd = cgroup_path + sched_dicts[sched_key]
+ status, cmd_value = utils.exec_cmd(cmd, shell=True)
+ if status:
+ logger.error("failed to get ***%s*** value" % sched_key)
+ return 1
+ sched_dicts[sched_key] = int(cmd_value[0])
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
+ return 1
+
+ else:
+ guestxml = domobj.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)
+ logger.debug("domain %s config xml :\n%s" % (domobj.name(), guestxml))
+
+ xmlrootnode = minidom.parseString(guestxml)
+
+ sched_dicts = {'vcpu_quota': 'quota', 'vcpu_period': 'period', \
+ 'emulator_period': 'emulator_period', \
+ 'emulator_quota': 'emulator_quota', \
+ 'cpu_shares': 'shares'}
+
+ for sched_key in sched_dicts:
+ node = xmlrootnode.getElementsByTagName(sched_dicts[sched_key])[0]
+ sched_dicts[sched_key] = int(node.childNodes[0].data)
+ if sched_dicts[sched_key] != sched_params_after[sched_key]:
+ logger.error("set scheduler parameters failed")
+ return 1
+
+ logger.info("set scheduler parameters success")
+ return 0
+
+def sched_params_flag(params):
+ """ Change and get the scheduler parameters
+ """
+
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ dicts = {'vcpu_quota': int(params['vcpuquota']), \
+ 'vcpu_period': int(params['vcpuperiod']), \
+ 'emulator_period': int(params['emulatorperiod']), \
+ 'emulator_quota': int(params['emulatorquota']), \
+ 'cpu_shares': int(params['cpushares'])}
+ flags = params['flag']
+
+ try:
+ conn = sharedmod.libvirtobj['conn']
+ domobj = conn.lookupByName(guestname)
+
+ domstate = domobj.state(0)[0]
+ """following is the domain state:
+ '1' is running status
+ '5' is shutoff status
+ please see the following reference link:
+ http://libvirt.org/html/libvirt-libvirt.html#virDomainState
+ """
+ if domstate == 1:
+ logger.info("the state of virtual machine is ***running***")
+ elif domstate == 5:
+ logger.info("the state of virtual machine is ***shutoff***")
+ else:
+ logger.error("the state of virtual machine is not running or " \
+ "shutoff now, it is out of the check range of this " \
+ "script. Please check the domain status.")
+ return 1
+
+ """virDomainModificationImpact
+ VIR_DOMAIN_AFFECT_CURRENT = 0
+ VIR_DOMAIN_AFFECT_LIVE = 1
+ VIR_DOMAIN_AFFECT_CONFIG = 2
+ """
+
+ if flags == "current":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_CURRENT
+ elif flags == "live":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_LIVE
+ elif flags == "config":
+ flags_value = libvirt.VIR_DOMAIN_AFFECT_CONFIG
+ else:
+ logger.error("the value of flags is not correct, please check " \
+ "the conf file")
+ return 1
+
+ sched_type = str(domobj.schedulerType()[0])
+ logger.info("the scheduler type is: %s" % sched_type)
+ sched_params_original = domobj.schedulerParametersFlags(flags_value)
+ logger.info("original scheduler parameters with flag ***%s***: %s" % \
+ (flags, sched_params_original))
+ logger.info("setting scheduler parameters: %s" % dicts)
+ domobj.setSchedulerParametersFlags(dicts, flags_value)
+ sched_params_after = domobj.schedulerParametersFlags(flags_value)
+ logger.info("current scheduler parameters with flag ***%s***: %s" % \
+ (flags, sched_params_after))
+
+ ret = check_sched_params_flag(guestname, domobj, sched_params_after, \
+ domstate, flags_value)
+
+ return ret
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
--
1.8.3.1
11 years, 6 months