master
h 102 lines 2.93 KB
Raw
1 /*
2 * Declarations for block exports
3 *
4 * Copyright (c) 2012, 2020 Red Hat, Inc.
5 *
6 * Authors:
7 * Paolo Bonzini <pbonzini@redhat.com>
8 * Kevin Wolf <kwolf@redhat.com>
9 *
10 * This work is licensed under the terms of the GNU GPL, version 2 or
11 * later. See the COPYING file in the top-level directory.
12 */
13
14 #ifndef BLOCK_EXPORT_H
15 #define BLOCK_EXPORT_H
16
17 #include "qapi/qapi-types-block-export.h"
18 #include "qemu/queue.h"
19
20 typedef struct BlockExport BlockExport;
21
22 typedef struct BlockExportDriver {
23 /* The export type that this driver services */
24 BlockExportType type;
25
26 /*
27 * The size of the driver-specific state that contains BlockExport as its
28 * first field.
29 */
30 size_t instance_size;
31
32 /* True if the export type supports running on an inactive node */
33 bool supports_inactive;
34
35 /*
36 * Creates and starts a new block export.
37 *
38 * If the user passed a set of I/O threads for multi-threading, @multithread
39 * is a list of the @multithread_count corresponding contexts (freed by the
40 * caller). Note that @exp->ctx has no relation to that list.
41 */
42 int (*create)(BlockExport *exp, BlockExportOptions *opts,
43 AioContext *const *multithread, size_t multithread_count,
44 Error **errp);
45
46 /*
47 * Frees a removed block export. This function is only called after all
48 * references have been dropped.
49 */
50 void (*delete)(BlockExport *);
51
52 /*
53 * Start to disconnect all clients and drop other references held
54 * internally by the export driver. When the function returns, there may
55 * still be active references while the export is in the process of
56 * shutting down.
57 */
58 void (*request_shutdown)(BlockExport *);
59 } BlockExportDriver;
60
61 struct BlockExport {
62 const BlockExportDriver *drv;
63
64 /* Unique identifier for the export */
65 char *id;
66
67 /*
68 * Reference count for this block export. This includes strong references
69 * both from the owner (qemu-nbd or the monitor) and clients connected to
70 * the export.
71 *
72 * Use atomics to access this field.
73 */
74 int refcount;
75
76 /*
77 * True if one of the references in refcount belongs to the user. After the
78 * user has dropped their reference, they may not e.g. remove the same
79 * export a second time (which would decrease the refcount without having
80 * it incremented first).
81 */
82 bool user_owned;
83
84 /* The AioContext whose lock protects this BlockExport object. */
85 AioContext *ctx;
86
87 /* The block device to export */
88 BlockBackend *blk;
89
90 /* List entry for block_exports */
91 QLIST_ENTRY(BlockExport) next;
92 };
93
94 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp);
95 BlockExport *blk_exp_find(const char *id);
96 void blk_exp_ref(BlockExport *exp);
97 void blk_exp_unref(BlockExport *exp);
98 void blk_exp_request_shutdown(BlockExport *exp);
99 void blk_exp_close_all(void);
100 void blk_exp_close_all_type(BlockExportType type);
101
102 #endif