Centos7下配置tgtd支援thin provision(scsi unmap)
阿新 • • 發佈:2019-01-09
操作環境
OS
CentOS Linux release 7.4.1708 (Core)
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
[[email protected] ~]# tgtadm --version
1.0.55
操作步驟
配置tgtd支援thin provision,tgtd後端必須使用檔案系統型別,不能是硬碟。並且檔案系統必須支援FALLOC_FL_PUNCH_HOLE,下面是支援FALLOC_FL_PUNCH_HOLE的檔案系統
Not all filesystems support FALLOC_FL_PUNCH_HOLE; if a filesystem doesn't support the operation, an error is returned. The operation is supported on at least the following filesystems: * XFS (since Linux 2.6.38) * ext4 (since Linux 3.0) * Btrfs (since Linux 3.7) * tmpfs(5) (since Linux 3.5)
本次實驗採用的xfs檔案系統。
1.安裝tgtd
[[email protected] ~]# yum -y install scsi-target-utils
2.建立backstore檔案,該檔案儲存在支援xfs檔案系統的裝置上。
[[email protected] ~]# tgtimg --op new --device-type disk --type disk --size 5120m --file /mnt/big_disc_file1.tgt
3.修改tgtd配置檔案
[[email protected] ~]# vi /etc/tgt/targets.conf # This is a sample config file for tgt-admin. # # The "#" symbol disables the processing of a line. # Set the driver. If not specified, defaults to "iscsi". default-driver iscsi # Set iSNS parameters, if needed #iSNSServerIP 192.168.111.222 #iSNSServerPort 3205 #iSNSAccessControl On #iSNS On # Continue if tgtadm exits with non-zero code (equivalent of # --ignore-errors command line option) ignore-errors yes include /etc/tgt/conf.d/*.conf
4.在tgt的conf.d目錄下,修改sample.conf檔案,也可自行建立新conf檔案
<target iqn.2008-09.com.example:server.target1>
backing-store /mnt/big_disc_file1.tgt
verdor_id BobMake
</target>
5.檢視tgt資訊,此次我們檢視tgt資訊中Thin-provisioning選項為No狀態
[[email protected] ~]# tgtadm --mode target --op show Target 1: iqn.2008-09.com.example:server.target1 System information: Driver: iscsi State: ready I_T nexus information: LUN information: LUN: 0 Type: controller SCSI ID: IET 00010000 SCSI SN: beaf10 Size: 0 MB, Block size: 1 Online: Yes Removable media: No Prevent removal: No Readonly: No SWP: No Thin-provisioning: No Backing store type: null Backing store path: None Backing store flags: LUN: 1 Type: disk SCSI ID: IET 00010001 SCSI SN: beaf11 Size: 5369 MB, Block size: 512 Online: Yes Removable media: No Prevent removal: No Readonly: No SWP: No Thin-provisioning: No Backing store type: rdwr Backing store path: /mnt/big_disc_file1.tgt Backing store flags: Account information: ACL information: ALL
6.配置tgtd支援Thin-Provisioning
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op update --tid 1 --lun 0 --params thin_provisioning=1
[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op update --tid 1 --lun 1 --params thin_provisioning=1
再次檢視tgt資訊,Thin-provisionging為Yes狀態
[[email protected] ~]# tgtadm --mode target --op show
Target 1: iqn.2008-09.com.example:server.target1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: Yes
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 5369 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: Yes
Backing store type: rdwr
Backing store path: /mnt/big_disc_file1.tgt
Backing store flags:
Account information:
ACL information:
ALL
很奇怪在這裡必須用命令列才能配置tgtd支援thin-provisioning,在配置檔案裡面新增thin-provisioning如下,tgt資訊裡面thin-provisioning仍然顯示No狀態
<target iqn.2008-09.com.example:server.target1>
backing-store /mnt/big_disc_file1.tgt
verdor_id BobMake
thin_provisioning 1
</target>
7.從客戶端連線該tgt,並檢視是否支援thin-provisioning
[[email protected] ~]# sg_vpd -p 0xb2 /dev/sdg
Logical block provisioning VPD page (SBC):
Unmap command supported (LBPU): 1
Write same (16) with unmap bit supported (LBWS): 1
Write same (10) with unmap bit supported (LBWS10): 1
Logical block provisioning read zeros (LBPRZ): 1
Anchored LBAs supported (ANC_SUP): 0
Threshold exponent: 0
Descriptor present (DP): 0
Provisioning type: 2
注意unmap command supportd值為1。
8.測試scsi unmap命令
在iscsi客戶端向sdg(iscsi target裝置)寫入資料塊
[[email protected] ~]# dd if=/dev/zero of=/dev/sdg bs=512 seek=1024 count=128
128+0 records in
128+0 records out
65536 bytes (66 kB) copied, 0.014353 s, 4.6 MB/s
檢驗塊是否對映
[[email protected] ~]# sg_get_lba_status -l 1024 /dev/sdg
descriptor LBA: 0x0000000000000400 blocks: 128 mapped
取消對映塊,這裡我們取消16個對映塊
[[email protected] ~]# sg_unmap -v -l 1024 -n 16 /dev/sdg
unmap cdb: 42 00 00 00 00 00 00 00 18 00
檢驗unmap是否執行
檢視是否已取消對映塊
[[email protected] ~]# sg_get_lba_status -l 1024 /dev/sdg
descriptor LBA: 0x0000000000000400 blocks: 16 deallocated
檢視之後未取消的對映塊
[[email protected] ~]# sg_get_lba_status -l 1040 /dev/sdg
descriptor LBA: 0x0000000000000410 blocks: 112 mapped