The lvm C library requires that you close/re-open for long
running processes to reclaim memory.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
targetd/block.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/targetd/block.py b/targetd/block.py
index da78872..c77b021 100644
--- a/targetd/block.py
+++ b/targetd/block.py
@@ -26,6 +26,22 @@ from main import TargetdError
from utils import ignored
+def lib_housekeeping(method):
+ def c_wrapper(*args, **kwargs):
+ global c_library_calls
+ c_library_calls += 1
+ if c_library_calls > 50:
+ try:
+ #May not be present
+ lvm.gc()
+ except AttributeError:
+ pass
+ c_library_calls = 0
+
+ return method(*args, **kwargs)
+ return c_wrapper
+
+
def get_vg_lv(pool_name):
"""
Checks for the existence of a '/' in the pool name. We are using this
@@ -61,6 +77,7 @@ def vgopen(pool_name):
pools = []
target_name = None
+c_library_calls = 0
#
@@ -91,6 +108,7 @@ def initialize(config_dict):
)
+@lib_housekeeping
def volumes(req, pool):
output = []
vg_name, lv_pool = get_vg_lv(pool)
@@ -102,6 +120,7 @@ def volumes(req, pool):
return output
+@lib_housekeeping
def create(req, pool, name, size):
vg_name, lv_pool = get_vg_lv(pool)
with vgopen(vg_name) as vg:
@@ -115,6 +134,7 @@ def create(req, pool, name, size):
vg.createLvLinear(name, int(size))
+@lib_housekeeping
def destroy(req, pool, name):
with ignored(RTSLibNotInCFS):
fm = FabricModule('iscsi')
@@ -130,6 +150,7 @@ def destroy(req, pool, name):
vg.lvFromName(name).remove()
+@lib_housekeeping
def copy(req, pool, vol_orig, vol_new, timeout=10):
"""
Create a new volume that is a copy of an existing one.
@@ -181,6 +202,7 @@ def copy(req, pool, vol_orig, vol_new, timeout=10):
raise TargetdError(-303, "Unexpected exception: %s" % (str(e)))
+@lib_housekeeping
def export_list(req):
try:
fm = FabricModule('iscsi')
@@ -211,6 +233,7 @@ def _exports_save_config():
root.ui_command_saveconfig()
+@lib_housekeeping
def export_create(req, pool, vol, initiator_wwn, lun):
# get wwn of volume so LIO can export as vpd83 info
vg_name, thin_pool = get_vg_lv(pool)
@@ -258,6 +281,7 @@ def export_create(req, pool, vol, initiator_wwn, lun):
_exports_save_config()
+@lib_housekeeping
def export_destroy(req, pool, vol, initiator_wwn):
pool_check(pool)
fm = FabricModule('iscsi')
@@ -296,6 +320,7 @@ def export_destroy(req, pool, vol, initiator_wwn):
_exports_save_config()
+@lib_housekeeping
def initiator_set_auth(req, initiator_wwn, in_user, in_pass, out_user,
out_pass):
fm = FabricModule('iscsi')
@@ -319,6 +344,7 @@ def initiator_set_auth(req, initiator_wwn, in_user, in_pass, out_user,
_exports_save_config()
+@lib_housekeeping
def block_pools(req):
results = []
--
1.8.2.1