linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Kent Overstreet <kmo@daterainc.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Dave Kleikamp <dave.kleikamp@oracle.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"Maxim V. Patlasov" <mpatlasov@parallels.com>,
	linux-aio@kvack.org, Jens Axboe <axboe@kernel.dk>
Subject: Re: [GIT PULL] direct IO support for loop driver
Date: Thu, 21 Nov 2013 09:34:32 -0800	[thread overview]
Message-ID: <20131121173432.GA11984@infradead.org> (raw)
In-Reply-To: <20131121100609.GB17871@kmo-pixel>

find the target one below.  I haven't found the ecryptfs work, but it
is a lot more involved as it only wants to use direct I/O, not aio.

--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -31,6 +31,7 @@
 #include <linux/spinlock.h>
 #include <linux/module.h>
 #include <linux/falloc.h>
+#include <linux/blk_types.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_host.h>
 #include <asm/unaligned.h>
@@ -120,6 +121,8 @@ static int fd_configure_device(struct se_device *dev)
 	 * of pure timestamp updates.
 	 */
 	flags = O_RDWR | O_CREAT | O_LARGEFILE | O_DSYNC;
+	if (1)
+		flags |= O_DIRECT;
 
 	/*
 	 * Optionally allow fd_buffered_io=1 to be enabled for people
@@ -546,6 +549,61 @@ fd_execute_unmap(struct se_cmd *cmd)
 	return sbc_execute_unmap(cmd, fd_do_unmap, file);
 }
 
+static void fd_rw_aio_complete(u64 data, long res)
+{
+	struct se_cmd *cmd = (struct se_cmd *)(uintptr_t)data;
+
+	kfree(cmd->priv);
+
+	if (res < 0)
+		target_complete_cmd(cmd, SAM_STAT_CHECK_CONDITION);
+	else
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
+}
+
+static sense_reason_t
+fd_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
+	      enum dma_data_direction data_direction)
+{
+	struct se_device *se_dev = cmd->se_dev;
+	struct fd_dev *dev = FD_DEV(se_dev);
+	struct file *file = dev->fd_file;
+	struct scatterlist *sg;
+	struct kiocb *iocb;
+	unsigned int op;
+	struct iov_iter iter;
+	struct bio_vec *bvec;
+	loff_t pos = (cmd->t_task_lba * se_dev->dev_attrib.block_size);
+	int i;
+
+	iocb = aio_kernel_alloc(GFP_NOIO);
+	if (!iocb)
+		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+	
+	if (data_direction == DMA_TO_DEVICE)
+		op = IOCB_CMD_WRITE_ITER;
+	else
+		op = IOCB_CMD_READ_ITER;
+
+	bvec = cmd->priv = kcalloc(sgl_nents, sizeof(struct bio_vec), GFP_NOIO);
+	if (!bvec) {
+		aio_kernel_free(iocb);
+		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+	}
+
+	for_each_sg(sgl, sg, sgl_nents, i) {
+		bvec[i].bv_page = sg_page(sg);
+		bvec[i].bv_len = sg->length;
+		bvec[i].bv_offset = sg->offset;
+	}
+
+	iov_iter_init_bvec(&iter, bvec, sgl_nents, bvec_length(bvec, sgl_nents), 0);
+	aio_kernel_init_rw(iocb, file, iov_iter_count(&iter), pos);
+	aio_kernel_init_callback(iocb, fd_rw_aio_complete, (u64)(uintptr_t)bvec);
+
+	return aio_kernel_submit(iocb, op, &iter);
+}
+
 static sense_reason_t
 fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 	      enum dma_data_direction data_direction)
@@ -553,6 +611,9 @@ fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 	struct se_device *dev = cmd->se_dev;
 	int ret = 0;
 
+	if (1)
+		return fd_rw_aio(cmd, sgl, sgl_nents, data_direction);
+
 	/*
 	 * Call vectorized fileio functions to map struct scatterlist
 	 * physical memory addresses to struct iovec virtual memory.

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org.  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

      parent reply	other threads:[~2013-11-21 17:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-18 19:03 [GIT PULL] direct IO support for loop driver Dave Kleikamp
2013-11-18 19:07 ` Dave Kleikamp
2013-11-20 21:19 ` Linus Torvalds
2013-11-20 21:38   ` Linus Torvalds
2013-11-20 21:50     ` Kent Overstreet
2013-11-20 22:46     ` Dave Kleikamp
2013-11-21  4:24       ` Stephen Rothwell
2013-11-21  9:58   ` Christoph Hellwig
2013-11-21 10:06     ` Kent Overstreet
2013-11-21 10:11       ` Christoph Hellwig
2013-11-21 10:13         ` Kent Overstreet
2013-11-21 17:34       ` Christoph Hellwig [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131121173432.GA11984@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=dave.kleikamp@oracle.com \
    --cc=kmo@daterainc.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatlasov@parallels.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).