]> xenbits.xensource.com Git - libvirt.git/commitdiff
lib: introduce virDomainSetLifecycleAction() API
authorPavel Hrdina <phrdina@redhat.com>
Wed, 11 Oct 2017 12:02:01 +0000 (14:02 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 19 Oct 2017 09:52:26 +0000 (11:52 +0200)
Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
docs/formatdomain.html.in
include/libvirt/libvirt-domain.h
src/conf/domain_conf.h
src/driver-hypervisor.h
src/libvirt-domain.c
src/libvirt_public.syms
src/remote/remote_driver.c
src/remote/remote_protocol.x
src/remote_protocol-structs

index b7e145e0fa1ca8ae27cba65a5e50c0bfd0fad7bd..58d86f953569b97b8e5b534385f36f604aee1bb1 100644 (file)
         domain will be restarted with the same configuration</dd>
     </dl>
 
+    <p>
+      <span class="since">Since 3.9.0</span>, the lifecycle events can
+      be configured via the
+      <a href="html/libvirt-libvirt-domain.html#virDomainSetLifecycleAction">
+        <code>virDomainSetLifecycleAction</code></a> API.
+    </p>
+
     <p>
       The <code>on_lockfailure</code> element (<span class="since">since
       1.0.0</span>) may be used to configure what action should be
index 9fb94a9837df071336cfecf040cb4d1b2cfd98a4..4048acf38aafd7f137d5efa900f00825c9ba56fb 100644 (file)
@@ -4728,4 +4728,32 @@ int virDomainSetBlockThreshold(virDomainPtr domain,
                                unsigned long long threshold,
                                unsigned int flags);
 
+typedef enum {
+    VIR_DOMAIN_LIFECYCLE_POWEROFF = 0,
+    VIR_DOMAIN_LIFECYCLE_REBOOT = 1,
+    VIR_DOMAIN_LIFECYCLE_CRASH = 2,
+
+# ifdef VIR_ENUM_SENTINELS
+    VIR_DOMAIN_LIFECYCLE_LAST
+# endif
+} virDomainLifecycle;
+
+typedef enum {
+    VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY = 0,
+    VIR_DOMAIN_LIFECYCLE_ACTION_RESTART = 1,
+    VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME = 2,
+    VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE = 3,
+    VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY = 4,
+    VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART = 5,
+
+# ifdef VIR_ENUM_SENTINELS
+    VIR_DOMAIN_LIFECYCLE_ACTION_LAST
+# endif
+} virDomainLifecycleAction;
+
+int virDomainSetLifecycleAction(virDomainPtr domain,
+                                unsigned int type,
+                                unsigned int action,
+                                unsigned int flags);
+
 #endif /* __VIR_LIBVIRT_DOMAIN_H__ */
index 38b966f6de2103a76c6d978ddd38b8975c20ad1e..8240433611a007649da9fc4f011e44994d551de0 100644 (file)
@@ -1791,25 +1791,6 @@ typedef enum {
     VIR_DOMAIN_CAPS_FEATURE_LAST
 } virDomainCapsFeature;
 
-typedef enum {
-    VIR_DOMAIN_LIFECYCLE_POWEROFF,
-    VIR_DOMAIN_LIFECYCLE_REBOOT,
-    VIR_DOMAIN_LIFECYCLE_CRASH,
-
-    VIR_DOMAIN_LIFECYCLE_LAST
-} virDomainLifecycle;
-
-typedef enum {
-    VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY,
-    VIR_DOMAIN_LIFECYCLE_ACTION_RESTART,
-    VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME,
-    VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE,
-    VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY,
-    VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART,
-
-    VIR_DOMAIN_LIFECYCLE_ACTION_LAST
-} virDomainLifecycleAction;
-
 typedef enum {
     VIR_DOMAIN_LOCK_FAILURE_DEFAULT,
     VIR_DOMAIN_LOCK_FAILURE_POWEROFF,
index 4de0581c3f1a99b85db0cd396d737094a58c2db2..ce0e2b2525527be54f9a58545e387a000f836338 100644 (file)
@@ -1277,6 +1277,12 @@ typedef int
                                  unsigned long long threshold,
                                  unsigned int flags);
 
+typedef int
+(*virDrvDomainSetLifecycleAction)(virDomainPtr domain,
+                                  unsigned int type,
+                                  unsigned int action,
+                                  unsigned int flags);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1521,6 +1527,7 @@ struct _virHypervisorDriver {
     virDrvDomainSetGuestVcpus domainSetGuestVcpus;
     virDrvDomainSetVcpu domainSetVcpu;
     virDrvDomainSetBlockThreshold domainSetBlockThreshold;
+    virDrvDomainSetLifecycleAction domainSetLifecycleAction;
 };
 
 
index fc2e4ce381197fe70d8246191d6bba4bf75e6add..a51d8e3820760be2c5511a706bc692acc3fde7e0 100644 (file)
@@ -12035,3 +12035,59 @@ virDomainSetBlockThreshold(virDomainPtr domain,
     virDispatchError(domain->conn);
     return -1;
 }
+
+
+/**
+ * virDomainSetLifecycleAction:
+ * @domain: pointer to domain object
+ * @type: the lifecycle type from virDomainLifecycle
+ * @action: the action type from virDomainLifecycleAction
+ * @flags: bitwise-OR of virDomainModificationImpact
+ *
+ * Changes the actions of lifecycle events for domain represented as
+ * <on_$type>$action</on_$type> in the domain XML.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int virDomainSetLifecycleAction(virDomainPtr domain,
+                                unsigned int type,
+                                unsigned int action,
+                                unsigned int flags)
+{
+    VIR_DOMAIN_DEBUG(domain, "type='%u' action='%u' flags='0x%x'",
+                     type, action, flags);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    virCheckReadOnlyGoto(domain->conn->flags, error);
+
+    if (type >= VIR_DOMAIN_LIFECYCLE_LAST) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("invalid lifecycle type '%u'"), type);
+        goto error;
+    }
+
+    if (action >= VIR_DOMAIN_LIFECYCLE_ACTION_LAST) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("invalid lifecycle action '%u'"), action);
+        goto error;
+    }
+
+    if (domain->conn->driver->domainSetLifecycleAction) {
+        int ret;
+        ret = domain->conn->driver->domainSetLifecycleAction(domain,
+                                                             type,
+                                                             action,
+                                                             flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
index 4986019431f188079e0190f9cfd0ce5be335ac4e..0efde25a7f76d6151bf3625643487c1da685afe6 100644 (file)
@@ -774,4 +774,9 @@ LIBVIRT_3.7.0 {
         virDomainManagedSaveGetXMLDesc;
         virDomainManagedSaveDefineXML;
 } LIBVIRT_3.4.0;
+
+LIBVIRT_3.9.0 {
+    global:
+        virDomainSetLifecycleAction;
+} LIBVIRT_3.7.0;
 # .... define new API here using predicted next version number ....
index 00e8086d51a0091480baad694c86a18529556830..06719bb8256ea68f596c35e0793a00886469ec53 100644 (file)
@@ -8497,6 +8497,7 @@ static virHypervisorDriver hypervisor_driver = {
     .domainSetGuestVcpus = remoteDomainSetGuestVcpus, /* 2.0.0 */
     .domainSetVcpu = remoteDomainSetVcpu, /* 3.1.0 */
     .domainSetBlockThreshold = remoteDomainSetBlockThreshold, /* 3.2.0 */
+    .domainSetLifecycleAction = remoteDomainSetLifecycleAction /* 3.9.0 */
 };
 
 static virNetworkDriver network_driver = {
index e3014f66bc67b0e51c8687fcce4156120ef72370..0aed25220dc47bca52f3945923625ba887cf6ab8 100644 (file)
@@ -3433,6 +3433,12 @@ struct remote_domain_set_block_threshold_args {
     unsigned int flags;
 };
 
+struct remote_domain_set_lifecycle_action_args {
+    remote_nonnull_domain dom;
+    unsigned int type;
+    unsigned int action;
+    unsigned int flags;
+};
 
 /*----- Protocol. -----*/
 
@@ -6108,5 +6114,11 @@ enum remote_procedure {
      * @acl: domain:write
      * @acl: domain:hibernate
      */
-    REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML = 389
+    REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML = 389,
+
+    /**
+     * @generate: both
+     * @acl: domain:write
+     */
+    REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION = 390
 };
index dc78d51c4a6616bf50125c8ab5d6b48dc1630c29..59b0acec69bf4eee464e1f7be2256afc4645b533 100644 (file)
@@ -2865,6 +2865,12 @@ struct remote_domain_set_block_threshold_args {
         uint64_t                   threshold;
         u_int                      flags;
 };
+struct remote_domain_set_lifecycle_action_args {
+        remote_nonnull_domain      dom;
+        u_int                      type;
+        u_int                      action;
+        u_int                      flags;
+};
 enum remote_procedure {
         REMOTE_PROC_CONNECT_OPEN = 1,
         REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -3255,4 +3261,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_DOWNTIME = 387,
         REMOTE_PROC_DOMAIN_MANAGED_SAVE_GET_XML_DESC = 388,
         REMOTE_PROC_DOMAIN_MANAGED_SAVE_DEFINE_XML = 389,
+        REMOTE_PROC_DOMAIN_SET_LIFECYCLE_ACTION = 390,
 };