dm-io.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2003 Sistina Software
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef _DM_IO_H
  7. #define _DM_IO_H
  8. #include "dm.h"
  9. struct io_region {
  10. struct block_device *bdev;
  11. sector_t sector;
  12. sector_t count;
  13. };
  14. struct page_list {
  15. struct page_list *next;
  16. struct page *page;
  17. };
  18. /*
  19. * 'error' is a bitset, with each bit indicating whether an error
  20. * occurred doing io to the corresponding region.
  21. */
  22. typedef void (*io_notify_fn)(unsigned long error, void *context);
  23. enum dm_io_mem_type {
  24. DM_IO_PAGE_LIST,/* Page list */
  25. DM_IO_BVEC, /* Bio vector */
  26. DM_IO_VMA, /* Virtual memory area */
  27. DM_IO_KMEM, /* Kernel memory */
  28. };
  29. struct dm_io_memory {
  30. enum dm_io_mem_type type;
  31. union {
  32. struct page_list *pl;
  33. struct bio_vec *bvec;
  34. void *vma;
  35. void *addr;
  36. } ptr;
  37. unsigned offset;
  38. };
  39. struct dm_io_notify {
  40. io_notify_fn fn; /* Callback for asynchronous requests */
  41. void *context; /* Passed to callback */
  42. };
  43. /*
  44. * IO request structure
  45. */
  46. struct dm_io_client;
  47. struct dm_io_request {
  48. int bi_rw; /* READ|WRITE - not READA */
  49. struct dm_io_memory mem; /* Memory to use for io */
  50. struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
  51. struct dm_io_client *client; /* Client memory handler */
  52. };
  53. /*
  54. * Before anyone uses the IO interface they should call
  55. * dm_io_get(), specifying roughly how many pages they are
  56. * expecting to perform io on concurrently.
  57. *
  58. * This function may block.
  59. */
  60. int dm_io_get(unsigned int num_pages);
  61. void dm_io_put(unsigned int num_pages);
  62. /*
  63. * For async io calls, users can alternatively use the dm_io() function below
  64. * and dm_io_client_create() to create private mempools for the client.
  65. *
  66. * Create/destroy may block.
  67. */
  68. struct dm_io_client *dm_io_client_create(unsigned num_pages);
  69. int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client);
  70. void dm_io_client_destroy(struct dm_io_client *client);
  71. /*
  72. * Synchronous IO.
  73. *
  74. * Please ensure that the rw flag in the next two functions is
  75. * either READ or WRITE, ie. we don't take READA. Any
  76. * regions with a zero count field will be ignored.
  77. */
  78. int dm_io_sync(unsigned int num_regions, struct io_region *where, int rw,
  79. struct page_list *pl, unsigned int offset,
  80. unsigned long *error_bits);
  81. int dm_io_sync_bvec(unsigned int num_regions, struct io_region *where, int rw,
  82. struct bio_vec *bvec, unsigned long *error_bits);
  83. int dm_io_sync_vm(unsigned int num_regions, struct io_region *where, int rw,
  84. void *data, unsigned long *error_bits);
  85. /*
  86. * Aynchronous IO.
  87. *
  88. * The 'where' array may be safely allocated on the stack since
  89. * the function takes a copy.
  90. */
  91. int dm_io_async(unsigned int num_regions, struct io_region *where, int rw,
  92. struct page_list *pl, unsigned int offset,
  93. io_notify_fn fn, void *context);
  94. int dm_io_async_bvec(unsigned int num_regions, struct io_region *where, int rw,
  95. struct bio_vec *bvec, io_notify_fn fn, void *context);
  96. int dm_io_async_vm(unsigned int num_regions, struct io_region *where, int rw,
  97. void *data, io_notify_fn fn, void *context);
  98. /*
  99. * IO interface using private per-client pools.
  100. */
  101. int dm_io(struct dm_io_request *io_req, unsigned num_regions,
  102. struct io_region *region, unsigned long *sync_error_bits);
  103. #endif