[PATCH] bhyve: don't reset domain autostart flag on destroy

Roman Bogorodskiy posted 1 patch 1 month, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20250720170414.25710-1-bogorodskiy@gmail.com
src/bhyve/bhyve_process.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
[PATCH] bhyve: don't reset domain autostart flag on destroy
Posted by Roman Bogorodskiy 1 month, 2 weeks ago
Currently, virBhyveProcessStop() uses the virDomainDeleteConfig()
helper to clean up domain status. It passes BHYVE_STATE_DIR as
a configuration dir and NULL as autostart dir, so the helper does its
job, even though it has a different purpose. However, the issue is that
it also resets the autostart (and autostartOnce) property.

This results in a situation that when a persistent domain with autostart
enabled gets destroyed, its autostart state is reported as disabled,
which is not correct.

To fix that, implement the bhyveProcessRemoveDomainStatus() which
removes the status file without side effects on the virDomainObj object.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_process.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index 5e77a9c4d6..79be6f7aba 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -427,6 +427,17 @@ virBhyveProcessStart(bhyveConn *driver,
     return virBhyveProcessStartImpl(driver, vm, reason);
 }
 
+static void
+bhyveProcessRemoveDomainStatus(const char *statusDir,
+                               const char *name)
+{
+    g_autofree char *file = virDomainConfigFile(statusDir, name);
+
+    if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
+        VIR_WARN("Failed to remove domain XML for %s: %s",
+                 name, g_strerror(errno));
+}
+
 int
 virBhyveProcessStop(struct _bhyveConn *driver,
                     virDomainObj *vm,
@@ -483,7 +494,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
 
  cleanup:
     virPidFileDelete(BHYVE_STATE_DIR, vm->def->name);
-    virDomainDeleteConfig(BHYVE_STATE_DIR, NULL, vm);
+    bhyveProcessRemoveDomainStatus(BHYVE_STATE_DIR, vm->def->name);
 
     return ret;
 }
-- 
2.49.0
Re: [PATCH] bhyve: don't reset domain autostart flag on destroy
Posted by Michal Prívozník via Devel 1 month, 2 weeks ago
On 7/20/25 19:04, Roman Bogorodskiy wrote:
> Currently, virBhyveProcessStop() uses the virDomainDeleteConfig()
> helper to clean up domain status. It passes BHYVE_STATE_DIR as
> a configuration dir and NULL as autostart dir, so the helper does its
> job, even though it has a different purpose. However, the issue is that
> it also resets the autostart (and autostartOnce) property.
> 
> This results in a situation that when a persistent domain with autostart
> enabled gets destroyed, its autostart state is reported as disabled,
> which is not correct.
> 
> To fix that, implement the bhyveProcessRemoveDomainStatus() which
> removes the status file without side effects on the virDomainObj object.
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/bhyve/bhyve_process.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
> index 5e77a9c4d6..79be6f7aba 100644
> --- a/src/bhyve/bhyve_process.c
> +++ b/src/bhyve/bhyve_process.c
> @@ -427,6 +427,17 @@ virBhyveProcessStart(bhyveConn *driver,
>      return virBhyveProcessStartImpl(driver, vm, reason);
>  }
>  
> +static void
> +bhyveProcessRemoveDomainStatus(const char *statusDir,
> +                               const char *name)
> +{
> +    g_autofree char *file = virDomainConfigFile(statusDir, name);
> +
> +    if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
> +        VIR_WARN("Failed to remove domain XML for %s: %s",
> +                 name, g_strerror(errno));

Nit pick, since this body is more than one line long, please wrap it in
curly braces.

> +}
> +
>  int
>  virBhyveProcessStop(struct _bhyveConn *driver,
>                      virDomainObj *vm,
> @@ -483,7 +494,7 @@ virBhyveProcessStop(struct _bhyveConn *driver,
>  
>   cleanup:
>      virPidFileDelete(BHYVE_STATE_DIR, vm->def->name);
> -    virDomainDeleteConfig(BHYVE_STATE_DIR, NULL, vm);
> +    bhyveProcessRemoveDomainStatus(BHYVE_STATE_DIR, vm->def->name);
>  
>      return ret;
>  }

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal