Change in vdsm[ovirt-3.5-gluster]: gluster: verbs to override/reset cli snapshot scheduling.

dnarayan at redhat.com dnarayan at redhat.com
Sat Jun 13 14:20:12 UTC 2015


Hello Bala.FA, Dan Kenigsberg,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/42302

to review the following change.

Change subject: gluster: verbs to override/reset cli snapshot scheduling.
......................................................................

gluster: verbs to override/reset cli snapshot scheduling.

This patch adds two verbs to override/reset gluster cli
based snapshot scheduling. The verbs are as follows:

*snapshotScheduleOverride: This verb sets the snapshot
scheduling flag in meta-volume to ovirt, this means
the snapshot scheduling job will be taken care by
engine and the gluster won't be able to schedule
snapshots. This has optional argument force. With
force option, any existing gluster schedules will
be disabled.

*snapshotScheduleReset: This verb sets the snapshot
scheduling flag in meta-volume to none, this means
the snapshot scheduling job will no longer be taken
care by engine.

Change-Id: Iff8f21593921bac18950a9ee42bb3972d278f7aa
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1230342
Signed-off-by: Darshan N <dnarayan at redhat.com>
Reviewed-on: https://gerrit.ovirt.org/40141
Reviewed-by: Bala.FA <barumuga at redhat.com>
Continuous-Integration: Jenkins CI
Reviewed-by: Shubhendu Tripathi <shtripat at redhat.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M client/vdsClientGluster.py
M vdsm.spec.in
M vdsm/gluster/api.py
M vdsm/gluster/apiwrapper.py
M vdsm/gluster/exception.py
M vdsm/rpc/vdsmapi-gluster-schema.json
6 files changed, 123 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/42302/1

diff --git a/client/vdsClientGluster.py b/client/vdsClientGluster.py
index 668babe..a4bce63 100644
--- a/client/vdsClientGluster.py
+++ b/client/vdsClientGluster.py
@@ -724,7 +724,19 @@
         metaVolumeName = params.get('metaVolumeName', '')
 
         status = self.s.glusterMetaVolumeMount(metaVolumeName)
+        pp.pprint(status)
+        return status['status']['code'], status['status']['message']
 
+    def do_glusterSnapshotScheduleOverride(self, args):
+        params = self._eqSplit(args)
+        force = (params.get('force', 'no').upper() == 'YES')
+
+        status = self.s.glusterSnapshotScheduleOverride(force)
+        pp.pprint(status)
+        return status['status']['code'], status['status']['message']
+
+    def do_glusterSnapshotScheduleReset(self, args):
+        status = self.s.glusterSnapshotScheduleReset()
         pp.pprint(status)
         return status['status']['code'], status['status']['message']
 
@@ -1230,5 +1242,15 @@
              serv.do_glusterMetaVolumeMount,
              ('[volumeName=<volume name>]',
               'mount the meta-volume'
+              )),
+         'glusterSnapshotScheduleOverride': (
+             serv.do_glusterSnapshotScheduleOverride,
+             ('[force={yes|no}]\n\t',
+              'override gluster snapshot scheduling'
+              )),
+         'glusterSnapshotScheduleReset': (
+             serv.do_glusterSnapshotScheduleReset,
+             ('',
+              'Reset gluster snapshot scheduling'
               ))
          }
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 0414056..b2a514a 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -289,7 +289,7 @@
 
 # GlusterFS client-side RPMs needed for Gluster SD
 %if 0%{?with_gluster}
-Requires: glusterfs >= 3.6.999
+Requires: glusterfs >= 3.7.1
 Requires: glusterfs-cli
 Requires: glusterfs-api
 Requires: glusterfs-fuse
diff --git a/vdsm/gluster/api.py b/vdsm/gluster/api.py
index bc1fdcf..c007b28 100644
--- a/vdsm/gluster/api.py
+++ b/vdsm/gluster/api.py
@@ -19,6 +19,7 @@
 #
 
 import errno
+import fcntl
 import os
 from functools import wraps
 from vdsm.define import doneCode
@@ -38,8 +39,17 @@
 MOUNT_BROKER_ROOT = "/var/mountbroker-root"
 META_VOLUME = "gluster_shared_storage"
 META_VOL_MOUNT_POINT = "/var/run/gluster/shared_storage"
+LOCK_FILE_DIR = META_VOL_MOUNT_POINT + "/snaps/lock_files"
+LOCK_FILE = LOCK_FILE_DIR + "/lock_file"
+SNAP_SCHEDULER_FLAG_FILE = META_VOL_MOUNT_POINT + "/snaps/current_scheduler"
 FS_TYPE = "glusterfs"
+SNAP_SCHEDULER_ALREADY_DISABLED_RC = 7
 
