From 6fd1d004a8b0aa51047a359ec464919892854049 Mon Sep 17 00:00:00 2001 From: paul luse Date: Thu, 16 Aug 2018 13:10:49 -0700 Subject: [PATCH] vbdev: add get_buf call to passthru example Previously a null buffer on read would get passed on which would be fine for a simple example but for something more complex where the module in question might need that buffer at some time after the read callback, it's possible that an underlying module might free it too soon. So, to be a good example we now own the buffer in this module. Change-Id: I411477e83b1e222c64011688952cfd587c32c16e Signed-off-by: paul luse Reviewed-on: https://review.gerrithub.io/422603 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/bdev/passthru/vbdev_passthru.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) mode change 100644 => 100755 lib/bdev/passthru/vbdev_passthru.c diff --git a/lib/bdev/passthru/vbdev_passthru.c b/lib/bdev/passthru/vbdev_passthru.c old mode 100644 new mode 100755 index 0723306cb..23339979e --- a/lib/bdev/passthru/vbdev_passthru.c +++ b/lib/bdev/passthru/vbdev_passthru.c @@ -151,6 +151,23 @@ _pt_complete_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) spdk_bdev_free_io(bdev_io); } +/* Callback for getting a buf from the bdev pool in the event that the caller passed + * in NULL, we need to own the buffer so it doesn't get freed by another vbdev module + * beneath us before we're done with it. That won't happen in this example but it could + * if this example were used as a template for something more complex. + */ +static void +pt_read_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io) +{ + struct vbdev_passthru *pt_node = SPDK_CONTAINEROF(bdev_io->bdev, struct vbdev_passthru, + pt_bdev); + struct pt_io_channel *pt_ch = spdk_io_channel_get_ctx(ch); + + spdk_bdev_readv_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs, + bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks, + bdev_io->u.bdev.num_blocks, _pt_complete_io, + bdev_io); +} /* Called when someone above submits IO to this pt vbdev. We're simply passing it on here * via SPDK IO calls which in turn allocate another bdev IO and call our cpl callback provided @@ -162,7 +179,7 @@ vbdev_passthru_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *b struct vbdev_passthru *pt_node = SPDK_CONTAINEROF(bdev_io->bdev, struct vbdev_passthru, pt_bdev); struct pt_io_channel *pt_ch = spdk_io_channel_get_ctx(ch); struct passthru_bdev_io *io_ctx = (struct passthru_bdev_io *)bdev_io->driver_ctx; - int rc = 1; + int rc = 0; /* Setup a per IO context value; we don't do anything with it in the vbdev other * than confirm we get the same thing back in the completion callback just to @@ -172,10 +189,8 @@ vbdev_passthru_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *b switch (bdev_io->type) { case SPDK_BDEV_IO_TYPE_READ: - rc = spdk_bdev_readv_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs, - bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks, - bdev_io->u.bdev.num_blocks, _pt_complete_io, - bdev_io); + spdk_bdev_io_get_buf(bdev_io, pt_read_get_buf_cb, + bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen); break; case SPDK_BDEV_IO_TYPE_WRITE: rc = spdk_bdev_writev_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,