On Fri, 2015-09-25 at 20:00 -0700, Sheng Yang wrote: > Hi, > > I got hard time to determine which block device was created when I was > using tcm_loop. > > Normally I would just take a look at dmesg, see sda or sdb got > attached etc, but that's not a reliable way of doing it I guess. > > I also found the device showed up in "udevadm monitor", but unable to > find a way to associate with the original device I created from TCM > either. > > Here is the commands I've used to create the device(with tcmu-runner > running with file_handler demo code). I guess it's possible associate > with iscsi name somehow: > > mkdir -p /sys/kernel/config/target/core/user_1/test > echo dev_size=1024000000 > /sys/kernel/config/target/core/user_1/test/control > echo dev_config=file//root/test > > /sys/kernel/config/target/core/user_1/test/control > echo 1 > /sys/kernel/config/target/core/user_1/test/enable > > mkdir -p /sys/kernel/config/target/loopback/naa.60014059436855c1/tpgt_1 > echo "naa.60014051153c198a" > > /sys/kernel/config/target/loopback/naa.60014059436855c1/tpgt_1/nexus > mkdir -p /sys/kernel/config/target/loopback/naa.60014059436855c1/tpgt_1/lun/lun_0 > ln -s /sys/kernel/config/target/core/user_1/test > /sys/kernel/config/target/loopback/naa.60014059436855c1/tpgt_1/lun/lun_0/c68d79910b You can get scsi port/lun from the configfs. Try below script. The only missing part is I don't how to map wwn to SCSI host number. So you need to modify the hard-coded map_wwn_to_host(). mlin@ssi:~$ ./tcm.sh /sys/kernel/config/target/loopback/naa.6000000000000001/tpgt_1/lun/lun_0:/dev/sdd /sys/kernel/config/target/loopback/naa.6000000000000001/tpgt_1/lun/lun_1:/dev/sde /sys/kernel/config/target/loopback/naa.6000000000000001/tpgt_5/lun/lun_3:/dev/sdf /sys/kernel/config/target/loopback/naa.60014055f195952b/tpgt_1/lun/lun_0:/dev/sdc ------ #!/bin/bash #tcm.sh tcm_loop_dir=/sys/kernel/config/target/loopback function get_wwns() { ls $tcm_loop_dir |grep naa } #$1: wwn function map_wwn_to_host() { local wwn=$1 #TDB: how to map wwn to SCSI host number??? #I don't know, just hard code it now #run "lsscsi -H" to see the scsi host number if [ "$wwn" = "naa.6000000000000001" ] ; then echo 7 else echo 6 fi } #$1:wwn function get_ports() { local wwn=$1 local wwn_path=${tcm_loop_dir}/${wwn} ls $wwn_path |grep tpgt_ | awk -F"tpgt_" '{print $2}' } #$1:wwn #$2:port function get_luns() { local wwn=$1 local port=$2 lun_path=${tcm_loop_dir}/${wwn}/tpgt_${port}/lun ls $lun_path |grep lun_ | awk -F"lun_" '{print $2}' } #$1: host #$2: port #$3: lun function get_one_dev() { local host=$1 local port=$2 local lun=$3 local id=$host:0:$port:$lun lsscsi | grep $id | awk '{print $6}' } function get_all_devs() { local host local port local lun local wwn for wwn in `get_wwns` ; do host=`map_wwn_to_host $wwn` for port in `get_ports $wwn` ; do for lun in `get_luns $wwn $port` ; do echo -n $tcm_loop_dir/$wwn/tpgt_$port/lun/lun_$lun: get_one_dev $host $port $lun done done done } get_all_devs -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html