|
|
e51146 |
diff -ur a/server/checkpoint.c b/server/checkpoint.c
|
|
|
e51146 |
--- a/server/checkpoint.c 2014-06-23 15:56:09.000000000 -0400
|
|
|
e51146 |
+++ b/server/checkpoint.c 2017-08-09 13:30:40.708689303 -0400
|
|
|
e51146 |
@@ -79,7 +79,7 @@
|
|
|
e51146 |
{
|
|
|
e51146 |
virt_list_t *list = NULL;
|
|
|
e51146 |
|
|
|
e51146 |
- list = vl_get(vp, my_id);
|
|
|
e51146 |
+ list = vl_get(vp, 1, my_id);
|
|
|
e51146 |
if (!list)
|
|
|
e51146 |
return -1;
|
|
|
e51146 |
|
|
|
e51146 |
diff -ur a/server/libvirt.c b/server/libvirt.c
|
|
|
e51146 |
--- a/server/libvirt.c 2014-06-23 15:56:09.000000000 -0400
|
|
|
e51146 |
+++ b/server/libvirt.c 2017-08-09 13:30:40.709689288 -0400
|
|
|
e51146 |
@@ -1,5 +1,5 @@
|
|
|
e51146 |
/*
|
|
|
e51146 |
- Copyright Red Hat, Inc. 2006
|
|
|
e51146 |
+ Copyright Red Hat, Inc. 2006-2017
|
|
|
e51146 |
|
|
|
e51146 |
This program is free software; you can redistribute it and/or modify it
|
|
|
e51146 |
under the terms of the GNU General Public License as published by the
|
|
|
e51146 |
@@ -61,13 +61,15 @@
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
#define NAME "libvirt"
|
|
|
e51146 |
-#define VERSION "0.1"
|
|
|
e51146 |
+#define VERSION "0.3"
|
|
|
e51146 |
|
|
|
e51146 |
#define MAGIC 0x1e19317a
|
|
|
e51146 |
|
|
|
e51146 |
struct libvirt_info {
|
|
|
e51146 |
int magic;
|
|
|
e51146 |
- virConnectPtr vp;
|
|
|
e51146 |
+ config_object_t *config;
|
|
|
e51146 |
+ int vp_count;
|
|
|
e51146 |
+ virConnectPtr *vp;
|
|
|
e51146 |
};
|
|
|
e51146 |
|
|
|
e51146 |
#define VALIDATE(arg) \
|
|
|
e51146 |
@@ -79,179 +81,128 @@
|
|
|
e51146 |
} while(0)
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
-static inline int
|
|
|
e51146 |
-wait_domain(const char *vm_name, virConnectPtr vp,
|
|
|
e51146 |
- int timeout)
|
|
|
e51146 |
-{
|
|
|
e51146 |
- int tries = 0;
|
|
|
e51146 |
- int response = 1;
|
|
|
e51146 |
- int ret;
|
|
|
e51146 |
- virDomainPtr vdp;
|
|
|
e51146 |
- virDomainInfo vdi;
|
|
|
e51146 |
- int uuid_check;
|
|
|
e51146 |
-
|
|
|
e51146 |
- uuid_check = is_uuid(vm_name);
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (uuid_check) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(vp, (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(vp, vm_name);
|
|
|
e51146 |
+static void
|
|
|
e51146 |
+libvirt_init_libvirt_conf(struct libvirt_info *info) {
|
|
|
e51146 |
+ config_object_t *config = info->config;
|
|
|
e51146 |
+ int i = 0;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (info->vp) {
|
|
|
e51146 |
+ dbg_printf(2, "Lost libvirtd connection. Reinitializing.\n");
|
|
|
e51146 |
+ for (i = 0 ; i < info->vp_count ; i++)
|
|
|
e51146 |
+ virConnectClose(info->vp[i]);
|
|
|
e51146 |
+ free(info->vp);
|
|
|
e51146 |
+ info->vp = NULL;
|
|
|
e51146 |
}
|
|
|
e51146 |
- if (!vdp)
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
+ info->vp_count = 0;
|
|
|
e51146 |
|
|
|
e51146 |
- /* Check domain liveliness. If the domain is still here,
|
|
|
e51146 |
- we return failure, and the client must then retry */
|
|
|
e51146 |
- /* XXX On the xen 3.0.4 API, we will be able to guarantee
|
|
|
e51146 |
- synchronous virDomainDestroy, so this check will not
|
|
|
e51146 |
- be necessary */
|
|
|
e51146 |
do {
|
|
|
e51146 |
- if (++tries > timeout)
|
|
|
e51146 |
- break;
|
|
|
e51146 |
+ virConnectPtr vp;
|
|
|
e51146 |
+ virConnectPtr *vpl = NULL;
|
|
|
e51146 |
+ char conf_attr[256];
|
|
|
e51146 |
+ char value[1024];
|
|
|
e51146 |
+ char *uri;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (i != 0) {
|
|
|
e51146 |
+ snprintf(conf_attr, sizeof(conf_attr),
|
|
|
e51146 |
+ "backends/libvirt/@uri%d", i);
|
|
|
e51146 |
+ } else
|
|
|
e51146 |
+ snprintf(conf_attr, sizeof(conf_attr), "backends/libvirt/@uri");
|
|
|
e51146 |
+ ++i;
|
|
|
e51146 |
|
|
|
e51146 |
- sleep(1);
|
|
|
e51146 |
- if (uuid_check) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(vp,
|
|
|
e51146 |
- (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(vp, vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
- if (!vdp) {
|
|
|
e51146 |
- dbg_printf(2, "Domain no longer exists\n");
|
|
|
e51146 |
- response = 0;
|
|
|
e51146 |
+ if (sc_get(config, conf_attr, value, sizeof(value)) != 0)
|
|
|
e51146 |
break;
|
|
|
e51146 |
- }
|
|
|
e51146 |
|
|
|
e51146 |
- memset(&vdi, 0, sizeof(vdi));
|
|
|
e51146 |
- ret = virDomainGetInfo(vdp, &vdi;;
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- if (ret < 0)
|
|
|
e51146 |
+ uri = value;
|
|
|
e51146 |
+ vp = virConnectOpen(uri);
|
|
|
e51146 |
+ if (!vp) {
|
|
|
e51146 |
+ dbg_printf(1, "[libvirt:INIT] Failed to connect to URI: %s\n", uri);
|
|
|
e51146 |
continue;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
|
|
|
e51146 |
- if (vdi.state == VIR_DOMAIN_SHUTOFF) {
|
|
|
e51146 |
- dbg_printf(2, "Domain has been shut off\n");
|
|
|
e51146 |
- response = 0;
|
|
|
e51146 |
- break;
|
|
|
e51146 |
+ vpl = realloc(info->vp, sizeof(*info->vp) * (info->vp_count + 1));
|
|
|
e51146 |
+ if (!vpl) {
|
|
|
e51146 |
+ dbg_printf(1, "[libvirt:INIT] Out of memory allocating URI: %s\n",
|
|
|
e51146 |
+ uri);
|
|
|
e51146 |
+ virConnectClose(vp);
|
|
|
e51146 |
+ continue;
|
|
|
e51146 |
}
|
|
|
e51146 |
-
|
|
|
e51146 |
- dbg_printf(4, "Domain still exists (state %d) "
|
|
|
e51146 |
- "after %d seconds\n",
|
|
|
e51146 |
- vdi.state, tries);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ info->vp = vpl;
|
|
|
e51146 |
+ info->vp[info->vp_count++] = vp;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (i > 1)
|
|
|
e51146 |
+ dbg_printf(1, "[libvirt:INIT] Added URI%d %s\n", i - 1, uri);
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ dbg_printf(1, "[libvirt:INIT] Added URI %s\n", uri);
|
|
|
e51146 |
} while (1);
|
|
|
e51146 |
+}
|
|
|
e51146 |
|
|
|
e51146 |
- return response;
|
|
|
e51146 |
+
|
|
|
e51146 |
+static int
|
|
|
e51146 |
+libvirt_bad_connections(struct libvirt_info *info) {
|
|
|
e51146 |
+ int bad = 0;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ for (i = 0 ; i < info->vp_count ; i++) {
|
|
|
e51146 |
+ /*
|
|
|
e51146 |
+ ** Send a dummy command to trigger an error if libvirtd
|
|
|
e51146 |
+ ** died or restarted
|
|
|
e51146 |
+ */
|
|
|
e51146 |
+ virConnectNumOfDomains(info->vp[i]);
|
|
|
e51146 |
+ if (!virConnectIsAlive(info->vp[i])) {
|
|
|
e51146 |
+ dbg_printf(1, "libvirt connection %d is dead\n", i);
|
|
|
e51146 |
+ bad++;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (info->vp_count < 1 || bad)
|
|
|
e51146 |
+ libvirt_init_libvirt_conf(info);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ return bad || info->vp_count < 1;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
+static void
|
|
|
e51146 |
+libvirt_validate_connections(struct libvirt_info *info) {
|
|
|
e51146 |
+ while (1) {
|
|
|
e51146 |
+ if (libvirt_bad_connections(info))
|
|
|
e51146 |
+ sleep(1);
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+}
|
|
|
e51146 |
|
|
|
e51146 |
static int
|
|
|
e51146 |
libvirt_null(const char *vm_name, void *priv)
|
|
|
e51146 |
{
|
|
|
e51146 |
- dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
printf("NULL operation: returning failure\n");
|
|
|
e51146 |
return 1;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
static int
|
|
|
e51146 |
-libvirt_off(const char *vm_name, const char *src,
|
|
|
e51146 |
- uint32_t seqno, void *priv)
|
|
|
e51146 |
+libvirt_off(const char *vm_name, const char *src, uint32_t seqno, void *priv)
|
|
|
e51146 |
{
|
|
|
e51146 |
struct libvirt_info *info = (struct libvirt_info *)priv;
|
|
|
e51146 |
- virDomainPtr vdp;
|
|
|
e51146 |
- virDomainInfo vdi;
|
|
|
e51146 |
- int ret = -1;
|
|
|
e51146 |
|
|
|
e51146 |
- dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s %s %u\n", __FUNCTION__, vm_name, seqno);
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
|
|
|
e51146 |
- if (is_uuid(vm_name)) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(info->vp,
|
|
|
e51146 |
- (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(info->vp, vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (!vdp) {
|
|
|
e51146 |
- dbg_printf(2, "Nothing to do - domain does not exist\n");
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (((virDomainGetInfo(vdp, &vdi) == 0) &&
|
|
|
e51146 |
- (vdi.state == VIR_DOMAIN_SHUTOFF))) {
|
|
|
e51146 |
- dbg_printf(2, "Nothing to do - domain is off\n");
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Destroying domain %s\n", vm_name);
|
|
|
e51146 |
- dbg_printf(2, "[OFF] Calling virDomainDestroy\n");
|
|
|
e51146 |
- ret = virDomainDestroy(vdp);
|
|
|
e51146 |
- if (ret < 0) {
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Failed to destroy domain: %d\n", ret);
|
|
|
e51146 |
- printf("virDomainDestroy() failed: %d\n", ret);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (ret) {
|
|
|
e51146 |
- syslog(LOG_NOTICE,
|
|
|
e51146 |
- "Domain %s still exists; fencing failed\n",
|
|
|
e51146 |
- vm_name);
|
|
|
e51146 |
- printf("Domain %s still exists; fencing failed\n", vm_name);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
+ libvirt_validate_connections(info);
|
|
|
e51146 |
+ return vm_off(info->vp, info->vp_count, vm_name);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
static int
|
|
|
e51146 |
-libvirt_on(const char *vm_name, const char *src,
|
|
|
e51146 |
- uint32_t seqno, void *priv)
|
|
|
e51146 |
+libvirt_on(const char *vm_name, const char *src, uint32_t seqno, void *priv)
|
|
|
e51146 |
{
|
|
|
e51146 |
struct libvirt_info *info = (struct libvirt_info *)priv;
|
|
|
e51146 |
- virDomainPtr vdp;
|
|
|
e51146 |
- virDomainInfo vdi;
|
|
|
e51146 |
- int ret = -1;
|
|
|
e51146 |
|
|
|
e51146 |
- dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s %s %u\n", __FUNCTION__, vm_name, seqno);
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
|
|
|
e51146 |
- if (is_uuid(vm_name)) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(info->vp,
|
|
|
e51146 |
- (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(info->vp, vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (vdp &&
|
|
|
e51146 |
- ((virDomainGetInfo(vdp, &vdi) == 0) &&
|
|
|
e51146 |
- (vdi.state != VIR_DOMAIN_SHUTOFF))) {
|
|
|
e51146 |
- dbg_printf(2, "Nothing to do - domain is running\n");
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (vdp)
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Starting domain %s\n", vm_name);
|
|
|
e51146 |
- dbg_printf(2, "[ON] Calling virDomainCreate\n");
|
|
|
e51146 |
- ret = virDomainCreate(vdp);
|
|
|
e51146 |
- if (ret < 0) {
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Failed to start domain: %d\n", ret);
|
|
|
e51146 |
- printf("virDomainCreate() failed: %d\n", ret);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (ret) {
|
|
|
e51146 |
- syslog(LOG_NOTICE,
|
|
|
e51146 |
- "Domain %s did not start\n",
|
|
|
e51146 |
- vm_name);
|
|
|
e51146 |
- printf("Domain %s did not start\n", vm_name);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Domain %s started\n", vm_name);
|
|
|
e51146 |
-
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
+ libvirt_validate_connections(info);
|
|
|
e51146 |
+ return vm_on(info->vp, info->vp_count, vm_name);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
@@ -270,126 +221,25 @@
|
|
|
e51146 |
libvirt_status(const char *vm_name, void *priv)
|
|
|
e51146 |
{
|
|
|
e51146 |
struct libvirt_info *info = (struct libvirt_info *)priv;
|
|
|
e51146 |
- virDomainPtr vdp;
|
|
|
e51146 |
- virDomainInfo vdi;
|
|
|
e51146 |
- int ret = 0;
|
|
|
e51146 |
|
|
|
e51146 |
- dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
|
|
|
e51146 |
- if (is_uuid(vm_name)) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(info->vp,
|
|
|
e51146 |
- (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(info->vp, vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (!vdp || ((virDomainGetInfo(vdp, &vdi) == 0) &&
|
|
|
e51146 |
- (vdi.state == VIR_DOMAIN_SHUTOFF))) {
|
|
|
e51146 |
- ret = RESP_OFF;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (vdp)
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- return ret;
|
|
|
e51146 |
+ libvirt_validate_connections(info);
|
|
|
e51146 |
+ return vm_status(info->vp, info->vp_count, vm_name);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
static int
|
|
|
e51146 |
-libvirt_reboot(const char *vm_name, const char *src,
|
|
|
e51146 |
- uint32_t seqno, void *priv)
|
|
|
e51146 |
+libvirt_reboot(const char *vm_name, const char *src, uint32_t seqno, void *priv)
|
|
|
e51146 |
{
|
|
|
e51146 |
struct libvirt_info *info = (struct libvirt_info *)priv;
|
|
|
e51146 |
- virDomainPtr vdp, nvdp;
|
|
|
e51146 |
- virDomainInfo vdi;
|
|
|
e51146 |
- char *domain_desc;
|
|
|
e51146 |
- int ret;
|
|
|
e51146 |
|
|
|
e51146 |
- //uuid_unparse(vm_uuid, uu_string);
|
|
|
e51146 |
- dbg_printf(5, "%s %s\n", __FUNCTION__, vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s %s %u\n", __FUNCTION__, vm_name, seqno);
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (is_uuid(vm_name)) {
|
|
|
e51146 |
- vdp = virDomainLookupByUUIDString(info->vp,
|
|
|
e51146 |
- (const char *)vm_name);
|
|
|
e51146 |
- } else {
|
|
|
e51146 |
- vdp = virDomainLookupByName(info->vp, vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (!vdp) {
|
|
|
e51146 |
- dbg_printf(2, "[libvirt:REBOOT] Nothing to "
|
|
|
e51146 |
- "do - domain does not exist\n");
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (((virDomainGetInfo(vdp, &vdi) == 0) &&
|
|
|
e51146 |
- (vdi.state == VIR_DOMAIN_SHUTOFF))) {
|
|
|
e51146 |
- dbg_printf(2, "[libvirt:REBOOT] Nothing to "
|
|
|
e51146 |
- "do - domain is off\n");
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
-
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Rebooting domain %s\n", vm_name);
|
|
|
e51146 |
- printf("Rebooting domain %s...\n", vm_name);
|
|
|
e51146 |
- domain_desc = virDomainGetXMLDesc(vdp, 0);
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (!domain_desc) {
|
|
|
e51146 |
- printf("Failed getting domain description from "
|
|
|
e51146 |
- "libvirt\n");
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- dbg_printf(2, "[REBOOT] Calling virDomainDestroy(%p)\n", vdp);
|
|
|
e51146 |
- ret = virDomainDestroy(vdp);
|
|
|
e51146 |
- if (ret < 0) {
|
|
|
e51146 |
- printf("virDomainDestroy() failed: %d/%d\n", ret, errno);
|
|
|
e51146 |
- free(domain_desc);
|
|
|
e51146 |
- virDomainFree(vdp);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- ret = wait_domain(vm_name, info->vp, 15);
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (ret) {
|
|
|
e51146 |
- syslog(LOG_NOTICE, "Domain %s still exists; fencing failed\n",
|
|
|
e51146 |
- vm_name);
|
|
|
e51146 |
- printf("Domain %s still exists; fencing failed\n", vm_name);
|
|
|
e51146 |
- if (domain_desc)
|
|
|
e51146 |
- free(domain_desc);
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (!domain_desc)
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
|
|
|
e51146 |
- /* 'on' is not a failure */
|
|
|
e51146 |
- ret = 0;
|
|
|
e51146 |
-
|
|
|
e51146 |
- dbg_printf(3, "[[ XML Domain Info ]]\n");
|
|
|
e51146 |
- dbg_printf(3, "%s\n[[ XML END ]]\n", domain_desc);
|
|
|
e51146 |
- dbg_printf(2, "Calling virDomainCreateLinux()...\n");
|
|
|
e51146 |
-
|
|
|
e51146 |
- nvdp = virDomainCreateLinux(info->vp, domain_desc, 0);
|
|
|
e51146 |
- if (nvdp == NULL) {
|
|
|
e51146 |
- /* More recent versions of libvirt or perhaps the
|
|
|
e51146 |
- * KVM back-end do not let you create a domain from
|
|
|
e51146 |
- * XML if there is already a defined domain description
|
|
|
e51146 |
- * with the same name that it knows about. You must
|
|
|
e51146 |
- * then call virDomainCreate() */
|
|
|
e51146 |
- dbg_printf(2, "Failed; Trying virDomainCreate()...\n");
|
|
|
e51146 |
- if (virDomainCreate(vdp) < 0) {
|
|
|
e51146 |
- syslog(LOG_NOTICE,
|
|
|
e51146 |
- "Could not restart %s\n",
|
|
|
e51146 |
- vm_name);
|
|
|
e51146 |
- dbg_printf(1, "Failed to recreate guest"
|
|
|
e51146 |
- " %s!\n", vm_name);
|
|
|
e51146 |
- }
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- free(domain_desc);
|
|
|
e51146 |
-
|
|
|
e51146 |
- return ret;
|
|
|
e51146 |
+ libvirt_validate_connections(info);
|
|
|
e51146 |
+ return vm_reboot(info->vp, info->vp_count, vm_name);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
@@ -400,22 +250,27 @@
|
|
|
e51146 |
virt_list_t *vl;
|
|
|
e51146 |
int x;
|
|
|
e51146 |
|
|
|
e51146 |
- dbg_printf(5, "%s\n", __FUNCTION__);
|
|
|
e51146 |
+ dbg_printf(5, "ENTER %s\n", __FUNCTION__);
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
|
|
|
e51146 |
- vl = vl_get(info->vp, 1);
|
|
|
e51146 |
+ libvirt_validate_connections(info);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ vl = vl_get(info->vp, info->vp_count, 1);
|
|
|
e51146 |
if (!vl)
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
|
|
|
e51146 |
for (x = 0; x < vl->vm_count; x++) {
|
|
|
e51146 |
- dbg_printf(10, "Sending %s\n", vl->vm_states[x].v_uuid);
|
|
|
e51146 |
callback(vl->vm_states[x].v_name,
|
|
|
e51146 |
- vl->vm_states[x].v_uuid,
|
|
|
e51146 |
- vl->vm_states[x].v_state.s_state, arg);
|
|
|
e51146 |
+ vl->vm_states[x].v_uuid,
|
|
|
e51146 |
+ vl->vm_states[x].v_state.s_state, arg);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(10, "[libvirt:HOSTLIST] Sent %s %s %d\n",
|
|
|
e51146 |
+ vl->vm_states[x].v_name,
|
|
|
e51146 |
+ vl->vm_states[x].v_uuid,
|
|
|
e51146 |
+ vl->vm_states[x].v_state.s_state);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
vl_free(vl);
|
|
|
e51146 |
-
|
|
|
e51146 |
return 0;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
@@ -423,46 +278,33 @@
|
|
|
e51146 |
static int
|
|
|
e51146 |
libvirt_init(backend_context_t *c, config_object_t *config)
|
|
|
e51146 |
{
|
|
|
e51146 |
- virConnectPtr vp;
|
|
|
e51146 |
char value[256];
|
|
|
e51146 |
struct libvirt_info *info = NULL;
|
|
|
e51146 |
- char *uri = NULL;
|
|
|
e51146 |
|
|
|
e51146 |
- info = malloc(sizeof(*info));
|
|
|
e51146 |
+ dbg_printf(5, "ENTER [%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ info = calloc(1, sizeof(*info));
|
|
|
e51146 |
if (!info)
|
|
|
e51146 |
return -1;
|
|
|
e51146 |
+ info->magic = MAGIC;
|
|
|
e51146 |
+ info->config = config;
|
|
|
e51146 |
|
|
|
e51146 |
- dbg_printf(5, "[%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__);
|
|
|
e51146 |
- memset(info, 0, sizeof(*info));
|
|
|
e51146 |
+ libvirt_init_libvirt_conf(info);
|
|
|
e51146 |
|
|
|
e51146 |
#ifdef _MODULE
|
|
|
e51146 |
- if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0)
|
|
|
e51146 |
+ if (sc_get(config, "fence_virtd/@debug", value, sizeof(value)) == 0)
|
|
|
e51146 |
dset(atoi(value));
|
|
|
e51146 |
#endif
|
|
|
e51146 |
|
|
|
e51146 |
- if (sc_get(config, "backends/libvirt/@uri",
|
|
|
e51146 |
- value, sizeof(value)) == 0) {
|
|
|
e51146 |
- uri = strdup(value);
|
|
|
e51146 |
- if (!uri) {
|
|
|
e51146 |
- free(info);
|
|
|
e51146 |
- return -1;
|
|
|
e51146 |
- }
|
|
|
e51146 |
- dbg_printf(1, "Using %s\n", uri);
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- /* We don't need to store the URI; we only use it once */
|
|
|
e51146 |
- vp = virConnectOpen(uri);
|
|
|
e51146 |
- if (!vp) {
|
|
|
e51146 |
- free(uri);
|
|
|
e51146 |
+ if (info->vp_count < 1) {
|
|
|
e51146 |
+ dbg_printf(1, "[libvirt:INIT] Could not connect to any hypervisors\n");
|
|
|
e51146 |
+ if (info->vp)
|
|
|
e51146 |
+ free(info->vp);
|
|
|
e51146 |
free(info);
|
|
|
e51146 |
return -1;
|
|
|
e51146 |
}
|
|
|
e51146 |
- free(uri);
|
|
|
e51146 |
-
|
|
|
e51146 |
- info->magic = MAGIC;
|
|
|
e51146 |
- info->vp = vp;
|
|
|
e51146 |
|
|
|
e51146 |
- *c = (void *)info;
|
|
|
e51146 |
+ *c = (void *) info;
|
|
|
e51146 |
return 0;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
@@ -471,16 +313,19 @@
|
|
|
e51146 |
libvirt_shutdown(backend_context_t c)
|
|
|
e51146 |
{
|
|
|
e51146 |
struct libvirt_info *info = (struct libvirt_info *)c;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+ int ret = 0;
|
|
|
e51146 |
|
|
|
e51146 |
VALIDATE(info);
|
|
|
e51146 |
|
|
|
e51146 |
- if (virConnectClose(info->vp) < 0) {
|
|
|
e51146 |
- free(info);
|
|
|
e51146 |
- return -errno;
|
|
|
e51146 |
+ for (i = 0 ; i < info->vp_count ; i++) {
|
|
|
e51146 |
+ if (virConnectClose(info->vp[i]) < 0)
|
|
|
e51146 |
+ ret = -errno;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
+ free(info->vp);
|
|
|
e51146 |
free(info);
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
+ return ret;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
diff -ur a/server/virt.c b/server/virt.c
|
|
|
e51146 |
--- a/server/virt.c 2014-06-23 15:56:09.000000000 -0400
|
|
|
e51146 |
+++ b/server/virt.c 2017-08-09 13:35:07.247875913 -0400
|
|
|
e51146 |
@@ -1,5 +1,5 @@
|
|
|
e51146 |
/*
|
|
|
e51146 |
- Copyright Red Hat, Inc. 2006
|
|
|
e51146 |
+ Copyright Red Hat, Inc. 2006-2017
|
|
|
e51146 |
|
|
|
e51146 |
This program is free software; you can redistribute it and/or modify it
|
|
|
e51146 |
under the terms of the GNU General Public License as published by the
|
|
|
e51146 |
@@ -16,7 +16,9 @@
|
|
|
e51146 |
Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
|
|
|
e51146 |
MA 02139, USA.
|
|
|
e51146 |
*/
|
|
|
e51146 |
+
|
|
|
e51146 |
#include <stdio.h>
|
|
|
e51146 |
+#include <unistd.h>
|
|
|
e51146 |
#include <sys/types.h>
|
|
|
e51146 |
#include <stdlib.h>
|
|
|
e51146 |
#include <libvirt/libvirt.h>
|
|
|
e51146 |
@@ -24,8 +26,11 @@
|
|
|
e51146 |
#include <malloc.h>
|
|
|
e51146 |
#include <stdint.h>
|
|
|
e51146 |
#include <errno.h>
|
|
|
e51146 |
-#include "virt.h"
|
|
|
e51146 |
+#include <syslog.h>
|
|
|
e51146 |
|
|
|
e51146 |
+#include "debug.h"
|
|
|
e51146 |
+#include "uuid-test.h"
|
|
|
e51146 |
+#include "virt.h"
|
|
|
e51146 |
|
|
|
e51146 |
static int
|
|
|
e51146 |
_compare_virt(const void *_left, const void *_right)
|
|
|
e51146 |
@@ -37,96 +42,98 @@
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
-virt_list_t *vl_get(virConnectPtr vp, int my_id)
|
|
|
e51146 |
-{
|
|
|
e51146 |
- virt_list_t *vl = NULL;
|
|
|
e51146 |
- int d_count, x, saved_errno;
|
|
|
e51146 |
- virDomainPtr *dom_list;
|
|
|
e51146 |
-
|
|
|
e51146 |
- errno = EINVAL;
|
|
|
e51146 |
- if (!vp)
|
|
|
e51146 |
- return NULL;
|
|
|
e51146 |
-
|
|
|
e51146 |
- d_count = virConnectListAllDomains(vp, &dom_list, 0);
|
|
|
e51146 |
- if (d_count <= 0)
|
|
|
e51146 |
- goto out_fail;
|
|
|
e51146 |
+static void
|
|
|
e51146 |
+_free_dom_list(virDomainPtr *dom_list, int len) {
|
|
|
e51146 |
+ int x;
|
|
|
e51146 |
|
|
|
e51146 |
- vl = malloc(sizeof(uint32_t) + sizeof(virt_state_t) * d_count);
|
|
|
e51146 |
- if (!vl)
|
|
|
e51146 |
- goto out_fail;
|
|
|
e51146 |
+ if (!dom_list || len <= 0)
|
|
|
e51146 |
+ return;
|
|
|
e51146 |
+ for (x = 0 ; x < len; x++)
|
|
|
e51146 |
+ virDomainFree(dom_list[x]);
|
|
|
e51146 |
|
|
|
e51146 |
- vl->vm_count = d_count;
|
|
|
e51146 |
+ free(dom_list);
|
|
|
e51146 |
+}
|
|
|
e51146 |
|
|
|
e51146 |
- /* Ok, we have the domain IDs - let's get their names and states */
|
|
|
e51146 |
- for (x = 0; x < d_count; x++) {
|
|
|
e51146 |
- char *d_name;
|
|
|
e51146 |
- virDomainInfo d_info;
|
|
|
e51146 |
- char d_uuid[MAX_DOMAINNAME_LENGTH];
|
|
|
e51146 |
- virDomainPtr dom = dom_list[x];
|
|
|
e51146 |
|
|
|
e51146 |
- if (!(d_name = (char *)virDomainGetName(dom)))
|
|
|
e51146 |
- goto out_fail;
|
|
|
e51146 |
+virt_list_t *vl_get(virConnectPtr *vp, int vp_count, int my_id)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ virt_list_t *vl = NULL;
|
|
|
e51146 |
+ int d_count = 0;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
|
|
|
e51146 |
- if (virDomainGetUUIDString(dom, d_uuid) != 0)
|
|
|
e51146 |
- goto out_fail;
|
|
|
e51146 |
+ errno = EINVAL;
|
|
|
e51146 |
+ if (!vp || vp_count < 1)
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
|
|
|
e51146 |
- if (virDomainGetInfo(dom, &d_info) < 0)
|
|
|
e51146 |
- goto out_fail;
|
|
|
e51146 |
+ for (i = 0 ; i < vp_count ; i++) {
|
|
|
e51146 |
+ int x;
|
|
|
e51146 |
+ virDomainPtr *dom_list;
|
|
|
e51146 |
+ virt_list_t *new_vl;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ int ret = virConnectListAllDomains(vp[i], &dom_list, 0);
|
|
|
e51146 |
+ if (ret == 0)
|
|
|
e51146 |
+ continue;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret < 0) {
|
|
|
e51146 |
+ int saved_errno = errno;
|
|
|
e51146 |
+ dbg_printf(2, "Error: virConnectListAllDomains: %d %d\n",
|
|
|
e51146 |
+ ret, saved_errno);
|
|
|
e51146 |
+ if (vl)
|
|
|
e51146 |
+ free(vl);
|
|
|
e51146 |
+ errno = saved_errno;
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ d_count += ret;
|
|
|
e51146 |
+ new_vl = realloc(vl, sizeof(uint32_t) + sizeof(virt_state_t) * d_count);
|
|
|
e51146 |
+ if (!new_vl) {
|
|
|
e51146 |
+ _free_dom_list(dom_list, ret);
|
|
|
e51146 |
+ free(vl);
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ vl = new_vl;
|
|
|
e51146 |
+ vl->vm_count = d_count;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ /* Ok, we have the domain IDs - let's get their names and states */
|
|
|
e51146 |
+ for (x = 0; x < ret; x++) {
|
|
|
e51146 |
+ char *d_name;
|
|
|
e51146 |
+ virDomainInfo d_info;
|
|
|
e51146 |
+ char d_uuid[MAX_DOMAINNAME_LENGTH];
|
|
|
e51146 |
+ virDomainPtr dom = dom_list[x];
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!(d_name = (char *)virDomainGetName(dom))) {
|
|
|
e51146 |
+ _free_dom_list(dom_list, ret);
|
|
|
e51146 |
+ free(vl);
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetUUIDString(dom, d_uuid) != 0) {
|
|
|
e51146 |
+ _free_dom_list(dom_list, ret);
|
|
|
e51146 |
+ free(vl);
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetInfo(dom, &d_info) < 0) {
|
|
|
e51146 |
+ _free_dom_list(dom_list, ret);
|
|
|
e51146 |
+ free(vl);
|
|
|
e51146 |
+ return NULL;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ /* Store the name & state */
|
|
|
e51146 |
+ strncpy(vl->vm_states[x].v_name, d_name, MAX_DOMAINNAME_LENGTH);
|
|
|
e51146 |
+ strncpy(vl->vm_states[x].v_uuid, d_uuid, MAX_DOMAINNAME_LENGTH);
|
|
|
e51146 |
+ vl->vm_states[x].v_state.s_state = d_info.state;
|
|
|
e51146 |
+ vl->vm_states[x].v_state.s_owner = my_id;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
|
|
|
e51146 |
- /* Store the name & state */
|
|
|
e51146 |
- strncpy(vl->vm_states[x].v_name, d_name, MAX_DOMAINNAME_LENGTH);
|
|
|
e51146 |
- strncpy(vl->vm_states[x].v_uuid, d_uuid, MAX_DOMAINNAME_LENGTH);
|
|
|
e51146 |
- vl->vm_states[x].v_state.s_state = d_info.state;
|
|
|
e51146 |
- vl->vm_states[x].v_state.s_owner = my_id;
|
|
|
e51146 |
+ _free_dom_list(dom_list, ret);
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
- for (x = 0 ; x < d_count; x++)
|
|
|
e51146 |
- virDomainFree(dom_list[x]);
|
|
|
e51146 |
- free(dom_list);
|
|
|
e51146 |
-
|
|
|
e51146 |
/* We have all the locally running domains & states now */
|
|
|
e51146 |
/* Sort */
|
|
|
e51146 |
qsort(&vl->vm_states[0], vl->vm_count, sizeof(vl->vm_states[0]),
|
|
|
e51146 |
_compare_virt);
|
|
|
e51146 |
return vl;
|
|
|
e51146 |
-
|
|
|
e51146 |
-out_fail:
|
|
|
e51146 |
- saved_errno = errno;
|
|
|
e51146 |
- for (x = 0 ; x < d_count; x++)
|
|
|
e51146 |
- virDomainFree(dom_list[x]);
|
|
|
e51146 |
- free(dom_list);
|
|
|
e51146 |
-
|
|
|
e51146 |
- if (vl)
|
|
|
e51146 |
- free(vl);
|
|
|
e51146 |
- errno = saved_errno;
|
|
|
e51146 |
- return NULL;
|
|
|
e51146 |
-}
|
|
|
e51146 |
-
|
|
|
e51146 |
-
|
|
|
e51146 |
-/* Returns 0 if equal, nonzero if not */
|
|
|
e51146 |
-int
|
|
|
e51146 |
-vl_cmp(virt_list_t *left, virt_list_t *right)
|
|
|
e51146 |
-{
|
|
|
e51146 |
- int x;
|
|
|
e51146 |
-
|
|
|
e51146 |
- /* Quick checks */
|
|
|
e51146 |
- if (!left->vm_count && !right->vm_count)
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- if (left->vm_count != right->vm_count)
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
-
|
|
|
e51146 |
- for (x = 0; x < left->vm_count; x++) {
|
|
|
e51146 |
- if (strcmp(left->vm_states[x].v_name,
|
|
|
e51146 |
- right->vm_states[x].v_name))
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- /*
|
|
|
e51146 |
- if (left->vm_states[x].v_state.s_state !=
|
|
|
e51146 |
- right->vm_states[x].v_state.s_state)
|
|
|
e51146 |
- return 1;
|
|
|
e51146 |
- */
|
|
|
e51146 |
- }
|
|
|
e51146 |
-
|
|
|
e51146 |
- return 0;
|
|
|
e51146 |
}
|
|
|
e51146 |
|
|
|
e51146 |
|
|
|
e51146 |
@@ -192,3 +199,333 @@
|
|
|
e51146 |
{
|
|
|
e51146 |
free(old);
|
|
|
e51146 |
}
|
|
|
e51146 |
+
|
|
|
e51146 |
+
|
|
|
e51146 |
+static inline int
|
|
|
e51146 |
+wait_domain(const char *vm_name, virConnectPtr vp, int timeout)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ int tries = 0;
|
|
|
e51146 |
+ int response = 1;
|
|
|
e51146 |
+ int ret;
|
|
|
e51146 |
+ virDomainPtr vdp;
|
|
|
e51146 |
+ virDomainInfo vdi;
|
|
|
e51146 |
+ int uuid_check;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ uuid_check = is_uuid(vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (uuid_check) {
|
|
|
e51146 |
+ vdp = virDomainLookupByUUIDString(vp, (const char *)vm_name);
|
|
|
e51146 |
+ } else {
|
|
|
e51146 |
+ vdp = virDomainLookupByName(vp, vm_name);
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ if (!vdp)
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ /* Check domain liveliness. If the domain is still here,
|
|
|
e51146 |
+ we return failure, and the client must then retry */
|
|
|
e51146 |
+ /* XXX On the xen 3.0.4 API, we will be able to guarantee
|
|
|
e51146 |
+ synchronous virDomainDestroy, so this check will not
|
|
|
e51146 |
+ be necessary */
|
|
|
e51146 |
+ do {
|
|
|
e51146 |
+ if (++tries > timeout)
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ sleep(1);
|
|
|
e51146 |
+ if (uuid_check) {
|
|
|
e51146 |
+ vdp = virDomainLookupByUUIDString(vp, (const char *)vm_name);
|
|
|
e51146 |
+ } else {
|
|
|
e51146 |
+ vdp = virDomainLookupByName(vp, vm_name);
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ if (!vdp) {
|
|
|
e51146 |
+ dbg_printf(2, "Domain no longer exists\n");
|
|
|
e51146 |
+ response = 0;
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ memset(&vdi, 0, sizeof(vdi));
|
|
|
e51146 |
+ ret = virDomainGetInfo(vdp, &vdi;;
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ if (ret < 0)
|
|
|
e51146 |
+ continue;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (vdi.state == VIR_DOMAIN_SHUTOFF) {
|
|
|
e51146 |
+ dbg_printf(2, "Domain has been shut off\n");
|
|
|
e51146 |
+ response = 0;
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(4, "Domain still exists (state %d) after %d seconds\n",
|
|
|
e51146 |
+ vdi.state, tries);
|
|
|
e51146 |
+ } while (1);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ return response;
|
|
|
e51146 |
+}
|
|
|
e51146 |
+
|
|
|
e51146 |
+
|
|
|
e51146 |
+int
|
|
|
e51146 |
+vm_off(virConnectPtr *vp, int vp_count, const char *vm_name)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ virDomainPtr vdp = NULL;
|
|
|
e51146 |
+ virDomainInfo vdi;
|
|
|
e51146 |
+ virDomainPtr (*virt_lookup_fn)(virConnectPtr, const char *);
|
|
|
e51146 |
+ int ret = -1;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (is_uuid(vm_name))
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByUUIDString;
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByName;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ for (i = 0 ; i < vp_count ; i++) {
|
|
|
e51146 |
+ vdp = virt_lookup_fn(vp[i], vm_name);
|
|
|
e51146 |
+ if (vdp)
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!vdp) {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:OFF] Domain %s does not exist\n", vm_name);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetInfo(vdp, &vdi) == 0 && vdi.state == VIR_DOMAIN_SHUTOFF)
|
|
|
e51146 |
+ {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:OFF] Nothing to do - "
|
|
|
e51146 |
+ "domain %s is already off\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Destroying domain %s\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:OFF] Calling virDomainDestroy for %s\n", vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ ret = virDomainDestroy(vdp);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret < 0) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE,
|
|
|
e51146 |
+ "Failed to destroy domain %s: %d\n", vm_name, ret);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:OFF] Failed to destroy domain: %s %d\n",
|
|
|
e51146 |
+ vm_name, ret);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Domain %s still exists; fencing failed\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ dbg_printf(2,
|
|
|
e51146 |
+ "[virt:OFF] Domain %s still exists; fencing failed\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(2, "[virt:OFF] Success for %s\n", vm_name);
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+}
|
|
|
e51146 |
+
|
|
|
e51146 |
+
|
|
|
e51146 |
+int
|
|
|
e51146 |
+vm_on(virConnectPtr *vp, int vp_count, const char *vm_name)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ virDomainPtr vdp = NULL;
|
|
|
e51146 |
+ virDomainInfo vdi;
|
|
|
e51146 |
+ virDomainPtr (*virt_lookup_fn)(virConnectPtr, const char *);
|
|
|
e51146 |
+ int ret = -1;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (is_uuid(vm_name))
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByUUIDString;
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByName;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ for (i = 0 ; i < vp_count ; i++) {
|
|
|
e51146 |
+ vdp = virt_lookup_fn(vp[i], vm_name);
|
|
|
e51146 |
+ if (vdp)
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!vdp) {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:ON] Domain %s does not exist\n", vm_name);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetInfo(vdp, &vdi) == 0 && vdi.state != VIR_DOMAIN_SHUTOFF) {
|
|
|
e51146 |
+ dbg_printf(2, "Nothing to do - domain %s is already running\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Starting domain %s\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:ON] Calling virDomainCreate for %s\n", vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ ret = virDomainCreate(vdp);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret < 0) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Failed to start domain %s: %d\n", vm_name, ret);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:ON] virDomainCreate() failed for %s: %d\n",
|
|
|
e51146 |
+ vm_name, ret);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Domain %s did not start\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:ON] Domain %s did not start\n", vm_name);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Domain %s started\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(2, "[virt:ON] Success for %s\n", vm_name);
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+}
|
|
|
e51146 |
+
|
|
|
e51146 |
+
|
|
|
e51146 |
+int
|
|
|
e51146 |
+vm_status(virConnectPtr *vp, int vp_count, const char *vm_name)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ virDomainPtr vdp = NULL;
|
|
|
e51146 |
+ virDomainInfo vdi;
|
|
|
e51146 |
+ int ret = 0;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+ virDomainPtr (*virt_lookup_fn)(virConnectPtr, const char *);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (is_uuid(vm_name))
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByUUIDString;
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByName;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ for (i = 0 ; i < vp_count ; i++) {
|
|
|
e51146 |
+ vdp = virt_lookup_fn(vp[i], vm_name);
|
|
|
e51146 |
+ if (vdp)
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!vdp) {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:STATUS] Unknown VM %s - return OFF\n", vm_name);
|
|
|
e51146 |
+ return RESP_OFF;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetInfo(vdp, &vdi) == 0 && vdi.state == VIR_DOMAIN_SHUTOFF) {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:STATUS] VM %s is OFF\n", vm_name);
|
|
|
e51146 |
+ ret = RESP_OFF;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (vdp)
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return ret;
|
|
|
e51146 |
+}
|
|
|
e51146 |
+
|
|
|
e51146 |
+
|
|
|
e51146 |
+int
|
|
|
e51146 |
+vm_reboot(virConnectPtr *vp, int vp_count, const char *vm_name)
|
|
|
e51146 |
+{
|
|
|
e51146 |
+ virDomainPtr vdp = NULL, nvdp;
|
|
|
e51146 |
+ virDomainInfo vdi;
|
|
|
e51146 |
+ char *domain_desc;
|
|
|
e51146 |
+ virConnectPtr vcp = NULL;
|
|
|
e51146 |
+ virDomainPtr (*virt_lookup_fn)(virConnectPtr, const char *);
|
|
|
e51146 |
+ int ret;
|
|
|
e51146 |
+ int i;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (is_uuid(vm_name))
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByUUIDString;
|
|
|
e51146 |
+ else
|
|
|
e51146 |
+ virt_lookup_fn = virDomainLookupByName;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ for (i = 0 ; i < vp_count ; i++) {
|
|
|
e51146 |
+ vdp = virt_lookup_fn(vp[i], vm_name);
|
|
|
e51146 |
+ if (vdp) {
|
|
|
e51146 |
+ vcp = vp[i];
|
|
|
e51146 |
+ break;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!vdp || !vcp) {
|
|
|
e51146 |
+ dbg_printf(2,
|
|
|
e51146 |
+ "[virt:REBOOT] Nothing to do - domain %s does not exist\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainGetInfo(vdp, &vdi) == 0 && vdi.state == VIR_DOMAIN_SHUTOFF) {
|
|
|
e51146 |
+ dbg_printf(2, "[virt:REBOOT] Nothing to do - domain %s is off\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Rebooting domain %s\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(5, "[virt:REBOOT] Rebooting domain %s...\n", vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ domain_desc = virDomainGetXMLDesc(vdp, 0);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!domain_desc) {
|
|
|
e51146 |
+ dbg_printf(5, "[virt:REBOOT] Failed getting domain description "
|
|
|
e51146 |
+ "from libvirt for %s...\n", vm_name);
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(2, "[virt:REBOOT] Calling virDomainDestroy(%p) for %s\n",
|
|
|
e51146 |
+ vdp, vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ ret = virDomainDestroy(vdp);
|
|
|
e51146 |
+ if (ret < 0) {
|
|
|
e51146 |
+ dbg_printf(2,
|
|
|
e51146 |
+ "[virt:REBOOT] virDomainDestroy() failed for %s: %d/%d\n",
|
|
|
e51146 |
+ vm_name, ret, errno);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (domain_desc)
|
|
|
e51146 |
+ free(domain_desc);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ ret = wait_domain(vm_name, vcp, 15);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (ret) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Domain %s still exists; fencing failed\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(2,
|
|
|
e51146 |
+ "[virt:REBOOT] Domain %s still exists; fencing failed\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (domain_desc)
|
|
|
e51146 |
+ free(domain_desc);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return 1;
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (!domain_desc)
|
|
|
e51146 |
+ return 0;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ /* 'on' is not a failure */
|
|
|
e51146 |
+ ret = 0;
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(3, "[[ XML Domain Info ]]\n");
|
|
|
e51146 |
+ dbg_printf(3, "%s\n[[ XML END ]]\n", domain_desc);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ dbg_printf(2, "[virt:REBOOT] Calling virDomainCreateLinux() for %s\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ nvdp = virDomainCreateLinux(vcp, domain_desc, 0);
|
|
|
e51146 |
+ if (nvdp == NULL) {
|
|
|
e51146 |
+ /* More recent versions of libvirt or perhaps the
|
|
|
e51146 |
+ * KVM back-end do not let you create a domain from
|
|
|
e51146 |
+ * XML if there is already a defined domain description
|
|
|
e51146 |
+ * with the same name that it knows about. You must
|
|
|
e51146 |
+ * then call virDomainCreate() */
|
|
|
e51146 |
+ dbg_printf(2,
|
|
|
e51146 |
+ "[virt:REBOOT] virDomainCreateLinux() failed for %s; "
|
|
|
e51146 |
+ "Trying virDomainCreate()\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+
|
|
|
e51146 |
+ if (virDomainCreate(vdp) < 0) {
|
|
|
e51146 |
+ syslog(LOG_NOTICE, "Could not restart %s\n", vm_name);
|
|
|
e51146 |
+ dbg_printf(1, "[virt:REBOOT] Failed to recreate guest %s!\n",
|
|
|
e51146 |
+ vm_name);
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+ }
|
|
|
e51146 |
+
|
|
|
e51146 |
+ free(domain_desc);
|
|
|
e51146 |
+ virDomainFree(vdp);
|
|
|
e51146 |
+ return ret;
|
|
|
e51146 |
+}
|
|
|
e51146 |
diff -ur a/server/virt.h b/server/virt.h
|
|
|
e51146 |
--- a/server/virt.h 2014-06-23 15:56:09.000000000 -0400
|
|
|
e51146 |
+++ b/server/virt.h 2017-08-09 13:30:40.709689288 -0400
|
|
|
e51146 |
@@ -1,5 +1,5 @@
|
|
|
e51146 |
/*
|
|
|
e51146 |
- Copyright Red Hat, Inc. 2006
|
|
|
e51146 |
+ Copyright Red Hat, Inc. 2006-2017
|
|
|
e51146 |
|
|
|
e51146 |
This program is free software; you can redistribute it and/or modify it
|
|
|
e51146 |
under the terms of the GNU General Public License as published by the
|
|
|
e51146 |
@@ -16,11 +16,13 @@
|
|
|
e51146 |
Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
|
|
|
e51146 |
MA 02139, USA.
|
|
|
e51146 |
*/
|
|
|
e51146 |
+
|
|
|
e51146 |
#ifndef _VIRT_H
|
|
|
e51146 |
#define _VIRT_H
|
|
|
e51146 |
-#include <libvirt/libvirt.h>
|
|
|
e51146 |
+
|
|
|
e51146 |
#include <stdint.h>
|
|
|
e51146 |
#include <netinet/in.h>
|
|
|
e51146 |
+#include <libvirt/libvirt.h>
|
|
|
e51146 |
|
|
|
e51146 |
#include "xvm.h"
|
|
|
e51146 |
|
|
|
e51146 |
@@ -59,15 +61,16 @@
|
|
|
e51146 |
virt_state_t vm_states[0];
|
|
|
e51146 |
} virt_list_t;
|
|
|
e51146 |
|
|
|
e51146 |
-virt_list_t *vl_get(virConnectPtr vp, int my_id);
|
|
|
e51146 |
-
|
|
|
e51146 |
-int vl_cmp(virt_list_t *left, virt_list_t *right);
|
|
|
e51146 |
-
|
|
|
e51146 |
+virt_list_t *vl_get(virConnectPtr *vp, int vp_count, int my_id);
|
|
|
e51146 |
void vl_print(virt_list_t *vl);
|
|
|
e51146 |
void vl_free(virt_list_t *old);
|
|
|
e51146 |
-virt_state_t * vl_find_uuid(virt_list_t *vl, const char *name);
|
|
|
e51146 |
-virt_state_t * vl_find_name(virt_list_t *vl, const char *name);
|
|
|
e51146 |
+virt_state_t *vl_find_uuid(virt_list_t *vl, const char *name);
|
|
|
e51146 |
+virt_state_t *vl_find_name(virt_list_t *vl, const char *name);
|
|
|
e51146 |
|
|
|
e51146 |
+int vm_off(virConnectPtr *vp, int vp_count, const char *vm_name);
|
|
|
e51146 |
+int vm_on(virConnectPtr *vp, int vp_count, const char *vm_name);
|
|
|
e51146 |
+int vm_status(virConnectPtr *vp, int vp_count, const char *vm_name);
|
|
|
e51146 |
+int vm_reboot(virConnectPtr *vp, int vp_count, const char *vm_name);
|
|
|
e51146 |
|
|
|
e51146 |
typedef void ckpt_handle;
|
|
|
e51146 |
int ckpt_read(void *hp, const char *secid, void *buf, size_t maxlen);
|