Commit 9bcbc99b authored by Thibault VINCENT's avatar Thibault VINCENT
Browse files

various drbd changes

parent 009e5e45
Loading
Loading
Loading
Loading
+22 −20
Original line number Diff line number Diff line
@@ -124,7 +124,6 @@ class DRBD(object):
    def destroy(self):
        '''
        '''
        with self._mutex.write:
        # bring down drbd device
        Exec.silent([self.DRBDSETUP,
                     self._path,
@@ -179,6 +178,10 @@ class DRBD(object):
            status['rdisk'] = self.DSTATES.get(xres.getAttribute('ds2'))
            status['role']  = self.NROLES.get(xres.getAttribute('ro1'))
            status['rrole'] = self.NROLES.get(xres.getAttribute('ro2'))
            if xres.hasAttribute('resynced_percent'):
                status['percent'] = xres.getAttribute('resynced_percent')
            else:
                status['percent'] = None
            return status
        except Exception as err:
            return {'conn' : None}
@@ -258,7 +261,6 @@ class DRBD(object):
    def disconnect(self):
        '''
        '''
        with self._mutex.write:
        # disconnect from remote node
        Exec.silent([self.DRBDSETUP,
                     self._path,
@@ -321,7 +323,7 @@ class DRBD(object):
            # FIXME magic sleep, seems to be mandatory
            sleep(0.5)
            status = self.status()
            print status, self.DSTATES.UP_TO_DATE_str
            if (rc != 0 or not status or
                            status['disk'] != self.DSTATES.UP_TO_DATE):
                        ('disk' in status and
                            status['disk'] != self.DSTATES.UP_TO_DATE)):
                raise DRBDError('synchronization failed')
+13 −9
Original line number Diff line number Diff line
@@ -946,17 +946,22 @@ class NodeHandler(RpcHandler):
        job.drbd_takeover(state)
    
    @pure
    def drbd_sync(self, res):
    def drbd_sync_status(self, res):
        '''
        Wait for the live copy engine to complete a pending initial disk
        synchronization.
        Get status information about a running sync
        '''
        # facilities
        jobmgr = self._host_handle.jobmgr
        # get the job
        job = jobmgr.get_job(res['jid'])
        # wait for sync completion
        job.drbd_waitsync()
        # get drbd status
        status = job.drbd_status()
        # return status
        return {
            'done' : status['disk'] == job._drbd.DSTATES.UP_TO_DATE,
            'completion' : status['percent'],
            'speed' : None,
            }
    
    @pure
    def drbd_shutdown(self, res):
@@ -965,10 +970,9 @@ class NodeHandler(RpcHandler):
        '''
        # facilities
        jobmgr = self._host_handle.jobmgr
        # get the job
        job = jobmgr.get_job(res['jid'])
        # FIXME
        job.drbd_stop()
        # cancel the job so it can clean itself
        # FIXME: check type, we don't want to cancel anything
        jobmgr.cancel(res['jid'])
    
    ##################################
    #   Job management
+12 −10
Original line number Diff line number Diff line
@@ -610,8 +610,14 @@ class DrbdCopyJob(BaseJob):
        '''
        '''
        # release some pending calls
        self._event_connected_ready.set()
        self._event_connected.set()
        self._event_rolechosen_ready.set()
        self._event_rolechosen.set()
        self._event_sleep_ready.set()
        self._event_sleep.set()
        # disconnect the node
        self._drbd.disconnect()
    
    def _cleanup(self):
        '''
@@ -731,7 +737,7 @@ class DrbdCopyJob(BaseJob):
                                                        self._drbd.get_path())
                self._drbd.setup(self._copy_path, self._meta_path)
                self._drbd_table = '0 %d linear %s 0' % (self._source_size / 512
                                                        , self._source_path)
                                                    , self._drbd.get_path())
            except Exception as err:
                self._log.append('failed to configure the drbd device')
                raise err
@@ -772,6 +778,8 @@ class DrbdCopyJob(BaseJob):
            self._log.append('waiting for initial device sync')
            self._drbd.wait_sync()
        except Exception as err:
            import traceback
            traceback.print_exc()
            self._log.append('failed to sync the DRBD')
            raise err
        else:
@@ -828,7 +836,7 @@ class DrbdCopyJob(BaseJob):
        self._log.append('waiting for sync')
        # wait for initial sync and setup to be completed
        self._event_sleep_ready.wait()
        # wait for DRBD sync
        # wait for additionnal DRBD sync
        with self._mutex_step:
            self._drbd.wait_sync()
    
@@ -849,16 +857,10 @@ class DrbdCopyJob(BaseJob):
            #
            self._lvm.dm_set_table(self._source_dm, table)
    
    def drbd_stop(self):
    def drbd_status(self):
        '''
        '''
        self._event_sleep_ready.wait(5) # to fix thread sync issue
        if self._event_sleep_ready.is_set():
            with self._mutex_step:
                # unlock job termination
                self._event_sleep.set()
        else:
            raise DrbdCopyJobError('can\'t stop now')
        return self._drbd.status()


class TCPTunnelJob(BaseJob):