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