Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v5.9-rc6 242 lines 7.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_DAX_H 3#define _LINUX_DAX_H 4 5#include <linux/fs.h> 6#include <linux/mm.h> 7#include <linux/radix-tree.h> 8 9/* Flag for synchronous flush */ 10#define DAXDEV_F_SYNC (1UL << 0) 11 12typedef unsigned long dax_entry_t; 13 14struct iomap_ops; 15struct iomap; 16struct dax_device; 17struct dax_operations { 18 /* 19 * direct_access: translate a device-relative 20 * logical-page-offset into an absolute physical pfn. Return the 21 * number of pages available for DAX at that pfn. 22 */ 23 long (*direct_access)(struct dax_device *, pgoff_t, long, 24 void **, pfn_t *); 25 /* 26 * Validate whether this device is usable as an fsdax backing 27 * device. 28 */ 29 bool (*dax_supported)(struct dax_device *, struct block_device *, int, 30 sector_t, sector_t); 31 /* copy_from_iter: required operation for fs-dax direct-i/o */ 32 size_t (*copy_from_iter)(struct dax_device *, pgoff_t, void *, size_t, 33 struct iov_iter *); 34 /* copy_to_iter: required operation for fs-dax direct-i/o */ 35 size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t, 36 struct iov_iter *); 37 /* zero_page_range: required operation. Zero page range */ 38 int (*zero_page_range)(struct dax_device *, pgoff_t, size_t); 39}; 40 41extern struct attribute_group dax_attribute_group; 42 43#if IS_ENABLED(CONFIG_DAX) 44struct dax_device *dax_get_by_host(const char *host); 45struct dax_device *alloc_dax(void *private, const char *host, 46 const struct dax_operations *ops, unsigned long flags); 47void put_dax(struct dax_device *dax_dev); 48void kill_dax(struct dax_device *dax_dev); 49void dax_write_cache(struct dax_device *dax_dev, bool wc); 50bool dax_write_cache_enabled(struct dax_device *dax_dev); 51bool __dax_synchronous(struct dax_device *dax_dev); 52static inline bool dax_synchronous(struct dax_device *dax_dev) 53{ 54 return __dax_synchronous(dax_dev); 55} 56void __set_dax_synchronous(struct dax_device *dax_dev); 57static inline void set_dax_synchronous(struct dax_device *dax_dev) 58{ 59 __set_dax_synchronous(dax_dev); 60} 61/* 62 * Check if given mapping is supported by the file / underlying device. 63 */ 64static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, 65 struct dax_device *dax_dev) 66{ 67 if (!(vma->vm_flags & VM_SYNC)) 68 return true; 69 if (!IS_DAX(file_inode(vma->vm_file))) 70 return false; 71 return dax_synchronous(dax_dev); 72} 73#else 74static inline struct dax_device *dax_get_by_host(const char *host) 75{ 76 return NULL; 77} 78static inline struct dax_device *alloc_dax(void *private, const char *host, 79 const struct dax_operations *ops, unsigned long flags) 80{ 81 /* 82 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this 83 * NULL is an error or expected. 84 */ 85 return NULL; 86} 87static inline void put_dax(struct dax_device *dax_dev) 88{ 89} 90static inline void kill_dax(struct dax_device *dax_dev) 91{ 92} 93static inline void dax_write_cache(struct dax_device *dax_dev, bool wc) 94{ 95} 96static inline bool dax_write_cache_enabled(struct dax_device *dax_dev) 97{ 98 return false; 99} 100static inline bool dax_synchronous(struct dax_device *dax_dev) 101{ 102 return true; 103} 104static inline void set_dax_synchronous(struct dax_device *dax_dev) 105{ 106} 107static inline bool daxdev_mapping_supported(struct vm_area_struct *vma, 108 struct dax_device *dax_dev) 109{ 110 return !(vma->vm_flags & VM_SYNC); 111} 112#endif 113 114struct writeback_control; 115int bdev_dax_pgoff(struct block_device *, sector_t, size_t, pgoff_t *pgoff); 116#if IS_ENABLED(CONFIG_FS_DAX) 117bool __bdev_dax_supported(struct block_device *bdev, int blocksize); 118static inline bool bdev_dax_supported(struct block_device *bdev, int blocksize) 119{ 120 return __bdev_dax_supported(bdev, blocksize); 121} 122 123bool __generic_fsdax_supported(struct dax_device *dax_dev, 124 struct block_device *bdev, int blocksize, sector_t start, 125 sector_t sectors); 126static inline bool generic_fsdax_supported(struct dax_device *dax_dev, 127 struct block_device *bdev, int blocksize, sector_t start, 128 sector_t sectors) 129{ 130 return __generic_fsdax_supported(dax_dev, bdev, blocksize, start, 131 sectors); 132} 133bool dax_supported(struct dax_device *dax_dev, struct block_device *bdev, 134 int blocksize, sector_t start, sector_t len); 135 136static inline void fs_put_dax(struct dax_device *dax_dev) 137{ 138 put_dax(dax_dev); 139} 140 141struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev); 142int dax_writeback_mapping_range(struct address_space *mapping, 143 struct dax_device *dax_dev, struct writeback_control *wbc); 144 145struct page *dax_layout_busy_page(struct address_space *mapping); 146dax_entry_t dax_lock_page(struct page *page); 147void dax_unlock_page(struct page *page, dax_entry_t cookie); 148#else 149static inline bool bdev_dax_supported(struct block_device *bdev, 150 int blocksize) 151{ 152 return false; 153} 154 155static inline bool generic_fsdax_supported(struct dax_device *dax_dev, 156 struct block_device *bdev, int blocksize, sector_t start, 157 sector_t sectors) 158{ 159 return false; 160} 161 162static inline bool dax_supported(struct dax_device *dax_dev, 163 struct block_device *bdev, int blocksize, sector_t start, 164 sector_t len) 165{ 166 return false; 167} 168 169static inline void fs_put_dax(struct dax_device *dax_dev) 170{ 171} 172 173static inline struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) 174{ 175 return NULL; 176} 177 178static inline struct page *dax_layout_busy_page(struct address_space *mapping) 179{ 180 return NULL; 181} 182 183static inline int dax_writeback_mapping_range(struct address_space *mapping, 184 struct dax_device *dax_dev, struct writeback_control *wbc) 185{ 186 return -EOPNOTSUPP; 187} 188 189static inline dax_entry_t dax_lock_page(struct page *page) 190{ 191 if (IS_DAX(page->mapping->host)) 192 return ~0UL; 193 return 0; 194} 195 196static inline void dax_unlock_page(struct page *page, dax_entry_t cookie) 197{ 198} 199#endif 200 201#if IS_ENABLED(CONFIG_DAX) 202int dax_read_lock(void); 203void dax_read_unlock(int id); 204#else 205static inline int dax_read_lock(void) 206{ 207 return 0; 208} 209 210static inline void dax_read_unlock(int id) 211{ 212} 213#endif /* CONFIG_DAX */ 214bool dax_alive(struct dax_device *dax_dev); 215void *dax_get_private(struct dax_device *dax_dev); 216long dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, 217 void **kaddr, pfn_t *pfn); 218size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, 219 size_t bytes, struct iov_iter *i); 220size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr, 221 size_t bytes, struct iov_iter *i); 222int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, 223 size_t nr_pages); 224void dax_flush(struct dax_device *dax_dev, void *addr, size_t size); 225 226ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter, 227 const struct iomap_ops *ops); 228vm_fault_t dax_iomap_fault(struct vm_fault *vmf, enum page_entry_size pe_size, 229 pfn_t *pfnp, int *errp, const struct iomap_ops *ops); 230vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, 231 enum page_entry_size pe_size, pfn_t pfn); 232int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); 233int dax_invalidate_mapping_entry_sync(struct address_space *mapping, 234 pgoff_t index); 235int dax_iomap_zero(loff_t pos, unsigned offset, unsigned size, 236 struct iomap *iomap); 237static inline bool dax_mapping(struct address_space *mapping) 238{ 239 return mapping->host && IS_DAX(mapping->host); 240} 241 242#endif