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