Bug 1571728

Summary: targetcli cmd exits abnormally
Product: Red Hat Enterprise Linux 7 Reporter: jiyan <jiyan>
Component: targetcliAssignee: Maurizio Lombardi <mlombard>
Status: CLOSED WONTFIX QA Contact: Martin Hoyer <mhoyer>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.5CC: dyuan, lmen, xuzhang
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-02-15 07:38:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description jiyan 2018-04-25 10:17:34 UTC
Description of problem:
targetcli cmd exists abnormally

Version-Release number of selected component (if applicable):
targetcli-2.1.fb46-4.el7_5.noarch

How reproducible:
100%

Steps to Reproduce:
1. Install targetcli
# targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
  o- xen_pvscsi ....................................................................................................... [Targets: 0]


2. Configure 1 lun, the detailed info is as following:
# targetcli 
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> cd iscsi 
/iscsi> create 
Created target iqn.2003-01.org.linux-iscsi.hp-z800-05.x8664:sn.f47d3a60b2b9.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd /backstores/fileio 
/backstores/fileio> create file_or_dev=/home/iscsi/target0.img name=lun0
Created fileio lun0 with size 53687091200
/backstores/fileio> cd /iscsi/iqn.2003-01.org.linux-iscsi.hp-z800-05.x8664:sn.f47d3a60b2b9/tpg1/luns 
/iscsi/iqn.20...2b9/tpg1/luns> create /backstores/fileio/lun0 
Created LUN 0.
/iscsi/iqn.20...2b9/tpg1/luns> cd ..
/iscsi/iqn.20...3a60b2b9/tpg1> set attribute authentication=0
Parameter authentication is now '0'.
/iscsi/iqn.20...3a60b2b9/tpg1> set attribute demo_mode_write_protect=0
Parameter demo_mode_write_protect is now '0'.
/iscsi/iqn.20...3a60b2b9/tpg1> set attribute cache_dynamic_acls=1
Parameter cache_dynamic_acls is now '1'.
/iscsi/iqn.20...3a60b2b9/tpg1> set attribute generate_node_acls=1
Parameter generate_node_acls is now '1'.
/iscsi/iqn.20...3a60b2b9/tpg1> 
/iscsi/iqn.20...3a60b2b9/tpg1> cd /
/> saveconfig 
Configuration saved to /etc/target/saveconfig.json
/> exit 
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json

# targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- lun0 ............................................................. [/home/iscsi/target0.img (50.0GiB) write-back activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2003-01.org.linux-iscsi.hp-z800-05.x8664:sn.f47d3a60b2b9 ...................................................... [TPGs: 1]
  |   o- tpg1 .................................................................................................. [gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ....................................................... [fileio/lun0 (/home/iscsi/target0.img) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  o- xen_pvscsi ....................................................................................................... [Targets: 0]


3. Delete the first lun, and configure another lun
# targetcli 
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> cd /backstores/fileio/
/backstores/fileio> delete name=lun0 
Deleted storage object lun0.
/backstores/fileio> create file_or_dev=/home/iscsi/target1.img name=file0
Created fileio file0 with size 53687091200
/backstores/fileio> cd /iscsi/iqn.2003-01.org.linux-iscsi.hp-z800-05.x8664:sn.f47d3a60b2b9/tpg1/luns/
/iscsi/iqn.20...2b9/tpg1/luns> create /backstores/fileio/file0 
Created LUN 0.
Traceback (most recent call last):
  File "/usr/bin/targetcli", line 122, in <module>
    main()
  File "/usr/bin/targetcli", line 112, in main
    shell.run_interactive()
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 905, in run_interactive
    self._cli_loop()
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 734, in _cli_loop
    self.run_cmdline(cmdline)
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 848, in run_cmdline
    self._execute_command(path, command, pparams, kparams)
  File "/usr/lib/python2.7/site-packages/configshell_fb/shell.py", line 823, in _execute_command
    result = target.execute_command(command, pparams, kparams)
  File "/usr/lib/python2.7/site-packages/configshell_fb/node.py", line 1406, in execute_command
    return method(*pparams, **kparams)
  File "/usr/lib/python2.7/site-packages/targetcli/ui_target.py", line 1133, in ui_command_create
    ui_lun = UILUN(lun_object, self)
  File "/usr/lib/python2.7/site-packages/targetcli/ui_target.py", line 1243, in __init__
    super(UILUN, self).__init__(name, lun, parent)
  File "/usr/lib/python2.7/site-packages/targetcli/ui_node.py", line 140, in __init__
    UINode.__init__(self, name, parent)
  File "/usr/lib/python2.7/site-packages/targetcli/ui_node.py", line 29, in __init__
    ConfigNode.__init__(self, name, parent, shell)
  File "/usr/lib/python2.7/site-packages/configshell_fb/node.py", line 105, in __init__
    % self._name)
ValueError: Name 'lun0' already used by a sibling.

4. Check the targetcli info
# targetcli ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- file0 ............................................................ [/home/iscsi/target1.img (50.0GiB) write-back activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2003-01.org.linux-iscsi.hp-z800-05.x8664:sn.f47d3a60b2b9 ...................................................... [TPGs: 1]
  |   o- tpg1 .................................................................................................. [gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ...................................................... [fileio/file0 (/home/iscsi/target1.img) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  o- xen_pvscsi ....................................................................................................... [Targets: 0]


Actual results:
As step3 shows

Expected results:
targetcli should report noraml info rather that exist.

Additional info:

Comment 2 Martin Hoyer 2018-04-25 11:23:41 UTC
Reproducible by deleting assigned backstore. To simplify:
# targetcli
1. /backstores/fileio create file_or_dev=test1.img name=test1 size=10M
2. /iscsi create wwn=iqn.2018-04.com.redhat.test1
3. /iscsi/iqn.2018-04.com.redhat.test1/tpg1/luns create /backstores/fileio/test1
4. /backstores/fileio/ delete name=test1
5. /backstores/fileio create file_or_dev=test2.img name=test2 size=10M
6. /iscsi/iqn.2018-04.com.redhat.test1/tpg1/luns/ create /backstores/fileio/test2

Not reproducible from cmd line with individual targetcli commands.

Comment 4 Maurizio Lombardi 2018-11-02 09:09:46 UTC
The problem is due to the fact that the iscsi target instance has a reference to a LUN that has been removed:

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- test3 ....................................................................... [/home/test3 (100.0MiB) write-back activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2003-01.org.linux-iscsi.ibm-p8-kvm-01-guest-07.ppc64:sn.01eb3cfc5684 .......................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................. [fileio/test3 (/home/test3) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> backstores/fileio/ delete test3 
Deleted storage object test3.
/> ls
This LUN does not exist in configFS


Ideally, when a LUN is removed, rtslib should scan the targets and remove all references to the LUN.

Comment 9 RHEL Program Management 2021-02-15 07:38:40 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.