[PATCH 06/14] qemuBuildSmartcardCommandLine: Replace qemuBuildSmartcardFindCCIDController

Peter Krempa pkrempa at redhat.com
Tue Oct 12 11:12:12 UTC 2021


We have a commonly used helper virDomainControllerAliasFind, which does
the same thing and also reports errors internally.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_command.c | 35 +++--------------------------------
 1 file changed, 3 insertions(+), 32 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2d7a6ebde7..e41c7dfaaa 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9048,32 +9048,6 @@ qemuBuildNetCommandLine(virQEMUDriver *driver,
 }


-static const char *
-qemuBuildSmartcardFindCCIDController(const virDomainDef *def,
-                                     const virDomainSmartcardDef *smartcard)
-{
-    size_t i;
-
-    /* Should never happen. But doesn't hurt to check. */
-    if (smartcard->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID)
-        return NULL;
-
-    for (i = 0; i < def->ncontrollers; i++) {
-        const virDomainControllerDef *tmp = def->controllers[i];
-
-        if (tmp->type != VIR_DOMAIN_CONTROLLER_TYPE_CCID)
-            continue;
-
-        if (tmp->idx != smartcard->info.addr.ccid.controller)
-            continue;
-
-        return tmp->info.alias;
-    }
-
-    return NULL;
-}
-
-
 static int
 qemuBuildSmartcardCommandLine(virLogManager *logManager,
                               virSecurityManager *secManager,
@@ -9152,13 +9126,10 @@ qemuBuildSmartcardCommandLine(virLogManager *logManager,
         return -1;
     }

-    if (!(contAlias = qemuBuildSmartcardFindCCIDController(def,
-                                                           smartcard))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to find controller for %s"),
-                       smartcard->info.alias);
+    if (!(contAlias = virDomainControllerAliasFind(def,
+                                                   VIR_DOMAIN_CONTROLLER_TYPE_CCID,
+                                                   smartcard->info.addr.ccid.controller)))
         return -1;
-    }

     virCommandAddArg(cmd, "-device");
     virBufferAsprintf(&opt, ",id=%s,bus=%s.0", smartcard->info.alias, contAlias);
-- 
2.31.1




More information about the libvir-list mailing list