]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - include/linux/iomap.h
Merge tag 'f2fs-for-5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
[linux.git] / include / linux / iomap.h
index 7aa5d61179361d3bbdd3e949645568160d25ae15..8b09463dae0dba2a4a60ce2372863ba0e8fd16b9 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <linux/atomic.h>
 #include <linux/bitmap.h>
+#include <linux/blk_types.h>
 #include <linux/mm.h>
 #include <linux/types.h>
 #include <linux/mm_types.h>
@@ -12,6 +13,7 @@
 struct address_space;
 struct fiemap_extent_info;
 struct inode;
+struct iomap_writepage_ctx;
 struct iov_iter;
 struct kiocb;
 struct page;
@@ -21,28 +23,45 @@ struct vm_fault;
 /*
  * Types of block ranges for iomap mappings:
  */
-#define IOMAP_HOLE     0x01    /* no blocks allocated, need allocation */
-#define IOMAP_DELALLOC 0x02    /* delayed allocation blocks */
-#define IOMAP_MAPPED   0x03    /* blocks allocated at @addr */
-#define IOMAP_UNWRITTEN        0x04    /* blocks allocated at @addr in unwritten state */
-#define IOMAP_INLINE   0x05    /* data inline in the inode */
+#define IOMAP_HOLE     0       /* no blocks allocated, need allocation */
+#define IOMAP_DELALLOC 1       /* delayed allocation blocks */
+#define IOMAP_MAPPED   2       /* blocks allocated at @addr */
+#define IOMAP_UNWRITTEN        3       /* blocks allocated at @addr in unwritten state */
+#define IOMAP_INLINE   4       /* data inline in the inode */
 
 /*
- * Flags for all iomap mappings:
+ * Flags reported by the file system from iomap_begin:
+ *
+ * IOMAP_F_NEW indicates that the blocks have been newly allocated and need
+ * zeroing for areas that no data is copied to.
  *
  * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access
  * written data and requires fdatasync to commit them to persistent storage.
+ * This needs to take into account metadata changes that *may* be made at IO
+ * completion, such as file size updates from direct IO.
+ *
+ * IOMAP_F_SHARED indicates that the blocks are shared, and will need to be
+ * unshared as part a write.
+ *
+ * IOMAP_F_MERGED indicates that the iomap contains the merge of multiple block
+ * mappings.
+ *
+ * IOMAP_F_BUFFER_HEAD indicates that the file system requires the use of
+ * buffer heads for this mapping.
  */
-#define IOMAP_F_NEW            0x01    /* blocks have been newly allocated */
-#define IOMAP_F_DIRTY          0x02    /* uncommitted metadata */
-#define IOMAP_F_BUFFER_HEAD    0x04    /* file system requires buffer heads */
-#define IOMAP_F_SIZE_CHANGED   0x08    /* file size has changed */
+#define IOMAP_F_NEW            0x01
+#define IOMAP_F_DIRTY          0x02
+#define IOMAP_F_SHARED         0x04
+#define IOMAP_F_MERGED         0x08
+#define IOMAP_F_BUFFER_HEAD    0x10
 
 /*
- * Flags that only need to be reported for IOMAP_REPORT requests:
+ * Flags set by the core iomap code during operations:
+ *
+ * IOMAP_F_SIZE_CHANGED indicates to the iomap_end method that the file size
+ * has changed as the result of this write operation.
  */
-#define IOMAP_F_MERGED         0x10    /* contains multiple blocks/extents */
-#define IOMAP_F_SHARED         0x20    /* block shared with another file */
+#define IOMAP_F_SIZE_CHANGED   0x100
 
 /*
  * Flags from 0x1000 up are for file system specific usage:
@@ -110,7 +129,8 @@ struct iomap_ops {
         * The actual length is returned in iomap->length.
         */
        int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length,
-                       unsigned flags, struct iomap *iomap);
+                       unsigned flags, struct iomap *iomap,
+                       struct iomap *srcmap);
 
        /*
         * Commit and/or unreserve space previous allocated using iomap_begin.
@@ -126,29 +146,12 @@ struct iomap_ops {
  * Main iomap iterator function.
  */
 typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len,
