2008-11-25 10:44:52 +00:00
|
|
|
/*
|
2014-03-07 13:38:51 +00:00
|
|
|
* xen_inotify.c: Xen notification of xml file activity in the
|
2008-11-25 10:44:52 +00:00
|
|
|
* following dirs:
|
|
|
|
* /etc/xen
|
|
|
|
* /var/lib/xend/domains
|
|
|
|
*
|
2013-01-29 14:22:46 +00:00
|
|
|
* Copyright (C) 2010-2013 Red Hat, Inc.
|
2008-11-25 10:44:52 +00:00
|
|
|
* Copyright (C) 2008 VirtualIron
|
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-25 10:44:52 +00:00
|
|
|
*
|
|
|
|
* Author: Ben Guthro
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2008-11-25 10:44:52 +00:00
|
|
|
#include "datatypes.h"
|
|
|
|
#include "driver.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
Move xen driver code into src/xen/ directory
* src/Makefile.am, src/proxy_internal.c, src/proxy_internal.h
src/sexpr.c, src/sexpr.h, src/xen_unified.c, src/xen_unified.h,
src/xen_internal.c, src/xen_internal.h, src/xen_inotify.c,
src/xen_inotify.h, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h, src/xs_internal.c,
src/xs_internal.h: Move to src/xen/ directory
* proxy/Makefile.am, proxy/libvirt_proxy.c, src/Makefile.am,
src/libvirt.c, tests/sexpr2xmltest.c, tests/statstest.c,
tests/xencapstest.c, tests/xmconfigtest.c, tests/xml2sexprtest.c:
Adapt to changed xen location
* src/stats_linux.h, src/stats_linux.c: Remove xen specific block
stats APIs
* src/qemu_driver.c, src/uml_driver.c: Add missing sys/un.h include
uncovered after change to stats_linux.h
* src/xen/block_stats.h, src/xen/block_stats.c: Add xen specific
block stats APIs
2009-09-15 15:38:33 +00:00
|
|
|
#include "xen_driver.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2008-11-25 10:44:52 +00:00
|
|
|
#include "domain_conf.h"
|
|
|
|
#include "xen_inotify.h"
|
|
|
|
#include "xend_internal.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2013-05-03 12:51:25 +00:00
|
|
|
#include "virstring.h"
|
2008-11-25 10:44:52 +00:00
|
|
|
#include "xm_internal.h" /* for xenXMDomainConfigParse */
|
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("xen.xen_inotify");
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
static int
|
2009-01-20 17:34:56 +00:00
|
|
|
xenInotifyXenCacheLookup(virConnectPtr conn,
|
|
|
|
const char *filename,
|
2013-01-29 14:22:46 +00:00
|
|
|
char **name,
|
|
|
|
unsigned char *uuid)
|
|
|
|
{
|
2009-01-20 17:34:56 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
2008-11-25 10:44:52 +00:00
|
|
|
xenXMConfCachePtr entry;
|
|
|
|
|
2009-01-20 17:34:56 +00:00
|
|
|
if (!(entry = virHashLookup(priv->configCache, filename))) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("No config found for %s", filename);
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
memcpy(uuid, entry->def->uuid, VIR_UUID_BUFLEN);
|
2013-05-03 12:51:25 +00:00
|
|
|
if (VIR_STRDUP(*name, entry->def->name) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("Error getting dom from def");
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
2008-12-04 21:09:20 +00:00
|
|
|
return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
static int
|
2013-01-29 14:22:46 +00:00
|
|
|
xenInotifyXendDomainsDirLookup(virConnectPtr conn,
|
|
|
|
const char *filename,
|
|
|
|
char **name,
|
|
|
|
unsigned char *uuid)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in src/{xen,xenapi,xenxs} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-05-01 09:31:23 +00:00
|
|
|
virDomainDefPtr def;
|
2008-11-25 10:44:52 +00:00
|
|
|
const char *uuid_str;
|
2008-12-04 21:09:20 +00:00
|
|
|
unsigned char rawuuid[VIR_UUID_BUFLEN];
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
/* xend is managing domains. we will get
|
|
|
|
* a filename in the manner:
|
|
|
|
* /var/lib/xend/domains/<uuid>/
|
|
|
|
*/
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
uuid_str = filename + strlen(XEND_DOMAINS_DIR) + 1;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
if (virUUIDParse(uuid_str, rawuuid) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("parsing uuid %s"), uuid_str);
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
/* call directly into xend here, as driver may not yet
|
|
|
|
be set during open while we are building our
|
|
|
|
initial list of domains */
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("Looking for dom with uuid: %s", uuid_str);
|
2013-05-01 09:31:23 +00:00
|
|
|
|
|
|
|
if (!(def = xenDaemonLookupByUUID(conn, rawuuid))) {
|
2008-11-25 10:44:52 +00:00
|
|
|
/* If we are here, the domain has gone away.
|
|
|
|
search for, and create a domain from the stored
|
|
|
|
list info */
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < priv->configInfoList->count; i++) {
|
2009-10-24 17:20:33 +00:00
|
|
|
if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
|
2013-05-03 12:51:25 +00:00
|
|
|
if (VIR_STRDUP(*name, priv->configInfoList->doms[i]->name) < 0)
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2009-01-20 17:19:23 +00:00
|
|
|
memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN);
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("Found dom on list");
|
2008-12-04 21:09:20 +00:00
|
|
|
return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("finding dom on config list"));
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:51:25 +00:00
|
|
|
if (VIR_STRDUP(*name, def->name) < 0) {
|
2013-05-01 09:31:23 +00:00
|
|
|
virDomainDefFree(def);
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2009-11-08 21:08:54 +00:00
|
|
|
}
|
2013-05-01 09:31:23 +00:00
|
|
|
memcpy(uuid, def->uuid, VIR_UUID_BUFLEN);
|
|
|
|
virDomainDefFree(def);
|
2008-11-25 10:44:52 +00:00
|
|
|
/* succeeded too find domain by uuid */
|
2008-12-04 21:09:20 +00:00
|
|
|
return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
static int
|
|
|
|
xenInotifyDomainLookup(virConnectPtr conn,
|
|
|
|
const char *filename,
|
2013-01-29 14:22:46 +00:00
|
|
|
char **name,
|
|
|
|
unsigned char *uuid)
|
|
|
|
{
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
|
|
|
if (priv->useXenConfigCache)
|
2009-01-20 17:34:56 +00:00
|
|
|
return xenInotifyXenCacheLookup(conn, filename, name, uuid);
|
2008-12-04 21:09:20 +00:00
|
|
|
else
|
|
|
|
return xenInotifyXendDomainsDirLookup(conn, filename, name, uuid);
|
|
|
|
}
|
|
|
|
|
2013-11-22 14:38:05 +00:00
|
|
|
static virObjectEventPtr
|
2008-12-04 21:09:20 +00:00
|
|
|
xenInotifyDomainEventFromFile(virConnectPtr conn,
|
|
|
|
const char *filename,
|
2013-01-29 14:22:46 +00:00
|
|
|
int type,
|
|
|
|
int detail)
|
|
|
|
{
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event;
|
2008-12-04 21:09:20 +00:00
|
|
|
char *name = NULL;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (xenInotifyDomainLookup(conn, filename, &name, uuid) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2013-11-21 17:03:26 +00:00
|
|
|
event = virDomainEventLifecycleNew(-1, name, uuid, type, detail);
|
2008-12-04 21:09:20 +00:00
|
|
|
VIR_FREE(name);
|
|
|
|
return event;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-01-29 14:22:46 +00:00
|
|
|
xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn, const char *fname)
|
|
|
|
{
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
const char *uuidstr = fname + strlen(XEND_DOMAINS_DIR) + 1;
|
2008-11-25 10:44:52 +00:00
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
Convert 'int i' to 'size_t i' in src/{xen,xenapi,xenxs} files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("parsing uuid %s"), uuidstr);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* match and remove on uuid */
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < priv->configInfoList->count; i++) {
|
2009-01-20 17:19:23 +00:00
|
|
|
if (!memcmp(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
|
|
|
|
VIR_FREE(priv->configInfoList->doms[i]->name);
|
|
|
|
VIR_FREE(priv->configInfoList->doms[i]);
|
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
VIR_DELETE_ELEMENT(priv->configInfoList->doms, i,
|
|
|
|
priv->configInfoList->count);
|
2008-11-25 10:44:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-01-29 14:22:46 +00:00
|
|
|
xenInotifyXendDomainsDirAddEntry(virConnectPtr conn, const char *fname)
|
|
|
|
{
|
2008-12-04 21:09:20 +00:00
|
|
|
char *name = NULL;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
if (xenInotifyDomainLookup(conn, fname, &name, uuid) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error looking up domain"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
if (xenUnifiedAddDomainInfo(priv->configInfoList,
|
2008-12-04 21:09:20 +00:00
|
|
|
-1, name, uuid) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error adding file to config cache"));
|
2008-12-04 21:09:20 +00:00
|
|
|
VIR_FREE(name);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-12-04 21:09:20 +00:00
|
|
|
VIR_FREE(name);
|
2008-11-25 10:44:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-01-29 14:22:46 +00:00
|
|
|
xenInotifyRemoveDomainConfigInfo(virConnectPtr conn, const char *fname)
|
|
|
|
{
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
|
|
|
return priv->useXenConfigCache ?
|
|
|
|
xenXMConfigCacheRemoveFile(conn, fname) :
|
|
|
|
xenInotifyXendDomainsDirRemoveEntry(conn, fname);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-01-29 14:22:46 +00:00
|
|
|
xenInotifyAddDomainConfigInfo(virConnectPtr conn, const char *fname)
|
|
|
|
{
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
|
|
|
return priv->useXenConfigCache ?
|
|
|
|
xenXMConfigCacheAddFile(conn, fname) :
|
|
|
|
xenInotifyXendDomainsDirAddEntry(conn, fname);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xenInotifyEvent(int watch ATTRIBUTE_UNUSED,
|
|
|
|
int fd,
|
|
|
|
int events ATTRIBUTE_UNUSED,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char fname[1024];
|
|
|
|
struct inotify_event *e;
|
|
|
|
int got;
|
|
|
|
char *tmp, *name;
|
2009-01-20 17:19:23 +00:00
|
|
|
virConnectPtr conn = data;
|
2008-11-25 10:44:52 +00:00
|
|
|
xenUnifiedPrivatePtr priv = NULL;
|
|
|
|
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("got inotify event");
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
if (conn && conn->privateData) {
|
2008-11-25 10:44:52 +00:00
|
|
|
priv = conn->privateData;
|
|
|
|
} else {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("conn, or private data is NULL"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedLock(priv);
|
|
|
|
|
2014-03-25 06:54:51 +00:00
|
|
|
reread:
|
2008-11-25 10:44:52 +00:00
|
|
|
got = read(fd, buf, sizeof(buf));
|
|
|
|
if (got == -1) {
|
|
|
|
if (errno == EINTR)
|
|
|
|
goto reread;
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp = buf;
|
|
|
|
while (got) {
|
|
|
|
if (got < sizeof(struct inotify_event))
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup; /* bad */
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2013-05-13 11:44:15 +00:00
|
|
|
VIR_WARNINGS_NO_CAST_ALIGN
|
2008-11-25 10:44:52 +00:00
|
|
|
e = (struct inotify_event *)tmp;
|
2013-05-13 11:44:15 +00:00
|
|
|
VIR_WARNINGS_RESET
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
tmp += sizeof(struct inotify_event);
|
|
|
|
got -= sizeof(struct inotify_event);
|
|
|
|
|
|
|
|
if (got < e->len)
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
tmp += e->len;
|
|
|
|
got -= e->len;
|
|
|
|
|
|
|
|
name = (char *)&(e->name);
|
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
snprintf(fname, 1024, "%s/%s",
|
|
|
|
priv->configDir, name);
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if (e->mask & (IN_DELETE | IN_MOVED_FROM)) {
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event =
|
2008-12-04 21:09:20 +00:00
|
|
|
xenInotifyDomainEventFromFile(conn, fname,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
|
2009-10-24 17:20:33 +00:00
|
|
|
if (event)
|
2008-12-04 21:09:20 +00:00
|
|
|
xenUnifiedDomainEventDispatch(conn->privateData, event);
|
|
|
|
else
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("looking up dom"));
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
if (xenInotifyRemoveDomainConfigInfo(conn, fname) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error adding file to config cache"));
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
2012-10-17 09:23:12 +00:00
|
|
|
} else if (e->mask & (IN_CREATE | IN_CLOSE_WRITE | IN_MOVED_TO)) {
|
2013-11-22 14:38:05 +00:00
|
|
|
virObjectEventPtr event;
|
2012-10-17 09:23:12 +00:00
|
|
|
if (xenInotifyAddDomainConfigInfo(conn, fname) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error adding file to config cache"));
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
event = xenInotifyDomainEventFromFile(conn, fname,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED,
|
|
|
|
VIR_DOMAIN_EVENT_DEFINED_ADDED);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
xenUnifiedDomainEventDispatch(conn->privateData, event);
|
|
|
|
else
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("looking up dom"));
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-01-21 18:11:14 +00:00
|
|
|
|
2014-03-25 06:54:51 +00:00
|
|
|
cleanup:
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedUnlock(priv);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenInotifyOpen:
|
|
|
|
* @conn: pointer to the connection block
|
|
|
|
* @name: URL for the target, NULL for local
|
|
|
|
* @flags: combination of virDrvOpenFlag(s)
|
|
|
|
*
|
|
|
|
* Connects and starts listening for inotify events
|
|
|
|
*
|
|
|
|
* Returns 0 or -1 in case of error.
|
|
|
|
*/
|
2013-04-30 13:41:48 +00:00
|
|
|
int
|
2009-11-08 21:08:54 +00:00
|
|
|
xenInotifyOpen(virConnectPtr conn,
|
2011-07-06 20:40:19 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
xen: reject unknown flags
Also fix a logic bug in xenXMDomain{Attach,Detach}DeviceFlags,
where (flags & VIR_DOMAIN_DEVICE_MODIFY_CURRENT) is always false.
* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative)
(xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject
unknown flags.
* src/xen/xen_hypervisor.c (xenHypervisorOpen)
(xenHypervisorGetDomainState): Likewise.
* src/xen/xen_inotify.c (xenInotifyOpen): Likewise.
* src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState)
(xenStoreDomainReboot): Likewise.
* src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot)
(xenDaemonDomainCoreDump, xenDaemonDomainGetState)
(xenDaemonDomainMigratePrepare, xenDaemonDomainSetVcpusFlags,
xenDaemonDomainGetVcpusFlags, xenDaemonAttachDeviceFlags,
xenDaemonDetachDeviceFlags): Likewise.
(xenDaemonDomainGetXMLDesc): Prefer unsigned flags.
* src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise.
(xenXMOpen, xenXMDomainGetState, xenXMDomainSetVcpusFlags)
(xenXMDomainGetVcpusFlags): Reject unknown flags.
(xenXMDomainAttachDeviceFlags, xenXMDomainDetachDeviceFlags):
Likewise, and avoid always-false conditional.
* src/xen/xen_driver.h (XEN_MIGRATION_FLAGS): New define.
2011-07-06 23:15:33 +00:00
|
|
|
unsigned int flags)
|
2008-11-25 10:44:52 +00:00
|
|
|
{
|
|
|
|
DIR *dh;
|
|
|
|
struct dirent *ent;
|
2011-04-03 09:21:14 +00:00
|
|
|
char *path;
|
2013-01-29 14:22:46 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2013-04-30 13:41:48 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, -1);
|
xen: reject unknown flags
Also fix a logic bug in xenXMDomain{Attach,Detach}DeviceFlags,
where (flags & VIR_DOMAIN_DEVICE_MODIFY_CURRENT) is always false.
* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative)
(xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject
unknown flags.
* src/xen/xen_hypervisor.c (xenHypervisorOpen)
(xenHypervisorGetDomainState): Likewise.
* src/xen/xen_inotify.c (xenInotifyOpen): Likewise.
* src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState)
(xenStoreDomainReboot): Likewise.
* src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot)
(xenDaemonDomainCoreDump, xenDaemonDomainGetState)
(xenDaemonDomainMigratePrepare, xenDaemonDomainSetVcpusFlags,
xenDaemonDomainGetVcpusFlags, xenDaemonAttachDeviceFlags,
xenDaemonDetachDeviceFlags): Likewise.
(xenDaemonDomainGetXMLDesc): Prefer unsigned flags.
* src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise.
(xenXMOpen, xenXMDomainGetState, xenXMDomainSetVcpusFlags)
(xenXMDomainGetVcpusFlags): Reject unknown flags.
(xenXMDomainAttachDeviceFlags, xenXMDomainDetachDeviceFlags):
Likewise, and avoid always-false conditional.
* src/xen/xen_driver.h (XEN_MIGRATION_FLAGS): New define.
2011-07-06 23:15:33 +00:00
|
|
|
|
2009-01-20 17:34:56 +00:00
|
|
|
if (priv->configDir) {
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->useXenConfigCache = 1;
|
2008-11-25 10:44:52 +00:00
|
|
|
} else {
|
|
|
|
/* /var/lib/xend/domains/<uuid>/config.sxp */
|
Implmentation of new APIs to checking state/persistence of objects
This implements the virConnectIsSecure, virConnectIsEncrypted,
virDomainIsPersistent, virDomainIsActive, virNetworkIsActive,
virNetworkIsPersistent, virStoragePoolIsActive,
virStoragePoolIsPersistent, virInterfaceIsActive APIs in
(nearly) all drivers. Exceptions are:
phyp: missing domainIsActive/Persistent
esx: missing domainIsPersistent
opennebula: missing domainIsActive/Persistent
* src/remote/remote_protocol.x: Define remote wire ABI for newly
added APIs.
* daemon/remote_dispatch*.h: Re-generated from remote_protocol.x
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/opennebula/one_driver.c, src/openvz/openvz_conf.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c,
src/remote/remote_driver.c, src/storage/storage_driver.c,
src/test/test_driver.c, src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
src/xen/xen_driver.c, src/xen/xen_driver.h, src/xen/xen_inotify.c,
src/xen/xen_inotify.h: Implement all the new APIs where possible
2009-10-20 14:12:03 +00:00
|
|
|
priv->configDir = XEND_DOMAINS_DIR;
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->useXenConfigCache = 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2013-07-04 10:18:49 +00:00
|
|
|
if (VIR_ALLOC(priv->configInfoList) < 0)
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* populate initial list */
|
2009-01-20 17:19:23 +00:00
|
|
|
if (!(dh = opendir(priv->configDir))) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot open directory: %s"),
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->configDir);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
while ((ent = readdir(dh))) {
|
|
|
|
if (STRPREFIX(ent->d_name, "."))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Build the full file path */
|
2011-04-03 09:21:14 +00:00
|
|
|
if (!(path = virFileBuildPath(priv->configDir, ent->d_name, NULL))) {
|
|
|
|
closedir(dh);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2012-10-17 09:23:12 +00:00
|
|
|
if (xenInotifyAddDomainConfigInfo(conn, path) < 0) {
|
2012-07-18 13:48:05 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error adding file to config list"));
|
2009-09-07 14:47:13 +00:00
|
|
|
closedir(dh);
|
2011-04-03 09:21:14 +00:00
|
|
|
VIR_FREE(path);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-04-03 09:21:14 +00:00
|
|
|
|
|
|
|
VIR_FREE(path);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
2008-11-30 18:37:35 +00:00
|
|
|
closedir(dh);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((priv->inotifyFD = inotify_init()) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:19:23 +00:00
|
|
|
"%s", _("initializing inotify"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("Adding a watch on %s", priv->configDir);
|
2008-11-25 10:44:52 +00:00
|
|
|
if (inotify_add_watch(priv->inotifyFD,
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->configDir,
|
2008-11-25 10:44:52 +00:00
|
|
|
IN_CREATE |
|
|
|
|
IN_CLOSE_WRITE | IN_DELETE |
|
|
|
|
IN_MOVED_TO | IN_MOVED_FROM) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:19:23 +00:00
|
|
|
_("adding watch on %s"),
|
|
|
|
priv->configDir);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("Building initial config cache");
|
2009-01-20 17:19:23 +00:00
|
|
|
if (priv->useXenConfigCache &&
|
2012-10-17 09:23:12 +00:00
|
|
|
xenXMConfigCacheRefresh(conn) < 0) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("Failed to enable XM config cache %s", conn->err.message);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("Registering with event loop");
|
2008-11-25 10:44:52 +00:00
|
|
|
/* Add the handle for monitoring */
|
|
|
|
if ((priv->inotifyWatch = virEventAddHandle(priv->inotifyFD, VIR_EVENT_HANDLE_READABLE,
|
|
|
|
xenInotifyEvent, conn, NULL)) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("Failed to add inotify handle, disabling events");
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenInotifyClose:
|
|
|
|
* @conn: pointer to the connection block
|
|
|
|
*
|
|
|
|
* Close and stop listening for inotify events
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenInotifyClose(virConnectPtr conn)
|
|
|
|
{
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
if (priv->configInfoList)
|
|
|
|
xenUnifiedDomainInfoListFree(priv->configInfoList);
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if (priv->inotifyWatch != -1)
|
|
|
|
virEventRemoveHandle(priv->inotifyWatch);
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(priv->inotifyFD);
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|