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