162306a36Sopenharmony_ci=========================================
262306a36Sopenharmony_ciThe TCM v4 fabric module script generator
362306a36Sopenharmony_ci=========================================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ciGreetings all,
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciThis document is intended to be a mini-HOWTO for using the tcm_mod_builder.py
862306a36Sopenharmony_ciscript to generate a brand new functional TCM v4 fabric .ko module of your very own,
962306a36Sopenharmony_cithat once built can be immediately be loaded to start access the new TCM/ConfigFS
1062306a36Sopenharmony_cifabric skeleton, by simply using::
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci	modprobe $TCM_NEW_MOD
1362306a36Sopenharmony_ci	mkdir -p /sys/kernel/config/target/$TCM_NEW_MOD
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ciThis script will create a new drivers/target/$TCM_NEW_MOD/, and will do the following
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci	1) Generate new API callers for drivers/target/target_core_fabric_configs.c logic
1862306a36Sopenharmony_ci	   ->make_tpg(), ->drop_tpg(), ->make_wwn(), ->drop_wwn().  These are created
1962306a36Sopenharmony_ci	   into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c
2062306a36Sopenharmony_ci	2) Generate basic infrastructure for loading/unloading LKMs and TCM/ConfigFS fabric module
2162306a36Sopenharmony_ci	   using a skeleton struct target_core_fabric_ops API template.
2262306a36Sopenharmony_ci	3) Based on user defined T10 Proto_Ident for the new fabric module being built,
2362306a36Sopenharmony_ci	   the TransportID / Initiator and Target WWPN related handlers for
2462306a36Sopenharmony_ci	   SPC-3 persistent reservation are automatically generated in $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c
2562306a36Sopenharmony_ci	   using drivers/target/target_core_fabric_lib.c logic.
2662306a36Sopenharmony_ci	4) NOP API calls for all other Data I/O path and fabric dependent attribute logic
2762306a36Sopenharmony_ci	   in $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_citcm_mod_builder.py depends upon the mandatory '-p $PROTO_IDENT' and '-m
3062306a36Sopenharmony_ci$FABRIC_MOD_name' parameters, and actually running the script looks like::
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci  target:/mnt/sdb/lio-core-2.6.git/Documentation/target# python tcm_mod_builder.py -p iSCSI -m tcm_nab5000
3362306a36Sopenharmony_ci  tcm_dir: /mnt/sdb/lio-core-2.6.git/Documentation/target/../../
3462306a36Sopenharmony_ci  Set fabric_mod_name: tcm_nab5000
3562306a36Sopenharmony_ci  Set fabric_mod_dir:
3662306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000
3762306a36Sopenharmony_ci  Using proto_ident: iSCSI
3862306a36Sopenharmony_ci  Creating fabric_mod_dir:
3962306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000
4062306a36Sopenharmony_ci  Writing file:
4162306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_base.h
4262306a36Sopenharmony_ci  Using tcm_mod_scan_fabric_ops:
4362306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../include/target/target_core_fabric_ops.h
4462306a36Sopenharmony_ci  Writing file:
4562306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.c
4662306a36Sopenharmony_ci  Writing file:
4762306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.h
4862306a36Sopenharmony_ci  Writing file:
4962306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_configfs.c
5062306a36Sopenharmony_ci  Writing file:
5162306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kbuild
5262306a36Sopenharmony_ci  Writing file:
5362306a36Sopenharmony_ci  /mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kconfig
5462306a36Sopenharmony_ci  Would you like to add tcm_nab5000to drivers/target/Kbuild..? [yes,no]: yes
5562306a36Sopenharmony_ci  Would you like to add tcm_nab5000to drivers/target/Kconfig..? [yes,no]: yes
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciAt the end of tcm_mod_builder.py. the script will ask to add the following
5862306a36Sopenharmony_ciline to drivers/target/Kbuild::
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	obj-$(CONFIG_TCM_NAB5000)       += tcm_nab5000/
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciand the same for drivers/target/Kconfig::
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	source "drivers/target/tcm_nab5000/Kconfig"
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#) Run 'make menuconfig' and select the new CONFIG_TCM_NAB5000 item::
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	<M>   TCM_NAB5000 fabric module
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#) Build using 'make modules', once completed you will have::
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# ls -la drivers/target/tcm_nab5000/
7362306a36Sopenharmony_ci    total 1348
7462306a36Sopenharmony_ci    drwxr-xr-x 2 root root   4096 2010-10-05 03:23 .
7562306a36Sopenharmony_ci    drwxr-xr-x 9 root root   4096 2010-10-05 03:22 ..
7662306a36Sopenharmony_ci    -rw-r--r-- 1 root root    282 2010-10-05 03:22 Kbuild
7762306a36Sopenharmony_ci    -rw-r--r-- 1 root root    171 2010-10-05 03:22 Kconfig
7862306a36Sopenharmony_ci    -rw-r--r-- 1 root root     49 2010-10-05 03:23 modules.order
7962306a36Sopenharmony_ci    -rw-r--r-- 1 root root    738 2010-10-05 03:22 tcm_nab5000_base.h
8062306a36Sopenharmony_ci    -rw-r--r-- 1 root root   9096 2010-10-05 03:22 tcm_nab5000_configfs.c
8162306a36Sopenharmony_ci    -rw-r--r-- 1 root root 191200 2010-10-05 03:23 tcm_nab5000_configfs.o
8262306a36Sopenharmony_ci    -rw-r--r-- 1 root root  40504 2010-10-05 03:23 .tcm_nab5000_configfs.o.cmd
8362306a36Sopenharmony_ci    -rw-r--r-- 1 root root   5414 2010-10-05 03:22 tcm_nab5000_fabric.c
8462306a36Sopenharmony_ci    -rw-r--r-- 1 root root   2016 2010-10-05 03:22 tcm_nab5000_fabric.h
8562306a36Sopenharmony_ci    -rw-r--r-- 1 root root 190932 2010-10-05 03:23 tcm_nab5000_fabric.o
8662306a36Sopenharmony_ci    -rw-r--r-- 1 root root  40713 2010-10-05 03:23 .tcm_nab5000_fabric.o.cmd
8762306a36Sopenharmony_ci    -rw-r--r-- 1 root root 401861 2010-10-05 03:23 tcm_nab5000.ko
8862306a36Sopenharmony_ci    -rw-r--r-- 1 root root    265 2010-10-05 03:23 .tcm_nab5000.ko.cmd
8962306a36Sopenharmony_ci    -rw-r--r-- 1 root root    459 2010-10-05 03:23 tcm_nab5000.mod.c
9062306a36Sopenharmony_ci    -rw-r--r-- 1 root root  23896 2010-10-05 03:23 tcm_nab5000.mod.o
9162306a36Sopenharmony_ci    -rw-r--r-- 1 root root  22655 2010-10-05 03:23 .tcm_nab5000.mod.o.cmd
9262306a36Sopenharmony_ci    -rw-r--r-- 1 root root 379022 2010-10-05 03:23 tcm_nab5000.o
9362306a36Sopenharmony_ci    -rw-r--r-- 1 root root    211 2010-10-05 03:23 .tcm_nab5000.o.cmd
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#) Load the new module, create a lun_0 configfs group, and add new TCM Core
9662306a36Sopenharmony_ci   IBLOCK backstore symlink to port::
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# insmod drivers/target/tcm_nab5000.ko
9962306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# mkdir -p /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0
10062306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# cd /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0/
10162306a36Sopenharmony_ci    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
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci    target:/sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0# cd -
10462306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# tree /sys/kernel/config/target/nab5000/
10562306a36Sopenharmony_ci    /sys/kernel/config/target/nab5000/
10662306a36Sopenharmony_ci    |-- discovery_auth
10762306a36Sopenharmony_ci    |-- iqn.foo
10862306a36Sopenharmony_ci    |   `-- tpgt_1
10962306a36Sopenharmony_ci    |       |-- acls
11062306a36Sopenharmony_ci    |       |-- attrib
11162306a36Sopenharmony_ci    |       |-- lun
11262306a36Sopenharmony_ci    |       |   `-- lun_0
11362306a36Sopenharmony_ci    |       |       |-- alua_tg_pt_gp
11462306a36Sopenharmony_ci    |       |       |-- alua_tg_pt_offline
11562306a36Sopenharmony_ci    |       |       |-- alua_tg_pt_status
11662306a36Sopenharmony_ci    |       |       |-- alua_tg_pt_write_md
11762306a36Sopenharmony_ci    |	|	`-- nab5000_port -> ../../../../../../target/core/iblock_0/lvm_test0
11862306a36Sopenharmony_ci    |       |-- np
11962306a36Sopenharmony_ci    |       `-- param
12062306a36Sopenharmony_ci    `-- version
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci    target:/mnt/sdb/lio-core-2.6.git# lsmod
12362306a36Sopenharmony_ci    Module                  Size  Used by
12462306a36Sopenharmony_ci    tcm_nab5000             3935  4
12562306a36Sopenharmony_ci    iscsi_target_mod      193211  0
12662306a36Sopenharmony_ci    target_core_stgt        8090  0
12762306a36Sopenharmony_ci    target_core_pscsi      11122  1
12862306a36Sopenharmony_ci    target_core_file        9172  2
12962306a36Sopenharmony_ci    target_core_iblock      9280  1
13062306a36Sopenharmony_ci    target_core_mod       228575  31
13162306a36Sopenharmony_ci    tcm_nab5000,iscsi_target_mod,target_core_stgt,target_core_pscsi,target_core_file,target_core_iblock
13262306a36Sopenharmony_ci    libfc                  73681  0
13362306a36Sopenharmony_ci    scsi_debug             56265  0
13462306a36Sopenharmony_ci    scsi_tgt                8666  1 target_core_stgt
13562306a36Sopenharmony_ci    configfs               20644  2 target_core_mod
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci----------------------------------------------------------------------
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ciFuture TODO items
14062306a36Sopenharmony_ci=================
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci	1) Add more T10 proto_idents
14362306a36Sopenharmony_ci	2) Make tcm_mod_dump_fabric_ops() smarter and generate function pointer
14462306a36Sopenharmony_ci	   defs directly from include/target/target_core_fabric_ops.h:struct target_core_fabric_ops
14562306a36Sopenharmony_ci	   structure members.
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ciOctober 5th, 2010
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ciNicholas A. Bellinger <nab@linux-iscsi.org>
150