Change in vdsm[master]: Prefetch domains when connecting a storage server.

ewarszaw at redhat.com ewarszaw at redhat.com
Thu Mar 7 21:02:38 UTC 2013


Eduardo has uploaded a new change for review.

Change subject: Prefetch domains when connecting a storage server.
......................................................................

Prefetch domains when connecting a storage server.

When a storage server is connected is searched for domains.
A uuid:findDomain method dictionary is saved for accelerate
further produces.

Related to BZ#912158

Change-Id: I8f2b19a566c659bac30a318d17cef929e0b2575b
Signed-off-by: Eduardo <ewarszaw at redhat.com>
---
M vdsm/storage/hsm.py
M vdsm/storage/localFsSD.py
M vdsm/storage/sdc.py
3 files changed, 70 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/69/12869/1

diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py
index 179ddd1..c90f681 100644
--- a/vdsm/storage/hsm.py
+++ b/vdsm/storage/hsm.py
@@ -25,6 +25,7 @@
 import os
 import threading
 import logging
+import glob
 from fnmatch import fnmatch
 from copy import deepcopy
 from itertools import imap
@@ -2223,6 +2224,46 @@
         vars.task.setDefaultException(se.GetFloppyListError("%s" % spUUID))
         return self.getIsoList(spUUID=spUUID, extension='vfd')
 
+    def __getSDTypefindMethod(self, domType):
+        # TODO: make sd.domain_types a real dictionary and remove this.
+        # Storage Domain Types find methods
+        SDTypeFindMethod = {sd.NFS_DOMAIN: nfsSD.findDomain,
+                            sd.FCP_DOMAIN: blockSD.findDomain,
+                            sd.ISCSI_DOMAIN: blockSD.findDomain,
+                            sd.LOCALFS_DOMAIN: localFsSD.findDomain,
+                            sd.POSIXFS_DOMAIN: nfsSD.findDomain,
+                            sd.GLUSTERFS_DOMAIN: glusterSD.findDomain}
+        return SDTypeFindMethod.get(domType)
+
+    def __prefetchDomains(self, domType, conObj):
+        uuidPatern = "????????-????-????-????-????????????"
+
+        if domType in (sd.FCP_DOMAIN, sd.ISCSI_DOMAIN):
+            uuids = blockSD.getStorageDomainsList()
+            self.log.debug("block uuids: %s", uuids)
+        elif domType in (sd.NFS_DOMAIN, sd.POSIXFS_DOMAIN):
+            lPath = conObj._mountCon._getLocalPath()
+            self.log.debug("nfs lpath: %s", lPath)
+            uuids = tuple(os.path.basename(d) for d in
+                          glob.glob(os.path.join(lPath, uuidPatern)))
+            self.log.debug("nfs uuids: %s", uuids)
+        elif domType is sd.GLUSTERFS_DOMAIN:
+            glusterDomPath = os.path.join(sd.GLUSTERSD_DIR, "*")
+            uuids = tuple(sdUUID for sdUUID, domainPath in
+                          nfsSD.fileSD.scanDomains(glusterDomPath))
+        elif domType is sd.LOCALFS_DOMAIN:
+            lPath = conObj._path
+            self.log.debug("local lpath: %s", lPath)
+            uuids = tuple(os.path.basename(d) for d in
+                          glob.glob(os.path.join(lPath, uuidPatern)))
+            self.log.debug("local uuids: %s", uuids)
+        else:
+            self.log.warn("domType %s does not support prefetch")
+            uuids = tuple()
+
+        findMethod = self.__getSDTypefindMethod(domType)
+        return dict.fromkeys(uuids, findMethod)
+
     @deprecated
     @public(logger=logged(printers={'conList': connectionListPrinter}))
     def connectStorageServer(self, domType, spUUID, conList, options=None):
@@ -2254,11 +2295,16 @@
             try:
                 self._connectStorageOverIser(conDef, conObj, domType)
                 conObj.connect()
