Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / block / export.h
blobf2fe0f8078f32c6b4719d8d003044ebadc2993e2
1 /*
2 * Declarations for block exports
4 * Copyright (c) 2012, 2020 Red Hat, Inc.
6 * Authors:
7 * Paolo Bonzini <pbonzini@redhat.com>
8 * Kevin Wolf <kwolf@redhat.com>
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.
14 #ifndef BLOCK_EXPORT_H
15 #define BLOCK_EXPORT_H
17 #include "qapi/qapi-types-block-export.h"
18 #include "qemu/queue.h"
20 typedef struct BlockExport BlockExport;
22 typedef struct BlockExportDriver {
23 /* The export type that this driver services */
24 BlockExportType type;
27 * The size of the driver-specific state that contains BlockExport as its
28 * first field.
30 size_t instance_size;
32 /* Creates and starts a new block export */
33 int (*create)(BlockExport *, BlockExportOptions *, Error **);
36 * Frees a removed block export. This function is only called after all
37 * references have been dropped.
39 void (*delete)(BlockExport *);
42 * Start to disconnect all clients and drop other references held
43 * internally by the export driver. When the function returns, there may
44 * still be active references while the export is in the process of
45 * shutting down.
47 void (*request_shutdown)(BlockExport *);
48 } BlockExportDriver;
50 struct BlockExport {
51 const BlockExportDriver *drv;
53 /* Unique identifier for the export */
54 char *id;
57 * Reference count for this block export. This includes strong references
58 * both from the owner (qemu-nbd or the monitor) and clients connected to
59 * the export.
61 * Use atomics to access this field.
63 int refcount;
66 * True if one of the references in refcount belongs to the user. After the
67 * user has dropped their reference, they may not e.g. remove the same
68 * export a second time (which would decrease the refcount without having
69 * it incremented first).
71 bool user_owned;
73 /* The AioContext whose lock protects this BlockExport object. */
74 AioContext *ctx;
76 /* The block device to export */
77 BlockBackend *blk;
79 /* List entry for block_exports */
80 QLIST_ENTRY(BlockExport) next;
83 BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp);
84 BlockExport *blk_exp_find(const char *id);
85 void blk_exp_ref(BlockExport *exp);
86 void blk_exp_unref(BlockExport *exp);
87 void blk_exp_request_shutdown(BlockExport *exp);
88 void blk_exp_close_all(void);
89 void blk_exp_close_all_type(BlockExportType type);
91 #endif