xref: /openbmc/qemu/docs/tools/qemu-storage-daemon.rst (revision e246bf3ddc4d61d03227373fecfdcd4fec3508db)
1QEMU Storage Daemon
2===================
3
4Synopsis
5--------
6
7**qemu-storage-daemon** [options]
8
9Description
10-----------
11
12qemu-storage-daemon provides disk image functionality from QEMU, qemu-img, and
13qemu-nbd in a long-running process controlled via QMP commands without running
14a virtual machine. It can export disk images, run block job operations, and
15perform other disk-related operations. The daemon is controlled via a QMP
16monitor and initial configuration from the command-line.
17
18The daemon offers the following subset of QEMU features:
19
20* Block nodes
21* Block jobs
22* Block exports
23* Throttle groups
24* Character devices
25* Crypto and secrets
26* QMP
27* IOThreads
28
29Commands 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
31commands.
32
33The daemon runs until it is stopped using the ``quit`` QMP command or
34SIGINT/SIGHUP/SIGTERM.
35
36**Warning:** Never modify images in use by a running virtual machine or any
37other process; this may destroy the image. Also, be aware that querying an
38image that is being modified by another process may encounter inconsistent
39state.
40
41Options
42-------
43
44.. program:: qemu-storage-daemon
45
46Standard options:
47
48.. option:: -h, --help
49
50  Display help and exit
51
52.. option:: -V, --version
53
54  Display version information and exit
55
56.. option:: -T, --trace [[enable=]PATTERN][,events=FILE][,file=FILE]
57
58  .. include:: ../qemu-option-trace.rst.inc
59
60.. option:: --blockdev BLOCKDEVDEF
61
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.
65
66.. option:: --chardev CHARDEVDEF
67
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::
71
72  --chardev socket,id=char1,path=/var/run/qsd-qmp.sock,server=on,wait=off
73
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
78  is a block export definition. ``node-name`` is the block node that should be
79  exported. ``writable`` determines whether or not the export allows write
80  requests for modifying data (the default is off).
81
82  The ``nbd`` export type requires ``--nbd-server`` (see below). ``name`` is
83  the NBD export name. ``bitmap`` is the name of a dirty bitmap reachable from
84  the block node, so the NBD client can use NBD_OPT_SET_META_CONTEXT with the
85  metadata context name "qemu:dirty-bitmap:BITMAP" to inspect the bitmap.
86
87  The ``vhost-user-blk`` export type takes a vhost-user socket address on which
88  it accept incoming connections. Both
89  ``addr.type=unix,addr.path=<socket-path>`` for UNIX domain sockets and
90  ``addr.type=fd,addr.str=<fd>`` for file descriptor passing are supported.
91  ``logical-block-size`` sets the logical block size in bytes (the default is
92  512). ``num-queues`` sets the number of virtqueues (the default is 1).
93
94.. option:: --monitor MONITORDEF
95
96  is a QMP monitor definition. See the :manpage:`qemu(1)` manual page for
97  a description of QMP monitor properties. A common QMP monitor definition
98  configures a monitor on character device ``char1``::
99
100  --monitor chardev=char1
101
102.. option:: --nbd-server addr.type=inet,addr.host=<host>,addr.port=<port>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
103  --nbd-server addr.type=unix,addr.path=<path>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
104  --nbd-server addr.type=fd,addr.str=<fd>[,tls-creds=<id>][,tls-authz=<id>][,max-connections=<n>]
105
106  is a server for NBD exports. Both TCP and UNIX domain sockets are supported.
107  A listen socket can be provided via file descriptor passing (see Examples
108  below). TLS encryption can be configured using ``--object`` tls-creds-* and
109  authz-* secrets (see below).
110
111  To configure an NBD server on UNIX domain socket path
112  ``/var/run/qsd-nbd.sock``::
113
114  --nbd-server addr.type=unix,addr.path=/var/run/qsd-nbd.sock
115
116.. option:: --object help
117  --object <type>,help
118  --object <type>[,<property>=<value>...]
119
120  is a QEMU user creatable object definition. List object types with ``help``.
121  List object properties with ``<type>,help``. See the :manpage:`qemu(1)`
122  manual page for a description of the object properties.
123
124.. option:: --pidfile PATH
125
126  is the path to a file where the daemon writes its pid. This allows scripts to
127  stop the daemon by sending a signal::
128
129    $ kill -SIGTERM $(<path/to/qsd.pid)
130
131  A file lock is applied to the file so only one instance of the daemon can run
132  with a given pid file path. The daemon unlinks its pid file when terminating.
133
134  The pid file is written after chardevs, exports, and NBD servers have been
135  created but before accepting connections. The daemon has started successfully
136  when the pid file is written and clients may begin connecting.
137
138Examples
139--------
140Launch the daemon with QMP monitor socket ``qmp.sock`` so clients can execute
141QMP commands::
142
143  $ qemu-storage-daemon \
144      --chardev socket,path=qmp.sock,server=on,wait=off,id=char1 \
145      --monitor chardev=char1
146
147Launch the daemon from Python with a QMP monitor socket using file descriptor
148passing so there is no need to busy wait for the QMP monitor to become
149available::
150
151  #!/usr/bin/env python3
152  import subprocess
153  import socket
154
155  sock_path = '/var/run/qmp.sock'
156
157  with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as listen_sock:
158      listen_sock.bind(sock_path)
159      listen_sock.listen()
160
161      fd = listen_sock.fileno()
162
163      subprocess.Popen(
164          ['qemu-storage-daemon',
165           '--chardev', f'socket,fd={fd},server=on,id=char1',
166           '--monitor', 'chardev=char1'],
167          pass_fds=[fd],
168      )
169
170  # listen_sock was automatically closed when leaving the 'with' statement
171  # body. If the daemon process terminated early then the following connect()
172  # will fail with "Connection refused" because no process has the listen
173  # socket open anymore. Launch errors can be detected this way.
174
175  qmp_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
176  qmp_sock.connect(sock_path)
177  ...QMP interaction...
178
179The same socket spawning approach also works with the ``--nbd-server
180addr.type=fd,addr.str=<fd>`` and ``--export
181type=vhost-user-blk,addr.type=fd,addr.str=<fd>`` options.
182
183Export raw image file ``disk.img`` over NBD UNIX domain socket ``nbd.sock``::
184
185  $ qemu-storage-daemon \
186      --blockdev driver=file,node-name=disk,filename=disk.img \
187      --nbd-server addr.type=unix,addr.path=nbd.sock \
188      --export type=nbd,id=export,node-name=disk,writable=on
189
190Export a qcow2 image file ``disk.qcow2`` as a vhosts-user-blk device over UNIX
191domain socket ``vhost-user-blk.sock``::
192
193  $ qemu-storage-daemon \
194      --blockdev driver=file,node-name=file,filename=disk.qcow2 \
195      --blockdev driver=qcow2,node-name=qcow2,file=file \
196      --export type=vhost-user-blk,id=export,addr.type=unix,addr.path=vhost-user-blk.sock,node-name=qcow2
197
198See also
199--------
200
201:manpage:`qemu(1)`, :manpage:`qemu-block-drivers(7)`, :manpage:`qemu-storage-daemon-qmp-ref(7)`
202