Index: lib/libcam/camlib.c =================================================================== --- lib/libcam/camlib.c (revision 291390) +++ lib/libcam/camlib.c (working copy) @@ -752,3 +752,41 @@ bcopy(src, dst, sizeof(struct cam_device)); } + +/* + * Send a reprobe unit request for a given bus, target and lun + */ +int +cam_reprobe_btl(path_id_t path_id, target_id_t target_id, lun_id_t target_lun) +{ + int fd; + char *func_name = "cam_reprobe_btl"; + union ccb ccb; + + if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) { + snprintf(cam_errbuf, CAM_ERRBUF_SIZE, + "%s: couldn't open %s\n%s: %s", func_name, XPT_DEVICE, + func_name, strerror(errno)); + return(-1); + } + + /* Setup our request ccb */ + bzero(&ccb.ccb_h, sizeof(struct ccb_hdr)); + ccb.ccb_h.path_id = path_id; + ccb.ccb_h.target_id = target_id; + ccb.ccb_h.target_lun = target_lun; + + /* + * Attempt to issue a unit reprobe request. This ioctl will fail if the + * kernel can't find a unit for the given path, target and lun. + */ + if (ioctl(fd, CAMUNITREPROBE, &ccb) != 0) { + snprintf(cam_errbuf, CAM_ERRBUF_SIZE, + "%s: failed to issue unit reprobe request", func_name ); + close(fd); + return(-1); + } + + close(fd); + return 0; +} Index: lib/libcam/camlib.h =================================================================== --- lib/libcam/camlib.h (revision 291390) +++ lib/libcam/camlib.h (working copy) @@ -146,6 +146,8 @@ struct cam_device *dst); int cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit); +int cam_reprobe_btl(path_id_t path_id, target_id_t target_id, + lun_id_t target_lun); /* * Buffer encoding/decoding routines, from the old SCSI library. Index: sbin/camcontrol/camcontrol.c =================================================================== --- sbin/camcontrol/camcontrol.c (revision 291390) +++ sbin/camcontrol/camcontrol.c (working copy) @@ -100,7 +100,8 @@ CAM_CMD_APM = 0x00000021, CAM_CMD_AAM = 0x00000022, CAM_CMD_ATTRIB = 0x00000023, - CAM_CMD_OPCODES = 0x00000024 + CAM_CMD_OPCODES = 0x00000024, + CAM_CMD_REPROBE = 0x00000025 } cam_cmdmask; typedef enum { @@ -193,6 +194,7 @@ #endif /* MINIMALISTIC */ {"rescan", CAM_CMD_RESCAN, CAM_ARG_NONE, NULL}, {"reset", CAM_CMD_RESET, CAM_ARG_NONE, NULL}, + {"reprobe", CAM_CMD_REPROBE, CAM_ARG_NONE, NULL}, #ifndef MINIMALISTIC {"cmd", CAM_CMD_SCSI_CMD, CAM_ARG_NONE, scsicmd_opts}, {"command", CAM_CMD_SCSI_CMD, CAM_ARG_NONE, scsicmd_opts}, @@ -3127,6 +3129,34 @@ } static int +doreprobe(int argc, char **argv) +{ + static const char must[] = + "you must specify a bus:target:lun to reprobe"; + int rv; + path_id_t bus = CAM_BUS_WILDCARD; + target_id_t target = CAM_TARGET_WILDCARD; + lun_id_t lun = CAM_LUN_WILDCARD; + char *tstr; + + if (argc < 3) { + warnx(must); + return(1); + } + + tstr = argv[optind]; + while (isspace(*tstr) && (*tstr != '\0')) + tstr++; + rv = parse_btl(argv[optind], &bus, &target, &lun, &arglist); + if (rv != 3) { + warnx(must); + return(1); + } + + return(cam_reprobe_btl(bus, target, lun)); +} + +static int rescan_or_reset_bus(path_id_t bus, int rescan) { union ccb ccb, matchccb; @@ -8685,6 +8715,7 @@ #endif /* MINIMALISTIC */ " camcontrol rescan \n" " camcontrol reset \n" +" camcontrol reprobe bus:target:lun\n" #ifndef MINIMALISTIC " camcontrol defects [dev_id][generic args] <-f format> [-P][-G]\n" " [-q][-s][-S offset][-X]\n" @@ -9053,6 +9084,7 @@ */ if ((cmdlist == CAM_CMD_RESCAN) || (cmdlist == CAM_CMD_RESET) + || (cmdlist == CAM_CMD_REPROBE) || (cmdlist == CAM_CMD_DEVTREE) || (cmdlist == CAM_CMD_USAGE) || (cmdlist == CAM_CMD_DEBUG)) @@ -9204,6 +9236,9 @@ case CAM_CMD_RESET: error = dorescan_or_reset(argc, argv, 0); break; + case CAM_CMD_REPROBE: + error = doreprobe(argc, argv); + break; #ifndef MINIMALISTIC case CAM_CMD_READ_DEFECTS: error = readdefects(cam_dev, argc, argv, combinedopt, Index: sys/amd64/conf/GENERIC =================================================================== --- sys/amd64/conf/GENERIC (revision 291390) +++ sys/amd64/conf/GENERIC (working copy) @@ -366,3 +366,6 @@ # The crypto framework is required by IPSEC device crypto # Required by IPSEC + +# Cam Debug Support +options CAMDEBUG Index: sys/cam/cam_ccb.h =================================================================== --- sys/cam/cam_ccb.h (revision 291390) +++ sys/cam/cam_ccb.h (working copy) @@ -767,6 +767,7 @@ * Definitions for the asynchronous callback CCB fields. */ typedef enum { + AC_UNIT_REPROBE = 0x8000,/* Device reprobe user request */ AC_UNIT_ATTENTION = 0x4000,/* Device reported UNIT ATTENTION */ AC_ADVINFO_CHANGED = 0x2000,/* Advance info might have changes */ AC_CONTRACT = 0x1000,/* A contractual callback */ Index: sys/cam/cam_xpt.c =================================================================== --- sys/cam/cam_xpt.c (revision 291390) +++ sys/cam/cam_xpt.c (working copy) @@ -717,7 +717,41 @@ } xpt_unlock_buses(); break; + } + case CAMUNITREPROBE: { + union ccb *inccb; + struct cam_path path; + + inccb = (union ccb *)addr; + + /* + * Make sure a specific bus, target and lun were specified. + */ + if (inccb->ccb_h.path_id == CAM_BUS_WILDCARD || + inccb->ccb_h.target_id == CAM_TARGET_WILDCARD || + inccb->ccb_h.target_lun == CAM_LUN_WILDCARD) { + error = EINVAL; + break; } + + /* + * Compile a path using the bus, target, and lun the user passed in. + */ + if (xpt_compile_path(&path, NULL, + inccb->ccb_h.path_id, + inccb->ccb_h.target_id, + inccb->ccb_h.target_lun) != + CAM_REQ_CMP){ + error = EINVAL; + break; + } + + /* + * Notify interested parties + */ + xpt_async(AC_UNIT_REPROBE, &path, NULL); + break; + } default: error = ENOTTY; break; Index: sys/cam/scsi/scsi_da.c =================================================================== --- sys/cam/scsi/scsi_da.c (revision 291390) +++ sys/cam/scsi/scsi_da.c (working copy) @@ -1702,6 +1702,17 @@ } break; } + case AC_UNIT_REPROBE: + { + softc = (struct da_softc *)periph->softc; + + xpt_print(periph->path, + "Re-probe requested\n"); + softc->flags &= ~DA_FLAG_PROBED; + dareprobe(periph); + + break; + } case AC_UNIT_ATTENTION: { union ccb *ccb; @@ -2240,7 +2251,7 @@ * would be to not attach the device on failure. */ xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE | - AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION, + AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION | AC_UNIT_REPROBE, daasync, periph, periph->path); /* @@ -3244,12 +3255,11 @@ if (have_sense) scsi_sense_print( &done_ccb->csio); - else { + else xpt_print(periph->path, "got CAM status %#x\n", done_ccb->ccb_h.status); - } - + xpt_print(periph->path, "fatal error, " "failed to attach to device\n"); Index: sys/cam/scsi/scsi_pass.h =================================================================== --- sys/cam/scsi/scsi_pass.h (revision 291390) +++ sys/cam/scsi/scsi_pass.h (working copy) @@ -38,5 +38,6 @@ */ #define CAMIOCOMMAND _IOWR(CAM_VERSION, 2, union ccb) #define CAMGETPASSTHRU _IOWR(CAM_VERSION, 3, union ccb) +#define CAMUNITREPROBE _IOWR(CAM_VERSION, 4, union ccb) #endif