TCM v4 结构模块脚本生成器

大家好,

本文档旨在作为一份简短的指南,介绍如何使用 tcm_mod_builder.py 脚本生成全新的功能性 TCM v4 结构 .ko 模块,一旦构建完成,只需使用以下命令即可立即加载,开始访问新的 TCM/ConfigFS 结构骨架:

modprobe $TCM_NEW_MOD
mkdir -p /sys/kernel/config/target/$TCM_NEW_MOD

该脚本将创建一个新的 drivers/target/$TCM_NEW_MOD/,并执行以下操作:

  1. 为 drivers/target/target_core_fabric_configs.c 逻辑生成新的 API 调用者:->make_tpg()、->drop_tpg()、->make_wwn()、->drop_wwn()。这些调用者会在 $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c 中创建。

  2. 为加载/卸载 LKM 和 TCM/ConfigFS 结构模块生成基本的基础设施,使用一个骨架 struct target_core_fabric_ops API 模板。

  3. 基于用户为正在构建的新结构模块定义的 T10 Proto_Ident,SPC-3 持久预留的 TransportID / Initiator 和 Target WWPN 相关处理程序会在 $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c 中自动生成,使用 drivers/target/target_core_fabric_lib.c 逻辑。

  4. 在 $TCM_NEW_MOD/$TCM_NEW_MOD_fabric.c 中,为所有其他数据 I/O 路径和结构相关的属性逻辑生成 NOP API 调用。

tcm_mod_builder.py 依赖于强制性的 '-p $PROTO_IDENT' 和 '-m $FABRIC_MOD_name' 参数,实际运行脚本如下所示:

target:/mnt/sdb/lio-core-2.6.git/Documentation/target# python tcm_mod_builder.py -p iSCSI -m tcm_nab5000
tcm_dir: /mnt/sdb/lio-core-2.6.git/Documentation/target/../../
Set fabric_mod_name: tcm_nab5000
Set fabric_mod_dir:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000
Using proto_ident: iSCSI
Creating fabric_mod_dir:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_base.h
Using tcm_mod_scan_fabric_ops:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../include/target/target_core_fabric_ops.h
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.c
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_fabric.h
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/tcm_nab5000_configfs.c
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kbuild
Writing file:
/mnt/sdb/lio-core-2.6.git/Documentation/target/../../drivers/target/tcm_nab5000/Kconfig
Would you like to add tcm_nab5000to drivers/target/Kbuild..? [yes,no]: yes
Would you like to add tcm_nab5000to drivers/target/Kconfig..? [yes,no]: yes

在 tcm_mod_builder.py 的末尾,脚本会要求将以下行添加到 drivers/target/Kbuild 中:

obj-$(CONFIG_TCM_NAB5000)       += tcm_nab5000/

以及对 drivers/target/Kconfig 执行相同的操作:

source "drivers/target/tcm_nab5000/Kconfig"
  1. 运行 “make menuconfig” 并选择新的 CONFIG_TCM_NAB5000 项

    <M>   TCM_NAB5000 fabric module
    
  2. 使用 “make modules” 构建,完成后,你将得到:

    target:/mnt/sdb/lio-core-2.6.git# ls -la drivers/target/tcm_nab5000/
    total 1348
    drwxr-xr-x 2 root root   4096 2010-10-05 03:23 .
    drwxr-xr-x 9 root root   4096 2010-10-05 03:22 ..
    -rw-r--r-- 1 root root    282 2010-10-05 03:22 Kbuild
    -rw-r--r-- 1 root root    171 2010-10-05 03:22 Kconfig
    -rw-r--r-- 1 root root     49 2010-10-05 03:23 modules.order
    -rw-r--r-- 1 root root    738 2010-10-05 03:22 tcm_nab5000_base.h
    -rw-r--r-- 1 root root   9096 2010-10-05 03:22 tcm_nab5000_configfs.c
    -rw-r--r-- 1 root root 191200 2010-10-05 03:23 tcm_nab5000_configfs.o
    -rw-r--r-- 1 root root  40504 2010-10-05 03:23 .tcm_nab5000_configfs.o.cmd
    -rw-r--r-- 1 root root   5414 2010-10-05 03:22 tcm_nab5000_fabric.c
    -rw-r--r-- 1 root root   2016 2010-10-05 03:22 tcm_nab5000_fabric.h
    -rw-r--r-- 1 root root 190932 2010-10-05 03:23 tcm_nab5000_fabric.o
    -rw-r--r-- 1 root root  40713 2010-10-05 03:23 .tcm_nab5000_fabric.o.cmd
    -rw-r--r-- 1 root root 401861 2010-10-05 03:23 tcm_nab5000.ko
    -rw-r--r-- 1 root root    265 2010-10-05 03:23 .tcm_nab5000.ko.cmd
    -rw-r--r-- 1 root root    459 2010-10-05 03:23 tcm_nab5000.mod.c
    -rw-r--r-- 1 root root  23896 2010-10-05 03:23 tcm_nab5000.mod.o
    -rw-r--r-- 1 root root  22655 2010-10-05 03:23 .tcm_nab5000.mod.o.cmd
    -rw-r--r-- 1 root root 379022 2010-10-05 03:23 tcm_nab5000.o
    -rw-r--r-- 1 root root    211 2010-10-05 03:23 .tcm_nab5000.o.cmd
    
  3. 加载新模块,创建一个 lun_0 configfs 组,并将新的 TCM Core IBLOCK 后端存储符号链接添加到端口

    target:/mnt/sdb/lio-core-2.6.git# insmod drivers/target/tcm_nab5000.ko
    target:/mnt/sdb/lio-core-2.6.git# mkdir -p /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0
    target:/mnt/sdb/lio-core-2.6.git# cd /sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0/
    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
    
    target:/sys/kernel/config/target/nab5000/iqn.foo/tpgt_1/lun/lun_0# cd -
    target:/mnt/sdb/lio-core-2.6.git# tree /sys/kernel/config/target/nab5000/
    /sys/kernel/config/target/nab5000/
    |-- discovery_auth
    |-- iqn.foo
    |   `-- tpgt_1
    |       |-- acls
    |       |-- attrib
    |       |-- lun
    |       |   `-- lun_0
    |       |       |-- alua_tg_pt_gp
    |       |       |-- alua_tg_pt_offline
    |       |       |-- alua_tg_pt_status
    |       |       |-- alua_tg_pt_write_md
    |   |       `-- nab5000_port -> ../../../../../../target/core/iblock_0/lvm_test0
    |       |-- np
    |       `-- param
    `-- version
    
    target:/mnt/sdb/lio-core-2.6.git# lsmod
    Module                  Size  Used by
    tcm_nab5000             3935  4
    iscsi_target_mod      193211  0
    target_core_stgt        8090  0
    target_core_pscsi      11122  1
    target_core_file        9172  2
    target_core_iblock      9280  1
    target_core_mod       228575  31
    tcm_nab5000,iscsi_target_mod,target_core_stgt,target_core_pscsi,target_core_file,target_core_iblock
    libfc                  73681  0
    scsi_debug             56265  0
    scsi_tgt                8666  1 target_core_stgt
    configfs               20644  2 target_core_mod
    

未来的 TODO 项

  1. 添加更多 T10 proto_idents

  2. 让 tcm_mod_dump_fabric_ops() 更智能,并直接从 include/target/target_core_fabric_ops.h:struct target_core_fabric_ops 结构成员生成函数指针定义。

2010 年 10 月 5 日

Nicholas A. Bellinger <nab@linux-iscsi.org>