[libvirt] [PATCH] libxl: add support for soft reset

Jim Fehlig posted 1 patch 3 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20181030012600.31585-1-jfehlig@suse.com
src/libxl/libxl_domain.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
[libvirt] [PATCH] libxl: add support for soft reset
Posted by Jim Fehlig 3 years, 6 months ago
The pvops Linux kernel implements machine_ops.crash_shutdown as

static void xen_hvm_crash_shutdown(struct pt_regs *regs)
{
        native_machine_crash_shutdown(regs);
        xen_reboot(SHUTDOWN_soft_reset);
}

but currently the libxl driver does not handle the soft reset
shutdown event. As a result, the guest domain never proceeds
past xen_reboot(), making it impossible for HVM domains to save
a crash dump using kexec.

This patch adds support for handling the soft reset event by
calling libxl_domain_soft_reset() and re-enabling domain death
events, which is similar to the xl tool handling of soft reset
shutdown event.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_domain.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 0032b9dd11..295ec04a85 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -447,8 +447,10 @@ libxlDomainShutdownThread(void *opaque)
     virObjectEventPtr dom_event = NULL;
     libxl_shutdown_reason xl_reason = ev->u.domain_shutdown.shutdown_reason;
     libxlDriverConfigPtr cfg;
+    libxl_domain_config d_config;
 
     cfg = libxlDriverConfigGet(driver);
+    libxl_domain_config_init(&d_config);
 
     vm = virDomainObjListFindByID(driver->domains, ev->domid);
     if (!vm) {
@@ -532,6 +534,33 @@ libxlDomainShutdownThread(void *opaque)
          * after calling libxl_domain_suspend() are handled by it's callers.
          */
         goto endjob;
+    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
+        libxlDomainObjPrivatePtr priv = vm->privateData;
+        int res;
+
+        if (libxl_retrieve_domain_configuration(cfg->ctx, vm->def->id,
+                                                &d_config) != 0) {
+            VIR_ERROR(_("Failed to retrieve config for VM '%s'. "
+                        "Unable to perform soft reset. Destroying VM"),
+                      vm->def->name);
+            goto destroy;
+        }
+
+        if (priv->deathW) {
+            libxl_evdisable_domain_death(cfg->ctx, priv->deathW);
+            priv->deathW = NULL;
+        }
+
+        res = libxl_domain_soft_reset(cfg->ctx, &d_config, vm->def->id,
+                                      NULL, NULL);
+        if (res != 0) {
+            VIR_ERROR(_("Failed to soft reset VM '%s'. Destroying VM"),
+                      vm->def->name);
+            goto destroy;
+        }
+        libxl_evenable_domain_death(cfg->ctx, vm->def->id, 0, &priv->deathW);
+        libxl_domain_unpause(cfg->ctx, vm->def->id);
+        goto endjob;
     } else {
         VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
         goto endjob;
@@ -565,6 +594,7 @@ libxlDomainShutdownThread(void *opaque)
     virObjectEventStateQueue(driver->domainEventState, dom_event);
     libxl_event_free(cfg->ctx, ev);
     VIR_FREE(shutdown_info);
+    libxl_domain_config_dispose(&d_config);
     virObjectUnref(cfg);
 }
 
-- 
2.18.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] libxl: add support for soft reset
Posted by Jim Fehlig 3 years, 6 months ago
On 10/29/18 7:26 PM, Jim Fehlig wrote:
> The pvops Linux kernel implements machine_ops.crash_shutdown as
> 
> static void xen_hvm_crash_shutdown(struct pt_regs *regs)
> {
>          native_machine_crash_shutdown(regs);
>          xen_reboot(SHUTDOWN_soft_reset);
> }
> 
> but currently the libxl driver does not handle the soft reset
> shutdown event. As a result, the guest domain never proceeds
> past xen_reboot(), making it impossible for HVM domains to save
> a crash dump using kexec.
> 
> This patch adds support for handling the soft reset event by
> calling libxl_domain_soft_reset() and re-enabling domain death
> events, which is similar to the xl tool handling of soft reset
> shutdown event.
> 
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> ---
>   src/libxl/libxl_domain.c | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
> 
> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
> index 0032b9dd11..295ec04a85 100644
> --- a/src/libxl/libxl_domain.c
> +++ b/src/libxl/libxl_domain.c
> @@ -447,8 +447,10 @@ libxlDomainShutdownThread(void *opaque)
>       virObjectEventPtr dom_event = NULL;
>       libxl_shutdown_reason xl_reason = ev->u.domain_shutdown.shutdown_reason;
>       libxlDriverConfigPtr cfg;
> +    libxl_domain_config d_config;
>   
>       cfg = libxlDriverConfigGet(driver);
> +    libxl_domain_config_init(&d_config);
>   
>       vm = virDomainObjListFindByID(driver->domains, ev->domid);
>       if (!vm) {
> @@ -532,6 +534,33 @@ libxlDomainShutdownThread(void *opaque)
>            * after calling libxl_domain_suspend() are handled by it's callers.
>            */
>           goto endjob;
> +    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
> +        libxlDomainObjPrivatePtr priv = vm->privateData;
> +        int res;

I'm not sure why I have this useless local. I've squashed the below diff into my 
local branch.

Regards,
Jim

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 295ec04a85..af5127bc2f 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -536,7 +536,6 @@ libxlDomainShutdownThread(void *opaque)
          goto endjob;
      } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
          libxlDomainObjPrivatePtr priv = vm->privateData;
-        int res;

          if (libxl_retrieve_domain_configuration(cfg->ctx, vm->def->id,
                                                  &d_config) != 0) {
@@ -551,9 +550,8 @@ libxlDomainShutdownThread(void *opaque)
              priv->deathW = NULL;
          }

