当前位置:   article > 正文

Centos7下配置tgtd支持thin provision(scsi unmap)

scsi unmap

操作环境

OS

  1. CentOS Linux release 7.4.1708 (Core)
  2. Linux centos7-nfstest 3.16.55 #1 SMP Sun Mar 4 23:15:32 EST 2018 x86_64 x86_64 x86_64 GNU/Linux

tgt

  1. [root@centos7-nfstest ~]# tgtadm --version
  2. 1.0.55

操作步骤

配置tgtd支持thin provision,tgtd后端必须使用文件系统类型,不能是硬盘。并且文件系统必须支持FALLOC_FL_PUNCH_HOLE,下面是支持FALLOC_FL_PUNCH_HOLE的文件系统

  1. Not all filesystems support FALLOC_FL_PUNCH_HOLE; if a filesystem
  2. doesn't support the operation, an error is returned. The operation
  3. is supported on at least the following filesystems:
  4. * XFS (since Linux 2.6.38)
  5. * ext4 (since Linux 3.0)
  6. * Btrfs (since Linux 3.7)
  7. * tmpfs(5) (since Linux 3.5)

本次实验采用的xfs文件系统。

1.安装tgtd

[root@centos7-nfstest ~]# yum -y install scsi-target-utils

2.创建backstore文件,该文件存储在支持xfs文件系统的设备上。

[root@centos7-nfstest ~]# tgtimg --op new --device-type disk --type disk --size 5120m --file /mnt/big_disc_file1.tgt

