On Thu, Jul 30, 2015 at 07:36:24AM -0400, Ming Lei wrote:
> + /*
> + * When working at direct I/O, under very unusual cases,
> + * such as unaligned direct I/O from application and
> + * access to loop block device with 'unaligned' offset & size,
> + * we have to fallback to non-dio mode.
> + *
> + * During the switch between dio and non-dio, page cache
> + * has to be flushed to the backing file.
> + */
> + if (unlikely(lo->use_dio && lo->last_use_dio != cmd->use_aio))
> + vfs_fsync(lo->lo_backing_file, 0);
Filesystems do the cache flushing for you.
> +static inline bool req_dio_aligned(struct loop_device *lo,
> + const struct request *rq)
> +{
> + return !((blk_rq_pos(rq) << 9) & lo->dio_align) &&
> + !(blk_rq_bytes(rq) & lo->dio_align);
> +}
> +
> static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
> const struct blk_mq_queue_data *bd)
> {
> @@ -1554,6 +1658,13 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
> if (lo->lo_state != Lo_bound)
> return -EIO;
>
> + if (lo->use_dio && !lo->transfer &&
> + req_dio_aligned(lo, bd->rq) &&
> + !(cmd->rq->cmd_flags & (REQ_FLUSH | REQ_DISCARD)))
> + cmd->use_aio = true;
> + else
> + cmd->use_aio = false;
But honestly run time switching between buffered I/O and direct I/O from
the same I/O stream is almost asking for triggering every possible
race in the dio vs buffered I/O synchronization. And there have been
a lot of those..
I'd feel much more comfortable with a setup time check.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/