dax.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /*
  9. * We use lowest available bit in exceptional entry for locking, one bit for
  10. * the entry size (PMD) and two more to tell us if the entry is a huge zero
  11. * page (HZP) or an empty entry that is just used for locking. In total four
  12. * special bits.
  13. *
  14. * If the PMD bit isn't set the entry has size PAGE_SIZE, and if the HZP and
  15. * EMPTY bits aren't set the entry is a normal DAX entry with a filesystem
  16. * block allocation.
  17. */
  18. #define RADIX_DAX_SHIFT (RADIX_TREE_EXCEPTIONAL_SHIFT + 4)
  19. #define RADIX_DAX_ENTRY_LOCK (1 << RADIX_TREE_EXCEPTIONAL_SHIFT)
  20. #define RADIX_DAX_PMD (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 1))
  21. #define RADIX_DAX_HZP (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 2))
  22. #define RADIX_DAX_EMPTY (1 << (RADIX_TREE_EXCEPTIONAL_SHIFT + 3))
  23. static inline unsigned long dax_radix_sector(void *entry)
  24. {
  25. return (unsigned long)entry >> RADIX_DAX_SHIFT;
  26. }
  27. static inline void *dax_radix_locked_entry(sector_t sector, unsigned long flags)
  28. {
  29. return (void *)(RADIX_TREE_EXCEPTIONAL_ENTRY | flags |
  30. ((unsigned long)sector << RADIX_DAX_SHIFT) |
  31. RADIX_DAX_ENTRY_LOCK);
  32. }
  33. ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
  34. const struct iomap_ops *ops);
  35. int dax_iomap_fault(struct vm_fault *vmf, const struct iomap_ops *ops);
  36. int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index);
  37. int dax_invalidate_mapping_entry(struct address_space *mapping, pgoff_t index);
  38. int dax_invalidate_mapping_entry_sync(struct address_space *mapping,
  39. pgoff_t index);
  40. void dax_wake_mapping_entry_waiter(struct address_space *mapping,
  41. pgoff_t index, void *entry, bool wake_all);
  42. #ifdef CONFIG_FS_DAX
  43. struct page *read_dax_sector(struct block_device *bdev, sector_t n);
  44. int __dax_zero_page_range(struct block_device *bdev, sector_t sector,
  45. unsigned int offset, unsigned int length);
  46. #else
  47. static inline struct page *read_dax_sector(struct block_device *bdev,
  48. sector_t n)
  49. {
  50. return ERR_PTR(-ENXIO);
  51. }
  52. static inline int __dax_zero_page_range(struct block_device *bdev,
  53. sector_t sector, unsigned int offset, unsigned int length)
  54. {
  55. return -ENXIO;
  56. }
  57. #endif
  58. #ifdef CONFIG_FS_DAX_PMD
  59. static inline unsigned int dax_radix_order(void *entry)
  60. {
  61. if ((unsigned long)entry & RADIX_DAX_PMD)
  62. return PMD_SHIFT - PAGE_SHIFT;
  63. return 0;
  64. }
  65. int dax_iomap_pmd_fault(struct vm_fault *vmf, const struct iomap_ops *ops);
  66. #else
  67. static inline unsigned int dax_radix_order(void *entry)
  68. {
  69. return 0;
  70. }
  71. static inline int dax_iomap_pmd_fault(struct vm_fault *vmf,
  72. const struct iomap_ops *ops)
  73. {
  74. return VM_FAULT_FALLBACK;
  75. }
  76. #endif
  77. int dax_pfn_mkwrite(struct vm_fault *vmf);
  78. static inline bool vma_is_dax(struct vm_area_struct *vma)
  79. {
  80. return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
  81. }
  82. static inline bool dax_mapping(struct address_space *mapping)
  83. {
  84. return mapping->host && IS_DAX(mapping->host);
  85. }
  86. struct writeback_control;
  87. int dax_writeback_mapping_range(struct address_space *mapping,
  88. struct block_device *bdev, struct writeback_control *wbc);
  89. #endif