Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Jun 2013 04:02:51 +0000 (UTC)
From:      "Justin T. Gibbs" <gibbs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r251214 - head/sys/dev/xen/blkfront
Message-ID:  <201306010402.r5142pA4011661@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gibbs
Date: Sat Jun  1 04:02:51 2013
New Revision: 251214
URL: http://svnweb.freebsd.org/changeset/base/251214

Log:
  sys/dev/xen/blkfront/blkfront.c:
  	Remove local, and incorrect, definition for the value of an invalid
  	grant reference.
  
  	Extract ring cleanup code into xbd_free_ring() function for
  	symetry with xbd_alloc_ring().  This process also eliminated
  	an initialized but unused variable.
  
  Sponsored by:	Spectra Logic Corporation
  MFC after:	1 week

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

Modified: head/sys/dev/xen/blkfront/blkfront.c
==============================================================================
--- head/sys/dev/xen/blkfront/blkfront.c	Sat Jun  1 02:07:37 2013	(r251213)
+++ head/sys/dev/xen/blkfront/blkfront.c	Sat Jun  1 04:02:51 2013	(r251214)
@@ -87,8 +87,6 @@ static void xbd_startio(struct xbd_softc
 #define XBD_SECTOR_SIZE		512	/* XXX: assume for now */
 #define XBD_SECTOR_SHFT		9
 
-#define GRANT_INVALID_REF 0
-
 /* Control whether runtime update of vbds is enabled. */
 #define ENABLE_VBD_UPDATE 0
 
@@ -709,6 +707,24 @@ xbd_alloc_ring(struct xbd_softc *sc)
 	return (0);
 }
 
+static void
+xbd_free_ring(struct xbd_softc *sc)
+{
+	int i;
+
+	if (sc->xbd_ring.sring == NULL)
+		return;
+
+	for (i = 0; i < sc->xbd_ring_pages; i++) {
+		if (sc->xbd_ring_ref[i] != GRANT_REF_INVALID) {
+			gnttab_end_foreign_access_ref(sc->xbd_ring_ref[i]);
+			sc->xbd_ring_ref[i] = GRANT_REF_INVALID;
+		}
+	}
+	free(sc->xbd_ring.sring, M_XENBLOCKFRONT);
+	sc->xbd_ring.sring = NULL;
+}
+
 /*-------------------------- Initialization/Teardown -------------------------*/
 static void
 xbd_setup_sysctl(struct xbd_softc *xbd)
@@ -846,7 +862,6 @@ xbd_instance_create(struct xbd_softc *sc
 static void 
 xbd_free(struct xbd_softc *sc)
 {
-	uint8_t *sring_page_ptr;
 	int i;
 	
 	/* Prevent new requests being issued until we fix things up. */
@@ -855,22 +870,7 @@ xbd_free(struct xbd_softc *sc)
 	mtx_unlock(&sc->xbd_io_lock);
 
 	/* Free resources associated with old device channel. */
-	if (sc->xbd_ring.sring != NULL) {
-		sring_page_ptr = (uint8_t *)sc->xbd_ring.sring;
-		for (i = 0; i < sc->xbd_ring_pages; i++) {
-			grant_ref_t *ref;
-
-			ref = &sc->xbd_ring_ref[i];
-			if (*ref != GRANT_INVALID_REF) {
-				gnttab_end_foreign_access_ref(*ref);
-				*ref = GRANT_INVALID_REF;
-			}
-			sring_page_ptr += PAGE_SIZE;
-		}
-		free(sc->xbd_ring.sring, M_XENBLOCKFRONT);
-		sc->xbd_ring.sring = NULL;
-	}
-
+	xbd_free_ring(sc);
 	if (sc->xbd_shadow) {
 
 		for (i = 0; i < sc->xbd_max_requests; i++) {
@@ -1277,7 +1277,7 @@ xbd_attach(device_t dev)
 	xbd_initq_complete(sc);
 	xbd_initq_bio(sc);
 	for (i = 0; i < XBD_MAX_RING_PAGES; i++)
-		sc->xbd_ring_ref[i] = GRANT_INVALID_REF;
+		sc->xbd_ring_ref[i] = GRANT_REF_INVALID;
 
 	sc->xbd_dev = dev;
 	sc->xbd_vdevice = vdevice;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306010402.r5142pA4011661>