Sunday 26 April 2015

How can I view, create, and remove SCSI persistent reservations and keys. from redhat

APPLIES TO:


Redhat Enterprise Linux 5, 6, 7
Oracle Enterprise Linux 5, 6, 7
SUSE Linux Enterprise Server 9,10, 11, 12

SYMPTOMS


Can't read/write to lun.
Can't join cluster.

Also you can see something like that in your dmesg:
[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


Scsi persistent reservation, usualy used in cluster environment, it's allow scsi initiator to reserve LUN to exclusive access.

SOLUTION


Install sg3_utils package. (in case of SLES, use zypper)
# yum install sg3_utils


To view the keys registered on a LUN use the following command:
# sg_persist --in -k -d /dev/sdd

To view the reservations currently out on a device use the following command:
# sg_persist --in -r -d /dev/sdd

Keys are 6 or 8 digit HEX numbers. Key numbers can be arbitrary. For example 0xDEADBEEF or 0x123ABC To register a key on a LUN use the following command:
# sg_persist --out --register --param-sark=0xDEADBEEF /dev/sdd

You can take out a reservation on behalf of a key with the following command:
# sg_persist --out --reserve --param-rk=0xDEADBEEF --prout-type=1 /dev/sdd
The reservation types are defined in the SCSI Primary Commands spec. Here are the reservation types from the sg_persist manpage

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.



to  release a registration:

# sg_persist --out --release --param-rk=0xDEADBEEF  --prout-type=5 /dev/sdd

to unregister a key:

# sg_persist --out --register --param-rk=0xDEADBEEF  /dev/sdd

clear the reservation and all registered keys:

# sg_persist --out --clear --param-rk=0xDEADBEEF   /dev/sdd





2 comments:

  1. root@zfs-storage1-n1:~# sg_persist --in -r -d /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    PR generation=0x0, Reservation follows:
    Key=0x59b18d5900000001
    scope: LU_SCOPE, type: Write Exclusive, registrants only
    root@zfs-storage1-n1:~# sg_persist --out --register --param-sark=0x59b18d5900000001 /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    root@zfs-storage1-n1:~# sg_persist --out --release --param-rk=0x59b18d5900000001 --prout-type=5 /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    root@zfs-storage1-n1:~# sg_persist --out --register --param-rk=0x59b18d5900000001 /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    root@zfs-storage1-n1:~# sg_persist --out --register --param-sark=0x59b18d5900000001 /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    root@zfs-storage1-n1:~# sg_persist --out --clear --param-rk=0x59b18d5900000001 /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    root@zfs-storage1-n1:~# sg_persist --in -r -d /dev/rdsk/c0t5000CCA04B12952Cd0
    HGST HUSMH8040BSS204 C290
    Peripheral device type: disk
    PR generation=0x7, there is NO reservation held

    ReplyDelete
  2. root@znstor5-n1:~# cat remove_scsi_psr.sh
    #!/bin/bash

    sg_persist --out --register --param-sark=${1} $2
    sg_persist --out --release --param-rk=${1} --prout-type=5 $2
    sg_persist --out --register --param-rk=${1} $2

    sg_persist --out --register --param-sark=${1} $2
    sg_persist --out --clear --param-rk=${1} $2
    root@znstor5-n1:~#

    ReplyDelete