Skip to content

Commit

Permalink
iomap: add a IOMAP_DIO_OVERWRITE_ONLY flag
Browse files Browse the repository at this point in the history
Add a flag to signal that only pure overwrites are allowed.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Dave Chinner <[email protected]>
Reviewed-by: Brian Foster <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Signed-off-by: Darrick J. Wong <[email protected]>
  • Loading branch information
Christoph Hellwig authored and Darrick J. Wong committed Jan 23, 2021
1 parent 2f63296 commit 213f627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fs/iomap/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
iomap_flags |= IOMAP_NOWAIT;
}

if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
ret = -EAGAIN;
if (pos >= dio->i_size || pos + count > dio->i_size)
goto out_free_dio;
iomap_flags |= IOMAP_OVERWRITE_ONLY;
}

ret = filemap_write_and_wait_range(mapping, pos, end);
if (ret)
goto out_free_dio;
Expand Down
8 changes: 8 additions & 0 deletions include/linux/iomap.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct iomap_page_ops {
#define IOMAP_FAULT (1 << 3) /* mapping for page fault */
#define IOMAP_DIRECT (1 << 4) /* direct I/O */
#define IOMAP_NOWAIT (1 << 5) /* do not block */
#define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */

struct iomap_ops {
/*
Expand Down Expand Up @@ -262,6 +263,13 @@ struct iomap_dio_ops {
*/
#define IOMAP_DIO_FORCE_WAIT (1 << 0)

/*
* Do not allocate blocks or zero partial blocks, but instead fall back to
* the caller by returning -EAGAIN. Used to optimize direct I/O writes that
* are not aligned to the file system block size.
*/
#define IOMAP_DIO_OVERWRITE_ONLY (1 << 1)

ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
unsigned int dio_flags);
Expand Down

0 comments on commit 213f627

Please sign in to comment.