| 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 | |
| 46 | void no_coroutine_fn blk_unref(BlockBackend *blk); |
| 47 | void coroutine_fn no_co_wrapper blk_co_unref(BlockBackend *blk); |
| 48 | |
| 49 | void blk_remove_all_bs(void); |
| 50 | BlockBackend *blk_by_name(const char *name); |
| 51 | BlockBackend *blk_next(BlockBackend *blk); |
| 52 | BlockBackend *blk_all_next(BlockBackend *blk); |
| 53 | bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp); |
| 54 | void monitor_remove_blk(BlockBackend *blk); |
| 55 | |
| 56 | BlockBackendPublic *blk_get_public(BlockBackend *blk); |
| 57 | |
| 58 | void GRAPH_UNLOCKED blk_remove_bs(BlockBackend *blk); |
| 59 | int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp); |
| 60 | int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **errp); |
| 61 | bool GRAPH_RDLOCK bdrv_has_blk(BlockDriverState *bs); |
| 62 | bool GRAPH_RDLOCK bdrv_is_root_node(BlockDriverState *bs); |
| 63 | int GRAPH_UNLOCKED blk_set_perm(BlockBackend *blk, uint64_t perm, |
| 64 | uint64_t shared_perm, Error **errp); |
| 65 | void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm); |
| 66 | |
| 67 | void blk_iostatus_enable(BlockBackend *blk); |
| 68 | BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk); |
| 69 | void blk_iostatus_reset(BlockBackend *blk); |
| 70 | int blk_attach_dev(BlockBackend *blk, DeviceState *dev); |
| 71 | void blk_detach_dev(BlockBackend *blk, DeviceState *dev); |
| 72 | DeviceState *blk_get_attached_dev(BlockBackend *blk); |
| 73 | BlockBackend *blk_by_dev(void *dev); |
| 74 | BlockBackend *blk_by_qdev_id(const char *id, Error **errp); |
| 75 | void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque); |
| 76 | |
| 77 | int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags); |
| 78 | void blk_aio_cancel(BlockAIOCB *acb); |
| 79 | int blk_commit_all(void); |
| 80 | bool blk_in_drain(BlockBackend *blk); |
| 81 | void GRAPH_UNLOCKED blk_drain(BlockBackend *blk); |
| 82 | void GRAPH_UNLOCKED 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 | int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, |
| 90 | Error **errp); |
| 91 | void blk_add_aio_context_notifier(BlockBackend *blk, |
| 92 | void (*attached_aio_context)(AioContext *new_context, void *opaque), |
| 93 | void (*detach_aio_context)(void *opaque), void *opaque); |
| 94 | void blk_remove_aio_context_notifier(BlockBackend *blk, |
| 95 | void (*attached_aio_context)(AioContext *, |
| 96 | void *), |
| 97 | void (*detach_aio_context)(void *), |
| 98 | void *opaque); |
| 99 | void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify); |
| 100 | BlockBackendRootState *blk_get_root_state(BlockBackend *blk); |
| 101 | void blk_update_root_state(BlockBackend *blk); |
| 102 | bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk); |
| 103 | int blk_get_open_flags_from_root_state(BlockBackend *blk); |
| 104 | |
| 105 | int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, |
| 106 | int64_t pos, int size); |
| 107 | int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size); |
| 108 | int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz); |
| 109 | int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo); |
| 110 | |
| 111 | void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg); |
| 112 | void GRAPH_UNLOCKED blk_io_limits_disable(BlockBackend *blk); |
| 113 | void blk_io_limits_enable(BlockBackend *blk, const char *group); |
| 114 | void blk_io_limits_update_group(BlockBackend *blk, const char *group); |
| 115 | void blk_set_force_allow_inactivate(BlockBackend *blk); |
| 116 | |
| 117 | bool blk_register_buf(BlockBackend *blk, void *host, size_t size, Error **errp); |
| 118 | void blk_unregister_buf(BlockBackend *blk, void *host, size_t size); |
| 119 | |
| 120 | const BdrvChild *blk_root(BlockBackend *blk); |
| 121 | |
| 122 | int blk_make_empty(BlockBackend *blk, Error **errp); |
| 123 | |
| 124 | #endif /* BLOCK_BACKEND_GLOBAL_STATE_H */ |