1 /*
2  * QEMU Block backends
3  *
4  * Copyright (C) 2014-2016 Red Hat, Inc.
5  *
6  * Authors:
7  *  Markus Armbruster <armbru@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU LGPL, version 2.1
10  * or later.  See the COPYING.LIB file in the top-level directory.
11  */
12 
13 #ifndef BLOCK_BACKEND_GLOBAL_STATE_H
14 #define BLOCK_BACKEND_GLOBAL_STATE_H
15 
16 #include "block-backend-common.h"
17 
18 /*
19  * Global state (GS) API. These functions run under the BQL.
20  *
21  * See include/block/block-global-state.h for more information about
22  * the GS API.
23  */
24 
25 BlockBackend *blk_new(AioContext *ctx, uint64_t perm, uint64_t shared_perm);
26 
27 BlockBackend * no_coroutine_fn
28 blk_new_with_bs(BlockDriverState *bs, uint64_t perm, uint64_t shared_perm,
29                 Error **errp);
30 
31 BlockBackend * coroutine_fn no_co_wrapper
32 blk_co_new_with_bs(BlockDriverState *bs, uint64_t perm, uint64_t shared_perm,
33                    Error **errp);
34 
35 BlockBackend * no_coroutine_fn
36 blk_new_open(const char *filename, const char *reference, QDict *options,
37              int flags, Error **errp);
38 
39 BlockBackend * coroutine_fn no_co_wrapper
40 blk_co_new_open(const char *filename, const char *reference, QDict *options,
41                 int flags, Error **errp);
42 
43 int blk_get_refcnt(BlockBackend *blk);
44 void blk_ref(BlockBackend *blk);
45 void blk_unref(BlockBackend *blk);
46 void blk_remove_all_bs(void);
47 BlockBackend *blk_by_name(const char *name);
48 BlockBackend *blk_next(BlockBackend *blk);
49 BlockBackend *blk_all_next(BlockBackend *blk);
50 bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp);
51 void monitor_remove_blk(BlockBackend *blk);
52 
53 BlockBackendPublic *blk_get_public(BlockBackend *blk);
54 BlockBackend *blk_by_public(BlockBackendPublic *public);
55 
56 void blk_remove_bs(BlockBackend *blk);
57 int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp);
58 int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **errp);
59 bool bdrv_has_blk(BlockDriverState *bs);
60 bool bdrv_is_root_node(BlockDriverState *bs);
61 int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
62                  Error **errp);
63 void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm);
64 
65 void blk_iostatus_enable(BlockBackend *blk);
66 BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk);
67 void blk_iostatus_disable(BlockBackend *blk);
68 void blk_iostatus_reset(BlockBackend *blk);
69 int blk_attach_dev(BlockBackend *blk, DeviceState *dev);
70 void blk_detach_dev(BlockBackend *blk, DeviceState *dev);
71 DeviceState *blk_get_attached_dev(BlockBackend *blk);
72 BlockBackend *blk_by_dev(void *dev);
73 BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
74 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
75 
76 void blk_activate(BlockBackend *blk, Error **errp);
77 
78 int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags);
79 void blk_aio_cancel(BlockAIOCB *acb);
80 int blk_commit_all(void);
81 void blk_drain(BlockBackend *blk);
82 void blk_drain_all(void);
83 void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error,
84                       BlockdevOnError on_write_error);
85 bool blk_supports_write_perm(BlockBackend *blk);
86 bool blk_is_sg(BlockBackend *blk);
87 void blk_set_enable_write_cache(BlockBackend *blk, bool wce);
88 int blk_get_flags(BlockBackend *blk);
89 bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp);
90 void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason);
91 void blk_op_block_all(BlockBackend *blk, Error *reason);
92 void blk_op_unblock_all(BlockBackend *blk, Error *reason);
93 int blk_set_aio_context(BlockBackend *blk, AioContext *new_context,
94                         Error **errp);
95 void blk_add_aio_context_notifier(BlockBackend *blk,
96         void (*attached_aio_context)(AioContext *new_context, void *opaque),
97         void (*detach_aio_context)(void *opaque), void *opaque);
98 void blk_remove_aio_context_notifier(BlockBackend *blk,
99                                      void (*attached_aio_context)(AioContext *,
100                                                                   void *),
101                                      void (*detach_aio_context)(void *),
102                                      void *opaque);
103 void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify);
104 void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify);
105 BlockBackendRootState *blk_get_root_state(BlockBackend *blk);
106 void blk_update_root_state(BlockBackend *blk);
107 bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk);
108 int blk_get_open_flags_from_root_state(BlockBackend *blk);
109 
110 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
111                      int64_t pos, int size);
112 int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size);
113 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz);
114 int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo);
115 
116 void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg);
117 void blk_io_limits_disable(BlockBackend *blk);
118 void blk_io_limits_enable(BlockBackend *blk, const char *group);
119 void blk_io_limits_update_group(BlockBackend *blk, const char *group);
120 void blk_set_force_allow_inactivate(BlockBackend *blk);
121 
122 bool blk_register_buf(BlockBackend *blk, void *host, size_t size, Error **errp);
123 void blk_unregister_buf(BlockBackend *blk, void *host, size_t size);
124 
125 const BdrvChild *blk_root(BlockBackend *blk);
126 
127 int blk_make_empty(BlockBackend *blk, Error **errp);
128 
129 #endif /* BLOCK_BACKEND_GLOBAL_STATE_H */
130