mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
lvmdbusd: Remove duplicate code
The logic for _cache_lv and _writecache_lv was identical except for which underlying lvm command to run. Factor out common.
This commit is contained in:
parent
f4c03faa65
commit
e977b70bfb
@ -751,7 +751,7 @@ class Lv(LvCommon):
|
|||||||
cfg.worker_q.put(r)
|
cfg.worker_q.put(r)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _writecache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
|
def _caching_common(method, lv_uuid, lv_name, lv_object_path, cache_options):
|
||||||
# Make sure we have a dbus object representing it
|
# Make sure we have a dbus object representing it
|
||||||
dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
|
dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
|
||||||
|
|
||||||
@ -760,7 +760,7 @@ class Lv(LvCommon):
|
|||||||
|
|
||||||
if lv_to_cache:
|
if lv_to_cache:
|
||||||
fcn = lv_to_cache.lv_full_name()
|
fcn = lv_to_cache.lv_full_name()
|
||||||
rc, out, err = cmdhandler.lv_writecache_lv(
|
rc, out, err = method(
|
||||||
dbo.lv_full_name(), fcn, cache_options)
|
dbo.lv_full_name(), fcn, cache_options)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
# When we cache an LV, the cache pool and the lv that is getting
|
# When we cache an LV, the cache pool and the lv that is getting
|
||||||
@ -777,9 +777,14 @@ class Lv(LvCommon):
|
|||||||
else:
|
else:
|
||||||
raise dbus.exceptions.DBusException(
|
raise dbus.exceptions.DBusException(
|
||||||
LV_INTERFACE, 'LV to cache with object path %s not present!' %
|
LV_INTERFACE, 'LV to cache with object path %s not present!' %
|
||||||
lv_object_path)
|
lv_object_path)
|
||||||
return lv_converted
|
return lv_converted
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _writecache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
|
||||||
|
return Lv._caching_common(cmdhandler.lv_writecache_lv, lv_uuid,
|
||||||
|
lv_name, lv_object_path, cache_options)
|
||||||
|
|
||||||
@dbus.service.method(
|
@dbus.service.method(
|
||||||
dbus_interface=LV_INTERFACE,
|
dbus_interface=LV_INTERFACE,
|
||||||
in_signature='oia{sv}',
|
in_signature='oia{sv}',
|
||||||
@ -959,33 +964,8 @@ class LvCachePool(Lv):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _cache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
|
def _cache_lv(lv_uuid, lv_name, lv_object_path, cache_options):
|
||||||
# Make sure we have a dbus object representing cache pool
|
return Lv._caching_common(cmdhandler.lv_cache_lv, lv_uuid, lv_name,
|
||||||
dbo = LvCommon.validate_dbus_object(lv_uuid, lv_name)
|
lv_object_path, cache_options)
|
||||||
|
|
||||||
# Make sure we have dbus object representing lv to cache
|
|
||||||
lv_to_cache = cfg.om.get_object_by_path(lv_object_path)
|
|
||||||
|
|
||||||
if lv_to_cache:
|
|
||||||
fcn = lv_to_cache.lv_full_name()
|
|
||||||
rc, out, err = cmdhandler.lv_cache_lv(
|
|
||||||
dbo.lv_full_name(), fcn, cache_options)
|
|
||||||
if rc == 0:
|
|
||||||
# When we cache an LV, the cache pool and the lv that is getting
|
|
||||||
# cached need to be removed from the object manager and
|
|
||||||
# re-created as their interfaces have changed!
|
|
||||||
mt_remove_dbus_objects((dbo, lv_to_cache))
|
|
||||||
cfg.load()
|
|
||||||
|
|
||||||
lv_converted = cfg.om.get_object_path_by_lvm_id(fcn)
|
|
||||||
else:
|
|
||||||
raise dbus.exceptions.DBusException(
|
|
||||||
LV_INTERFACE,
|
|
||||||
'Exit code %s, stderr = %s' % (str(rc), err))
|
|
||||||
else:
|
|
||||||
raise dbus.exceptions.DBusException(
|
|
||||||
LV_INTERFACE, 'LV to cache with object path %s not present!' %
|
|
||||||
lv_object_path)
|
|
||||||
return lv_converted
|
|
||||||
|
|
||||||
@dbus.service.method(
|
@dbus.service.method(
|
||||||
dbus_interface=CACHE_POOL_INTERFACE,
|
dbus_interface=CACHE_POOL_INTERFACE,
|
||||||
|
Loading…
Reference in New Issue
Block a user