-        res = libxl_domain_soft_reset(cfg->ctx, &d_config, vm->def->id,
-                                      NULL, NULL);
-        if (res != 0) {
+        if (libxl_domain_soft_reset(cfg->ctx, &d_config, vm->def->id,
+                                    NULL, NULL) != 0) {
              VIR_ERROR(_("Failed to soft reset VM '%s'. Destroying VM"),
                        vm->def->name);
              goto destroy;

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] libxl: add support for soft reset
Posted by Michal Privoznik 3 years, 6 months ago
On 10/30/2018 03:17 AM, Jim Fehlig wrote:
> On 10/29/18 7:26 PM, Jim Fehlig wrote:
>> The pvops Linux kernel implements machine_ops.crash_shutdown as
>>
>> static void xen_hvm_crash_shutdown(struct pt_regs *regs)
>> {
>>          native_machine_crash_shutdown(regs);
>>          xen_reboot(SHUTDOWN_soft_reset);
>> }
>>
>> but currently the libxl driver does not handle the soft reset
>> shutdown event. As a result, the guest domain never proceeds
>> past xen_reboot(), making it impossible for HVM domains to save
>> a crash dump using kexec.
>>
>> This patch adds support for handling the soft reset event by
>> calling libxl_domain_soft_reset() and re-enabling domain death
>> events, which is similar to the xl tool handling of soft reset
>> shutdown event.
>>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>> ---
>>   src/libxl/libxl_domain.c | 30 ++++++++++++++++++++++++++++++
>>   1 file changed, 30 insertions(+)
>>
>> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
>> index 0032b9dd11..295ec04a85 100644
>> --- a/src/libxl/libxl_domain.c
>> +++ b/src/libxl/libxl_domain.c
>> @@ -447,8 +447,10 @@ libxlDomainShutdownThread(void *opaque)
>>       virObjectEventPtr dom_event = NULL;
>>       libxl_shutdown_reason xl_reason =
>> ev->u.domain_shutdown.shutdown_reason;
>>       libxlDriverConfigPtr cfg;
>> +    libxl_domain_config d_config;
>>         cfg = libxlDriverConfigGet(driver);
>> +    libxl_domain_config_init(&d_config);
>>         vm = virDomainObjListFindByID(driver->domains, ev->domid);
>>       if (!vm) {
>> @@ -532,6 +534,33 @@ libxlDomainShutdownThread(void *opaque)
>>            * after calling libxl_domain_suspend() are handled by it's
>> callers.
>>            */
>>           goto endjob;
>> +    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
>> +        libxlDomainObjPrivatePtr priv = vm->privateData;
>> +        int res;
> 
> I'm not sure why I have this useless local. I've squashed the below diff
> into my local branch.

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] libxl: add support for soft reset
Posted by Jim Fehlig 3 years, 6 months ago
On 10/30/18 3:18 AM, Michal Privoznik wrote:
> On 10/30/2018 03:17 AM, Jim Fehlig wrote:
>> On 10/29/18 7:26 PM, Jim Fehlig wrote:
>>> The pvops Linux kernel implements machine_ops.crash_shutdown as
>>>
>>> static void xen_hvm_crash_shutdown(struct pt_regs *regs)
>>> {
>>>           native_machine_crash_shutdown(regs);
>>>           xen_reboot(SHUTDOWN_soft_reset);
>>> }
>>>
>>> but currently the libxl driver does not handle the soft reset
>>> shutdown event. As a result, the guest domain never proceeds
>>> past xen_reboot(), making it impossible for HVM domains to save
>>> a crash dump using kexec.
>>>
>>> This patch adds support for handling the soft reset event by
>>> calling libxl_domain_soft_reset() and re-enabling domain death
>>> events, which is similar to the xl tool handling of soft reset
>>> shutdown event.
>>>
>>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
>>> ---
>>>    src/libxl/libxl_domain.c | 30 ++++++++++++++++++++++++++++++
>>>    1 file changed, 30 insertions(+)
>>>
>>> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
>>> index 0032b9dd11..295ec04a85 100644
>>> --- a/src/libxl/libxl_domain.c
>>> +++ b/src/libxl/libxl_domain.c
>>> @@ -447,8 +447,10 @@ libxlDomainShutdownThread(void *opaque)
>>>        virObjectEventPtr dom_event = NULL;
>>>        libxl_shutdown_reason xl_reason =
>>> ev->u.domain_shutdown.shutdown_reason;
>>>        libxlDriverConfigPtr cfg;
>>> +    libxl_domain_config d_config;
>>>          cfg = libxlDriverConfigGet(driver);
>>> +    libxl_domain_config_init(&d_config);
>>>          vm = virDomainObjListFindByID(driver->domains, ev->domid);
>>>        if (!vm) {
>>> @@ -532,6 +534,33 @@ libxlDomainShutdownThread(void *opaque)
>>>             * after calling libxl_domain_suspend() are handled by it's
>>> callers.
>>>             */
>>>            goto endjob;
>>> +    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_SOFT_RESET) {
>>> +        libxlDomainObjPrivatePtr priv = vm->privateData;
>>> +        int res;
>>
>> I'm not sure why I have this useless local. I've squashed the below diff
>> into my local branch.
> 
> ACK

Thanks, but I found this didn't compile with Xen 4.6, our minimum supported Xen 
version. Soft reset was introduced in 4.7. I've sent a V2, which includes some 
cleanups to the libxlDomainShutdownThread function. Thanks for looking at it if 
you have time

https://www.redhat.com/archives/libvir-list/2018-October/msg01370.html

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list