]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: open nodedev driver connection at time of use
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 31 Jan 2018 16:31:57 +0000 (16:31 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 31 Jan 2018 18:34:48 +0000 (18:34 +0000)
Instead of passing around a virConnectPtr object, just open a connection
to the nodedev driver at time of use. Opening connections on demand will
be beneficial when the nodedev driver is in a separate daemon. It also
solves the problem that a number of callers just pass in a NULL
connection today which prevents nodedev lookup working at all.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/storage/storage_backend_scsi.c

index 9347d66384740db8539006e9abcf342e38c2add3..d7e80ac02dc8a97bee2dec461711ee5293795518 100644 (file)
@@ -36,6 +36,7 @@
 #include "virstring.h"
 #include "storage_util.h"
 #include "node_device_conf.h"
+#include "driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_STORAGE
 
@@ -245,20 +246,20 @@ checkName(const char *name)
  * sysfs tree to get the parent 'scsi_host#' to ensure it matches.
  */
 static bool
-checkParent(virConnectPtr conn,
-            const char *name,
+checkParent(const char *name,
             const char *parent_name)
 {
     unsigned int host_num;
     char *scsi_host_name = NULL;
     char *vhba_parent = NULL;
     bool retval = false;
+    virConnectPtr conn = NULL;
 
-    VIR_DEBUG("conn=%p, name=%s, parent_name=%s", conn, name, parent_name);
+    VIR_DEBUG("name=%s, parent_name=%s", name, parent_name);
 
-    /* autostarted pool - assume we're OK */
+    conn = virGetConnectNodeDev();
     if (!conn)
-        return true;
+        goto cleanup;
 
     if (virSCSIHostGetNumber(parent_name, &host_num) < 0) {
         virReportError(VIR_ERR_XML_ERROR,
@@ -291,6 +292,7 @@ checkParent(virConnectPtr conn,
     retval = true;
 
  cleanup:
+    virObjectUnref(conn);
     VIR_FREE(vhba_parent);
     VIR_FREE(scsi_host_name);
     return retval;
@@ -298,8 +300,7 @@ checkParent(virConnectPtr conn,
 
 
 static int
-createVport(virConnectPtr conn,
-            virStoragePoolDefPtr def,
+createVport(virStoragePoolDefPtr def,
             const char *configFile,
             virStorageAdapterFCHostPtr fchost)
 {
@@ -308,8 +309,8 @@ createVport(virConnectPtr conn,
     virThread thread;
     int ret = -1;
 
-    VIR_DEBUG("conn=%p, configFile='%s' parent='%s', wwnn='%s' wwpn='%s'",
-              conn, NULLSTR(configFile), NULLSTR(fchost->parent),
+    VIR_DEBUG("configFile='%s' parent='%s', wwnn='%s' wwpn='%s'",
+              NULLSTR(configFile), NULLSTR(fchost->parent),
               fchost->wwnn, fchost->wwpn);
 
     /* If we find an existing HBA/vHBA within the fc_host sysfs
@@ -322,7 +323,7 @@ createVport(virConnectPtr conn,
 
         /* If a parent was provided, let's make sure the 'name' we've
          * retrieved has the same parent. If not this will cause failure. */
-        if (!fchost->parent || checkParent(conn, name, fchost->parent))
+        if (!fchost->parent || checkParent(name, fchost->parent))
             ret = 0;
 
         goto cleanup;
@@ -443,14 +444,14 @@ virStorageBackendSCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
 
 
 static int
-virStorageBackendSCSIStartPool(virConnectPtr conn,
+virStorageBackendSCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                virStoragePoolObjPtr pool)
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     const char *configFile = virStoragePoolObjGetConfigFile(pool);
 
     if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST)
-        return createVport(conn, def, configFile,
+        return createVport(def, configFile,
                            &def->source.adapter.data.fchost);
 
     return 0;
@@ -463,9 +464,17 @@ virStorageBackendSCSIStopPool(virConnectPtr conn,
 {
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
 
-    if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST)
-        return virNodeDeviceDeleteVport(conn,
-                                        &def->source.adapter.data.fchost);
+    if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+        int ret;
+        conn = virGetConnectNodeDev();
+        if (!conn)
+            return -1;
+
+        ret = virNodeDeviceDeleteVport(conn,
+                                       &def->source.adapter.data.fchost);
+        virObjectUnref(conn);
+        return ret;
+    }
 
     return 0;
 }