2008-11-25 10:44:52 +00:00
|
|
|
/*
|
|
|
|
* xen_inofify.c: Xen notification of xml file activity in the
|
|
|
|
* following dirs:
|
|
|
|
* /etc/xen
|
|
|
|
* /var/lib/xend/domains
|
|
|
|
*
|
2010-03-01 23:38:28 +00:00
|
|
|
* Copyright (C) 2010 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
|
|
|
|
* 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: Ben Guthro
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/inotify.h>
|
|
|
|
|
|
|
|
#include "virterror_internal.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "event.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"
|
2008-11-25 10:44:52 +00:00
|
|
|
#include "conf.h"
|
|
|
|
#include "domain_conf.h"
|
|
|
|
#include "xen_inotify.h"
|
|
|
|
#include "xend_internal.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "uuid.h"
|
2010-11-09 20:48:48 +00:00
|
|
|
#include "files.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
|
|
|
|
|
2010-04-02 23:50:56 +00:00
|
|
|
#define virXenInotifyError(code, ...) \
|
2008-11-25 10:44:52 +00:00
|
|
|
virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \
|
2010-03-01 23:38:28 +00:00
|
|
|
__FUNCTION__, __LINE__, __VA_ARGS__)
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
struct xenUnifiedDriver xenInotifyDriver = {
|
|
|
|
xenInotifyOpen, /* open */
|
|
|
|
xenInotifyClose, /* close */
|
|
|
|
NULL, /* version */
|
|
|
|
NULL, /* hostname */
|
|
|
|
NULL, /* nodeGetInfo */
|
|
|
|
NULL, /* getCapabilities */
|
|
|
|
NULL, /* listDomains */
|
|
|
|
NULL, /* numOfDomains */
|
|
|
|
NULL, /* domainCreateLinux */
|
|
|
|
NULL, /* domainSuspend */
|
|
|
|
NULL, /* domainResume */
|
|
|
|
NULL, /* domainShutdown */
|
|
|
|
NULL, /* domainReboot */
|
|
|
|
NULL, /* domainDestroy */
|
|
|
|
NULL, /* domainGetOSType */
|
|
|
|
NULL, /* domainGetMaxMemory */
|
|
|
|
NULL, /* domainSetMaxMemory */
|
|
|
|
NULL, /* domainSetMemory */
|
|
|
|
NULL, /* domainGetInfo */
|
|
|
|
NULL, /* domainSave */
|
|
|
|
NULL, /* domainRestore */
|
|
|
|
NULL, /* domainCoreDump */
|
|
|
|
NULL, /* domainPinVcpu */
|
|
|
|
NULL, /* domainGetVcpus */
|
|
|
|
NULL, /* listDefinedDomains */
|
|
|
|
NULL, /* numOfDefinedDomains */
|
|
|
|
NULL, /* domainCreate */
|
|
|
|
NULL, /* domainDefineXML */
|
|
|
|
NULL, /* domainUndefine */
|
2010-01-14 01:44:26 +00:00
|
|
|
NULL, /* domainAttachDeviceFlags */
|
|
|
|
NULL, /* domainDetachDeviceFlags */
|
2010-03-22 13:13:53 +00:00
|
|
|
NULL, /* domainUpdateDeviceFlags */
|
2008-11-25 10:44:52 +00:00
|
|
|
NULL, /* domainGetAutostart */
|
|
|
|
NULL, /* domainSetAutostart */
|
|
|
|
NULL, /* domainGetSchedulerType */
|
|
|
|
NULL, /* domainGetSchedulerParameters */
|
|
|
|
NULL, /* domainSetSchedulerParameters */
|
|
|
|
};
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
static int
|
2009-01-20 17:34:56 +00:00
|
|
|
xenInotifyXenCacheLookup(virConnectPtr conn,
|
|
|
|
const char *filename,
|
2008-12-04 21:09:20 +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
|
|
|
*name = strdup(entry->def->name);
|
|
|
|
memcpy(uuid, entry->def->uuid, VIR_UUID_BUFLEN);
|
|
|
|
|
|
|
|
if (!*name) {
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("Error getting dom from def");
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
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
|
|
|
|
xenInotifyXendDomainsDirLookup(virConnectPtr conn, const char *filename,
|
|
|
|
char **name, unsigned char *uuid) {
|
2008-11-25 10:44:52 +00:00
|
|
|
int i;
|
|
|
|
virDomainPtr dom;
|
|
|
|
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) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2009-01-05 08:16:44 +00:00
|
|
|
_("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);
|
2008-12-04 21:09:20 +00:00
|
|
|
/* XXX Should not have to go via a virDomainPtr obj instance */
|
|
|
|
if(!(dom = 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 */
|
2009-01-20 17:19:23 +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)) {
|
2009-01-20 17:19:23 +00:00
|
|
|
*name = strdup(priv->configInfoList->doms[i]->name);
|
2008-12-04 21:09:20 +00:00
|
|
|
if (!*name) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
2009-01-20 17:19:23 +00:00
|
|
|
memcpy(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN);
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("Found dom on list");
|
2008-12-04 21:09:20 +00:00
|
|
|
return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:09:20 +00:00
|
|
|
"%s", _("finding dom on config list"));
|
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 21:08:54 +00:00
|
|
|
if (!(*name = strdup(dom->name))) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-12-04 21:09:20 +00:00
|
|
|
return -1;
|
2009-11-08 21:08:54 +00:00
|
|
|
}
|
2008-12-04 21:09:20 +00:00
|
|
|
memcpy(uuid, dom->uuid, VIR_UUID_BUFLEN);
|
|
|
|
virDomainFree(dom);
|
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,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static virDomainEventPtr
|
|
|
|
xenInotifyDomainEventFromFile(virConnectPtr conn,
|
|
|
|
const char *filename,
|
|
|
|
int type, int detail) {
|
|
|
|
virDomainEventPtr event;
|
|
|
|
char *name = NULL;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (xenInotifyDomainLookup(conn, filename, &name, uuid) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
event = virDomainEventNew(-1, name, uuid, type, detail);
|
|
|
|
VIR_FREE(name);
|
|
|
|
return event;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-01-20 17:19:23 +00:00
|
|
|
xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn,
|
2008-11-25 10:44:52 +00:00
|
|
|
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];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2009-01-05 08:16:44 +00:00
|
|
|
_("parsing uuid %s"), uuidstr);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* match and remove on uuid */
|
2009-01-20 17:19:23 +00:00
|
|
|
for (i = 0 ; i < priv->configInfoList->count ; i++) {
|
|
|
|
if (!memcmp(uuid, priv->configInfoList->doms[i]->uuid, VIR_UUID_BUFLEN)) {
|
|
|
|
VIR_FREE(priv->configInfoList->doms[i]->name);
|
|
|
|
VIR_FREE(priv->configInfoList->doms[i]);
|
|
|
|
|
|
|
|
if (i < (priv->configInfoList->count - 1))
|
|
|
|
memmove(priv->configInfoList->doms + i,
|
|
|
|
priv->configInfoList->doms + i + 1,
|
|
|
|
sizeof(*(priv->configInfoList->doms)) *
|
|
|
|
(priv->configInfoList->count - (i + 1)));
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(priv->configInfoList->doms,
|
|
|
|
priv->configInfoList->count - 1) < 0) {
|
2008-11-25 10:44:52 +00:00
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->configInfoList->count--;
|
2008-11-25 10:44:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
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) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:09:20 +00:00
|
|
|
"%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) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-25 10:44:52 +00:00
|
|
|
"%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
|
|
|
|
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
|
|
|
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("got inotify event");
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if( conn && conn->privateData ) {
|
|
|
|
priv = conn->privateData;
|
|
|
|
} else {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-25 10:44:52 +00:00
|
|
|
"%s", _("conn, or private data is NULL"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedLock(priv);
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
reread:
|
|
|
|
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
|
|
|
|
|
|
|
e = (struct inotify_event *)tmp;
|
|
|
|
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)) {
|
2008-12-04 21:09:20 +00:00
|
|
|
virDomainEventPtr event =
|
|
|
|
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
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:09:20 +00:00
|
|
|
"%s", _("looking up dom"));
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if (xenInotifyRemoveDomainConfigInfo(conn, fname) < 0 ) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-25 10:44:52 +00:00
|
|
|
"%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
|
|
|
}
|
|
|
|
} else if (e->mask & ( IN_CREATE | IN_CLOSE_WRITE | IN_MOVED_TO) ) {
|
2008-12-04 21:09:20 +00:00
|
|
|
virDomainEventPtr event;
|
2008-11-25 10:44:52 +00:00
|
|
|
if (xenInotifyAddDomainConfigInfo(conn, fname) < 0 ) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-25 10:44:52 +00:00
|
|
|
"%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
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-12-04 21:09:20 +00:00
|
|
|
"%s", _("looking up dom"));
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-01-21 18:11:14 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
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.
|
|
|
|
*/
|
2008-12-17 21:26:16 +00:00
|
|
|
virDrvOpenStatus
|
2009-11-08 21:08:54 +00:00
|
|
|
xenInotifyOpen(virConnectPtr conn,
|
2008-11-25 10:44:52 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
DIR *dh;
|
|
|
|
struct dirent *ent;
|
2011-04-03 09:21:14 +00:00
|
|
|
char *path;
|
2008-11-25 10:44:52 +00:00
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
|
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
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
if (VIR_ALLOC(priv->configInfoList) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
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))) {
|
|
|
|
virReportOOMError();
|
|
|
|
closedir(dh);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if (xenInotifyAddDomainConfigInfo(conn, path) < 0 ) {
|
2010-04-02 23:50:56 +00:00
|
|
|
virXenInotifyError(VIR_ERR_INTERNAL_ERROR,
|
2008-11-25 10:44:52 +00:00
|
|
|
"%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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("Building initial config cache");
|
2009-01-20 17:19:23 +00:00
|
|
|
if (priv->useXenConfigCache &&
|
2008-11-25 10:44:52 +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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG0("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;
|
|
|
|
}
|