[Midnightbsd-cvs] src [9122] trunk/sys/cam: implement CAM_PERIPH_FOREACH macro
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Oct 1 20:36:37 EDT 2016
Revision: 9122
http://svnweb.midnightbsd.org/src/?rev=9122
Author: laffer1
Date: 2016-10-01 20:36:37 -0400 (Sat, 01 Oct 2016)
Log Message:
-----------
implement CAM_PERIPH_FOREACH macro
Modified Paths:
--------------
trunk/sys/cam/ata/ata_da.c
trunk/sys/cam/cam_periph.h
trunk/sys/cam/scsi/scsi_da.c
Modified: trunk/sys/cam/ata/ata_da.c
===================================================================
--- trunk/sys/cam/ata/ata_da.c 2016-10-02 00:35:58 UTC (rev 9121)
+++ trunk/sys/cam/ata/ata_da.c 2016-10-02 00:36:37 UTC (rev 9122)
@@ -1973,7 +1973,7 @@
struct ada_softc *softc;
int error;
- TAILQ_FOREACH(periph, &adadriver.units, unit_links) {
+ CAM_PERIPH_FOREACH(periph, &adadriver) {
union ccb ccb;
/* If we paniced with lock held - not recurse here. */
@@ -2027,7 +2027,7 @@
struct ada_softc *softc;
int error;
- TAILQ_FOREACH(periph, &adadriver.units, unit_links) {
+ CAM_PERIPH_FOREACH(periph, &adadriver) {
union ccb ccb;
/* If we paniced with lock held - not recurse here. */
@@ -2100,7 +2100,7 @@
if (ada_spindown_suspend == 0)
return;
- TAILQ_FOREACH(periph, &adadriver.units, unit_links) {
+ CAM_PERIPH_FOREACH(periph, &adadriver) {
cam_periph_lock(periph);
softc = (struct ada_softc *)periph->softc;
/*
Modified: trunk/sys/cam/cam_periph.h
===================================================================
--- trunk/sys/cam/cam_periph.h 2016-10-02 00:35:58 UTC (rev 9121)
+++ trunk/sys/cam/cam_periph.h 2016-10-02 00:36:37 UTC (rev 9122)
@@ -36,6 +36,8 @@
#ifdef _KERNEL
+#include <cam/cam_xpt.h>
+
struct devstat;
extern struct cam_periph *xpt_periph;
@@ -209,5 +211,42 @@
return (msleep(chan, periph->sim->mtx, priority, wmesg, timo));
}
+static inline struct cam_periph *
+cam_periph_acquire_first(struct periph_driver *driver)
+{
+ struct cam_periph *periph;
+
+ xpt_lock_buses();
+ periph = TAILQ_FIRST(&driver->units);
+ while (periph != NULL && (periph->flags & CAM_PERIPH_INVALID) != 0)
+ periph = TAILQ_NEXT(periph, unit_links);
+ if (periph != NULL)
+ periph->refcount++;
+ xpt_unlock_buses();
+ return (periph);
+}
+
+static inline struct cam_periph *
+cam_periph_acquire_next(struct cam_periph *pperiph)
+{
+ struct cam_periph *periph = pperiph;
+
+ mtx_assert(pperiph->sim->mtx, MA_NOTOWNED);
+ xpt_lock_buses();
+ do {
+ periph = TAILQ_NEXT(periph, unit_links);
+ } while (periph != NULL && (periph->flags & CAM_PERIPH_INVALID) != 0);
+ if (periph != NULL)
+ periph->refcount++;
+ xpt_unlock_buses();
+ cam_periph_release(pperiph);
+ return (periph);
+}
+
+#define CAM_PERIPH_FOREACH(periph, driver) \
+ for ((periph) = cam_periph_acquire_first(driver); \
+ (periph) != NULL; \
+ (periph) = cam_periph_acquire_next(periph))
+
#endif /* _KERNEL */
#endif /* _CAM_CAM_PERIPH_H */
Modified: trunk/sys/cam/scsi/scsi_da.c
===================================================================
--- trunk/sys/cam/scsi/scsi_da.c 2016-10-02 00:35:58 UTC (rev 9121)
+++ trunk/sys/cam/scsi/scsi_da.c 2016-10-02 00:36:37 UTC (rev 9122)
@@ -2836,7 +2836,7 @@
struct da_softc *softc;
int error;
- TAILQ_FOREACH(periph, &dadriver.units, unit_links) {
+ CAM_PERIPH_FOREACH(periph, &dadriver) {
union ccb ccb;
cam_periph_lock(periph);
More information about the Midnightbsd-cvs
mailing list