Skip to content

Commit 0cf3b27

Browse files
Refresh cached ConfigFS data after deleting a backstore
1 parent 48fb5a3 commit 0cf3b27

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

targetcli/ui_backstore.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,48 @@ def ui_command_delete(self, name, save=None):
301301
except ValueError:
302302
raise ExecutionError("No storage object named %s." % name)
303303

304+
root_node = self.get_root()
305+
304306
save = self.ui_eval_param(save, 'bool', False)
305307
if save:
306-
rn = self.get_root()
307-
rn._save_backups(default_save_file)
308+
root_node._save_backups(default_save_file)
309+
310+
ui_nodes_to_refresh = set()
311+
fabrics = {}
312+
for lun in child.rtsnode.attached_luns:
313+
fabric_name = lun.parent_tpg.parent_target.fabric_module.name
314+
target_name = lun.parent_tpg.parent_target.wwn
315+
try:
316+
if fabric_name not in fabrics:
317+
fabrics[fabric_name] = root_node.get_child(fabric_name)
318+
319+
target_node = fabrics[fabric_name].get_child(target_name)
320+
321+
target_children = [child.name for child in target_node.children]
322+
tpg_name = 'tpg' + str(lun.parent_tpg.tag)
323+
if tpg_name in target_children:
324+
stale_node = target_node.get_child(tpg_name).get_child('luns')
325+
elif 'luns' in target_children:
326+
stale_node = target_node.get_child('luns')
327+
else:
328+
stale_node = target_node
329+
330+
ui_nodes_to_refresh.add(stale_node)
331+
except ValueError as error:
332+
self.shell.log.debug("Failed to retrieve cached configuration data for %s target %s LUN %d: %s"
333+
% (fabric_name, target_name, lun.lun, error))
334+
# If any errors occurred while looking up cached configuration data, refresh everything.
335+
ui_nodes_to_refresh.clear()
336+
ui_nodes_to_refresh.add(root_node)
337+
break
308338

309339
child.rtsnode.delete(save=save)
310340
self.remove_child(child)
341+
342+
for ui_node in ui_nodes_to_refresh:
343+
# Refresh cached configuration data to prevent 'This LUN does not exist in configFS'
344+
ui_node.refresh()
345+
311346
self.shell.log.info("Deleted storage object %s." % name)
312347

313348
def ui_complete_delete(self, parameters, text, current_param):

0 commit comments

Comments
 (0)