[PATCH 03/12] conf: Separate SEV formatting into a function

Michal Privoznik posted 12 patches 2 months, 4 weeks ago
[PATCH 03/12] conf: Separate SEV formatting into a function
Posted by Michal Privoznik 2 months, 4 weeks ago
To avoid convolution of switch() inside of virDomainSecDefFormat() even
more (as new sectypes are added), move formatting into a separate
function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/conf/domain_conf.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9179cc18bb..264f182d05 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -26670,6 +26670,19 @@ virDomainSEVCommonDefFormat(virBuffer *attrBuf,
 }
 
 
+static void
+virDomainSEVDefFormat(virBuffer *attrBuf,
+                      virBuffer *childBuf,
+                      virDomainSEVDef *def)
+{
+    virDomainSEVCommonDefFormat(attrBuf, childBuf, &def->common);
+
+    virBufferAsprintf(childBuf, "<policy>0x%04x</policy>\n", def->policy);
+    virBufferEscapeString(childBuf, "<dhCert>%s</dhCert>\n", def->dh_cert);
+    virBufferEscapeString(childBuf, "<session>%s</session>\n", def->session);
+}
+
+
 static void
 virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec)
 {
@@ -26683,18 +26696,9 @@ virDomainSecDefFormat(virBuffer *buf, virDomainSecDef *sec)
                       virDomainLaunchSecurityTypeToString(sec->sectype));
 
     switch ((virDomainLaunchSecurity) sec->sectype) {
-    case VIR_DOMAIN_LAUNCH_SECURITY_SEV: {
-        virDomainSEVDef *sev = &sec->data.sev;
-
-        virDomainSEVCommonDefFormat(&attrBuf, &childBuf, &sev->common);
-
-        virBufferAsprintf(&childBuf, "<policy>0x%04x</policy>\n", sev->policy);
-        virBufferEscapeString(&childBuf, "<dhCert>%s</dhCert>\n", sev->dh_cert);
-
-        virBufferEscapeString(&childBuf, "<session>%s</session>\n", sev->session);
-
+    case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+        virDomainSEVDefFormat(&attrBuf, &childBuf, &sec->data.sev);
         break;
-    }
 
     case VIR_DOMAIN_LAUNCH_SECURITY_PV:
         break;
-- 
2.44.2
Re: [PATCH 03/12] conf: Separate SEV formatting into a function
Posted by Daniel P. Berrangé 2 months, 4 weeks ago
On Thu, Jun 20, 2024 at 01:22:40PM +0200, Michal Privoznik wrote:
> To avoid convolution of switch() inside of virDomainSecDefFormat() even
> more (as new sectypes are added), move formatting into a separate
> function.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/conf/domain_conf.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|