2006-03-23 15:42:10 +00:00
|
|
|
/*
|
|
|
|
* xs_internal.c: access to Xen Store
|
|
|
|
*
|
2010-02-02 11:22:17 +00:00
|
|
|
* Copyright (C) 2006, 2009-2010 Red Hat, Inc.
|
2006-03-23 15:42:10 +00:00
|
|
|
*
|
|
|
|
* See COPYING.LIB for the License of this software
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-12-05 21:40:15 +00:00
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2008-02-05 19:27:37 +00:00
|
|
|
#include <xen/dom0_ops.h>
|
2006-03-23 15:42:10 +00:00
|
|
|
#include <xen/version.h>
|
2007-11-20 18:57:41 +00:00
|
|
|
#include <xen/xen.h>
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
#include <xs.h>
|
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2006-03-23 15:42:10 +00:00
|
|
|
#include "driver.h"
|
2008-11-25 10:44:52 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "uuid.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"
|
2006-03-23 15:42:10 +00:00
|
|
|
#include "xs_internal.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_hypervisor.h"
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_XEN
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifndef PROXY
|
2006-11-07 16:28:16 +00:00
|
|
|
static char *xenStoreDomainGetOSType(virDomainPtr domain);
|
2009-01-21 18:11:14 +00:00
|
|
|
static void xenStoreWatchEvent(int watch, int fd, int events, void *data);
|
|
|
|
static void xenStoreWatchListFree(xenStoreWatchListPtr list);
|
2006-11-07 16:28:16 +00:00
|
|
|
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
struct xenUnifiedDriver xenStoreDriver = {
|
2006-03-23 15:42:10 +00:00
|
|
|
xenStoreOpen, /* open */
|
|
|
|
xenStoreClose, /* close */
|
|
|
|
NULL, /* version */
|
2007-06-26 11:42:46 +00:00
|
|
|
NULL, /* hostname */
|
2006-03-29 12:46:03 +00:00
|
|
|
NULL, /* nodeGetInfo */
|
2007-03-15 17:24:56 +00:00
|
|
|
NULL, /* getCapabilities */
|
2006-03-23 15:42:10 +00:00
|
|
|
xenStoreListDomains, /* listDomains */
|
|
|
|
NULL, /* numOfDomains */
|
2008-10-10 09:32:27 +00:00
|
|
|
NULL, /* domainCreateXML */
|
2006-03-23 15:42:10 +00:00
|
|
|
NULL, /* domainSuspend */
|
|
|
|
NULL, /* domainResume */
|
2006-04-03 13:46:43 +00:00
|
|
|
xenStoreDomainShutdown, /* domainShutdown */
|
|
|
|
xenStoreDomainReboot, /* domainReboot */
|
2006-03-23 15:42:10 +00:00
|
|
|
NULL, /* domainDestroy */
|
2006-11-07 16:28:16 +00:00
|
|
|
xenStoreDomainGetOSType, /* domainGetOSType */
|
2006-03-23 15:42:10 +00:00
|
|
|
xenStoreDomainGetMaxMemory, /* domainGetMaxMemory */
|
2006-04-13 17:18:49 +00:00
|
|
|
NULL, /* domainSetMaxMemory */
|
|
|
|
xenStoreDomainSetMemory, /* domainSetMemory */
|
2006-03-23 15:42:10 +00:00
|
|
|
xenStoreGetDomainInfo, /* domainGetInfo */
|
|
|
|
NULL, /* domainSave */
|
2006-08-08 22:22:55 +00:00
|
|
|
NULL, /* domainRestore */
|
2006-11-22 17:48:29 +00:00
|
|
|
NULL, /* domainCoreDump */
|
2006-08-08 22:22:55 +00:00
|
|
|
NULL, /* domainSetVcpus */
|
|
|
|
NULL, /* domainPinVcpu */
|
2006-08-09 15:21:16 +00:00
|
|
|
NULL, /* domainGetVcpus */
|
2007-03-08 08:31:07 +00:00
|
|
|
NULL, /* domainGetMaxVcpus */
|
2006-08-30 14:21:03 +00:00
|
|
|
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 */
|
2007-02-23 08:51:30 +00:00
|
|
|
NULL, /* domainGetAutostart */
|
|
|
|
NULL, /* domainSetAutostart */
|
2007-06-05 12:06:08 +00:00
|
|
|
NULL, /* domainGetSchedulerType */
|
|
|
|
NULL, /* domainGetSchedulerParameters */
|
|
|
|
NULL, /* domainSetSchedulerParameters */
|
2006-03-23 15:42:10 +00:00
|
|
|
};
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#endif /* ! PROXY */
|
2006-03-27 15:24:36 +00:00
|
|
|
|
2010-04-02 23:50:19 +00:00
|
|
|
#define virXenStoreError(code, ...) \
|
2008-11-04 22:30:33 +00:00
|
|
|
virReportErrorHelper(NULL, VIR_FROM_XENSTORE, code, __FILE__, \
|
2010-03-01 23:38:28 +00:00
|
|
|
__FUNCTION__, __LINE__, __VA_ARGS__)
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Helper internal APIs *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifndef PROXY
|
2006-03-23 15:42:10 +00:00
|
|
|
/**
|
|
|
|
* virConnectDoStoreList:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @path: the absolute path of the directory in the store to list
|
|
|
|
* @nb: OUT pointer to the number of items found
|
|
|
|
*
|
|
|
|
* Internal API querying the Xenstore for a list
|
|
|
|
*
|
|
|
|
* Returns a string which must be freed by the caller or NULL in case of error
|
|
|
|
*/
|
|
|
|
static char **
|
|
|
|
virConnectDoStoreList(virConnectPtr conn, const char *path,
|
|
|
|
unsigned int *nb)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
|
|
|
if (conn == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL || path == NULL || nb == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
return xs_directory (priv->xshandle, 0, path, nb);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2006-08-09 15:21:16 +00:00
|
|
|
#endif /* ! PROXY */
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainDoStoreQuery:
|
2006-08-09 15:21:16 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @domid: id of the domain
|
2006-03-23 15:42:10 +00:00
|
|
|
* @path: the relative path of the data in the store to retrieve
|
|
|
|
*
|
|
|
|
* Internal API querying the Xenstore for a string value.
|
|
|
|
*
|
|
|
|
* Returns a string which must be freed by the caller or NULL in case of error
|
|
|
|
*/
|
|
|
|
static char *
|
2006-08-09 15:21:16 +00:00
|
|
|
virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
|
2006-03-23 15:42:10 +00:00
|
|
|
{
|
|
|
|
char s[256];
|
|
|
|
unsigned int len = 0;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
|
|
|
if (!conn)
|
|
|
|
return NULL;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
snprintf(s, 255, "/local/domain/%d/%s", domid, path);
|
2006-03-23 15:42:10 +00:00
|
|
|
s[255] = 0;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
return xs_read(priv->xshandle, 0, &s[0], &len);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifndef PROXY
|
2006-03-23 15:42:10 +00:00
|
|
|
/**
|
|
|
|
* virDomainDoStoreWrite:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @path: the relative path of the data in the store to retrieve
|
|
|
|
*
|
|
|
|
* Internal API setting up a string value in the Xenstore
|
|
|
|
* Requires write access to the XenStore
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of failure
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
virDomainDoStoreWrite(virDomainPtr domain, const char *path,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
char s[256];
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain))
|
|
|
|
return (-1);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return (-1);
|
|
|
|
if (domain->conn->flags & VIR_CONNECT_RO)
|
|
|
|
return (-1);
|
|
|
|
|
2007-01-22 16:25:27 +00:00
|
|
|
snprintf(s, 255, "/local/domain/%d/%s", domain->id, path);
|
2006-03-23 15:42:10 +00:00
|
|
|
s[255] = 0;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (xs_write(priv->xshandle, 0, &s[0], value, strlen(value)))
|
2006-03-23 15:42:10 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainGetVM:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Internal API extracting a xenstore vm path.
|
|
|
|
*
|
|
|
|
* Returns the new string or NULL in case of error
|
|
|
|
*/
|
2008-01-21 16:29:10 +00:00
|
|
|
static char *
|
2006-03-23 15:42:10 +00:00
|
|
|
virDomainGetVM(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
char *vm;
|
|
|
|
char query[200];
|
|
|
|
unsigned int len;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain))
|
|
|
|
return (NULL);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
snprintf(query, 199, "/local/domain/%d/vm", virDomainGetID(domain));
|
|
|
|
query[199] = 0;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
vm = xs_read(priv->xshandle, 0, &query[0], &len);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
return (vm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virDomainGetVMInfo:
|
|
|
|
* @domain: a domain object
|
|
|
|
* @vm: the xenstore vm path
|
|
|
|
* @name: the value's path
|
|
|
|
*
|
2008-02-05 19:27:37 +00:00
|
|
|
* Internal API extracting one information the device used
|
2006-03-23 15:42:10 +00:00
|
|
|
* by the domain from xensttore
|
|
|
|
*
|
|
|
|
* Returns the new string or NULL in case of error
|
|
|
|
*/
|
2008-01-21 16:29:10 +00:00
|
|
|
static char *
|
2006-03-23 15:42:10 +00:00
|
|
|
virDomainGetVMInfo(virDomainPtr domain, const char *vm, const char *name)
|
|
|
|
{
|
|
|
|
char s[256];
|
|
|
|
char *ret = NULL;
|
|
|
|
unsigned int len = 0;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain))
|
|
|
|
return (NULL);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
snprintf(s, 255, "%s/%s", vm, name);
|
|
|
|
s[255] = 0;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
ret = xs_read(priv->xshandle, 0, &s[0], &len);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#endif /* ! PROXY */
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Canonical internal APIs *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
/**
|
|
|
|
* xenStoreOpen:
|
|
|
|
* @conn: pointer to the connection block
|
|
|
|
* @name: URL for the target, NULL for local
|
|
|
|
* @flags: combination of virDrvOpenFlag(s)
|
|
|
|
*
|
|
|
|
* Connects to the Xen hypervisor.
|
|
|
|
*
|
|
|
|
* Returns 0 or -1 in case of error.
|
|
|
|
*/
|
2008-12-17 21:26:16 +00:00
|
|
|
virDrvOpenStatus
|
2007-04-04 14:19:49 +00:00
|
|
|
xenStoreOpen(virConnectPtr conn,
|
2007-12-05 18:28:05 +00:00
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
2007-04-30 17:30:11 +00:00
|
|
|
int flags ATTRIBUTE_UNUSED)
|
2006-03-23 15:42:10 +00:00
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifdef PROXY
|
2007-04-04 14:19:49 +00:00
|
|
|
priv->xshandle = xs_daemon_open_readonly();
|
2006-08-09 15:21:16 +00:00
|
|
|
#else
|
2007-12-05 18:28:05 +00:00
|
|
|
if (flags & VIR_CONNECT_RO)
|
2008-04-10 16:54:54 +00:00
|
|
|
priv->xshandle = xs_daemon_open_readonly();
|
2006-03-23 15:42:10 +00:00
|
|
|
else
|
2008-04-10 16:54:54 +00:00
|
|
|
priv->xshandle = xs_daemon_open();
|
2006-08-09 15:21:16 +00:00
|
|
|
#endif /* ! PROXY */
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (priv->xshandle == NULL) {
|
2008-04-10 16:54:54 +00:00
|
|
|
/*
|
2009-01-22 17:49:41 +00:00
|
|
|
* not being able to connect via the socket as an unprivileged
|
|
|
|
* user is rather normal, this should fallback to the proxy (or
|
2007-11-27 14:39:42 +00:00
|
|
|
* remote) mechanism.
|
2008-04-10 16:54:54 +00:00
|
|
|
*/
|
2009-01-22 17:49:41 +00:00
|
|
|
if (xenHavePrivilege()) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_NO_XEN,
|
|
|
|
"%s", _("failed to connect to Xen Store"));
|
2008-04-10 16:54:54 +00:00
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
#ifndef PROXY
|
|
|
|
/* Init activeDomainList */
|
2009-01-20 17:19:23 +00:00
|
|
|
if (VIR_ALLOC(priv->activeDomainList) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init watch list before filling in domInfoList,
|
|
|
|
so we can know if it is the first time through
|
|
|
|
when the callback fires */
|
2009-11-08 21:08:54 +00:00
|
|
|
if (VIR_ALLOC(priv->xsWatchList) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This will get called once at start */
|
|
|
|
if ( xenStoreAddWatch(conn, "@releaseDomain",
|
|
|
|
"releaseDomain", xenStoreDomainReleased, priv) < 0 )
|
|
|
|
{
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("adding watch @releaseDomain"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The initial call of this will fill domInfoList */
|
|
|
|
if( xenStoreAddWatch(conn, "@introduceDomain",
|
|
|
|
"introduceDomain", xenStoreDomainIntroduced, priv) < 0 )
|
|
|
|
{
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("adding watch @introduceDomain"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add an event handle */
|
|
|
|
if ((priv->xsWatch = virEventAddHandle(xs_fileno(priv->xshandle),
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
|
|
|
xenStoreWatchEvent,
|
|
|
|
conn,
|
|
|
|
NULL)) < 0)
|
2010-04-02 19:44:04 +00:00
|
|
|
DEBUG0("Failed to add event handle, disabling events");
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
#endif //PROXY
|
|
|
|
return 0;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreClose:
|
|
|
|
* @conn: pointer to the connection block
|
|
|
|
*
|
|
|
|
* Close the connection to the Xen hypervisor.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success or -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreClose(virConnectPtr conn)
|
|
|
|
{
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
if (conn == NULL) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
#ifndef PROXY
|
2008-11-25 10:44:52 +00:00
|
|
|
if (xenStoreRemoveWatch(conn, "@introduceDomain", "introduceDomain") < 0) {
|
|
|
|
DEBUG0("Warning, could not remove @introduceDomain watch");
|
|
|
|
/* not fatal */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xenStoreRemoveWatch(conn, "@releaseDomain", "releaseDomain") < 0) {
|
|
|
|
DEBUG0("Warning, could not remove @releaseDomain watch");
|
|
|
|
/* not fatal */
|
|
|
|
}
|
|
|
|
|
|
|
|
xenStoreWatchListFree(priv->xsWatchList);
|
2009-01-15 01:21:36 +00:00
|
|
|
priv->xsWatchList = NULL;
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedDomainInfoListFree(priv->activeDomainList);
|
|
|
|
priv->activeDomainList = NULL;
|
2008-11-25 10:44:52 +00:00
|
|
|
#endif
|
2007-04-04 14:19:49 +00:00
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return(-1);
|
|
|
|
|
Move all shared utility files to src/util/
* src/bridge.c, src/bridge.h, src/buf.c, src/buf.h, src/cgroup.c,
src/cgroup.h, src/conf.c, src/conf.h, src/event.c, src/event.h,
src/hash.c, src/hash.h, src/hostusb.c, src/hostusb.h,
src/iptables.c, src/iptables.h, src/logging.c, src/logging.h,
src/memory.c, src/memory.h, src/pci.c, src/pci.h, src/qparams.c,
src/qparams.h, src/stats_linux.c, src/stats_linux.h,
src/threads-pthread.c, src/threads-pthread.h, src/threads-win32.c,
src/threads-win32.h, src/threads.c, src/threads.h, src/util.c,
src/util.h, src/uuid.c, src/uuid.h, src/virterror.c,
src/virterror_internal.h, src/xml.c, src/xml.h: Move all files
into src/util/
* daemon/Makefile.am: Add -Isrc/util/ to build flags
* src/Makefile.am: Add -Isrc/util/ to build flags and update for
moved files
* src/libvirt_private.syms: Export cgroup APIs since they're now
in util rather than linking directly to drivers
* src/xen/xs_internal.c: Disable bogus virEventRemoveHandle call
when built under PROXY
* proxy/Makefile.am: Update for changed file locations. Remove
bogus build of event.c
* tools/Makefile.am, tests/Makefile.am: Add -Isrc/util/ to build flags
2009-09-16 15:28:46 +00:00
|
|
|
#ifndef PROXY
|
2008-11-25 10:44:52 +00:00
|
|
|
if (priv->xsWatch != -1)
|
|
|
|
virEventRemoveHandle(priv->xsWatch);
|
Move all shared utility files to src/util/
* src/bridge.c, src/bridge.h, src/buf.c, src/buf.h, src/cgroup.c,
src/cgroup.h, src/conf.c, src/conf.h, src/event.c, src/event.h,
src/hash.c, src/hash.h, src/hostusb.c, src/hostusb.h,
src/iptables.c, src/iptables.h, src/logging.c, src/logging.h,
src/memory.c, src/memory.h, src/pci.c, src/pci.h, src/qparams.c,
src/qparams.h, src/stats_linux.c, src/stats_linux.h,
src/threads-pthread.c, src/threads-pthread.h, src/threads-win32.c,
src/threads-win32.h, src/threads.c, src/threads.h, src/util.c,
src/util.h, src/uuid.c, src/uuid.h, src/virterror.c,
src/virterror_internal.h, src/xml.c, src/xml.h: Move all files
into src/util/
* daemon/Makefile.am: Add -Isrc/util/ to build flags
* src/Makefile.am: Add -Isrc/util/ to build flags and update for
moved files
* src/libvirt_private.syms: Export cgroup APIs since they're now
in util rather than linking directly to drivers
* src/xen/xs_internal.c: Disable bogus virEventRemoveHandle call
when built under PROXY
* proxy/Makefile.am: Update for changed file locations. Remove
bogus build of event.c
* tools/Makefile.am, tests/Makefile.am: Add -Isrc/util/ to build flags
2009-09-16 15:28:46 +00:00
|
|
|
#endif
|
2007-04-04 14:19:49 +00:00
|
|
|
xs_daemon_close(priv->xshandle);
|
2008-11-25 10:44:52 +00:00
|
|
|
priv->xshandle = NULL;
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
#ifndef PROXY
|
2006-03-23 15:42:10 +00:00
|
|
|
/**
|
|
|
|
* xenStoreGetDomainInfo:
|
|
|
|
* @domain: pointer to the domain block
|
2006-07-19 22:24:37 +00:00
|
|
|
* @info: the place where information should be stored
|
2006-03-23 15:42:10 +00:00
|
|
|
*
|
2006-07-19 22:24:37 +00:00
|
|
|
* Do an hypervisor call to get the related set of domain information.
|
2006-03-23 15:42:10 +00:00
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info)
|
|
|
|
{
|
|
|
|
char *tmp, **tmp2;
|
|
|
|
unsigned int nb_vcpus;
|
|
|
|
char request[200];
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain))
|
|
|
|
return (-1);
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
if ((domain == NULL) || (domain->conn == NULL) || (info == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return(-1);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-01-22 16:25:27 +00:00
|
|
|
if (domain->id == -1)
|
2006-11-15 21:03:34 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2007-01-22 16:25:27 +00:00
|
|
|
tmp = virDomainDoStoreQuery(domain->conn, domain->id, "running");
|
2006-03-23 15:42:10 +00:00
|
|
|
if (tmp != NULL) {
|
|
|
|
if (tmp[0] == '1')
|
|
|
|
info->state = VIR_DOMAIN_RUNNING;
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp);
|
2006-03-23 15:42:10 +00:00
|
|
|
} else {
|
2008-07-08 17:49:26 +00:00
|
|
|
info->state = VIR_DOMAIN_NOSTATE;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2007-01-22 16:25:27 +00:00
|
|
|
tmp = virDomainDoStoreQuery(domain->conn, domain->id, "memory/target");
|
2006-03-23 15:42:10 +00:00
|
|
|
if (tmp != NULL) {
|
|
|
|
info->memory = atol(tmp);
|
|
|
|
info->maxMem = atol(tmp);
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp);
|
2006-03-23 15:42:10 +00:00
|
|
|
} else {
|
|
|
|
info->memory = 0;
|
|
|
|
info->maxMem = 0;
|
|
|
|
}
|
2010-03-09 18:22:22 +00:00
|
|
|
# if 0
|
2006-03-23 15:42:10 +00:00
|
|
|
/* doesn't seems to work */
|
2007-01-22 16:25:27 +00:00
|
|
|
tmp = virDomainDoStoreQuery(domain->conn, domain->id, "cpu_time");
|
2006-03-23 15:42:10 +00:00
|
|
|
if (tmp != NULL) {
|
|
|
|
info->cpuTime = atol(tmp);
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp);
|
2006-03-23 15:42:10 +00:00
|
|
|
} else {
|
|
|
|
info->cpuTime = 0;
|
|
|
|
}
|
2010-03-09 18:22:22 +00:00
|
|
|
# endif
|
2007-01-22 16:25:27 +00:00
|
|
|
snprintf(request, 199, "/local/domain/%d/cpu", domain->id);
|
2006-03-23 15:42:10 +00:00
|
|
|
request[199] = 0;
|
|
|
|
tmp2 = virConnectDoStoreList(domain->conn, request, &nb_vcpus);
|
|
|
|
if (tmp2 != NULL) {
|
|
|
|
info->nrVirtCpu = nb_vcpus;
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp2);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-04-13 17:18:49 +00:00
|
|
|
* xenStoreDomainSetMemory:
|
2006-03-23 15:42:10 +00:00
|
|
|
* @domain: pointer to the domain block
|
|
|
|
* @memory: the max memory size in kilobytes.
|
|
|
|
*
|
|
|
|
* Change the maximum amount of memory allowed in the xen store
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
2006-04-13 17:18:49 +00:00
|
|
|
xenStoreDomainSetMemory(virDomainPtr domain, unsigned long memory)
|
2006-03-23 15:42:10 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char value[20];
|
|
|
|
|
2007-03-08 14:17:32 +00:00
|
|
|
if ((domain == NULL) || (domain->conn == NULL) ||
|
|
|
|
(memory < 1024 * MIN_XEN_GUEST_SIZE)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2007-01-22 16:25:27 +00:00
|
|
|
if (domain->id == -1)
|
2006-11-15 21:03:34 +00:00
|
|
|
return(-1);
|
2007-03-08 14:17:32 +00:00
|
|
|
if ((domain->id == 0) && (memory < (2 * MIN_XEN_GUEST_SIZE * 1024)))
|
2008-04-10 16:54:54 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
snprintf(value, 19, "%lu", memory);
|
|
|
|
value[19] = 0;
|
|
|
|
ret = virDomainDoStoreWrite(domain, "memory/target", &value[0]);
|
|
|
|
if (ret < 0)
|
|
|
|
return (-1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreDomainGetMaxMemory:
|
|
|
|
* @domain: pointer to the domain block
|
|
|
|
*
|
|
|
|
* Ask the xenstore for the maximum memory allowed for a domain
|
|
|
|
*
|
|
|
|
* Returns the memory size in kilobytes or 0 in case of error.
|
|
|
|
*/
|
|
|
|
unsigned long
|
|
|
|
xenStoreDomainGetMaxMemory(virDomainPtr domain)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
unsigned long ret = 0;
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
if (!VIR_IS_CONNECTED_DOMAIN(domain))
|
|
|
|
return (ret);
|
2007-01-22 16:25:27 +00:00
|
|
|
if (domain->id == -1)
|
2006-11-15 21:03:34 +00:00
|
|
|
return(-1);
|
2006-08-09 15:21:16 +00:00
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
priv = domain->conn->privateData;
|
|
|
|
xenUnifiedLock(priv);
|
2007-01-22 16:25:27 +00:00
|
|
|
tmp = virDomainDoStoreQuery(domain->conn, domain->id, "memory/target");
|
2006-03-23 15:42:10 +00:00
|
|
|
if (tmp != NULL) {
|
2008-04-10 16:54:54 +00:00
|
|
|
ret = (unsigned long) atol(tmp);
|
2009-01-21 18:11:14 +00:00
|
|
|
VIR_FREE(tmp);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedUnlock(priv);
|
2006-03-23 15:42:10 +00:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreNumOfDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
*
|
|
|
|
* Provides the number of active domains.
|
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreNumOfDomains(virConnectPtr conn)
|
|
|
|
{
|
|
|
|
unsigned int num;
|
2009-10-09 09:32:37 +00:00
|
|
|
char **idlist = NULL, *endptr;
|
|
|
|
int i, ret = -1, realnum = 0;
|
|
|
|
long id;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (conn == NULL) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return -1;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2007-04-04 14:19:49 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2009-10-09 09:32:37 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
|
2006-03-23 15:42:10 +00:00
|
|
|
if (idlist) {
|
2009-10-09 09:32:37 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
id = strtol(idlist[i], &endptr, 10);
|
|
|
|
if ((endptr == idlist[i]) || (*endptr != 0))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Sometimes xenstore has stale domain IDs, so filter
|
|
|
|
against the hypervisor's info */
|
|
|
|
if (xenHypervisorHasDomain(conn, (int)id))
|
|
|
|
realnum++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
VIR_FREE (idlist);
|
|
|
|
ret = realnum;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-23 19:18:24 +00:00
|
|
|
* xenStoreDoListDomains:
|
2006-03-23 15:42:10 +00:00
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @ids: array to collect the list of IDs of active domains
|
|
|
|
* @maxids: size of @ids
|
|
|
|
*
|
2009-01-23 19:18:24 +00:00
|
|
|
* Internal API: collect the list of active domains, and store
|
|
|
|
* their ID in @maxids. The driver lock must be held.
|
2006-03-23 15:42:10 +00:00
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
2009-01-23 19:18:24 +00:00
|
|
|
static int
|
2009-10-09 09:32:37 +00:00
|
|
|
xenStoreDoListDomains(virConnectPtr conn, xenUnifiedPrivatePtr priv, int *ids, int maxids)
|
2006-03-23 15:42:10 +00:00
|
|
|
{
|
|
|
|
char **idlist = NULL, *endptr;
|
|
|
|
unsigned int num, i;
|
2009-01-23 19:18:24 +00:00
|
|
|
int ret = -1;
|
2006-03-23 15:42:10 +00:00
|
|
|
long id;
|
2009-01-21 18:11:14 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
if (priv->xshandle == NULL)
|
2009-01-23 19:18:24 +00:00
|
|
|
goto out;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
idlist = xs_directory (priv->xshandle, 0, "/local/domain", &num);
|
2006-03-23 15:42:10 +00:00
|
|
|
if (idlist == NULL)
|
2009-01-23 19:18:24 +00:00
|
|
|
goto out;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
for (ret = 0, i = 0; (i < num) && (ret < maxids); i++) {
|
2008-04-10 16:54:54 +00:00
|
|
|
id = strtol(idlist[i], &endptr, 10);
|
2009-01-23 19:18:24 +00:00
|
|
|
if ((endptr == idlist[i]) || (*endptr != 0))
|
|
|
|
goto out;
|
2009-10-09 09:32:37 +00:00
|
|
|
|
|
|
|
/* Sometimes xenstore has stale domain IDs, so filter
|
|
|
|
against the hypervisor's info */
|
|
|
|
if (xenHypervisorHasDomain(conn, (int)id))
|
|
|
|
ids[ret++] = (int) id;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2009-01-23 19:18:24 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
VIR_FREE (idlist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreListDomains:
|
|
|
|
* @conn: pointer to the hypervisor connection
|
|
|
|
* @ids: array to collect the list of IDs of active domains
|
|
|
|
* @maxids: size of @ids
|
|
|
|
*
|
|
|
|
* Collect the list of active domains, and store their ID in @maxids
|
|
|
|
*
|
|
|
|
* Returns the number of domain found or -1 in case of error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
|
|
|
|
{
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((conn == NULL) || (ids == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2009-01-23 19:18:24 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
|
|
|
|
xenUnifiedLock(priv);
|
2009-10-09 09:32:37 +00:00
|
|
|
ret = xenStoreDoListDomains(conn, priv, ids, maxids);
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedUnlock(priv);
|
2009-01-23 19:18:24 +00:00
|
|
|
|
|
|
|
return(ret);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
* xenStoreLookupByName:
|
2006-03-23 15:42:10 +00:00
|
|
|
* @conn: A xend instance
|
|
|
|
* @name: The name of the domain
|
|
|
|
*
|
|
|
|
* Try to lookup a domain on the Xen Store based on its name.
|
|
|
|
*
|
|
|
|
* Returns a new domain object or NULL in case of failure
|
|
|
|
*/
|
|
|
|
virDomainPtr
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
xenStoreLookupByName(virConnectPtr conn, const char *name)
|
2006-03-23 15:42:10 +00:00
|
|
|
{
|
|
|
|
virDomainPtr ret = NULL;
|
|
|
|
unsigned int num, i, len;
|
|
|
|
long id = -1;
|
|
|
|
char **idlist = NULL, *endptr;
|
2007-08-21 11:53:52 +00:00
|
|
|
char prop[200], *tmp;
|
2006-03-23 15:42:10 +00:00
|
|
|
int found = 0;
|
|
|
|
struct xend_domain *xenddomain = NULL;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
if ((conn == NULL) || (name == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2008-04-10 16:54:54 +00:00
|
|
|
return(NULL);
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-03-23 15:42:10 +00:00
|
|
|
return(NULL);
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
|
2006-03-23 15:42:10 +00:00
|
|
|
if (idlist == NULL)
|
2008-04-10 16:54:54 +00:00
|
|
|
goto done;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
id = strtol(idlist[i], &endptr, 10);
|
|
|
|
if ((endptr == idlist[i]) || (*endptr != 0)) {
|
|
|
|
goto done;
|
|
|
|
}
|
2010-03-09 18:22:22 +00:00
|
|
|
# if 0
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
if (virConnectCheckStoreID(conn, (int) id) < 0)
|
|
|
|
continue;
|
2010-03-09 18:22:22 +00:00
|
|
|
# endif
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
snprintf(prop, 199, "/local/domain/%s/name", idlist[i]);
|
|
|
|
prop[199] = 0;
|
|
|
|
tmp = xs_read(priv->xshandle, 0, prop, &len);
|
|
|
|
if (tmp != NULL) {
|
|
|
|
found = STREQ (name, tmp);
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp);
|
Fri Jul 6 16:08:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
* src/proxy_internal.c, src/proxy_internal.h,
src.xen_internal.c, src/xen_internal.h,
src/xen_unified.c, src/xen_unified.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: The interface
between xen_unified.c and its underlying driver now uses
a custom structure (struct xenUnifiedDriver) instead
of reusing virDriver.
* src/xen_unified.c: virDomainLookup* functions in Xen
now throw VIR_ERR_NO_DOMAIN if the domain does not exist.
* src/xs_internal.c: Fix indentation.
2007-07-06 15:11:22 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
}
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
if (!found)
|
2007-08-21 11:53:52 +00:00
|
|
|
goto done;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
2006-04-09 13:11:22 +00:00
|
|
|
ret = virGetDomain(conn, name, NULL);
|
2007-08-21 11:53:52 +00:00
|
|
|
if (ret == NULL)
|
2007-07-06 15:02:09 +00:00
|
|
|
goto done;
|
2007-08-21 11:53:52 +00:00
|
|
|
|
2007-01-22 16:25:27 +00:00
|
|
|
ret->id = id;
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
done:
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(xenddomain);
|
|
|
|
VIR_FREE(idlist);
|
2006-03-23 15:42:10 +00:00
|
|
|
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreDomainShutdown:
|
|
|
|
* @domain: pointer to the Domain block
|
|
|
|
*
|
|
|
|
* Shutdown the domain, the OS is requested to properly shutdown
|
|
|
|
* and the domain may ignore it. It will return immediately
|
|
|
|
* after queuing the request.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreDomainShutdown(virDomainPtr domain)
|
|
|
|
{
|
2009-01-21 18:11:14 +00:00
|
|
|
int ret;
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
2006-03-23 15:42:10 +00:00
|
|
|
if ((domain == NULL) || (domain->conn == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-03-23 15:42:10 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2007-02-22 16:49:12 +00:00
|
|
|
if (domain->id == -1 || domain->id == 0)
|
2006-11-15 21:03:34 +00:00
|
|
|
return(-1);
|
2006-03-23 15:42:10 +00:00
|
|
|
/*
|
2008-02-05 19:27:37 +00:00
|
|
|
* this is very hackish, the domU kernel probes for a special
|
2006-03-23 15:42:10 +00:00
|
|
|
* node in the xenstore and launch the shutdown command if found.
|
|
|
|
*/
|
2009-01-21 18:11:14 +00:00
|
|
|
priv = domain->conn->privateData;
|
|
|
|
xenUnifiedLock(priv);
|
|
|
|
ret = virDomainDoStoreWrite(domain, "control/shutdown", "poweroff");
|
|
|
|
xenUnifiedUnlock(priv);
|
|
|
|
return ret;
|
2006-03-23 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 13:46:43 +00:00
|
|
|
/**
|
|
|
|
* xenStoreDomainReboot:
|
|
|
|
* @domain: pointer to the Domain block
|
|
|
|
* @flags: extra flags for the reboot operation, not used yet
|
|
|
|
*
|
|
|
|
* Reboot the domain, the OS is requested to properly shutdown
|
|
|
|
* and reboot but the domain may ignore it. It will return immediately
|
|
|
|
* after queuing the request.
|
|
|
|
*
|
|
|
|
* Returns 0 in case of success, -1 in case of error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
|
|
|
|
{
|
2009-01-21 18:11:14 +00:00
|
|
|
int ret;
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
2006-04-03 13:46:43 +00:00
|
|
|
if ((domain == NULL) || (domain->conn == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-04-03 13:46:43 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2007-02-22 16:49:12 +00:00
|
|
|
if (domain->id == -1 || domain->id == 0)
|
2006-11-15 21:03:34 +00:00
|
|
|
return(-1);
|
2006-04-03 13:46:43 +00:00
|
|
|
/*
|
2008-02-05 19:27:37 +00:00
|
|
|
* this is very hackish, the domU kernel probes for a special
|
2006-04-03 13:46:43 +00:00
|
|
|
* node in the xenstore and launch the shutdown command if found.
|
|
|
|
*/
|
2009-01-21 18:11:14 +00:00
|
|
|
priv = domain->conn->privateData;
|
|
|
|
xenUnifiedLock(priv);
|
|
|
|
ret = virDomainDoStoreWrite(domain, "control/shutdown", "reboot");
|
|
|
|
xenUnifiedUnlock(priv);
|
|
|
|
return ret;
|
2006-04-03 13:46:43 +00:00
|
|
|
}
|
2006-11-07 16:28:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* xenStoreDomainGetOSType:
|
|
|
|
* @domain: a domain object
|
|
|
|
*
|
|
|
|
* Get the type of domain operation system.
|
|
|
|
*
|
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
xenStoreDomainGetOSType(virDomainPtr domain) {
|
|
|
|
char *vm, *str = NULL;
|
|
|
|
|
|
|
|
if ((domain == NULL) || (domain->conn == NULL)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INVALID_ARG, __FUNCTION__);
|
2006-11-07 16:28:16 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
vm = virDomainGetVM(domain);
|
|
|
|
if (vm) {
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedPrivatePtr priv = domain->conn->privateData;
|
|
|
|
xenUnifiedLock(priv);
|
2006-11-07 16:28:16 +00:00
|
|
|
str = virDomainGetVMInfo(domain, vm, "image/ostype");
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedUnlock(priv);
|
|
|
|
VIR_FREE(vm);
|
2006-11-07 16:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (str);
|
|
|
|
}
|
2006-08-09 15:21:16 +00:00
|
|
|
#endif /* ! PROXY */
|
2006-04-03 13:46:43 +00:00
|
|
|
|
2006-08-08 20:14:40 +00:00
|
|
|
/**
|
|
|
|
* xenStoreDomainGetVNCPort:
|
2006-08-09 15:21:16 +00:00
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @domid: id of the domain
|
2006-08-08 20:14:40 +00:00
|
|
|
*
|
|
|
|
* Return the port number on which the domain is listening for VNC
|
2008-02-05 19:27:37 +00:00
|
|
|
* connections.
|
2006-08-08 20:14:40 +00:00
|
|
|
*
|
2009-01-21 18:11:14 +00:00
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*
|
2006-08-08 20:14:40 +00:00
|
|
|
* Returns the port number, -1 in case of error
|
|
|
|
*/
|
2006-08-09 15:21:16 +00:00
|
|
|
int xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) {
|
2006-08-08 20:14:40 +00:00
|
|
|
char *tmp;
|
|
|
|
int ret = -1;
|
|
|
|
|
2006-08-09 15:21:16 +00:00
|
|
|
tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
|
2006-08-08 20:14:40 +00:00
|
|
|
if (tmp != NULL) {
|
|
|
|
char *end;
|
|
|
|
ret = strtol(tmp, &end, 10);
|
|
|
|
if (ret == 0 && end == tmp)
|
|
|
|
ret = -1;
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(tmp);
|
2006-08-08 20:14:40 +00:00
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xenStoreDomainGetConsolePath:
|
2006-08-09 15:21:16 +00:00
|
|
|
* @conn: the hypervisor connection
|
|
|
|
* @domid: id of the domain
|
2006-08-08 20:14:40 +00:00
|
|
|
*
|
2010-01-25 14:58:40 +00:00
|
|
|
* Return the path to the pseudo TTY on which the guest domain's
|
2006-08-08 20:14:40 +00:00
|
|
|
* serial console is attached.
|
|
|
|
*
|
|
|
|
* Returns the path to the serial console. It is the callers
|
|
|
|
* responsibilty to free() the return string. Returns NULL
|
|
|
|
* on error
|
2009-01-21 18:11:14 +00:00
|
|
|
*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
2006-08-08 20:14:40 +00:00
|
|
|
*/
|
2006-08-09 15:21:16 +00:00
|
|
|
char * xenStoreDomainGetConsolePath(virConnectPtr conn, int domid) {
|
|
|
|
return virDomainDoStoreQuery(conn, domid, "console/tty");
|
2006-08-08 20:14:40 +00:00
|
|
|
}
|
2006-11-07 16:28:16 +00:00
|
|
|
|
|
|
|
#ifdef PROXY
|
|
|
|
/*
|
|
|
|
* xenStoreDomainGetOSTypeID:
|
|
|
|
* @conn: pointer to the connection.
|
|
|
|
* @id: the domain id
|
|
|
|
*
|
|
|
|
* Get the type of domain operation system.
|
|
|
|
*
|
2009-01-21 18:11:14 +00:00
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*
|
2006-11-07 16:28:16 +00:00
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
xenStoreDomainGetOSTypeID(virConnectPtr conn, int id) {
|
|
|
|
char *vm, *str = NULL;
|
|
|
|
char query[200];
|
|
|
|
unsigned int len;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-11-07 16:28:16 +00:00
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return(NULL);
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-11-07 16:28:16 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
snprintf(query, 199, "/local/domain/%d/vm", id);
|
|
|
|
query[199] = 0;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
vm = xs_read(priv->xshandle, 0, &query[0], &len);
|
2006-11-07 16:28:16 +00:00
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
snprintf(query, 199, "%s/image/ostype", vm);
|
2008-04-10 16:54:54 +00:00
|
|
|
str = xs_read(priv->xshandle, 0, &query[0], &len);
|
2009-12-09 23:00:50 +00:00
|
|
|
VIR_FREE(vm);
|
2006-11-07 16:28:16 +00:00
|
|
|
}
|
2006-11-08 13:53:29 +00:00
|
|
|
if (str == NULL)
|
|
|
|
str = strdup("linux");
|
2009-11-08 21:08:54 +00:00
|
|
|
if (str == NULL)
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2006-11-07 16:28:16 +00:00
|
|
|
|
|
|
|
return (str);
|
|
|
|
}
|
|
|
|
#endif /* PROXY */
|
2006-11-20 16:42:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* xenStoreDomainGetNetworkID:
|
|
|
|
* @conn: pointer to the connection.
|
|
|
|
* @id: the domain id
|
|
|
|
* @mac: the mac address
|
|
|
|
*
|
|
|
|
* Get the reference (i.e. the string number) for the device on that domain
|
|
|
|
* which uses the given mac address
|
|
|
|
*
|
2009-01-21 18:11:14 +00:00
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*
|
2006-11-20 16:42:16 +00:00
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
xenStoreDomainGetNetworkID(virConnectPtr conn, int id, const char *mac) {
|
|
|
|
char dir[80], path[128], **list = NULL, *val = NULL;
|
2009-02-05 18:14:00 +00:00
|
|
|
unsigned int len, i, num;
|
2006-11-20 16:42:16 +00:00
|
|
|
char *ret = NULL;
|
2007-04-04 14:19:49 +00:00
|
|
|
xenUnifiedPrivatePtr priv;
|
2006-11-20 16:42:16 +00:00
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return(NULL);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
2006-11-20 16:42:16 +00:00
|
|
|
return (NULL);
|
|
|
|
if (mac == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2007-03-23 16:15:07 +00:00
|
|
|
snprintf(dir, sizeof(dir), "/local/domain/0/backend/vif/%d", id);
|
2007-04-04 14:19:49 +00:00
|
|
|
list = xs_directory(priv->xshandle, 0, dir, &num);
|
2006-11-20 16:42:16 +00:00
|
|
|
if (list == NULL)
|
2008-04-10 16:54:54 +00:00
|
|
|
return(NULL);
|
2006-11-20 16:42:16 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2008-04-10 16:54:54 +00:00
|
|
|
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "mac");
|
2009-02-05 18:14:00 +00:00
|
|
|
if ((val = xs_read(priv->xshandle, 0, path, &len)) == NULL)
|
2008-04-10 16:54:54 +00:00
|
|
|
break;
|
2009-02-05 18:14:00 +00:00
|
|
|
|
|
|
|
bool match = (virMacAddrCompare(val, mac) == 0);
|
|
|
|
|
|
|
|
VIR_FREE(val);
|
|
|
|
|
|
|
|
if (match) {
|
2008-04-10 16:54:54 +00:00
|
|
|
ret = strdup(list[i]);
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
if (ret == NULL)
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
|
2008-04-10 16:54:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-11-20 16:42:16 +00:00
|
|
|
}
|
2009-02-05 18:14:00 +00:00
|
|
|
|
|
|
|
VIR_FREE(list);
|
2006-11-20 16:42:16 +00:00
|
|
|
return(ret);
|
|
|
|
}
|
2007-03-15 07:43:16 +00:00
|
|
|
|
2007-11-06 11:49:01 +00:00
|
|
|
/*
|
|
|
|
* xenStoreDomainGetDiskID:
|
|
|
|
* @conn: pointer to the connection.
|
|
|
|
* @id: the domain id
|
|
|
|
* @dev: the virtual block device name
|
|
|
|
*
|
|
|
|
* Get the reference (i.e. the string number) for the device on that domain
|
|
|
|
* which uses the given virtual block device name
|
|
|
|
*
|
2009-01-21 18:11:14 +00:00
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*
|
2007-11-06 11:49:01 +00:00
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
xenStoreDomainGetDiskID(virConnectPtr conn, int id, const char *dev) {
|
|
|
|
char dir[80], path[128], **list = NULL, *val = NULL;
|
|
|
|
unsigned int devlen, len, i, num;
|
|
|
|
char *ret = NULL;
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return (NULL);
|
|
|
|
if (dev == NULL)
|
|
|
|
return (NULL);
|
|
|
|
devlen = strlen(dev);
|
|
|
|
if (devlen <= 0)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
snprintf(dir, sizeof(dir), "/local/domain/0/backend/vbd/%d", id);
|
|
|
|
list = xs_directory(priv->xshandle, 0, dir, &num);
|
2007-12-14 15:38:02 +00:00
|
|
|
if (list != NULL) {
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
|
|
|
|
val = xs_read(priv->xshandle, 0, path, &len);
|
|
|
|
if (val == NULL)
|
|
|
|
break;
|
|
|
|
if ((devlen != len) || memcmp(val, dev, len)) {
|
2009-11-08 21:08:54 +00:00
|
|
|
VIR_FREE (val);
|
2007-12-14 15:38:02 +00:00
|
|
|
} else {
|
|
|
|
ret = strdup(list[i]);
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
if (ret == NULL)
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
VIR_FREE (val);
|
|
|
|
VIR_FREE (list);
|
2007-12-14 15:38:02 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
2007-11-06 11:49:01 +00:00
|
|
|
}
|
2009-11-08 21:08:54 +00:00
|
|
|
VIR_FREE (list);
|
2007-11-06 11:49:01 +00:00
|
|
|
}
|
2007-12-14 15:38:02 +00:00
|
|
|
snprintf(dir, sizeof(dir), "/local/domain/0/backend/tap/%d", id);
|
|
|
|
list = xs_directory(priv->xshandle, 0, dir, &num);
|
|
|
|
if (list != NULL) {
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev");
|
|
|
|
val = xs_read(priv->xshandle, 0, path, &len);
|
|
|
|
if (val == NULL)
|
|
|
|
break;
|
|
|
|
if ((devlen != len) || memcmp(val, dev, len)) {
|
2009-11-08 21:08:54 +00:00
|
|
|
VIR_FREE (val);
|
2007-12-14 15:38:02 +00:00
|
|
|
} else {
|
|
|
|
ret = strdup(list[i]);
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
if (ret == NULL)
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
VIR_FREE (val);
|
|
|
|
VIR_FREE (list);
|
2007-12-14 15:38:02 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
}
|
2009-11-08 21:08:54 +00:00
|
|
|
VIR_FREE (list);
|
2007-12-14 15:38:02 +00:00
|
|
|
}
|
|
|
|
return (NULL);
|
2007-11-06 11:49:01 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 09:53:51 +00:00
|
|
|
/*
|
|
|
|
* xenStoreDomainGetPCIID:
|
|
|
|
* @conn: pointer to the connection.
|
|
|
|
* @id: the domain id
|
|
|
|
* @bdf: the PCI BDF
|
|
|
|
*
|
|
|
|
* Get the reference (i.e. the string number) for the device on that domain
|
|
|
|
* which uses the given PCI address
|
|
|
|
*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*
|
|
|
|
* Returns the new string or NULL in case of error, the string must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
xenStoreDomainGetPCIID(virConnectPtr conn, int id, const char *bdf)
|
|
|
|
{
|
|
|
|
char dir[80], path[128], **list = NULL, *val = NULL;
|
|
|
|
unsigned int len, i, num;
|
|
|
|
char *ret = NULL;
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
|
|
|
|
if (id < 0)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return (NULL);
|
|
|
|
if (bdf == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
snprintf(dir, sizeof(dir), "/local/domain/0/backend/pci/%d", id);
|
|
|
|
list = xs_directory(priv->xshandle, 0, dir, &num);
|
|
|
|
if (list == NULL)
|
|
|
|
return(NULL);
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
snprintf(path, sizeof(path), "%s/%s/%s", dir, list[i], "dev-0");
|
|
|
|
if ((val = xs_read(priv->xshandle, 0, path, &len)) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool match = STREQ(val, bdf);
|
|
|
|
|
|
|
|
VIR_FREE(val);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
ret = strdup(list[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(list);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
/*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*/
|
2007-08-10 18:25:15 +00:00
|
|
|
char *xenStoreDomainGetName(virConnectPtr conn,
|
|
|
|
int id) {
|
|
|
|
char prop[200];
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
unsigned int len;
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
snprintf(prop, 199, "/local/domain/%d/name", id);
|
|
|
|
prop[199] = 0;
|
|
|
|
return xs_read(priv->xshandle, 0, prop, &len);
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
#ifndef PROXY
|
2009-01-21 18:11:14 +00:00
|
|
|
/*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*/
|
2008-11-25 10:44:52 +00:00
|
|
|
int xenStoreDomainGetUUID(virConnectPtr conn,
|
|
|
|
int id,
|
|
|
|
unsigned char *uuid) {
|
|
|
|
char prop[200];
|
|
|
|
xenUnifiedPrivatePtr priv;
|
|
|
|
unsigned int len;
|
|
|
|
char *uuidstr;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
snprintf(prop, 199, "/local/domain/%d/vm", id);
|
|
|
|
prop[199] = 0;
|
|
|
|
// This will return something like
|
|
|
|
// /vm/00000000-0000-0000-0000-000000000000
|
|
|
|
uuidstr = xs_read(priv->xshandle, 0, prop, &len);
|
|
|
|
|
|
|
|
// remove "/vm/"
|
|
|
|
ret = virUUIDParse(uuidstr + 4, uuid);
|
|
|
|
|
|
|
|
VIR_FREE(uuidstr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
static void
|
|
|
|
xenStoreWatchListFree(xenStoreWatchListPtr list)
|
2008-11-25 10:44:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<list->count; i++) {
|
|
|
|
VIR_FREE(list->watches[i]->path);
|
|
|
|
VIR_FREE(list->watches[i]->token);
|
|
|
|
VIR_FREE(list->watches[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(list);
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
/*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*/
|
2008-11-25 10:44:52 +00:00
|
|
|
int xenStoreAddWatch(virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
const char *token,
|
|
|
|
xenStoreWatchCallback cb,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2009-11-08 21:08:54 +00:00
|
|
|
xenStoreWatchPtr watch = NULL;
|
2008-11-25 10:44:52 +00:00
|
|
|
int n;
|
|
|
|
xenStoreWatchListPtr list;
|
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
list = priv->xsWatchList;
|
|
|
|
if(!list)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* check if we already have this callback on our list */
|
|
|
|
for (n=0; n < list->count; n++) {
|
|
|
|
if( STREQ(list->watches[n]->path, path) &&
|
|
|
|
STREQ(list->watches[n]->token, token)) {
|
2010-04-02 23:50:19 +00:00
|
|
|
virXenStoreError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("watch already tracked"));
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(watch) < 0)
|
2009-11-08 21:08:54 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
watch->path = strdup(path);
|
|
|
|
watch->token = strdup(token);
|
|
|
|
watch->cb = cb;
|
|
|
|
watch->opaque = opaque;
|
|
|
|
|
2009-11-08 21:08:54 +00:00
|
|
|
if (watch->path == NULL || watch->token == NULL) {
|
|
|
|
goto no_memory;
|
|
|
|
}
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
/* Make space on list */
|
|
|
|
n = list->count;
|
|
|
|
if (VIR_REALLOC_N(list->watches, n + 1) < 0) {
|
2009-11-08 21:08:54 +00:00
|
|
|
goto no_memory;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
list->watches[n] = watch;
|
|
|
|
list->count++;
|
|
|
|
|
|
|
|
return xs_watch(priv->xshandle, watch->path, watch->token);
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
if (watch) {
|
|
|
|
VIR_FREE(watch->path);
|
|
|
|
VIR_FREE(watch->token);
|
|
|
|
VIR_FREE(watch);
|
|
|
|
}
|
|
|
|
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
/*
|
|
|
|
* The caller must hold the lock on the privateData
|
|
|
|
* associated with the 'conn' parameter.
|
|
|
|
*/
|
2008-11-25 10:44:52 +00:00
|
|
|
int xenStoreRemoveWatch(virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
const char *token)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
xenStoreWatchListPtr list;
|
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
|
|
|
|
|
|
|
if (priv->xshandle == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
list = priv->xsWatchList;
|
|
|
|
if(!list)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0 ; i < list->count ; i++) {
|
|
|
|
if( STREQ(list->watches[i]->path, path) &&
|
|
|
|
STREQ(list->watches[i]->token, token)) {
|
|
|
|
|
|
|
|
if (!xs_unwatch(priv->xshandle,
|
|
|
|
list->watches[i]->path,
|
2009-01-15 01:23:32 +00:00
|
|
|
list->watches[i]->token))
|
2008-11-25 10:44:52 +00:00
|
|
|
{
|
|
|
|
DEBUG0("WARNING: Could not remove watch");
|
|
|
|
/* Not fatal, continue */
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(list->watches[i]->path);
|
|
|
|
VIR_FREE(list->watches[i]->token);
|
|
|
|
VIR_FREE(list->watches[i]);
|
|
|
|
|
|
|
|
if (i < (list->count - 1))
|
|
|
|
memmove(list->watches + i,
|
|
|
|
list->watches + i + 1,
|
|
|
|
sizeof(*(list->watches)) *
|
|
|
|
(list->count - (i + 1)));
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(list->watches,
|
|
|
|
list->count - 1) < 0) {
|
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
|
|
|
list->count--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
static xenStoreWatchPtr
|
|
|
|
xenStoreFindWatch(xenStoreWatchListPtr list,
|
|
|
|
const char *path,
|
|
|
|
const char *token)
|
2008-11-25 10:44:52 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0 ; i < list->count ; i++)
|
|
|
|
if( STREQ(path, list->watches[i]->path) &&
|
|
|
|
STREQ(token, list->watches[i]->token) )
|
|
|
|
return list->watches[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
static void
|
|
|
|
xenStoreWatchEvent(int watch ATTRIBUTE_UNUSED,
|
|
|
|
int fd ATTRIBUTE_UNUSED,
|
2009-03-11 13:43:24 +00:00
|
|
|
int events,
|
2009-01-21 18:11:14 +00:00
|
|
|
void *data)
|
2008-11-25 10:44:52 +00:00
|
|
|
{
|
|
|
|
char **event;
|
|
|
|
char *path;
|
|
|
|
char *token;
|
|
|
|
unsigned int stringCount;
|
|
|
|
xenStoreWatchPtr sw;
|
|
|
|
|
|
|
|
virConnectPtr conn = data;
|
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
|
2009-03-11 13:43:24 +00:00
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
if(!priv) return;
|
2009-01-21 18:11:14 +00:00
|
|
|
|
2009-03-11 13:43:24 +00:00
|
|
|
/* only set a watch on read and write events */
|
|
|
|
if (events & (VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP)) return;
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
xenUnifiedLock(priv);
|
|
|
|
|
|
|
|
if(!priv->xshandle)
|
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
event = xs_read_watch(priv->xshandle, &stringCount);
|
|
|
|
if (!event)
|
2009-01-21 18:11:14 +00:00
|
|
|
goto cleanup;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
path = event[XS_WATCH_PATH];
|
|
|
|
token = event[XS_WATCH_TOKEN];
|
|
|
|
|
|
|
|
sw = xenStoreFindWatch(priv->xsWatchList, path, token);
|
|
|
|
if( sw )
|
|
|
|
sw->cb(conn, path, token, sw->opaque);
|
|
|
|
VIR_FREE(event);
|
2009-01-21 18:11:14 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
xenUnifiedUnlock(priv);
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The domain callback for the @introduceDomain watch
|
|
|
|
*
|
|
|
|
* The lock on 'priv' is held when calling this
|
|
|
|
*/
|
2008-11-25 10:44:52 +00:00
|
|
|
int xenStoreDomainIntroduced(virConnectPtr conn,
|
|
|
|
const char *path ATTRIBUTE_UNUSED,
|
|
|
|
const char *token ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
int i, j, found, missing = 0, retries = 20;
|
|
|
|
int new_domain_cnt;
|
|
|
|
int *new_domids;
|
|
|
|
int nread;
|
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedPrivatePtr priv = opaque;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
retry:
|
|
|
|
new_domain_cnt = xenStoreNumOfDomains(conn);
|
2010-02-02 11:22:17 +00:00
|
|
|
if (new_domain_cnt < 0)
|
|
|
|
return -1;
|
|
|
|
|
2008-11-25 10:44:52 +00:00
|
|
|
if( VIR_ALLOC_N(new_domids,new_domain_cnt) < 0 ) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 09:32:37 +00:00
|
|
|
nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
|
2008-11-25 10:44:52 +00:00
|
|
|
if (nread != new_domain_cnt) {
|
|
|
|
// mismatch. retry this read
|
|
|
|
VIR_FREE(new_domids);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
missing = 0;
|
|
|
|
for (i=0 ; i < new_domain_cnt ; i++) {
|
|
|
|
found = 0;
|
2009-01-20 17:19:23 +00:00
|
|
|
for (j = 0 ; j < priv->activeDomainList->count ; j++) {
|
|
|
|
if (priv->activeDomainList->doms[j]->id == new_domids[i]) {
|
2008-11-25 10:44:52 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2008-12-04 21:09:20 +00:00
|
|
|
virDomainEventPtr event;
|
2008-11-25 10:44:52 +00:00
|
|
|
char *name;
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
|
|
|
|
|
|
|
if (!(name = xenStoreDomainGetName(conn, new_domids[i]))) {
|
|
|
|
missing = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xenStoreDomainGetUUID(conn, new_domids[i], uuid) < 0) {
|
|
|
|
missing = 1;
|
|
|
|
VIR_FREE(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
event = virDomainEventNew(new_domids[i], name, uuid,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED,
|
|
|
|
VIR_DOMAIN_EVENT_STARTED_BOOTED);
|
|
|
|
if (event)
|
|
|
|
xenUnifiedDomainEventDispatch(priv, event);
|
2008-11-25 10:44:52 +00:00
|
|
|
|
2008-12-04 21:09:20 +00:00
|
|
|
/* Add to the list */
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedAddDomainInfo(priv->activeDomainList,
|
2008-12-04 21:09:20 +00:00
|
|
|
new_domids[i], name, uuid);
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
VIR_FREE(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VIR_FREE(new_domids);
|
|
|
|
|
|
|
|
if (missing && retries--) {
|
|
|
|
DEBUG0("Some domains were missing, trying again");
|
|
|
|
usleep(100 * 1000);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-21 18:11:14 +00:00
|
|
|
/*
|
|
|
|
* The domain callback for the @destroyDomain watch
|
|
|
|
*
|
|
|
|
* The lock on 'priv' is held when calling this
|
|
|
|
*/
|
2008-11-25 10:44:52 +00:00
|
|
|
int xenStoreDomainReleased(virConnectPtr conn,
|
|
|
|
const char *path ATTRIBUTE_UNUSED,
|
|
|
|
const char *token ATTRIBUTE_UNUSED,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
int i, j, found, removed, retries = 20;
|
|
|
|
int new_domain_cnt;
|
|
|
|
int *new_domids;
|
|
|
|
int nread;
|
|
|
|
|
|
|
|
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) opaque;
|
|
|
|
|
2009-01-20 17:19:23 +00:00
|
|
|
if(!priv->activeDomainList->count) return 0;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
retry:
|
|
|
|
new_domain_cnt = xenStoreNumOfDomains(conn);
|
2010-02-02 11:22:17 +00:00
|
|
|
if (new_domain_cnt < 0)
|
|
|
|
return -1;
|
2008-11-25 10:44:52 +00:00
|
|
|
|
|
|
|
if( VIR_ALLOC_N(new_domids,new_domain_cnt) < 0 ) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-25 10:44:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 09:32:37 +00:00
|
|
|
nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
|
2008-11-25 10:44:52 +00:00
|
|
|
if (nread != new_domain_cnt) {
|
|
|
|
// mismatch. retry this read
|
|
|
|
VIR_FREE(new_domids);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
removed = 0;
|
2009-01-20 17:19:23 +00:00
|
|
|
for (j=0 ; j < priv->activeDomainList->count ; j++) {
|
2008-11-25 10:44:52 +00:00
|
|
|
found = 0;
|
|
|
|
for (i=0 ; i < new_domain_cnt ; i++) {
|
2009-01-20 17:19:23 +00:00
|
|
|
if (priv->activeDomainList->doms[j]->id == new_domids[i]) {
|
2008-11-25 10:44:52 +00:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2008-12-04 21:09:20 +00:00
|
|
|
virDomainEventPtr event =
|
|
|
|
virDomainEventNew(-1,
|
2009-01-20 17:19:23 +00:00
|
|
|
priv->activeDomainList->doms[j]->name,
|
|
|
|
priv->activeDomainList->doms[j]->uuid,
|
2008-12-04 21:09:20 +00:00
|
|
|
VIR_DOMAIN_EVENT_STOPPED,
|
|
|
|
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
|
|
|
|
if (event)
|
|
|
|
xenUnifiedDomainEventDispatch(priv, event);
|
|
|
|
|
|
|
|
/* Remove from the list */
|
2009-01-20 17:19:23 +00:00
|
|
|
xenUnifiedRemoveDomainInfo(priv->activeDomainList,
|
|
|
|
priv->activeDomainList->doms[j]->id,
|
|
|
|
priv->activeDomainList->doms[j]->name,
|
|
|
|
priv->activeDomainList->doms[j]->uuid);
|
2008-12-04 21:09:20 +00:00
|
|
|
|
|
|
|
removed = 1;
|
2008-11-25 10:44:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(new_domids);
|
|
|
|
|
|
|
|
if (!removed && retries--) {
|
|
|
|
DEBUG0("No domains removed, retrying");
|
|
|
|
usleep(100 * 1000);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //PROXY
|