Skip to content

Instantly share code, notes, and snippets.

@alicefr
Last active July 25, 2022 12:41
Show Gist options
  • Save alicefr/c2e4221d7c8834a2b8746d510692d86c to your computer and use it in GitHub Desktop.
Save alicefr/c2e4221d7c8834a2b8746d510692d86c to your computer and use it in GitHub Desktop.
Create local scsi disk and test scsi persistent reservation

Tools installation

yum install targetcli sg3_utils

Create loopback scsi target

modprobe tcm_loop
mount -t configfs configfs /sys/kernel/config/

mkdir -p /disks
targetcli backstores/fileio create disk1 /disks/disk.img 1G
targetcli loopback/ create 50014051998a423d
targetcli loopback/naa.50014051998a423d/luns create /backstores/fileio/disk1

System preparation for executing SCSI persistent reservation

mkdir -p /etc/target/pr

Clean up

targetcli loopback/ delete  50014057c28948ab
targetcli backstores/fileio delete disk1

Test scsi reservation

sg_persist -i -k /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
  PR generation=0x0, there are NO registered reservation keys
sg_persist -o -G  --param-sark=12345678 /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
sg_persist -i -k /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
  PR generation=0x1, 1 registered reservation key follows:
    0x12345678
sg_persist  -o -R --prout-type 5  --param-rk=12345678 /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
sg_persist -i -k /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
  PR generation=0x1, 1 registered reservation key follows:
    0x12345678

 sg_persist -i -r /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
  PR generation=0x1, Reservation follows:
    Key=0x12345678
    scope: LU_SCOPE,  type: Write Exclusive, registrants only

sg_persist -o -L --prout-type 5 --param-rk=12345678 /dev/sda
  LIO-ORG   disk1             4.0 
  Peripheral device type: disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment