Example #1
0
File: fsm.c Project: 2asoft/freebsd
static int
doCAM(isess_t *sess)
{
     char	pathstr[1024];
     union ccb	*ccb;
     int	i, n;

     if(ioctl(sess->fd, ISCSIGETCAM, &sess->cam) != 0) {
	  syslog(LOG_WARNING, "ISCSIGETCAM failed: %d", errno);
	  return 0;
     }
     debug(1, "nluns=%d", sess->cam.target_nluns);
     /*
      | for now will do this for each lun ...
      */
     for(n = i = 0; i < sess->cam.target_nluns; i++) {
	  debug(2, "CAM path_id=%d target_id=%d",
		sess->cam.path_id, sess->cam.target_id);

	  sess->camdev = cam_open_btl(sess->cam.path_id, sess->cam.target_id,
				      i, O_RDWR, NULL);
	  if(sess->camdev == NULL) {
	       //syslog(LOG_WARNING, "%s", cam_errbuf);
	       debug(3, "%s", cam_errbuf);
	       continue;
	  }

	  cam_path_string(sess->camdev, pathstr, sizeof(pathstr));
	  debug(2, "pathstr=%s", pathstr);

	  ccb = cam_getccb(sess->camdev);
	  CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->crs);
	  ccb->ccb_h.func_code = XPT_REL_SIMQ;
	  ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
	  ccb->crs.openings = sess->op->tags;
	  if(cam_send_ccb(sess->camdev, ccb) < 0)
	       debug(2, "%s", cam_errbuf);
	  else
	  if((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
	       syslog(LOG_WARNING, "XPT_REL_SIMQ CCB failed");
	       // cam_error_print(sess->camdev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr);
	  }
	  else {
	       n++;
	       syslog(LOG_INFO, "%s tagged openings now %d\n", pathstr, ccb->crs.openings);
	  }
	  cam_freeccb(ccb);
	  cam_close_device(sess->camdev);
     }
     return n;
}
Example #2
0
/*
 * Print SMP error output.  For userland commands, we need the cam_device
 * structure so we can get the path information from the CCB.
 */
#ifdef _KERNEL
void
smp_error_sbuf(struct ccb_smpio *smpio, struct sbuf *sb)
#else /* !_KERNEL*/
void
smp_error_sbuf(struct cam_device *device, struct ccb_smpio *smpio,
	       struct sbuf *sb)
#endif /* _KERNEL/!_KERNEL */
{
	char path_str[64];

#ifdef _KERNEL
	xpt_path_string(smpio->ccb_h.path, path_str, sizeof(path_str));
#else
	cam_path_string(device, path_str, sizeof(path_str));
#endif
	smp_command_sbuf(smpio, sb, path_str, 80 - strlen(path_str), 80);
	sbuf_printf(sb, "\n");

	sbuf_cat(sb, path_str);
	sbuf_printf(sb, "SMP Error: %s (0x%x)\n",
		    smp_error_desc(smpio->smp_response[2]),
		    smpio->smp_response[2]);
}
Example #3
0
int sg_grab(struct burn_drive *d)
{
	struct cam_device *cam;
	char path_string[80];

	if (mmc_function_spy(d, "sg_grab") <= 0)
		return 0;

	if (burn_drive_is_open(d)) {
		d->released = 0;
		return 1;
	}

	cam = cam_open_device(d->devname, O_RDWR);
	if (cam == NULL) {
		libdax_msgs_submit(libdax_messenger, d->global_index,
				0x00020003,
				LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
				"Could not grab drive", errno, 0);
		return 0;
	}
	d->cam = cam;
	if (burn_sg_open_o_excl & 63)
		if (sg_lock(d, 0) <= 0)
			return 0;
	fcntl(cam->fd, F_SETOWN, getpid());

	cam_path_string(d->cam, path_string, sizeof(path_string));

#ifdef Libburn_ahci_verbouS
	fprintf(stderr, "libburn_EXPERIMENTAL: CAM path = %s\n", path_string);
#endif

	if (strstr(path_string, ":ahcich") != NULL)
		d->is_ahci = 1;
	else
		d->is_ahci = -1;

	d->released = 0;
	return 1;
}