[libvirt] libvirt binding for Rust
by Sahid Orentino Ferdjaoui
Hello,
I started a work on a libvirt binding for Rust [0]. Not all of the API
is implemeted but I think it's now in a usable state.
https://docs.rs/crate/virt
https://github.com/sahid/libvirt-rs
The code is licensed under LGPL-2.1, it's tested by a CI running
libvirt 1.2.0, 2.5.0, 3.3.0. There are unit tests, integration tests
and some examples to exercise the code (some parts are still not
covered) I also have checked the code with valgrind to avoid any
memory leaks.
https://travis-ci.org/sahid/libvirt-rs
Do you think that we can consider it ready to be hosted by libvirt.org
GIT server ? That could help to get new contributors also interested
by Rust and improve the code and coverage of the API.
Thanks,
s.
7 years, 5 months
[libvirt] More CI options
by Martin Kletzander
Since the addition of Travis CI builds, there is some more progress
towards more testing. I was just wondering if anyone was thinking about
(or is already working on) some settings for other CI environments as
well. For example if configured AppVeyor, we could have MSVC builds as
well. And there are more of those, I didn't compare all of them, but
the more environments we have, the more build failures we might catch.
Or even test failures, maybe.
Martin
7 years, 5 months
[libvirt] [PATCH 00/15] Fix regression caused by recent CPU driver changes
by Jiri Denemark
https://bugzilla.redhat.com/show_bug.cgi?id=1441662
when I was enhancing libvirt's guest CPU configuration code to be able
to really ensure stable guest CPU ABI, I added a new attribute
//cpu/@check which is nicely backward compatible... an old libvirt will
just ignore it. However, even if check='full' will be ignored, an old
libvirt will still see the updated CPU definition (features added or
removed by the hypervisor will be shown there). And because we need QEMU
2.9.0 to check what features are going to be added or removed before we
actually start the domain, migrating such domain to an older libvirt or
QEMU may fail if QEMU enables a feature which is not supported by the
host CPU. Known features causing problems are, e.g., x2apic, hypervisor,
and arat. To make things even worse, updating a CPU definition with the
automatically added/removed features can be done since QEMU 1.5.0.
Even save/restore or snapshot revert on a single host running new
libvirt and QEMU < 2.9.0 is now affected by this regression.
This series fixes the regression by storing the original guest CPU
definition in migratable XML and sending the updated CPU in a side
channel (a migration or save cookie).
Jiri Denemark (15):
conf: Make error reporting in virCPUDefIsEqual optional
conf: Refactor virCPUDefParseXML
conf: Make virDomainSnapshotDefFormat easier to read
conf: Pass xmlopt to virDomainSnapshotDefFormat
qemu: Rename xml_len in virQEMUSaveHeader as data_len
qemu: Refactor save image header
conf: Introduce virSaveCookie
conf: Add save cookie callbacks to xmlopt
qemu: Implement virSaveCookie object and callbacks
qemu: Store save cookie in save images and snapshots
qemu: Remember CPU def from domain start
qemu: Report the original CPU in migratable xml
qemu: Send updated CPU in migration cookie
qemu: Store updated CPU in save cookie
qemu: Use updated CPU when starting QEMU if possible
docs/formatsnapshot.html.in | 6 +
docs/schemas/domainsnapshot.rng | 7 +
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/bhyve/bhyve_domain.c | 2 +-
src/conf/cpu_conf.c | 224 +++++++++++--------
src/conf/cpu_conf.h | 12 +-
src/conf/domain_conf.c | 30 ++-
src/conf/domain_conf.h | 7 +-
src/conf/snapshot_conf.c | 40 +++-
src/conf/snapshot_conf.h | 3 +
src/conf/virsavecookie.c | 144 ++++++++++++
src/conf/virsavecookie.h | 62 +++++
src/cpu/cpu.c | 5 +-
src/esx/esx_driver.c | 2 +-
src/libvirt_private.syms | 10 +
src/libxl/libxl_conf.c | 2 +-
src/lxc/lxc_conf.c | 2 +-
src/openvz/openvz_driver.c | 2 +-
src/phyp/phyp_driver.c | 2 +-
src/qemu/qemu_capabilities.c | 2 +-
src/qemu/qemu_conf.c | 3 +-
src/qemu/qemu_domain.c | 207 +++++++++++++++--
src/qemu/qemu_domain.h | 22 ++
src/qemu/qemu_driver.c | 459 ++++++++++++++++++++++++++------------
src/qemu/qemu_migration.c | 18 +-
src/qemu/qemu_migration_cookie.c | 31 ++-
src/qemu/qemu_migration_cookie.h | 5 +
src/qemu/qemu_process.c | 37 ++-
src/qemu/qemu_process.h | 2 +
src/security/virt-aa-helper.c | 2 +-
src/test/test_driver.c | 3 +-
src/uml/uml_driver.c | 2 +-
src/vbox/vbox_common.c | 6 +-
src/vmware/vmware_driver.c | 3 +-
src/vmx/vmx.c | 2 +-
src/vz/vz_driver.c | 3 +-
src/xen/xen_driver.c | 2 +-
src/xenapi/xenapi_driver.c | 2 +-
tests/bhyveargv2xmltest.c | 2 +-
tests/cputest.c | 5 +-
tests/domainsnapshotxml2xmltest.c | 1 +
tests/testutils.c | 2 +-
43 files changed, 1069 insertions(+), 316 deletions(-)
create mode 100644 src/conf/virsavecookie.c
create mode 100644 src/conf/virsavecookie.h
--
2.13.0
7 years, 5 months
[libvirt] [PATCH] qemu: Set operation on completed migration job
by Jiri Denemark
Without this patch libvirt would just report the operation of a
completed job as "unknown" instead of "incoming migration".
https://bugzilla.redhat.com/show_bug.cgi?id=1457052
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_migration_cookie.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 12887892d..559b1f0c1 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -1292,6 +1292,7 @@ qemuMigrationEatCookie(virQEMUDriverPtr driver,
int cookieinlen,
unsigned int flags)
{
+ qemuDomainObjPrivatePtr priv = dom->privateData;
qemuMigrationCookiePtr mig = NULL;
/* Parse & validate incoming cookie (if any) */
@@ -1340,6 +1341,9 @@ qemuMigrationEatCookie(virQEMUDriverPtr driver,
}
}
+ if (flags & QEMU_MIGRATION_COOKIE_STATS && mig->jobInfo)
+ mig->jobInfo->operation = priv->job.current->operation;
+
return mig;
error:
--
2.13.0
7 years, 5 months
[libvirt] [PATCH] qemu: Starting a domain with custom model and allowed-fallback failed when host lacks some CPU features
by 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.yi59(a)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
7 years, 5 months
[libvirt] [PATCH] docs: correct improper information about domain states in virsh manpage
by Laine Stump
Commit 24d4a0a1f removed the non-existent "dying" state from the list
of possible domain states given in the virsh manpage, but didn't
correct the count of states from 8 down to 7. This patch fixes that
mismatch, while wording the sentence in a more readable/truthful
manner.
---
tools/virsh.pod | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index aee9646..611ea88 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -418,8 +418,9 @@ State is the run state (see below).
B<STATES>
-The State field lists 8 states for a domain, and which ones the
-current domain is in.
+The State field lists what state each domain is currently in. A domain
+can be in one of the following seven possible states:
+
=over 4
--
2.9.3
7 years, 5 months
[libvirt] [libvirt-php PATCH] add API bindings for get/set network autostart
by Dawid Zamirski
Aside from that:
* fix arginfo_libvirt_conn_flags - it has 2 args not 1
* get rid arginfo_libvirt_domain_set_autostart and use
arginfo_libvirt_conn_flags instead as it's the same.
---
src/libvirt-php.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
src/libvirt-php.h | 2 ++
2 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 99d6397..c2ab0da 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -284,7 +284,7 @@ ZEND_ARG_INFO(0, conn)
ZEND_ARG_INFO(0, to)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_flags, 0, 0, 1)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_conn_flags, 0, 0, 2)
ZEND_ARG_INFO(0, conn)
ZEND_ARG_INFO(0, flags)
ZEND_END_ARG_INFO()
@@ -399,11 +399,6 @@ ZEND_ARG_INFO(0, res)
ZEND_ARG_INFO(0, mac)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_set_autostart, 0, 0, 2)
-ZEND_ARG_INFO(0, conn)
-ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO()
-
ZEND_BEGIN_ARG_INFO_EX(arginfo_libvirt_domain_get_metadata, 0, 0, 4)
ZEND_ARG_INFO(0, conn)
ZEND_ARG_INFO(0, type)
@@ -662,7 +657,7 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_domain_get_block_info, arginfo_libvirt_domain_get_block_info)
PHP_FE(libvirt_domain_get_network_info, arginfo_libvirt_domain_get_network_info)
PHP_FE(libvirt_domain_get_autostart, arginfo_libvirt_conn)
- PHP_FE(libvirt_domain_set_autostart, arginfo_libvirt_domain_set_autostart)
+ PHP_FE(libvirt_domain_set_autostart, arginfo_libvirt_conn_flags)
PHP_FE(libvirt_domain_get_metadata, arginfo_libvirt_domain_get_metadata)
PHP_FE(libvirt_domain_set_metadata, arginfo_libvirt_domain_set_metadata)
PHP_FE(libvirt_domain_is_active, arginfo_libvirt_conn)
@@ -724,6 +719,8 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_network_get_uuid_string, arginfo_libvirt_conn)
PHP_FE(libvirt_network_get_uuid, arginfo_libvirt_conn)
PHP_FE(libvirt_network_get_name, arginfo_libvirt_conn)
+ PHP_FE(libvirt_network_get_autostart, arginfo_libvirt_conn)
+ PHP_FE(libvirt_network_set_autostart, arginfo_libvirt_conn_flags)
/* Node functions */
PHP_FE(libvirt_node_get_info, arginfo_libvirt_conn)
PHP_FE(libvirt_node_get_cpu_stats, arginfo_libvirt_conn_optcpunr)
@@ -10002,6 +9999,49 @@ PHP_FUNCTION(libvirt_network_get_name)
}
/*
+ * Function name: libvirt_network_get_autostart
+ * Since version: 0.5.4
+ * Description: Function is getting the autostart value for the network
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: autostart value or -1 on error
+ */
+PHP_FUNCTION(libvirt_network_get_autostart)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ int autostart;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ if (virNetworkGetAutostart(network->network, &autostart) != 0)
+ RETURN_LONG(-1);
+
+ RETURN_LONG((long) autostart);
+}
+
+/*
+ * Function name: libvirt_network_set_autostart
+ * Since version: 0.5.4
+ * Description: Function is setting the autostart value for the network
+ * Arguments: @res [resource]: libvirt network resource
+ * @flags [int]: flag to enable/disable autostart
+ * Returns: TRUE on success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_network_set_autostart)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ zend_long autostart = 0;
+
+ GET_NETWORK_FROM_ARGS("rl", &znetwork, &autostart);
+
+ if (virNetworkSetAutostart(network->network, autostart) < 0)
+ RETURN_FALSE;
+
+ RETURN_TRUE;
+}
+
+/*
* Function name: libvirt_version
* Since version: 0.4.1(-1)
* Description: Function is used to get libvirt, driver and libvirt-php version numbers. Can be used for information purposes, for version checking please use libvirt_check_version() defined below
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index f87d180..f9dec09 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -423,6 +423,8 @@ PHP_FUNCTION(libvirt_network_set_active);
PHP_FUNCTION(libvirt_network_get_uuid_string);
PHP_FUNCTION(libvirt_network_get_uuid);
PHP_FUNCTION(libvirt_network_get_name);
+PHP_FUNCTION(libvirt_network_get_autostart);
+PHP_FUNCTION(libvirt_network_set_autostart);
/* Nodedev functions */
PHP_FUNCTION(libvirt_nodedev_get);
PHP_FUNCTION(libvirt_nodedev_capabilities);
--
2.13.0
7 years, 5 months
[libvirt] [PATCH] lxc: add possibility to define init uid/gid
by Cédric Bosdonnat
Users may want to run the init command of a container as a special
user / group. Allow doing it using <inituser uid=""/> and <initgroup
gid=""/> elements.
---
docs/formatdomain.html.in | 6 ++++++
docs/schemas/domaincommon.rng | 12 ++++++++++++
src/conf/domain_conf.c | 19 +++++++++++++++++++
src/conf/domain_conf.h | 2 ++
src/lxc/lxc_container.c | 13 +++++++++++++
tests/lxcxml2xmldata/lxc-inituser.xml | 31 +++++++++++++++++++++++++++++++
tests/lxcxml2xmltest.c | 1 +
7 files changed, 84 insertions(+)
create mode 100644 tests/lxcxml2xmldata/lxc-inituser.xml
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 7627fd0d0..85d5f4539 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -334,6 +334,10 @@
To set a custom work directory for the init, use the <code>initdir</code>
element.
</p>
+ <p>
+ To run the init command as a given user or group, use the <code>inituser</code>
+ or <code>initgroup</code> elements respectively.
+ </p>
<pre>
<os>
@@ -343,6 +347,8 @@
<initarg>emergency.service</initarg>
<initenv name='MYENV'>some value</initenv>
<initdir>/my/custom/cwd</initdir>
+ <inituser uid="1000"/>
+ <initgroup gid="1000"/>
</os>
</pre>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5a4c4ecf1..385e937e9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -400,6 +400,18 @@
<ref name="absFilePath"/>
</element>
</optional>
+ <optional>
+ <element name="inituser">
+ <attribute name="uid">
+ <ref name="unsignedInt"/>
+ </attribute>
+ </element>
+ <element name="initgroup">
+ <attribute name="gid">
+ <ref name="unsignedInt"/>
+ </attribute>
+ </element>
+ </optional>
</interleave>
</element>
</define>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3c2a81f52..21bb104a9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16806,6 +16806,18 @@ virDomainDefParseBootOptions(virDomainDefPtr def,
def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
def->os.initdir = virXPathString("string(./os/initdir[1])", ctxt);
+ if (virXPathUInt("string(./os/inituser[1]/@uid)", ctxt, &def->os.inituid) == -2) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Failed to parse inituser uid"));
+ goto error;
+ }
+
+ if (virXPathUInt("string(./os/initgroup[1]/@gid)", ctxt, &def->os.initgid) == -2) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Failed to parse initgroup gid"));
+ goto error;
+ }
+
if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0)
goto error;
@@ -24593,6 +24605,13 @@ virDomainDefFormatInternal(virDomainDefPtr def,
if (def->os.initdir)
virBufferEscapeString(buf, "<initdir>%s</initdir>\n",
def->os.initdir);
+ if (def->os.inituid)
+ virBufferAsprintf(buf, "<inituser uid='%u'/>\n",
+ def->os.inituid);
+ if (def->os.initgid)
+ virBufferAsprintf(buf, "<initgroup gid='%u'/>\n",
+ def->os.initgid);
+
if (def->os.loader)
virDomainLoaderDefFormat(buf, def->os.loader);
virBufferEscapeString(buf, "<kernel>%s</kernel>\n",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index d6b8429c3..6e1997324 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1842,6 +1842,8 @@ struct _virDomainOSDef {
char **initargv;
virDomainOSEnvPtr *initenv;
char *initdir;
+ uid_t inituid;
+ gid_t initgid;
char *kernel;
char *initrd;
char *cmdline;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 8d8e1a735..42bcd25c4 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -247,6 +247,10 @@ static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef,
virCommandAddEnvPair(cmd, "LIBVIRT_LXC_CMDLINE", vmDef->os.cmdline);
if (vmDef->os.initdir)
virCommandSetWorkingDirectory(cmd, vmDef->os.initdir);
+ if (vmDef->os.inituid)
+ virCommandSetUID(cmd, vmDef->os.inituid);
+ if (vmDef->os.initgid)
+ virCommandSetGID(cmd, vmDef->os.initgid);
for (i = 0; vmDef->os.initenv[i]; i++) {
virCommandAddEnvPair(cmd, vmDef->os.initenv[i]->name,
@@ -2192,6 +2196,15 @@ static int lxcContainerChild(void *data)
goto cleanup;
}
+ /* Change the newly created tty owner to the inituid for
+ * shells to have job control */
+ if (vmDef->os.inituid && chown(ttyPath, vmDef->os.inituid, -1) < 0) {
+ virReportSystemError(errno,
+ _("Failed to change ownership of tty %s"),
+ ttyPath);
+ goto cleanup;
+ }
+
if (lxcContainerResolveAllSymlinks(vmDef) < 0)
goto cleanup;
diff --git a/tests/lxcxml2xmldata/lxc-inituser.xml b/tests/lxcxml2xmldata/lxc-inituser.xml
new file mode 100644
index 000000000..61b5db4af
--- /dev/null
+++ b/tests/lxcxml2xmldata/lxc-inituser.xml
@@ -0,0 +1,31 @@
+<domain type='lxc'>
+ <name>jessie</name>
+ <uuid>e21987a5-e98e-9c99-0e35-803e4d9ad1fe</uuid>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <resource>
+ <partition>/machine</partition>
+ </resource>
+ <os>
+ <type arch='x86_64'>exe</type>
+ <init>/sbin/sh</init>
+ <inituser uid='1000'/>
+ <initgroup gid='1234'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/libexec/libvirt_lxc</emulator>
+ <filesystem type='mount' accessmode='passthrough'>
+ <source dir='/mach/jessie'/>
+ <target dir='/'/>
+ </filesystem>
+ <console type='pty'>
+ <target type='lxc' port='0'/>
+ </console>
+ </devices>
+ <seclabel type='none'/>
+</domain>
diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c
index c81b0eace..9b9314cf8 100644
--- a/tests/lxcxml2xmltest.c
+++ b/tests/lxcxml2xmltest.c
@@ -100,6 +100,7 @@ mymain(void)
VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS);
DO_TEST("initenv");
DO_TEST("initdir");
+ DO_TEST("inituser");
virObjectUnref(caps);
virObjectUnref(xmlopt);
--
2.12.2
7 years, 5 months
[libvirt] [PATCH 0/2] Set lxc container working directory
by Cédric Bosdonnat
Hi all,
Here is a resubmit with:
* virExec() call orders preserved while still sharing code with
virCommandExec()
* Cleanup in the last patch
Cédric Bosdonnat (2):
util: share code between virExec and virCommandExec
lxc: allow user to specify command working directory
docs/formatdomain.html.in | 5 +++
docs/schemas/domaincommon.rng | 5 +++
src/conf/domain_conf.c | 5 +++
src/conf/domain_conf.h | 1 +
src/lxc/lxc_container.c | 2 ++
src/util/vircommand.c | 69 +++++++++++++++++++++---------------
tests/lxcxml2xmldata/lxc-initdir.xml | 30 ++++++++++++++++
tests/lxcxml2xmltest.c | 1 +
8 files changed, 89 insertions(+), 29 deletions(-)
create mode 100644 tests/lxcxml2xmldata/lxc-initdir.xml
--
2.12.2
7 years, 5 months