block/export: Allocate BlockExport in blk_exp_add()
[qemu.git] / include / block / export.h
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
19 typedef struct BlockExport BlockExport;
20
21 typedef struct BlockExportDriver {
22 /* The export type that this driver services */
23 BlockExportType type;
24
25 /*
26 * The size of the driver-specific state that contains BlockExport as its
27 * first field.
28 */
29 size_t instance_size;
30
31 /* Creates and starts a new block export */
32 int (*create)(BlockExport *, BlockExportOptions *, Error **);
33
34 /*
35 * Frees a removed block export. This function is only called after all
36 * references have been dropped.
37 */
38 void (*delete)(BlockExport *);
39 } BlockExportDriver;
40
41 struct BlockExport {
42 const BlockExportDriver *drv;
43
44 /*
45 * Reference count for this block export. This includes strong references
46 * both from the owner (qemu-nbd or the monitor) and clients connected to
47 * the export.
48 */
49 int refcount;
50
51 /* The AioContext whose lock protects this BlockExport object. */
52 AioContext *ctx;
53 };
54
55 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp);
56 void blk_exp_ref(BlockExport *exp);
57 void blk_exp_unref(BlockExport *exp);
58
59 #endif