Commit 13fc5780 authored by Anael Beutot's avatar Anael Beutot
Browse files

Updated subproc_call in DRBD job and DRBD allocator

parent 19a0126f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -715,8 +715,7 @@ class Handler(HostHandler):
            raise DRBDError('Cannot setup DRBD: volume does not exist')

        try:
            job = self.main.job_manager.create(DRBD, self.main.evloop,
                                               self.hypervisor.storage,
            job = self.main.job_manager.create(DRBD, self.hypervisor.storage,
                                               pool, volume)
        except Exception:
            logger.exception('Error while creating DRBD job')
+36 −33
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import os
import errno
import socket
import logging
from functools import partial
from os.path import exists as path_exists
from time import sleep
from hashlib import md5
@@ -590,9 +591,10 @@ class DRBDAllocator(object):
    #: maximum number of DRBD devices
    MINOR_MAX = 100

    def __init__(self):
    def __init__(self, main_loop):
        self.volumes = set()

        self.subproc_call = partial(subproc_call, main_loop)
        self.reload_kernel_module()

    def new_volume(self):
@@ -611,7 +613,7 @@ class DRBDAllocator(object):
        # FIXME find an other way to set parameters to drbd module
        # try to remove kernel module
        try:
            subproc_call([self.RMMOD, 'drbd'])
            self.subproc_call([self.RMMOD, 'drbd'])
        except CalledProcessError:
            # this is not an error if drbd module wasn't loaded
            if 'drbd' in open('/proc/modules').read():
@@ -623,7 +625,7 @@ class DRBDAllocator(object):
            # we set usermode helper to bin true because by default, the module
            # is calling some drbd helpers that returns non 0 value and make the
            # synchronisation halt.
            subproc_call([self.MODPROBE, 'drbd',
            self.subproc_call([self.MODPROBE, 'drbd',
                          'minor_count=%d' % self.MINOR_MAX,
                          'usermode_helper=/bin/true'])
        except CalledProcessError:
@@ -639,10 +641,9 @@ class DRBD(object):
    DRBD_TIMEOUT = '30'
    DRBD_RATE = '50000'

    def __init__(self, job_manager, ev_loop, storage_index, lvm_pool, lvm_volume):
    def __init__(self, job_manager, storage_index, lvm_pool, lvm_volume):
        """
        :param job_manager: :class:`JobManager` instance
        :param ev_loop: ev loop instance
        :param storage_index: :class:`StorageIndex` instance
        :param lvm_pool: :class:`Storage` instance
        :param lvm_volume: :class:`Volume` instance
@@ -650,7 +651,9 @@ class DRBD(object):
        #: job id
        self.id = job_manager.job_id.next()

        self.allocator = DRBDAllocator()
        self.subproc_call = partial(subproc_call, job_manager.main)

        self.allocator = DRBDAllocator(job_manager.main)

        # define a set of states
        self.state = 'INIT'
@@ -682,16 +685,16 @@ class DRBD(object):
    def cleanup(self):
        # reset DM to initial state
        try:
            table = subproc_call([self.DMSETUP, 'table', self.volume.path])
            table = self.subproc_call([self.DMSETUP, 'table', self.volume.path])
        except CalledProcessError:
            logger.error('Error while getting table of VM LV')
        else:
            if table != self.dm_table:
                try:
                    subproc_call([self.DMSETUP, 'load', self.volume.path],
                    self.subproc_call([self.DMSETUP, 'load', self.volume.path],
                                      self.dm_table)
                    subproc_call([self.DMSETUP, 'suspend', self.volume.path])
                    subproc_call([self.DMSETUP, 'resume', self.volume.path])
                    self.subproc_call([self.DMSETUP, 'suspend', self.volume.path])
                    self.subproc_call([self.DMSETUP, 'resume', self.volume.path])
                except CalledProcessError:
                    logger.error('Error while loading back VM LV table')
                    # FIXME this is kind of critical, we should tell the user to
@@ -701,22 +704,22 @@ class DRBD(object):
        # if path_exists(self.drbd_path):
        if self.drbd_id is not None:
            try:
                subproc_call([self.DRBDSETUP, self.drbd_path, 'disconnect'])
                self.subproc_call([self.DRBDSETUP, self.drbd_path, 'disconnect'])
            except CalledProcessError:
                logger.error('Error while disconnecting DRBD device %s',
                             self.drbd_path)
            try:
                subproc_call([self.DRBDSETUP, self.drbd_path, 'secondary'])
                self.subproc_call([self.DRBDSETUP, self.drbd_path, 'secondary'])
            except CalledProcessError:
                logger.error('Error while switching DRBD device to secondary'
                             ' (%s)', self.drbd_path)
            try:
                subproc_call([self.DRBDSETUP, self.drbd_path, 'detach'])
                self.subproc_call([self.DRBDSETUP, self.drbd_path, 'detach'])
            except CalledProcessError:
                logger.error('Error while detaching DRBD device %s',
                             self.drbd_path)
            try:
                subproc_call([self.DRBDSETUP, self.drbd_path, 'down'])
                self.subproc_call([self.DRBDSETUP, self.drbd_path, 'down'])
            except CalledProcessError:
                logger.error('Error while bringing down DRBD device %s',
                             self.drbd_path)
@@ -742,7 +745,7 @@ class DRBD(object):
        # remove copy DM
        if path_exists('/dev/mapper/' + self.dm_copy):
            try:
                subproc_call([self.DMSETUP, 'remove', self.dm_copy])
                self.subproc_call([self.DMSETUP, 'remove', self.dm_copy])
            except CalledProcessError:
                logger.error('Error while removing DM copy')
            self.dm_table = None
@@ -763,7 +766,7 @@ class DRBD(object):
        logger.debug('Create a copy DM of the LV')
        # get LV table
        try:
            self.dm_table = subproc_call([self.DMSETUP, 'table',
            self.dm_table = self.subproc_call([self.DMSETUP, 'table',
                                          '--showkeys', self.volume.path])
        except CalledProcessError:
            logger.error('Cannot get DM table of VM LV')
@@ -771,7 +774,7 @@ class DRBD(object):
        # create new DM
        logger.debug('Got table of LV "%s"', self.dm_table)
        try:
            subproc_call([self.DMSETUP, 'create', self.dm_copy], self.dm_table)
            self.subproc_call([self.DMSETUP, 'create', self.dm_copy], self.dm_table)
        except CalledProcessError:
            logger.error('Cannot create copy DM of LV with table "%s"',
                         self.dm_table)
@@ -783,18 +786,18 @@ class DRBD(object):
        self.drbd_path = '/dev/drbd%d' % self.drbd_id
        # wipe drbd metadata (just in case)
        try:
            subproc_call([self.DRBDMETA, '--force', self.drbd_path,
            self.subproc_call([self.DRBDMETA, '--force', self.drbd_path,
                          'v08', self.meta_volume.path, '0', 'wipe-md'])
        except CalledProcessError:
            pass
        try:
            subproc_call([self.DRBDMETA, '--force', self.drbd_path,
            self.subproc_call([self.DRBDMETA, '--force', self.drbd_path,
                          'v08', self.meta_volume.path, '0', 'create-md'])
        except CalledProcessError:
            logger.error('Cannot create DRBD external metadata on device')
            raise DRBDError('Cannot create DRBD metadata')
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'disk',
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'disk',
                          '/dev/mapper/%s' % self.dm_copy,
                          self.meta_volume.path,
                         '0', '--create-device'])
@@ -813,7 +816,7 @@ class DRBD(object):
        logger.debug('Setup networking for DRBD')
        # connect to remote node
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'net',
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'net',
                          '0.0.0.0:%d' % self.drbd_port,
                          '%s:%d' % (remote_addr, remote_port),
                          'C', '-m', '-S', '10000000'])
@@ -824,7 +827,7 @@ class DRBD(object):
        sleep(.5)  # FIXME
        logger.debug('Set up bandwidth limit')
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'syncer', '-r',
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'syncer', '-r',
                          self.DRBD_RATE])
        except CalledProcessError:
            logger.error('Cannot set bandwidth rate limit on DRBD')
@@ -836,7 +839,7 @@ class DRBD(object):
        self.state = 'WAIT PEER CONNECT'
        sleep(.5)  # FIXME
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'wait-connect',
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'wait-connect',
                          '-t', self.DRBD_TIMEOUT,
                          '-d', self.DRBD_TIMEOUT,
                          '-o', self.DRBD_TIMEOUT])
@@ -851,7 +854,7 @@ class DRBD(object):
    def switch_primary(self):
        logger.debug('Switch DRBD %s in primary mode', self.drbd_path)
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'primary', '-o'])
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'primary', '-o'])
        except CalledProcessError:
            logger.error('Error while switching to primary role (%s)',
                         self.drbd_path)
@@ -862,7 +865,7 @@ class DRBD(object):
    def switch_secondary(self):
        logger.debug('Switch DRBD %s in secondary mode', self.drbd_path)
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'secondary'])
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'secondary'])
        except CalledProcessError:
            logger.error('Error while switching to secondary role (%s)',
                         self.drbd_path)
@@ -876,7 +879,7 @@ class DRBD(object):

        logger.debug('Wait sync %s', self.drbd_path)
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'wait-sync'])
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'wait-sync'])
        except CalledProcessError:
            logger.error('Error while waiting for synchronisation of DRBD'
                         ' device (%s)', self.drbd_path)
@@ -886,7 +889,7 @@ class DRBD(object):

    def disconnect(self):
        try:
            subproc_call([self.DRBDSETUP, self.drbd_path, 'disconnect'])
            self.subproc_call([self.DRBDSETUP, self.drbd_path, 'disconnect'])
        except CalledProcessError:
            logger.error('Error while disconnecting DRBD device %s',
                         self.drbd_path)
@@ -897,7 +900,7 @@ class DRBD(object):
    def status(self):
        """DRBD status."""
        try:
            out = subproc_call([self.DRBDSETUP, self.drbd_path, 'status'])
            out = self.subproc_call([self.DRBDSETUP, self.drbd_path, 'status'])
        except CalledProcessError:
            logger.error('Error while getting DRBD status (%s)', self.drbd_path)
            raise DRBDError('Status: error while executing DRBD status')
@@ -923,18 +926,18 @@ class DRBD(object):
        logger.debug('DRBD takeover %s', self.drbd_path)
        assert self.drbd_table is not None
        try:
            subproc_call([self.DMSETUP, 'load', self.volume.path],
            self.subproc_call([self.DMSETUP, 'load', self.volume.path],
                              self.drbd_table)
        except CalledProcessError:
            logger.error('Error while loading new table for VM LV')
            raise DRBDError('Takeover: cannot load DM table')
        try:
            subproc_call([self.DMSETUP, 'suspend', self.volume.path])
            self.subproc_call([self.DMSETUP, 'suspend', self.volume.path])
        except CalledProcessError:
            logger.error('Error while suspending VM LV')
            raise DRBDError('Takeover: cannot suspend DM')
        try:
            subproc_call([self.DMSETUP, 'resume', self.volume.path])
            self.subproc_call([self.DMSETUP, 'resume', self.volume.path])
        except CalledProcessError:
            logger.error('Error while resuming VM LV')
            raise DRBDError('Takeover: cannot resume DM')