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
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include "xm_internal.h" /* for xenXMDomainConfigParse */
|
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
#define virXenInotifyError(conn, code, fmt...) \
|
|
|
|
virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \
|
|
|
|
__FUNCTION__, __LINE__, fmt)
|
|
|
|
|
|
|
|
#define LIBVIRTD_DOMAINS_DIR "/var/lib/xend/domains"
|
|
|
|
|
|
|
|
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, /* domainSetVcpus */
|
|
|
|
NULL, /* domainPinVcpu */
|
|
|
|
NULL, /* domainGetVcpus */
|
|
|
|
NULL, /* domainGetMaxVcpus */
|
|
|
|
NULL, /* listDefinedDomains */
|
|
|
|
NULL, /* numOfDefinedDomains */
|
|
|
|
NULL, /* domainCreate */
|
|
|
|
NULL, /* domainDefineXML */
|
|
|
|
NULL, /* domainUndefine */
|
|
|
|
NULL, /* domainAttachDevice */
|
|
|
|
NULL, /* domainDetachDevice */
|
|
|
|
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))) {
|
2008-11-25 10:44:52 +00:00
|
|
|
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) {
|
2008-11-25 10:44:52 +00:00
|
|
|
DEBUG0("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
|
|
|
|
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>/
|
|
|
|
*/
|
|
|
|
uuid_str = filename + strlen(LIBVIRTD_DOMAINS_DIR) + 1;
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
if (virUUIDParse(uuid_str, rawuuid) < 0) {
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, 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 */
|
|
|
|
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) {
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
|
2009-01-05 08:16:44 +00:00
|
|
|
_("finding dom for %s"), uuid_str);
|
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);
|
2008-11-25 10:44:52 +00:00
|
|
|
DEBUG0("Found dom on list");
|
2008-12-04 21:09:20 +00:00
|
|
|
return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
virXenInotifyError(NULL, 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
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
if (!(*name = strdup(dom->name)))
|
|
|
|
return -1;
|
|
|
|
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;
|
2008-11-25 10:44:52 +00:00
|
|
|
const char *uuidstr = fname + strlen(LIBVIRTD_DOMAINS_DIR) + 1;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (virUUIDParse(uuidstr, uuid) < 0) {
|
|
|
|
virXenInotifyError(NULL, 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) {
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, 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) {
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, 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
|
|
|
|
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;
|
|
|
|
|
|
|
|
DEBUG0("got inotify event");
|
|
|
|
|
|
|
|
if( conn && conn->privateData ) {
|
|
|
|
priv = conn->privateData;
|
|
|
|
} else {
|
|
|
|
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%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
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, 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 ) {
|
|
|
|
virXenInotifyError(NULL, 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
|
|
|
}
|
|
|
|
} 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 ) {
|
|
|
|
virXenInotifyError(NULL, 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
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, 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
|
2008-11-25 10:44:52 +00:00
|
|
|
xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
|
|
|
int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
DIR *dh;
|
|
|
|
struct dirent *ent;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
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 */
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->configDir = LIBVIRTD_DOMAINS_DIR;
|
|
|
|
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) {
|
2008-11-25 10:44:52 +00:00
|
|
|
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
|
2009-01-20 17:19:23 +00:00
|
|
|
"%s", _("failed to allocate configInfoList"));
|
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))) {
|
2009-01-20 17:13:33 +00:00
|
|
|
virReportSystemError(NULL, errno,
|
|
|
|
_("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 */
|
2009-01-20 17:19:23 +00:00
|
|
|
if ((strlen(priv->configDir) + 1 +
|
|
|
|
strlen(ent->d_name) + 1) > PATH_MAX)
|
2008-11-25 10:44:52 +00:00
|
|
|
continue;
|
2009-01-20 17:19:23 +00:00
|
|
|
strcpy(path, priv->configDir);
|
2008-11-25 10:44:52 +00:00
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, ent->d_name);
|
|
|
|
|
|
|
|
if (xenInotifyAddDomainConfigInfo(conn, path) < 0 ) {
|
|
|
|
virXenInotifyError(NULL, VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Error adding file to config list"));
|
2009-09-07 14:47:13 +00:00
|
|
|
closedir(dh);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2008-11-30 18:37:35 +00:00
|
|
|
closedir(dh);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((priv->inotifyFD = inotify_init()) < 0) {
|
2009-01-20 17:19:23 +00:00
|
|
|
virReportSystemError(NULL, errno,
|
|
|
|
"%s", _("initializing inotify"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
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) {
|
2009-01-20 17:19:23 +00:00
|
|
|
virReportSystemError(NULL, errno,
|
|
|
|
_("adding watch on %s"),
|
|
|
|
priv->configDir);
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
DEBUG("Failed to enable XM config cache %s", conn->err.message);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG0("Registering with event loop");
|
|
|
|
/* Add the handle for monitoring */
|
|
|
|
if ((priv->inotifyWatch = virEventAddHandle(priv->inotifyFD, VIR_EVENT_HANDLE_READABLE,
|
|
|
|
xenInotifyEvent, conn, NULL)) < 0) {
|
|
|
|
DEBUG0("Failed to add inotify handle, disabling events");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
close(priv->inotifyFD);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|