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 <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/422603 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
1570c87f81
commit
6fd1d004a8
25
lib/bdev/passthru/vbdev_passthru.c
Normal file → Executable file
25
lib/bdev/passthru/vbdev_passthru.c
Normal file → Executable file
@ -151,6 +151,23 @@ _pt_complete_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
|
|||||||
spdk_bdev_free_io(bdev_io);
|
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
|
/* 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
|
* 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 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 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;
|
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
|
/* 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
|
* 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) {
|
switch (bdev_io->type) {
|
||||||
case SPDK_BDEV_IO_TYPE_READ:
|
case SPDK_BDEV_IO_TYPE_READ:
|
||||||
rc = spdk_bdev_readv_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,
|
spdk_bdev_io_get_buf(bdev_io, pt_read_get_buf_cb,
|
||||||
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks,
|
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen);
|
||||||
bdev_io->u.bdev.num_blocks, _pt_complete_io,
|
|
||||||
bdev_io);
|
|
||||||
break;
|
break;
|
||||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||||
rc = spdk_bdev_writev_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,
|
rc = spdk_bdev_writev_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,
|
||||||
|
Loading…
Reference in New Issue
Block a user