Ejemplo n.º 1
0
    def test_rebuild_empty(self, fake_sanlock):
        with make_volume() as vol:
            # Add underlying sanlock resources
            for i in [3, 4, 6]:
                resource = "%04d" % i
                offset = xlease.USER_RESOURCE_BASE + xlease.SLOT_SIZE * i
                fake_sanlock.write_resource(vol.lockspace, resource,
                                            [(vol.path, offset)])
            # The index is empty
            assert vol.leases() == {}

            # After rebuilding the index it should contain all the underlying
            # resources.
            file = xlease.DirectFile(vol.path)
            with utils.closing(file):
                xlease.rebuild_index(vol.lockspace, file)
            expected = {
                "0003": {
                    "offset": xlease.USER_RESOURCE_BASE + xlease.SLOT_SIZE * 3,
                    "updating": False,
                },
                "0004": {
                    "offset": xlease.USER_RESOURCE_BASE + xlease.SLOT_SIZE * 4,
                    "updating": False,
                },
                "0006": {
                    "offset": xlease.USER_RESOURCE_BASE + xlease.SLOT_SIZE * 6,
                    "updating": False,
                },
            }
            file = xlease.DirectFile(vol.path)
            with utils.closing(file):
                vol = xlease.LeasesVolume(file)
                with utils.closing(vol):
                    assert vol.leases() == expected
Ejemplo n.º 2
0
 def __init__(self, path):
     """
     Zero storage and format index area.
     """
     self.backend = xlease.DirectFile(path)
     self.zero_storage()
     self.format_index()
Ejemplo n.º 3
0
 def __init__(self, storage):
     """
     Zero storage and format index area.
     """
     self.path = storage.path
     self.block_size = storage.sector_size
     self.backend = xlease.DirectFile(storage.path)
     self.zero_storage()
     self.format_index()
Ejemplo n.º 4
0
def write_records(records, lockspace, path):
    file = xlease.DirectFile(path)
    with utils.closing(file):
        index = xlease.VolumeIndex(file)
        with utils.closing(index):
            for recnum, record in records:
                block = index.copy_block(recnum)
                with utils.closing(block):
                    block.write_record(recnum, record)
                    block.dump(file)
Ejemplo n.º 5
0
def make_volume(*records):
    with make_leases() as path:
        lockspace = os.path.basename(os.path.dirname(path))
        file = xlease.DirectFile(path)
        with utils.closing(file):
            xlease.format_index(lockspace, file)
            if records:
                write_records(records, file)
            vol = xlease.LeasesVolume(file)
            with utils.closing(vol):
                yield vol
Ejemplo n.º 6
0
 def __init__(self, storage, alignment):
     """
     Zero storage and format index area.
     """
     self.path = storage.path
     self.lockspace = make_uuid()
     self.alignment = alignment
     self.block_size = storage.sector_size
     self.backend = xlease.DirectFile(storage.path)
     self.zero_storage()
     self.format_index()
Ejemplo n.º 7
0
    def rebuild_external_leases(self):
        """
        Rebuild the external leases volume index from volume contents.

        Must be called only on the SPM.
        """
        with self._manifest.external_leases_lock.exclusive:
            path = self.external_leases_path()
            backend = xlease.DirectFile(path)
            with utils.closing(backend):
                xlease.rebuild_index(self.sdUUID, backend)
Ejemplo n.º 8
0
def _external_leases_volume(path):
    """
    Context manager returning the external leases volume.

    The caller is responsible for holding the external_leases_lock in the
    correct mode.
    """
    backend = xlease.DirectFile(path)
    with utils.closing(backend):
        vol = xlease.LeasesVolume(backend)
        with utils.closing(vol):
            yield vol
Ejemplo n.º 9
0
Archivo: sd.py Proyecto: benipeled/vdsm
    def external_leases_backend(cls, lockspace, path):
        """
        Return a context manager for performing I/O to the extenal leases
        volume.

        Arguments:
            lockspace (str): Sanlock lockspace name, storage domain uuid.
            path (str): Path to the external leases volume

        Returns:
            context manager.
        """
        backend = xlease.DirectFile(path)
        with utils.closing(backend):
            yield backend
