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_COMMON_H
14 #define BLOCK_BACKEND_COMMON_H
15 
16 #include "qemu/iov.h"
17 #include "block/throttle-groups.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 /* Callbacks for block device models */
29 typedef struct BlockDevOps {
30 
31     /*
32      * Global state (GS) API. These functions run under the BQL.
33      *
34      * See include/block/block-global-state.h for more information about
35      * the GS API.
36      */
37 
38     /*
39      * Runs when virtual media changed (monitor commands eject, change)
40      * Argument load is true on load and false on eject.
41      * Beware: doesn't run when a host device's physical media
42      * changes.  Sure would be useful if it did.
43      * Device models with removable media must implement this callback.
44      */
45     void (*change_media_cb)(void *opaque, bool load, Error **errp);
46     /*
47      * Runs when an eject request is issued from the monitor, the tray
48      * is closed, and the medium is locked.
49      * Device models that do not implement is_medium_locked will not need
50      * this callback.  Device models that can lock the medium or tray might
51      * want to implement the callback and unlock the tray when "force" is
52      * true, even if they do not support eject requests.
53      */
54     void (*eject_request_cb)(void *opaque, bool force);
55 
56     /*
57      * Is the virtual medium locked into the device?
58      * Device models implement this only when device has such a lock.
59      */
60     bool (*is_medium_locked)(void *opaque);
61 
62     /*
63      * I/O API functions. These functions are thread-safe.
64      *
65      * See include/block/block-io.h for more information about
66      * the I/O API.
67      */
68 
69     /*
70      * Is the virtual tray open?
71      * Device models implement this only when the device has a tray.
72      */
73     bool (*is_tray_open)(void *opaque);
74 
75     /*
76      * Runs when the size changed (e.g. monitor command block_resize)
77      */
78     void (*resize_cb)(void *opaque);
79     /*
80      * Runs when the backend receives a drain request.
81      */
82     void (*drained_begin)(void *opaque);
83     /*
84      * Runs when the backend's last drain request ends.
85      */
86     void (*drained_end)(void *opaque);
87     /*
88      * Is the device still busy?
89      */
90     bool (*drained_poll)(void *opaque);
91 } BlockDevOps;
92 
93 /*
94  * This struct is embedded in (the private) BlockBackend struct and contains
95  * fields that must be public. This is in particular for QLIST_ENTRY() and
96  * friends so that BlockBackends can be kept in lists outside block-backend.c
97  */
98 typedef struct BlockBackendPublic {
99     ThrottleGroupMember throttle_group_member;
100 } BlockBackendPublic;
101 
102 #endif /* BLOCK_BACKEND_COMMON_H */
103