xref: /openbmc/qemu/qapi/block-export.json (revision cad9aa6fbdccd95e56e10cfa57c354a20a333717)
1# -*- Mode: Python -*-
2# vim: filetype=python
3
4##
5# Block device exports
6# ====================
7##
8
9{ 'include': 'sockets.json' }
10{ 'include': 'block-core.json' }
11
12##
13# @NbdServerOptionsBase:
14#
15# @handshake-max-seconds: Time limit, in seconds, at which a client
16#     that has not completed the negotiation handshake will be
17#     disconnected, or 0 for no limit (since 10.0; default: 10).
18#
19# @tls-creds: ID of the TLS credentials object (since 2.6).
20#
21# @tls-authz: ID of the QAuthZ authorization object used to validate
22#     the client's x509 distinguished name.  This object is is only
23#     resolved at time of use, so can be deleted and recreated on the
24#     fly while the NBD server is active.  If missing, it will default
25#     to denying access (since 4.0).
26#
27# @max-connections: The maximum number of connections to allow at the
28#     same time, 0 for unlimited.  Setting this to 1 also stops the
29#     server from advertising multiple client support (since 5.2;
30#     default: 100).
31##
32{ 'struct': 'NbdServerOptionsBase',
33  'data': { '*handshake-max-seconds': 'uint32',
34            '*tls-creds': 'str',
35            '*tls-authz': 'str',
36            '*max-connections': 'uint32' } }
37
38##
39# @NbdServerOptions:
40#
41# Keep this type consistent with the `NbdServerOptionsLegacy` type.  The
42# only intended difference is using `SocketAddress` instead of
43# `SocketAddressLegacy`.
44#
45# @addr: Address on which to listen (since 4.2).
46##
47{ 'struct': 'NbdServerOptions',
48  'base': 'NbdServerOptionsBase',
49  'data': { 'addr': 'SocketAddress' } }
50
51##
52# @NbdServerOptionsLegacy:
53#
54# Keep this type consistent with the `NbdServerOptions` type.  The only
55# intended difference is using `SocketAddressLegacy` instead of
56# `SocketAddress`.
57#
58# @addr: Address on which to listen (since 1.3).
59##
60{ 'struct': 'NbdServerOptionsLegacy',
61  'base': 'NbdServerOptionsBase',
62  'data': { 'addr': 'SocketAddressLegacy' } }
63
64##
65# @nbd-server-start:
66#
67# Start an NBD server listening on the given host and port.  Block
68# devices can then be exported using `nbd-server-add`.  The NBD server
69# will present them as named exports; for example, another QEMU
70# instance could refer to them as "nbd:HOST:PORT:exportname=NAME".
71#
72# Errors:
73#     - if the server is already running
74#
75# Since: 1.3
76##
77{ 'command': 'nbd-server-start',
78  'data': 'NbdServerOptionsLegacy',
79  'allow-preconfig': true }
80
81##
82# @BlockExportOptionsNbdBase:
83#
84# An NBD block export (common options shared between `nbd-server-add`
85# and the NBD branch of `block-export-add`).
86#
87# @name: Export name.  If unspecified, the @device parameter is used
88#     as the export name.  (Since 2.12)
89#
90# @description: Free-form description of the export, up to 4096 bytes.
91#     (Since 5.0)
92#
93# Since: 5.0
94##
95{ 'struct': 'BlockExportOptionsNbdBase',
96  'data': { '*name': 'str', '*description': 'str' } }
97
98##
99# @BlockExportOptionsNbd:
100#
101# An NBD block export (distinct options used in the NBD branch of
102# `block-export-add`).
103#
104# @bitmaps: Also export each of the named dirty bitmaps reachable from
105#     @device, so the NBD client can use NBD_OPT_SET_META_CONTEXT with
106#     the metadata context name "qemu:dirty-bitmap:BITMAP" to inspect
107#     each bitmap.  Since 7.1 bitmap may be specified by node/name
108#     pair.
109#
110# @allocation-depth: Also export the allocation depth map for @device,
111#     so the NBD client can use NBD_OPT_SET_META_CONTEXT with the
112#     metadata context name "qemu:allocation-depth" to inspect
113#     allocation details.  (since 5.2)
114#
115# Since: 5.2
116##
117{ 'struct': 'BlockExportOptionsNbd',
118  'base': 'BlockExportOptionsNbdBase',
119  'data': { '*bitmaps': ['BlockDirtyBitmapOrStr'],
120            '*allocation-depth': 'bool' } }
121
122##
123# @BlockExportOptionsVhostUserBlk:
124#
125# A vhost-user-blk block export.
126#
127# @addr: The vhost-user socket on which to listen.  Both 'unix' and
128#     'fd' `SocketAddress` types are supported.  Passed fds must be UNIX
129#     domain sockets.
130#
131# @logical-block-size: Logical block size in bytes.  Defaults to 512
132#     bytes.
133#
134# @num-queues: Number of request virtqueues.  Must be greater than 0.
135#     Defaults to 1.
136#
137# Since: 5.2
138##
139{ 'struct': 'BlockExportOptionsVhostUserBlk',
140  'data': { 'addr': 'SocketAddress',
141	    '*logical-block-size': 'size',
142            '*num-queues': 'uint16'} }
143
144##
145# @FuseExportAllowOther:
146#
147# Possible allow_other modes for FUSE exports.
148#
149# @off: Do not pass allow_other as a mount option.
150#
151# @on: Pass allow_other as a mount option.
152#
153# @auto: Try mounting with allow_other first, and if that fails, retry
154#     without allow_other.
155#
156# Since: 6.1
157##
158{ 'enum': 'FuseExportAllowOther',
159  'data': ['off', 'on', 'auto'] }
160
161##
162# @BlockExportOptionsFuse:
163#
164# Options for exporting a block graph node on some (file) mountpoint
165# as a raw image.
166#
167# @mountpoint: Path on which to export the block device via FUSE.
168#     This must point to an existing regular file.
169#
170# @growable: Whether writes beyond the EOF should grow the block node
171#     accordingly.  (default: false)
172#
173# @allow-other: If this is off, only QEMU's user is allowed access to
174#     this export.  That cannot be changed even with chmod or chown.
175#     Enabling this option will allow other users access to the export
176#     with the FUSE mount option "allow_other".  Note that using
177#     allow_other as a non-root user requires user_allow_other to be
178#     enabled in the global fuse.conf configuration file.  In auto
179#     mode (the default), the FUSE export driver will first attempt to
180#     mount the export with allow_other, and if that fails, try again
181#     without.  (since 6.1; default: auto)
182#
183# Since: 6.0
184##
185{ 'struct': 'BlockExportOptionsFuse',
186  'data': { 'mountpoint': 'str',
187            '*growable': 'bool',
188            '*allow-other': 'FuseExportAllowOther' },
189  'if': 'CONFIG_FUSE' }
190
191##
192# @BlockExportOptionsVduseBlk:
193#
194# A vduse-blk block export.
195#
196# @name: the name of VDUSE device (must be unique across the host).
197#
198# @num-queues: the number of virtqueues.  Defaults to 1.
199#
200# @queue-size: the size of virtqueue.  Defaults to 256.
201#
202# @logical-block-size: Logical block size in bytes.  Range [512,
203#     PAGE_SIZE] and must be power of 2.  Defaults to 512 bytes.
204#
205# @serial: the serial number of virtio block device.  Defaults to
206#     empty string.
207#
208# Since: 7.1
209##
210{ 'struct': 'BlockExportOptionsVduseBlk',
211  'data': { 'name': 'str',
212            '*num-queues': 'uint16',
213            '*queue-size': 'uint16',
214            '*logical-block-size': 'size',
215            '*serial': 'str' } }
216
217##
218# @NbdServerAddOptions:
219#
220# An NBD block export, per legacy `nbd-server-add` command.
221#
222# @device: The device name or node name of the node to be exported
223#
224# @writable: Whether clients should be able to write to the device via
225#     the NBD connection (default false).
226#
227# @bitmap: Also export a single dirty bitmap reachable from @device,
228#     so the NBD client can use NBD_OPT_SET_META_CONTEXT with the
229#     metadata context name "qemu:dirty-bitmap:BITMAP" to inspect the
230#     bitmap (since 4.0).
231#
232# Since: 5.0
233##
234{ 'struct': 'NbdServerAddOptions',
235  'base': 'BlockExportOptionsNbdBase',
236  'data': { 'device': 'str',
237            '*writable': 'bool', '*bitmap': 'str' } }
238
239##
240# @nbd-server-add:
241#
242# Export a block node to QEMU's embedded NBD server.
243#
244# The export name will be used as the id for the resulting block
245# export.
246#
247# Features:
248#
249# @deprecated: This command is deprecated.  Use `block-export-add`
250#     instead.
251#
252# Errors:
253#     - if the server is not running
254#     - if an export with the same name already exists
255#
256# Since: 1.3
257##
258{ 'command': 'nbd-server-add',
259  'data': 'NbdServerAddOptions', 'boxed': true, 'features': ['deprecated'],
260  'allow-preconfig': true }
261
262##
263# @BlockExportRemoveMode:
264#
265# Mode for removing a block export.
266#
267# @safe: Remove export if there are no existing connections, fail
268#     otherwise.
269#
270# @hard: Drop all connections immediately and remove export.
271#
272# TODO: Potential additional modes to be added in the future:
273#
274#     - hide: Just hide export from new clients, leave existing
275#       connections as is.  Remove export after all clients are
276#       disconnected.
277#
278#     - soft: Hide export from new clients, answer with ESHUTDOWN for
279#       all further requests from existing clients.
280#
281# Since: 2.12
282##
283{'enum': 'BlockExportRemoveMode', 'data': ['safe', 'hard']}
284
285##
286# @nbd-server-remove:
287#
288# Remove NBD export by name.
289#
290# @name: Block export id.
291#
292# @mode: Mode of command operation.  See `BlockExportRemoveMode`
293#     description.  Default is 'safe'.
294#
295# Features:
296#
297# @deprecated: This command is deprecated.  Use `block-export-del`
298#     instead.
299#
300# Errors:
301#     - if the server is not running
302#     - if export is not found
303#     - if mode is 'safe' and there are existing connections
304#
305# Since: 2.12
306##
307{ 'command': 'nbd-server-remove',
308  'data': {'name': 'str', '*mode': 'BlockExportRemoveMode'},
309  'features': ['deprecated'],
310  'allow-preconfig': true }
311
312##
313# @nbd-server-stop:
314#
315# Stop QEMU's embedded NBD server, and unregister all devices
316# previously added via `nbd-server-add`.
317#
318# Since: 1.3
319##
320{ 'command': 'nbd-server-stop',
321  'allow-preconfig': true }
322
323##
324# @BlockExportType:
325#
326# An enumeration of block export types
327#
328# @nbd: NBD export
329#
330# @vhost-user-blk: vhost-user-blk export (since 5.2)
331#
332# @fuse: FUSE export (since: 6.0)
333#
334# @vduse-blk: vduse-blk export (since 7.1)
335#
336# Since: 4.2
337##
338{ 'enum': 'BlockExportType',
339  'data': [ 'nbd',
340            { 'name': 'vhost-user-blk',
341              'if': 'CONFIG_VHOST_USER_BLK_SERVER' },
342            { 'name': 'fuse', 'if': 'CONFIG_FUSE' },
343            { 'name': 'vduse-blk', 'if': 'CONFIG_VDUSE_BLK_EXPORT' } ] }
344
345##
346# @BlockExportOptions:
347#
348# Describes a block export, i.e. how single node should be exported on
349# an external interface.
350#
351# @type: Block export type
352#
353# @id: A unique identifier for the block export (across all export
354#     types)
355#
356# @node-name: The node name of the block node to be exported
357#     (since: 5.2)
358#
359# @writable: True if clients should be able to write to the export
360#     (default false)
361#
362# @writethrough: If true, caches are flushed after every write request
363#     to the export before completion is signalled.  (since: 5.2;
364#     default: false)
365#
366# @iothread: The name of the iothread object where the export will
367#     run.  The default is to use the thread currently associated with
368#     the block node.  (since: 5.2)
369#
370# @fixed-iothread: True prevents the block node from being moved to
371#     another thread while the export is active.  If true and
372#     @iothread is given, export creation fails if the block node
373#     cannot be moved to the iothread.  The default is false.
374#     (since: 5.2)
375#
376# @allow-inactive: If true, the export allows the exported node to be inactive.
377#     If it is created for an inactive block node, the node remains inactive.  If
378#     the export type doesn't support running on an inactive node, an error is
379#     returned.  If false, inactive block nodes are automatically activated before
380#     creating the export and trying to inactivate them later fails.
381#     (since: 10.0; default: false)
382#
383# Since: 4.2
384##
385{ 'union': 'BlockExportOptions',
386  'base': { 'type': 'BlockExportType',
387            'id': 'str',
388            '*fixed-iothread': 'bool',
389            '*iothread': 'str',
390            'node-name': 'str',
391            '*writable': 'bool',
392            '*writethrough': 'bool',
393            '*allow-inactive': 'bool' },
394  'discriminator': 'type',
395  'data': {
396      'nbd': 'BlockExportOptionsNbd',
397      'vhost-user-blk': { 'type': 'BlockExportOptionsVhostUserBlk',
398                          'if': 'CONFIG_VHOST_USER_BLK_SERVER' },
399      'fuse': { 'type': 'BlockExportOptionsFuse',
400                'if': 'CONFIG_FUSE' },
401      'vduse-blk': { 'type': 'BlockExportOptionsVduseBlk',
402                     'if': 'CONFIG_VDUSE_BLK_EXPORT' }
403   } }
404
405##
406# @block-export-add:
407#
408# Creates a new block export.
409#
410# Since: 5.2
411##
412{ 'command': 'block-export-add',
413  'data': 'BlockExportOptions', 'boxed': true,
414  'allow-preconfig': true }
415
416##
417# @block-export-del:
418#
419# Request to remove a block export.  This drops the user's reference
420# to the export, but the export may still stay around after this
421# command returns until the shutdown of the export has completed.
422#
423# @id: Block export id.
424#
425# @mode: Mode of command operation.  See `BlockExportRemoveMode`
426#     description.  Default is 'safe'.
427#
428# Errors:
429#     - if the export is not found
430#     - if @mode is 'safe' and the export is still in use (e.g. by
431#       existing client connections)
432#
433# Since: 5.2
434##
435{ 'command': 'block-export-del',
436  'data': { 'id': 'str', '*mode': 'BlockExportRemoveMode' },
437  'allow-preconfig': true }
438
439##
440# @BLOCK_EXPORT_DELETED:
441#
442# Emitted when a block export is removed and its id can be reused.
443#
444# @id: Block export id.
445#
446# Since: 5.2
447##
448{ 'event': 'BLOCK_EXPORT_DELETED',
449  'data': { 'id': 'str' } }
450
451##
452# @BlockExportInfo:
453#
454# Information about a single block export.
455#
456# @id: The unique identifier for the block export
457#
458# @type: The block export type
459#
460# @node-name: The node name of the block node that is exported
461#
462# @shutting-down: True if the export is shutting down (e.g. after a
463#     `block-export-del` command, but before the shutdown has completed)
464#
465# Since: 5.2
466##
467{ 'struct': 'BlockExportInfo',
468  'data': { 'id': 'str',
469            'type': 'BlockExportType',
470            'node-name': 'str',
471            'shutting-down': 'bool' } }
472
473##
474# @query-block-exports:
475#
476# Returns: A list describing all block exports
477#
478# Since: 5.2
479##
480{ 'command': 'query-block-exports', 'returns': ['BlockExportInfo'],
481  'allow-preconfig': true }
482