]> git.proxmox.com Git - mirror_qemu.git/blob - include/sysemu/block-backend.h
hw: Convert from BlockDriverState to BlockBackend, mostly
[mirror_qemu.git] / include / sysemu / block-backend.h
1 /*
2 * QEMU Block backends
3 *
4 * Copyright (C) 2014 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_H
14 #define BLOCK_BACKEND_H
15
16 #include "qemu/typedefs.h"
17 #include "qapi/error.h"
18
19 /*
20 * TODO Have to include block/block.h for a bunch of block layer
21 * types. Unfortunately, this pulls in the whole BlockDriverState
22 * API, which we don't want used by many BlockBackend users. Some of
23 * the types belong here, and the rest should be split into a common
24 * header and one for the BlockDriverState API.
25 */
26 #include "block/block.h"
27
28 BlockBackend *blk_new(const char *name, Error **errp);
29 BlockBackend *blk_new_with_bs(const char *name, Error **errp);
30 void blk_ref(BlockBackend *blk);
31 void blk_unref(BlockBackend *blk);
32 const char *blk_name(BlockBackend *blk);
33 BlockBackend *blk_by_name(const char *name);
34 BlockBackend *blk_next(BlockBackend *blk);
35
36 BlockDriverState *blk_bs(BlockBackend *blk);
37
38 void blk_hide_on_behalf_of_do_drive_del(BlockBackend *blk);
39
40 void blk_iostatus_enable(BlockBackend *blk);
41 int blk_attach_dev(BlockBackend *blk, void *dev);
42 void blk_attach_dev_nofail(BlockBackend *blk, void *dev);
43 void blk_detach_dev(BlockBackend *blk, void *dev);
44 void *blk_get_attached_dev(BlockBackend *blk);
45 void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
46 int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
47 int nb_sectors);
48 int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
49 int nb_sectors);
50 int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf,
51 int nb_sectors);
52 BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num,
53 int nb_sectors, BdrvRequestFlags flags,
54 BlockCompletionFunc *cb, void *opaque);
55 int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count);
56 int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count);
57 int64_t blk_getlength(BlockBackend *blk);
58 void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
59 BlockAIOCB *blk_aio_readv(BlockBackend *blk, int64_t sector_num,
60 QEMUIOVector *iov, int nb_sectors,
61 BlockCompletionFunc *cb, void *opaque);
62 BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
63 QEMUIOVector *iov, int nb_sectors,
64 BlockCompletionFunc *cb, void *opaque);
65 BlockAIOCB *blk_aio_flush(BlockBackend *blk,
66 BlockCompletionFunc *cb, void *opaque);
67 BlockAIOCB *blk_aio_discard(BlockBackend *blk,
68 int64_t sector_num, int nb_sectors,
69 BlockCompletionFunc *cb, void *opaque);
70 void blk_aio_cancel(BlockAIOCB *acb);
71 void blk_aio_cancel_async(BlockAIOCB *acb);
72 int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs);
73 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
74 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
75 BlockCompletionFunc *cb, void *opaque);
76 int blk_flush(BlockBackend *blk);
77 int blk_flush_all(void);
78 void blk_drain_all(void);
79 BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
80 BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
81 int error);
82 void blk_error_action(BlockBackend *blk, BlockErrorAction action,
83 bool is_read, int error);
84 int blk_is_read_only(BlockBackend *blk);
85 int blk_is_sg(BlockBackend *blk);
86 int blk_enable_write_cache(BlockBackend *blk);
87 void blk_set_enable_write_cache(BlockBackend *blk, bool wce);
88 int blk_is_inserted(BlockBackend *blk);
89 void blk_lock_medium(BlockBackend *blk, bool locked);
90 void blk_eject(BlockBackend *blk, bool eject_flag);
91 int blk_get_flags(BlockBackend *blk);
92 void blk_set_guest_block_size(BlockBackend *blk, int align);
93 void *blk_blockalign(BlockBackend *blk, size_t size);
94 bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp);
95 void blk_op_unblock(BlockBackend *blk, BlockOpType op, Error *reason);
96 void blk_op_block_all(BlockBackend *blk, Error *reason);
97 void blk_op_unblock_all(BlockBackend *blk, Error *reason);
98 AioContext *blk_get_aio_context(BlockBackend *blk);
99 void blk_set_aio_context(BlockBackend *blk, AioContext *new_context);
100 void blk_io_plug(BlockBackend *blk);
101 void blk_io_unplug(BlockBackend *blk);
102 BlockAcctStats *blk_get_stats(BlockBackend *blk);
103
104 void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
105 BlockCompletionFunc *cb, void *opaque);
106
107 #endif