Author: mav
Date: Thu Apr  4 10:19:05 2013
New Revision: 249091
URL: http://svnweb.freebsd.org/changeset/base/249091

Log:
  Use xpt_lock_buses() instead of equivalent mtx_lock(&xsoftc.xpt_topo_lock)
  to unify the code.

Modified:
  head/sys/cam/cam_xpt.c

Modified: head/sys/cam/cam_xpt.c
==============================================================================
--- head/sys/cam/cam_xpt.c      Thu Apr  4 09:21:24 2013        (r249090)
+++ head/sys/cam/cam_xpt.c      Thu Apr  4 10:19:05 2013        (r249091)
@@ -654,7 +654,7 @@ xptioctl(struct cdev *dev, u_long cmd, c
                }
 
                /* Keep the list from changing while we traverse it */
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
 ptstartover:
                cur_generation = xsoftc.xpt_generation;
 
@@ -664,7 +664,7 @@ ptstartover:
                                break;
 
                if (*p_drv == NULL) {
-                       mtx_unlock(&xsoftc.xpt_topo_lock);
+                       xpt_unlock_buses();
                        ccb->ccb_h.status = CAM_REQ_CMP_ERR;
                        ccb->cgdl.status = CAM_GDEVLIST_ERROR;
                        *ccb->cgdl.periph_name = '\0';
@@ -686,8 +686,8 @@ ptstartover:
                        if (periph->unit_number == unit) {
                                break;
                        } else if (--splbreaknum == 0) {
-                               mtx_unlock(&xsoftc.xpt_topo_lock);
-                               mtx_lock(&xsoftc.xpt_topo_lock);
+                               xpt_unlock_buses();
+                               xpt_lock_buses();
                                splbreaknum = 100;
                                if (cur_generation != xsoftc.xpt_generation)
                                       goto ptstartover;
@@ -776,7 +776,7 @@ ptstartover:
                                       "your kernel config file\n");
                        }
                }
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
                break;
                }
        default:
@@ -1024,9 +1024,9 @@ xpt_add_periph(struct cam_periph *periph
                SLIST_INSERT_HEAD(periph_head, periph, periph_links);
        }
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        xsoftc.xpt_generation++;
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
 
        return (status);
 }
@@ -1054,12 +1054,12 @@ xpt_remove_periph(struct cam_periph *per
        }
 
        if (topology_lock_held == 0)
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
 
        xsoftc.xpt_generation++;
 
        if (topology_lock_held == 0)
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
 }
 
 
@@ -2031,7 +2031,7 @@ xptbustraverse(struct cam_eb *start_bus,
 
        retval = 1;
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        for (bus = (start_bus ? start_bus : TAILQ_FIRST(&xsoftc.xpt_busses));
             bus != NULL;
             bus = next_bus) {
@@ -2042,22 +2042,22 @@ xptbustraverse(struct cam_eb *start_bus,
                 * XXX The locking here is obviously very complex.  We
                 * should work to simplify it.
                 */
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
                CAM_SIM_LOCK(bus->sim);
                retval = tr_func(bus, arg);
                CAM_SIM_UNLOCK(bus->sim);
 
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
                next_bus = TAILQ_NEXT(bus, links);
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
 
                xpt_release_bus(bus);
 
                if (retval == 0)
                        return(retval);
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
        }
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
 
        return(retval);
 }
@@ -2073,7 +2073,7 @@ xpt_sim_opened(struct cam_sim *sim)
        KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
        mtx_assert(sim->mtx, MA_OWNED);
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        TAILQ_FOREACH(bus, &xsoftc.xpt_busses, links) {
                if (bus->sim != sim)
                        continue;
@@ -2083,7 +2083,7 @@ xpt_sim_opened(struct cam_sim *sim)
                                SLIST_FOREACH(periph, &device->periphs,
                                    periph_links) {
                                        if (periph->refcount > 0) {
-                                               
mtx_unlock(&xsoftc.xpt_topo_lock);
+                                               xpt_unlock_buses();
                                                return (1);
                                        }
                                }
@@ -2091,7 +2091,7 @@ xpt_sim_opened(struct cam_sim *sim)
                }
        }
 
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
        return (0);
 }
 
