]> xenbits.xensource.com Git - libvirt.git/commitdiff
Pass shutoff reason to release hook
authorSwapnil Ingle <swapnil.ingle@nutanix.com>
Tue, 18 Jun 2024 16:39:58 +0000 (16:39 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 19 Jun 2024 10:15:26 +0000 (12:15 +0200)
Sometimes in release hook it is useful to know if the VM shutdown was graceful
or not. This is especially useful to do cleanup based on the VM shutdown failure
reason in release hook. This patch proposes to use the last argument 'extra'
to pass VM shutoff reason in the call to release hook.
Making this change for Qemu and LXC.

Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/hooks.rst
src/lxc/lxc_process.c
src/qemu/qemu_process.c

index 1dbc492bd482499262862c72a197c9b109fd03ff..48128ba3d8c575e2ca2bcdafdc3bdfd4bfe43f62 100644 (file)
@@ -215,7 +215,30 @@ operation. There is no specific operation to indicate a "restart" is occurring.
 
    ::
 
-      /etc/libvirt/hooks/qemu guest_name release end -
+      /etc/libvirt/hooks/qemu guest_name release end <shutoff-reason>
+
+   +-------------------+-------------------------------------------------------------------+
+   | Shutoff reason    | Description                                                       |
+   +===================+===================================================================+
+   | unknown           | the reason is unknown                                             |
+   +-------------------+-------------------------------------------------------------------+
+   | shutdown          | normal shutdown                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | destroyed         | forced poweroff                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | crashed           | domain crashed                                                    |
+   +-------------------+-------------------------------------------------------------------+
+   | migrated          | migrated to another host                                          |
+   +-------------------+-------------------------------------------------------------------+
+   | saved             | saved to a file                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | failed            | domain failed to start                                            |
+   +-------------------+-------------------------------------------------------------------+
+   | from snapshot     | restored from a snapshot which was taken while domain was shutoff |
+   +-------------------+-------------------------------------------------------------------+
+   | daemon            | daemon decides to kill domain during reconnection processing      |
+   +-------------------+-------------------------------------------------------------------+
+
 
 -  :since:`Since 0.9.11`, the qemu hook script is also called at the beginning
    of incoming migration. It is called as:
@@ -312,7 +335,29 @@ operation. There is no specific operation to indicate a "restart" is occurring.
 
    ::
 
-      /etc/libvirt/hooks/lxc guest_name release end -
+      /etc/libvirt/hooks/lxc guest_name release end <shutoff-reason>
+
+   +-------------------+-------------------------------------------------------------------+
+   | Shutoff reason    | Description                                                       |
+   +===================+===================================================================+
+   | unknown           | the reason is unknown                                             |
+   +-------------------+-------------------------------------------------------------------+
+   | shutdown          | normal shutdown                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | destroyed         | forced poweroff                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | crashed           | domain crashed                                                    |
+   +-------------------+-------------------------------------------------------------------+
+   | migrated          | migrated to another host                                          |
+   +-------------------+-------------------------------------------------------------------+
+   | saved             | saved to a file                                                   |
+   +-------------------+-------------------------------------------------------------------+
+   | failed            | domain failed to start                                            |
+   +-------------------+-------------------------------------------------------------------+
+   | from snapshot     | restored from a snapshot which was taken while domain was shutoff |
+   +-------------------+-------------------------------------------------------------------+
+   | daemon            | daemon decides to kill domain during reconnection processing      |
+   +-------------------+-------------------------------------------------------------------+
 
 -  :since:`Since 0.9.13`, the lxc hook script is also called when the libvirtd
    daemon restarts and reconnects to previously running LXC processes. If the
index 30ff4eb3d09292f928159400c53a1f249f160cae..f5eb5383ec4f7024be22e4c352931e0e016cd430 100644 (file)
@@ -244,7 +244,7 @@ static void virLXCProcessCleanup(virLXCDriver *driver,
         /* we can't stop the operation even if the script raised an error */
         virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
                     VIR_HOOK_LXC_OP_RELEASE, VIR_HOOK_SUBOP_END,
-                    NULL, xml, NULL);
+                    virDomainShutoffReasonTypeToString(reason), xml, NULL);
     }
 
     if (flags & VIR_LXC_PROCESS_CLEANUP_REMOVE_TRANSIENT)
index 2c33ac3bf754b105ebe1dd0d7776b3bbd0182a91..9de01b1a0d1789dc630ae132c73cc02832c17c21 100644 (file)
@@ -8722,7 +8722,7 @@ void qemuProcessStop(virQEMUDriver *driver,
         /* we can't stop the operation even if the script raised an error */
         virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
                     VIR_HOOK_QEMU_OP_RELEASE, VIR_HOOK_SUBOP_END,
-                    NULL, xml, NULL);
+                    virDomainShutoffReasonTypeToString(reason), xml, NULL);
     }
 
     virDomainObjRemoveTransientDef(vm);