block-common.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /*
  2. * QEMU System Emulator block driver
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #ifndef BLOCK_COMMON_H
  25. #define BLOCK_COMMON_H
  26. #include "qapi/qapi-types-block-core.h"
  27. #include "qemu/queue.h"
  28. /*
  29. * co_wrapper{*}: Function specifiers used by block-coroutine-wrapper.py
  30. *
  31. * Function specifiers, which do nothing but mark functions to be
  32. * generated by scripts/block-coroutine-wrapper.py
  33. *
  34. * Usage: read docs/devel/block-coroutine-wrapper.rst
  35. *
  36. * There are 4 kind of specifiers:
  37. * - co_wrapper functions can be called by only non-coroutine context, because
  38. * they always generate a new coroutine.
  39. * - co_wrapper_mixed functions can be called by both coroutine and
  40. * non-coroutine context.
  41. * - co_wrapper_bdrv_rdlock are co_wrapper functions but automatically take and
  42. * release the graph rdlock when creating a new coroutine
  43. * - co_wrapper_mixed_bdrv_rdlock are co_wrapper_mixed functions but
  44. * automatically take and release the graph rdlock when creating a new
  45. * coroutine.
  46. *
  47. * These functions should not be called from a coroutine_fn; instead,
  48. * call the wrapped function directly.
  49. */
  50. #define co_wrapper no_coroutine_fn
  51. #define co_wrapper_mixed no_coroutine_fn coroutine_mixed_fn
  52. #define co_wrapper_bdrv_rdlock no_coroutine_fn
  53. #define co_wrapper_mixed_bdrv_rdlock no_coroutine_fn coroutine_mixed_fn
  54. /*
  55. * no_co_wrapper: Function specifier used by block-coroutine-wrapper.py
  56. *
  57. * Function specifier which does nothing but mark functions to be generated by
  58. * scripts/block-coroutine-wrapper.py.
  59. *
  60. * A no_co_wrapper function declaration creates a coroutine_fn wrapper around
  61. * functions that must not be called in coroutine context. It achieves this by
  62. * scheduling a BH in the bottom half that runs the respective non-coroutine
  63. * function. The coroutine yields after scheduling the BH and is reentered when
  64. * the wrapped function returns.
  65. *
  66. * A no_co_wrapper_bdrv_rdlock function is a no_co_wrapper function that
  67. * automatically takes the graph rdlock when calling the wrapped function. In
  68. * the same way, no_co_wrapper_bdrv_wrlock functions automatically take the
  69. * graph wrlock.
  70. */
  71. #define no_co_wrapper
  72. #define no_co_wrapper_bdrv_rdlock
  73. #define no_co_wrapper_bdrv_wrlock
  74. #include "block/blockjob.h"
  75. /* block.c */
  76. typedef struct BlockDriver BlockDriver;
  77. typedef struct BdrvChild BdrvChild;
  78. typedef struct BdrvChildClass BdrvChildClass;
  79. typedef enum BlockZoneOp {
  80. BLK_ZO_OPEN,
  81. BLK_ZO_CLOSE,
  82. BLK_ZO_FINISH,
  83. BLK_ZO_RESET,
  84. } BlockZoneOp;
  85. typedef enum BlockZoneModel {
  86. BLK_Z_NONE = 0x0, /* Regular block device */
  87. BLK_Z_HM = 0x1, /* Host-managed zoned block device */
  88. BLK_Z_HA = 0x2, /* Host-aware zoned block device */
  89. } BlockZoneModel;
  90. typedef enum BlockZoneState {
  91. BLK_ZS_NOT_WP = 0x0,
  92. BLK_ZS_EMPTY = 0x1,
  93. BLK_ZS_IOPEN = 0x2,
  94. BLK_ZS_EOPEN = 0x3,
  95. BLK_ZS_CLOSED = 0x4,
  96. BLK_ZS_RDONLY = 0xD,
  97. BLK_ZS_FULL = 0xE,
  98. BLK_ZS_OFFLINE = 0xF,
  99. } BlockZoneState;
  100. typedef enum BlockZoneType {
  101. BLK_ZT_CONV = 0x1, /* Conventional random writes supported */
  102. BLK_ZT_SWR = 0x2, /* Sequential writes required */
  103. BLK_ZT_SWP = 0x3, /* Sequential writes preferred */
  104. } BlockZoneType;
  105. /*
  106. * Zone descriptor data structure.
  107. * Provides information on a zone with all position and size values in bytes.
  108. */
  109. typedef struct BlockZoneDescriptor {
  110. uint64_t start;
  111. uint64_t length;
  112. uint64_t cap;
  113. uint64_t wp;
  114. BlockZoneType type;
  115. BlockZoneState state;
  116. } BlockZoneDescriptor;
  117. /*
  118. * Track write pointers of a zone in bytes.
  119. */
  120. typedef struct BlockZoneWps {
  121. CoMutex colock;
  122. uint64_t wp[];
  123. } BlockZoneWps;
  124. typedef struct BlockDriverInfo {
  125. /* in bytes, 0 if irrelevant */
  126. int cluster_size;
  127. /*
  128. * A fraction of cluster_size, if supported (currently QCOW2 only); if
  129. * disabled or unsupported, set equal to cluster_size.
  130. */
  131. int subcluster_size;
  132. /* offset at which the VM state can be saved (0 if not possible) */
  133. int64_t vm_state_offset;
  134. bool is_dirty;
  135. /*
  136. * True if this block driver only supports compressed writes
  137. */
  138. bool needs_compressed_writes;
  139. } BlockDriverInfo;
  140. typedef struct BlockFragInfo {
  141. uint64_t allocated_clusters;
  142. uint64_t total_clusters;
  143. uint64_t fragmented_clusters;
  144. uint64_t compressed_clusters;
  145. } BlockFragInfo;
  146. typedef enum {
  147. BDRV_REQ_COPY_ON_READ = 0x1,
  148. BDRV_REQ_ZERO_WRITE = 0x2,
  149. /*
  150. * The BDRV_REQ_MAY_UNMAP flag is used in write_zeroes requests to indicate
  151. * that the block driver should unmap (discard) blocks if it is guaranteed
  152. * that the result will read back as zeroes. The flag is only passed to the
  153. * driver if the block device is opened with BDRV_O_UNMAP.
  154. */
  155. BDRV_REQ_MAY_UNMAP = 0x4,
  156. /*
  157. * An optimization hint when all QEMUIOVector elements are within
  158. * previously registered bdrv_register_buf() memory ranges.
  159. *
  160. * Code that replaces the user's QEMUIOVector elements with bounce buffers
  161. * must take care to clear this flag.
  162. */
  163. BDRV_REQ_REGISTERED_BUF = 0x8,
  164. BDRV_REQ_FUA = 0x10,
  165. BDRV_REQ_WRITE_COMPRESSED = 0x20,
  166. /*
  167. * Signifies that this write request will not change the visible disk
  168. * content.
  169. */
  170. BDRV_REQ_WRITE_UNCHANGED = 0x40,
  171. /*
  172. * Forces request serialisation. Use only with write requests.
  173. */
  174. BDRV_REQ_SERIALISING = 0x80,
  175. /*
  176. * Execute the request only if the operation can be offloaded or otherwise
  177. * be executed efficiently, but return an error instead of using a slow
  178. * fallback.
  179. */
  180. BDRV_REQ_NO_FALLBACK = 0x100,
  181. /*
  182. * BDRV_REQ_PREFETCH makes sense only in the context of copy-on-read
  183. * (i.e., together with the BDRV_REQ_COPY_ON_READ flag or when a COR
  184. * filter is involved), in which case it signals that the COR operation
  185. * need not read the data into memory (qiov) but only ensure they are
  186. * copied to the top layer (i.e., that COR operation is done).
  187. */
  188. BDRV_REQ_PREFETCH = 0x200,
  189. /*
  190. * If we need to wait for other requests, just fail immediately. Used
  191. * only together with BDRV_REQ_SERIALISING. Used only with requests aligned
  192. * to request_alignment (corresponding assertions are in block/io.c).
  193. */
  194. BDRV_REQ_NO_WAIT = 0x400,
  195. /* Mask of valid flags */
  196. BDRV_REQ_MASK = 0x7ff,
  197. } BdrvRequestFlags;
  198. #define BDRV_O_NO_SHARE 0x0001 /* don't share permissions */
  199. #define BDRV_O_RDWR 0x0002
  200. #define BDRV_O_RESIZE 0x0004 /* request permission for resizing the node */
  201. #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save
  202. writes in a snapshot */
  203. #define BDRV_O_TEMPORARY 0x0010 /* delete the file after use */
  204. #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
  205. #define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the
  206. thread pool */
  207. #define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */
  208. #define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */
  209. #define BDRV_O_COPY_ON_READ 0x0400 /* copy read backing sectors into image */
  210. #define BDRV_O_INACTIVE 0x0800 /* consistency hint for migration handoff */
  211. #define BDRV_O_CHECK 0x1000 /* open solely for consistency check */
  212. #define BDRV_O_ALLOW_RDWR 0x2000 /* allow reopen to change from r/o to r/w */
  213. #define BDRV_O_UNMAP 0x4000 /* execute guest UNMAP/TRIM operations */
  214. #define BDRV_O_PROTOCOL 0x8000 /* if no block driver is explicitly given:
  215. select an appropriate protocol driver,
  216. ignoring the format layer */
  217. #define BDRV_O_NO_IO 0x10000 /* don't initialize for I/O */
  218. #define BDRV_O_AUTO_RDONLY 0x20000 /* degrade to read-only if opening
  219. read-write fails */
  220. #define BDRV_O_IO_URING 0x40000 /* use io_uring instead of the thread pool */
  221. #define BDRV_O_CBW_DISCARD_SOURCE 0x80000 /* for copy-before-write filter */
  222. #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_NO_FLUSH)
  223. /* Option names of options parsed by the block layer */
  224. #define BDRV_OPT_CACHE_WB "cache.writeback"
  225. #define BDRV_OPT_CACHE_DIRECT "cache.direct"
  226. #define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
  227. #define BDRV_OPT_READ_ONLY "read-only"
  228. #define BDRV_OPT_AUTO_READ_ONLY "auto-read-only"
  229. #define BDRV_OPT_DISCARD "discard"
  230. #define BDRV_OPT_FORCE_SHARE "force-share"
  231. #define BDRV_OPT_ACTIVE "active"
  232. #define BDRV_SECTOR_BITS 9
  233. #define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)
  234. /*
  235. * Get the first most significant bit of wp. If it is zero, then
  236. * the zone type is SWR.
  237. */
  238. #define BDRV_ZT_IS_CONV(wp) (wp & (1ULL << 63))
  239. #define BDRV_REQUEST_MAX_SECTORS MIN_CONST(SIZE_MAX >> BDRV_SECTOR_BITS, \
  240. INT_MAX >> BDRV_SECTOR_BITS)
  241. #define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
  242. /*
  243. * We want allow aligning requests and disk length up to any 32bit alignment
  244. * and don't afraid of overflow.
  245. * To achieve it, and in the same time use some pretty number as maximum disk
  246. * size, let's define maximum "length" (a limit for any offset/bytes request and
  247. * for disk size) to be the greatest power of 2 less than INT64_MAX.
  248. */
  249. #define BDRV_MAX_ALIGNMENT (1L << 30)
  250. #define BDRV_MAX_LENGTH (QEMU_ALIGN_DOWN(INT64_MAX, BDRV_MAX_ALIGNMENT))
  251. /*
  252. * Allocation status flags for bdrv_block_status() and friends.
  253. *
  254. * Public flags:
  255. * BDRV_BLOCK_DATA: allocation for data at offset is tied to this layer
  256. * BDRV_BLOCK_ZERO: offset reads as zero
  257. * BDRV_BLOCK_OFFSET_VALID: an associated offset exists for accessing raw data
  258. * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
  259. * layer rather than any backing, set by block layer
  260. * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this
  261. * layer, set by block layer
  262. * BDRV_BLOCK_COMPRESSED: the underlying data is compressed; only valid for
  263. * the formats supporting compression: qcow, qcow2
  264. *
  265. * Internal flags:
  266. * BDRV_BLOCK_RAW: for use by passthrough drivers, such as raw, to request
  267. * that the block layer recompute the answer from the returned
  268. * BDS; must be accompanied by just BDRV_BLOCK_OFFSET_VALID.
  269. * BDRV_BLOCK_RECURSE: request that the block layer will recursively search for
  270. * zeroes in file child of current block node inside
  271. * returned region. Only valid together with both
  272. * BDRV_BLOCK_DATA and BDRV_BLOCK_OFFSET_VALID. Should not
  273. * appear with BDRV_BLOCK_ZERO.
  274. *
  275. * If BDRV_BLOCK_OFFSET_VALID is set, the map parameter represents the
  276. * host offset within the returned BDS that is allocated for the
  277. * corresponding raw guest data. However, whether that offset
  278. * actually contains data also depends on BDRV_BLOCK_DATA, as follows:
  279. *
  280. * DATA ZERO OFFSET_VALID
  281. * t t t sectors read as zero, returned file is zero at offset
  282. * t f t sectors read as valid from file at offset
  283. * f t t sectors preallocated, read as zero, returned file not
  284. * necessarily zero at offset
  285. * f f t sectors preallocated but read from backing_hd,
  286. * returned file contains garbage at offset
  287. * t t f sectors preallocated, read as zero, unknown offset
  288. * t f f sectors read from unknown file or offset
  289. * f t f not allocated or unknown offset, read as zero
  290. * f f f not allocated or unknown offset, read from backing_hd
  291. */
  292. #define BDRV_BLOCK_DATA 0x01
  293. #define BDRV_BLOCK_ZERO 0x02
  294. #define BDRV_BLOCK_OFFSET_VALID 0x04
  295. #define BDRV_BLOCK_RAW 0x08
  296. #define BDRV_BLOCK_ALLOCATED 0x10
  297. #define BDRV_BLOCK_EOF 0x20
  298. #define BDRV_BLOCK_RECURSE 0x40
  299. #define BDRV_BLOCK_COMPRESSED 0x80
  300. typedef QTAILQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
  301. typedef struct BDRVReopenState {
  302. BlockDriverState *bs;
  303. int flags;
  304. BlockdevDetectZeroesOptions detect_zeroes;
  305. bool backing_missing;
  306. BlockDriverState *old_backing_bs; /* keep pointer for permissions update */
  307. BlockDriverState *old_file_bs; /* keep pointer for permissions update */
  308. QDict *options;
  309. QDict *explicit_options;
  310. void *opaque;
  311. } BDRVReopenState;
  312. /*
  313. * Block operation types
  314. */
  315. typedef enum BlockOpType {
  316. BLOCK_OP_TYPE_BACKUP_SOURCE,
  317. BLOCK_OP_TYPE_BACKUP_TARGET,
  318. BLOCK_OP_TYPE_CHANGE,
  319. BLOCK_OP_TYPE_COMMIT_SOURCE,
  320. BLOCK_OP_TYPE_COMMIT_TARGET,
  321. BLOCK_OP_TYPE_DRIVE_DEL,
  322. BLOCK_OP_TYPE_EJECT,
  323. BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
  324. BLOCK_OP_TYPE_INTERNAL_SNAPSHOT,
  325. BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
  326. BLOCK_OP_TYPE_MIRROR_SOURCE,
  327. BLOCK_OP_TYPE_MIRROR_TARGET,
  328. BLOCK_OP_TYPE_RESIZE,
  329. BLOCK_OP_TYPE_STREAM,
  330. BLOCK_OP_TYPE_REPLACE,
  331. BLOCK_OP_TYPE_MAX,
  332. } BlockOpType;
  333. /* Block node permission constants */
  334. enum {
  335. /**
  336. * A user that has the "permission" of consistent reads is guaranteed that
  337. * their view of the contents of the block device is complete and
  338. * self-consistent, representing the contents of a disk at a specific
  339. * point.
  340. *
  341. * For most block devices (including their backing files) this is true, but
  342. * the property cannot be maintained in a few situations like for
  343. * intermediate nodes of a commit block job.
  344. */
  345. BLK_PERM_CONSISTENT_READ = 0x01,
  346. /** This permission is required to change the visible disk contents. */
  347. BLK_PERM_WRITE = 0x02,
  348. /**
  349. * This permission (which is weaker than BLK_PERM_WRITE) is both enough and
  350. * required for writes to the block node when the caller promises that
  351. * the visible disk content doesn't change.
  352. *
  353. * As the BLK_PERM_WRITE permission is strictly stronger, either is
  354. * sufficient to perform an unchanging write.
  355. */
  356. BLK_PERM_WRITE_UNCHANGED = 0x04,
  357. /** This permission is required to change the size of a block node. */
  358. BLK_PERM_RESIZE = 0x08,
  359. /**
  360. * There was a now-removed bit BLK_PERM_GRAPH_MOD, with value of 0x10. QEMU
  361. * 6.1 and earlier may still lock the corresponding byte in block/file-posix
  362. * locking. So, implementing some new permission should be very careful to
  363. * not interfere with this old unused thing.
  364. */
  365. BLK_PERM_ALL = 0x0f,
  366. DEFAULT_PERM_PASSTHROUGH = BLK_PERM_CONSISTENT_READ
  367. | BLK_PERM_WRITE
  368. | BLK_PERM_WRITE_UNCHANGED
  369. | BLK_PERM_RESIZE,
  370. DEFAULT_PERM_UNCHANGED = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH,
  371. };
  372. /*
  373. * Flags that parent nodes assign to child nodes to specify what kind of
  374. * role(s) they take.
  375. *
  376. * At least one of DATA, METADATA, FILTERED, or COW must be set for
  377. * every child.
  378. *
  379. *
  380. * = Connection with bs->children, bs->file and bs->backing fields =
  381. *
  382. * 1. Filters
  383. *
  384. * Filter drivers have drv->is_filter = true.
  385. *
  386. * Filter node has exactly one FILTERED|PRIMARY child, and may have other
  387. * children which must not have these bits (one example is the
  388. * copy-before-write filter, which also has its target DATA child).
  389. *
  390. * Filter nodes never have COW children.
  391. *
  392. * For most filters, the filtered child is linked in bs->file, bs->backing is
  393. * NULL. For some filters (as an exception), it is the other way around; those
  394. * drivers will have drv->filtered_child_is_backing set to true (see that
  395. * field’s documentation for what drivers this concerns)
  396. *
  397. * 2. "raw" driver (block/raw-format.c)
  398. *
  399. * Formally it's not a filter (drv->is_filter = false)
  400. *
  401. * bs->backing is always NULL
  402. *
  403. * Only has one child, linked in bs->file. Its role is either FILTERED|PRIMARY
  404. * (like filter) or DATA|PRIMARY depending on options.
  405. *
  406. * 3. Other drivers
  407. *
  408. * Don't have any FILTERED children.
  409. *
  410. * May have at most one COW child. In this case it's linked in bs->backing.
  411. * Otherwise bs->backing is NULL. COW child is never PRIMARY.
  412. *
  413. * May have at most one PRIMARY child. In this case it's linked in bs->file.
  414. * Otherwise bs->file is NULL.
  415. *
  416. * May also have some other children that don't have the PRIMARY or COW bit set.
  417. */
  418. enum BdrvChildRoleBits {
  419. /*
  420. * This child stores data.
  421. * Any node may have an arbitrary number of such children.
  422. */
  423. BDRV_CHILD_DATA = (1 << 0),
  424. /*
  425. * This child stores metadata.
  426. * Any node may have an arbitrary number of metadata-storing
  427. * children.
  428. */
  429. BDRV_CHILD_METADATA = (1 << 1),
  430. /*
  431. * A child that always presents exactly the same visible data as
  432. * the parent, e.g. by virtue of the parent forwarding all reads
  433. * and writes.
  434. * This flag is mutually exclusive with DATA, METADATA, and COW.
  435. * Any node may have at most one filtered child at a time.
  436. */
  437. BDRV_CHILD_FILTERED = (1 << 2),
  438. /*
  439. * Child from which to read all data that isn't allocated in the
  440. * parent (i.e., the backing child); such data is copied to the
  441. * parent through COW (and optionally COR).
  442. * This field is mutually exclusive with DATA, METADATA, and
  443. * FILTERED.
  444. * Any node may have at most one such backing child at a time.
  445. */
  446. BDRV_CHILD_COW = (1 << 3),
  447. /*
  448. * The primary child. For most drivers, this is the child whose
  449. * filename applies best to the parent node.
  450. * Any node may have at most one primary child at a time.
  451. */
  452. BDRV_CHILD_PRIMARY = (1 << 4),
  453. /* Useful combination of flags */
  454. BDRV_CHILD_IMAGE = BDRV_CHILD_DATA
  455. | BDRV_CHILD_METADATA
  456. | BDRV_CHILD_PRIMARY,
  457. };
  458. /* Mask of BdrvChildRoleBits values */
  459. typedef unsigned int BdrvChildRole;
  460. typedef struct BdrvCheckResult {
  461. int corruptions;
  462. int leaks;
  463. int check_errors;
  464. int corruptions_fixed;
  465. int leaks_fixed;
  466. int64_t image_end_offset;
  467. BlockFragInfo bfi;
  468. } BdrvCheckResult;
  469. typedef enum {
  470. BDRV_FIX_LEAKS = 1,
  471. BDRV_FIX_ERRORS = 2,
  472. } BdrvCheckMode;
  473. typedef struct BlockSizes {
  474. uint32_t phys;
  475. uint32_t log;
  476. } BlockSizes;
  477. typedef struct HDGeometry {
  478. uint32_t heads;
  479. uint32_t sectors;
  480. uint32_t cylinders;
  481. } HDGeometry;
  482. /*
  483. * Common functions that are neither I/O nor Global State.
  484. *
  485. * These functions must never call any function from other categories
  486. * (I/O, "I/O or GS", Global State) except this one, but can be invoked by
  487. * all of them.
  488. */
  489. char *bdrv_perm_names(uint64_t perm);
  490. uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm);
  491. void bdrv_init_with_whitelist(void);
  492. bool bdrv_uses_whitelist(void);
  493. int bdrv_is_whitelisted(BlockDriver *drv, bool read_only);
  494. int bdrv_parse_aio(const char *mode, int *flags);
  495. int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough);
  496. int bdrv_parse_discard_flags(const char *mode, int *flags);
  497. int path_has_protocol(const char *path);
  498. int path_is_absolute(const char *path);
  499. char *path_combine(const char *base_path, const char *filename);
  500. char *bdrv_get_full_backing_filename_from_filename(const char *backed,
  501. const char *backing,
  502. Error **errp);
  503. #endif /* BLOCK_COMMON_H */