@@ -3550,14 +3550,14 @@ xpt_path_counts(struct cam_path *path, u
     uint32_t *periph_ref, uint32_t *target_ref, uint32_t *device_ref)
 {
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        if (bus_ref) {
                if (path->bus)
                        *bus_ref = path->bus->refcount;
                else
                        *bus_ref = 0;
        }
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
        if (periph_ref) {
                if (path->periph)
                        *periph_ref = path->periph->refcount;
@@ -3873,7 +3873,7 @@ xpt_bus_register(struct cam_sim *sim, de
        new_bus->refcount = 1;  /* Held until a bus_deregister event */
        new_bus->generation = 0;
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        old_bus = TAILQ_FIRST(&xsoftc.xpt_busses);
        while (old_bus != NULL
            && old_bus->path_id < new_bus->path_id)
@@ -3883,7 +3883,7 @@ xpt_bus_register(struct cam_sim *sim, de
        else
                TAILQ_INSERT_TAIL(&xsoftc.xpt_busses, new_bus, links);
        xsoftc.bus_generation++;
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
 
        /*
         * Set a default transport so that a PATH_INQ can be issued to
@@ -3969,7 +3969,7 @@ xptnextfreepathid(void)
        const char *strval;
 
        pathid = 0;
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        bus = TAILQ_FIRST(&xsoftc.xpt_busses);
 retry:
        /* Find an unoccupied pathid */
@@ -3978,7 +3978,7 @@ retry:
                        pathid++;
                bus = TAILQ_NEXT(bus, links);
        }
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
 
        /*
         * Ensure that this pathid is not reserved for
@@ -3987,7 +3987,7 @@ retry:
        if (resource_string_value("scbus", pathid, "at", &strval) == 0) {
                ++pathid;
                /* Start the search over */
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
                goto retry;
        }
        return (pathid);
@@ -4436,17 +4436,17 @@ static void
 xpt_release_bus(struct cam_eb *bus)
 {
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        KASSERT(bus->refcount >= 1, ("bus->refcount >= 1"));
        if ((--bus->refcount == 0)
         && (TAILQ_FIRST(&bus->et_entries) == NULL)) {
                TAILQ_REMOVE(&xsoftc.xpt_busses, bus, links);
                xsoftc.bus_generation++;
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
                cam_sim_release(bus->sim);
                free(bus, M_CAMXPT);
        } else
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
 }
 
 static struct cam_et *
@@ -4470,9 +4470,9 @@ xpt_alloc_target(struct cam_eb *bus, tar
                 * Hold a reference to our parent bus so it
                 * will not go away before we do.
                 */
-               mtx_lock(&xsoftc.xpt_topo_lock);
+               xpt_lock_buses();
                bus->refcount++;
-               mtx_unlock(&xsoftc.xpt_topo_lock);
+               xpt_unlock_buses();
 
                /* Insertion sort into our bus's target list */
                cur_target = TAILQ_FIRST(&bus->et_entries);
@@ -4662,7 +4662,7 @@ xpt_find_bus(path_id_t path_id)
 {
        struct cam_eb *bus;
 
-       mtx_lock(&xsoftc.xpt_topo_lock);
+       xpt_lock_buses();
        for (bus = TAILQ_FIRST(&xsoftc.xpt_busses);
             bus != NULL;
             bus = TAILQ_NEXT(bus, links)) {
@@ -4671,7 +4671,7 @@ xpt_find_bus(path_id_t path_id)
                        break;
                }
        }
-       mtx_unlock(&xsoftc.xpt_topo_lock);
+       xpt_unlock_buses();
        return (bus);
 }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to