[PATCH] Pass shutoff reason to release hook

Swapnil Ingle posted 1 patch 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20240603141038.22713-1-swapnil.ingle@nutanix.com
There is a newer version of this series
docs/hooks.rst          | 24 +++++++++++++++++++++++-
src/qemu/qemu_process.c |  2 +-
2 files changed, 24 insertions(+), 2 deletions(-)
[PATCH] Pass shutoff reason to release hook
Posted by Swapnil Ingle 3 months ago
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.

Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
---
 docs/hooks.rst          | 24 +++++++++++++++++++++++-
 src/qemu/qemu_process.c |  2 +-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/docs/hooks.rst b/docs/hooks.rst
index 1dbc492bd4..e76208021a 100644
--- a/docs/hooks.rst
+++ b/docs/hooks.rst
@@ -312,7 +312,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
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7ef7040a85..0a03685ca7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8716,7 +8716,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);
-- 
2.45.2
Re: [PATCH] Pass shutoff reason to release hook
Posted by Michal Prívozník 2 months, 3 weeks ago
On 6/3/24 16:10, Swapnil Ingle wrote:
> 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.
> 
> Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
> ---
>  docs/hooks.rst          | 24 +++++++++++++++++++++++-
>  src/qemu/qemu_process.c |  2 +-
>  2 files changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/docs/hooks.rst b/docs/hooks.rst
> index 1dbc492bd4..e76208021a 100644
> --- a/docs/hooks.rst
> +++ b/docs/hooks.rst
> @@ -312,7 +312,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
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 7ef7040a85..0a03685ca7 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -8716,7 +8716,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);

Ahh, sorry for letting this slip.
Anyway, you're documenting LXC hook but changing hook calling from QEMU
driver. These are independent of each other, though I believe we can
make the same change to both. Do you mind posting v2?

Michal
Re: [PATCH] Pass shutoff reason to release hook
Posted by Swapnil Ingle 2 months, 3 weeks ago
On 18.06.24 10:53, Michal Prívozník wrote:
> !-------------------------------------------------------------------|
>    CAUTION: External Email
>
> |-------------------------------------------------------------------!
>
> On 6/3/24 16:10, Swapnil Ingle wrote:
>> 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.
>>
>> Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
>> ---
>>   docs/hooks.rst          | 24 +++++++++++++++++++++++-
>>   src/qemu/qemu_process.c |  2 +-
>>   2 files changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git a/docs/hooks.rst b/docs/hooks.rst
>> index 1dbc492bd4..e76208021a 100644
>> --- a/docs/hooks.rst
>> +++ b/docs/hooks.rst
>> @@ -312,7 +312,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
>> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
>> index 7ef7040a85..0a03685ca7 100644
>> --- a/src/qemu/qemu_process.c
>> +++ b/src/qemu/qemu_process.c
>> @@ -8716,7 +8716,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);
> Ahh, sorry for letting this slip.
> Anyway, you're documenting LXC hook but changing hook calling from QEMU
> driver. These are independent of each other, though I believe we can
> make the same change to both. Do you mind posting v2?
>
Thanks for the review.

Sent V2 please have another look.

-Swapnil
Re: [PATCH] Pass shutoff reason to release hook
Posted by Swapnil Ingle 2 months, 3 weeks ago
Gentle reminder! Can someone please review this change?


Thanks,

-Swapnil

On 03.06.24 16:10, Swapnil Ingle wrote:
> 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.
>
> Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
> ---
>   docs/hooks.rst          | 24 +++++++++++++++++++++++-
>   src/qemu/qemu_process.c |  2 +-
>   2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/docs/hooks.rst b/docs/hooks.rst
> index 1dbc492bd4..e76208021a 100644
> --- a/docs/hooks.rst
> +++ b/docs/hooks.rst
> @@ -312,7 +312,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
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 7ef7040a85..0a03685ca7 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -8716,7 +8716,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);