-               void *data, struct iomap *iomap);
+               void *data, struct iomap *iomap, struct iomap *srcmap);
 
 loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length,
                unsigned flags, const struct iomap_ops *ops, void *data,
                iomap_actor_t actor);
 
-/*
- * Structure allocate for each page when block size < PAGE_SIZE to track
- * sub-page uptodate status and I/O completions.
- */
-struct iomap_page {
-       atomic_t                read_count;
-       atomic_t                write_count;
-       DECLARE_BITMAP(uptodate, PAGE_SIZE / 512);
-};
-
-static inline struct iomap_page *to_iomap_page(struct page *page)
-{
-       if (page_has_private(page))
-               return (struct iomap_page *)page_private(page);
-       return NULL;
-}
-
 ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
                const struct iomap_ops *ops);
 int iomap_readpage(struct page *page, const struct iomap_ops *ops);
@@ -166,7 +169,7 @@ int iomap_migrate_page(struct address_space *mapping, struct page *newpage,
 #else
 #define iomap_migrate_page NULL
 #endif
-int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
+int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
                const struct iomap_ops *ops);
 int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
                bool *did_zero, const struct iomap_ops *ops);
@@ -183,6 +186,63 @@ loff_t iomap_seek_data(struct inode *inode, loff_t offset,
 sector_t iomap_bmap(struct address_space *mapping, sector_t bno,
                const struct iomap_ops *ops);
 
+/*
+ * Structure for writeback I/O completions.
+ */
+struct iomap_ioend {
+       struct list_head        io_list;        /* next ioend in chain */
+       u16                     io_type;
+       u16                     io_flags;       /* IOMAP_F_* */
+       struct inode            *io_inode;      /* file being written to */
+       size_t                  io_size;        /* size of the extent */
+       loff_t                  io_offset;      /* offset in the file */
+       void                    *io_private;    /* file system private data */
+       struct bio              *io_bio;        /* bio being built */
+       struct bio              io_inline_bio;  /* MUST BE LAST! */
+};
+
+struct iomap_writeback_ops {
+       /*
+        * Required, maps the blocks so that writeback can be performed on
+        * the range starting at offset.
+        */
+       int (*map_blocks)(struct iomap_writepage_ctx *wpc, struct inode *inode,
+                               loff_t offset);
+
+       /*
+        * Optional, allows the file systems to perform actions just before
+        * submitting the bio and/or override the bio end_io handler for complex
+        * operations like copy on write extent manipulation or unwritten extent
+        * conversions.
+        */
+       int (*prepare_ioend)(struct iomap_ioend *ioend, int status);
+
+       /*
+        * Optional, allows the file system to discard state on a page where
+        * we failed to submit any I/O.
+        */
+       void (*discard_page)(struct page *page);
+};
+
+struct iomap_writepage_ctx {
+       struct iomap            iomap;
+       struct iomap_ioend      *ioend;
+       const struct iomap_writeback_ops *ops;
+};
+
+void iomap_finish_ioends(struct iomap_ioend *ioend, int error);
+void iomap_ioend_try_merge(struct iomap_ioend *ioend,
+               struct list_head *more_ioends,
+               void (*merge_private)(struct iomap_ioend *ioend,
+                               struct iomap_ioend *next));
+void iomap_sort_ioends(struct list_head *ioend_list);
+int iomap_writepage(struct page *page, struct writeback_control *wbc,
+               struct iomap_writepage_ctx *wpc,
+               const struct iomap_writeback_ops *ops);
+int iomap_writepages(struct address_space *mapping,
+               struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
+               const struct iomap_writeback_ops *ops);
+
 /*
  * Flags for direct I/O ->end_io:
  */
@@ -195,7 +255,8 @@ struct iomap_dio_ops {
 };
 
 ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
-               const struct iomap_ops *ops, const struct iomap_dio_ops *dops);
+               const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
+               bool wait_for_completion);
 int iomap_dio_iopoll(struct kiocb *kiocb, bool spin);
 
 #ifdef CONFIG_SWAP