3.修改tgtd配置文件

  1. [root@centos7-nfstest ~]# vi /etc/tgt/targets.conf
  2. # This is a sample config file for tgt-admin.
  3. #
  4. # The "#" symbol disables the processing of a line.
  5. # Set the driver. If not specified, defaults to "iscsi".
  6. default-driver iscsi
  7. # Set iSNS parameters, if needed
  8. #iSNSServerIP 192.168.111.222
  9. #iSNSServerPort 3205
  10. #iSNSAccessControl On
  11. #iSNS On
  12. # Continue if tgtadm exits with non-zero code (equivalent of
  13. # --ignore-errors command line option)
  14. ignore-errors yes
  15. include /etc/tgt/conf.d/*.conf

4.在tgt的conf.d目录下,修改sample.conf文件,也可自行创建新conf文件

  1. <target iqn.2008-09.com.example:server.target1>
  2. backing-store /mnt/big_disc_file1.tgt
  3. verdor_id BobMake
  4. </target>

5.查看tgt信息,此次我们查看tgt信息中Thin-provisioning选项为No状态

  1. [root@centos7-nfstest ~]# tgtadm --mode target --op show
  2. Target 1: iqn.2008-09.com.example:server.target1
  3. System information:
  4. Driver: iscsi
  5. State: ready
  6. I_T nexus information:
  7. LUN information:
  8. LUN: 0
  9. Type: controller
  10. SCSI ID: IET 00010000
  11. SCSI SN: beaf10
  12. Size: 0 MB, Block size: 1
  13. Online: Yes
  14. Removable media: No
  15. Prevent removal: No
  16. Readonly: No
  17. SWP: No
  18. Thin-provisioning: No
  19. Backing store type: null
  20. Backing store path: None
  21. Backing store flags:
  22. LUN: 1
  23. Type: disk
  24. SCSI ID: IET 00010001
  25. SCSI SN: beaf11
  26. Size: 5369 MB, Block size: 512
  27. Online: Yes
  28. Removable media: No
  29. Prevent removal: No
  30. Readonly: No
  31. SWP: No
  32. Thin-provisioning: No
  33. Backing store type: rdwr
  34. Backing store path: /mnt/big_disc_file1.tgt
  35. Backing store flags:
  36. Account information:
  37. ACL information:
  38. ALL

6.配置tgtd支持Thin-Provisioning

  1. [root@centos7-nfstest ~]# tgtadm --lld iscsi --mode logicalunit --op update --tid 1 --lun 0 --params thin_provisioning=1
  2. [root@centos7-nfstest ~]# tgtadm --lld iscsi --mode logicalunit --op update --tid 1 --lun 1 --params thin_provisioning=1

再次查看tgt信息,Thin-provisionging为Yes状态

  1. [root@centos7-nfstest ~]# tgtadm --mode target --op show
  2. Target 1: iqn.2008-09.com.example:server.target1
  3. System information:
  4. Driver: iscsi
  5. State: ready
  6. I_T nexus information:
  7. LUN information:
  8. LUN: 0
  9. Type: controller
  10. SCSI ID: IET 00010000
  11. SCSI SN: beaf10
  12. Size: 0 MB, Block size: 1
  13. Online: Yes
  14. Removable media: No
  15. Prevent removal: No
  16. Readonly: No
  17. SWP: No
  18. Thin-provisioning: Yes
  19. Backing store type: null
  20. Backing store path: None
  21. Backing store flags:
  22. LUN: 1
  23. Type: disk
  24. SCSI ID: IET 00010001
  25. SCSI SN: beaf11
  26. Size: 5369 MB, Block size: 512
  27. Online: Yes
  28. Removable media: No
  29. Prevent removal: No
  30. Readonly: No
  31. SWP: No
  32. Thin-provisioning: Yes
  33. Backing store type: rdwr
  34. Backing store path: /mnt/big_disc_file1.tgt
  35. Backing store flags:
  36. Account information:
  37. ACL information:
  38. ALL

很奇怪在这里必须用命令行才能配置tgtd支持thin-provisioning,在配置文件里面添加thin-provisioning如下,tgt信息里面thin-provisioning仍然显示No状态

  1. <target iqn.2008-09.com.example:server.target1>
  2. backing-store /mnt/big_disc_file1.tgt
  3. verdor_id BobMake
  4. thin_provisioning 1
  5. </target>

7.从客户端连接该tgt,并查看是否支持thin-provisioning

  1. [root@quadstor-node1 ~]# sg_vpd -p 0xb2 /dev/sdg
  2. Logical block provisioning VPD page (SBC):
  3. Unmap command supported (LBPU): 1
  4. Write same (16) with unmap bit supported (LBWS): 1
  5. Write same (10) with unmap bit supported (LBWS10): 1
  6. Logical block provisioning read zeros (LBPRZ): 1
  7. Anchored LBAs supported (ANC_SUP): 0
  8. Threshold exponent: 0
  9. Descriptor present (DP): 0
  10. Provisioning type: 2

注意unmap command supportd值为1。

8.测试scsi unmap命令

在iscsi客户端向sdg(iscsi target设备)写入数据块

  1. [root@quadstor-node1 ~]# dd if=/dev/zero of=/dev/sdg bs=512 seek=1024 count=128
  2. 128+0 records in
  3. 128+0 records out
  4. 65536 bytes (66 kB) copied, 0.014353 s, 4.6 MB/s

检验块是否映射

  1. [root@quadstor-node1 ~]# sg_get_lba_status -l 1024 /dev/sdg
  2. descriptor LBA: 0x0000000000000400 blocks: 128 mapped

取消映射块,这里我们取消16个映射块

  1. [root@quadstor-node1 ~]# sg_unmap -v -l 1024 -n 16 /dev/sdg
  2. unmap cdb: 42 00 00 00 00 00 00 00 18 00

检验unmap是否运行

查看是否已取消映射块

  1. [root@quadstor-node1 ~]# sg_get_lba_status -l 1024 /dev/sdg
  2. descriptor LBA: 0x0000000000000400 blocks: 16 deallocated

查看之后未取消的映射块

  1. [root@quadstor-node1 ~]# sg_get_lba_status -l 1040 /dev/sdg
  2. descriptor LBA: 0x0000000000000410 blocks: 112 mapped

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/217358
推荐阅读
相关标签
  

闽ICP备14008679号