From a86b89281ba6be184fac648955ad1aa4f83dac15 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 23 Jun 2023 09:37:26 +0200 Subject: [PATCH] Allow running with both libblockdev 3.0 and 2.0 API The only API change in libblockdev 3.0 affecting targetd is the removal of bd_switch_init_checks function. Dependency checking is now disabled during initialization by defautl so removing this call with 3.0 does not change the behaviour. --- targetd/backends/lvm.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/targetd/backends/lvm.py b/targetd/backends/lvm.py index 521bdec..ae46381 100755 --- a/targetd/backends/lvm.py +++ b/targetd/backends/lvm.py @@ -18,18 +18,23 @@ import gi gi.require_version("GLib", "2.0") -gi.require_version("BlockDev", "2.0") - from gi.repository import GLib -from gi.repository import BlockDev as bd + +try: + gi.require_version("BlockDev", "3.0") + from gi.repository import BlockDev as bd +except ValueError: + gi.require_version("BlockDev", "2.0") + from gi.repository import BlockDev as bd + + bd.switch_init_checks(False) + from targetd.main import TargetdError REQUESTED_PLUGIN_NAMES = {"lvm"} requested_plugins = bd.plugin_specs_from_names(REQUESTED_PLUGIN_NAMES) -bd.switch_init_checks(False) - pools = [] vg_name_2_pool_name_dict = {}