]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: implement domainGetAutostart
authorMatt Coleman <mcoleman@datto.com>
Mon, 5 Oct 2020 16:20:14 +0000 (12:20 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 9 Oct 2020 07:27:48 +0000 (09:27 +0200)
Co-authored-by: Sri Ramanujam <sramanujam@datto.com>
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hyperv/hyperv_driver.c

index 528c826e16301d06086b1218e471715a78b6dbd8..dcde469442b84c792e6c876a037eaf0f56c0cf88 100644 (file)
@@ -1274,6 +1274,45 @@ hypervDomainCreate(virDomainPtr domain)
 
 
 
+static int
+hypervDomainGetAutostart(virDomainPtr domain, int *autostart)
+{
+    int result = -1;
+    char uuid_string[VIR_UUID_STRING_BUFLEN];
+    hypervPrivate *priv = domain->conn->privateData;
+    g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
+    Msvm_VirtualSystemGlobalSettingData *vsgsd = NULL;
+    Msvm_VirtualSystemSettingData *vssd = NULL;
+
+    virUUIDFormat(domain->uuid, uuid_string);
+
+    if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
+        virBufferEscapeSQL(&query,
+                           MSVM_VIRTUALSYSTEMGLOBALSETTINGDATA_WQL_SELECT
+                           "WHERE SystemName = \"%s\"", uuid_string);
+
+        if (hypervGetWmiClass(Msvm_VirtualSystemGlobalSettingData, &vsgsd) < 0)
+            goto cleanup;
+
+        *autostart = vsgsd->data.common->AutomaticStartupAction == 2;
+        result = 0;
+    } else {
+        if (hypervGetVSSDFromUUID(priv, uuid_string, &vssd) < 0)
+            goto cleanup;
+
+        *autostart = vssd->data.v2->AutomaticStartupAction == 4;
+        result = 0;
+    }
+
+    cleanup:
+    hypervFreeObject(priv, (hypervObject *) vsgsd);
+    hypervFreeObject(priv, (hypervObject *) vssd);
+
+    return result;
+}
+
+
+
 static int
 hypervConnectIsEncrypted(virConnectPtr conn)
 {
@@ -1824,6 +1863,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
     .connectNumOfDefinedDomains = hypervConnectNumOfDefinedDomains, /* 0.9.5 */
     .domainCreate = hypervDomainCreate, /* 0.9.5 */
     .domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
+    .domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
     .connectIsEncrypted = hypervConnectIsEncrypted, /* 0.9.5 */
     .connectIsSecure = hypervConnectIsSecure, /* 0.9.5 */
     .domainIsActive = hypervDomainIsActive, /* 0.9.5 */