Re: [PATCH 1/1] src/driver.c: remove duplicated code in virGetConnect* functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/27/19 11:09 AM, Daniel Henrique Barboza wrote:
All the 6 virGetConnect* functions in driver.c shares the
same code base. This patch creates a new static function
virGetConnectGeneric() that contains the common code to
be used with all other virGetConnect*.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---

CC'ing Cole Robinson since he reviewed similar patches
a few days ago.

  src/driver.c | 100 +++++++++++++--------------------------------------
  1 file changed, 25 insertions(+), 75 deletions(-)

diff --git a/src/driver.c b/src/driver.c
index ed2d943ddf..8a4bc8ff66 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -29,6 +29,7 @@
  #include "virfile.h"
  #include "virlog.h"
  #include "virmodule.h"
+#include "virstring.h"
  #include "virthread.h"
  #include "configmake.h"
@@ -96,112 +97,61 @@ virConnectCacheOnceInit(void) VIR_ONCE_GLOBAL_INIT(virConnectCache); -virConnectPtr virGetConnectInterface(void)
+static virConnectPtr
+virGetConnectGeneric(virThreadLocal thread, const char *name)
  {

virThreadLocal is a struct behind the typedef, so better to make this virThreadLocalPtr. That's also what all other functions that use virThreadLocal take as an argument

      virConnectPtr conn;
if (virConnectCacheInitialize() < 0)
          return NULL;
- conn = virThreadLocalGet(&connectInterface);
+    conn = virThreadLocalGet(&thread);
+
      if (conn) {
-        VIR_DEBUG("Return cached interface connection %p", conn);
+        VIR_DEBUG("Return cached %s connection %p", name, conn);
          virObjectRef(conn);
      } else {
-        conn = virConnectOpen(geteuid() == 0 ? "interface:///system" : "interface:///session");
-        VIR_DEBUG("Opened new interface connection %p", conn);
+        VIR_AUTOFREE(char *) uri = NULL;
+        const char *uriPath = geteuid() == 0 ? "/system" : "/session";
+
+        if (virAsprintf(&uri, "%s//%s", name, uriPath) < 0)
+            return NULL;
+

Missing a : here

- Cole

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux