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

操作环境

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

[root@centos7-nfstest ~]# 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

[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配置文件

[root@centos7-nfstest ~]# 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文件

backing-store /mnt/big_disc_file1.tgt

verdor_id BobMake

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

[root@centos7-nfstest ~]# 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

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

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

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

[root@centos7-nfstest ~]# 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状态

backing-store /mnt/big_disc_file1.tgt

verdor_id BobMake

thin_provisioning 1

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

[root@quadstor-node1 ~]# 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设备)写入数据块

[root@quadstor-node1 ~]# 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

检验块是否映射

[root@quadstor-node1 ~]# sg_get_lba_status -l 1024 /dev/sdg

descriptor LBA: 0x0000000000000400 blocks: 128 mapped

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

[root@quadstor-node1 ~]# sg_unmap -v -l 1024 -n 16 /dev/sdg

unmap cdb: 42 00 00 00 00 00 00 00 18 00

检验unmap是否运行

查看是否已取消映射块

[root@quadstor-node1 ~]# sg_get_lba_status -l 1024 /dev/sdg

descriptor LBA: 0x0000000000000400 blocks: 16 deallocated

查看之后未取消的映射块

[root@quadstor-node1 ~]# sg_get_lba_status -l 1040 /dev/sdg

descriptor LBA: 0x0000000000000410 blocks: 112 mapped

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值