PERFORCE change 174150 for review

Alexander Motin mav at FreeBSD.org
Tue Feb 2 16:18:19 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=174150

Change 174150 by mav at mav_mavtest on 2010/02/02 16:17:35

	Change the way in which fake async events generated. Do not use
	taskqueue for lock decoupling, as it causes unwanted races.

Affected files ...

.. //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#148 edit

Differences ...

==== //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#148 (text+ko) ====

@@ -2392,10 +2392,8 @@
 {
 	struct cam_path path;
 	struct ccb_getdev cgd;
-	struct async_node *cur_entry;
+	struct ccb_setasync *csa = (struct ccb_setasync *)arg;
 
-	cur_entry = (struct async_node *)arg;
-
 	/*
 	 * Don't report unconfigured devices (Wildcard devs,
 	 * devices only for target mode, device instances
@@ -2413,7 +2411,7 @@
 	xpt_setup_ccb(&cgd.ccb_h, &path, CAM_PRIORITY_NORMAL);
 	cgd.ccb_h.func_code = XPT_GDEV_TYPE;
 	xpt_action((union ccb *)&cgd);
-	cur_entry->callback(cur_entry->callback_arg,
+	csa->callback(csa->callback_arg,
 			    AC_FOUND_DEVICE,
 			    &path, &cgd);
 	xpt_release_path(&path);
@@ -2426,9 +2424,7 @@
 {
 	struct cam_path path;
 	struct ccb_pathinq cpi;
-	struct async_node *cur_entry;
-
-	cur_entry = (struct async_node *)arg;
+	struct ccb_setasync *csa = (struct ccb_setasync *)arg;
 
 	xpt_compile_path(&path, /*periph*/NULL,
 			 bus->sim->path_id,
@@ -2437,7 +2433,7 @@
 	xpt_setup_ccb(&cpi.ccb_h, &path, CAM_PRIORITY_NORMAL);
 	cpi.ccb_h.func_code = XPT_PATH_INQ;
 	xpt_action((union ccb *)&cpi);
-	cur_entry->callback(cur_entry->callback_arg,
+	csa->callback(csa->callback_arg,
 			    AC_PATH_REGISTERED,
 			    &path, &cpi);
 	xpt_release_path(&path);
@@ -2445,35 +2441,6 @@
 	return(1);
 }
 
-static void
-xpt_action_sasync_cb(void *context, int pending)
-{
-	struct async_node *cur_entry;
-	struct xpt_task *task;
-	uint32_t added;
-
-	task = (struct xpt_task *)context;
-	cur_entry = (struct async_node *)task->data1;
-	added = task->data2;
-
-	if ((added & AC_FOUND_DEVICE) != 0) {
-		/*
-		 * Get this peripheral up to date with all
-		 * the currently existing devices.
-		 */
-		xpt_for_all_devices(xptsetasyncfunc, cur_entry);
-	}
-	if ((added & AC_PATH_REGISTERED) != 0) {
-		/*
-		 * Get this peripheral up to date with all
-		 * the currently existing busses.
-		 */
-		xpt_for_all_busses(xptsetasyncbusfunc, cur_entry);
-	}
-
-	free(task, M_CAMXPT);
-}
-
 void
 xpt_action(union ccb *start_ccb)
 {
@@ -2890,6 +2857,7 @@
 			} else {
 				cur_entry->event_enable = csa->event_enable;
 			}
+			csa->event_enable = added;
 		} else {
 			cur_entry = malloc(sizeof(*cur_entry), M_CAMXPT,
 					   M_NOWAIT);
@@ -2903,27 +2871,6 @@
 			SLIST_INSERT_HEAD(async_head, cur_entry, links);
 			xpt_acquire_device(csa->ccb_h.path->device);
 		}
-
-		/*
-		 * Need to decouple this operation via a taqskqueue so that
-		 * the locking doesn't become a mess.
-		 */
-		if ((added & (AC_FOUND_DEVICE | AC_PATH_REGISTERED)) != 0) {
-			struct xpt_task *task;
-
-			task = malloc(sizeof(struct xpt_task), M_CAMXPT,
-				      M_NOWAIT);
-			if (task == NULL) {
-				csa->ccb_h.status = CAM_RESRC_UNAVAIL;
-				break;
-			}
-
-			TASK_INIT(&task->task, 0, xpt_action_sasync_cb, task);
-			task->data1 = cur_entry;
-			task->data2 = added;
-			taskqueue_enqueue(taskqueue_thread, &task->task);
-		}
-
 		start_ccb->ccb_h.status = CAM_REQ_CMP;
 		break;
 	}
@@ -4823,6 +4770,23 @@
 	if (xptpath) {
 		xpt_free_path(path);
 		mtx_unlock(&xsoftc.xpt_lock);
+
+		if ((status == CAM_REQ_CMP) &&
+		    (csa.event_enable & AC_FOUND_DEVICE)) {
+			/*
+			 * Get this peripheral up to date with all
+			 * the currently existing devices.
+			 */
+			xpt_for_all_devices(xptsetasyncfunc, &csa);
+		}
+		if ((status == CAM_REQ_CMP) &&
+		    (csa.event_enable & AC_PATH_REGISTERED)) {
+			/*
+			 * Get this peripheral up to date with all
+			 * the currently existing busses.
+			 */
+			xpt_for_all_busses(xptsetasyncbusfunc, &csa);
+		}
 	}
 	return (status);
 }


More information about the p4-projects mailing list