xref: /qemu/include/system/block-backend-common.h (revision a2c4c3b19bb2453008dfb5efdb35be0258b4cb2b)
1*a2c4c3b1SEmanuele Giuseppe Esposito /*
2*a2c4c3b1SEmanuele Giuseppe Esposito  * QEMU Block backends
3*a2c4c3b1SEmanuele Giuseppe Esposito  *
4*a2c4c3b1SEmanuele Giuseppe Esposito  * Copyright (C) 2014-2016 Red Hat, Inc.
5*a2c4c3b1SEmanuele Giuseppe Esposito  *
6*a2c4c3b1SEmanuele Giuseppe Esposito  * Authors:
7*a2c4c3b1SEmanuele Giuseppe Esposito  *  Markus Armbruster <armbru@redhat.com>,
8*a2c4c3b1SEmanuele Giuseppe Esposito  *
9*a2c4c3b1SEmanuele Giuseppe Esposito  * This work is licensed under the terms of the GNU LGPL, version 2.1
10*a2c4c3b1SEmanuele Giuseppe Esposito  * or later.  See the COPYING.LIB file in the top-level directory.
11*a2c4c3b1SEmanuele Giuseppe Esposito  */
12*a2c4c3b1SEmanuele Giuseppe Esposito 
13*a2c4c3b1SEmanuele Giuseppe Esposito #ifndef BLOCK_BACKEND_COMMON_H
14*a2c4c3b1SEmanuele Giuseppe Esposito #define BLOCK_BACKEND_COMMON_H
15*a2c4c3b1SEmanuele Giuseppe Esposito 
16*a2c4c3b1SEmanuele Giuseppe Esposito #include "qemu/iov.h"
17*a2c4c3b1SEmanuele Giuseppe Esposito #include "block/throttle-groups.h"
18*a2c4c3b1SEmanuele Giuseppe Esposito 
19*a2c4c3b1SEmanuele Giuseppe Esposito /*
20*a2c4c3b1SEmanuele Giuseppe Esposito  * TODO Have to include block/block.h for a bunch of block layer
21*a2c4c3b1SEmanuele Giuseppe Esposito  * types.  Unfortunately, this pulls in the whole BlockDriverState
22*a2c4c3b1SEmanuele Giuseppe Esposito  * API, which we don't want used by many BlockBackend users.  Some of
23*a2c4c3b1SEmanuele Giuseppe Esposito  * the types belong here, and the rest should be split into a common
24*a2c4c3b1SEmanuele Giuseppe Esposito  * header and one for the BlockDriverState API.
25*a2c4c3b1SEmanuele Giuseppe Esposito  */
26*a2c4c3b1SEmanuele Giuseppe Esposito #include "block/block.h"
27*a2c4c3b1SEmanuele Giuseppe Esposito 
28*a2c4c3b1SEmanuele Giuseppe Esposito /* Callbacks for block device models */
29*a2c4c3b1SEmanuele Giuseppe Esposito typedef struct BlockDevOps {
30*a2c4c3b1SEmanuele Giuseppe Esposito     /*
31*a2c4c3b1SEmanuele Giuseppe Esposito      * Runs when virtual media changed (monitor commands eject, change)
32*a2c4c3b1SEmanuele Giuseppe Esposito      * Argument load is true on load and false on eject.
33*a2c4c3b1SEmanuele Giuseppe Esposito      * Beware: doesn't run when a host device's physical media
34*a2c4c3b1SEmanuele Giuseppe Esposito      * changes.  Sure would be useful if it did.
35*a2c4c3b1SEmanuele Giuseppe Esposito      * Device models with removable media must implement this callback.
36*a2c4c3b1SEmanuele Giuseppe Esposito      */
37*a2c4c3b1SEmanuele Giuseppe Esposito     void (*change_media_cb)(void *opaque, bool load, Error **errp);
38*a2c4c3b1SEmanuele Giuseppe Esposito     /*
39*a2c4c3b1SEmanuele Giuseppe Esposito      * Runs when an eject request is issued from the monitor, the tray
40*a2c4c3b1SEmanuele Giuseppe Esposito      * is closed, and the medium is locked.
41*a2c4c3b1SEmanuele Giuseppe Esposito      * Device models that do not implement is_medium_locked will not need
42*a2c4c3b1SEmanuele Giuseppe Esposito      * this callback.  Device models that can lock the medium or tray might
43*a2c4c3b1SEmanuele Giuseppe Esposito      * want to implement the callback and unlock the tray when "force" is
44*a2c4c3b1SEmanuele Giuseppe Esposito      * true, even if they do not support eject requests.
45*a2c4c3b1SEmanuele Giuseppe Esposito      */
46*a2c4c3b1SEmanuele Giuseppe Esposito     void (*eject_request_cb)(void *opaque, bool force);
47*a2c4c3b1SEmanuele Giuseppe Esposito     /*
48*a2c4c3b1SEmanuele Giuseppe Esposito      * Is the virtual tray open?
49*a2c4c3b1SEmanuele Giuseppe Esposito      * Device models implement this only when the device has a tray.
50*a2c4c3b1SEmanuele Giuseppe Esposito      */
51*a2c4c3b1SEmanuele Giuseppe Esposito     bool (*is_tray_open)(void *opaque);
52*a2c4c3b1SEmanuele Giuseppe Esposito     /*
53*a2c4c3b1SEmanuele Giuseppe Esposito      * Is the virtual medium locked into the device?
54*a2c4c3b1SEmanuele Giuseppe Esposito      * Device models implement this only when device has such a lock.
55*a2c4c3b1SEmanuele Giuseppe Esposito      */
56*a2c4c3b1SEmanuele Giuseppe Esposito     bool (*is_medium_locked)(void *opaque);
57*a2c4c3b1SEmanuele Giuseppe Esposito     /*
58*a2c4c3b1SEmanuele Giuseppe Esposito      * Runs when the size changed (e.g. monitor command block_resize)
59*a2c4c3b1SEmanuele Giuseppe Esposito      */
60*a2c4c3b1SEmanuele Giuseppe Esposito     void (*resize_cb)(void *opaque);
61*a2c4c3b1SEmanuele Giuseppe Esposito     /*
62*a2c4c3b1SEmanuele Giuseppe Esposito      * Runs when the backend receives a drain request.
63*a2c4c3b1SEmanuele Giuseppe Esposito      */
64*a2c4c3b1SEmanuele Giuseppe Esposito     void (*drained_begin)(void *opaque);
65*a2c4c3b1SEmanuele Giuseppe Esposito     /*
66*a2c4c3b1SEmanuele Giuseppe Esposito      * Runs when the backend's last drain request ends.
67*a2c4c3b1SEmanuele Giuseppe Esposito      */
68*a2c4c3b1SEmanuele Giuseppe Esposito     void (*drained_end)(void *opaque);
69*a2c4c3b1SEmanuele Giuseppe Esposito     /*
70*a2c4c3b1SEmanuele Giuseppe Esposito      * Is the device still busy?
71*a2c4c3b1SEmanuele Giuseppe Esposito      */
72*a2c4c3b1SEmanuele Giuseppe Esposito     bool (*drained_poll)(void *opaque);
73*a2c4c3b1SEmanuele Giuseppe Esposito } BlockDevOps;
74*a2c4c3b1SEmanuele Giuseppe Esposito 
75*a2c4c3b1SEmanuele Giuseppe Esposito /*
76*a2c4c3b1SEmanuele Giuseppe Esposito  * This struct is embedded in (the private) BlockBackend struct and contains
77*a2c4c3b1SEmanuele Giuseppe Esposito  * fields that must be public. This is in particular for QLIST_ENTRY() and
78*a2c4c3b1SEmanuele Giuseppe Esposito  * friends so that BlockBackends can be kept in lists outside block-backend.c
79*a2c4c3b1SEmanuele Giuseppe Esposito  */
80*a2c4c3b1SEmanuele Giuseppe Esposito typedef struct BlockBackendPublic {
81*a2c4c3b1SEmanuele Giuseppe Esposito     ThrottleGroupMember throttle_group_member;
82*a2c4c3b1SEmanuele Giuseppe Esposito } BlockBackendPublic;
83*a2c4c3b1SEmanuele Giuseppe Esposito 
84*a2c4c3b1SEmanuele Giuseppe Esposito #endif /* BLOCK_BACKEND_COMMON_H */
85