linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew.r.wilcox@intel.com>
To: linux-fsdevel@vger.kernel.org, linux-mm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Matthew Wilcox <matthew.r.wilcox@intel.com>
Subject: [PATCH 5/6] virtio_blk: Add rw_page implementation
Date: Thu,  9 Jan 2014 21:39:50 -0500	[thread overview]
Message-ID: <1389321591-25455-5-git-send-email-matthew.r.wilcox@intel.com> (raw)
In-Reply-To: <1389321591-25455-1-git-send-email-matthew.r.wilcox@intel.com>
In-Reply-To: <cover.1387748522.git.matthew.r.wilcox@intel.com>

This is an implementation of the new rw_page interface.  It primarily
demonstrates a low-impact, low-reward method for adding support to a
driver.  I don't expect it to improve performance; in fact I expect it
to worsen performance slightly since there are still memory allocations
in the I/O path.

Please don't apply this patch.

Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
---
 drivers/block/virtio_blk.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6a680d4..4c1c9ad 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -110,11 +110,22 @@ static int __virtblk_add_req(struct virtqueue *vq,
 	return virtqueue_add_sgs(vq, sgs, num_out, num_in, vbr, GFP_ATOMIC);
 }
 
+#define rw_to_dmad(rw)	(((rw) == WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)
+
 static inline void virtblk_request_done(struct virtblk_req *vbr)
 {
 	struct request *req = vbr->req;
 	int error = virtblk_result(vbr);
 
+	if ((unsigned long)req & 1) {
+		struct virtio_blk *vblk = (void *)((unsigned long)req & ~1UL);
+		int rw = (vbr->out_hdr.type & VIRTIO_BLK_T_OUT) ? WRITE : READ;
+		struct page *page = sg_page(vbr->sg);
+		dma_unmap_sg(&vblk->vdev->dev, vbr->sg, 1, rw_to_dmad(rw));
+		page_endio(page, rw, error);
+		return;
+	}
+
 	if (req->cmd_type == REQ_TYPE_BLOCK_PC) {
 		req->resid_len = vbr->in_hdr.residual;
 		req->sense_len = vbr->in_hdr.sense_len;
@@ -239,6 +250,38 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
 	return err;
 }
 
+static int virtblk_rw_page(struct block_device *bdev, sector_t sector,
+				struct page *page, int rw)
+{
+	unsigned long flags;
+	struct virtio_blk *vblk = bdev->bd_disk->private_data;
+	struct virtblk_req *vbr;
+	int err;
+
+	vbr = kmalloc(sizeof(*vbr) + sizeof(struct scatterlist), GFP_NOFS);
+	if (!vbr)
+		return -ENOMEM;
+
+	vbr->req = (void *)((unsigned long)vblk | 1);
+	vbr->out_hdr.type = (rw == WRITE) ? VIRTIO_BLK_T_OUT : VIRTIO_BLK_T_IN;
+	vbr->out_hdr.sector = sector;
+	vbr->out_hdr.ioprio = 0;
+
+	sg_init_table(vbr->sg, 1);
+	sg_set_page(vbr->sg, page, PAGE_CACHE_SIZE, 0);
+	sg_mark_end(vbr->sg);
+	if (dma_map_sg(&vblk->vdev->dev, vbr->sg, 1, rw_to_dmad(rw))) {
+		kfree(vbr);
+		return -ENOMEM;
+	}
+
+	spin_lock_irqsave(&vblk->vq_lock, flags);
+	err = __virtblk_add_req(vblk->vq, vbr, vbr->sg, 1);
+	virtqueue_kick(vblk->vq);
+	spin_unlock_irqrestore(&vblk->vq_lock, flags);
+	return err;
+}
+
 static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
 			     unsigned int cmd, unsigned long data)
 {
@@ -278,6 +321,7 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
 }
 
 static const struct block_device_operations virtblk_fops = {
+	.rw_page = virtblk_rw_page,
 	.ioctl  = virtblk_ioctl,
 	.owner  = THIS_MODULE,
 	.getgeo = virtblk_getgeo,
-- 
1.8.5.2


  parent reply	other threads:[~2014-01-10  2:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10  2:39 [PATCH 0/6] Page I/O Matthew Wilcox
2014-01-10  2:39 ` [PATCH 1/6] Add bdev_read_page() and bdev_write_page() Matthew Wilcox
2014-01-10  2:39   ` [PATCH 2/6] Factor page_endio() out of mpage_end_io() Matthew Wilcox
2014-01-10  2:39   ` [PATCH 3/6] swap: Use bdev_read_page() / bdev_write_page() Matthew Wilcox
2014-01-10  2:39   ` [PATCH 4/6] brd: Add support for rw_page Matthew Wilcox
2014-01-10  2:39   ` Matthew Wilcox [this message]
2014-01-10  2:39   ` [PATCH 6/6] NVMe: " Matthew Wilcox
2014-01-10 15:24 ` [PATCH 0/6] Page I/O Jeff Moyer
2014-01-10 16:17   ` Matthew Wilcox
2014-01-15  0:04   ` Dave Chinner

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=1389321591-25455-5-git-send-email-matthew.r.wilcox@intel.com \
    --to=matthew.r.wilcox@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@vger.kernel.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).