Beispiel #1
0
    def set_lvb(self, lease, info):
        self.log.info("Setting LVB data to lease %s, info: %r", lease, info)
        data = json.dumps(info).encode("utf-8")

        if len(data) > LVB_SIZE:
            raise se.SanlockLVBError("lvb dict is too big ")

        # Pad the data with zeroes to ensure it is properly initialized and
        # does not contain garbage from previous writes.
        data = data.ljust(LVB_SIZE, b"\0")

        try:
            # pylint: disable=E1101
            sanlock.set_lvb(self._lockspace_name, lease.name.encode("utf-8"),
                            [(lease.path, lease.offset)], data)
        except sanlock.SanlockException as e:
            raise se.SanlockLVBError(e)
Beispiel #2
0
    def get_lvb(self, lease):
        self.log.debug("Getting LVB data from lease %s", lease)
        try:
            # pylint: disable=E1101
            data = sanlock.get_lvb(self._lockspace_name,
                                   lease.name.encode("utf-8"),
                                   [(lease.path, lease.offset)],
                                   size=LVB_SIZE)
        except sanlock.SanlockException as e:
            raise se.SanlockLVBError(e)

        data = data.rstrip(b"\0").decode("utf-8")
        # In case the LVB was not written to before
        if data == '':
            return {}

        return json.loads(data)