Page MenuHomeFreeBSD

D62323.1796405159.diff
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

D62323.1796405159.diff

diff --git a/sys/cam/cam_periph.h b/sys/cam/cam_periph.h
--- a/sys/cam/cam_periph.h
+++ b/sys/cam/cam_periph.h
@@ -52,6 +52,9 @@
void periphdriver_register(void *);
int periphdriver_unregister(void *);
void periphdriver_init(int level);
+struct periph_driver *periphdriver_get(int n);
+struct periph_driver *periphdriver_find(const char *name);
+int periphdriver_index(struct periph_driver *drv);
#include <sys/module.h>
#define PERIPHDRIVER_DECLARE(name, driver) \
diff --git a/sys/cam/cam_periph.c b/sys/cam/cam_periph.c
--- a/sys/cam/cam_periph.c
+++ b/sys/cam/cam_periph.c
@@ -190,6 +190,57 @@
return (0);
}
+/*
+ * The following three accessors exist because periph_drivers is replaced
+ * wholesale by periphdriver_register(), so a caller must not keep a pointer
+ * into the array across a window where the topology lock is dropped.
+ */
+struct periph_driver *
+periphdriver_get(int n)
+{
+ struct periph_driver *drv;
+
+ xpt_lock_buses();
+ drv = n < nperiph_drivers ? periph_drivers[n] : NULL;
+ xpt_unlock_buses();
+ return (drv);
+}
+
+struct periph_driver *
+periphdriver_find(const char *name)
+{
+ struct periph_driver *drv;
+ int n;
+
+ drv = NULL;
+ xpt_lock_buses();
+ for (n = 0; n < nperiph_drivers; n++) {
+ if (strcmp(periph_drivers[n]->driver_name, name) == 0) {
+ drv = periph_drivers[n];
+ break;
+ }
+ }
+ xpt_unlock_buses();
+ return (drv);
+}
+
+int
+periphdriver_index(struct periph_driver *drv)
+{
+ int n, ret;
+
+ ret = -1;
+ xpt_lock_buses();
+ for (n = 0; n < nperiph_drivers; n++) {
+ if (periph_drivers[n] == drv) {
+ ret = n;
+ break;
+ }
+ }
+ xpt_unlock_buses();
+ return (ret);
+}
+
void
periphdriver_init(int level)
{
diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c
--- a/sys/cam/cam_xpt.c
+++ b/sys/cam/cam_xpt.c
@@ -160,7 +160,7 @@
typedef int xpt_targetfunc_t (struct cam_et *target, void *arg);
typedef int xpt_devicefunc_t (struct cam_ed *device, void *arg);
typedef int xpt_periphfunc_t (struct cam_periph *periph, void *arg);
-typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
+typedef int xpt_pdrvfunc_t (struct periph_driver *pdrv, void *arg);
/* Transport layer configuration information */
static struct xpt_softc xsoftc;
@@ -304,9 +304,9 @@
static int xptperiphtraverse(struct cam_ed *device,
struct cam_periph *start_periph,
xpt_periphfunc_t *tr_func, void *arg);
-static int xptpdrvtraverse(struct periph_driver **start_pdrv,
+static int xptpdrvtraverse(struct periph_driver *start_pdrv,
xpt_pdrvfunc_t *tr_func, void *arg);
-static int xptpdperiphtraverse(struct periph_driver **pdrv,
+static int xptpdperiphtraverse(struct periph_driver *pdrv,
struct cam_periph *start_periph,
xpt_periphfunc_t *tr_func,
void *arg);
@@ -1974,7 +1974,7 @@
}
static int
-xptplistpdrvfunc(struct periph_driver **pdrv, void *arg)
+xptplistpdrvfunc(struct periph_driver *pdrv, void *arg)
{
struct cam_periph *periph;
struct ccb_dev_match *cdm;
@@ -1987,7 +1987,7 @@
&& (cdm->pos.position_type & CAM_DEV_POS_PERIPH)
&& (cdm->pos.cookie.periph != NULL)) {
if (cdm->pos.generations[CAM_PERIPH_GENERATION] !=
- (*pdrv)->generation) {
+ pdrv->generation) {
xpt_unlock_buses();
cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
return(0);
@@ -2032,9 +2032,8 @@
* user there are more devices to check.
*/
if (spaceleft < sizeof(struct dev_match_result)) {
- struct periph_driver **pdrv;
+ struct periph_driver *pdrv;
- pdrv = NULL;
bzero(&cdm->pos, sizeof(cdm->pos));
cdm->pos.position_type =
CAM_DEV_POS_PDRV | CAM_DEV_POS_PDPTR |
@@ -2045,16 +2044,12 @@
* actually quite logical. There are very few
* peripheral drivers, and bloating every peripheral
* structure with a pointer back to its parent
- * peripheral driver linker set entry would cost
- * more in the long run than doing this quick lookup.
+ * peripheral driver would cost more in the long run
+ * than doing this quick lookup.
*/
- for (pdrv = periph_drivers; *pdrv != NULL; pdrv++) {
- if (strcmp((*pdrv)->driver_name,
- periph->periph_name) == 0)
- break;
- }
+ pdrv = periphdriver_find(periph->periph_name);
- if (*pdrv == NULL) {
+ if (pdrv == NULL) {
cdm->status = CAM_DEV_MATCH_ERROR;
return(0);
}
@@ -2067,7 +2062,7 @@
*/
cdm->pos.cookie.periph = periph;
cdm->pos.generations[CAM_PERIPH_GENERATION] =
- (*pdrv)->generation;
+ pdrv->generation;
cdm->status = CAM_DEV_MATCH_MORE;
return(0);
}
@@ -2117,18 +2112,21 @@
* At this point in the edt traversal function, we check the bus
* list generation to make sure that no buses have been added or
* removed since the user last sent a XPT_DEV_MATCH ccb through.
- * For the peripheral driver list traversal function, however, we
- * don't have to worry about new peripheral driver types coming or
- * going; they're in a linker set, and therefore can't change
- * without a recompile.
+ * The peripheral driver list can change too: a driver is added or
+ * removed when its module is loaded or unloaded. A stored cookie is
+ * therefore only usable if that driver is still registered.
*/
if ((cdm->pos.position_type & CAM_DEV_POS_PDPTR)
- && (cdm->pos.cookie.pdrv != NULL))
+ && (cdm->pos.cookie.pdrv != NULL)) {
+ if (periphdriver_index(cdm->pos.cookie.pdrv) < 0) {
+ cdm->status = CAM_DEV_MATCH_LIST_CHANGED;
+ return (0);
+ }
ret = xptpdrvtraverse(
- (struct periph_driver **)cdm->pos.cookie.pdrv,
+ (struct periph_driver *)cdm->pos.cookie.pdrv,
xptplistpdrvfunc, cdm);
- else
+ } else
ret = xptpdrvtraverse(NULL, xptplistpdrvfunc, cdm);
/*
@@ -2305,24 +2303,24 @@
}
static int
-xptpdrvtraverse(struct periph_driver **start_pdrv,
+xptpdrvtraverse(struct periph_driver *start_pdrv,
xpt_pdrvfunc_t *tr_func, void *arg)
{
- struct periph_driver **pdrv;
- int retval;
+ struct periph_driver *pdrv;
+ int i, retval;
retval = 1;
/*
- * We don't traverse the peripheral driver list like we do the
- * other lists, because it is a linker set, and therefore cannot be
- * changed during runtime. If the peripheral driver list is ever
- * re-done to be something other than a linker set (i.e. it can
- * change while the system is running), the list traversal should
- * be modified to work like the other traversal functions.
+ * periphdriver_register() replaces the array and frees the old one,
+ * so fetch each entry afresh instead of walking a pointer into it.
*/
- for (pdrv = (start_pdrv ? start_pdrv : periph_drivers);
- *pdrv != NULL; pdrv++) {
+ for (i = 0; (pdrv = periphdriver_get(i)) != NULL; i++) {
+ if (start_pdrv != NULL) {
+ if (pdrv != start_pdrv)
+ continue;
+ start_pdrv = NULL;
+ }
retval = tr_func(pdrv, arg);
if (retval == 0)
@@ -2333,7 +2331,7 @@
}
static int
-xptpdperiphtraverse(struct periph_driver **pdrv,
+xptpdperiphtraverse(struct periph_driver *pdrv,
struct cam_periph *start_periph,
xpt_periphfunc_t *tr_func, void *arg)
{
@@ -2346,7 +2344,7 @@
periph = start_periph;
else {
xpt_lock_buses();
- periph = TAILQ_FIRST(&(*pdrv)->units);
+ periph = TAILQ_FIRST(&pdrv->units);
while (periph != NULL && (periph->flags & CAM_PERIPH_FREE) != 0)
periph = TAILQ_NEXT(periph, unit_links);
if (periph == NULL) {

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 4, 5:25 PM (9 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42210818
Default Alt Text
D62323.1796405159.diff (7 KB)

Event Timeline