dax.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #else
  66. static inline unsigned int dax_radix_order(void *entry)
  67. {
  68. return 0;
  69. }
  70. #endif
  71. int dax_pfn_mkwrite(struct vm_fault *vmf);
  72. static inline bool vma_is_dax(struct vm_area_struct *vma)
  73. {
  74. return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
  75. }
  76. static inline bool dax_mapping(struct address_space *mapping)
  77. {
  78. return mapping->host && IS_DAX(mapping->host);
  79. }
  80. struct writeback_control;
  81. int dax_writeback_mapping_range(struct address_space *mapping,
  82. struct block_device *bdev, struct writeback_control *wbc);
  83. #endif