Exemplo n.º 1
0
def reset_sr(session, host_uuid, sr_uuid, is_sr_master):
    from vhdutil import LOCK_TYPE_SR
    from cleanup import LOCK_TYPE_RUNNING

    cleanup.abort(sr_uuid)

    gc_lock = lock.Lock(LOCK_TYPE_RUNNING, sr_uuid)
    sr_lock = lock.Lock(LOCK_TYPE_SR, sr_uuid)
    gc_lock.acquire()
    sr_lock.acquire()

    sr_ref = session.xenapi.SR.get_by_uuid(sr_uuid)

    host_ref = session.xenapi.host.get_by_uuid(host_uuid)
    host_key = "host_%s" % host_ref

    util.SMlog("RESET for SR %s (master: %s)" % (sr_uuid, is_sr_master))

    vdi_recs = session.xenapi.VDI.get_all_records_where( \
            "field \"SR\" = \"%s\"" % sr_ref)

    for vdi_ref, vdi_rec in vdi_recs.iteritems():
        vdi_uuid = vdi_rec["uuid"]
        sm_config = vdi_rec["sm_config"]
        if sm_config.get(host_key):
            util.SMlog("Clearing attached status for VDI %s" % vdi_uuid)
            session.xenapi.VDI.remove_from_sm_config(vdi_ref, host_key)
        if is_sr_master and sm_config.get("paused"):
            util.SMlog("Clearing paused status for VDI %s" % vdi_uuid)
            session.xenapi.VDI.remove_from_sm_config(vdi_ref, "paused")

    sr_lock.release()
    gc_lock.release()
Exemplo n.º 2
0
Arquivo: FileSR.py Projeto: falaa/sm
 def detach(self, sr_uuid):
     if self._checkmount():
         try:
             util.SMlog("Aborting GC/coalesce")
             cleanup.abort(self.uuid)
             os.chdir(SR.MOUNT_BASE)
             util.pread(["umount", self.path])
             os.rmdir(self.path)
         except Exception, e:
             raise xs_errors.XenError('SRInUse', opterr=str(e))
Exemplo n.º 3
0
 def detach(self, sr_uuid):
     if self._checkmount():
         try:
             util.SMlog("Aborting GC/coalesce")
             cleanup.abort(self.uuid)
             os.chdir(SR.MOUNT_BASE)
             util.pread(["umount", self.path])
             os.rmdir(self.path)
         except Exception, e:
             raise xs_errors.XenError('SRInUse', opterr=str(e))
Exemplo n.º 4
0
 def detach(self, sr_uuid):
     if not self.checkmount():
         return
     util.SMlog("Aborting GC/coalesce")
     cleanup.abort(self.uuid)
     # Change directory to avoid unmount conflicts
     os.chdir(SR.MOUNT_BASE)
     self.unmount(self.mountpoint, True)
     os.unlink(self.path)
     self.attached = False
Exemplo n.º 5
0
    def detach(self, sr_uuid):
        """Detach the SR: Unmounts and removes the mountpoint"""
        if not self._checkmount():
            return
        util.SMlog("Aborting GC/coalesce")
        cleanup.abort(self.uuid)

        # Change directory to avoid unmount conflicts
        os.chdir(SR.MOUNT_BASE)

        try:
            nfs.unmount(self.path, True)
        except nfs.NfsException, exc:
            raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
Exemplo n.º 6
0
    def detach(self, sr_uuid):
        """Detach the SR: Unmounts and removes the mountpoint"""
        if not self._checkmount():
            return
        util.SMlog("Aborting GC/coalesce")
        cleanup.abort(self.uuid)

        # Change directory to avoid unmount conflicts
        os.chdir(SR.MOUNT_BASE)

        try:
            nfs.unmount(self.path, True)
        except nfs.NfsException, exc:
            raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
