4 * Copyright (C) 2014-2016 Red Hat, Inc.
7 * Markus Armbruster <armbru@redhat.com>,
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.
13 #ifndef BLOCK_BACKEND_COMMON_H
14 #define BLOCK_BACKEND_COMMON_H
17 #include "block/throttle-groups.h"
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.
26 #include "block/block.h"
28 /* Callbacks for block device models */
29 typedef struct BlockDevOps {
32 * Global state (GS) API. These functions run under the BQL.
34 * See include/block/block-global-state.h for more information about
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.
45 void (*change_media_cb)(void *opaque, bool load, Error **errp);
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.
54 void (*eject_request_cb)(void *opaque, bool force);
57 * Is the virtual medium locked into the device?
58 * Device models implement this only when device has such a lock.
60 bool (*is_medium_locked)(void *opaque);
63 * I/O API functions. These functions are thread-safe.
65 * See include/block/block-io.h for more information about
70 * Is the virtual tray open?
71 * Device models implement this only when the device has a tray.
73 bool (*is_tray_open)(void *opaque);
76 * Runs when the size changed (e.g. monitor command block_resize)
78 void (*resize_cb)(void *opaque);
80 * Runs when the backend receives a drain request.
82 void (*drained_begin)(void *opaque);
84 * Runs when the backend's last drain request ends.
86 void (*drained_end)(void *opaque);
88 * Is the device still busy?
90 bool (*drained_poll)(void *opaque);
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
98 typedef struct BlockBackendPublic {
99 ThrottleGroupMember throttle_group_member;
100 } BlockBackendPublic;
102 #endif /* BLOCK_BACKEND_COMMON_H */