-                status = 0
             except Exception as err:
                 self.log.error(
                     "Could not connect to storageServer", exc_info=True)
                 status, _ = self._translateConnectionError(err)
+            else:
+                status = 0
+                doms = self.__prefetchDomains(domType, conObj)
+                sdCache.knownSDs.update(doms)
+
+            self.log.debug("knownSDs: %s", sdCache.knownSDs)
 
             res.append({'id': conDef["id"], 'status': status})
 
@@ -2481,6 +2527,10 @@
                 domVersion)
         else:
             raise se.StorageDomainTypeError(storageType)
+
+        findMethod = self.__getSDTypefindMethod(storageType)
+        sdCache.knownSDs[sdUUID] = findMethod
+        self.log.debug("knownSDs: %s", sdCache.knownSDs)
         sdCache.manuallyAddDomain(newSD)
 
     @public
diff --git a/vdsm/storage/localFsSD.py b/vdsm/storage/localFsSD.py
index fac54f9..1066fb5 100644
--- a/vdsm/storage/localFsSD.py
+++ b/vdsm/storage/localFsSD.py
@@ -102,34 +102,13 @@
     @staticmethod
     def findDomainPath(sdUUID):
         for tmpSdUUID, domainPath in fileSD.scanDomains("_*"):
-            if tmpSdUUID == sdUUID and isLocalFsDomain(domainPath):
+            if tmpSdUUID == sdUUID:
                 return domainPath
         else:
             raise se.StorageDomainDoesNotExist(sdUUID)
 
     def getRealPath(self):
         return os.readlink(self.mountpoint)
-
-
-def isLocalFsDomain(domainPath):
-    """This ancillary function differentiates local and mounted SD's.
-
-    Assumed that a local SD can't be mounted.
-    mounted: nfs, posixFS
-    local: a link to a local dir in the /rhev/datacenter
-    """
-    mtab = open("/etc/mtab", "r").readlines()
-    for mEntry in mtab:
-        mPoint = mEntry.split()[1]
-        if mPoint == '/':
-            continue
-        elif mPoint in domainPath:
-            # This is a mounted domain therefore not exists as a local SD.
-            isLocal = False
-            break
-    else:
-        isLocal = True
-    return isLocal
 
 
 def findDomain(sdUUID):
diff --git a/vdsm/storage/sdc.py b/vdsm/storage/sdc.py
index 4ead0b5..39e19dd 100644
--- a/vdsm/storage/sdc.py
+++ b/vdsm/storage/sdc.py
@@ -70,6 +70,7 @@
         self.__inProgress = set()
         self.__staleStatus = self.STORAGE_STALE
         self.storage_repo = storage_repo
+        self.knownSDs = {}  # {sdUUID: mod.findDomain}
 
     def invalidateStorage(self):
         with self._syncroot:
@@ -130,11 +131,28 @@
                 self._syncroot.notifyAll()
 
     def _findDomain(self, sdUUID):
+        try:
+            findMethod = self.knownSDs[sdUUID]
+        except KeyError:
+            self.log.error("looking for unfetched domain %s", sdUUID)
+            self._findUnfetchedDomain(sdUUID)
+        else:
+            try:
+                dom = findMethod(sdUUID)
+            except se.StorageDomainDoesNotExist:
+                self.log.error("prefetch domain %s not found", sdUUID,
+                               exc_info=True)
+            else:
+                return dom
+
+    def _findUnfetchedDomain(self, sdUUID):
         import blockSD
         import glusterSD
         import localFsSD
         import nfsSD
 
+        self.log.error("looking for unfetched domain %s", sdUUID)
+
         # The order is somewhat important, it's ordered
         # by how quickly get can find the domain. For instance
         # if an nfs mount is unavailable we will get stuck


--
To view, visit http://gerrit.ovirt.org/12869
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f2b19a566c659bac30a318d17cef929e0b2575b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Eduardo <ewarszaw at redhat.com>


More information about the vdsm-patches mailing list