From 74448961ec9a8ecb496066cacac4aee33258b2b0 Mon Sep 17 00:00:00 2001 From: scottl Date: Wed, 16 May 2007 16:54:23 +0000 Subject: [PATCH] Add a helper function for registering async callbacks. Besides eliminating a lot of duplicated code, this also fixes a locking edge case. --- sys/cam/cam_xpt.c | 33 +++++++++++++++++++++++++++++++ sys/cam/cam_xpt.h | 2 ++ sys/cam/scsi/scsi_cd.c | 36 ++++------------------------------ sys/cam/scsi/scsi_ch.c | 36 ++++------------------------------ sys/cam/scsi/scsi_da.c | 37 +++++------------------------------ sys/cam/scsi/scsi_pass.c | 36 ++++------------------------------ sys/cam/scsi/scsi_pt.c | 37 +++++------------------------------ sys/cam/scsi/scsi_sa.c | 39 ++++--------------------------------- sys/cam/scsi/scsi_ses.c | 33 +++---------------------------- sys/cam/scsi/scsi_sg.c | 35 ++++----------------------------- sys/cam/scsi/scsi_targ_bh.c | 18 ++--------------- 11 files changed, 70 insertions(+), 272 deletions(-) diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index 882ce61a775a..9c64a5c413e0 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -7029,6 +7029,39 @@ xpt_finishconfig(struct cam_periph *periph, union ccb *done_ccb) xpt_free_ccb(done_ccb); } +cam_status +xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg, + struct cam_path *path) +{ + struct ccb_setasync csa; + cam_status status; + int xptpath = 0; + + if (path == NULL) { + mtx_lock(&xsoftc.xpt_lock); + status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, + CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); + if (status != CAM_REQ_CMP) { + mtx_unlock(&xsoftc.xpt_lock); + return (status); + } + xptpath = 1; + } + + xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); + csa.ccb_h.func_code = XPT_SASYNC_CB; + csa.event_enable = event; + csa.callback = cbfunc; + csa.callback_arg = cbarg; + xpt_action((union ccb *)&csa); + status = csa.ccb_h.status; + if (xptpath) { + xpt_free_path(path); + mtx_unlock(&xsoftc.xpt_lock); + } + return (status); +} + static void xptaction(struct cam_sim *sim, union ccb *work_ccb) { diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h index deed466ce1d2..26ca65769d12 100644 --- a/sys/cam/cam_xpt.h +++ b/sys/cam/cam_xpt.h @@ -79,6 +79,8 @@ void xpt_async(u_int32_t async_code, struct cam_path *path, void xpt_rescan(union ccb *ccb); void xpt_lock_buses(void); void xpt_unlock_buses(void); +cam_status xpt_register_async(int event, ac_callback_t *cbfunc, + void *cbarg, struct cam_path *path); #endif /* _KERNEL */ #endif /* _CAM_CAM_XPT_H */ diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index daff0120d440..118e977f6c94 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -335,7 +335,6 @@ static void cdinit(void) { cam_status status; - struct cam_path *path; mtx_init(&changerq_mtx, "cdchangerq", "SCSI CD Changer List", MTX_DEF); STAILQ_INIT(&changerq); @@ -344,21 +343,7 @@ cdinit(void) * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = cdasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, cdasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("cd: Failed to attach master async callback " @@ -370,20 +355,13 @@ static void cdoninvalidate(struct cam_periph *periph) { struct cd_softc *softc; - struct ccb_setasync csa; softc = (struct cd_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = cdasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, cdasync, periph, periph->path); softc->flags |= CD_FLAG_INVALID; @@ -639,7 +617,6 @@ static cam_status cdregister(struct cam_periph *periph, void *arg) { struct cd_softc *softc; - struct ccb_setasync csa; struct ccb_pathinq cpi; struct ccb_getdev *cgd; char tmpstr[80]; @@ -751,13 +728,8 @@ cdregister(struct cam_periph *periph, void *arg) * Add an async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE; - csa.callback = cdasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE, + cdasync, periph, periph->path); /* * If the target lun is greater than 0, we most likely have a CD diff --git a/sys/cam/scsi/scsi_ch.c b/sys/cam/scsi/scsi_ch.c index f678b2a3a064..ca4a365da7f8 100644 --- a/sys/cam/scsi/scsi_ch.c +++ b/sys/cam/scsi/scsi_ch.c @@ -224,27 +224,12 @@ static void chinit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = chasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, chasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("ch: Failed to attach master async callback " @@ -256,20 +241,13 @@ static void choninvalidate(struct cam_periph *periph) { struct ch_softc *softc; - struct ccb_setasync csa; softc = (struct ch_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = chasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, chasync, periph, periph->path); softc->flags |= CH_FLAG_INVALID; @@ -338,7 +316,6 @@ static cam_status chregister(struct cam_periph *periph, void *arg) { struct ch_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; cgd = (struct ccb_getdev *)arg; @@ -369,6 +346,7 @@ chregister(struct cam_periph *periph, void *arg) * Changers don't have a blocksize, and obviously don't support * tagged queueing. */ + cam_periph_unlock(periph); softc->device_stats = devstat_new_entry("ch", periph->unit_number, 0, DEVSTAT_NO_BLOCKSIZE | DEVSTAT_NO_ORDERED_TAGS, @@ -376,7 +354,6 @@ chregister(struct cam_periph *periph, void *arg) DEVSTAT_PRIORITY_OTHER); /* Register the device */ - cam_periph_unlock(periph); softc->dev = make_dev(&ch_cdevsw, periph->unit_number, UID_ROOT, GID_OPERATOR, 0600, "%s%d", periph->periph_name, periph->unit_number); @@ -387,12 +364,7 @@ chregister(struct cam_periph *periph, void *arg) * Add an async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_LOST_DEVICE; - csa.callback = chasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_LOST_DEVICE, chasync, periph, periph->path); /* * Lock this periph until we are setup. diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index f234290d4f9e..b835a1991e3e 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -695,8 +695,8 @@ daclose(struct disk *dp) softc->flags &= ~DA_FLAG_OPEN; cam_periph_unhold(periph); - cam_periph_unlock(periph); cam_periph_release(periph); + cam_periph_unlock(periph); return (0); } @@ -858,27 +858,12 @@ static void dainit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = daasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("da: Failed to attach master async callback " @@ -896,20 +881,13 @@ static void daoninvalidate(struct cam_periph *periph) { struct da_softc *softc; - struct ccb_setasync csa; softc = (struct da_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = daasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, daasync, periph, periph->path); softc->flags |= DA_FLAG_PACK_INVALID; @@ -1087,7 +1065,6 @@ static cam_status daregister(struct cam_periph *periph, void *arg) { struct da_softc *softc; - struct ccb_setasync csa; struct ccb_pathinq cpi; struct ccb_getdev *cgd; char tmpstr[80]; @@ -1202,12 +1179,8 @@ daregister(struct cam_periph *periph, void *arg) * them and the only alternative would be to * not attach the device on failure. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE; - csa.callback = daasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE, + daasync, periph, periph->path); /* * Take an exclusive refcount on the periph while dastart is called diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index 5617ef09d7f7..17084e6f8d71 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -118,27 +118,12 @@ static void passinit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = passasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, passasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("pass: Failed to attach master async callback " @@ -151,20 +136,13 @@ static void passoninvalidate(struct cam_periph *periph) { struct pass_softc *softc; - struct ccb_setasync csa; softc = (struct pass_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = passasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, passasync, periph, periph->path); softc->flags |= PASS_FLAG_INVALID; @@ -250,7 +228,6 @@ static cam_status passregister(struct cam_periph *periph, void *arg) { struct pass_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; int no_tags; @@ -285,6 +262,7 @@ passregister(struct cam_periph *periph, void *arg) * know what the blocksize of this device is, if * it even has a blocksize. */ + mtx_unlock(periph->sim->mtx); no_tags = (cgd->inq_data.flags & SID_CmdQue) == 0; softc->device_stats = devstat_new_entry("pass", unit2minor(periph->unit_number), 0, @@ -296,7 +274,6 @@ passregister(struct cam_periph *periph, void *arg) DEVSTAT_PRIORITY_PASS); /* Register the device */ - mtx_unlock(periph->sim->mtx); softc->dev = make_dev(&pass_cdevsw, unit2minor(periph->unit_number), UID_ROOT, GID_OPERATOR, 0600, "%s%d", periph->periph_name, periph->unit_number); @@ -307,12 +284,7 @@ passregister(struct cam_periph *periph, void *arg) * Add an async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_LOST_DEVICE; - csa.callback = passasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_LOST_DEVICE, passasync, periph, periph->path); if (bootverbose) xpt_announce_periph(periph, NULL); diff --git a/sys/cam/scsi/scsi_pt.c b/sys/cam/scsi/scsi_pt.c index 7201a58727cf..d70972e7771b 100644 --- a/sys/cam/scsi/scsi_pt.c +++ b/sys/cam/scsi/scsi_pt.c @@ -234,27 +234,12 @@ static void ptinit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = ptasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, ptasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("pt: Failed to attach master async callback " @@ -266,7 +251,6 @@ static cam_status ptctor(struct cam_periph *periph, void *arg) { struct pt_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; cgd = (struct ccb_getdev *)arg; @@ -297,13 +281,13 @@ ptctor(struct cam_periph *periph, void *arg) periph->softc = softc; + cam_periph_unlock(periph); softc->device_stats = devstat_new_entry("pt", periph->unit_number, 0, DEVSTAT_NO_BLOCKSIZE, SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_OTHER); - cam_periph_unlock(periph); softc->dev = make_dev(&pt_cdevsw, periph->unit_number, UID_ROOT, GID_OPERATOR, 0600, "%s%d", periph->periph_name, periph->unit_number); @@ -318,12 +302,8 @@ ptctor(struct cam_periph *periph, void *arg) * them and the only alternative would be to * not attach the device on failure. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE; - csa.callback = ptasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE, + ptasync, periph, periph->path); /* Tell the user we've attached to the device */ xpt_announce_periph(periph, NULL); @@ -335,20 +315,13 @@ static void ptoninvalidate(struct cam_periph *periph) { struct pt_softc *softc; - struct ccb_setasync csa; softc = (struct pt_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = ptasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, ptasync, periph, periph->path); softc->flags |= PT_FLAG_DEVICE_INVALID; diff --git a/sys/cam/scsi/scsi_sa.c b/sys/cam/scsi/scsi_sa.c index c963d89a1c3e..4f818e03ecac 100644 --- a/sys/cam/scsi/scsi_sa.c +++ b/sys/cam/scsi/scsi_sa.c @@ -1331,29 +1331,11 @@ static void sainit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. */ - status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - /* Register the async callbacks of interrest */ - struct ccb_setasync csa; /* - * This is an immediate CCB, - * so using the stack is OK - */ - xpt_setup_ccb(&csa.ccb_h, path, 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = saasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, saasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("sa: Failed to attach master async callback " @@ -1365,20 +1347,13 @@ static void saoninvalidate(struct cam_periph *periph) { struct sa_softc *softc; - struct ccb_setasync csa; softc = (struct sa_softc *)periph->softc; /* * De-register any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, - /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = saasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, saasync, periph, periph->path); softc->flags |= SA_FLAG_INVALID; @@ -1462,7 +1437,6 @@ static cam_status saregister(struct cam_periph *periph, void *arg) { struct sa_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; caddr_t match; int i; @@ -1517,11 +1491,11 @@ saregister(struct cam_periph *periph, void *arg) * blocksize until we media is inserted. So, set a flag to * indicate that the blocksize is unavailable right now. */ + cam_periph_unlock(periph); softc->device_stats = devstat_new_entry("sa", periph->unit_number, 0, DEVSTAT_BS_UNAVAILABLE, SID_TYPE(&cgd->inq_data) | DEVSTAT_TYPE_IF_SCSI, DEVSTAT_PRIORITY_TAPE); - cam_periph_unlock(periph); softc->devs.ctl_dev = make_dev(&sa_cdevsw, SAMINOR(SA_CTLDEV, periph->unit_number, 0, SA_ATYPE_R), UID_ROOT, GID_OPERATOR, 0660, "%s%d.ctl", periph->periph_name, periph->unit_number); @@ -1570,12 +1544,7 @@ saregister(struct cam_periph *periph, void *arg) * Add an async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /* priority */ 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_LOST_DEVICE; - csa.callback = saasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_LOST_DEVICE, saasync, periph, periph->path); xpt_announce_periph(periph, NULL); diff --git a/sys/cam/scsi/scsi_ses.c b/sys/cam/scsi/scsi_ses.c index 8e0b57224555..0c3092b7cf85 100644 --- a/sys/cam/scsi/scsi_ses.c +++ b/sys/cam/scsi/scsi_ses.c @@ -190,27 +190,12 @@ static void sesinit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new device found". */ - status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = sesasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, sesasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("ses: Failed to attach master async callback " @@ -222,19 +207,13 @@ static void sesoninvalidate(struct cam_periph *periph) { struct ses_softc *softc; - struct ccb_setasync csa; softc = (struct ses_softc *)periph->softc; /* * Unregister any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = sesasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, sesasync, periph, periph->path); softc->ses_flags |= SES_FLAG_INVALID; @@ -310,7 +289,6 @@ static cam_status sesregister(struct cam_periph *periph, void *arg) { struct ses_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; char *tname; @@ -375,12 +353,7 @@ sesregister(struct cam_periph *periph, void *arg) * Add an async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, 5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_LOST_DEVICE; - csa.callback = sesasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_LOST_DEVICE, sesasync, periph, periph->path); switch (softc->ses_type) { default: diff --git a/sys/cam/scsi/scsi_sg.c b/sys/cam/scsi/scsi_sg.c index 402d4b4e0efc..f636c7d25e52 100644 --- a/sys/cam/scsi/scsi_sg.c +++ b/sys/cam/scsi/scsi_sg.c @@ -156,27 +156,12 @@ static void sginit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will receive aync * callbacks like "new device found". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_FOUND_DEVICE; - csa.callback = sgasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_FOUND_DEVICE, sgasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("sg: Failed to attach master async callbac " @@ -188,19 +173,13 @@ static void sgoninvalidate(struct cam_periph *periph) { struct sg_softc *softc; - struct ccb_setasync csa; softc = (struct sg_softc *)periph->softc; /* * Deregister any async callbacks. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = 0; - csa.callback = sgasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(0, sgasync, periph, periph->path); softc->flags |= SG_FLAG_INVALID; @@ -274,7 +253,6 @@ static cam_status sgregister(struct cam_periph *periph, void *arg) { struct sg_softc *softc; - struct ccb_setasync csa; struct ccb_getdev *cgd; int no_tags; @@ -306,6 +284,7 @@ sgregister(struct cam_periph *periph, void *arg) * We pass in 0 for all blocksize, since we don't know what the * blocksize of the device is, if it even has a blocksize. */ + cam_periph_unlock(periph); no_tags = (cgd->inq_data.flags & SID_CmdQue) == 0; softc->device_stats = devstat_new_entry("sg", unit2minor(periph->unit_number), 0, @@ -317,7 +296,6 @@ sgregister(struct cam_periph *periph, void *arg) DEVSTAT_PRIORITY_PASS); /* Register the device */ - cam_periph_unlock(periph); softc->dev = make_dev(&sg_cdevsw, unit2minor(periph->unit_number), UID_ROOT, GID_OPERATOR, 0600, "%s%d", periph->periph_name, periph->unit_number); @@ -329,12 +307,7 @@ sgregister(struct cam_periph *periph, void *arg) * Add as async callback so that we get * notified if this device goes away. */ - xpt_setup_ccb(&csa.ccb_h, periph->path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_LOST_DEVICE; - csa.callback = sgasync; - csa.callback_arg = periph; - xpt_action((union ccb *)&csa); + xpt_register_async(AC_LOST_DEVICE, sgasync, periph, periph->path); if (bootverbose) xpt_announce_periph(periph, NULL); diff --git a/sys/cam/scsi/scsi_targ_bh.c b/sys/cam/scsi/scsi_targ_bh.c index 984baf44ba1a..e8ec51f41d59 100644 --- a/sys/cam/scsi/scsi_targ_bh.c +++ b/sys/cam/scsi/scsi_targ_bh.c @@ -156,27 +156,13 @@ static void targbhinit(void) { cam_status status; - struct cam_path *path; /* * Install a global async callback. This callback will * receive async callbacks like "new path registered". */ - status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID, - CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); - - if (status == CAM_REQ_CMP) { - struct ccb_setasync csa; - - xpt_setup_ccb(&csa.ccb_h, path, /*priority*/5); - csa.ccb_h.func_code = XPT_SASYNC_CB; - csa.event_enable = AC_PATH_REGISTERED | AC_PATH_DEREGISTERED; - csa.callback = targbhasync; - csa.callback_arg = NULL; - xpt_action((union ccb *)&csa); - status = csa.ccb_h.status; - xpt_free_path(path); - } + status = xpt_register_async(AC_PATH_REGISTERED | AC_PATH_DEREGISTERED, + targbhasync, NULL, NULL); if (status != CAM_REQ_CMP) { printf("targbh: Failed to attach master async callback "