# HG changeset patch
# User Sharad Mishra <snmishra(a)us.ibm.com>
# Date 1298472523 28800
# Node ID 219b9e147e611772e9f540800943653ce73acdfd
# Parent f3d3d546da029d62d3e5bceec52152a010e2e4b2
Set/Reset VM autostart.
Support for VM autostart was added few months back, but a defect was opened against
libvirt-cim that autostart can only be set during VM creation and cannot be changed later.
This patch fixes that issue.
Signed-off-by: Sharad Mishra <snmishra(a)us.ibm.com>
diff -r f3d3d546da02 -r 219b9e147e61 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Thu Feb 17 12:00:51 2011 -0800
+++ b/libxkutil/device_parsing.c Wed Feb 23 06:48:43 2011 -0800
@@ -1086,12 +1086,17 @@
{
char *xml;
int ret;
+ int start;
xml = virDomainGetXMLDesc(dom, 0);
if (xml == NULL)
return 0;
ret = get_dominfo_from_xml(xml, dominfo);
+ if (virDomainGetAutostart(dom, &start) != 0)
+ return 0;
+
+ (*dominfo)->autostrt = start;
free(xml);
diff -r f3d3d546da02 -r 219b9e147e61 libxkutil/device_parsing.h
--- a/libxkutil/device_parsing.h Thu Feb 17 12:00:51 2011 -0800
+++ b/libxkutil/device_parsing.h Wed Feb 23 06:48:43 2011 -0800
@@ -136,13 +136,13 @@
char *name;
char *typestr; /*xen, kvm, etc */
char *uuid;
- int autostart;
char *bootloader;
char *bootloader_args;
char *clock;
bool acpi;
bool apic;
bool pae;
+ int autostrt;
union {
struct pv_os_info pv;
diff -r f3d3d546da02 -r 219b9e147e61 schema/ComputerSystem.mof
--- a/schema/ComputerSystem.mof Thu Feb 17 12:00:51 2011 -0800
+++ b/schema/ComputerSystem.mof Wed Feb 23 06:48:43 2011 -0800
@@ -10,9 +10,6 @@
[Description("UUID assigned to this DomU.")]
string UUID;
- [Description("Flag to set VM autostart.")]
- string autoStart;
-
};
[Description (
@@ -26,9 +23,6 @@
[Description("UUID assigned to this virtual machine.")]
string UUID;
- [Description("Flag to set VM autostart.")]
- string autoStart;
-
};
[Description (
@@ -42,8 +36,5 @@
[Description("UUID assigned to this virtual machine.")]
string UUID;
- [Description("Flag to set VM autostart.")]
- string autoStart;
-
};
diff -r f3d3d546da02 -r 219b9e147e61 schema/Virt_VSSD.mof
--- a/schema/Virt_VSSD.mof Thu Feb 17 12:00:51 2011 -0800
+++ b/schema/Virt_VSSD.mof Wed Feb 23 06:48:43 2011 -0800
@@ -24,4 +24,7 @@
[Description ("Flag to determine whether this guest has pae enabled")]
boolean EnablePAE;
+ [Description ("Flag to determine whether this guest has to be autostarted on
reboot")]
+ uint16 AutoStart;
+
};
diff -r f3d3d546da02 -r 219b9e147e61 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Thu Feb 17 12:00:51 2011 -0800
+++ b/src/Virt_ComputerSystem.c Wed Feb 23 06:48:43 2011 -0800
@@ -65,33 +65,6 @@
return 1;
}
-/* Set the "autoStart" property of an instance from a domain */
-static int set_autostart_from_dom(virDomainPtr dom,
- CMPIInstance *instance,
- struct domain *dominfo)
-{
- int autoFlag = 0;
- char autovalue[16];
-
- if((virDomainGetAutostart(dom, &autoFlag)) == -1) {
- CU_DEBUG("Could not read autostart value from xml");
- } else {
- CU_DEBUG("Autostart for current domain is set to %d",
- autoFlag);
- dominfo->autostart = autoFlag;
- }
-
- if(autoFlag)
- strcpy(autovalue, "enable");
- else
- strcpy(autovalue, "disable");
-
- CMSetProperty(instance, "autoStart",
- (CMPIValue *)autovalue, CMPI_chars);
-
- return 1;
-}
-
/* Set the "UUID" property of an instance from a domain */
static int set_uuid_from_dom(virDomainPtr dom,
CMPIInstance *instance,
@@ -526,15 +499,6 @@
goto out;
}
- if (!set_autostart_from_dom(dom, instance, domain)) {
- virt_set_status(broker, &s,
- CMPI_RC_ERR_FAILED,
- virDomainGetConnect(dom),
- "Unable to get domain autostart flag");
-
- goto out;
- }
-
if (!set_uuid_from_dom(dom, instance, &uuid)) {
virt_set_status(broker, &s,
CMPI_RC_ERR_FAILED,
diff -r f3d3d546da02 -r 219b9e147e61 src/Virt_VSSD.c
--- a/src/Virt_VSSD.c Thu Feb 17 12:00:51 2011 -0800
+++ b/src/Virt_VSSD.c Wed Feb 23 06:48:43 2011 -0800
@@ -220,6 +220,9 @@
CMSetProperty(inst, "EnablePAE",
(CMPIValue *)&dominfo->pae, CMPI_boolean);
+ CMSetProperty(inst, "AutoStart",
+ (CMPIValue *)&dominfo->autostrt, CMPI_uint16);
+
if (dominfo->clock != NULL) {
uint16_t clock = VSSD_CLOCK_UTC;
diff -r f3d3d546da02 -r 219b9e147e61 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c Thu Feb 17 12:00:51 2011 -0800
+++ b/src/Virt_VirtualSystemManagementService.c Wed Feb 23 06:48:43 2011 -0800
@@ -1374,8 +1374,6 @@
virDomainPtr dom;
const char *name;
CMPIInstance *inst = NULL;
- const char *autoStartFlag = NULL;
- int autoflag;
conn = connect_by_classname(_BROKER, CLASSNAME(ref), s);
if (conn == NULL) {
@@ -1404,19 +1402,6 @@
goto out;
}
- if (inst != NULL) {
- if (cu_get_str_prop(inst, "autoStart",
- &autoStartFlag) != CMPI_RC_OK)
- autoStartFlag = strdup("disable");
-
- if (STREQ(autoStartFlag, "enable"))
- autoflag = 1;
- else
- autoflag = 0;
- if((virDomainSetAutostart(dom, autoflag)) == -1)
- CU_DEBUG("Failed to set autostart flag.");
- }
-
out:
virDomainFree(dom);
virConnectClose(conn);
@@ -1663,6 +1648,74 @@
}
+static CMPIStatus set_autostart(CMPIInstance *vssd,
+ const CMPIObjectPath *ref,
+ virDomainPtr dom)
+{
+ CMPIStatus s;
+ const char *name = NULL;
+ CMPIrc ret;
+ virConnectPtr conn = NULL;
+ virDomainPtr inst_dom = NULL;
+ uint16_t val = 0;
+ int i = 0;
+
+ CU_DEBUG("Enter set_autostart");
+ ret = cu_get_str_prop(vssd, "VirtualSystemIdentifier", &name);
+ if (ret != CMPI_RC_OK) {
+ CU_DEBUG("Missing VirtualSystemIdentifier");
+ cu_statusf(_BROKER, &s,
+ ret,
+ "Missing VirtualSystemIdentifier");
+ goto out;
+ }
+
+ conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
+ if (conn == NULL) {
+ CU_DEBUG("Failed to connect");
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to connect");
+ goto out;
+ }
+
+ inst_dom = virDomainLookupByName(conn, name);
+ if (inst_dom == NULL) {
+ CU_DEBUG("reference domain '%s' does not exist",
name);
+ virt_set_status(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ conn,
+ "Referenced domain `%s' does not exist",
name);
+ goto out;
+ }
+
+ if (cu_get_u16_prop(vssd, "AutoStart", &val) != CMPI_RC_OK) {
+ if (dom != NULL) {
+ /* Read the current domain's autostart setting.
+ Since the user did not specify any new
+ autostart, the updated VM will use the same
+ autostart setting as used before this
+ update. */
+ if (virDomainGetAutostart(dom, &i) != 0)
+ i = 0;
+ }
+ }
+ else
+ i = val;
+ CU_DEBUG("setting VM's autostart to %d", i);
+ if (virDomainSetAutostart(inst_dom, i) == -1) {
+ CU_DEBUG("Failed to set autostart");
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to set autostart");
+ }
+
+ out:
+ virDomainFree(inst_dom);
+ virConnectClose(conn);
+ return s;
+}
+
static CMPIInstance *create_system(const CMPIContext *context,
CMPIInstance *vssd,
CMPIArray *resources,
@@ -1673,15 +1726,13 @@
CMPIInstance *inst = NULL;
char *xml = NULL;
const char *msg = NULL;
- virConnectPtr conn = NULL;
- virDomainPtr dom = NULL;
struct inst_list list;
const char *props[] = {NULL};
-
struct domain *domain = NULL;
inst_list_init(&list);
+ CU_DEBUG("Enter create_system");
if (refconf != NULL) {
*s = get_reference_domain(&domain, ref, refconf);
if (s->rc != CMPI_RC_OK)
@@ -1731,6 +1782,7 @@
inst = connect_and_create(xml, ref, s);
if (inst != NULL) {
update_dominfo(domain, CLASSNAME(ref));
+ set_autostart(vssd, ref, NULL);
*s = enum_rasds(_BROKER,
ref,
@@ -1755,8 +1807,6 @@
out:
cleanup_dominfo(&domain);
free(xml);
- virDomainFree(dom);
- virConnectClose(conn);
inst_list_free(&list);
return inst;
@@ -1943,6 +1993,7 @@
char *xml = NULL;
const char *uuid = NULL;
+ CU_DEBUG("Enter update_system_settings");
ret = cu_get_str_prop(vssd, "VirtualSystemIdentifier", &name);
if (ret != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
@@ -2002,6 +2053,7 @@
}
if (s.rc == CMPI_RC_OK) {
+ set_autostart(vssd, ref, dom);
trigger_indication(context,
"ComputerSystemModifiedIndication",
ref);