Author: cperciva
Date: Sat Jun 20 00:02:03 2015
New Revision: 284618
URL: https://svnweb.freebsd.org/changeset/base/284618

Log:
  Refactor xbd_queue_cb, extracting the code which converts bus_dma segments
  into blkif segments, and moving it into a new function.  This will be used
  by upcoming support for indirect-segment blkif requests.
  
  This commit should not result in any functional changes.

Modified:
  head/sys/dev/xen/blkfront/blkfront.c

Modified: head/sys/dev/xen/blkfront/blkfront.c
==============================================================================
--- head/sys/dev/xen/blkfront/blkfront.c        Fri Jun 19 23:03:05 2015        
(r284617)
+++ head/sys/dev/xen/blkfront/blkfront.c        Sat Jun 20 00:02:03 2015        
(r284618)
@@ -156,45 +156,14 @@ xbd_free_command(struct xbd_command *cm)
 }
 
 static void
-xbd_queue_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
+mksegarray(bus_dma_segment_t *segs, int nsegs,
+    grant_ref_t * gref_head, int otherend_id, int readonly,
+    grant_ref_t * sg_ref, blkif_request_segment_t * sg)
 {
-       struct xbd_softc *sc;
-       struct xbd_command *cm;
-       blkif_request_t *ring_req;
-       struct blkif_request_segment *sg;
-       struct blkif_request_segment *last_block_sg;
-       grant_ref_t *sg_ref;
+       struct blkif_request_segment *last_block_sg = sg + nsegs;
        vm_paddr_t buffer_ma;
        uint64_t fsect, lsect;
        int ref;
-       int op;
-
-       cm = arg;
-       sc = cm->cm_sc;
-
-       if (error) {
-               cm->cm_bp->bio_error = EIO;
-               biodone(cm->cm_bp);
-               xbd_free_command(cm);
-               return;
-       }
-
-       KASSERT(nsegs <= BLKIF_MAX_SEGMENTS_PER_REQUEST,
-           ("Too many segments in a blkfront I/O"));
-
-       /* Fill out a communications ring structure. */
-       ring_req = RING_GET_REQUEST(&sc->xbd_ring, sc->xbd_ring.req_prod_pvt);
-       sc->xbd_ring.req_prod_pvt++;
-       ring_req->id = cm->cm_id;
-       ring_req->operation = cm->cm_operation;
-       ring_req->sector_number = cm->cm_sector_number;
-       ring_req->handle = (blkif_vdev_t)(uintptr_t)sc->xbd_disk;
-       ring_req->nr_segments = nsegs;
-       cm->cm_nseg = nsegs;
-
-       sg            = ring_req->seg;
-       last_block_sg = sg + nsegs;
-       sg_ref        = cm->cm_sg_refs;
 
        while (sg < last_block_sg) {
                buffer_ma = segs->ds_addr;
@@ -205,7 +174,7 @@ xbd_queue_cb(void *arg, bus_dma_segment_
                    "cross a page boundary"));
 
                /* install a grant reference. */
-               ref = gnttab_claim_grant_reference(&cm->cm_gref_head);
+               ref = gnttab_claim_grant_reference(gref_head);
 
                /*
                 * GNTTAB_LIST_END == 0xffffffff, but it is private
@@ -215,9 +184,9 @@ xbd_queue_cb(void *arg, bus_dma_segment_
 
                gnttab_grant_foreign_access_ref(
                    ref,
-                   xenbus_get_otherend_id(sc->xbd_dev),
+                   otherend_id,
                    buffer_ma >> PAGE_SHIFT,
-                   ring_req->operation == BLKIF_OP_WRITE);
+                   readonly);
 
                *sg_ref = ref;
                *sg = (struct blkif_request_segment) {
@@ -229,6 +198,42 @@ xbd_queue_cb(void *arg, bus_dma_segment_
                sg_ref++;
                segs++;
        }
+}
+
+static void
+xbd_queue_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
+{
+       struct xbd_softc *sc;
+       struct xbd_command *cm;
+       blkif_request_t *ring_req;
+       int op;
+
+       cm = arg;
+       sc = cm->cm_sc;
+
+       if (error) {
+               cm->cm_bp->bio_error = EIO;
+               biodone(cm->cm_bp);
+               xbd_free_command(cm);
+               return;
+       }
+
+       KASSERT(nsegs <= BLKIF_MAX_SEGMENTS_PER_REQUEST,
+           ("Too many segments in a blkfront I/O"));
+
+       /* Fill out a communications ring structure. */
+       ring_req = RING_GET_REQUEST(&sc->xbd_ring, sc->xbd_ring.req_prod_pvt);
+       sc->xbd_ring.req_prod_pvt++;
+       ring_req->id = cm->cm_id;
+       ring_req->operation = cm->cm_operation;
+       ring_req->sector_number = cm->cm_sector_number;
+       ring_req->handle = (blkif_vdev_t)(uintptr_t)sc->xbd_disk;
+       ring_req->nr_segments = nsegs;
+       cm->cm_nseg = nsegs;
+       mksegarray(segs, nsegs, &cm->cm_gref_head,
+           xenbus_get_otherend_id(sc->xbd_dev),
+           cm->cm_operation == BLKIF_OP_WRITE,
+           cm->cm_sg_refs, ring_req->seg);
 
        if (cm->cm_operation == BLKIF_OP_READ)
                op = BUS_DMASYNC_PREREAD;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to