Yeela Kaplan has uploaded a new change for review.

Change subject: mount: Reassign mount specification in case of backup option
......................................................................

mount: Reassign mount specification in case of backup option

When using glusterfs volumes the backup option
'backupvolfile-server' allows mount to an alternative volume
when mount source not available.

Change-Id: I3166c6863dffa297bc0adcdeb4c22f810d18de8e
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=922744
Signed-off-by: Yeela Kaplan <[email protected]>
---
M vdsm/storage/mount.py
M vdsm/storage/storageServer.py
2 files changed, 44 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/34/16534/1

diff --git a/vdsm/storage/mount.py b/vdsm/storage/mount.py
index 90cacc7..8cade18 100644
--- a/vdsm/storage/mount.py
+++ b/vdsm/storage/mount.py
@@ -187,6 +187,15 @@
     raise OSError(errno.ENOENT, 'device %s not mounted' % device)
 
 
+def _getRecord(spec, file):
+    for record in _iterMountRecords():
+        if (record.fs_spec == spec and record.fs_file == file):
+            return record
+
+    raise OSError(errno.ENOENT,
+                  "Mount of `%s` at `%s` does not exist" % (spec, file))
+
+
 class Mount(object):
     def __init__(self, fs_spec, fs_file):
         self.fs_spec = normpath(fs_spec)
@@ -261,14 +270,7 @@
         return True
 
     def getRecord(self):
-        for record in _iterMountRecords():
-            if (record.fs_spec == self.fs_spec and
-                    record.fs_file == self.fs_file):
-                return record
-
-        raise OSError(errno.ENOENT,
-                      "Mount of `%s` at `%s` does not exist" %
-                      (self.fs_spec, self.fs_file))
+        return _getRecord(self.fs_spec, self.fs_file)
 
     def __repr__(self):
         return ("<Mount fs_spec='%s' fs_file='%s'>" %
diff --git a/vdsm/storage/storageServer.py b/vdsm/storage/storageServer.py
index 023f607..515ebd9 100644
--- a/vdsm/storage/storageServer.py
+++ b/vdsm/storage/storageServer.py
@@ -197,14 +197,14 @@
                             self._remotePath.replace("_",
                                                      "__").replace("/", "_"))
 
-    def connect(self):
+    def createConnection(self):
         if self._mount.isMounted():
             return
 
         fileUtils.createdir(self._getLocalPath())
 
         try:
-            self._mount.mount(self.options, self._vfsType)
+            self._mount.mount(self.options, self.vfsType)
         except MountError as e:
             self.log.error("Mount failed: %s", e, exc_info=True)
             try:
@@ -214,17 +214,21 @@
                               self._getLocalPath(), exc_info=True)
             raise e
 
-        else:
+    def validateConnection(self):
+        try:
+            fileSD.validateDirAccess(
+                self.getMountObj().getRecord().fs_file)
+        except se.StorageServerAccessPermissionError as e:
             try:
-                fileSD.validateDirAccess(
-                    self.getMountObj().getRecord().fs_file)
-            except se.StorageServerAccessPermissionError as e:
-                try:
-                    self.disconnect()
-                except OSError:
-                    self.log.warn("Error while disconnecting after access"
-                                  "problem", exc_info=True)
-                raise e
+                self.disconnect()
+            except OSError:
+                self.log.warn("Error while disconnecting after access"
+                              "problem", exc_info=True)
+            raise e
+
+    def connect(self):
+        self.createConnection()
+        self.validateConnection()
 
     def isConnected(self):
         return self._mount.isMounted()
@@ -255,6 +259,24 @@
     def getLocalPathBase(cls):
         return os.path.join(MountConnection.getLocalPathBase(), "glusterSD")
 
+    def updateBackup(self):
+        if self.options and not self.isConnected():
+            for opt in self.options.split(','):
+                if opt.strip().startswith("backupvolfile-server"):
+                    backupSpec = opt.split('=', 1)[1].strip()
+                    try:
+                        mount._getRecord(backupSpec, self._mount.fs_file)
+                    except OSError as e:
+                        self.log.warning("Mount of backup failed: %s", e)
+                    else:
+                        self._mount.fs_spec = backupSpec
+                    return
+
+    def connect(self):
+        self.createConnection()
+        self.updateBackup()
+        self.validateConnection()
+
 
 class NFSConnection(object):
     DEFAULT_OPTIONS = ["soft", "nosharecache"]


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3166c6863dffa297bc0adcdeb4c22f810d18de8e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yeela Kaplan <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to