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