xref: /OK3568_Linux_fs/kernel/Documentation/block/pr.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===============================================
2*4882a593SmuzhiyunBlock layer support for Persistent Reservations
3*4882a593Smuzhiyun===============================================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunThe Linux kernel supports a user space interface for simplified
6*4882a593SmuzhiyunPersistent Reservations which map to block devices that support
7*4882a593Smuzhiyunthese (like SCSI). Persistent Reservations allow restricting
8*4882a593Smuzhiyunaccess to block devices to specific initiators in a shared storage
9*4882a593Smuzhiyunsetup.
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThis document gives a general overview of the support ioctl commands.
12*4882a593SmuzhiyunFor a more detailed reference please refer to the SCSI Primary
13*4882a593SmuzhiyunCommands standard, specifically the section on Reservations and the
14*4882a593Smuzhiyun"PERSISTENT RESERVE IN" and "PERSISTENT RESERVE OUT" commands.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunAll implementations are expected to ensure the reservations survive
17*4882a593Smuzhiyuna power loss and cover all connections in a multi path environment.
18*4882a593SmuzhiyunThese behaviors are optional in SPC but will be automatically applied
19*4882a593Smuzhiyunby Linux.
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunThe following types of reservations are supported:
23*4882a593Smuzhiyun--------------------------------------------------
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun - PR_WRITE_EXCLUSIVE
26*4882a593Smuzhiyun	Only the initiator that owns the reservation can write to the
27*4882a593Smuzhiyun	device.  Any initiator can read from the device.
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun - PR_EXCLUSIVE_ACCESS
30*4882a593Smuzhiyun	Only the initiator that owns the reservation can access the
31*4882a593Smuzhiyun	device.
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun - PR_WRITE_EXCLUSIVE_REG_ONLY
34*4882a593Smuzhiyun	Only initiators with a registered key can write to the device,
35*4882a593Smuzhiyun	Any initiator can read from the device.
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun - PR_EXCLUSIVE_ACCESS_REG_ONLY
38*4882a593Smuzhiyun	Only initiators with a registered key can access the device.
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun - PR_WRITE_EXCLUSIVE_ALL_REGS
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun	Only initiators with a registered key can write to the device,
43*4882a593Smuzhiyun	Any initiator can read from the device.
44*4882a593Smuzhiyun	All initiators with a registered key are considered reservation
45*4882a593Smuzhiyun	holders.
46*4882a593Smuzhiyun	Please reference the SPC spec on the meaning of a reservation
47*4882a593Smuzhiyun	holder if you want to use this type.
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun - PR_EXCLUSIVE_ACCESS_ALL_REGS
50*4882a593Smuzhiyun	Only initiators with a registered key can access the device.
51*4882a593Smuzhiyun	All initiators with a registered key are considered reservation
52*4882a593Smuzhiyun	holders.
53*4882a593Smuzhiyun	Please reference the SPC spec on the meaning of a reservation
54*4882a593Smuzhiyun	holder if you want to use this type.
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun
57*4882a593SmuzhiyunThe following ioctl are supported:
58*4882a593Smuzhiyun----------------------------------
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun1. IOC_PR_REGISTER
61*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunThis ioctl command registers a new reservation if the new_key argument
64*4882a593Smuzhiyunis non-null.  If no existing reservation exists old_key must be zero,
65*4882a593Smuzhiyunif an existing reservation should be replaced old_key must contain
66*4882a593Smuzhiyunthe old reservation key.
67*4882a593Smuzhiyun
68*4882a593SmuzhiyunIf the new_key argument is 0 it unregisters the existing reservation passed
69*4882a593Smuzhiyunin old_key.
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun2. IOC_PR_RESERVE
73*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^
74*4882a593Smuzhiyun
75*4882a593SmuzhiyunThis ioctl command reserves the device and thus restricts access for other
76*4882a593Smuzhiyundevices based on the type argument.  The key argument must be the existing
77*4882a593Smuzhiyunreservation key for the device as acquired by the IOC_PR_REGISTER,
78*4882a593SmuzhiyunIOC_PR_REGISTER_IGNORE, IOC_PR_PREEMPT or IOC_PR_PREEMPT_ABORT commands.
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun3. IOC_PR_RELEASE
82*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunThis ioctl command releases the reservation specified by key and flags
85*4882a593Smuzhiyunand thus removes any access restriction implied by it.
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun4. IOC_PR_PREEMPT
89*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunThis ioctl command releases the existing reservation referred to by
92*4882a593Smuzhiyunold_key and replaces it with a new reservation of type for the
93*4882a593Smuzhiyunreservation key new_key.
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun5. IOC_PR_PREEMPT_ABORT
97*4882a593Smuzhiyun^^^^^^^^^^^^^^^^^^^^^^^
98*4882a593Smuzhiyun
99*4882a593SmuzhiyunThis ioctl command works like IOC_PR_PREEMPT except that it also aborts
100*4882a593Smuzhiyunany outstanding command sent over a connection identified by old_key.
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun6. IOC_PR_CLEAR
103*4882a593Smuzhiyun^^^^^^^^^^^^^^^
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunThis ioctl command unregisters both key and any other reservation key
106*4882a593Smuzhiyunregistered with the device and drops any existing reservation.
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun
109*4882a593SmuzhiyunFlags
110*4882a593Smuzhiyun-----
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunAll the ioctls have a flag field.  Currently only one flag is supported:
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun - PR_FL_IGNORE_KEY
115*4882a593Smuzhiyun	Ignore the existing reservation key.  This is commonly supported for
116*4882a593Smuzhiyun	IOC_PR_REGISTER, and some implementation may support the flag for
117*4882a593Smuzhiyun	IOC_PR_RESERVE.
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunFor all unknown flags the kernel will return -EOPNOTSUPP.
120