Author: mav
Date: Thu May 28 18:12:05 2020
New Revision: 361590
URL: https://svnweb.freebsd.org/changeset/base/361590

Log:
  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.

Modified:
  head/sys/cam/ctl/ctl_backend_block.c

Modified: head/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend_block.c        Thu May 28 17:08:39 2020        
(r361589)
+++ head/sys/cam/ctl/ctl_backend_block.c        Thu May 28 18:12:05 2020        
(r361590)
@@ -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(softc->buf_zone, beio->sg_segs[i].addr);
 
-               uma_zfree(beio->lun->lun_zone, beio->sg_segs[i].addr);
-               beio->sg_segs[i].addr = NULL;
-
                /* 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 *b
                } 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, 
        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);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to