[stgt] [BUG] [tgt-setup-lun] - adding inaccurate LUN to existing target will remove the target itself

Max Benenson mbenenso at redhat.com
Mon Feb 7 16:17:48 CET 2011

Description of problem:
If you try to add a new LUN (and pass not existing device and the target name that already exists) the operation will fail since the target with the same name already exists and then the utility will suggest to the user to add this LUN to this existing target and if the user will select to proceed it will fail since the device does not exist and as the result will remove the target itself (a kind of rollback).

Steps to reproduce:
1. lvcreate -L 10G -n /dev/vg_autofiler01/max_lv01
2. tgt-setup-lun -n target1 -d /dev/vg_autofiler01/max_lv01 -t iscsi
3. tgt-setup-lun -n target1 -d /dev/vg_autofiler01/max_lv02 -t iscsi

the last line will produce the following output:
Using transport: iscsi
Error: target named iqn.2001-04.com.auto-filer01-target1 already exists
Add a new lun to the existing target? (yes/NO): yes
Adding a logical unit (/dev/vg_autofiler01/max_lv02) to target, tid=1
tgtadm: invalid request
Error: failed to add a logical unit (/dev/vg_autofiler01/max_lv02) to target, tid=1
Deleting new target, tid=1

Actual result:
The target with id 1 was removed from the targets.conf file.

Expected result:
The rollback action should consider the presence of existing target and should NOT remove it.

Environment details:
[root at auto-filer01 tgt]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.0 (Santiago)
[root at auto-filer01 tgt]# rpm -qa | grep kernel
[root at auto-filer01 tgt]# rpm -qa | grep lvm
[root at auto-filer01 tgt]# less /var/log/messages
Jan 31 17:43:09 auto-filer01 tgtd: backed_file_open(92) Could not open /dev/vg_autofiler01/max_lv02, No such file or directory

IMHO the fix should be in err_exit() method which should verify (using additional function) 
LUN presence in the target before performing "tgtadm --lld $lld_name --op delete --mode target --tid $tid".
Something like (I am using Python syntax):
if not hasAttachedLUN($tid):
    tgtadm --lld $lld_name --op delete --mode target --tid $tid

To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

More information about the stgt mailing list