SCST-project / scst

SCST is a SCSI target software stack that allows to export any block device or file via iSCSI, FC or RDMA (SRP).
http://scst.sourceforge.net
93 stars 34 forks source link

scstadmin: Eliminate use of uninitialized value error #217

Closed bmeagherix closed 9 months ago

bmeagherix commented 9 months ago

When running scstadmin to load a config file with a reduced the number of targets defined, the first time will generate an error Use of uninitialized value in numeric ne (!=) at /usr/local/sbin/scstadmin line 2834. Rectify by checking for the uninitialized value, and taking appropriate steps (i.e disable the target).

It appears that the first time the command is run the target is supposed to get disabled, and fully removed when next run.

Here is an example of a failure when switching from 2 targets to 1 target (demonstrates error, target not properly disabled):

root@cluster1:~# scstadmin -noprompt -force -config /etc/scst.conf.1TARGET

Collecting current configuration: done.

-> Checking configuration file '/etc/scst.conf.1TARGET' for errors.
        -> Done, 0 warnings found.

-> Applying configuration.
        -> Removing LUN 0 from driver/target/group 'iscsi/iqn.2005-10.org.freenas.ctl:test2/security_group': done.
        -> Removing group 'security_group' from driver/target 'iscsi/iqn.2005-10.org.freenas.ctl:test2': done.

Collecting current configuration: done.

        -> Closing device 'extent2' using handler 'vdisk_fileio': done.
        -> Virtual target 'copy_manager_tgt' for driver 'copy_manager' is not in configuration. Use -force to remove it.
Use of uninitialized value in numeric ne (!=) at /usr/local/sbin/scstadmin line 2834.
        -> Disabling driver/target 'iscsi/iqn.2005-10.org.freenas.ctl:test2': done.
        -> Done, 4 change(s) made.

All done.
root@cluster1:~# cat /sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled
1
root@cluster1:~# scstadmin -noprompt -force -config /etc/scst.conf.1TARGET

Collecting current configuration: done.

-> Checking configuration file '/etc/scst.conf.1TARGET' for errors.
        -> Done, 0 warnings found.

-> Applying configuration.

Collecting current configuration: done.

        -> Virtual target 'copy_manager_tgt' for driver 'copy_manager' is not in configuration. Use -force to remove it.
        -> Removing virtual target 'iqn.2005-10.org.freenas.ctl:test2' from driver 'iscsi': done.
        -> Done, 1 change(s) made.

All done.
root@cluster1:~# cat /sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled
cat: '/sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled': No such file or directory
root@cluster1:~#

and here is the same change steps executed with the updated scstadmin script (no error):

root@cluster1:~# ./scstadmin -noprompt -force -config /etc/scst.conf.1TARGET

Collecting current configuration: done.

-> Checking configuration file '/etc/scst.conf.1TARGET' for errors.
        -> Done, 0 warnings found.

-> Applying configuration.
        -> Removing LUN 0 from driver/target/group 'iscsi/iqn.2005-10.org.freenas.ctl:test2/security_group': done.
        -> Removing group 'security_group' from driver/target 'iscsi/iqn.2005-10.org.freenas.ctl:test2': done.

Collecting current configuration: done.

        -> Closing device 'extent2' using handler 'vdisk_fileio': done.
        -> Virtual target 'copy_manager_tgt' for driver 'copy_manager' is not in configuration. Use -force to remove it.
        -> Disabling driver/target 'iscsi/iqn.2005-10.org.freenas.ctl:test2': done.
        -> Done, 4 change(s) made.

All done.
root@cluster1:~# cat /sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled
0
root@cluster1:~# ./scstadmin -noprompt -force -config /etc/scst.conf.1TARGET

Collecting current configuration: done.

-> Checking configuration file '/etc/scst.conf.1TARGET' for errors.
        -> Done, 0 warnings found.

-> Applying configuration.

Collecting current configuration: done.

        -> Virtual target 'copy_manager_tgt' for driver 'copy_manager' is not in configuration. Use -force to remove it.
        -> Removing virtual target 'iqn.2005-10.org.freenas.ctl:test2' from driver 'iscsi': done.
        -> Done, 1 change(s) made.

All done.
root@cluster1:~# cat /sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled
cat: '/sys/kernel/scst_tgt/targets/iscsi/iqn.2005-10.org.freenas.ctl:test2/enabled': No such file or directory
root@cluster1:~#
bmeagherix commented 9 months ago

Hmmm. Seems like the fix may be breaking something else. Let me see if I can rectify.

bmeagherix commented 9 months ago

Hmmm. Seems like the fix may be breaking something else. Let me see if I can rectify.

OK, adding a check vs copy_manager resolved that issue. (FWIW, scstadmin already checks against it in multiple other locations.)

lnocturno commented 9 months ago

Hi Brian,

Thank you for the patch!

Thanks, Gleb