In this Document
APPLIES TO:
Linux OS - Version Oracle Linux 5.0 and later
Linux x86
Linux x86-64
GOAL
SCSI Reservation is a mechanism which allow SCSI initiators to reserve a LUN for exclusive access, and preventing other initiators from making changes.
The feature is usually used in cluster. This article elaborates the basic usage of SCSI reservation in Oracle Linux.
SOLUTION
SCSI Reservation contain two stages: First, initiators must register a reservation key, then continue to reserve the device using the same reservation key when a host need exclusive access.
Here is a mini howto:
Install the necessary utils
The sg_persist command provides all the necessary functions for SCSI Reservation, it's contained in the package sg3_utils.
# yum install sg3_utils
View the registration
In this example, no reservation key had been registered yet.
# sg_persist /dev/sdc
>> No service action given; assume Persistent Reserve In command
>> with Read Keys service action
IET VIRTUAL-DISK 0001
Peripheral device type: disk
PR generation=0x4, there are NO registered reservation keys
Register a reservation key
The reservation key must be hex strings, and up to 8 bytes long, here we use abc123 for example.
# sg_persist --out --register --param-sark=abc123 /dev/sdc
The output below show a SCSI LUN which have 2 reservation keys (or 2 hosts) registered.
# sg_persist /dev/sdc
>> No service action given; assume Persistent Reserve In command
>> with Read Keys service action
IET VIRTUAL-DISK 0001
Peripheral device type: disk
PR generation=0x6, 2 registered reservation keys follow:
0xabc123
0x123abc
Reserve a registered LUN on behalf of a given key
# sg_persist --out --reserve --param-rk=abc123 --prout-type=3 /dev/sdc
IET VIRTUAL-DISK 0001
Peripheral device type: disk
The --prout-type parameter specified the reservation type, from manpage, valid types including:
-
1-> write exclusive
-
3-> exclusive access
-
5-> write exclusive - registrants only
-
6-> exclusive access - registrants only
-
7-> write exclusive - all registrants
-
8-> exclusive access - all registrants
Each "persistent reservation type" is explained in more detail in a subsection of that name in the read reservation section of the PRIN command (section 6.13.3.4 of SPC-4 revision 9).
View the reservation
The output indicated the server was reserved by key abc123, with type 3 (exclusive access):
[root@node1 ~]# sg_persist -r /dev/sdc
IET VIRTUAL-DISK 0001
Peripheral device type: disk
PR generation=0x6, Reservation follows:
Key=0xabc123
scope: LU_SCOPE, type: Exclusive Access
Verify the reservation
On node1 which have /dev/sdc1 reserved, it was able to mount the disk.
[root@node1 ~]# mount /dev/sdc1 /mnt
[root@node1 ~]# mount | grep mnt
/dev/sdc1 on /mnt type ext3 (rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered)
[root@node1 ~]# umount /mnt
In the meanwhile, it was not able to access the same disk on node2
[root@node2 ~]# mount /dev/sdc1 /mnt
mount: mount /dev/sdc1 on /mnt failed: Invalid exchange
The dmesg show reservation conflict
[root@node2 ~]# dmesg | tail
[6902380.608058] sd 11:0:0:1: [sdc] tag#16 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK
[6902380.608060] sd 11:0:0:1: [sdc] tag#16 CDB: Read(10) 28 00 00 1f ff 80 00 00 08 00
[6902380.608061] blk_update_request: critical nexus error, dev sdc, sector 2097024
[6902380.608064] Buffer I/O error on dev sdc1, logical block 261872, async page read
[6902380.609007] sd 11:0:0:1: reservation conflict
[6902380.609011] sd 11:0:0:1: [sdc] tag#14 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK
[6902380.609013] sd 11:0:0:1: [sdc] tag#14 CDB: Read(10) 28 00 00 00 08 00 00 00 01 00
[6902380.609015] blk_update_request: critical nexus error, dev sdc, sector 2048
[6902380.609523] sd 11:0:0:1: reservation conflict
[6902380.609526] blk_update_request: critical nexus error, dev sdc, sector 0
Release the reservation
# sg_persist --out --release --param-rk=abc123 --prout-type=3 /dev/sdc
Unregister a reservation key
# sg_persist --out --register --param-rk=abc123 /dev/sdc