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 BlockBackend *blk_by_public(BlockBackendPublic *public); 58 59 void blk_remove_bs(BlockBackend *blk); 60 int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp); 61 int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **errp); 62 bool GRAPH_RDLOCK bdrv_has_blk(BlockDriverState *bs); 63 bool GRAPH_RDLOCK bdrv_is_root_node(BlockDriverState *bs); 64 int GRAPH_UNLOCKED blk_set_perm(BlockBackend *blk, uint64_t perm, 65 uint64_t shared_perm, Error **errp); 66 void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm); 67 68 void blk_iostatus_enable(BlockBackend *blk); 69 BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk); 70 void blk_iostatus_disable(BlockBackend *blk); 71 void blk_iostatus_reset(BlockBackend *blk); 72 int blk_attach_dev(BlockBackend *blk, DeviceState *dev); 73 void blk_detach_dev(BlockBackend *blk, DeviceState *dev); 74 DeviceState *blk_get_attached_dev(BlockBackend *blk); 75 BlockBackend *blk_by_dev(void *dev); 76 BlockBackend *blk_by_qdev_id(const char *id, Error **errp); 77 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque); 78 79 void blk_activate(BlockBackend *blk, Error **errp); 80 81 int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags); 82 void blk_aio_cancel(BlockAIOCB *acb); 83 int blk_commit_all(void); 84 bool blk_in_drain(BlockBackend *blk); 85 void blk_drain(BlockBackend *blk); 86 void blk_drain_all(void); 87 void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, 88 BlockdevOnError on_write_error); 89 bool blk_supports_write_perm(BlockBackend *blk); 90 bool blk_is_sg(BlockBackend *blk); 91 void blk_set_enable_write_cache(BlockBackend *blk, bool wce); 92 int blk_get_flags(BlockBackend *blk); 93 bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp); 94 void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason); 95 void blk_op_block_all(BlockBackend *blk, Error *reason); 96 void blk_op_unblock_all(BlockBackend *blk, Error *reason); 97 int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, 98 Error **errp); 99 void blk_add_aio_context_notifier(BlockBackend *blk, 100 void (*attached_aio_context)(AioContext *new_context, void *opaque), 101 void (*detach_aio_context)(void *opaque), void *opaque); 102 void blk_remove_aio_context_notifier(BlockBackend *blk, 103 void (*attached_aio_context)(AioContext *, 104 void *), 105 void (*detach_aio_context)(void *), 106 void *opaque); 107 void blk_add_remove_bs_notifier(BlockBackend *blk, Notifier *notify); 108 void blk_add_insert_bs_notifier(BlockBackend *blk, Notifier *notify); 109 BlockBackendRootState *blk_get_root_state(BlockBackend *blk); 110 void blk_update_root_state(BlockBackend *blk); 111 bool blk_get_detect_zeroes_from_root_state(BlockBackend *blk); 112 int blk_get_open_flags_from_root_state(BlockBackend *blk); 113 114 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, 115 int64_t pos, int size); 116 int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size); 117 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz); 118 int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo); 119 120 void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg); 121 void blk_io_limits_disable(BlockBackend *blk); 122 void blk_io_limits_enable(BlockBackend *blk, const char *group); 123 void blk_io_limits_update_group(BlockBackend *blk, const char *group); 124 void blk_set_force_allow_inactivate(BlockBackend *blk); 125 126 bool blk_register_buf(BlockBackend *blk, void *host, size_t size, Error **errp); 127 void blk_unregister_buf(BlockBackend *blk, void *host, size_t size); 128 129 const BdrvChild *blk_root(BlockBackend *blk); 130 131 int blk_make_empty(BlockBackend *blk, Error **errp); 132 133 #endif /* BLOCK_BACKEND_GLOBAL_STATE_H */ 134