Ejemplo n.º 10
0
    def format_external_leases(cls, lockspace, path):
        """
        Format the special xleases volume.

        Called when creating a new storage domain, or when upgrading storage
        domain to version 4.

        WARNING: destructive operation, must not be called on active external
        leases volume.

        TODO: should move to storage domain subclasses of each subclass can use
        its own backend.

        Must be called only on the SPM.
        """
        backend = xlease.DirectFile(path)
        with utils.closing(backend):
            xlease.format_index(lockspace, backend)
Ejemplo n.º 11
0
def format_xleases(*args):
    """
    format-xleases sd_id path

    WARNING:

        This is a destructive operation - you must put the storage
        domain into maintenance before running this tool.

    Format the xleases volume index, dropping all leases from the index.
    This does not delete sanlock resources on the volume. If you want to
    restore existing sanlock resources, use rebuild-index. If you want
    to delete also sanlock resources on this volume you can wipe the
    entire volume using dd before formatting it.

    Notes:

    - With iSCSI based storage you may need to connect to the traget
      using iscsiadm.

    - With file based storage, you may need to mount the storage domain.

    - With block based stoage, you need to activate the xleases logical
      volume before the operation, and deactivate after the operation.

    If formatting fails, the volume will not be usable (it will be
    marked as "updating"), but the operation can be tried again.

    Creating xleases volume on file storage:

        PATH=/rhev/data-center/mnt/server:_path/sd-id/dom_md/xleases
        truncate -s 1G $PATH
        vdsm-tool format-xleases sd-id $PATH

    Creating the xleases volume on block storage:

        lvcreate --name xleases --size 1g sd-id
        vdsm-tool format-xleases sd-id /dev/sd-id/xleases
        lvchange -an sd-id/xleases
    """
    args = parse_args(args)
    backend = xlease.DirectFile(args.path)
    with utils.closing(backend):
        xlease.format_index(args.sd_id, backend)
Ejemplo n.º 12
0
def rebuild_xleases(*args):
    """
    rebuild-xleases sd_id path

    WARNING:

        This is a destructive operation - you must put the storage
        domain into maintenance before running this tool.
        The xleases volume index is the source of truth so rebuilding
        from storage can break it badly.

    Rebuild the xleases volume index, restoring all sanlock resource on
    the xleases volume. If you want to drop all leases in the index, use
    format-xleases.

    Notes:

    - With iSCSI based storage you may need to connect to the traget
      using iscsiadm.

    - With file based storage, you may need to mount the storage domain.

    - With block based stoage, you need to activate the xleases logical
      volume before the operation, and deactivate after the operation.

    If rebuilding fails, the volume will not be usable (it will be
    marked as "updating"), but the operation can be tried again.

    Rebuilding xleases volume on file storage:

        PATH=/rhev/data-center/mnt/server:_path/sd-id/dom_md/xleases
        vdsm-tool rebuild-xleases sd-id $PATH

    Rebuilding the xleases volume on block storage:

        lvchange -ay sd-id/xleases
        vdsm-tool rebuild-xleases sd-id /dev/sd-id/xleases
        lvchange -an sd-id/xleases
    """
    args = parse_args(args)
    backend = xlease.DirectFile(args.path)
    with utils.closing(backend):
        xlease.rebuild_index(args.sd_id, backend)
Ejemplo n.º 13
0
 def check_invalid_index(self, path):
     file = xlease.DirectFile(path)
     with utils.closing(file):
         with self.assertRaises(xlease.InvalidIndex):
             vol = xlease.LeasesVolume(file)
             vol.close()
Ejemplo n.º 14
0
 def test_size(self):
     with make_leases() as path:
         file = xlease.DirectFile(path)
         with utils.closing(file):
             self.assertEqual(file.size(), constants.GIB)
Ejemplo n.º 15
0
def format_vol(lockspace, path):
    file = xlease.DirectFile(path)
    with utils.closing(file):
        vol = xlease.LeasesVolume(lockspace, file)
        with utils.closing(vol):
            vol.format()