+
+_snapSchedulerPath = utils.CommandPath(
+    "snap_scheduler.py",
+    "/usr/sbin/snap_scheduler.py",
+)
 
 GLUSTER_RPM_PACKAGES = (
     ('glusterfs', ('glusterfs',)),
@@ -208,6 +218,45 @@
     if rc:
         raise ge.GlusterMetaVolumeMountFailedException(
             rc, out, err)
+    return True
+
+
+ at makePublic
+def snapshotScheduleDisable():
+    command = [_snapSchedulerPath.cmd, "disable_force"]
+    rc, out, err = utils.execCmd(command)
+    if rc not in [0, SNAP_SCHEDULER_ALREADY_DISABLED_RC]:
+        raise ge.GlusterDisableSnapshotScheduleFailedException(
+            rc)
+    return True
+
+
+ at makePublic
+def snapshotScheduleFlagUpdate(value):
+    if not os.path.exists(LOCK_FILE_DIR):
+        try:
+            os.makedirs(LOCK_FILE_DIR, 0o755)
+        except OSError as e:
+            raise ge.GlusterSnapshotScheduleFlagUpdateFailedException(
+                err=[str(e)])
+
+    try:
+        f = os.open(LOCK_FILE, os.O_CREAT | os.O_RDWR | os.O_NONBLOCK)
+        try:
+            fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
+            safeWrite(SNAP_SCHEDULER_FLAG_FILE, value)
+            fcntl.flock(f, fcntl.LOCK_UN)
+        except IOError as e:
+            os.close(f)
+            raise ge.GlusterSnapshotScheduleFlagUpdateFailedException(
+                err=["unable to get the lock", str(e)])
+        except OSError as e:
+            os.close(f)
+            raise ge.GlusterSnapshotScheduleFlagUpdateFailedException(
+                err=[str(e)])
+    except (IOError, OSError) as e:
+        raise ge.GlusterSnapshotScheduleFlagUpdateFailedException(
+            err=[str(e)])
     return True
 
 
@@ -688,6 +737,16 @@
     def metaVolumeMount(self, metaVolumeName=META_VOLUME, options=None):
         self.svdsmProxy.glusterMountMetaVolume(metaVolumeName)
 
+    @exportAsVerb
+    def snapshotScheduleOverride(self, force=True, options=None):
+        self.svdsmProxy.glusterSnapshotScheduleFlagUpdate("ovirt")
+        if force:
+            self.svdsmProxy.glusterSnapshotScheduleDisable()
+
+    @exportAsVerb
+    def snapshotScheduleReset(self, options=None):
+        self.svdsmProxy.glusterSnapshotScheduleFlagUpdate("none")
+
 
 def getGlusterMethods(gluster):
     l = []
diff --git a/vdsm/gluster/apiwrapper.py b/vdsm/gluster/apiwrapper.py
index 26eba7a..4768a86 100644
--- a/vdsm/gluster/apiwrapper.py
+++ b/vdsm/gluster/apiwrapper.py
@@ -314,6 +314,12 @@
     def metaVolumeMount(self, metaVolumeName=META_VOLUME):
         return self._gluster.metaVolumeMount(metaVolumeName)
 
+    def snapshotScheduleOverride(self, force=True):
+        return self._gluster.snapshotScheduleOverride(force)
+
+    def snapshotScheduleReset(self):
+        return self._gluster.snapshotScheduleReset()
+
 
 class GlusterSnapshot(GlusterApiBase):
     def __init__(self):
diff --git a/vdsm/gluster/exception.py b/vdsm/gluster/exception.py
index 8a9f538..fb18177 100644
--- a/vdsm/gluster/exception.py
+++ b/vdsm/gluster/exception.py
@@ -564,6 +564,18 @@
     message = "Failed to Update fstab entry for meta-volume"
 
 
+class GlusterSnapshotScheduleFlagUpdateFailedException(
+        GlusterVolumeException):
+    code = 4577
+    message = "Failed to update snapshot schedule flag"
+
+
+class GlusterDisableSnapshotScheduleFailedException(
+        GlusterVolumeException):
+    code = 4578
+    message = "Failed to disable snapshot schedule through cli"
+
+
 # geo-replication
 class GlusterGeoRepException(GlusterException):
     code = 4200
diff --git a/vdsm/rpc/vdsmapi-gluster-schema.json b/vdsm/rpc/vdsmapi-gluster-schema.json
index c9dbc27..d83344c 100644
--- a/vdsm/rpc/vdsmapi-gluster-schema.json
+++ b/vdsm/rpc/vdsmapi-gluster-schema.json
@@ -2160,3 +2160,26 @@
 ##
 {'command': {'class': 'GlusterVolume', 'name': 'metaVolumeMount'},
  'data': {'*metaVolumeName': 'str'}}
+
+##
+# @GlusterVolume.snapshotScheduleOverride:
+#
+# overrides gluster snapshot scheduling.
+#
+# @force: #optional force override snapshot schedule
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'GlusterVolume',
+             'name': 'snapshotScheduleOverride'},
+ 'data': {'*force': 'bool'}}
+
+##
+# @GlusterVolume.snapshotScheduleReset:
+#
+# resets gluster snapshot scheduling.
+#
+# Since: 4.17.0
+##
+{'command': {'class': 'GlusterVolume',
+             'name': 'snapshotScheduleReset'}}


-- 
To view, visit https://gerrit.ovirt.org/42302
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff8f21593921bac18950a9ee42bb3972d278f7aa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.5-gluster
Gerrit-Owner: Darshan N <dnarayan at redhat.com>
Gerrit-Reviewer: Bala.FA <barumuga at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list