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