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
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
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)
def test_rebuild_empty(self, tmp_vol, fake_sanlock): # Add underlying sanlock resources. for i in [3, 4, 6]: resource = "%04d" % i offset = xlease.lease_offset(i, tmp_vol.alignment) fake_sanlock.write_resource( tmp_vol.lockspace.encode("utf-8"), resource.encode("utf-8"), [(tmp_vol.path, offset)], align=tmp_vol.alignment, sector=tmp_vol.block_size) # Check that the index is empty before rebuilding. vol = xlease.LeasesVolume( tmp_vol.backend, alignment=tmp_vol.alignment, block_size=tmp_vol.block_size) with utils.closing(vol): assert vol.leases() == {} # Rebuild the index from storage. xlease.rebuild_index( tmp_vol.lockspace, tmp_vol.backend, alignment=tmp_vol.alignment, block_size=tmp_vol.block_size) # After rebuilding the index it should contain all the underlying # resources. expected = { "0003": { "offset": xlease.lease_offset(3, tmp_vol.alignment), "updating": False, }, "0004": { "offset": xlease.lease_offset(4, tmp_vol.alignment), "updating": False, }, "0006": { "offset": xlease.lease_offset(6, tmp_vol.alignment), "updating": False, }, } vol = xlease.LeasesVolume( tmp_vol.backend, alignment=tmp_vol.alignment, block_size=tmp_vol.block_size) with utils.closing(vol): assert vol.leases() == expected
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)
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. 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)