Exemple #1
0
int
main(int argc, char **argv)
{
	/*
	 * get the port number
	 */
	const char	*usage_command = (const char *)basename(argv[0]);
	int			c;
	short			port = DEFAULT_PORT;

	opterr = 0;
	while ((c = getopt(argc, argv, "p:h")) != EOF) {
		switch (c) {
		case 'p':	/* port number				*/
			port = atoi(optarg);
			break;

		case 'h':	/* help 				*/
			help(stdout, usage_command);
			exit(0);
		default:	/* usage 				*/
			usage(stderr, usage_command);
			exit(-1);
		}
	}

	argc -= optind;
	if ( argc != 0 ) {
		usage(stderr, usage_command);
		exit(-1);
	}

	while (1) {
		connection_mgmt(port);

		/*
		 * connection_mgmt returns only on a error, so sleep in hopes
		 * the retry will be successful
		 */
		sleep(1);
	}
}
Exemple #2
0
static tgtadm_err mtask_execute(struct mgmt_task *mtask)
{
	struct tgtadm_req *req = &mtask->req;
	int lld_no;
	tgtadm_err adm_err = TGTADM_INVALID_REQUEST;

	req->lld[TGT_LLD_NAME_LEN - 1] = '\0';

	if (!strlen(req->lld))
		lld_no = 0;
	else {
		lld_no = get_driver_index(req->lld);
		if (lld_no < 0 ||
		   (tgt_drivers[lld_no]->drv_state != DRIVER_INIT &&
		    req->mode != MODE_LLD))
		{
			if (lld_no < 0)
				eprintf("can't find the driver %s\n", req->lld);
			else
				eprintf("driver %s is in state: %s\n",
					req->lld, driver_state_name(tgt_drivers[lld_no]));
			return TGTADM_NO_DRIVER;
		}
	}

	dprintf("%d %d %d %d %d %" PRIx64 " %" PRIx64 " %s %d\n",
		req->len, lld_no, req->mode, req->op,
		req->tid, req->sid, req->lun, mtask->req_buf, getpid());

	switch (req->mode) {
	case MODE_SYSTEM:
		adm_err = sys_mgmt(lld_no, mtask);
		break;
	case MODE_TARGET:
		adm_err = target_mgmt(lld_no, mtask);
		break;
	case MODE_PORTAL:
		adm_err = portal_mgmt(lld_no, mtask);
		break;
	case MODE_DEVICE:
		adm_err = device_mgmt(lld_no, mtask);
		break;
	case MODE_ACCOUNT:
		adm_err = account_mgmt(lld_no, mtask);
		break;
	case MODE_SESSION:
		adm_err = session_mgmt(lld_no, mtask);
		break;
	case MODE_CONNECTION:
		adm_err = connection_mgmt(lld_no, mtask);
		break;
	case MODE_LLD:
		adm_err = lld_mgmt(lld_no, mtask);
		break;
	default:
		if (req->op == OP_SHOW && tgt_drivers[lld_no]->show) {
			concat_buf_init(&mtask->rsp_concat);
			adm_err = tgt_drivers[lld_no]->show(req->mode,
							    req->tid, req->sid,
							    req->cid, req->lun,
							    &mtask->rsp_concat);
			concat_buf_finish(&mtask->rsp_concat);
		} else
			eprintf("unsupported mode: %d\n", req->mode);
		break;
	}

	return adm_err;
}
Exemple #3
0
static int tgt_mgmt(struct mgmt_task *mtask)
{
    struct tgtadm_req *req = &mtask->req;
    struct tgtadm_rsp *rsp = &mtask->rsp;
    int lld_no, err = TGTADM_INVALID_REQUEST, len = mtask->bsize;

    if (!strlen(req->lld))
        lld_no = 0;
    else {
        lld_no = get_driver_index(req->lld);
        if (lld_no < 0 || tgt_drivers[lld_no]->drv_state != DRIVER_INIT) {
            if (lld_no < 0)
                eprintf("can't find the driver %s\n", req->lld);
            else
                eprintf("driver %s is in state: %s\n",
                        req->lld, driver_state_name(tgt_drivers[lld_no]));
            rsp->err = TGTADM_NO_DRIVER;
            rsp->len = sizeof(*rsp);
            return 0;
        }
    }

    dprintf("%d %d %d %d %d %" PRIx64 " %" PRIx64 " %s %d\n",
            req->len, lld_no, req->mode, req->op,
            req->tid, req->sid, req->lun, mtask->buf, getpid());

    switch (req->mode) {
    case MODE_SYSTEM:
        err = sys_mgmt(lld_no, mtask);
        break;
    case MODE_TARGET:
        err = target_mgmt(lld_no, mtask);
        break;
    case MODE_PORTAL:
        err = portal_mgmt(lld_no, mtask, req, rsp);
        break;
    case MODE_DEVICE:
        err = device_mgmt(lld_no, req, mtask->buf, rsp, &len);
        break;
    case MODE_ACCOUNT:
        err = account_mgmt(lld_no, mtask);
        break;
    case MODE_CONNECTION:
        err = connection_mgmt(lld_no, mtask, req, rsp);
        break;
    default:
        if (req->op == OP_SHOW && tgt_drivers[lld_no]->show) {
            err = tgt_drivers[lld_no]->show(req->mode,
                                            req->tid, req->sid,
                                            req->cid, req->lun,
                                            mtask->buf, len);

            set_show_results(rsp, &err);
        } else {
            rsp->err = err;
            rsp->len = sizeof(*rsp);
        }
        break;
    }

    return err;
}