dm-bufio.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2009-2011 Red Hat, Inc.
  3. *
  4. * Author: Mikulas Patocka <[email protected]>
  5. *
  6. * This file is released under the GPL.
  7. */
  8. #ifndef _LINUX_DM_BUFIO_H
  9. #define _LINUX_DM_BUFIO_H
  10. #include <linux/blkdev.h>
  11. #include <linux/types.h>
  12. /*----------------------------------------------------------------*/
  13. struct dm_bufio_client;
  14. struct dm_buffer;
  15. /*
  16. * Flags for dm_bufio_client_create
  17. */
  18. #define DM_BUFIO_CLIENT_NO_SLEEP 0x1
  19. /*
  20. * Create a buffered IO cache on a given device
  21. */
  22. struct dm_bufio_client *
  23. dm_bufio_client_create(struct block_device *bdev, unsigned int block_size,
  24. unsigned int reserved_buffers, unsigned int aux_size,
  25. void (*alloc_callback)(struct dm_buffer *),
  26. void (*write_callback)(struct dm_buffer *),
  27. unsigned int flags);
  28. /*
  29. * Release a buffered IO cache.
  30. */
  31. void dm_bufio_client_destroy(struct dm_bufio_client *c);
  32. /*
  33. * Set the sector range.
  34. * When this function is called, there must be no I/O in progress on the bufio
  35. * client.
  36. */
  37. void dm_bufio_set_sector_offset(struct dm_bufio_client *c, sector_t start);
  38. /*
  39. * WARNING: to avoid deadlocks, these conditions are observed:
  40. *
  41. * - At most one thread can hold at most "reserved_buffers" simultaneously.
  42. * - Each other threads can hold at most one buffer.
  43. * - Threads which call only dm_bufio_get can hold unlimited number of
  44. * buffers.
  45. */
  46. /*
  47. * Read a given block from disk. Returns pointer to data. Returns a
  48. * pointer to dm_buffer that can be used to release the buffer or to make
  49. * it dirty.
  50. */
  51. void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
  52. struct dm_buffer **bp);
  53. /*
  54. * Like dm_bufio_read, but return buffer from cache, don't read
  55. * it. If the buffer is not in the cache, return NULL.
  56. */
  57. void *dm_bufio_get(struct dm_bufio_client *c, sector_t block,
  58. struct dm_buffer **bp);
  59. /*
  60. * Like dm_bufio_read, but don't read anything from the disk. It is
  61. * expected that the caller initializes the buffer and marks it dirty.
  62. */
  63. void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
  64. struct dm_buffer **bp);
  65. /*
  66. * Prefetch the specified blocks to the cache.
  67. * The function starts to read the blocks and returns without waiting for
  68. * I/O to finish.
  69. */
  70. void dm_bufio_prefetch(struct dm_bufio_client *c,
  71. sector_t block, unsigned int n_blocks);
  72. /*
  73. * Release a reference obtained with dm_bufio_{read,get,new}. The data
  74. * pointer and dm_buffer pointer is no longer valid after this call.
  75. */
  76. void dm_bufio_release(struct dm_buffer *b);
  77. /*
  78. * Mark a buffer dirty. It should be called after the buffer is modified.
  79. *
  80. * In case of memory pressure, the buffer may be written after
  81. * dm_bufio_mark_buffer_dirty, but before dm_bufio_write_dirty_buffers. So
  82. * dm_bufio_write_dirty_buffers guarantees that the buffer is on-disk but
  83. * the actual writing may occur earlier.
  84. */
  85. void dm_bufio_mark_buffer_dirty(struct dm_buffer *b);
  86. /*
  87. * Mark a part of the buffer dirty.
  88. *
  89. * The specified part of the buffer is scheduled to be written. dm-bufio may
  90. * write the specified part of the buffer or it may write a larger superset.
  91. */
  92. void dm_bufio_mark_partial_buffer_dirty(struct dm_buffer *b,
  93. unsigned int start, unsigned int end);
  94. /*
  95. * Initiate writing of dirty buffers, without waiting for completion.
  96. */
  97. void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c);
  98. /*
  99. * Write all dirty buffers. Guarantees that all dirty buffers created prior
  100. * to this call are on disk when this call exits.
  101. */
  102. int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c);
  103. /*
  104. * Send an empty write barrier to the device to flush hardware disk cache.
  105. */
  106. int dm_bufio_issue_flush(struct dm_bufio_client *c);
  107. /*
  108. * Send a discard request to the underlying device.
  109. */
  110. int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t count);
  111. /*
  112. * Like dm_bufio_release but also move the buffer to the new
  113. * block. dm_bufio_write_dirty_buffers is needed to commit the new block.
  114. */
  115. void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block);
  116. /*
  117. * Free the given buffer.
  118. * This is just a hint, if the buffer is in use or dirty, this function
  119. * does nothing.
  120. */
  121. void dm_bufio_forget(struct dm_bufio_client *c, sector_t block);
  122. /*
  123. * Free the given range of buffers.
  124. * This is just a hint, if the buffer is in use or dirty, this function
  125. * does nothing.
  126. */
  127. void dm_bufio_forget_buffers(struct dm_bufio_client *c, sector_t block, sector_t n_blocks);
  128. /*
  129. * Set the minimum number of buffers before cleanup happens.
  130. */
  131. void dm_bufio_set_minimum_buffers(struct dm_bufio_client *c, unsigned int n);
  132. unsigned int dm_bufio_get_block_size(struct dm_bufio_client *c);
  133. sector_t dm_bufio_get_device_size(struct dm_bufio_client *c);
  134. struct dm_io_client *dm_bufio_get_dm_io_client(struct dm_bufio_client *c);
  135. sector_t dm_bufio_get_block_number(struct dm_buffer *b);
  136. void *dm_bufio_get_block_data(struct dm_buffer *b);
  137. void *dm_bufio_get_aux_data(struct dm_buffer *b);
  138. struct dm_bufio_client *dm_bufio_get_client(struct dm_buffer *b);
  139. /*----------------------------------------------------------------*/
  140. #endif