tcm_mod_builder.rst 6.8 KB

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