Ejemplo n.º 1
0
    def remove(self, lease_id):
        """
        Remove lease from index

        Raises:
        - NoSuchLease if lease was not found
        - OSError if I/O operation failed
        - sanlock.SanlockException if sanlock operation failed.
        """
        log.info("Removing lease %r in lockspace %r",
                 lease_id, self.lockspace)
        recnum = self._index.find_record(lease_id)
        if recnum == -1:
            raise se.NoSuchLease(lease_id)

        offset = lease_offset(recnum)
        record = Record(lease_id, offset, updating=True)
        self._write_record(recnum, record)

        # There is no way to remove a resource, so we write an invalid resource
        # with empty resource and lockspace values.
        # TODO: Use SANLK_WRITE_CLEAR, expected in rhel 7.4.
        sanlock.write_resource(
            "",
            "",
            [(self._file.name, offset)],
            align=self._alignment,
            sector=self._block_size)

        self._write_record(recnum, EMPTY_RECORD)
Ejemplo n.º 2
0
    def lookup(self, lease_id):
        """
        Lookup lease by lease_id and return LeaseInfo if found.

        Raises:
        - NoSuchLease if lease is not found or updating flag is set (legacy)
        - InvalidRecord if corrupted lease record is found
        - OSError if io operation failed
        """
        log.debug("Looking up lease %r in lockspace %r", lease_id,
                  self.lockspace)
        recnum = self._index.find_record(lease_id)
        if recnum == -1:
            raise se.NoSuchLease(lease_id)

        record = self._index.read_record(recnum)
        if record.updating:
            # Record can have updating flag due to partial creation caused
            # by older vdsm versions.
            raise se.NoSuchLease(lease_id)

        offset = lease_offset(recnum, self._alignment)
        return LeaseInfo(self.lockspace, lease_id, self._file.name, offset)
Ejemplo n.º 3
0
    def lookup(self, lease_id):
        """
        Lookup lease by lease_id and return LeaseInfo if found.

        Raises:
        - NoSuchLease if lease is not found.
        - InvalidRecord if corrupted lease record is found
        - OSError if io operation failed
        """
        log.debug("Looking up lease %r in lockspace %r",
                  lease_id, self.lockspace)
        recnum = self._index.find_record(lease_id)
        if recnum == -1:
            raise se.NoSuchLease(lease_id)

        record = self._index.read_record(recnum)
        if record.updating:
            raise LeaseUpdating(lease_id)

        offset = lease_offset(recnum)
        return LeaseInfo(self.lockspace, lease_id, self._file.name, offset)
Ejemplo n.º 4
0
    def remove(self, lease_id):
        """
        Remove lease from index

        Raises:
        - NoSuchLease if lease was not found
        - OSError if I/O operation failed
        - sanlock.SanlockException if sanlock operation failed.
        """
        log.info("Removing lease %r in lockspace %r", lease_id, self.lockspace)
        recnum = self._index.find_record(lease_id)
        if recnum == -1:
            raise se.NoSuchLease(lease_id)

        offset = lease_offset(recnum, self._alignment)

        # We remove a lease in 2 steps:
        # 1. write an empty record, making the resource unavailable. If writing
        #    a record fails, the index does not change and the new resource
        #    remains available
        # 2. write an empty sanlock resource in the slot associated with this
        #    record. If this fails we log an error and don't fail the removal
        #    as index is already updated and resource will not be available.

        self._write_record(recnum, EMPTY_RECORD)

        # There is no way to remove a resource, so we write an invalid resource
        # with empty resource and lockspace values.
        # TODO: Use SANLK_WRITE_CLEAR, expected in rhel 7.4.
        try:
            sanlock.write_resource(b"",
                                   b"", [(self._file.name, offset)],
                                   align=self._alignment,
                                   sector=self._block_size)
        except sanlock.SanlockException:
            log.warning(
                "Ignoring failure to clear sanlock resource file=%s "
                "offset=%s", self._file.name, offset)