1=============================== 2Persistent reservation managers 3=============================== 4 5SCSI persistent reservations allow restricting access to block devices 6to specific initiators in a shared storage setup. When implementing 7clustering of virtual machines, it is a common requirement for virtual 8machines to send persistent reservation SCSI commands. However, 9the operating system restricts sending these commands to unprivileged 10programs because incorrect usage can disrupt regular operation of the 11storage fabric. 12 13For this reason, QEMU's SCSI passthrough devices, ``scsi-block`` 14and ``scsi-generic`` (both are only available on Linux) can delegate 15implementation of persistent reservations to a separate object, 16the "persistent reservation manager". Only PERSISTENT RESERVE OUT and 17PERSISTENT RESERVE IN commands are passed to the persistent reservation 18manager object; other commands are processed by QEMU as usual. 19 20----------------------------------------- 21Defining a persistent reservation manager 22----------------------------------------- 23 24A persistent reservation manager is an instance of a subclass of the 25"pr-manager" QOM class. 26 27Right now only one subclass is defined, ``pr-manager-helper``, which 28forwards the commands to an external privileged helper program 29over Unix sockets. The helper program only allows sending persistent 30reservation commands to devices for which QEMU has a file descriptor, 31so that QEMU will not be able to effect persistent reservations 32unless it has access to both the socket and the device. 33 34``pr-manager-helper`` has a single string property, ``path``, which 35accepts the path to the helper program's Unix socket. For example, 36the following command line defines a ``pr-manager-helper`` object and 37attaches it to a SCSI passthrough device:: 38 39 $ qemu-system-x86_64 40 -device virtio-scsi \ 41 -object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock 42 -drive if=none,id=hd,driver=raw,file.filename=/dev/sdb,file.pr-manager=helper0 43 -device scsi-block,drive=hd 44 45Alternatively, using ``-blockdev``:: 46 47 $ qemu-system-x86_64 48 -device virtio-scsi \ 49 -object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock 50 -blockdev node-name=hd,driver=raw,file.driver=host_device,file.filename=/dev/sdb,file.pr-manager=helper0 51 -device scsi-block,drive=hd 52 53You will also need to ensure that the helper program 54:command:`qemu-pr-helper` is running, and that it has been 55set up to use the same socket filename as your QEMU commandline 56specifies. See the qemu-pr-helper documentation or manpage for 57further details. 58 59--------------------------------------------- 60Multipath devices and persistent reservations 61--------------------------------------------- 62 63Proper support of persistent reservation for multipath devices requires 64communication with the multipath daemon, so that the reservation is 65registered and applied when a path is newly discovered or becomes online 66again. :command:`qemu-pr-helper` can do this if the ``libmpathpersist`` 67library was available on the system at build time. 68 69As of August 2017, a reservation key must be specified in ``multipath.conf`` 70for ``multipathd`` to check for persistent reservation for newly 71discovered paths or reinstated paths. The attribute can be added 72to the ``defaults`` section or the ``multipaths`` section; for example:: 73 74 multipaths { 75 multipath { 76 wwid XXXXXXXXXXXXXXXX 77 alias yellow 78 reservation_key 0x123abc 79 } 80 } 81 82Linking :program:`qemu-pr-helper` to ``libmpathpersist`` does not impede 83its usage on regular SCSI devices. 84