xref: /openbmc/linux/Documentation/block/pr.rst (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1898bd37aSMauro Carvalho Chehab===============================================
2898bd37aSMauro Carvalho ChehabBlock layer support for Persistent Reservations
3898bd37aSMauro Carvalho Chehab===============================================
4898bd37aSMauro Carvalho Chehab
5898bd37aSMauro Carvalho ChehabThe Linux kernel supports a user space interface for simplified
6898bd37aSMauro Carvalho ChehabPersistent Reservations which map to block devices that support
7898bd37aSMauro Carvalho Chehabthese (like SCSI). Persistent Reservations allow restricting
8898bd37aSMauro Carvalho Chehabaccess to block devices to specific initiators in a shared storage
9898bd37aSMauro Carvalho Chehabsetup.
10898bd37aSMauro Carvalho Chehab
11898bd37aSMauro Carvalho ChehabThis document gives a general overview of the support ioctl commands.
12*6fa9a5a2SRandy DunlapFor a more detailed reference please refer to the SCSI Primary
13898bd37aSMauro Carvalho ChehabCommands standard, specifically the section on Reservations and the
14898bd37aSMauro Carvalho Chehab"PERSISTENT RESERVE IN" and "PERSISTENT RESERVE OUT" commands.
15898bd37aSMauro Carvalho Chehab
16898bd37aSMauro Carvalho ChehabAll implementations are expected to ensure the reservations survive
17898bd37aSMauro Carvalho Chehaba power loss and cover all connections in a multi path environment.
18898bd37aSMauro Carvalho ChehabThese behaviors are optional in SPC but will be automatically applied
19898bd37aSMauro Carvalho Chehabby Linux.
20898bd37aSMauro Carvalho Chehab
21898bd37aSMauro Carvalho Chehab
22898bd37aSMauro Carvalho ChehabThe following types of reservations are supported:
23898bd37aSMauro Carvalho Chehab--------------------------------------------------
24898bd37aSMauro Carvalho Chehab
25898bd37aSMauro Carvalho Chehab - PR_WRITE_EXCLUSIVE
26898bd37aSMauro Carvalho Chehab	Only the initiator that owns the reservation can write to the
27898bd37aSMauro Carvalho Chehab	device.  Any initiator can read from the device.
28898bd37aSMauro Carvalho Chehab
29898bd37aSMauro Carvalho Chehab - PR_EXCLUSIVE_ACCESS
30898bd37aSMauro Carvalho Chehab	Only the initiator that owns the reservation can access the
31898bd37aSMauro Carvalho Chehab	device.
32898bd37aSMauro Carvalho Chehab
33898bd37aSMauro Carvalho Chehab - PR_WRITE_EXCLUSIVE_REG_ONLY
34898bd37aSMauro Carvalho Chehab	Only initiators with a registered key can write to the device,
35898bd37aSMauro Carvalho Chehab	Any initiator can read from the device.
36898bd37aSMauro Carvalho Chehab
37898bd37aSMauro Carvalho Chehab - PR_EXCLUSIVE_ACCESS_REG_ONLY
38898bd37aSMauro Carvalho Chehab	Only initiators with a registered key can access the device.
39898bd37aSMauro Carvalho Chehab
40898bd37aSMauro Carvalho Chehab - PR_WRITE_EXCLUSIVE_ALL_REGS
41898bd37aSMauro Carvalho Chehab
42898bd37aSMauro Carvalho Chehab	Only initiators with a registered key can write to the device,
43898bd37aSMauro Carvalho Chehab	Any initiator can read from the device.
44898bd37aSMauro Carvalho Chehab	All initiators with a registered key are considered reservation
45898bd37aSMauro Carvalho Chehab	holders.
46898bd37aSMauro Carvalho Chehab	Please reference the SPC spec on the meaning of a reservation
47898bd37aSMauro Carvalho Chehab	holder if you want to use this type.
48898bd37aSMauro Carvalho Chehab
49898bd37aSMauro Carvalho Chehab - PR_EXCLUSIVE_ACCESS_ALL_REGS
50898bd37aSMauro Carvalho Chehab	Only initiators with a registered key can access the device.
51898bd37aSMauro Carvalho Chehab	All initiators with a registered key are considered reservation
52898bd37aSMauro Carvalho Chehab	holders.
53898bd37aSMauro Carvalho Chehab	Please reference the SPC spec on the meaning of a reservation
54898bd37aSMauro Carvalho Chehab	holder if you want to use this type.
55898bd37aSMauro Carvalho Chehab
56898bd37aSMauro Carvalho Chehab
57898bd37aSMauro Carvalho ChehabThe following ioctl are supported:
58898bd37aSMauro Carvalho Chehab----------------------------------
59898bd37aSMauro Carvalho Chehab
60898bd37aSMauro Carvalho Chehab1. IOC_PR_REGISTER
61898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^
62898bd37aSMauro Carvalho Chehab
63898bd37aSMauro Carvalho ChehabThis ioctl command registers a new reservation if the new_key argument
64898bd37aSMauro Carvalho Chehabis non-null.  If no existing reservation exists old_key must be zero,
65898bd37aSMauro Carvalho Chehabif an existing reservation should be replaced old_key must contain
66898bd37aSMauro Carvalho Chehabthe old reservation key.
67898bd37aSMauro Carvalho Chehab
68898bd37aSMauro Carvalho ChehabIf the new_key argument is 0 it unregisters the existing reservation passed
69898bd37aSMauro Carvalho Chehabin old_key.
70898bd37aSMauro Carvalho Chehab
71898bd37aSMauro Carvalho Chehab
72898bd37aSMauro Carvalho Chehab2. IOC_PR_RESERVE
73898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^^^
74898bd37aSMauro Carvalho Chehab
75898bd37aSMauro Carvalho ChehabThis ioctl command reserves the device and thus restricts access for other
76898bd37aSMauro Carvalho Chehabdevices based on the type argument.  The key argument must be the existing
77898bd37aSMauro Carvalho Chehabreservation key for the device as acquired by the IOC_PR_REGISTER,
78898bd37aSMauro Carvalho ChehabIOC_PR_REGISTER_IGNORE, IOC_PR_PREEMPT or IOC_PR_PREEMPT_ABORT commands.
79898bd37aSMauro Carvalho Chehab
80898bd37aSMauro Carvalho Chehab
81898bd37aSMauro Carvalho Chehab3. IOC_PR_RELEASE
82898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^^^
83898bd37aSMauro Carvalho Chehab
84898bd37aSMauro Carvalho ChehabThis ioctl command releases the reservation specified by key and flags
85898bd37aSMauro Carvalho Chehaband thus removes any access restriction implied by it.
86898bd37aSMauro Carvalho Chehab
87898bd37aSMauro Carvalho Chehab
88898bd37aSMauro Carvalho Chehab4. IOC_PR_PREEMPT
89898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^^^
90898bd37aSMauro Carvalho Chehab
91898bd37aSMauro Carvalho ChehabThis ioctl command releases the existing reservation referred to by
92898bd37aSMauro Carvalho Chehabold_key and replaces it with a new reservation of type for the
93898bd37aSMauro Carvalho Chehabreservation key new_key.
94898bd37aSMauro Carvalho Chehab
95898bd37aSMauro Carvalho Chehab
96898bd37aSMauro Carvalho Chehab5. IOC_PR_PREEMPT_ABORT
97898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^^^^^^^^^
98898bd37aSMauro Carvalho Chehab
99898bd37aSMauro Carvalho ChehabThis ioctl command works like IOC_PR_PREEMPT except that it also aborts
100898bd37aSMauro Carvalho Chehabany outstanding command sent over a connection identified by old_key.
101898bd37aSMauro Carvalho Chehab
102898bd37aSMauro Carvalho Chehab6. IOC_PR_CLEAR
103898bd37aSMauro Carvalho Chehab^^^^^^^^^^^^^^^
104898bd37aSMauro Carvalho Chehab
105898bd37aSMauro Carvalho ChehabThis ioctl command unregisters both key and any other reservation key
106898bd37aSMauro Carvalho Chehabregistered with the device and drops any existing reservation.
107898bd37aSMauro Carvalho Chehab
108898bd37aSMauro Carvalho Chehab
109898bd37aSMauro Carvalho ChehabFlags
110898bd37aSMauro Carvalho Chehab-----
111898bd37aSMauro Carvalho Chehab
112898bd37aSMauro Carvalho ChehabAll the ioctls have a flag field.  Currently only one flag is supported:
113898bd37aSMauro Carvalho Chehab
114898bd37aSMauro Carvalho Chehab - PR_FL_IGNORE_KEY
115898bd37aSMauro Carvalho Chehab	Ignore the existing reservation key.  This is commonly supported for
116898bd37aSMauro Carvalho Chehab	IOC_PR_REGISTER, and some implementation may support the flag for
117898bd37aSMauro Carvalho Chehab	IOC_PR_RESERVE.
118898bd37aSMauro Carvalho Chehab
119898bd37aSMauro Carvalho ChehabFor all unknown flags the kernel will return -EOPNOTSUPP.
120