aboutsummaryrefslogtreecommitdiff
path: root/sys/cam/ctl
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2020-05-28 18:12:05 +0000
committerAlexander Motin <mav@FreeBSD.org>2020-05-28 18:12:05 +0000
commit0d7fed74c739e02be1e09489c26f0eb30bf60f6f (patch)
tree93d4609c0e83945782400d4927c4f391136cd9c9 /sys/cam/ctl
parentdde3b16bbcd41ca7432e8c8eaa908ec8a70aa251 (diff)
downloadsrc-0d7fed74c739e02be1e09489c26f0eb30bf60f6f.tar.gz
src-0d7fed74c739e02be1e09489c26f0eb30bf60f6f.zip
Remove ctl_free_beio() LUN and ctl_io dependencies.
This slightly simplifies the code, plus may be a ground for asynchronous buffer free. MFC after: 2 weeks Sponsored by: iXsystems, Inc.
Notes
Notes: svn path=/head/; revision=361590
Diffstat (limited to 'sys/cam/ctl')
-rw-r--r--sys/cam/ctl/ctl_backend_block.c57
1 files changed, 21 insertions, 36 deletions
diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c
index 4a2feb712443..19a62f4cf3af 100644
--- a/sys/cam/ctl/ctl_backend_block.c
+++ b/sys/cam/ctl/ctl_backend_block.c
@@ -162,7 +162,6 @@ struct ctl_be_block_lun {
cbb_dispatch_t unmap;
cbb_dispatch_t get_lba_status;
cbb_getattr_t getattr;
- uma_zone_t lun_zone;
uint64_t size_blocks;
uint64_t size_bytes;
struct ctl_be_block_softc *softc;
@@ -187,9 +186,10 @@ struct ctl_be_block_lun {
struct ctl_be_block_softc {
struct sx modify_lock;
struct mtx lock;
- uma_zone_t beio_zone;
int num_luns;
SLIST_HEAD(, ctl_be_block_lun) lun_list;
+ uma_zone_t beio_zone;
+ uma_zone_t buf_zone;
};
static struct ctl_be_block_softc backend_block_softc;
@@ -202,6 +202,7 @@ struct ctl_be_block_io {
struct ctl_sg_entry sg_segs[CTLBLK_MAX_SEGS];
struct iovec xiovecs[CTLBLK_MAX_SEGS];
int bio_cmd;
+ int two_sglists;
int num_segs;
int num_bios_sent;
int num_bios_done;
@@ -310,32 +311,20 @@ ctl_alloc_beio(struct ctl_be_block_softc *softc)
static void
ctl_free_beio(struct ctl_be_block_io *beio)
{
- int duplicate_free;
+ struct ctl_be_block_softc *softc = beio->softc;
int i;
- duplicate_free = 0;
-
for (i = 0; i < beio->num_segs; i++) {
- if (beio->sg_segs[i].addr == NULL)
- duplicate_free++;
-
- uma_zfree(beio->lun->lun_zone, beio->sg_segs[i].addr);
- beio->sg_segs[i].addr = NULL;
+ uma_zfree(softc->buf_zone, beio->sg_segs[i].addr);
/* For compare we had two equal S/G lists. */
- if (ARGS(beio->io)->flags & CTL_LLF_COMPARE) {
- uma_zfree(beio->lun->lun_zone,
+ if (beio->two_sglists) {
+ uma_zfree(softc->buf_zone,
beio->sg_segs[i + CTLBLK_HALF_SEGS].addr);
- beio->sg_segs[i + CTLBLK_HALF_SEGS].addr = NULL;
}
}
- if (duplicate_free > 0) {
- printf("%s: %d duplicate frees out of %d segments\n", __func__,
- duplicate_free, beio->num_segs);
- }
-
- uma_zfree(beio->softc->beio_zone, beio);
+ uma_zfree(softc->beio_zone, beio);
}
static void
@@ -1260,6 +1249,7 @@ static void
ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun,
union ctl_io *io)
{
+ struct ctl_be_block_softc *softc = be_lun->softc;
struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun;
struct ctl_be_block_io *beio;
struct ctl_lba_len_flags *lbalen;
@@ -1324,7 +1314,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *be_lun,
} else
seglen -= seglen % cbe_lun->blocksize;
beio->sg_segs[i].len = seglen;
- beio->sg_segs[i].addr = uma_zalloc(be_lun->lun_zone, M_WAITOK);
+ beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK);
DPRINTF("segment %d addr %p len %zd\n", i,
beio->sg_segs[i].addr, beio->sg_segs[i].len);
@@ -1578,10 +1568,12 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
DPRINTF("%s at LBA %jx len %u @%ju\n",
(beio->bio_cmd == BIO_READ) ? "READ" : "WRITE",
(uintmax_t)lbalen->lba, lbalen->len, bptrlen->len);
- if (lbalen->flags & CTL_LLF_COMPARE)
+ if (lbalen->flags & CTL_LLF_COMPARE) {
+ beio->two_sglists = 1;
lbas = CTLBLK_HALF_IO_SIZE;
- else
+ } else {
lbas = CTLBLK_MAX_IO_SIZE;
+ }
lbas = MIN(lbalen->len - bptrlen->len, lbas / cbe_lun->blocksize);
beio->io_offset = (lbalen->lba + bptrlen->len) * cbe_lun->blocksize;
beio->io_len = lbas * cbe_lun->blocksize;
@@ -1595,17 +1587,17 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
* Setup the S/G entry for this chunk.
*/
beio->sg_segs[i].len = min(CTLBLK_MAX_SEG, len_left);
- beio->sg_segs[i].addr = uma_zalloc(be_lun->lun_zone, M_WAITOK);
+ beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK);
DPRINTF("segment %d addr %p len %zd\n", i,
beio->sg_segs[i].addr, beio->sg_segs[i].len);
/* Set up second segment for compare operation. */
- if (lbalen->flags & CTL_LLF_COMPARE) {
+ if (beio->two_sglists) {
beio->sg_segs[i + CTLBLK_HALF_SEGS].len =
beio->sg_segs[i].len;
beio->sg_segs[i + CTLBLK_HALF_SEGS].addr =
- uma_zalloc(be_lun->lun_zone, M_WAITOK);
+ uma_zalloc(softc->buf_zone, M_WAITOK);
}
beio->num_segs++;
@@ -1615,7 +1607,7 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
beio->beio_cont = ctl_be_block_next;
io->scsiio.be_move_done = ctl_be_block_move_done;
/* For compare we have separate S/G lists for read and datamove. */
- if (lbalen->flags & CTL_LLF_COMPARE)
+ if (beio->two_sglists)
io->scsiio.kern_data_ptr = (uint8_t *)&beio->sg_segs[CTLBLK_HALF_SEGS];
else
io->scsiio.kern_data_ptr = (uint8_t *)beio->sg_segs;
@@ -2228,13 +2220,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req)
mtx_init(&be_lun->io_lock, "ctlblock io", NULL, MTX_DEF);
mtx_init(&be_lun->queue_lock, "ctlblock queue", NULL, MTX_DEF);
cbe_lun->options = nvlist_clone(req->args_nvl);
- be_lun->lun_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG,
- NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0);
- if (be_lun->lun_zone == NULL) {
- snprintf(req->error_str, sizeof(req->error_str),
- "error allocating UMA zone");
- goto bailout_error;
- }
if (params->flags & CTL_LUN_FLAG_DEV_TYPE)
cbe_lun->lun_type = params->device_type;
@@ -2404,8 +2389,6 @@ bailout_error:
ctl_be_block_close(be_lun);
if (be_lun->dev_path != NULL)
free(be_lun->dev_path, M_CTLBLK);
- if (be_lun->lun_zone != NULL)
- uma_zdestroy(be_lun->lun_zone);
nvlist_destroy(cbe_lun->options);
mtx_destroy(&be_lun->queue_lock);
mtx_destroy(&be_lun->io_lock);
@@ -2600,7 +2583,6 @@ ctl_be_block_lun_shutdown(void *lun)
taskqueue_free(be_lun->io_taskqueue);
if (be_lun->disk_stats != NULL)
devstat_remove_entry(be_lun->disk_stats);
- uma_zdestroy(be_lun->lun_zone);
nvlist_destroy(be_lun->cbe_lun.options);
free(be_lun->dev_path, M_CTLBLK);
mtx_destroy(&be_lun->queue_lock);
@@ -2782,6 +2764,8 @@ ctl_be_block_init(void)
mtx_init(&softc->lock, "ctlblock", NULL, MTX_DEF);
softc->beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
+ softc->buf_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG,
+ NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0);
SLIST_INIT(&softc->lun_list);
return (0);
}
@@ -2807,6 +2791,7 @@ ctl_be_block_shutdown(void)
mtx_lock(&softc->lock);
}
mtx_unlock(&softc->lock);
+ uma_zdestroy(softc->buf_zone);
uma_zdestroy(softc->beio_zone);
mtx_destroy(&softc->lock);
sx_destroy(&softc->modify_lock);