| 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 | * Runs when the backend receives a drain request. |
| 64 | */ |
| 65 | void (*drained_begin)(void *opaque); |
| 66 | /* |
| 67 | * Runs when the backend's last drain request ends. |
| 68 | */ |
| 69 | void (*drained_end)(void *opaque); |
| 70 | /* |
| 71 | * Is the device still busy? |
| 72 | */ |
| 73 | bool (*drained_poll)(void *opaque); |
| 74 | |
| 75 | /* |
| 76 | * I/O API functions. These functions are thread-safe. |
| 77 | * |
| 78 | * See include/block/block-io.h for more information about |
| 79 | * the I/O API. |
| 80 | */ |
| 81 | |
| 82 | /* |
| 83 | * Is the virtual tray open? |
| 84 | * Device models implement this only when the device has a tray. |
| 85 | */ |
| 86 | bool (*is_tray_open)(void *opaque); |
| 87 | |
| 88 | /* |
| 89 | * Runs when the size changed (e.g. monitor command block_resize) |
| 90 | */ |
| 91 | void (*resize_cb)(void *opaque); |
| 92 | } BlockDevOps; |
| 93 | |
| 94 | /* |
| 95 | * This struct is embedded in (the private) BlockBackend struct and contains |
| 96 | * fields that must be public. This is in particular for QLIST_ENTRY() and |
| 97 | * friends so that BlockBackends can be kept in lists outside block-backend.c |
| 98 | */ |
| 99 | typedef struct BlockBackendPublic { |
| 100 | ThrottleGroupMember throttle_group_member; |
| 101 | } BlockBackendPublic; |
| 102 | |
| 103 | #endif /* BLOCK_BACKEND_COMMON_H */ |