2007-02-14 01:40:09 +00:00
|
|
|
/*
|
2009-05-21 14:16:55 +00:00
|
|
|
* qemu_conf.c: QEMU configuration management
|
2007-02-14 01:40:09 +00:00
|
|
|
*
|
2011-07-19 21:54:48 +00:00
|
|
|
* Copyright (C) 2006-2011 Red Hat, Inc.
|
2007-02-14 01:40:09 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-11-26 11:50:16 +00:00
|
|
|
|
2007-02-14 01:40:09 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2008-10-10 16:52:20 +00:00
|
|
|
#include <stdlib.h>
|
2007-02-14 01:40:09 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2007-02-23 17:15:18 +00:00
|
|
|
#include <sys/wait.h>
|
2007-04-10 23:17:46 +00:00
|
|
|
#include <arpa/inet.h>
|
2007-04-16 13:14:28 +00:00
|
|
|
#include <sys/utsname.h>
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
#include <mntent.h>
|
2007-02-14 01:40:09 +00:00
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2007-06-27 00:12:29 +00:00
|
|
|
#include "qemu_conf.h"
|
2010-12-16 15:07:07 +00:00
|
|
|
#include "qemu_capabilities.h"
|
2009-11-03 22:41:23 +00:00
|
|
|
#include "qemu_bridge_filter.h"
|
2007-02-26 15:32:27 +00:00
|
|
|
#include "uuid.h"
|
2007-06-27 00:12:29 +00:00
|
|
|
#include "buf.h"
|
2007-10-12 16:05:44 +00:00
|
|
|
#include "conf.h"
|
2007-12-03 14:30:46 +00:00
|
|
|
#include "util.h"
|
2008-05-22 15:29:50 +00:00
|
|
|
#include "memory.h"
|
2008-12-20 13:09:45 +00:00
|
|
|
#include "datatypes.h"
|
|
|
|
#include "xml.h"
|
make NUMA-initialization code more portable and more robust
qemudCapsInitNUMA and umlCapsInitNUMA were identical, so this change
factors them into a new function, virCapsInitNUMA, and puts it in
nodeinfo.c.
In addition to factoring out the duplicates, this change also
adjusts that function definition (along with its macros) so
that it works with Fedora 9's numactl version 1, and makes it
so the code will work even if someone builds the kernel with
CONFIG_NR_CPUS > 4096.
Finally, also perform this NUMA initialization for the lxc
and openvz drivers.
* src/nodeinfo.c: Include <stdint.h>, <numa.h> and "memory.h".
(virCapsInitNUMA): Rename from qemudCapsInitNUMA and umlCapsInitNUMA.
(NUMA_MAX_N_CPUS): Define depending on NUMA API version.
(n_bits, MASK_CPU_ISSET): Define, adjust, use uint64 rather than long.
* src/nodeinfo.h: Include "capabilities.h".
(virCapsInitNUMA): Declare it.
* examples/domain-events/events-c/Makefile.am:
* src/Makefile.am: Add $(NUMACTL_CFLAGS) and $(NUMACTL_LIBS) to various
compile/link-related variables.
* src/qemu_conf.c: Include "nodeinfo.h".
(qemudCapsInitNUMA): Remove duplicate code. Adjust caller.
* src/uml_conf.c (umlCapsInitNUMA): Likewise.
Include "nodeinfo.h".
* src/lxc_conf.c: Include "nodeinfo.h".
(lxcCapsInit): Perform NUMA initialization here, too.
* src/openvz_conf.c (openvzCapsInit): And here.
Include "nodeinfo.h".
* src/libvirt_sym.version.in: Add virCapsInitNUMA so that libvirtd
can link to this function.
2008-12-21 18:55:09 +00:00
|
|
|
#include "nodeinfo.h"
|
2009-03-03 11:40:08 +00:00
|
|
|
#include "logging.h"
|
2009-12-18 15:24:14 +00:00
|
|
|
#include "cpu/cpu.h"
|
2010-06-21 18:18:31 +00:00
|
|
|
#include "domain_nwfilter.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2010-11-16 14:54:17 +00:00
|
|
|
#include "configmake.h"
|
2008-07-11 19:34:11 +00:00
|
|
|
|
2009-01-23 16:22:20 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2012-03-19 13:28:10 +00:00
|
|
|
struct _qemuDriverCloseDef {
|
|
|
|
virConnectPtr conn;
|
|
|
|
qemuDriverCloseCallback cb;
|
|
|
|
};
|
|
|
|
|
2010-12-16 16:11:48 +00:00
|
|
|
void qemuDriverLock(struct qemud_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexLock(&driver->lock);
|
|
|
|
}
|
|
|
|
void qemuDriverUnlock(struct qemud_driver *driver)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&driver->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 16:05:44 +00:00
|
|
|
int qemudLoadDriverConfig(struct qemud_driver *driver,
|
|
|
|
const char *filename) {
|
|
|
|
virConfPtr conf;
|
|
|
|
virConfValuePtr p;
|
2009-07-15 21:25:01 +00:00
|
|
|
char *user;
|
|
|
|
char *group;
|
2009-07-22 15:08:04 +00:00
|
|
|
int i;
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2010-01-13 17:41:36 +00:00
|
|
|
/* Setup critical defaults */
|
Add two new security label types
Curently security labels can be of type 'dynamic' or 'static'.
If no security label is given, then 'dynamic' is assumed. The
current code takes advantage of this default, and avoids even
saving <seclabel> elements with type='dynamic' to disk. This
means if you temporarily change security driver, the guests
can all still start.
With the introduction of sVirt to LXC though, there needs to be
a new default of 'none' to allow unconfined LXC containers.
This patch introduces two new security label types
- default: the host configuration decides whether to run the
guest with type 'none' or 'dynamic' at guest start
- none: the guest will run unconfined by security policy
The 'none' label type will obviously be undesirable for some
deployments, so a new qemu.conf option allows a host admin to
mandate confined guests. It is also possible to turn off default
confinement
security_default_confined = 1|0 (default == 1)
security_require_confined = 1|0 (default == 0)
* src/conf/domain_conf.c, src/conf/domain_conf.h: Add new
seclabel types
* src/security/security_manager.c, src/security/security_manager.h:
Set default sec label types
* src/security/security_selinux.c: Handle 'none' seclabel type
* src/qemu/qemu.conf, src/qemu/qemu_conf.c, src/qemu/qemu_conf.h,
src/qemu/libvirtd_qemu.aug: New security config options
* src/qemu/qemu_driver.c: Tell security driver about default
config
2012-01-25 14:12:52 +00:00
|
|
|
driver->securityDefaultConfined = true;
|
|
|
|
driver->securityRequireConfined = false;
|
2010-01-13 17:41:36 +00:00
|
|
|
driver->dynamicOwnership = 1;
|
2010-05-27 23:17:55 +00:00
|
|
|
driver->clearEmulatorCapabilities = 1;
|
2010-01-13 17:41:36 +00:00
|
|
|
|
2008-07-11 19:34:11 +00:00
|
|
|
if (!(driver->vncListen = strdup("127.0.0.1"))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-07-11 19:34:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-11-16 14:54:17 +00:00
|
|
|
if (!(driver->vncTLSx509certdir = strdup(SYSCONFDIR "/pki/libvirt-vnc"))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2007-10-12 16:05:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:31:50 +00:00
|
|
|
if (!(driver->spiceListen = strdup("127.0.0.1"))) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2010-11-16 14:54:17 +00:00
|
|
|
if (!(driver->spiceTLSx509certdir
|
|
|
|
= strdup(SYSCONFDIR "/pki/libvirt-spice"))) {
|
2010-03-05 20:31:50 +00:00
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-23 09:34:17 +00:00
|
|
|
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
/* For privileged driver, try and find hugepage mount automatically.
|
|
|
|
* Non-privileged driver requires admin to create a dir for the
|
|
|
|
* user, chown it, and then let user configure it manually */
|
|
|
|
if (driver->privileged &&
|
|
|
|
!(driver->hugetlbfs_mount = virFileFindMountPoint("hugetlbfs"))) {
|
|
|
|
if (errno != ENOENT) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
_("unable to find hugetlbfs mountpoint"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-26 14:04:46 +00:00
|
|
|
if (!(driver->lockManager =
|
2011-06-13 13:30:26 +00:00
|
|
|
virLockManagerPluginNew("nop", NULL, 0)))
|
2010-10-26 14:04:46 +00:00
|
|
|
return -1;
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
|
2011-09-16 11:50:56 +00:00
|
|
|
driver->keepAliveInterval = 5;
|
|
|
|
driver->keepAliveCount = 5;
|
|
|
|
|
2007-10-12 16:05:44 +00:00
|
|
|
/* Just check the file is readable before opening it, otherwise
|
|
|
|
* libvirt emits an error.
|
|
|
|
*/
|
2010-06-30 18:14:37 +00:00
|
|
|
if (access (filename, R_OK) == -1) {
|
|
|
|
VIR_INFO("Could not read qemu config file %s", filename);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-12 16:05:44 +00:00
|
|
|
|
2009-06-19 12:34:30 +00:00
|
|
|
conf = virConfReadFile (filename, 0);
|
2010-06-30 18:14:37 +00:00
|
|
|
if (!conf) {
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-12 16:05:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_TYPE(name,typ) if (p && p->type != (typ)) { \
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, \
|
2010-06-30 18:14:37 +00:00
|
|
|
"%s: %s: expected type " #typ, \
|
|
|
|
filename, (name)); \
|
2007-10-12 16:05:44 +00:00
|
|
|
virConfFree(conf); \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
2011-01-12 04:44:11 +00:00
|
|
|
p = virConfGetValue (conf, "vnc_auto_unix_socket");
|
|
|
|
CHECK_TYPE ("vnc_auto_unix_socket", VIR_CONF_LONG);
|
|
|
|
if (p) driver->vncAutoUnixSocket = p->l;
|
|
|
|
|
2007-10-12 16:05:44 +00:00
|
|
|
p = virConfGetValue (conf, "vnc_tls");
|
|
|
|
CHECK_TYPE ("vnc_tls", VIR_CONF_LONG);
|
|
|
|
if (p) driver->vncTLS = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "vnc_tls_x509_verify");
|
|
|
|
CHECK_TYPE ("vnc_tls_x509_verify", VIR_CONF_LONG);
|
|
|
|
if (p) driver->vncTLSx509verify = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "vnc_tls_x509_cert_dir");
|
|
|
|
CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
2008-05-29 19:20:22 +00:00
|
|
|
VIR_FREE(driver->vncTLSx509certdir);
|
2007-10-12 16:05:44 +00:00
|
|
|
if (!(driver->vncTLSx509certdir = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2007-10-12 16:05:44 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "vnc_listen");
|
|
|
|
CHECK_TYPE ("vnc_listen", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
2008-11-05 14:24:21 +00:00
|
|
|
VIR_FREE(driver->vncListen);
|
2008-07-11 19:34:11 +00:00
|
|
|
if (!(driver->vncListen = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-07-11 19:34:11 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-12 16:05:44 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 17:50:00 +00:00
|
|
|
p = virConfGetValue (conf, "vnc_password");
|
|
|
|
CHECK_TYPE ("vnc_password", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->vncPassword);
|
|
|
|
if (!(driver->vncPassword = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-01-29 17:50:00 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-03 12:03:44 +00:00
|
|
|
p = virConfGetValue (conf, "security_driver");
|
2009-03-03 15:12:30 +00:00
|
|
|
CHECK_TYPE ("security_driver", VIR_CONF_STRING);
|
2009-03-03 12:03:44 +00:00
|
|
|
if (p && p->str) {
|
|
|
|
if (!(driver->securityDriverName = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-03-03 12:03:44 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add two new security label types
Curently security labels can be of type 'dynamic' or 'static'.
If no security label is given, then 'dynamic' is assumed. The
current code takes advantage of this default, and avoids even
saving <seclabel> elements with type='dynamic' to disk. This
means if you temporarily change security driver, the guests
can all still start.
With the introduction of sVirt to LXC though, there needs to be
a new default of 'none' to allow unconfined LXC containers.
This patch introduces two new security label types
- default: the host configuration decides whether to run the
guest with type 'none' or 'dynamic' at guest start
- none: the guest will run unconfined by security policy
The 'none' label type will obviously be undesirable for some
deployments, so a new qemu.conf option allows a host admin to
mandate confined guests. It is also possible to turn off default
confinement
security_default_confined = 1|0 (default == 1)
security_require_confined = 1|0 (default == 0)
* src/conf/domain_conf.c, src/conf/domain_conf.h: Add new
seclabel types
* src/security/security_manager.c, src/security/security_manager.h:
Set default sec label types
* src/security/security_selinux.c: Handle 'none' seclabel type
* src/qemu/qemu.conf, src/qemu/qemu_conf.c, src/qemu/qemu_conf.h,
src/qemu/libvirtd_qemu.aug: New security config options
* src/qemu/qemu_driver.c: Tell security driver about default
config
2012-01-25 14:12:52 +00:00
|
|
|
p = virConfGetValue (conf, "security_default_confined");
|
|
|
|
CHECK_TYPE ("security_default_confined", VIR_CONF_LONG);
|
|
|
|
if (p) driver->securityDefaultConfined = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "security_require_confined");
|
|
|
|
CHECK_TYPE ("security_require_confined", VIR_CONF_LONG);
|
|
|
|
if (p) driver->securityRequireConfined = p->l;
|
|
|
|
|
|
|
|
|
2009-03-16 13:54:26 +00:00
|
|
|
p = virConfGetValue (conf, "vnc_sasl");
|
|
|
|
CHECK_TYPE ("vnc_sasl", VIR_CONF_LONG);
|
|
|
|
if (p) driver->vncSASL = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "vnc_sasl_dir");
|
|
|
|
CHECK_TYPE ("vnc_sasl_dir", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->vncSASLdir);
|
|
|
|
if (!(driver->vncSASLdir = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-03-16 13:54:26 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:31:50 +00:00
|
|
|
p = virConfGetValue (conf, "spice_tls");
|
|
|
|
CHECK_TYPE ("spice_tls", VIR_CONF_LONG);
|
|
|
|
if (p) driver->spiceTLS = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "spice_tls_x509_cert_dir");
|
|
|
|
CHECK_TYPE ("spice_tls_x509_cert_dir", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->spiceTLSx509certdir);
|
|
|
|
if (!(driver->spiceTLSx509certdir = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "spice_listen");
|
|
|
|
CHECK_TYPE ("spice_listen", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->spiceListen);
|
|
|
|
if (!(driver->spiceListen = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "spice_password");
|
|
|
|
CHECK_TYPE ("spice_password", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->spicePassword);
|
|
|
|
if (!(driver->spicePassword = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 21:25:01 +00:00
|
|
|
p = virConfGetValue (conf, "user");
|
|
|
|
CHECK_TYPE ("user", VIR_CONF_STRING);
|
|
|
|
if (!(user = strdup(p && p->str ? p->str : QEMU_USER))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-15 21:25:01 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virGetUserID(user, &driver->user) < 0) {
|
2009-07-15 21:25:01 +00:00
|
|
|
VIR_FREE(user);
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(user);
|
|
|
|
|
2010-01-13 17:41:36 +00:00
|
|
|
|
2009-07-15 21:25:01 +00:00
|
|
|
p = virConfGetValue (conf, "group");
|
|
|
|
CHECK_TYPE ("group", VIR_CONF_STRING);
|
|
|
|
if (!(group = strdup(p && p->str ? p->str : QEMU_GROUP))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-15 21:25:01 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virGetGroupID(group, &driver->group) < 0) {
|
2009-07-15 21:25:01 +00:00
|
|
|
VIR_FREE(group);
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
VIR_FREE(group);
|
|
|
|
|
2010-01-13 17:41:36 +00:00
|
|
|
|
|
|
|
p = virConfGetValue (conf, "dynamic_ownership");
|
|
|
|
CHECK_TYPE ("dynamic_ownership", VIR_CONF_LONG);
|
|
|
|
if (p) driver->dynamicOwnership = p->l;
|
|
|
|
|
|
|
|
|
2009-07-22 15:08:04 +00:00
|
|
|
p = virConfGetValue (conf, "cgroup_controllers");
|
|
|
|
CHECK_TYPE ("cgroup_controllers", VIR_CONF_LIST);
|
|
|
|
if (p) {
|
|
|
|
virConfValuePtr pp;
|
|
|
|
for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
|
|
|
|
int ctl;
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("cgroup_controllers must be a list of strings"));
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ctl = virCgroupControllerTypeFromString(pp->str);
|
|
|
|
if (ctl < 0) {
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("Unknown cgroup controller '%s'"), pp->str);
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
driver->cgroupControllers |= (1 << ctl);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
driver->cgroupControllers =
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
2010-10-12 16:12:31 +00:00
|
|
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES) |
|
2011-02-08 06:59:38 +00:00
|
|
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY) |
|
2011-11-17 09:44:12 +00:00
|
|
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO) |
|
2012-03-02 02:54:23 +00:00
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPUSET) |
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPUACCT);
|
2009-07-22 15:08:04 +00:00
|
|
|
}
|
|
|
|
for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
|
|
|
|
if (driver->cgroupControllers & (1 << i)) {
|
|
|
|
VIR_INFO("Configured cgroup controller '%s'",
|
|
|
|
virCgroupControllerTypeToString(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "cgroup_device_acl");
|
|
|
|
CHECK_TYPE ("cgroup_device_acl", VIR_CONF_LIST);
|
|
|
|
if (p) {
|
|
|
|
int len = 0;
|
|
|
|
virConfValuePtr pp;
|
|
|
|
for (pp = p->list; pp; pp = pp->next)
|
|
|
|
len++;
|
|
|
|
if (VIR_ALLOC_N(driver->cgroupDeviceACL, 1+len) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
|
|
|
|
if (pp->type != VIR_CONF_STRING) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_ERROR(_("cgroup_device_acl must be a list of strings"));
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
driver->cgroupDeviceACL[i] = strdup (pp->str);
|
|
|
|
if (driver->cgroupDeviceACL[i] == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-07-22 15:08:04 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
driver->cgroupDeviceACL[i] = NULL;
|
|
|
|
}
|
|
|
|
|
Compressed save image format for Qemu.
Implement a compressed save image format for qemu. While ideally
we would have the choice between compressed/non-compressed
available to the libvirt API, unfortunately there is no "flags"
parameter to the virDomainSave() API. Therefore, implement this
as a qemu.conf option. gzip, bzip2, and lzma are implemented, and
it should be very easy to implement additional compression
methods.
One open question is if/how we should detect the compression
binaries. One way to do it is to do compile-time setting of the
paths (via configure.in), but that doesn't seem like a great thing
to do. My preferred solution is not to detect at all;
when we go to run the commands that need them, if they
aren't available, or aren't available in one of the standard paths,
then we'll fail. That's also the solution implemented in this patch.
In the future, we'll have a more robust (managed) save/restore API,
at which time we can expose this functionality properly in the API.
V2: get rid of redundant dd command and just use >> to append data.
V3: Add back the missing pieces for the enum and bumping the save version.
V4: Make the compressed field in the save_header an int.
Implement LZMA compression.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-07 11:34:05 +00:00
|
|
|
p = virConfGetValue (conf, "save_image_format");
|
|
|
|
CHECK_TYPE ("save_image_format", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->saveImageFormat);
|
|
|
|
if (!(driver->saveImageFormat = strdup(p->str))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
Compressed save image format for Qemu.
Implement a compressed save image format for qemu. While ideally
we would have the choice between compressed/non-compressed
available to the libvirt API, unfortunately there is no "flags"
parameter to the virDomainSave() API. Therefore, implement this
as a qemu.conf option. gzip, bzip2, and lzma are implemented, and
it should be very easy to implement additional compression
methods.
One open question is if/how we should detect the compression
binaries. One way to do it is to do compile-time setting of the
paths (via configure.in), but that doesn't seem like a great thing
to do. My preferred solution is not to detect at all;
when we go to run the commands that need them, if they
aren't available, or aren't available in one of the standard paths,
then we'll fail. That's also the solution implemented in this patch.
In the future, we'll have a more robust (managed) save/restore API,
at which time we can expose this functionality properly in the API.
V2: get rid of redundant dd command and just use >> to append data.
V3: Add back the missing pieces for the enum and bumping the save version.
V4: Make the compressed field in the save_header an int.
Implement LZMA compression.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2009-08-07 11:34:05 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-28 07:31:46 +00:00
|
|
|
p = virConfGetValue (conf, "dump_image_format");
|
|
|
|
CHECK_TYPE ("dump_image_format", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->dumpImageFormat);
|
|
|
|
if (!(driver->dumpImageFormat = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 06:19:17 +00:00
|
|
|
p = virConfGetValue (conf, "auto_dump_path");
|
|
|
|
CHECK_TYPE ("auto_dump_path", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->autoDumpPath);
|
|
|
|
if (!(driver->autoDumpPath = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-19 21:54:48 +00:00
|
|
|
p = virConfGetValue (conf, "auto_dump_bypass_cache");
|
|
|
|
CHECK_TYPE ("auto_dump_bypass_cache", VIR_CONF_LONG);
|
|
|
|
if (p) driver->autoDumpBypassCache = true;
|
|
|
|
|
|
|
|
p = virConfGetValue (conf, "auto_start_bypass_cache");
|
|
|
|
CHECK_TYPE ("auto_start_bypass_cache", VIR_CONF_LONG);
|
|
|
|
if (p) driver->autoStartBypassCache = true;
|
|
|
|
|
2011-06-14 08:11:31 +00:00
|
|
|
p = virConfGetValue (conf, "hugetlbfs_mount");
|
|
|
|
CHECK_TYPE ("hugetlbfs_mount", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
|
|
|
VIR_FREE(driver->hugetlbfs_mount);
|
|
|
|
if (!(driver->hugetlbfs_mount = strdup(p->str))) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
Support configuration of huge pages in guests
Add option to domain XML for
<memoryBacking>
<hugepages/>
</memoryBacking>
* configure.in: Add check for mntent.h
* qemud/libvirtd_qemu.aug, qemud/test_libvirtd_qemu.aug, src/qemu.conf
Add 'hugetlbfs_mount' config parameter
* src/qemu_conf.c, src/qemu_conf.h: Check for -mem-path flag in QEMU,
and pass it when hugepages are requested.
Load hugetlbfs_mount config parameter, search for mount if not given.
* src/qemu_driver.c: Free hugetlbfs_mount/path parameter in driver shutdown.
Create directory for QEMU hugepage usage, chowning if required.
* docs/formatdomain.html.in: Document memoryBacking/hugepages elements
* docs/schemas/domain.rng: Add memoryBacking/hugepages elements to schema
* src/util.c, src/util.h, src/libvirt_private.syms: Add virFileFindMountPoint
helper API
* tests/qemuhelptest.c: Add -mem-path constants
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c: Add tests for hugepage
handling
* tests/qemuxml2argvdata/qemuxml2argv-hugepages.xml,
tests/qemuxml2argvdata/qemuxml2argv-hugepages.args: Data files for
hugepage tests
2009-08-25 14:05:18 +00:00
|
|
|
|
2009-11-03 22:41:23 +00:00
|
|
|
p = virConfGetValue (conf, "mac_filter");
|
|
|
|
CHECK_TYPE ("mac_filter", VIR_CONF_LONG);
|
2009-11-11 11:59:54 +00:00
|
|
|
if (p && p->l) {
|
2009-11-03 22:41:23 +00:00
|
|
|
driver->macFilter = p->l;
|
|
|
|
if (!(driver->ebtables = ebtablesContextNew("qemu"))) {
|
|
|
|
driver->macFilter = 0;
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2010-02-19 14:41:30 +00:00
|
|
|
_("failed to enable mac filter in '%s'"),
|
2009-11-03 22:41:23 +00:00
|
|
|
__FILE__);
|
2011-06-14 08:11:31 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
2009-11-03 22:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((errno = networkDisableAllFrames(driver))) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-11-03 22:41:23 +00:00
|
|
|
_("failed to add rule to drop all frames in '%s'"),
|
|
|
|
__FILE__);
|
2011-06-14 08:11:31 +00:00
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
2009-11-03 22:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-22 17:21:16 +00:00
|
|
|
p = virConfGetValue (conf, "relaxed_acs_check");
|
|
|
|
CHECK_TYPE ("relaxed_acs_check", VIR_CONF_LONG);
|
|
|
|
if (p) driver->relaxedACS = p->l;
|
|
|
|
|
2010-05-19 20:41:01 +00:00
|
|
|
p = virConfGetValue (conf, "vnc_allow_host_audio");
|
|
|
|
CHECK_TYPE ("vnc_allow_host_audio", VIR_CONF_LONG);
|
|
|
|
if (p) driver->vncAllowHostAudio = p->l;
|
|
|
|
|
2010-05-27 23:17:55 +00:00
|
|
|
p = virConfGetValue (conf, "clear_emulator_capabilities");
|
|
|
|
CHECK_TYPE ("clear_emulator_capabilities", VIR_CONF_LONG);
|
|
|
|
if (p) driver->clearEmulatorCapabilities = p->l;
|
|
|
|
|
2010-06-15 16:58:58 +00:00
|
|
|
p = virConfGetValue (conf, "allow_disk_format_probing");
|
|
|
|
CHECK_TYPE ("allow_disk_format_probing", VIR_CONF_LONG);
|
|
|
|
if (p) driver->allowDiskFormatProbing = p->l;
|
|
|
|
|
2010-10-20 08:25:05 +00:00
|
|
|
p = virConfGetValue (conf, "set_process_name");
|
|
|
|
CHECK_TYPE ("set_process_name", VIR_CONF_LONG);
|
|
|
|
if (p) driver->setProcessName = p->l;
|
|
|
|
|
2011-04-05 12:17:28 +00:00
|
|
|
p = virConfGetValue(conf, "max_processes");
|
|
|
|
CHECK_TYPE("max_processes", VIR_CONF_LONG);
|
|
|
|
if (p) driver->maxProcesses = p->l;
|
|
|
|
|
2011-12-22 11:22:31 +00:00
|
|
|
p = virConfGetValue(conf, "max_files");
|
|
|
|
CHECK_TYPE("max_files", VIR_CONF_LONG);
|
|
|
|
if (p) driver->maxFiles = p->l;
|
|
|
|
|
2010-10-26 14:04:46 +00:00
|
|
|
p = virConfGetValue (conf, "lock_manager");
|
|
|
|
CHECK_TYPE ("lock_manager", VIR_CONF_STRING);
|
|
|
|
if (p && p->str) {
|
2011-06-13 13:30:26 +00:00
|
|
|
char *lockConf;
|
2010-10-26 14:04:46 +00:00
|
|
|
virLockManagerPluginUnref(driver->lockManager);
|
2011-06-13 13:30:26 +00:00
|
|
|
if (virAsprintf(&lockConf, "%s/libvirt/qemu-%s.conf", SYSCONFDIR, p->str) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
virConfFree(conf);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-10-26 14:04:46 +00:00
|
|
|
if (!(driver->lockManager =
|
2011-06-13 13:30:26 +00:00
|
|
|
virLockManagerPluginNew(p->str, lockConf, 0)))
|
2010-10-26 14:04:46 +00:00
|
|
|
VIR_ERROR(_("Failed to load lock manager %s"), p->str);
|
2011-06-13 13:30:26 +00:00
|
|
|
VIR_FREE(lockConf);
|
2010-10-26 14:04:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 13:29:37 +00:00
|
|
|
p = virConfGetValue(conf, "max_queued");
|
|
|
|
CHECK_TYPE("max_queued", VIR_CONF_LONG);
|
|
|
|
if (p) driver->max_queued = p->l;
|
|
|
|
|
2011-09-16 11:50:56 +00:00
|
|
|
p = virConfGetValue(conf, "keepalive_interval");
|
|
|
|
CHECK_TYPE("keepalive_interval", VIR_CONF_LONG);
|
|
|
|
if (p) driver->keepAliveInterval = p->l;
|
|
|
|
|
|
|
|
p = virConfGetValue(conf, "keepalive_count");
|
|
|
|
CHECK_TYPE("keepalive_count", VIR_CONF_LONG);
|
|
|
|
if (p) driver->keepAliveCount = p->l;
|
|
|
|
|
2007-10-12 16:05:44 +00:00
|
|
|
virConfFree (conf);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-03-19 13:28:10 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
qemuDriverCloseCallbackFree(void *payload,
|
|
|
|
const void *name ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
VIR_FREE(payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuDriverCloseCallbackInit(struct qemud_driver *driver)
|
|
|
|
{
|
|
|
|
driver->closeCallbacks = virHashCreate(5, qemuDriverCloseCallbackFree);
|
|
|
|
if (!driver->closeCallbacks)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qemuDriverCloseCallbackShutdown(struct qemud_driver *driver)
|
|
|
|
{
|
|
|
|
virHashFree(driver->closeCallbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuDriverCloseCallbackSet(struct qemud_driver *driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virConnectPtr conn,
|
|
|
|
qemuDriverCloseCallback cb)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
qemuDriverCloseDefPtr closeDef;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
VIR_DEBUG("vm=%s, uuid=%s, conn=%p, cb=%p",
|
|
|
|
vm->def->name, uuidstr, conn, cb);
|
|
|
|
|
|
|
|
closeDef = virHashLookup(driver->closeCallbacks, uuidstr);
|
|
|
|
if (closeDef) {
|
|
|
|
if (closeDef->conn != conn) {
|
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Close callback for domain %s already registered"
|
|
|
|
" with another connection %p"),
|
|
|
|
vm->def->name, closeDef->conn);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (closeDef->cb && closeDef->cb != cb) {
|
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Another close callback is already defined for"
|
|
|
|
" domain %s"), vm->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDef->cb = cb;
|
|
|
|
} else {
|
|
|
|
if (VIR_ALLOC(closeDef) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDef->conn = conn;
|
|
|
|
closeDef->cb = cb;
|
|
|
|
if (virHashAddEntry(driver->closeCallbacks, uuidstr, closeDef) < 0) {
|
|
|
|
VIR_FREE(closeDef);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuDriverCloseCallbackUnset(struct qemud_driver *driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
qemuDriverCloseCallback cb)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
qemuDriverCloseDefPtr closeDef;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
VIR_DEBUG("vm=%s, uuid=%s, cb=%p",
|
|
|
|
vm->def->name, uuidstr, cb);
|
|
|
|
|
|
|
|
closeDef = virHashLookup(driver->closeCallbacks, uuidstr);
|
|
|
|
if (!closeDef)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (closeDef->cb && closeDef->cb != cb) {
|
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Trying to remove mismatching close callback for"
|
|
|
|
" domain %s"), vm->def->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return virHashRemoveEntry(driver->closeCallbacks, uuidstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuDriverCloseCallback
|
|
|
|
qemuDriverCloseCallbackGet(struct qemud_driver *driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virConnectPtr conn)
|
|
|
|
{
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
qemuDriverCloseDefPtr closeDef;
|
|
|
|
qemuDriverCloseCallback cb = NULL;
|
|
|
|
|
|
|
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
|
|
|
VIR_DEBUG("vm=%s, uuid=%s, conn=%p",
|
|
|
|
vm->def->name, uuidstr, conn);
|
|
|
|
|
|
|
|
closeDef = virHashLookup(driver->closeCallbacks, uuidstr);
|
|
|
|
if (closeDef && (!conn || closeDef->conn == conn))
|
|
|
|
cb = closeDef->cb;
|
|
|
|
|
|
|
|
VIR_DEBUG("cb=%p", cb);
|
|
|
|
return cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qemuDriverCloseCallbackData {
|
|
|
|
struct qemud_driver *driver;
|
|
|
|
virConnectPtr conn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuDriverCloseCallbackRun(void *payload,
|
|
|
|
const void *name,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
struct qemuDriverCloseCallbackData *data = opaque;
|
|
|
|
qemuDriverCloseDefPtr closeDef = payload;
|
|
|
|
const char *uuidstr = name;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
virDomainObjPtr dom;
|
|
|
|
|
|
|
|
VIR_DEBUG("conn=%p, thisconn=%p, uuid=%s, cb=%p",
|
|
|
|
closeDef->conn, data->conn, uuidstr, closeDef->cb);
|
|
|
|
|
|
|
|
if (data->conn != closeDef->conn || !closeDef->cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
|
|
|
VIR_WARN("Failed to parse %s", uuidstr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(dom = virDomainFindByUUID(&data->driver->domains, uuid))) {
|
|
|
|
VIR_DEBUG("No domain object with UUID %s", uuidstr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom = closeDef->cb(data->driver, dom, data->conn);
|
|
|
|
if (dom)
|
|
|
|
virDomainObjUnlock(dom);
|
|
|
|
|
|
|
|
virHashRemoveEntry(data->driver->closeCallbacks, uuidstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qemuDriverCloseCallbackRunAll(struct qemud_driver *driver,
|
|
|
|
virConnectPtr conn)
|
|
|
|
{
|
|
|
|
struct qemuDriverCloseCallbackData data = {
|
|
|
|
driver, conn
|
|
|
|
};
|
|
|
|
VIR_DEBUG("conn=%p", conn);
|
|
|
|
|
|
|
|
virHashForEach(driver->closeCallbacks, qemuDriverCloseCallbackRun, &data);
|
|
|
|
}
|