block-backend-common.h 3.1 KB

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