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 BlockBackend *blk_new_with_bs(BlockDriverState *bs, uint64_t perm,
27                               uint64_t shared_perm, Error **errp);
28 BlockBackend *blk_new_open(const char *filename, const char *reference,
29                            QDict *options, int flags, Error **errp);
30 int blk_get_refcnt(BlockBackend *blk);
31 void blk_ref(BlockBackend *blk);
32 void blk_unref(BlockBackend *blk);
33 void blk_remove_all_bs(void);
34 BlockBackend *blk_by_name(const char *name);
35 BlockBackend *blk_next(BlockBackend *blk);
36 BlockBackend *blk_all_next(BlockBackend *blk);
37 bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp);
38 void monitor_remove_blk(BlockBackend *blk);
39 
40 BlockBackendPublic *blk_get_public(BlockBackend *blk);
41 BlockBackend *blk_by_public(BlockBackendPublic *public);
42 
43 void blk_remove_bs(BlockBackend *blk);
44 int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp);
45 int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **errp);
46 bool bdrv_has_blk(BlockDriverState *bs);
47 bool bdrv_is_root_node(BlockDriverState *bs);
48 int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
49                  Error **errp);
50 void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm);
51 
52 void blk_iostatus_enable(BlockBackend *blk);
53 BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk);
54 void blk_iostatus_disable(BlockBackend *blk);
55 void blk_iostatus_reset(BlockBackend *blk);
56 int blk_attach_dev(BlockBackend *blk, DeviceState *dev);
57 void blk_detach_dev(BlockBackend *blk, DeviceState *dev);
58 DeviceState *blk_get_attached_dev(BlockBackend *blk);
59 BlockBackend *blk_by_dev(void *dev);
60 BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
61 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
62 
63 void blk_activate(BlockBackend *blk, Error **errp);
64 
65 int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags);
66 void blk_aio_cancel(BlockAIOCB *acb);
67 int blk_commit_all(void);
68 void blk_drain(BlockBackend *blk);
69 void blk_drain_all(void);
70 void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error,
71                       BlockdevOnError on_write_error);
72 bool blk_supports_write_perm(BlockBackend *blk);
73 bool blk_is_sg(BlockBackend *blk);
74 void blk_set_enable_write_cache(BlockBackend *blk, bool wce);
75 int blk_get_flags(BlockBackend *blk);
76 bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp);
77 void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason);
78 void blk_op_block_all(BlockBackend *blk, Error *reason);
79 void blk_op_unblock_all(BlockBackend *blk, Error *reason);
80 int blk_set_aio_context(BlockBackend *blk, AioContext *new_context,
81                         Error **errp);
82 void blk_add_aio_context_notifier(BlockBackend *blk,
83         void (*attached_aio_context)(AioContext *new_context, void *opaque),
84         void (*detach_aio_context)(void *opaque), void *opaque);
85 void blk_remove_aio_context_notifier(BlockBackend *blk,
86                                      void (*attached_aio_context)(AioContext *,
87                                                                   void *),
88                                      void (*detach_aio_context)(void *),
89                                      void *opaque);
90 void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify);
91 void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify);
92 BlockBackendRootState *blk_get_root_state(BlockBackend *blk);
93 void blk_update_root_state(BlockBackend *blk);
94 bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk);
95 int blk_get_open_flags_from_root_state(BlockBackend *blk);
96 
97 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
98                      int64_t pos, int size);
99 int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size);
100 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz);
101 int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo);
102 
103 void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg);
104 void blk_io_limits_disable(BlockBackend *blk);
105 void blk_io_limits_enable(BlockBackend *blk, const char *group);
106 void blk_io_limits_update_group(BlockBackend *blk, const char *group);
107 void blk_set_force_allow_inactivate(BlockBackend *blk);
108 
109 void blk_register_buf(BlockBackend *blk, void *host, size_t size);
110 void blk_unregister_buf(BlockBackend *blk, void *host);
111 
112 const BdrvChild *blk_root(BlockBackend *blk);
113 
114 int blk_make_empty(BlockBackend *blk, Error **errp);
115 
116 #endif /* BLOCK_BACKEND_GLOBAL_STATE_H */
117