]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes: introduce 'canceled' state in clone op state machine
authorVenky Shankar <vshankar@redhat.com>
Tue, 14 Jan 2020 09:13:16 +0000 (04:13 -0500)
committerRamana Raja <rraja@redhat.com>
Thu, 19 Mar 2020 12:59:20 +0000 (18:29 +0530)
When fetching the next execution state, -EINTR jumps to 'canceled'
state signifying a canceled (interrupted) operation. Also include
a helper routine to check if a given state machine is in initial
state.

Signed-off-by: Venky Shankar <vshankar@redhat.com>
(cherry picked from commit ac9d697b1cdb93b4c7e532727b482cece3674155)

src/pybind/mgr/volumes/fs/operations/op_sm.py

index 9915005a8f35ae720e747a0386aeb642f4d1ae18..56d847e97aab2d89a25c66f61ecb562c4d90cc38 100644 (file)
@@ -7,6 +7,7 @@ class OpSm(object):
 
     FAILED_STATE = 'failed'
     FINAL_STATE  = 'complete'
+    CANCEL_STATE = 'canceled'
 
     OP_SM_SUBVOLUME = {
         INIT_STATE_KEY : FINAL_STATE,
@@ -14,8 +15,8 @@ class OpSm(object):
 
     OP_SM_CLONE = {
         INIT_STATE_KEY : 'pending',
-        'pending'           : ('in-progress', FAILED_STATE),
-        'in-progress'       : (FINAL_STATE, FAILED_STATE),
+        'pending'           : ('in-progress', (FAILED_STATE, CANCEL_STATE)),
+        'in-progress'       : (FINAL_STATE, (FAILED_STATE, CANCEL_STATE)),
     }
 
     STATE_MACHINES_TYPES = {
@@ -29,7 +30,15 @@ class OpSm(object):
 
     @staticmethod
     def is_failed_state(state):
-        return state == OpSm.FAILED_STATE
+        return state == OpSm.FAILED_STATE or state == OpSm.CANCEL_STATE
+
+    @staticmethod
+    def is_init_state(stm_type, state):
+        stm = OpSm.STATE_MACHINES_TYPES.get(stm_type, None)
+        if not stm:
+            raise OpSmException(-errno.ENOENT, "state machine type '{0}' not found".format(stm_type))
+        init_state = stm.get(OpSm.INIT_STATE_KEY, None)
+        return init_state == state
 
     @staticmethod
     def get_init_state(stm_type):
@@ -49,4 +58,9 @@ class OpSm(object):
         next_state = stm.get(current_state, None)
         if not next_state:
             raise OpSmException(-errno.EINVAL, "invalid current state '{0}'".format(current_state))
-        return next_state[0] if ret == 0 else next_state[1]
+        if ret == 0:
+            return next_state[0]
+        elif ret == -errno.EINTR:
+            return next_state[1][1]
+        else:
+            return next_state[1][0]