Example #1
0
 def undo(self):
     path = getMirrorDevPath(self.lvolid)
     assert(len(self.components) > 0)
     if os.path.exists(path):
         executecommand("mdadm -S %s" % path)
         executecommand("rm -f %s" % path)
     self.path = None
Example #2
0
 def _do(self):
     assert(len(self.components) > 0)
     path = getMirrorDevPath(self.lvolid)
     if not os.path.exists(path):
         do_assemble = False
         mirrordevs = ""
         for c in self.components:
             blockdev_getsize(c.path) # XXX is this necessary?
             if c.mirror_status == MIRROR_STATUS['ALLOCATED']:
                 mirrordevs += " " + c.path
             elif c.mirror_status == MIRROR_STATUS['INSYNC']:
                 mirrordevs += " " + c.path
                 do_assemble = True
         mdcommand = ""
         if do_assemble:
             mdcommand = "mdadm --assemble %s %s %s" % \
                 (path, MDADM_ASSEMBLE_OPTIONS, mirrordevs)
             executemdadm(mdcommand)
         else: # all extents are ALLOCATED. do --create
             mdcommand = \
                 "mdadm --create %s %s --assume-clean --raid-devices=%d %s" \
                     % (path, MDADM_CREATE_OPTIONS, len(self.components), \
                     mirrordevs)
             executemdadm(mdcommand)
         blockdev_getsize(path) # XXX is this necessary?
     self.path = path
Example #3
0
 def __mirror_worker(self, eventid, mirrorid, add_lvolstruct, remove_lvolstruct):
     class MdadmNode(mynode.MyNode):
         def __init__(self, op, mirrordev, component):
             self.md_op = op
             self.md_mirrordev = mirrordev
             self.md_component = component
             mynode.MyNode.__init__(self, "mdadm:%s:%s:%s" % \
                 (op, mirrordev, component))
         def do(self):
             try:
                 executecommand("mdadm --manage --%s %s %s" % \
                     (self.md_op, self.md_mirrordev, \
                     self.md_component))
             except:
                 if self.md_op == "fail" or self.md_op == "remove":
                     # pass through dext remove.
                     # if fail/remove fail by already removed, it is OK and dext remove should be OK.
                     # otherwise dext remove will fail and return error to the caller
                     return
                 else:
                     raise
     def get_dext_path_from_lvolstruct(l):
         return getDextDevPath(l['lvolspec']['ssvrid'], l['lvolid'])
     failed = []
     try:
         mirrordev = getMirrorDevPath(mirrorid)
         add_path = get_dext_path_from_lvolstruct(add_lvolstruct)
         mdadd_node = MdadmNode("add", mirrordev, add_path)
         add_nodes = hsvr_dag.create_dag_from_lvolstruct(add_lvolstruct, \
             False)
         for n in add_nodes:
             mdadd_node.add_antecedent(n)
         remove_nodes = []
         if remove_lvolstruct['lvolid'] != 0:
             remove_path = get_dext_path_from_lvolstruct(remove_lvolstruct)
             if os.path.exists(remove_path):
                 mdfail_node = MdadmNode("fail", mirrordev, remove_path)
                 mdremove_node = MdadmNode("remove", mirrordev, remove_path)
             else:
                 mdfail_node = mynode.MyNode("mdfail_dummy")
                 mdremove_node = mynode.MyNode("mdremove_dummy")
             mdremove_node.add_antecedent(mdfail_node)
             if remove_lvolstruct['lvolid'] != add_lvolstruct['lvolid']:
                 remove_nodes = hsvr_dag.create_dag_from_lvolstruct( \
                     remove_lvolstruct, True)
                 for n in remove_nodes:
                     n.add_antecedent(mdremove_node)
             nodes = add_nodes + remove_nodes + \
                 [mdfail_node, mdadd_node, mdremove_node]
             mdadd_node.add_antecedent(mdremove_node)
         else: # add only
             nodes = add_nodes + [mdadd_node]
         def replace_do(n):
             if not n in remove_nodes:
                 mynode.mynode_do(n)
             else:
                 mynode.mynode_undo(n)
         def replace_undo(n):
             if not n in remove_nodes:
                 mynode.mynode_undo(n)
         failed = dag.dag_execute(nodes, replace_do, replace_undo, \
             self.dag_worker, mydaglogger)
         for n, ei in failed:
             t, v, tr = ei
             raise t, v
     except Exception:
         self.event_record.set_event_status_and_result(eventid, EVENT_STATUS['ERROR'], \
             500, needlock = True)
         if failed:
             for n, ei in failed:
                 t, v, tr = ei
                 logger.error(traceback.format_exception(t, v, tr))
         logger.error(traceback.format_exc())
     return 0