Exemplo n.º 7
0
    def detach(self, sr_uuid):
        """Detach the SR: Unmounts and removes the mountpoint"""
        if not self._checkmount():
            return
        util.SMlog("Aborting GC/coalesce")
        cleanup.abort(self.uuid)

        # Change directory to avoid unmount conflicts
        os.chdir(SR.MOUNT_BASE)

        cmd = ["umount", self.path]
        try:
            ret = util.pread(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError("OCFSUnMount", opterr="Failed to umount FS. Errno is %d" % os.strerror(inst.code))
Exemplo n.º 8
0
Arquivo: FileSR.py Projeto: xcp-ng/sm
    def _kickGC(self):
        # don't bother if an instance already running (this is just an
        # optimization to reduce the overhead of forking a new process if we
        # don't have to, but the process will check the lock anyways)
        lockRunning = Lock(cleanup.LOCK_TYPE_RUNNING, self.uuid)
        if not lockRunning.acquireNoblock():
            if cleanup.should_preempt(self.session, self.uuid):
                util.SMlog(
                    "Aborting currently-running coalesce of garbage VDI")
                try:
                    if not cleanup.abort(self.uuid, soft=True):
                        util.SMlog("The GC has already been scheduled to "
                                   "re-start")
                except util.CommandException as e:
                    if e.code != errno.ETIMEDOUT:
                        raise
                    util.SMlog('failed to abort the GC')
                finally:
                    return
            else:
                util.SMlog("A GC instance already running, not kicking")
                return
        else:
            lockRunning.release()

        util.SMlog("Kicking GC")
        cleanup.gc(self.session, self.uuid, True)
Exemplo n.º 9
0
    def detach(self, sr_uuid):
        """Detach the SR: Unmounts and removes the mountpoint"""
        if not self._checkmount():
            return
        util.SMlog("Aborting GC/coalesce")
        cleanup.abort(self.uuid)

        # Change directory to avoid unmount conflicts
        os.chdir(SR.MOUNT_BASE)

        cmd = ['umount', self.path ]
        try:
             ret = util.pread(cmd)
        except util.CommandException, inst:
                raise xs_errors.XenError('OCFSUnMount', \
                      opterr='Failed to umount FS. Errno is %d' % \
                      os.strerror(inst.code))
Exemplo n.º 10
0
    def _kickGC(self):
        # don't bother if an instance already running (this is just an 
        # optimization to reduce the overhead of forking a new process if we 
        # don't have to, but the process will check the lock anyways)
        lockRunning = Lock(cleanup.LOCK_TYPE_RUNNING, self.uuid) 
        if not lockRunning.acquireNoblock():
            if cleanup.should_preempt(self.session, self.uuid):
                util.SMlog("Aborting currently-running coalesce of garbage VDI")
                cleanup.abort(self.uuid)
            else:
                util.SMlog("A GC instance already running, not kicking")
                return
        else:
            lockRunning.release()

        util.SMlog("Kicking GC")
        cleanup.gc(self.session, self.uuid, True)
Exemplo n.º 11
0
    def detach(self, sr_uuid):
        """Detach the SR: Unmounts and removes the mountpoint"""
        if not self.checkmount():
            return
        util.SMlog("Aborting GC/coalesce")
        cleanup.abort(self.uuid)

        # Change directory to avoid unmount conflicts
        os.chdir(SR.MOUNT_BASE)

        try:
            self.unmount(self.mountpoint, True)
            os.unlink(self.path)
        except SMBException as exc:
            raise xs_errors.XenError('SMBUnMount', opterr=exc.errstr)

        self.attached = False
Exemplo n.º 12
0
    def _kickGC(self):
        # don't bother if an instance already running (this is just an
        # optimization to reduce the overhead of forking a new process if we
        # don't have to, but the process will check the lock anyways)
        lockRunning = Lock(cleanup.LOCK_TYPE_RUNNING, self.uuid)
        if not lockRunning.acquireNoblock():
            if cleanup.should_preempt(self.session, self.uuid):
                util.SMlog(
                    "Aborting currently-running coalesce of garbage VDI")
                cleanup.abort(self.uuid)
            else:
                util.SMlog("A GC instance already running, not kicking")
                return
        else:
            lockRunning.release()

        util.SMlog("Kicking GC")
        cleanup.gc(self.session, self.uuid, True)
Exemplo n.º 13
0
    def detach(self, sr_uuid):
        if not self._checkmount():
            return
        cleanup.abort(self.uuid)
        try:
            # Change directory to avoid unmount conflicts
            os.chdir(SR.MOUNT_BASE)
            
            # unmount the device
            util.pread(["umount", self.path])

            # remove the mountpoint
            os.rmdir(self.path)
            self.path = None

            # deactivate SR
            try:
                cmd = ["lvchange", "-an", self.remotepath]
                util.pread2(cmd)
            except util.CommandException, inst:
                raise xs_errors.XenError('LVMUnMount', \
                      opterr='lvm -an failed errno is %d' % inst.code)

            self.attached = False
Exemplo n.º 14
0
 def _kickGC(self):
     # don't bother if an instance already running (this is just an
     # optimization to reduce the overhead of forking a new process if we
     # don't have to, but the process will check the lock anyways)
     lockRunning = Lock(cleanup.LOCK_TYPE_RUNNING, self.uuid)
     if not lockRunning.acquireNoblock():
         if cleanup.should_preempt(self.session, self.uuid):
             util.SMlog("Aborting currently-running coalesce of garbage VDI")
             try:
                 if not cleanup.abort(self.uuid, soft=True):
                     util.SMlog("The GC has already been scheduled to " "re-start")
             except util.CommandException, e:
                 if e.code != errno.ETIMEDOUT:
                     raise
                 util.SMlog("failed to abort the GC")
             finally:
Exemplo n.º 15
0
    def test_lock_not_released_by_abort_when_not_held(
            self,
            mock_abort,
            mock_sr):
        """
        If _abort returns False don't release lockActive and ensure that
        False returned by _abort is passed on.
        """
        self.setup_mock_sr(mock_sr)

        # Fake _abort returning False.
        mock_abort.return_value = False

        # Mock lock release function.
        cleanup.lockActive = TestRelease()
        cleanup.lockActive.release = mock.Mock(return_value=None)

        ret = cleanup.abort(mock_sr, False)

        # Make sure pass on False returned by _abort
        self.assertEquals(False, ret)

        # Make sure we did not release the lock as we don't have it.
        self.assertEquals(cleanup.lockActive.release.call_count, 0)
Exemplo n.º 16
0
    def test_lock_released_by_abort_when_held(
            self,
            mock_abort,
            mock_sr):
        """
        If _abort returns True make sure we release the lockActive which will
        have been held by _abort, also check that we return True.
        """
        self.setup_mock_sr(mock_sr)

        # Fake that abort returns True, so we hold lockActive.
        mock_abort.return_value = True

        # Setup mock of release function.
        cleanup.lockActive = TestRelease()
        cleanup.lockActive.release = mock.Mock(return_value=None)

        ret = cleanup.abort(mock_sr, False)

        # Pass on the return from _abort.
        self.assertEquals(True, ret)

        # We hold lockActive so make sure we release it.
        self.assertEquals(cleanup.lockActive.release.call_count, 1)