1*4ca9bc22SMauro Carvalho Chehab========================================= 2*4ca9bc22SMauro Carvalho ChehabThe TCM v4 fabric module script generator 3*4ca9bc22SMauro Carvalho Chehab========================================= 4*4ca9bc22SMauro Carvalho Chehab 5*4ca9bc22SMauro Carvalho ChehabGreetings all, 6*4ca9bc22SMauro Carvalho Chehab 7*4ca9bc22SMauro Carvalho ChehabThis document is intended to be a mini-HOWTO for using the tcm_mod_builder.py 8*4ca9bc22SMauro Carvalho Chehabscript to generate a brand new functional TCM v4 fabric .ko module of your very own, 9*4ca9bc22SMauro Carvalho Chehabthat once built can be immediately be loaded to start access the new TCM/ConfigFS 10*4ca9bc22SMauro Carvalho Chehabfabric skeleton, by simply using:: 11*4ca9bc22SMauro Carvalho Chehab 12*4ca9bc22SMauro Carvalho Chehab modprobe $TCM_NEW_MOD 13*4ca9bc22SMauro Carvalho Chehab mkdir -p /sys/kernel/config/target/$TCM_NEW_MOD 14*4ca9bc22SMauro Carvalho Chehab 15*4ca9bc22SMauro Carvalho ChehabThis script will create a new drivers/target/$TCM_NEW_MOD/, and will do the following 16*4ca9bc22SMauro Carvalho Chehab 17*4ca9bc22SMauro Carvalho Chehab 1) Generate new API callers for drivers/target/target_core_fabric_configs.c logic 18*4ca9bc22SMauro Carvalho Chehab ->make_tpg(), ->drop_tpg(), ->make_wwn(), ->drop_wwn(). These are created 19*4ca9bc22SMauro Carvalho Chehab into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c 20*4ca9bc22SMauro Carvalho Chehab 2) Generate basic infrastructure for loading/unloading LKMs and TCM/ConfigFS fabric module 21*4ca9bc22SMauro Carvalho Chehab using a skeleton struct target_core_fabric_ops API template. 22*4ca9bc22SMauro Carvalho Chehab 3) Based on user defined T10 Proto_Ident for the new fabric module being built, 23*4ca9bc22SMauro Carvalho Chehab the TransportID / Initiator and Target WWPN related handlers for 24*4ca9bc22SMauro Carvalho Chehab SPC-3 persistent reservation are automatically generated in $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c 25*4ca9bc22SMauro Carvalho Chehab using drivers/target/target_core_fabric_lib.c logic. 26*4ca9bc22SMauro Carvalho Chehab 4) NOP API calls for all other Data I/O path and fabric dependent attribute logic 27*4ca9bc22SMauro Carvalho Chehab in $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c 28*4ca9bc22SMauro Carvalho Chehab 29*4ca9bc22SMauro Carvalho Chehabtcm_mod_builder.py depends upon the mandatory '-p $PROTO_IDENT' and '-m 30*4ca9bc22SMauro Carvalho Chehab$FABRIC_MOD_name' parameters, and actually running the script looks like:: 31*4ca9bc22SMauro Carvalho Chehab 32*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git/Documentation/target# python tcm_mod_builder.py -p iSCSI -m tcm_nab5000 33*4ca9bc22SMauro Carvalho Chehab tcm_dir: /mnt/sdb/lio-core-2.6.git/Documentation/target/../../ 34*4ca9bc22SMauro Carvalho Chehab Set fabric_mod_name: tcm_nab5000 35*4ca9bc22SMauro Carvalho Chehab Set fabric_mod_dir: 36*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000 37*4ca9bc22SMauro Carvalho Chehab Using proto_ident: iSCSI 38*4ca9bc22SMauro Carvalho Chehab Creating fabric_mod_dir: 39*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000 40*4ca9bc22SMauro Carvalho Chehab Writing file: 41*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_base.h 42*4ca9bc22SMauro Carvalho Chehab Using tcm_mod_scan_fabric_ops: 43*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../include/target/target_core_fabric_ops.h 44*4ca9bc22SMauro Carvalho Chehab Writing file: 45*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.c 46*4ca9bc22SMauro Carvalho Chehab Writing file: 47*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.h 48*4ca9bc22SMauro Carvalho Chehab Writing file: 49*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_configfs.c 50*4ca9bc22SMauro Carvalho Chehab Writing file: 51*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kbuild 52*4ca9bc22SMauro Carvalho Chehab Writing file: 53*4ca9bc22SMauro Carvalho Chehab /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kconfig 54*4ca9bc22SMauro Carvalho Chehab Would you like to add tcm_nab5000to drivers/target/Kbuild..? [yes,no]: yes 55*4ca9bc22SMauro Carvalho Chehab Would you like to add tcm_nab5000to drivers/target/Kconfig..? [yes,no]: yes 56*4ca9bc22SMauro Carvalho Chehab 57*4ca9bc22SMauro Carvalho ChehabAt the end of tcm_mod_builder.py. the script will ask to add the following 58*4ca9bc22SMauro Carvalho Chehabline to drivers/target/Kbuild:: 59*4ca9bc22SMauro Carvalho Chehab 60*4ca9bc22SMauro Carvalho Chehab obj-$(CONFIG_TCM_NAB5000) += tcm_nab5000/ 61*4ca9bc22SMauro Carvalho Chehab 62*4ca9bc22SMauro Carvalho Chehaband the same for drivers/target/Kconfig:: 63*4ca9bc22SMauro Carvalho Chehab 64*4ca9bc22SMauro Carvalho Chehab source "drivers/target/tcm_nab5000/Kconfig" 65*4ca9bc22SMauro Carvalho Chehab 66*4ca9bc22SMauro Carvalho Chehab#) Run 'make menuconfig' and select the new CONFIG_TCM_NAB5000 item:: 67*4ca9bc22SMauro Carvalho Chehab 68*4ca9bc22SMauro Carvalho Chehab <M> TCM_NAB5000 fabric module 69*4ca9bc22SMauro Carvalho Chehab 70*4ca9bc22SMauro Carvalho Chehab#) Build using 'make modules', once completed you will have:: 71*4ca9bc22SMauro Carvalho Chehab 72*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# ls -la drivers/target/tcm_nab5000/ 73*4ca9bc22SMauro Carvalho Chehab total 1348 74*4ca9bc22SMauro Carvalho Chehab drwxr-xr-x 2 root root 4096 2010-10-05 03:23 . 75*4ca9bc22SMauro Carvalho Chehab drwxr-xr-x 9 root root 4096 2010-10-05 03:22 .. 76*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 282 2010-10-05 03:22 Kbuild 77*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 171 2010-10-05 03:22 Kconfig 78*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 49 2010-10-05 03:23 modules.order 79*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 738 2010-10-05 03:22 tcm_nab5000_base.h 80*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 9096 2010-10-05 03:22 tcm_nab5000_configfs.c 81*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 191200 2010-10-05 03:23 tcm_nab5000_configfs.o 82*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 40504 2010-10-05 03:23 .tcm_nab5000_configfs.o.cmd 83*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 5414 2010-10-05 03:22 tcm_nab5000_fabric.c 84*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 2016 2010-10-05 03:22 tcm_nab5000_fabric.h 85*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 190932 2010-10-05 03:23 tcm_nab5000_fabric.o 86*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 40713 2010-10-05 03:23 .tcm_nab5000_fabric.o.cmd 87*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 401861 2010-10-05 03:23 tcm_nab5000.ko 88*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 265 2010-10-05 03:23 .tcm_nab5000.ko.cmd 89*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 459 2010-10-05 03:23 tcm_nab5000.mod.c 90*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 23896 2010-10-05 03:23 tcm_nab5000.mod.o 91*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 22655 2010-10-05 03:23 .tcm_nab5000.mod.o.cmd 92*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 379022 2010-10-05 03:23 tcm_nab5000.o 93*4ca9bc22SMauro Carvalho Chehab -rw-r--r-- 1 root root 211 2010-10-05 03:23 .tcm_nab5000.o.cmd 94*4ca9bc22SMauro Carvalho Chehab 95*4ca9bc22SMauro Carvalho Chehab#) Load the new module, create a lun_0 configfs group, and add new TCM Core 96*4ca9bc22SMauro Carvalho Chehab IBLOCK backstore symlink to port:: 97*4ca9bc22SMauro Carvalho Chehab 98*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# insmod drivers/target/tcm_nab5000.ko 99*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# mkdir -p /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0 100*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# cd /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0/ 101*4ca9bc22SMauro Carvalho Chehab target:/sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0# ln -s /sys/kernel/config/target/core/iblock_0/lvm_test0 nab5000_port 102*4ca9bc22SMauro Carvalho Chehab 103*4ca9bc22SMauro Carvalho Chehab target:/sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0# cd - 104*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# tree /sys/kernel/config/target/nab5000/ 105*4ca9bc22SMauro Carvalho Chehab /sys/kernel/config/target/nab5000/ 106*4ca9bc22SMauro Carvalho Chehab |-- discovery_auth 107*4ca9bc22SMauro Carvalho Chehab |-- iqn.foo 108*4ca9bc22SMauro Carvalho Chehab | `-- tpgt_1 109*4ca9bc22SMauro Carvalho Chehab | |-- acls 110*4ca9bc22SMauro Carvalho Chehab | |-- attrib 111*4ca9bc22SMauro Carvalho Chehab | |-- lun 112*4ca9bc22SMauro Carvalho Chehab | | `-- lun_0 113*4ca9bc22SMauro Carvalho Chehab | | |-- alua_tg_pt_gp 114*4ca9bc22SMauro Carvalho Chehab | | |-- alua_tg_pt_offline 115*4ca9bc22SMauro Carvalho Chehab | | |-- alua_tg_pt_status 116*4ca9bc22SMauro Carvalho Chehab | | |-- alua_tg_pt_write_md 117*4ca9bc22SMauro Carvalho Chehab | | `-- nab5000_port -> ../../../../../../target/core/iblock_0/lvm_test0 118*4ca9bc22SMauro Carvalho Chehab | |-- np 119*4ca9bc22SMauro Carvalho Chehab | `-- param 120*4ca9bc22SMauro Carvalho Chehab `-- version 121*4ca9bc22SMauro Carvalho Chehab 122*4ca9bc22SMauro Carvalho Chehab target:/mnt/sdb/lio-core-2.6.git# lsmod 123*4ca9bc22SMauro Carvalho Chehab Module Size Used by 124*4ca9bc22SMauro Carvalho Chehab tcm_nab5000 3935 4 125*4ca9bc22SMauro Carvalho Chehab iscsi_target_mod 193211 0 126*4ca9bc22SMauro Carvalho Chehab target_core_stgt 8090 0 127*4ca9bc22SMauro Carvalho Chehab target_core_pscsi 11122 1 128*4ca9bc22SMauro Carvalho Chehab target_core_file 9172 2 129*4ca9bc22SMauro Carvalho Chehab target_core_iblock 9280 1 130*4ca9bc22SMauro Carvalho Chehab target_core_mod 228575 31 131*4ca9bc22SMauro Carvalho Chehab tcm_nab5000,iscsi_target_mod,target_core_stgt,target_core_pscsi,target_core_file,target_core_iblock 132*4ca9bc22SMauro Carvalho Chehab libfc 73681 0 133*4ca9bc22SMauro Carvalho Chehab scsi_debug 56265 0 134*4ca9bc22SMauro Carvalho Chehab scsi_tgt 8666 1 target_core_stgt 135*4ca9bc22SMauro Carvalho Chehab configfs 20644 2 target_core_mod 136*4ca9bc22SMauro Carvalho Chehab 137*4ca9bc22SMauro Carvalho Chehab---------------------------------------------------------------------- 138*4ca9bc22SMauro Carvalho Chehab 139*4ca9bc22SMauro Carvalho ChehabFuture TODO items 140*4ca9bc22SMauro Carvalho Chehab================= 141*4ca9bc22SMauro Carvalho Chehab 142*4ca9bc22SMauro Carvalho Chehab 1) Add more T10 proto_idents 143*4ca9bc22SMauro Carvalho Chehab 2) Make tcm_mod_dump_fabric_ops() smarter and generate function pointer 144*4ca9bc22SMauro Carvalho Chehab defs directly from include/target/target_core_fabric_ops.h:struct target_core_fabric_ops 145*4ca9bc22SMauro Carvalho Chehab structure members. 146*4ca9bc22SMauro Carvalho Chehab 147*4ca9bc22SMauro Carvalho ChehabOctober 5th, 2010 148*4ca9bc22SMauro Carvalho Chehab 149*4ca9bc22SMauro Carvalho ChehabNicholas A. Bellinger <nab@linux-iscsi.org> 150