Example #1
0
File: mgmt.c Project: fujita/tgt
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;
}
Example #2
0
File: mgmt.c Project: redlicha/tgt
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;
}