]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Don't assume storage pool exists for FC/SCSI refresh thread
authorJohn Ferlan <jferlan@redhat.com>
Mon, 2 Nov 2015 22:21:11 +0000 (17:21 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 12 Nov 2015 11:30:33 +0000 (06:30 -0500)
https://bugzilla.redhat.com/show_bug.cgi?id=1277781

The virStoragePoolFCRefreshThread had passed a pointer to the pool obj
in the virStoragePoolFCRefreshInfoPtr; however, we cannot assume that
the pool exists still since we don't keep the pool lock throughout
the duration of the thread.

Therefore, instead of passing the pool obj pointer, pass the UUID of
the pool and perform a lookup.  If found, then we can perform the
refresh using the locked pool obj pointer; otherwise, we just exit
the thread since the pool is now gone.

src/storage/storage_backend_scsi.c

index f246a05f3a3e739784d849114f3ae7abbbe0bb11..7dd7674f88febf3af69ebfb2edcbcd68f86168bb 100644 (file)
@@ -44,7 +44,7 @@ typedef struct _virStoragePoolFCRefreshInfo virStoragePoolFCRefreshInfo;
 typedef virStoragePoolFCRefreshInfo *virStoragePoolFCRefreshInfoPtr;
 struct _virStoragePoolFCRefreshInfo {
     char *fchost_name;
-    virStoragePoolObjPtr pool;
+    unsigned char pool_uuid[VIR_UUID_BUFLEN];
 };
 
 /* Function to check if the type file in the given sysfs_path is a
@@ -594,7 +594,8 @@ virStoragePoolFCRefreshThread(void *opaque)
 {
     virStoragePoolFCRefreshInfoPtr cbdata = opaque;
     const char *fchost_name = cbdata->fchost_name;
-    virStoragePoolObjPtr pool = cbdata->pool;
+    const unsigned char *pool_uuid = cbdata->pool_uuid;
+    virStoragePoolObjPtr pool = NULL;
     unsigned int host;
     int found = 0;
     int tries = 2;
@@ -602,12 +603,15 @@ virStoragePoolFCRefreshThread(void *opaque)
     do {
         sleep(5); /* Give it time */
 
-        /* Lock the pool, if active, we can get the host number, successfully
-         * rescan, and find LUN's, then we are happy
+        /* Let's see if the pool still exists -  */
+        if (!(pool = virStoragePoolObjFindPoolByUUID(pool_uuid)))
+            break;
+
+        /* Return with pool lock, if active, we can get the host number,
+         * successfully, rescan, and find LUN's, then we are happy
          */
         VIR_DEBUG("Attempt FC Refresh for pool='%s' name='%s' tries='%d'",
                   pool->def->name, fchost_name, tries);
-        virStoragePoolObjLock(pool);
         if (virStoragePoolObjIsActive(pool) &&
             virGetSCSIHostNumber(fchost_name, &host) == 0 &&
             virStorageBackendSCSITriggerRescan(host) == 0) {
@@ -617,7 +621,7 @@ virStoragePoolFCRefreshThread(void *opaque)
         virStoragePoolObjUnlock(pool);
     } while (!found && --tries);
 
-    if (!found)
+    if (pool && !found)
         VIR_DEBUG("FC Refresh Thread failed to find LU's");
 
     virStoragePoolFCRefreshDataFree(cbdata);
@@ -798,7 +802,7 @@ createVport(virConnectPtr conn,
     if ((name = virGetFCHostNameByWWN(NULL, adapter->data.fchost.wwnn,
                                       adapter->data.fchost.wwpn))) {
         if (VIR_ALLOC(cbdata) == 0) {
-            cbdata->pool = pool;
+            memcpy(cbdata->pool_uuid, pool->def->uuid, VIR_UUID_BUFLEN);
             cbdata->fchost_name = name;
             name = NULL;