qemu-storage-daemon.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. ===================
  2. QEMU Storage Daemon
  3. ===================
  4. Synopsis
  5. --------
  6. **qemu-storage-daemon** [options]
  7. Description
  8. -----------
  9. ``qemu-storage-daemon`` provides disk image functionality from QEMU,
  10. ``qemu-img``, and ``qemu-nbd`` in a long-running process controlled via QMP
  11. commands without running a virtual machine.
  12. It can export disk images, run block job operations, and
  13. perform other disk-related operations. The daemon is controlled via a QMP
  14. monitor and initial configuration from the command-line.
  15. The daemon offers the following subset of QEMU features:
  16. * Block nodes
  17. * Block jobs
  18. * Block exports
  19. * Throttle groups
  20. * Character devices
  21. * Crypto and secrets
  22. * QMP
  23. * IOThreads
  24. Commands can be sent over a QEMU Monitor Protocol (QMP) connection. See the
  25. :manpage:`qemu-storage-daemon-qmp-ref(7)` manual page for a description of the
  26. commands.
  27. The daemon runs until it is stopped using the ``quit`` QMP command or
  28. SIGINT/SIGHUP/SIGTERM.
  29. **Warning:** Never modify images in use by a running virtual machine or any
  30. other process; this may destroy the image. Also, be aware that querying an
  31. image that is being modified by another process may encounter inconsistent
  32. state.
  33. Options
  34. -------
  35. .. program:: qemu-storage-daemon
  36. Standard options:
  37. .. option:: -h, --help
  38. Display help and exit
  39. .. option:: -V, --version
  40. Display version information and exit
  41. .. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
  42. .. include:: ../qemu-option-trace.rst.inc
  43. .. option:: --blockdev BLOCKDEVDEF
  44. is a block node definition. See the :manpage:`qemu(1)` manual page for a
  45. description of block node properties and the :manpage:`qemu-block-drivers(7)`
  46. manual page for a description of driver-specific parameters.
  47. .. option:: --chardev CHARDEVDEF
  48. is a character device definition. See the :manpage:`qemu(1)` manual page for
  49. a description of character device properties. A common character device
  50. definition configures a UNIX domain socket::
  51. --chardev socket,id=char1,path=/var/run/qsd-qmp.sock,server=on,wait=off
  52. .. option:: --export [type=]nbd,id=<id>,node-name=<node-name>[,name=<export-name>][,writable=on|off][,bitmap=<name>]
  53. --export [type=]vhost-user-blk,id=<id>,node-name=<node-name>,addr.type=unix,addr.path=<socket-path>[,writable=on|off][,logical-block-size=<block-size>][,num-queues=<num-queues>]
  54. --export [type=]vhost-user-blk,id=<id>,node-name=<node-name>,addr.type=fd,addr.str=<fd>[,writable=on|off][,logical-block-size=<block-size>][,num-queues=<num-queues>]
  55. --export [type=]fuse,id=<id>,node-name=<node-name>,mountpoint=<file>[,growable=on|off][,writable=on|off][,allow-other=on|off|auto]
  56. --export [type=]vduse-blk,id=<id>,node-name=<node-name>,name=<vduse-name>[,writable=on|off][,num-queues=<num-queues>][,queue-size=<queue-size>][,logical-block-size=<block-size>][,serial=<serial-number>]
  57. is a block export definition. ``node-name`` is the block node that should be
  58. exported. ``writable`` determines whether or not the export allows write
  59. requests for modifying data (the default is off).
  60. The ``nbd`` export type requires ``--nbd-server`` (see below). ``name`` is
  61. the NBD export name (if not specified, it defaults to the given
  62. ``node-name``). ``bitmap`` is the name of a dirty bitmap reachable from the
  63. block node, so the NBD client can use NBD_OPT_SET_META_CONTEXT with the
  64. metadata context name "qemu:dirty-bitmap:BITMAP" to inspect the bitmap.
  65. The ``vhost-user-blk`` export type takes a vhost-user socket address on which
  66. it accept incoming connections. Both
  67. ``addr.type=unix,addr.path=<socket-path>`` for UNIX domain sockets and
  68. ``addr.type=fd,addr.str=<fd>`` for file descriptor passing are supported.
  69. ``logical-block-size`` sets the logical block size in bytes (the default is
  70. 512). ``num-queues`` sets the number of virtqueues (the default is 1).
  71. The ``fuse`` export type takes a mount point, which must be a regular file,
  72. on which to export the given block node. That file will not be changed, it
  73. will just appear to have the block node's content while the export is active
  74. (very much like mounting a filesystem on a directory does not change what the
  75. directory contains, it only shows a different content while the filesystem is
  76. mounted). Consequently, applications that have opened the given file before
  77. the export became active will continue to see its original content. If
  78. ``growable`` is set, writes after the end of the exported file will grow the
  79. block node to fit. The ``allow-other`` option controls whether users other
  80. than the user running the process will be allowed to access the export. Note
  81. that enabling this option as a non-root user requires enabling the
  82. user_allow_other option in the global fuse.conf configuration file. Setting
  83. ``allow-other`` to auto (the default) will try enabling this option, and on
  84. error fall back to disabling it.
  85. The ``vduse-blk`` export type takes a ``name`` (must be unique across the host)
  86. to create the VDUSE device.
  87. ``num-queues`` sets the number of virtqueues (the default is 1).
  88. ``queue-size`` sets the virtqueue descriptor table size (the default is 256).
  89. The instantiated VDUSE device must then be added to the vDPA bus using the
  90. vdpa(8) command from the iproute2 project::
  91. # vdpa dev add name <id> mgmtdev vduse
  92. The device can be removed from the vDPA bus later as follows::
  93. # vdpa dev del <id>
  94. For more information about attaching vDPA devices to the host with
  95. virtio_vdpa.ko or attaching them to guests with vhost_vdpa.ko, see
  96. https://vdpa-dev.gitlab.io/.
  97. For more information about VDUSE, see
  98. https://docs.kernel.org/userspace-api/vduse.html.
  99. .. option:: --monitor MONITORDEF
  100. is a QMP monitor definition. See the :manpage:`qemu(1)` manual page for
  101. a description of QMP monitor properties. A common QMP monitor definition
  102. configures a monitor on character device ``char1``::
  103. --monitor chardev=char1
  104. .. option:: --nbd-server addr.type=inet,addr.host=<host>,addr.port=<port>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
  105. --nbd-server addr.type=unix,addr.path=<path>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
  106. --nbd-server addr.type=fd,addr.str=<fd>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
  107. is a server for NBD exports. Both TCP and UNIX domain sockets are supported.
  108. A listen socket can be provided via file descriptor passing (see Examples
  109. below). TLS encryption can be configured using ``--object`` tls-creds-* and
  110. authz-* secrets (see below).
  111. To configure an NBD server on UNIX domain socket path
  112. ``/var/run/qsd-nbd.sock``::
  113. --nbd-server addr.type=unix,addr.path=/var/run/qsd-nbd.sock
  114. .. option:: --object help
  115. --object <type>,help
  116. --object <type>[,<property>=<value>...]
  117. is a QEMU user creatable object definition. List object types with ``help``.
  118. List object properties with ``<type>,help``. See the :manpage:`qemu(1)`
  119. manual page for a description of the object properties.
  120. .. option:: --pidfile PATH
  121. is the path to a file where the daemon writes its pid. This allows scripts to
  122. stop the daemon by sending a signal::
  123. $ kill -SIGTERM $(<path/to/qsd.pid)
  124. A file lock is applied to the file so only one instance of the daemon can run
  125. with a given pid file path. The daemon unlinks its pid file when terminating.
  126. The pid file is written after chardevs, exports, and NBD servers have been
  127. created but before accepting connections. The daemon has started successfully
  128. when the pid file is written and clients may begin connecting.
  129. .. option:: --daemonize
  130. Daemonize the process. The parent process will exit once startup is complete
  131. (i.e., after the pid file has been or would have been written) or failure
  132. occurs. Its exit code reflects whether the child has started up successfully
  133. or failed to do so.
  134. Examples
  135. --------
  136. Launch the daemon with QMP monitor socket ``qmp.sock`` so clients can execute
  137. QMP commands::
  138. $ qemu-storage-daemon \
  139. --chardev socket,path=qmp.sock,server=on,wait=off,id=char1 \
  140. --monitor chardev=char1
  141. Launch the daemon from Python with a QMP monitor socket using file descriptor
  142. passing so there is no need to busy wait for the QMP monitor to become
  143. available::
  144. #!/usr/bin/env python3
  145. import subprocess
  146. import socket
  147. sock_path = '/var/run/qmp.sock'
  148. with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as listen_sock:
  149. listen_sock.bind(sock_path)
  150. listen_sock.listen()
  151. fd = listen_sock.fileno()
  152. subprocess.Popen(
  153. ['qemu-storage-daemon',
  154. '--chardev', f'socket,fd={fd},server=on,id=char1',
  155. '--monitor', 'chardev=char1'],
  156. pass_fds=[fd],
  157. )
  158. # listen_sock was automatically closed when leaving the 'with' statement
  159. # body. If the daemon process terminated early then the following connect()
  160. # will fail with "Connection refused" because no process has the listen
  161. # socket open anymore. Launch errors can be detected this way.
  162. qmp_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  163. qmp_sock.connect(sock_path)
  164. ...QMP interaction...
  165. The same socket spawning approach also works with the ``--nbd-server
  166. addr.type=fd,addr.str=<fd>`` and ``--export
  167. type=vhost-user-blk,addr.type=fd,addr.str=<fd>`` options.
  168. Export raw image file ``disk.img`` over NBD UNIX domain socket ``nbd.sock``::
  169. $ qemu-storage-daemon \
  170. --blockdev driver=file,node-name=disk,filename=disk.img \
  171. --nbd-server addr.type=unix,addr.path=nbd.sock \
  172. --export type=nbd,id=export,node-name=disk,writable=on
  173. Export a qcow2 image file ``disk.qcow2`` as a vhost-user-blk device over UNIX
  174. domain socket ``vhost-user-blk.sock``::
  175. $ qemu-storage-daemon \
  176. --blockdev driver=file,node-name=file,filename=disk.qcow2 \
  177. --blockdev driver=qcow2,node-name=qcow2,file=file \
  178. --export type=vhost-user-blk,id=export,addr.type=unix,addr.path=vhost-user-blk.sock,node-name=qcow2
  179. Export a qcow2 image file ``disk.qcow2`` via FUSE on itself, so the disk image
  180. file will then appear as a raw image::
  181. $ qemu-storage-daemon \
  182. --blockdev driver=file,node-name=file,filename=disk.qcow2 \
  183. --blockdev driver=qcow2,node-name=qcow2,file=file \
  184. --export type=fuse,id=export,node-name=qcow2,mountpoint=disk.qcow2,writable=on
  185. See also
  186. --------
  187. :manpage:`qemu(1)`, :manpage:`qemu-block-drivers(7)`, :manpage:`qemu-storage-daemon-qmp-ref(7)`