[PATCH 3/3] domain_conf: set default emulator into def if it fails to alloc

zhangjl02 posted 3 patches 3 years, 9 months ago
[PATCH 3/3] domain_conf: set default emulator into def if it fails to alloc
Posted by zhangjl02 3 years, 9 months ago
From: zhangjl02 <zhangjl02@inspur.com>

When emulator is not found on host, domainPostParseDataAlloc will return 1,
and the domain will fail to start. Call domainPostParseDataDefEmulator to
replace emulator with the default one of guest's arch, and try to alloc again
after domainPostParseDataAlloc's failure. This will increase error tolerance,
if emulator defined in xml is not found on host.

Signed-off-by: zhangjl02 <zhangjl02@inspur.com>
---
 src/conf/domain_conf.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bd2884088c..485f66357c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6266,7 +6266,15 @@ virDomainDefPostParse(virDomainDef *def,
         ret = xmlopt->config.domainPostParseDataAlloc(def, parseFlags,
                                                       xmlopt->config.priv,
                                                       &data.parseOpaque);
-
+        if (ret == 1){
+            int to_default = 0;
+            to_default = xmlopt->config.domainPostParseDataDefEmulator(def);
+            if (to_default) {
+                ret = xmlopt->config.domainPostParseDataAlloc(def, parseFlags,
+                                                              xmlopt->config.priv,
+                                                              &data.parseOpaque);
+            }
+        }
         if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
             goto cleanup;
         localParseOpaque = true;
-- 
2.35.1.windows.2
Re: [PATCH 3/3] domain_conf: set default emulator into def if it fails to alloc
Posted by Peter Krempa 3 years, 9 months ago
On Sat, May 07, 2022 at 17:40:16 +0800, zhangjl02 wrote:
> From: zhangjl02 <zhangjl02@inspur.com>
> 
> When emulator is not found on host, domainPostParseDataAlloc will return 1,
> and the domain will fail to start. Call domainPostParseDataDefEmulator to
> replace emulator with the default one of guest's arch, and try to alloc again
> after domainPostParseDataAlloc's failure. This will increase error tolerance,
> if emulator defined in xml is not found on host.

What you describe here is definitely not desired. When the user
specifies an emulator path in the XML we must not change it even if the
emulator is not present and we could theoretically use a different one.

This could mask problems and make users use a different binary without
even knowing about it.

If the user wishes to use the default they can certainly omit the
emulator.