提交 ea1c08e7 编写于 作者: D Daniel P. Berrange

Use explicit logic rules for opening Xen sub-drivers

上级 a34bcb78
Mon Mar 17 13:24:22 EDT 2008 Daniel P. Berrange <berrange@redhat.com>
* configure.in: Add WITH_PROXY to config.h file
* src/remote_internal.c: Handle local Xen URIs if Xen drivers
declines them
* src/xen_unfied.c: Use explicit logic for opening sub-drivers
rather than a hacked loop.
* src/xend_internal.c: Don't complain about failing to open
xend when non-root read-only.
Mon Mar 17 17:55:56 CET 2008 Jim Meyering <meyering@redhat.com>
Treat ENOTSUP like ENODATA, after failed fgetfilecon.
......
......@@ -869,6 +869,9 @@ fi
AC_MSG_RESULT([$with_xen_proxy])
AM_CONDITIONAL(WITH_PROXY,[test "$with_xen_proxy" = "yes"])
if test "$with_xen_proxy" = "yes"; then
AC_DEFINE(WITH_PROXY, 1, [Whether Xen proxy is enabled])
fi
dnl Enable building libvirtd?
AM_CONDITIONAL(WITH_LIBVIRTD,[test "x$with_libvirtd" = "xyes"])
......
......@@ -835,6 +835,14 @@ remoteOpen (virConnectPtr conn,
}
}
#endif
#if WITH_XEN
if (uri &&
uri->scheme && STREQ (uri->scheme, "xen") &&
(!uri->server || STREQ (uri->server, "")) &&
(!uri->path || STREQ(uri->path, "/"))) {
rflags |= VIR_DRV_OPEN_REMOTE_UNIX;
}
#endif
priv->magic = DEAD;
priv->sock = -1;
......
......@@ -42,6 +42,7 @@
#include "util.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
static int
xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info);
......@@ -239,7 +240,7 @@ xenUnifiedProbe (void)
static int
xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int flags)
{
int i, j;
int i;
xenUnifiedPrivatePtr priv;
/* Refuse any scheme which isn't "xen://" or "http://". */
......@@ -276,41 +277,73 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
priv->xshandle = NULL;
priv->proxy = -1;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i) {
priv->opened[i] = 0;
/* Only use XM driver for Xen <= 3.0.3 (ie xendConfigVersion <= 2) */
if (drivers[i] == &xenXMDriver &&
priv->xendConfigVersion > 2)
continue;
/* Ignore proxy for root */
if (i == XEN_UNIFIED_PROXY_OFFSET && getuid() == 0)
continue;
if (drivers[i]->open) {
DEBUG("trying Xen sub-driver %d", i);
if (drivers[i]->open (conn, uri, auth, flags) == VIR_DRV_OPEN_SUCCESS)
priv->opened[i] = 1;
DEBUG("Xen sub-driver %d open %s\n",
i, priv->opened[i] ? "ok" : "failed");
/* Hypervisor is only run as root & required to succeed */
if (getuid() == 0) {
DEBUG0("Trying hypervisor sub-driver");
if (drivers[XEN_UNIFIED_HYPERVISOR_OFFSET]->open(conn, uri, auth, flags) ==
VIR_DRV_OPEN_SUCCESS) {
DEBUG0("Activated hypervisor sub-driver");
priv->opened[XEN_UNIFIED_HYPERVISOR_OFFSET] = 1;
}
}
/* If as root, then all drivers must succeed.
If non-root, then only proxy must succeed */
if (!priv->opened[i] &&
(getuid() == 0 || i == XEN_UNIFIED_PROXY_OFFSET)) {
for (j = 0; j < i; ++j)
if (priv->opened[j]) drivers[j]->close (conn);
free (priv);
/* The assumption is that one of the underlying drivers
* has set virterror already.
*/
return VIR_DRV_OPEN_ERROR;
/* XenD is required to suceed if root.
* If it fails as non-root, then the proxy driver may take over
*/
DEBUG0("Trying XenD sub-driver");
if (drivers[XEN_UNIFIED_XEND_OFFSET]->open(conn, uri, auth, flags) ==
VIR_DRV_OPEN_SUCCESS) {
DEBUG0("Activated XenD sub-driver");
priv->opened[XEN_UNIFIED_XEND_OFFSET] = 1;
/* XenD is active, so try the xm & xs drivers too, both requird to
* succeed if root, optional otherwise */
if (priv->xendConfigVersion <= 2) {
DEBUG0("Trying XM sub-driver");
if (drivers[XEN_UNIFIED_XM_OFFSET]->open(conn, uri, auth, flags) ==
VIR_DRV_OPEN_SUCCESS) {
DEBUG0("Activated XM sub-driver");
priv->opened[XEN_UNIFIED_XM_OFFSET] = 1;
}
}
DEBUG0("Trying XS sub-driver");
if (drivers[XEN_UNIFIED_XS_OFFSET]->open(conn, uri, auth, flags) ==
VIR_DRV_OPEN_SUCCESS) {
DEBUG0("Activated XS sub-driver");
priv->opened[XEN_UNIFIED_XS_OFFSET] = 1;
} else {
if (getuid() == 0)
goto fail; /* XS is mandatory as root */
}
} else {
if (getuid() == 0) {
goto fail; /* XenD is mandatory as root */
} else {
#if WITH_PROXY
DEBUG0("Trying proxy sub-driver");
if (drivers[XEN_UNIFIED_PROXY_OFFSET]->open(conn, uri, auth, flags) ==
VIR_DRV_OPEN_SUCCESS) {
DEBUG0("Activated proxy sub-driver");
priv->opened[XEN_UNIFIED_PROXY_OFFSET] = 1;
} else {
goto fail; /* Proxy is mandatory if XenD failed */
}
#else
DEBUG0("Handing off for remote driver");
return VIR_DRV_OPEN_DECLINED; /* Let remote_driver try instead */
#endif
}
}
return VIR_DRV_OPEN_SUCCESS;
fail:
DEBUG0("Failed to activate a mandatory sub-driver");
for (i = 0 ; i < XEN_UNIFIED_NR_DRIVERS ; i++)
if (priv->opened[i]) drivers[i]->close(conn);
free(priv);
return VIR_DRV_OPEN_ERROR;
}
#define GET_PRIVATE(conn) \
......
......@@ -234,14 +234,13 @@ do_connect(virConnectPtr xend)
close(s);
errno = serrno;
s = -1;
/*
* not being able to connect via the socket as a normal user
* is rather normal, this should fallback to the proxy (or
* remote) mechanism.
*/
if ((getuid() == 0) || (xend->flags & VIR_CONNECT_RO)) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
_("failed to connect to xend"));
/*
* Connecting to XenD as root is mandatory, so log this error
*/
if (getuid() == 0) {
virXendError(xend, VIR_ERR_INTERNAL_ERROR,
_("failed to connect to xend"));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册