0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

targetcliをKVM vhostで試す

0
Posted at

■debian12のKVMホストから、targetcliでディスクストレージをサービスとして提供

$ lsb_release -d
No LSB modules are available.
Description:	Debian GNU/Linux 12 (bookworm)

■仮想マシンが認識できるストレージをKVM経由でiscsiadmを使って接続

$ virsh list
 Id   名前           状態
-----------------------------
 3    kvm-debian12   実行中

■まずはtargetcliをインストール

$ apt-file search bin/targetcli
targetcli-fb: /usr/bin/targetcli          
targetcli-fb: /usr/bin/targetclid

$ dpkg -l targetcli-fb | grep ^ii || sudo apt-get install -y targetcli-fb

■タブ補完が使える、専用のシェルで操作する

$ sudo targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> <tab> 
*              /              backstores/    iscsi/         loopback/      vhost/         xen-pvscsi/    bookmarks      
cd             clearconfig    exit           get            help           ls             pwd            refresh        
restoreconfig  saveconfig     sessions       set            status         version   

/> version 
targetcli version 2.1.53

■「Storage Objects」で設定したディスクを「Targets」の方式で提供できる

$ sudo targetcli ls /backstores/ | awk '/Storage/{print $2,$(NF-2),$(NF-1),$NF}'
block [Storage Objects: 0]
fileio [Storage Objects: 0]
pscsi [Storage Objects: 0]
ramdisk [Storage Objects: 0]
$ sudo targetcli ls / | awk '!/Storage/&&/Targets/{print $2,$(NF-1),$NF}'
iscsi [Targets: 0]
loopback [Targets: 0]
vhost [Targets: 1]
xen-pvscsi [Targets: 0]

■ストレージの選択肢のうち、テストでfileioを使うとする
 ※「pscsi」は上級ユーザ向けらしいので、わかる人だけが触っているはず

 ○block:/dev/sdX
 ●fileio:ddで作ったimg
 ○ramdisk:メモリ上に作ったファイル

■ターゲットとしてサービスを提供する選択肢のうち、KVM経由で仮想マシンに提供できるvhostを選択
 ※xen-pvscsiはXen向けなので触れない
※vhostのkernel moduleがなければ「naa.」が「iqn.」になるが、iscsiを使用する方針とする。

 ○iscsi
 ○loopback
 ●vhost

■まずはシンプロビジョニング的なイメージを作成
 [ストレージオブジェクトの種類]_[提供方法].img

$ dd if=/dev/zero of=fileio_vhost.img count=0 bs=1 seek=2G
0+0 records in
0+0 records out
0 bytes copied, 0.000203523 s, 0.0 kB/s

$ du fileio_vhost.img 
0       fileio_vhost.img

■「ストレージオブジェクトの種類」に沿って、どのディスクを公開したいのかを指定

/> /backstores/fileio
/backstores/fileio> create name=fileio_vhost file_or_dev=fileio_vhost.img size=2G
fileio_vhost.img exists, using its size (2147483648 bytes) instead
Created fileio fileio_vhost with size 2147483648

/backstores/fileio> cd fileio_vhost/
/backstores/f...ileio_vhost> <tab>
/           @last       alua/       bookmarks   cd          exit        get         help        info        ls          pwd         
refresh     saveconfig  set         status      version     
/backstores/f...ileio_vhost> info 
aio: False
dev: fileio_vhost.img
name: fileio_vhost
plugin: fileio
size: 2147483648
write_back: True
wwn: b8d1643a-3dbb-49d6-830d-ed35759302c0
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- fileio_vhost ....................................................... [fileio_vhost.img (2.0GiB) write-back deactivated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
  o- xen-pvscsi ....................................................................................................... [Targets: 0]
/> cd vhost

/vhost> info
Fabric module name: vhost
ConfigFS path: /sys/kernel/config/target/vhost
Allowed WWN types: naa
Fabric module features: nexus, acls, tpgts
Corresponding kernel module: tcm_vhost

/vhost> create
Created target naa.5001405e73b2348b.
Created TPG 1

/vhost> info
Fabric module name: vhost
ConfigFS path: /sys/kernel/config/target/vhost
Allowed WWN types: naa
Fabric module features: nexus, acls, tpgts
Corresponding kernel module: tcm_vhost
/vhost> status 
Status for /vhost: Targets: 1
/vhost> ls
o- vhost .............................................................................................................. [Targets: 1]
  o- naa.5001405e73b2348b ................................................................................................ [TPGs: 1]
    o- tpg1 .................................................................................... [naa.50014055541d38b1, no-gen-acls]
      o- acls ............................................................................................................ [ACLs: 0]
      o- luns ............................................................................................................ [LUNs: 0]

/vhost> cd naa.5001405e73b2348b/tpg1/luns 
/vhost/naa.50...48b/tpg1/luns> create /backstores/fileio/fileio_vhost 
Created LUN 0.

/vhost/naa.50...48b/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 .......................................................... [fileio/fileio_vhost (fileio_vhost.img) (default_tg_pt_gp)]

■以下を参考に「naa.〜」をホストから仮想マシンにわたす
libvirt: Host Setup

$ sudo targetcli ls /vhost/
o- vhost .............................................................................................................. [Targets: 2]
  o- naa.500140522c7d4e1e ................................................................................................ [TPGs: 1]
  | o- tpg1 .................................................................................... [naa.5001405a28b9c6c7, no-gen-acls]
  |   o- acls ............................................................................................................ [ACLs: 0]
  |   o- luns ............................................................................................................ [LUNs: 1]
  |     o- lun0 .................................................... [fileio/fileio_storage (fileio_storage.img) (default_tg_pt_gp)]
$ virsh dumpxml kvm-debian12 | grep -B1 -A3 -i naa
  <hostdev mode='subsystem' type='scsi_host' managed='no'>
    <source protocol='vhost' wwpn='naa.500140522c7d4e1e'/>
    <alias name='hostdev0'/>
    <address type='pci' domain='0x0000' bus='0x07' slot='0x00' function='0x0'/>
  </hostdev>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?