pr-helper.rst 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ..
  2. ======================================
  3. Persistent reservation helper protocol
  4. ======================================
  5. QEMU's SCSI passthrough devices, ``scsi-block`` and ``scsi-generic``,
  6. can delegate implementation of persistent reservations to an external
  7. (and typically privileged) program. Persistent Reservations allow
  8. restricting access to block devices to specific initiators in a shared
  9. storage setup.
  10. For a more detailed reference please refer to the SCSI Primary
  11. Commands standard, specifically the section on Reservations and the
  12. "PERSISTENT RESERVE IN" and "PERSISTENT RESERVE OUT" commands.
  13. This document describes the socket protocol used between QEMU's
  14. ``pr-manager-helper`` object and the external program.
  15. .. contents::
  16. Connection and initialization
  17. -----------------------------
  18. All data transmitted on the socket is big-endian.
  19. After connecting to the helper program's socket, the helper starts a simple
  20. feature negotiation process by writing four bytes corresponding to
  21. the features it exposes (``supported_features``). QEMU reads it,
  22. then writes four bytes corresponding to the desired features of the
  23. helper program (``requested_features``).
  24. If a bit is 1 in ``requested_features`` and 0 in ``supported_features``,
  25. the corresponding feature is not supported by the helper and the connection
  26. is closed. On the other hand, it is acceptable for a bit to be 0 in
  27. ``requested_features`` and 1 in ``supported_features``; in this case,
  28. the helper will not enable the feature.
  29. Right now no feature is defined, so the two parties always write four
  30. zero bytes.
  31. Command format
  32. --------------
  33. It is invalid to send multiple commands concurrently on the same
  34. socket. It is however possible to connect multiple sockets to the
  35. helper and send multiple commands to the helper for one or more
  36. file descriptors.
  37. A command consists of a request and a response. A request consists
  38. of a 16-byte SCSI CDB. A file descriptor must be passed to the helper
  39. together with the SCSI CDB using ancillary data.
  40. The CDB has the following limitations:
  41. - the command (stored in the first byte) must be one of 0x5E
  42. (PERSISTENT RESERVE IN) or 0x5F (PERSISTENT RESERVE OUT).
  43. - the allocation length (stored in bytes 7-8 of the CDB for PERSISTENT
  44. RESERVE IN) or parameter list length (stored in bytes 5-8 of the CDB
  45. for PERSISTENT RESERVE OUT) is limited to 8 KiB.
  46. For PERSISTENT RESERVE OUT, the parameter list is sent right after the
  47. CDB. The length of the parameter list is taken from the CDB itself.
  48. The helper's reply has the following structure:
  49. - 4 bytes for the SCSI status
  50. - 4 bytes for the payload size (nonzero only for PERSISTENT RESERVE IN
  51. and only if the SCSI status is 0x00, i.e. GOOD)
  52. - 96 bytes for the SCSI sense data
  53. - if the size is nonzero, the payload follows
  54. The sense data is always sent to keep the protocol simple, even though
  55. it is only valid if the SCSI status is CHECK CONDITION (0x02).
  56. The payload size is always less than or equal to the allocation length
  57. specified in the CDB for the PERSISTENT RESERVE IN command.
  58. If the protocol is violated, the helper closes the socket.