[libvirt] [PATCH] rpc: Avoid deadlock when closing client connection
by Jiri Denemark
We need to drop the server lock before calling virObjectUnlock(client)
since in case we had the last reference to the client, its dispose
callback would be called and that could possibly try to lock the server
and cause a deadlock. This is exactly what happens when there is only
one QEMU domain running and it is marked to be autodestroyed when the
connection dies. This results in qemuProcessAutoDestroy ->
qemuProcessStop -> virNetServerRemoveShutdownInhibition call sequence,
where the last function locks the server.
---
src/rpc/virnetserver.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 95333d0..e536cc3 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -1120,7 +1120,7 @@ void virNetServerRun(virNetServerPtr srv)
if (virNetServerClientWantClose(srv->clients[i]))
virNetServerClientClose(srv->clients[i]);
if (virNetServerClientIsClosed(srv->clients[i])) {
- virObjectUnref(srv->clients[i]);
+ virNetServerClientPtr client = srv->clients[i];
if (srv->nclients > 1) {
memmove(srv->clients + i,
srv->clients + i + 1,
@@ -1131,6 +1131,10 @@ void virNetServerRun(virNetServerPtr srv)
srv->nclients = 0;
}
+ virObjectUnlock(srv);
+ virObjectUnref(client);
+ virObjectLock(srv);
+
goto reprocess;
}
}
--
1.8.1.2
11 years, 9 months
[libvirt] [PATCH] Avoid resetting errors in virTypedParamsFree
by Jiri Denemark
The function does not report any errors so there should be no need too
reset an existing error first. Moreover, virTypedParamsFree is mostly
called in cleanup phase where it has the potential to reset any useful
reported earlier.
---
src/util/virtypedparam.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index ae2855a..c196321 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -1026,7 +1026,6 @@ void
virTypedParamsFree(virTypedParameterPtr params,
int nparams)
{
- virResetLastError();
virTypedParamsClear(params, nparams);
VIR_FREE(params);
}
--
1.8.1.2
11 years, 9 months
[libvirt] [PATCH] virsh: Always print capacity unit
by Jiri Denemark
It doesn't make sense to print the unit (B) only with Ki, Mi, ...
prefixes. Even those poor bytes under 1 KiB are still bytes :-)
---
tools/virsh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index f5a01b3..d64e539 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -148,7 +148,7 @@ double
vshPrettyCapacity(unsigned long long val, const char **unit)
{
if (val < 1024) {
- *unit = "";
+ *unit = "B";
return (double)val;
} else if (val < (1024.0l * 1024.0l)) {
*unit = "KiB";
--
1.8.1.2
11 years, 9 months
[libvirt] [PATCH] qemu: Run lzop with '--ignore-warn'
by Michal Privoznik
Currently, if lzop decompression binary produces a warning, it
doesn't exit with zero status but 2 instead. Terrifying, but
true. However, warnings may be ignored using '--ignore-warn'
command line argument. Moreover, in which case, the exit status
will be zero.
---
src/qemu/qemu_driver.c | 68 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 22 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dc35b91..41c6168 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2507,6 +2507,36 @@ qemuCompressProgramName(int compress)
qemuSaveCompressionTypeToString(compress));
}
+static virCommandPtr
+qemuCompressGetCommand(virQEMUSaveFormat compression)
+{
+ virCommandPtr ret = NULL;
+ const char *prog = qemuSaveCompressionTypeToString(compression);
+
+ if (!prog) {
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ _("Invalid compressed save format %d"),
+ compression);
+ return NULL;
+ }
+
+ if (!(ret = virCommandNew(prog))) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ switch (compression) {
+ case QEMU_SAVE_FORMAT_LZOP:
+ virCommandAddArg(ret, "--ignore-warn");
+ break;
+ default:
+ /* Don't add nothing for now */
+ break;
+ }
+
+ return ret;
+}
+
/* Internal function to properly create or open existing files, with
* ownership affected by qemu driver setup. */
static int
@@ -4775,32 +4805,26 @@ qemuDomainSaveImageStartVM(virConnectPtr conn,
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
- if (header->version == 2) {
- const char *prog = qemuSaveCompressionTypeToString(header->compressed);
- if (prog == NULL) {
- virReportError(VIR_ERR_OPERATION_FAILED,
- _("Invalid compressed save format %d"),
- header->compressed);
+ if ((header->version == 2) &&
+ (header->compressed != QEMU_SAVE_FORMAT_RAW)) {
+ if (!(cmd = qemuCompressGetCommand(header->compressed)))
goto cleanup;
- }
- if (header->compressed != QEMU_SAVE_FORMAT_RAW) {
- cmd = virCommandNewArgList(prog, "-dc", NULL);
- intermediatefd = *fd;
- *fd = -1;
+ intermediatefd = *fd;
+ *fd = -1;
- virCommandSetInputFD(cmd, intermediatefd);
- virCommandSetOutputFD(cmd, fd);
- virCommandSetErrorBuffer(cmd, &errbuf);
- virCommandDoAsyncIO(cmd);
+ virCommandAddArg(cmd, "-dc");
+ virCommandSetInputFD(cmd, intermediatefd);
+ virCommandSetOutputFD(cmd, fd);
+ virCommandSetErrorBuffer(cmd, &errbuf);
+ virCommandDoAsyncIO(cmd);
- if (virCommandRunAsync(cmd, NULL) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to start decompression binary %s"),
- prog);
- *fd = intermediatefd;
- goto cleanup;
- }
+ if (virCommandRunAsync(cmd, NULL) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to start decompression binary %s"),
+ qemuCompressProgramName(header->compressed));
+ *fd = intermediatefd;
+ goto cleanup;
}
}
--
1.8.1.2
11 years, 9 months
[libvirt] [PATCH 0/4] Finish QEMU locking refactoring
by Daniel P. Berrange
This is the last set of patches for the QEMU driver locking
refactor. The interesting one here is the last patch which
actually deletes the QEMU driver lock usage from almost
everywhere, except a few helper APIs in qemu_conf.c
And there was much rejoicing (and hopefully no race conditions
and crashes) across the world ;-P
11 years, 9 months
[libvirt] libvirt support for LXC
by Kunal Kushwaha
Hi,
I am new to this community and am not much aware of current status libvirt
work for LXC.
Currently I am evaluating LXC with libvirt.
and I found still many features like checkpoint/restore/live migration ,
Attach storage device etc are not implemented.
Is there any work going on these feature? or any plan or Roadmap?
Following is a table showing libvirt functionality support for LXC.
Please feel free to comment in case, I am wrong or tested not propely the
libvirt and marked some working feature as not working for LXC.
Sr. No.
Command Name
Description (brief)
Status (working or not)
01
autostart
Enable and disable the automatic starting of a guest domain when the
libvirt daemon starts.
ₒ
02
Console
connect to the virtual serial console for the guest.
ₒ
03
create
creates a guest domain from an xml file # does not work. gives error.
-
04
Define
defines but doesnt start a guest domain from an xml file
○
05
destroy
immediately terminates a running guest domain and releases any resources in
use by it. Not to be used lightly
○
06
attach-disk / detach-disk
attach or detach a disk device
Note : Doesnt work. maybe i am doing something wrong.
-
07
domjobinfo
info about running guest domain jobs
-
08
domjobabort
aborts current running guest domain job
-
09
Dump
Core dump a guest domain
-
10
managedsave / managedsave-remove
Save and destroy a running guest domain, so it can be restarted from the
same state at a later time. When the virsh start command is next run for
the guest domain, it will automatically be started from this saved state
-
11
Migrate **
migrates a guest domain to another host
12
Reboot
Runs a reboot in the guest domain
-
13
Restore
restores a guest domain
-
14
Resume
resumes a guest domain
○
15
Save
saves the running state of a guest domain to a file.
-
16
shutdown
runs shutdown in a guest domain
-
17
Start
starts a guest domain either form a last managedsave or via a fresh boot if
no managed save is present
○
18
Update-device
update device from an XML file
-
19
virt-viewer
display a vnc type interface to running domain
○
20
maxvcpus
show maximum number of virtual CPUs for guest domains on this connection
-
21
memtune
gets or sets the current memory parameters for a guest domain
○
22
schedinfo
show or set scheduler parameters
○
23
setmaxmem
change the maximum memory allocation limit in the guest domain
○
24
setmem
change the current memory allocation in the guest domain
○
25
setvcpus
change the number of virtual cpus in the guest domain
-
26
vcpuinfo
returns basic info about the guest domains virtual CPU's
-
27
dominfo
displays some basic information about the domain specified
○
28
dommemstat
displays info about the memory statistics of the domain
-
29
domblkinfo
gets the block device size or a guest domain
○
30
domblkstat
gets device block stats for a running guest domain
○
31
domifstat
gets network interface stat for a running guest domain
○
32
dominfo
gets basic information about a guest domain
○
33
dommemstat
gets memory statistics for a running guest domain
○
34
domstate
returns the state of a guest domain i.e. whether running etc
○
35
list
returns a list of guest domains
○
36
Capabilities
returns the capabilities of the host and guest in xml format
○
37
freecell
Display available free memory for a NUMA cell
○
38
hostname
Display the name of the hypervisor host
○
39
nodeinfo
Returns basic information about the node
○
40
iface-define
define a physical host network interface.
The file expected is of the type xml.
We have an example of how it is executed.
○
41
iface-destroy
shutsdown and siables a physical host network device
○
42
iface-dumpxml
Output information for a physical host network interface, as an XML dump to
stdout
○
43
iface-list
Returns a list of physical host network interfaces
○
44
iface-start
Enables and starts a physical host network interface
○
45
iface-undefine
Removes the configuration information for a physical host network interface
○
46
net-autostart
Enable or disable the automatic starting of a virtual network, when the
libvirt daemon starts
○
47
net-define
Adds a new permanent virtual network from an XML file, without starting it
○
48
net-dumpxml
Displays the XML configuration for a virtual network (to stdout)
○
49
net-edit
opens the network config xml for editing by user.
○
50
net-info
displays basic information about a network
○
51
net-start
starts a network
○
52
net-undefine
undefines a network from the configuration file.
○
53
Domain snapshot commands (multiple)
Does not work with LXC.
-
Thanks & Regards,
Kunal Kushwaha
11 years, 9 months
[libvirt] [PATCHv3 0/3] S390: Finish support for native CCW bus
by Viktor Mihajlovski
Originally, QEMU did not implement a native I/O bus for s390.
The initial implementation had a machine type 's390-virtio'
featuring a fully paravirtualized I/O system with an artificial
bus type 'virtio-s390'.
This bus had a number of short-comings, like the need for a
non-standard device discovery mechanism, a limited number
of devices, limited hotplugging capabilites and the lack
of persistent device addresses.
To resolve these issues a new machine type 's390-ccw-virtio'
has been recently added to QEMU which implementa the native
s390 CCW I/O bus.
Guests with arch='s390x' and machine='s390-ccw-virtio' can
now be defined with up to 262144 virtio devices.
This series adds the support for the s390-ccw-virtio
machine type and the CCW bus to libvirt.
V2 Changes
- use an attribute triple cssid, ssid, schid instead of devno
to better represent the libvirt CCW address structure
- rebase to current upstream, mainly address qemuCapsXXX rename
V3 Changes
- skip already acked patches 1/5 and 2/5
- revert machine-based capabilities
- use machine definition from domain object
J.B. Joret (1):
S390: Add hotplug support for s390 virtio devices
Viktor Mihajlovski (2):
S390: QEMU driver support for CCW addresses
S390: Testcases for virtio-ccw machines
src/qemu/qemu_capabilities.c | 7 +-
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 280 ++++++++++++++++++--
src/qemu/qemu_command.h | 6 +
src/qemu/qemu_domain.c | 1 +
src/qemu/qemu_domain.h | 3 +
src/qemu/qemu_driver.c | 6 +-
src/qemu/qemu_hotplug.c | 154 +++++++----
src/qemu/qemu_hotplug.h | 14 +-
src/qemu/qemu_process.c | 3 +
.../qemuxml2argv-console-virtio-ccw.args | 10 +
.../qemuxml2argv-console-virtio-ccw.xml | 27 ++
.../qemuxml2argv-console-virtio-s390.args | 4 +-
.../qemuxml2argv-console-virtio-s390.xml | 2 +-
.../qemuxml2argv-disk-virtio-ccw-many.args | 12 +
.../qemuxml2argv-disk-virtio-ccw-many.xml | 40 +++
.../qemuxml2argv-disk-virtio-ccw.args | 8 +
.../qemuxml2argv-disk-virtio-ccw.xml | 30 +++
.../qemuxml2argv-net-virtio-ccw.args | 8 +
.../qemuxml2argv-net-virtio-ccw.xml | 30 +++
tests/qemuxml2argvtest.c | 12 +-
tests/testutilsqemu.c | 3 +-
22 files changed, 578 insertions(+), 83 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-ccw-many.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-ccw-many.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-ccw.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-ccw.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-ccw.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-ccw.xml
--
1.7.9.5
11 years, 9 months
[libvirt] [test-API][PATCH v2] Add 7 memory API related cases
by Wayne Sun
v1:
add 7 new cases using domain memory related API
add 1 conf for domain memory testing
v2:
fix the file not close problem and a typo
7 new cases are:
memory_params_config: test set memory params with config flag
memory_params_live: test set memory params with live flag
memory_peek: test memory peek
memory_stats: test get memory stats
set_maxmem_config: test set maximum memory with config flag
set_memory_config: test set current memory with config flag
set_memory_live: test set current memory with live flag
memory hotplug is not supported yet, so live set max memory case
is not added.
Signed-off-by: Wayne Sun <gsun(a)redhat.com>
---
cases/domain_memory_test.conf | 99 +++++++++++++++++++++++++++++++
repos/domain/memory_params_config.py | 96 ++++++++++++++++++++++++++++++
repos/domain/memory_params_live.py | 112 +++++++++++++++++++++++++++++++++++
repos/domain/memory_peek.py | 48 +++++++++++++++
repos/domain/memory_stats.py | 65 ++++++++++++++++++++
repos/domain/set_maxmem_config.py | 59 ++++++++++++++++++
repos/domain/set_memory_config.py | 94 +++++++++++++++++++++++++++++
repos/domain/set_memory_live.py | 86 +++++++++++++++++++++++++++
8 files changed, 659 insertions(+)
create mode 100644 cases/domain_memory_test.conf
create mode 100644 repos/domain/memory_params_config.py
create mode 100644 repos/domain/memory_params_live.py
create mode 100644 repos/domain/memory_peek.py
create mode 100644 repos/domain/memory_stats.py
create mode 100644 repos/domain/set_maxmem_config.py
create mode 100644 repos/domain/set_memory_config.py
create mode 100644 repos/domain/set_memory_live.py
diff --git a/cases/domain_memory_test.conf b/cases/domain_memory_test.conf
new file mode 100644
index 0000000..90879ab
--- /dev/null
+++ b/cases/domain_memory_test.conf
@@ -0,0 +1,99 @@
+domain:install_linux_cdrom
+ guestname
+ $defaultname
+ guestos
+ $defaultos
+ guestarch
+ $defaultarch
+ vcpu
+ $defaultvcpu
+ memory
+ $defaultmem
+ hddriver
+ $defaulthd
+ nicdriver
+ $defaultnic
+ macaddr
+ 54:52:00:4a:c1:22
+
+domain:balloon_memory
+ guestname
+ $defaultname
+ memorypair
+ 1024,2048
+
+domain:destroy
+ guestname
+ $defaultname
+
+domain:memory_params_config
+ guestname
+ $defaultname
+ hard_limit
+ 0
+ soft_limit
+ 9007199254740991
+ swap_hard_limit
+ -1
+
+domain:set_maxmem_config
+ guestname
+ $defaultname
+ memory
+ 16777216
+
+domain:set_memory_config
+ guestname
+ $defaultname
+ memory
+ 1048576
+ maxmem
+ 4194304
+
+domain:start
+ guestname
+ $defaultname
+
+domain:memory_stats
+ guestname
+ $defaultname
+
+domain:memory_peek
+ guestname
+ $defaultname
+
+domain:memory_params_live
+ guestname
+ $defaultname
+ hard_limit
+ 25417224
+ soft_limit
+ 9007199254740900
+ swap_hard_limit
+ -1
+
+domain:set_memory_live
+ guestname
+ $defaultname
+ memory
+ 2097152
+ username
+ $username
+ password
+ $password
+
+domain:set_memory_config
+ guestname
+ $defaultname
+ memory
+ 4194304
+
+domain:destroy
+ guestname
+ $defaultname
+
+domain:undefine
+ guestname
+ $defaultname
+
+options cleanup=enable
diff --git a/repos/domain/memory_params_config.py b/repos/domain/memory_params_config.py
new file mode 100644
index 0000000..af9781b
--- /dev/null
+++ b/repos/domain/memory_params_config.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+# Test set domain memory parameters with flag
+# VIR_DOMAIN_AFFECT_CONFIG
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'hard_limit', 'soft_limit', 'swap_hard_limit', )
+optional_params = {}
+
+UNLIMITED = 9007199254740991
+
+def get_memory_config(domobj, param_dict):
+ """get domain config memory parameters
+ """
+ new_dict = {}
+ try:
+ guestxml = domobj.XMLDesc(2)
+ logger.debug("domain %s xml is :\n%s" %(domobj.name(), guestxml))
+ xml = minidom.parseString(guestxml)
+ logger.info("get domain memory parameters in config xml")
+ for i in param_dict.keys():
+ if xml.getElementsByTagName(i):
+ limit_element = xml.getElementsByTagName(i)[0]
+ limit = int(limit_element.childNodes[0].data)
+ logger.info("%s in config xml is: %s" % (i, limit))
+ new_dict[i] = limit
+ else:
+ logger.info("%s is not in config xml" % i)
+ new_dict[i] = 0
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return False
+
+ return new_dict
+
+def memory_params_config(params):
+ """set domain memory parameters with config flag and check
+ """
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ hard_limit = int(params['hard_limit'])
+ soft_limit = int(params['soft_limit'])
+ swap_hard_limit = int(params['swap_hard_limit'])
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ param_dict = {'hard_limit': hard_limit,
+ 'soft_limit': soft_limit,
+ 'swap_hard_limit': swap_hard_limit
+ }
+
+ for i in param_dict.keys():
+ if param_dict[i] == -1:
+ param_dict[i] = UNLIMITED
+
+ logger.info("the param dict for setting is %s" % param_dict)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG
+ logger.info("set %s memory parameters with flag: %s" %
+ (guestname, flags))
+ domobj.setMemoryParameters(param_dict, flags)
+ logger.info("set memory parameters done")
+
+ logger.info("get %s memory parameters with flag: %s" %
+ (guestname, flags))
+ ret = domobj.memoryParameters(flags)
+ logger.info("%s memory parameters is %s" % (guestname, ret))
+
+ if ret == param_dict:
+ logger.info("memory parameters is as expected")
+ else:
+ logger.error("memory parameters is not as expected")
+ return 1
+
+ ret = get_memory_config(domobj, param_dict)
+ if ret == param_dict:
+ logger.info("memory parameters is as expected in config xml")
+ else:
+ logger.error("memory parameters is not as expected in config xml")
+ return 1
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/memory_params_live.py b/repos/domain/memory_params_live.py
new file mode 100644
index 0000000..44fb8b4
--- /dev/null
+++ b/repos/domain/memory_params_live.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+# Test set domain memory parameters with flag
+# VIR_DOMAIN_AFFECT_LIVE
+
+import os
+import math
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'hard_limit', 'soft_limit', 'swap_hard_limit', )
+optional_params = {}
+
+UNLIMITED = 9007199254740991
+CGROUP_PATH = "/cgroup/memory/libvirt/qemu"
+
+def get_cgroup_setting(guestname):
+ """get domain memory parameters in cgroup
+ """
+ if os.path.exists(CGROUP_PATH):
+ cgroup_path = "%s/%s" % (CGROUP_PATH, guestname)
+ else:
+ cgroup_path = "/sys/fs%s/%s" % (CGROUP_PATH, guestname)
+
+ f = open("%s/memory.limit_in_bytes" % cgroup_path)
+ hard = int(f.read())
+ logger.info("memory.limit_in_bytes value is %s" % hard)
+ f.close()
+
+ f = open("%s/memory.soft_limit_in_bytes" % cgroup_path)
+ soft = int(f.read())
+ logger.info("memory.soft_limit_in_bytes value is %s" % soft)
+ f.close()
+
+ f = open("%s/memory.memsw.limit_in_bytes" % cgroup_path)
+ swap = int(f.read())
+ logger.info("memory.memsw.limit_in_bytes value is %s" % swap)
+ f.close()
+
+ new_dict = {'hard_limit': hard/1024,
+ 'soft_limit': soft/1024,
+ 'swap_hard_limit': swap/1024
+ }
+ logger.debug("memory parameters dict get from cgroup is %s" % new_dict)
+
+ return new_dict
+
+def memory_params_live(params):
+ """set domain memory parameters with live flag and check
+ """
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ hard_limit = int(params['hard_limit'])
+ soft_limit = int(params['soft_limit'])
+ swap_hard_limit = int(params['swap_hard_limit'])
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ param_dict = {'hard_limit': hard_limit,
+ 'soft_limit': soft_limit,
+ 'swap_hard_limit': swap_hard_limit
+ }
+
+ for i in param_dict.keys():
+ if param_dict[i] == -1:
+ param_dict[i] = UNLIMITED
+
+ logger.info("the param dict for setting is %s" % param_dict)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ flags = libvirt.VIR_DOMAIN_AFFECT_LIVE
+ logger.info("get %s memory parameters with flag: %s" %
+ (guestname, flags))
+ ret_pre = domobj.memoryParameters(flags)
+ logger.info("%s memory parameters is %s" % (guestname, ret_pre))
+
+ logger.info("set %s memory parameters with flag: %s" %
+ (guestname, flags))
+ domobj.setMemoryParameters(param_dict, flags)
+ logger.info("set memory parameters done")
+
+ logger.info("get %s memory parameters with flag: %s" %
+ (guestname, flags))
+ ret_pos = domobj.memoryParameters(flags)
+ logger.info("%s memory parameters is %s" % (guestname, ret_pos))
+
+ if ret_pos == param_dict:
+ logger.info("memory parameters is as expected")
+ else:
+ logger.error("memory parameters is not as expected")
+ return 1
+
+ logger.info("check memory parameters in cgroup")
+ ret = get_cgroup_setting(guestname)
+ for i in param_dict.keys():
+ if math.fabs(param_dict[i] - ret[i]) > 1:
+ logger.error("%s value not match with cgroup setting" % i)
+ return 1
+
+ logger.info("memory parameters is as expected in cgroup setting")
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/memory_peek.py b/repos/domain/memory_peek.py
new file mode 100644
index 0000000..de1ff87
--- /dev/null
+++ b/repos/domain/memory_peek.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# Test domain memory peek
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', )
+optional_params = {}
+
+def memory_peek(params):
+ """domain memory peek
+ """
+ logger = params['logger']
+ guestname = params['guestname']
+
+ flag_dict = {'1':"VIR_MEMORY_VIRTUAL", '2':"VIR_MEMORY_PHYSICAL"}
+
+ logger.info("the name of virtual machine is %s" % guestname)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("test memory peek API")
+ for flag in flag_dict.keys():
+ logger.info("using flag: %s" % flag_dict[flag])
+ mem = domobj.memoryPeek(0, 0, int(flag))
+ if mem:
+ return 1
+ logger.info("memory peek API works fine with flag: %s" %
+ flag_dict[flag])
+
+ logger.info("peek 8 bytes from domain memory")
+ for flag in flag_dict.keys():
+ logger.info("using flag: %s" % flag_dict[flag])
+ mem = domobj.memoryPeek(0, 8, int(flag))
+ if not mem:
+ return 1
+ logger.info("8 bytes start with 0 with flag %s is: %s" %
+ (flag_dict[flag], mem))
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/memory_stats.py b/repos/domain/memory_stats.py
new file mode 100644
index 0000000..a82adad
--- /dev/null
+++ b/repos/domain/memory_stats.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# Test get domain memory stats
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', )
+optional_params = {}
+
+VIRSH = "virsh qemu-monitor-command"
+
+def get_memory_actual(guestname):
+ """get memory stats with virsh commands
+ """
+ qmp_actual = -1
+ cmd ="%s %s '{ \"execute\": \"query-balloon\" }'" % (VIRSH, guestname)
+ logger.info("check memory stats with virsh command: %s" % cmd)
+ ret, out = utils.exec_cmd(cmd, shell=True)
+ out_dict = eval(out[0])
+ if out_dict.has_key('return'):
+ if out_dict['return'].has_key('actual'):
+ qmp_actual = out_dict['return']['actual']
+ else:
+ return False
+
+ if qmp_actual == -1:
+ return False
+
+ logger.info("the memory actual is: %s" % qmp_actual)
+ return qmp_actual
+
+def memory_stats(params):
+ """get domain memory stats
+ """
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+
+ logger.info("the name of virtual machine is %s" % guestname)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ mem = domobj.memoryStats()
+ logger.info("%s memory stats is: %s" % (guestname, mem))
+ ret = get_memory_actual(guestname)
+ if not ret:
+ logger.error("get memory actual with qmp command failed")
+ return 1
+
+ if ret == mem['actual']*1024:
+ logger.info("actual memory is equal to output of qmp command")
+ else:
+ logger.error("actual memory is not equal to output of qmp command")
+ return 1
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/set_maxmem_config.py b/repos/domain/set_maxmem_config.py
new file mode 100644
index 0000000..262d7b1
--- /dev/null
+++ b/repos/domain/set_maxmem_config.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# Test set domain max memory with API setMaxMemory.
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'memory', )
+optional_params = {}
+
+def set_maxmem_config(params):
+ """set domain max memory, check with config xml and
+ maxMemory API
+ """
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ memory = int(params['memory'])
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given max memory value is %s" % memory)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("set domain max memory as %s" % memory)
+ domobj.setMaxMemory(memory)
+
+ guestxml = domobj.XMLDesc(2)
+ logger.debug("domain %s xml is :\n%s" %(guestname, guestxml))
+ xml = minidom.parseString(guestxml)
+ mem = xml.getElementsByTagName('memory')[0]
+ maxmem = int(mem.childNodes[0].data)
+ logger.info("domain max memory in config xml is: %s" % maxmem)
+ if maxmem == memory:
+ logger.info("max memory in domain config xml is equal to set")
+ else:
+ logger.error("set max memory failed")
+ return 1
+
+ maxmem = domobj.maxMemory()
+ logger.info("max memory got by maxMemory API is: %s" % maxmem)
+ if maxmem == memory:
+ logger.info("max memory got by maxMemory API is equal to set")
+ else:
+ logger.error("set max memory failed")
+ return 1
+
+ logger.info("set max memory succeed")
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/set_memory_config.py b/repos/domain/set_memory_config.py
new file mode 100644
index 0000000..c8ef6c3
--- /dev/null
+++ b/repos/domain/set_memory_config.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+# Test set domain balloon memory with flag VIR_DOMAIN_AFFECT_CONFIG
+# or VIR_DOMAIN_VCPU_MAXIMUM, depend on which optional param is
+# given.
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', )
+optional_params = {'memory': 1048576,
+ 'maxmem': 4194304,
+ }
+def get_memory_config(domobj):
+ """get domain config current memory and max memory
+ """
+ try:
+ guestxml = domobj.XMLDesc(2)
+ logger.debug("domain %s xml is :\n%s" %(domobj.name(), guestxml))
+ xml = minidom.parseString(guestxml)
+
+ logger.info("get domain memory info in config xml")
+ mem = xml.getElementsByTagName('currentMemory')[0]
+ current = int(mem.childNodes[0].data)
+ logger.info("current memory in config xml is: %s" % current)
+
+ mem = xml.getElementsByTagName('memory')[0]
+ max_memory = int(mem.childNodes[0].data)
+ logger.info("max memory in config xml is: %s" % max_memory)
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return False
+
+ return current, max_memory
+
+def set_memory_config(params):
+ """set domain memory with live flag and check
+ """
+ global logger
+ logger = params['logger']
+ guestname = params['guestname']
+ memory = params.get('memory', None)
+ maxmem = params.get('maxmem', None)
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ if memory == None and maxmem == None:
+ logger.error("at least one of memory or maxmem should be provided")
+ return 1
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ if memory:
+ memory = int(memory)
+ flags = libvirt.VIR_DOMAIN_AFFECT_CONFIG
+ logger.info("set domain memory as %s with flag: %s" %
+ (memory, flags))
+ domobj.setMemoryFlags(memory, flags)
+ ret = get_memory_config(domobj)
+ if not ret:
+ return 1
+
+ if ret[0] == memory:
+ logger.info("set current memory succeed")
+ else:
+ logger.error("set current memory failed")
+ return 1
+
+ if maxmem:
+ maxmem = int(maxmem)
+ flags = libvirt.VIR_DOMAIN_MEM_MAXIMUM
+ logger.info("set domain max memory as %s with flag: %s" %
+ (maxmem, flags))
+ domobj.setMemoryFlags(maxmem, flags)
+ ret = get_memory_config(domobj)
+ if not ret:
+ return 1
+
+ if ret[1] == maxmem:
+ logger.info("set max memory succeed")
+ else:
+ logger.error("set max memory failed")
+ return 1
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
diff --git a/repos/domain/set_memory_live.py b/repos/domain/set_memory_live.py
new file mode 100644
index 0000000..f7c77f9
--- /dev/null
+++ b/repos/domain/set_memory_live.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# Test set domain balloon memory with flag VIR_DOMAIN_AFFECT_LIVE.
+# Check domain info and inside domain to get current memory value.
+# The live flag only work on running domain, so test on shutoff
+# domain will fail.
+
+import time
+import math
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', 'memory', 'username', 'password', )
+optional_params = {}
+
+def compare_memory(expect_memory, actual_memory):
+ """ comparing expected memory size with actual memory size """
+
+ logger.info("expected memory size is %s" % expect_memory)
+ logger.info("actual memory size is %s" % actual_memory)
+ diff = int(expect_memory) - int(actual_memory)
+
+ if math.fabs(diff)/expect_memory < 0.05:
+ return 0
+ else:
+ return 1
+
+def get_current_memory(guestname, username, password):
+ """get domain current memory inside domain
+ """
+ logger.debug("get the mac address of vm %s" % guestname)
+ mac = utils.get_dom_mac_addr(guestname)
+ logger.debug("the mac address of vm %s is %s" % (guestname, mac))
+ ip = utils.mac_to_ip(mac, 180)
+ current = utils.get_remote_memory(ip, username, password)
+
+ return current
+
+def set_memory_live(params):
+ """set domain memory with live flag and check
+ """
+ global logger
+ logger = params['logger']
+ params.pop('logger')
+ guestname = params['guestname']
+ memory = int(params['memory'])
+ username = params['username']
+ password = params['password']
+
+ logger.info("the name of virtual machine is %s" % guestname)
+ logger.info("the given memory value is %s" % memory)
+
+ conn = sharedmod.libvirtobj['conn']
+
+ try:
+ domobj = conn.lookupByName(guestname)
+ logger.info("set domain memory as %s with flag: %s" %
+ (memory, libvirt.VIR_DOMAIN_AFFECT_LIVE))
+ domobj.setMemoryFlags(memory, libvirt.VIR_DOMAIN_AFFECT_LIVE)
+ logger.info("get domain current memory")
+ time.sleep(3)
+ dominfo = domobj.info()
+ logger.debug("domain info list is: %s" % dominfo)
+ logger.info("domain current memory value is: %s KiB" % dominfo[2])
+ if memory == dominfo[2]:
+ logger.info("set memory match with domain info")
+ else:
+ logger.error("set memory not match with domain info")
+ return 1
+
+ logger.info("check domain memory inside domain")
+ ret = get_current_memory(guestname, username, password)
+ if not compare_memory(memory, ret):
+ logger.info("set domain memory succeed")
+ else:
+ logger.error("set domain memory failed")
+ return 1
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
--
1.8.1
11 years, 9 months
[libvirt] [PATCH v4] add pci-bridge support
by liguang
Now, it's impossible to arrange devices into multi-pci-bus,
for example:
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x1' slot='0x02' function='0x0'/>
</video>
libvirt will complain about "bus != 0",
fortunately, qemu supports pci-to-pci bridge,
if we want to use multi-pci-bus, we can define
2 pci bridge controllers, then attach 1 to the other
as a subordinate pci-bus, so, 2 pci-buses appear.
for example:
<controller type='pci-bridge' index='0'/>
<controller type='pci-bridge' index='1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<sound model='ac97'>
<address type='pci' domain='0x0000' bus='0x01' slot='0x02' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
src/conf/domain_conf.c | 98 ++++-
src/conf/domain_conf.h | 1 +
docs/schemas/domaincommon.rng | 1 +
src/qemu/qemu_capabilities.c | 4 +
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 43 ++++++++++++++++++++-----
6 files changed, 126 insertions(+), 22 deletions(-)
11 years, 9 months
[libvirt] [PATCH 0/6 v2] Fix problems on shared disk management
by Osier Yang
This fixes problems on shared disk management, inspired by the
crash when changing the media of cdrom and floppy disk, and
the source of cdrom and floppy disk is empty.
v1 - v2:
* v1 uses a bitmap to record whether the disk is added into the table
when do qemuProcessStart. v2 added a array to the hash entry to record
the names of domain which uses the shared disk.
* Update the shared disk table when reconnecting qemu process.
Osier Yang (6):
qemu: Add checking in helpers for sgio setting
qemu: Merge qemuCheckSharedDisk into qemuAddSharedDisk
qemu: Record names of domain which uses the shared disk in hash table
qemu: Update shared disk table when reconnecting qemu process
qemu: Move the shared disk adding and sgio setting prior to attaching
qemu: Remove the shared disk entry if the operation is ejecting
src/qemu/qemu_conf.c | 187 ++++++++++++++++++++++++++++++++++++++++++----
src/qemu/qemu_conf.h | 22 +++++-
src/qemu/qemu_driver.c | 84 ++++++++++++++-------
src/qemu/qemu_hotplug.c | 10 ++-
src/qemu/qemu_hotplug.h | 3 +-
src/qemu/qemu_process.c | 81 +++++---------------
src/qemu/qemu_process.h | 3 -
7 files changed, 276 insertions(+), 114 deletions(-)
--
1.7.7.6
11 years, 9 months