Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh cached ConfigFS data after deleting a backstore #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions targetcli/ui_backstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,48 @@ def ui_command_delete(self, name, save=None):
except ValueError:
raise ExecutionError("No storage object named %s." % name)

root_node = self.get_root()

save = self.ui_eval_param(save, 'bool', False)
if save:
rn = self.get_root()
rn._save_backups(default_save_file)
root_node._save_backups(default_save_file)

ui_nodes_to_refresh = set()
fabrics = {}
for lun in child.rtsnode.attached_luns:
fabric_name = lun.parent_tpg.parent_target.fabric_module.name
target_name = lun.parent_tpg.parent_target.wwn
try:
if fabric_name not in fabrics:
fabrics[fabric_name] = root_node.get_child(fabric_name)

target_node = fabrics[fabric_name].get_child(target_name)

target_children = [child.name for child in target_node.children]
tpg_name = 'tpg' + str(lun.parent_tpg.tag)
if tpg_name in target_children:
stale_node = target_node.get_child(tpg_name).get_child('luns')
elif 'luns' in target_children:
stale_node = target_node.get_child('luns')
else:
stale_node = target_node

ui_nodes_to_refresh.add(stale_node)
except ValueError as error:
self.shell.log.debug("Failed to retrieve cached configuration data for %s target %s LUN %d: %s"
% (fabric_name, target_name, lun.lun, error))
# If any errors occurred while looking up cached configuration data, refresh everything.
ui_nodes_to_refresh.clear()
ui_nodes_to_refresh.add(root_node)
break

child.rtsnode.delete(save=save)
self.remove_child(child)

for ui_node in ui_nodes_to_refresh:
# Refresh cached configuration data to prevent 'This LUN does not exist in configFS'
ui_node.refresh()

self.shell.log.info("Deleted storage object %s." % name)

def ui_complete_delete(self, parameters, text, current_param):
Expand Down