cpu: Introduce SysemuCPUOps structure
[qemu/ar7.git] / docs / tools / qemu-storage-daemon.rst
blob3ec4bdd9145a6f4cf876981788d85a8209d3d5cc
1 QEMU Storage Daemon
2 ===================
4 Synopsis
5 --------
7 **qemu-storage-daemon** [options]
9 Description
10 -----------
12 qemu-storage-daemon provides disk image functionality from QEMU, qemu-img, and
13 qemu-nbd in a long-running process controlled via QMP commands without running
14 a virtual machine. It can export disk images, run block job operations, and
15 perform other disk-related operations. The daemon is controlled via a QMP
16 monitor and initial configuration from the command-line.
18 The daemon offers the following subset of QEMU features:
20 * Block nodes
21 * Block jobs
22 * Block exports
23 * Throttle groups
24 * Character devices
25 * Crypto and secrets
26 * QMP
27 * IOThreads
29 Commands can be sent over a QEMU Monitor Protocol (QMP) connection. See the
30 :manpage:`qemu-storage-daemon-qmp-ref(7)` manual page for a description of the
31 commands.
33 The daemon runs until it is stopped using the ``quit`` QMP command or
34 SIGINT/SIGHUP/SIGTERM.
36 **Warning:** Never modify images in use by a running virtual machine or any
37 other process; this may destroy the image. Also, be aware that querying an
38 image that is being modified by another process may encounter inconsistent
39 state.
41 Options
42 -------
44 .. program:: qemu-storage-daemon
46 Standard options:
48 .. option:: -h, --help
50   Display help and exit
52 .. option:: -V, --version
54   Display version information and exit
56 .. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
58   .. include:: ../qemu-option-trace.rst.inc
60 .. option:: --blockdev BLOCKDEVDEF
62   is a block node definition. See the :manpage:`qemu(1)` manual page for a
63   description of block node properties and the :manpage:`qemu-block-drivers(7)`
64   manual page for a description of driver-specific parameters.
66 .. option:: --chardev CHARDEVDEF
68   is a character device definition. See the :manpage:`qemu(1)` manual page for
69   a description of character device properties. A common character device
70   definition configures a UNIX domain socket::
72   --chardev socket,id=char1,path=/var/run/qsd-qmp.sock,server=on,wait=off
74 .. option:: --export [type=]nbd,id=<id>,node-name=<node-name>[,name=<export-name>][,writable=on|off][,bitmap=<name>]
75   --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>]
76   --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>]
77   --export [type=]fuse,id=<id>,node-name=<node-name>,mountpoint=<file>[,growable=on|off][,writable=on|off]
79   is a block export definition. ``node-name`` is the block node that should be
80   exported. ``writable`` determines whether or not the export allows write
81   requests for modifying data (the default is off).
83   The ``nbd`` export type requires ``--nbd-server`` (see below). ``name`` is
84   the NBD export name (if not specified, it defaults to the given
85   ``node-name``). ``bitmap`` is the name of a dirty bitmap reachable from the
86   block node, so the NBD client can use NBD_OPT_SET_META_CONTEXT with the
87   metadata context name "qemu:dirty-bitmap:BITMAP" to inspect the bitmap.
89   The ``vhost-user-blk`` export type takes a vhost-user socket address on which
90   it accept incoming connections. Both
91   ``addr.type=unix,addr.path=<socket-path>`` for UNIX domain sockets and
92   ``addr.type=fd,addr.str=<fd>`` for file descriptor passing are supported.
93   ``logical-block-size`` sets the logical block size in bytes (the default is
94   512). ``num-queues`` sets the number of virtqueues (the default is 1).
96   The ``fuse`` export type takes a mount point, which must be a regular file,
97   on which to export the given block node. That file will not be changed, it
98   will just appear to have the block node's content while the export is active
99   (very much like mounting a filesystem on a directory does not change what the
100   directory contains, it only shows a different content while the filesystem is
101   mounted). Consequently, applications that have opened the given file before
102   the export became active will continue to see its original content. If
103   ``growable`` is set, writes after the end of the exported file will grow the
104   block node to fit.
106 .. option:: --monitor MONITORDEF
108   is a QMP monitor definition. See the :manpage:`qemu(1)` manual page for
109   a description of QMP monitor properties. A common QMP monitor definition
110   configures a monitor on character device ``char1``::
112   --monitor chardev=char1
114 .. option:: --nbd-server addr.type=inet,addr.host=<host>,addr.port=<port>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
115   --nbd-server addr.type=unix,addr.path=<path>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
116   --nbd-server addr.type=fd,addr.str=<fd>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
118   is a server for NBD exports. Both TCP and UNIX domain sockets are supported.
119   A listen socket can be provided via file descriptor passing (see Examples
120   below). TLS encryption can be configured using ``--object`` tls-creds-* and
121   authz-* secrets (see below).
123   To configure an NBD server on UNIX domain socket path
124   ``/var/run/qsd-nbd.sock``::
126   --nbd-server addr.type=unix,addr.path=/var/run/qsd-nbd.sock
128 .. option:: --object help
129   --object <type>,help
130   --object <type>[,<property>=<value>...]
132   is a QEMU user creatable object definition. List object types with ``help``.
133   List object properties with ``<type>,help``. See the :manpage:`qemu(1)`
134   manual page for a description of the object properties.
136 .. option:: --pidfile PATH
138   is the path to a file where the daemon writes its pid. This allows scripts to
139   stop the daemon by sending a signal::
141     $ kill -SIGTERM $(<path/to/qsd.pid)
143   A file lock is applied to the file so only one instance of the daemon can run
144   with a given pid file path. The daemon unlinks its pid file when terminating.
146   The pid file is written after chardevs, exports, and NBD servers have been
147   created but before accepting connections. The daemon has started successfully
148   when the pid file is written and clients may begin connecting.
150 Examples
151 --------
152 Launch the daemon with QMP monitor socket ``qmp.sock`` so clients can execute
153 QMP commands::
155   $ qemu-storage-daemon \
156       --chardev socket,path=qmp.sock,server=on,wait=off,id=char1 \
157       --monitor chardev=char1
159 Launch the daemon from Python with a QMP monitor socket using file descriptor
160 passing so there is no need to busy wait for the QMP monitor to become
161 available::
163   #!/usr/bin/env python3
164   import subprocess
165   import socket
167   sock_path = '/var/run/qmp.sock'
169   with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as listen_sock:
170       listen_sock.bind(sock_path)
171       listen_sock.listen()
173       fd = listen_sock.fileno()
175       subprocess.Popen(
176           ['qemu-storage-daemon',
177            '--chardev', f'socket,fd={fd},server=on,id=char1',
178            '--monitor', 'chardev=char1'],
179           pass_fds=[fd],
180       )
182   # listen_sock was automatically closed when leaving the 'with' statement
183   # body. If the daemon process terminated early then the following connect()
184   # will fail with "Connection refused" because no process has the listen
185   # socket open anymore. Launch errors can be detected this way.
187   qmp_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
188   qmp_sock.connect(sock_path)
189   ...QMP interaction...
191 The same socket spawning approach also works with the ``--nbd-server
192 addr.type=fd,addr.str=<fd>`` and ``--export
193 type=vhost-user-blk,addr.type=fd,addr.str=<fd>`` options.
195 Export raw image file ``disk.img`` over NBD UNIX domain socket ``nbd.sock``::
197   $ qemu-storage-daemon \
198       --blockdev driver=file,node-name=disk,filename=disk.img \
199       --nbd-server addr.type=unix,addr.path=nbd.sock \
200       --export type=nbd,id=export,node-name=disk,writable=on
202 Export a qcow2 image file ``disk.qcow2`` as a vhosts-user-blk device over UNIX
203 domain socket ``vhost-user-blk.sock``::
205   $ qemu-storage-daemon \
206       --blockdev driver=file,node-name=file,filename=disk.qcow2 \
207       --blockdev driver=qcow2,node-name=qcow2,file=file \
208       --export type=vhost-user-blk,id=export,addr.type=unix,addr.path=vhost-user-blk.sock,node-name=qcow2
210 Export a qcow2 image file ``disk.qcow2`` via FUSE on itself, so the disk image
211 file will then appear as a raw image::
213   $ qemu-storage-daemon \
214       --blockdev driver=file,node-name=file,filename=disk.qcow2 \
215       --blockdev driver=qcow2,node-name=qcow2,file=file \
216       --export type=fuse,id=export,node-name=qcow2,mountpoint=disk.qcow2,writable=on
218 See also
219 --------
221 :manpage:`qemu(1)`, :manpage:`qemu-block-drivers(7)`, :manpage:`qemu-storage-daemon-qmp-ref(7)`