dax.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_DAX_H
  3. #define _LINUX_DAX_H
  4. #include <linux/fs.h>
  5. #include <linux/mm.h>
  6. #include <linux/radix-tree.h>
  7. #include <asm/pgtable.h>
  8. struct iomap_ops;
  9. struct dax_device;
  10. struct dax_operations {
  11. /*
  12. * direct_access: translate a device-relative
  13. * logical-page-offset into an absolute physical pfn. Return the
  14. * number of pages available for DAX at that pfn.
  15. */
  16. long (*direct_access)(struct dax_device *, pgoff_t, long,
  17. void **, pfn_t *);
  18. /* copy_from_iter: required operation for fs-dax direct-i/o */
  19. size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t,
  20. struct iov_iter *);
  21. /* copy_to_iter: required operation for fs-dax direct-i/o */
  22. size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
  23. struct iov_iter *);
  24. };
  25. extern struct attribute_group dax_attribute_group;
  26. #if IS_ENABLED(CONFIG_DAX)
  27. struct dax_device *dax_get_by_host(const char *host);
  28. struct dax_device *alloc_dax(void *private, const char *host,
  29. const struct dax_operations *ops);
  30. void put_dax(struct dax_device *dax_dev);
  31. void kill_dax(struct dax_device *dax_dev);
  32. void dax_write_cache(struct dax_device *dax_dev, bool wc);
  33. bool dax_write_cache_enabled(struct dax_device *dax_dev);
  34. #else
  35. static inline struct dax_device *dax_get_by_host(const char *host)
  36. {
  37. return NULL;
  38. }
  39. static inline struct dax_device *alloc_dax(void *private, const char *host,
  40. const struct dax_operations *ops)
  41. {
  42. /*
  43. * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
  44. * NULL is an error or expected.
  45. */
  46. return NULL;
  47. }
  48. static inline void put_dax(struct dax_device *dax_dev)
  49. {
  50. }
  51. static inline void kill_dax(struct dax_device *dax_dev)
  52. {
  53. }
  54. static inline void dax_write_cache(struct dax_device *dax_dev, bool wc)
  55. {
  56. }
  57. static inline bool dax_write_cache_enabled(struct dax_device *dax_dev)
  58. {
  59. return false;
  60. }
  61. #endif
  62. struct writeback_control;
  63. int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff);
  64. #if IS_ENABLED(CONFIG_FS_DAX)
  65. bool __bdev_dax_supported(struct block_device *bdev, int blocksize);
  66. static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize)
  67. {
  68. return __bdev_dax_supported(bdev, blocksize);
  69. }
  70. static inline struct dax_device *fs_dax_get_by_host(const char *host)
  71. {
  72. return dax_get_by_host(host);
  73. }
  74. static inline void fs_put_dax(struct dax_device *dax_dev)
  75. {
  76. put_dax(dax_dev);
  77. }
  78. struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev);
  79. int dax_writeback_mapping_range(struct address_space *mapping,
  80. struct block_device *bdev, struct writeback_control *wbc);
  81. struct page *dax_layout_busy_page(struct address_space *mapping);
  82. #else
  83. static inline bool bdev_dax_supported(struct block_device *bdev,
  84. int blocksize)
  85. {
  86. return false;
  87. }
  88. static inline struct dax_device *fs_dax_get_by_host(const char *host)
  89. {
  90. return NULL;
  91. }
  92. static inline void fs_put_dax(struct dax_device *dax_dev)
  93. {
  94. }
  95. static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
  96. {
  97. return NULL;
  98. }
  99. static inline struct page *dax_layout_busy_page(struct address_space *mapping)
  100. {
  101. return NULL;
  102. }
  103. static inline int dax_writeback_mapping_range(struct address_space *mapping,
  104. struct block_device *bdev, struct writeback_control *wbc)
  105. {
  106. return -EOPNOTSUPP;
  107. }
  108. #endif
  109. int dax_read_lock(void);
  110. void dax_read_unlock(int id);
  111. bool dax_alive(struct dax_device *dax_dev);
  112. void *dax_get_private(struct dax_device *dax_dev);
  113. long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages,
  114. void **kaddr, pfn_t *pfn);
  115. size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
  116. size_t bytes, struct iov_iter *i);
  117. size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
  118. size_t bytes, struct iov_iter *i);
  119. void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
  120. ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
  121. const struct iomap_ops *ops);
  122. int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
  123. pfn_t *pfnp, int *errp, const struct iomap_ops *ops);
  124. vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf,
  125. enum page_entry_size pe_size, pfn_t pfn);
  126. int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
  127. int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
  128. pgoff_t index);
  129. #ifdef CONFIG_FS_DAX
  130. int __dax_zero_page_range(struct block_device *bdev,
  131. struct dax_device *dax_dev, sector_t sector,
  132. unsigned int offset, unsigned int length);
  133. #else
  134. static inline int __dax_zero_page_range(struct block_device *bdev,
  135. struct dax_device *dax_dev, sector_t sector,
  136. unsigned int offset, unsigned int length)
  137. {
  138. return -ENXIO;
  139. }
  140. #endif
  141. static inline bool dax_mapping(struct address_space *mapping)
  142. {
  143. return mapping->host && IS_DAX(mapping->host);
  144. }
  145. #endif