[PATCH 17/26] conf: implement support for autostart once feature

Daniel P. Berrangé posted 26 patches 1 year, 1 month ago
There is a newer version of this series
[PATCH 17/26] conf: implement support for autostart once feature
Posted by Daniel P. Berrangé 1 year, 1 month ago
This is maintained in the same way as the autostart flag, using a
symlink. The difference is that instead of '.xml', the symlink
suffix is '.xml.once'. The link is also deleted immediately after
it has been read.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/conf/domain_conf.c      | 6 +++++-
 src/conf/domain_conf.h      | 1 +
 src/conf/virdomainobjlist.c | 7 ++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index af88d0bcfd..4a794d1f71 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29083,13 +29083,17 @@ virDomainDeleteConfig(const char *configDir,
 {
     g_autofree char *configFile = NULL;
     g_autofree char *autostartLink = NULL;
+    g_autofree char *autostartOnceLink = NULL;
 
     configFile = virDomainConfigFile(configDir, dom->def->name);
     autostartLink = virDomainConfigFile(autostartDir, dom->def->name);
+    autostartOnceLink = g_strdup_printf("%s.once", autostartLink);
 
-    /* Not fatal if this doesn't work */
+    /* Not fatal if these don't work */
     unlink(autostartLink);
+    unlink(autostartOnceLink);
     dom->autostart = 0;
+    dom->autostartOnce = 0;
 
     if (unlink(configFile) < 0 &&
         errno != ENOENT) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9f7c28343f..f30143e704 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3282,6 +3282,7 @@ struct _virDomainObj {
     virDomainStateReason state;
 
     unsigned int autostart : 1;
+    unsigned int autostartOnce : 1;
     unsigned int persistent : 1;
     unsigned int updated : 1;
     unsigned int removing : 1;
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index 72207450c5..ba2f9f544d 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -487,9 +487,10 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
 {
     g_autofree char *configFile = NULL;
     g_autofree char *autostartLink = NULL;
+    g_autofree char *autostartOnceLink = NULL;
     g_autoptr(virDomainDef) def = NULL;
     virDomainObj *dom;
-    int autostart;
+    int autostart, autostartOnce;
     g_autoptr(virDomainDef) oldDef = NULL;
 
     configFile = virDomainConfigFile(configDir, name);
@@ -500,13 +501,17 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
         return NULL;
 
     autostartLink = virDomainConfigFile(autostartDir, name);
+    autostartOnceLink = g_strdup_printf("%s.once", autostartLink);
 
     autostart = virFileLinkPointsTo(autostartLink, configFile);
+    autostartOnce = virFileLinkPointsTo(autostartOnceLink, configFile);
+    unlink(autostartOnceLink);
 
     if (!(dom = virDomainObjListAddLocked(doms, &def, xmlopt, 0, &oldDef)))
         return NULL;
 
     dom->autostart = autostart;
+    dom->autostartOnce = autostartOnce;
 
     if (notify)
         (*notify)(dom, oldDef == NULL, opaque);
-- 
2.47.1
Re: [PATCH 17/26] conf: implement support for autostart once feature
Posted by Peter Krempa 1 year ago
On Wed, Jan 08, 2025 at 19:42:50 +0000, Daniel P. Berrangé wrote:
> This is maintained in the same way as the autostart flag, using a
> symlink. The difference is that instead of '.xml', the symlink
> suffix is '.xml.once'. The link is also deleted immediately after
> it has been read.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/conf/domain_conf.c      | 6 +++++-
>  src/conf/domain_conf.h      | 1 +
>  src/conf/virdomainobjlist.c | 7 ++++++-
>  3 files changed, 12 insertions(+), 2 deletions(-)

[...]

> diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
> index 72207450c5..ba2f9f544d 100644
> --- a/src/conf/virdomainobjlist.c
> +++ b/src/conf/virdomainobjlist.c

[...]

> @@ -500,13 +501,17 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
>          return NULL;
>  
>      autostartLink = virDomainConfigFile(autostartDir, name);
> +    autostartOnceLink = g_strdup_printf("%s.once", autostartLink);
>  
>      autostart = virFileLinkPointsTo(autostartLink, configFile);
> +    autostartOnce = virFileLinkPointsTo(autostartOnceLink, configFile);
> +    unlink(autostartOnceLink);

Actually this will not work properly if you restart the daemon before
rebooting the host as configs will be loaded, thus the file unlinked but
then the only place this is recorded is in memory.

The unlinking of the file needs to happen only after autostart was
actually attempted, which should be reasonably doable now that's
centralised.
Re: [PATCH 17/26] conf: implement support for autostart once feature
Posted by Peter Krempa 1 year ago
On Wed, Jan 08, 2025 at 19:42:50 +0000, Daniel P. Berrangé wrote:
> This is maintained in the same way as the autostart flag, using a
> symlink. The difference is that instead of '.xml', the symlink
> suffix is '.xml.once'. The link is also deleted immediately after
> it has been read.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/conf/domain_conf.c      | 6 +++++-
>  src/conf/domain_conf.h      | 1 +
>  src/conf/virdomainobjlist.c | 7 ++++++-
>  3 files changed, 12 insertions(+), 2 deletions(-)

[...]

> diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
> index 72207450c5..ba2f9f544d 100644
> --- a/src/conf/virdomainobjlist.c
> +++ b/src/conf/virdomainobjlist.c
> @@ -487,9 +487,10 @@ virDomainObjListLoadConfig(virDomainObjList *doms,
>  {
>      g_autofree char *configFile = NULL;
>      g_autofree char *autostartLink = NULL;
> +    g_autofree char *autostartOnceLink = NULL;
>      g_autoptr(virDomainDef) def = NULL;
>      virDomainObj *dom;
> -    int autostart;
> +    int autostart, autostartOnce;

Preferrably one per line.

>      g_autoptr(virDomainDef) oldDef = NULL;
>  
>      configFile = virDomainConfigFile(configDir, name);

Reviewed-by: Peter Krempa <pkrempa@redhat.com>