xref: /qemu/docs/system/pr-manager.rst (revision c6ff78563ad2971f289168c7cae6ecb0b4359516)
1*c6ff7856SPeter Maydell===============================
27c9e5276SPaolo BonziniPersistent reservation managers
3*c6ff7856SPeter Maydell===============================
47c9e5276SPaolo Bonzini
5*c6ff7856SPeter MaydellSCSI persistent reservations allow restricting access to block devices
67c9e5276SPaolo Bonzinito specific initiators in a shared storage setup.  When implementing
77c9e5276SPaolo Bonziniclustering of virtual machines, it is a common requirement for virtual
87c9e5276SPaolo Bonzinimachines to send persistent reservation SCSI commands.  However,
97c9e5276SPaolo Bonzinithe operating system restricts sending these commands to unprivileged
107c9e5276SPaolo Bonziniprograms because incorrect usage can disrupt regular operation of the
117c9e5276SPaolo Bonzinistorage fabric.
127c9e5276SPaolo Bonzini
137c9e5276SPaolo BonziniFor this reason, QEMU's SCSI passthrough devices, ``scsi-block``
147c9e5276SPaolo Bonziniand ``scsi-generic`` (both are only available on Linux) can delegate
157c9e5276SPaolo Bonziniimplementation of persistent reservations to a separate object,
167c9e5276SPaolo Bonzinithe "persistent reservation manager".  Only PERSISTENT RESERVE OUT and
177c9e5276SPaolo BonziniPERSISTENT RESERVE IN commands are passed to the persistent reservation
187c9e5276SPaolo Bonzinimanager object; other commands are processed by QEMU as usual.
197c9e5276SPaolo Bonzini
207c9e5276SPaolo Bonzini-----------------------------------------
217c9e5276SPaolo BonziniDefining a persistent reservation manager
227c9e5276SPaolo Bonzini-----------------------------------------
237c9e5276SPaolo Bonzini
247c9e5276SPaolo BonziniA persistent reservation manager is an instance of a subclass of the
257c9e5276SPaolo Bonzini"pr-manager" QOM class.
267c9e5276SPaolo Bonzini
277c9e5276SPaolo BonziniRight now only one subclass is defined, ``pr-manager-helper``, which
287c9e5276SPaolo Bonziniforwards the commands to an external privileged helper program
297c9e5276SPaolo Bonziniover Unix sockets.  The helper program only allows sending persistent
307c9e5276SPaolo Bonzinireservation commands to devices for which QEMU has a file descriptor,
317c9e5276SPaolo Bonziniso that QEMU will not be able to effect persistent reservations
327c9e5276SPaolo Bonziniunless it has access to both the socket and the device.
337c9e5276SPaolo Bonzini
347c9e5276SPaolo Bonzini``pr-manager-helper`` has a single string property, ``path``, which
357c9e5276SPaolo Bonziniaccepts the path to the helper program's Unix socket.  For example,
367c9e5276SPaolo Bonzinithe following command line defines a ``pr-manager-helper`` object and
377c9e5276SPaolo Bonziniattaches it to a SCSI passthrough device::
387c9e5276SPaolo Bonzini
397c9e5276SPaolo Bonzini      $ qemu-system-x86_64
407c9e5276SPaolo Bonzini          -device virtio-scsi \
417c9e5276SPaolo Bonzini          -object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock
427c9e5276SPaolo Bonzini          -drive if=none,id=hd,driver=raw,file.filename=/dev/sdb,file.pr-manager=helper0
437c9e5276SPaolo Bonzini          -device scsi-block,drive=hd
447c9e5276SPaolo Bonzini
457c9e5276SPaolo BonziniAlternatively, using ``-blockdev``::
467c9e5276SPaolo Bonzini
477c9e5276SPaolo Bonzini      $ qemu-system-x86_64
487c9e5276SPaolo Bonzini          -device virtio-scsi \
497c9e5276SPaolo Bonzini          -object pr-manager-helper,id=helper0,path=/var/run/qemu-pr-helper.sock
507c9e5276SPaolo Bonzini          -blockdev node-name=hd,driver=raw,file.driver=host_device,file.filename=/dev/sdb,file.pr-manager=helper0
517c9e5276SPaolo Bonzini          -device scsi-block,drive=hd
52b855f8d1SPaolo Bonzini
53773ee3f1SPeter MaydellYou will also need to ensure that the helper program
54773ee3f1SPeter Maydell:command:`qemu-pr-helper` is running, and that it has been
55773ee3f1SPeter Maydellset up to use the same socket filename as your QEMU commandline
56773ee3f1SPeter Maydellspecifies. See the qemu-pr-helper documentation or manpage for
57773ee3f1SPeter Maydellfurther details.
58fe8fc5aeSPaolo Bonzini
59fe8fc5aeSPaolo Bonzini---------------------------------------------
60fe8fc5aeSPaolo BonziniMultipath devices and persistent reservations
61fe8fc5aeSPaolo Bonzini---------------------------------------------
62fe8fc5aeSPaolo Bonzini
63fe8fc5aeSPaolo BonziniProper support of persistent reservation for multipath devices requires
64fe8fc5aeSPaolo Bonzinicommunication with the multipath daemon, so that the reservation is
65fe8fc5aeSPaolo Bonziniregistered and applied when a path is newly discovered or becomes online
66fe8fc5aeSPaolo Bonziniagain.  :command:`qemu-pr-helper` can do this if the ``libmpathpersist``
67fe8fc5aeSPaolo Bonzinilibrary was available on the system at build time.
68fe8fc5aeSPaolo Bonzini
69fe8fc5aeSPaolo BonziniAs of August 2017, a reservation key must be specified in ``multipath.conf``
70fe8fc5aeSPaolo Bonzinifor ``multipathd`` to check for persistent reservation for newly
71fe8fc5aeSPaolo Bonzinidiscovered paths or reinstated paths.  The attribute can be added
72fe8fc5aeSPaolo Bonzinito the ``defaults`` section or the ``multipaths`` section; for example::
73fe8fc5aeSPaolo Bonzini
74fe8fc5aeSPaolo Bonzini    multipaths {
75fe8fc5aeSPaolo Bonzini        multipath {
76fe8fc5aeSPaolo Bonzini            wwid   XXXXXXXXXXXXXXXX
77fe8fc5aeSPaolo Bonzini            alias      yellow
78fe8fc5aeSPaolo Bonzini            reservation_key  0x123abc
79fe8fc5aeSPaolo Bonzini        }
80fe8fc5aeSPaolo Bonzini    }
81fe8fc5aeSPaolo Bonzini
82fe8fc5aeSPaolo BonziniLinking :program:`qemu-pr-helper` to ``libmpathpersist`` does not impede
83fe8fc5aeSPaolo Bonziniits usage on regular SCSI devices.
84