Skip to content

Commit

Permalink
block: make __blkdev_direct_IO_sync() support O_SYNC/DSYNC
Browse files Browse the repository at this point in the history
Split the op setting code into a helper, use it in both places.

Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Jens Axboe committed Nov 17, 2016
1 parent 72ecad2 commit 78250c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ static struct inode *bdev_file_inode(struct file *file)
return file->f_mapping->host;
}

static unsigned int dio_bio_write_op(struct kiocb *iocb)
{
unsigned int op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE;

/* avoid the need for a I/O completion work item */
if (iocb->ki_flags & IOCB_DSYNC)
op |= REQ_FUA;
return op;
}

#define DIO_INLINE_BIO_VECS 4

static void blkdev_bio_end_io_simple(struct bio *bio)
Expand Down Expand Up @@ -226,11 +236,11 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,
ret = bio.bi_iter.bi_size;

if (iov_iter_rw(iter) == READ) {
bio_set_op_attrs(&bio, REQ_OP_READ, 0);
bio.bi_opf = REQ_OP_READ;
if (iter_is_iovec(iter))
should_dirty = true;
} else {
bio_set_op_attrs(&bio, REQ_OP_WRITE, REQ_SYNC | REQ_IDLE);
bio.bi_opf = dio_bio_write_op(iocb);
task_io_account_write(ret);
}

Expand Down

0 comments on commit 78250c0

Please sign in to comment.