dax.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef _LINUX_DAX_H
  2. #define _LINUX_DAX_H
  3. #include <linux/fs.h>
  4. #include <linux/mm.h>
  5. #include <linux/radix-tree.h>
  6. #include <asm/pgtable.h>
  7. struct iomap_ops;
  8. struct dax_device;
  9. struct dax_operations {
  10. /*
  11. * direct_access: translate a device-relative
  12. * logical-page-offset into an absolute physical pfn. Return the
  13. * number of pages available for DAX at that pfn.
  14. */
  15. long (*direct_access)(struct dax_device *, pgoff_t, long,
  16. void **, pfn_t *);
  17. };
  18. int dax_read_lock(void);
  19. void dax_read_unlock(int id);
  20. struct dax_device *dax_get_by_host(const char *host);
  21. struct dax_device *alloc_dax(void *private, const char *host,
  22. const struct dax_operations *ops);
  23. void put_dax(struct dax_device *dax_dev);
  24. bool dax_alive(struct dax_device *dax_dev);
  25. void kill_dax(struct dax_device *dax_dev);
  26. void *dax_get_private(struct dax_device *dax_dev);
  27. /*
  28. * We use lowest available bit in exceptional entry for locking, one bit for
  29. * the entry size (PMD) and two more to tell us if the entry is a huge zero
  30. * page (HZP) or an empty entry that is just used for locking. In total four
  31. * special bits.
  32. *
  33. * If the PMD bit isn't set the entry has size PAGE_SIZE, and if the HZP and
  34. * EMPTY bits aren't set the entry is a normal DAX entry with a filesystem
  35. * block allocation.
  36. */
  37. #define RADIX_DAX_SHIFT (RADIX_TREE_EXCEPTIONAL_SHIFT + 4)
  38. #define RADIX_DAX_ENTRY_LOCK (1 << RADIX_TREE_EXCEPTIONAL_SHIFT)
  39. #define RADIX_DAX_PMD (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 1))
  40. #define RADIX_DAX_HZP (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 2))
  41. #define RADIX_DAX_EMPTY (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 3))
  42. static inline unsigned long dax_radix_sector(void *entry)
  43. {
  44. return (unsigned long)entry >> RADIX_DAX_SHIFT;
  45. }
  46. static inline void *dax_radix_locked_entry(sector_t sector, unsigned long flags)
  47. {
  48. return (void *)(RADIX_TREE_EXCEPTIONAL_ENTRY | flags |
  49. ((unsigned long)sector << RADIX_DAX_SHIFT) |
  50. RADIX_DAX_ENTRY_LOCK);
  51. }
  52. ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
  53. const struct iomap_ops *ops);
  54. int dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size,
  55. const struct iomap_ops *ops);
  56. int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
  57. int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index);
  58. int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
  59. pgoff_t index);
  60. void dax_wake_mapping_entry_waiter(struct address_space *mapping,
  61. pgoff_t index, void *entry, bool wake_all);
  62. #ifdef CONFIG_FS_DAX
  63. struct page *read_dax_sector(struct block_device *bdev, sector_t n);
  64. int __dax_zero_page_range(struct block_device *bdev, sector_t sector,
  65. unsigned int offset, unsigned int length);
  66. #else
  67. static inline struct page *read_dax_sector(struct block_device *bdev,
  68. sector_t n)
  69. {
  70. return ERR_PTR(-ENXIO);
  71. }
  72. static inline int __dax_zero_page_range(struct block_device *bdev,
  73. sector_t sector, unsigned int offset, unsigned int length)
  74. {
  75. return -ENXIO;
  76. }
  77. #endif
  78. #ifdef CONFIG_FS_DAX_PMD
  79. static inline unsigned int dax_radix_order(void *entry)
  80. {
  81. if ((unsigned long)entry & RADIX_DAX_PMD)
  82. return PMD_SHIFT - PAGE_SHIFT;
  83. return 0;
  84. }
  85. #else
  86. static inline unsigned int dax_radix_order(void *entry)
  87. {
  88. return 0;
  89. }
  90. #endif
  91. int dax_pfn_mkwrite(struct vm_fault *vmf);
  92. static inline bool vma_is_dax(struct vm_area_struct *vma)
  93. {
  94. return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
  95. }
  96. static inline bool dax_mapping(struct address_space *mapping)
  97. {
  98. return mapping->host && IS_DAX(mapping->host);
  99. }
  100. struct writeback_control;
  101. int dax_writeback_mapping_range(struct address_space *mapping,
  102. struct block_device *bdev, struct writeback_control *wbc);
  103. #endif