コード例 #1
0
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct iscsi_target *target = NULL;
	long err;
	u32 id;

	if ((err = get_user(id, (u32 *) arg)) != 0)
		goto done;

	if (cmd == DEL_TARGET) {
		err = target_del(id);
		goto done;
	}

	target = target_lookup_by_id(id);

	if (cmd == ADD_TARGET)
		if (target) {
			err = -EEXIST;
			eprintk("Target %u already exist!\n", id);
			goto done;
		}

	switch (cmd) {
	case ADD_TARGET:
		assert(!target);
		err = add_target(arg);
		goto done;
	}

	if (!target) {
		eprintk("can't find the target %u\n", id);
		err = -EINVAL;
		goto done;
	}

	if ((err = target_lock(target, 1)) < 0) {
		eprintk("interrupted %ld %d\n", err, cmd);
		goto done;
	}

	switch (cmd) {
	case ADD_VOLUME:
		err = add_volume(target, arg);
		break;

	case DEL_VOLUME:
		err = del_volume(target, arg);
		break;

	case ADD_SESSION:
		err = add_session(target, arg);
		break;

	case DEL_SESSION:
		err = del_session(target, arg);
		break;

	case GET_SESSION_INFO:
		err = get_session_info(target, arg);
		break;

	case ISCSI_PARAM_SET:
		err = iscsi_param_config(target, arg, 1);
		break;

	case ISCSI_PARAM_GET:
		err = iscsi_param_config(target, arg, 0);
		break;

	case ADD_CONN:
		err = add_conn(target, arg);
		break;

	case DEL_CONN:
		err = del_conn(target, arg);
		break;

	case GET_CONN_INFO:
		err = get_conn_info(target, arg);
		break;

	}

	if (target)
		target_unlock(target);

done:
	return err;
}
コード例 #2
0
ファイル: config.c プロジェクト: OESF/linux-linaro-natty
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	struct iscsi_target *target = NULL;
	long err;
	u32 id;

	err = down_interruptible(&ioctl_sem);
	if (err < 0)
		return err;

	if (cmd == GET_MODULE_INFO) {
		err = get_module_info(arg);
		goto done;
	}

	if (cmd == ADD_TARGET) {
		err = add_target(arg);
		goto done;
	}

	err = get_user(id, (u32 *) arg);
	if (err < 0)
		goto done;

	/* locking handled in target_del */
	if (cmd == DEL_TARGET) {
		err = target_del(id);
		goto done;
	}

	target = target_lookup_by_id(id);
	if (!target) {
		err = -ENOENT;
		goto done;
	}

	err = target_lock(target, 1);
	if (err < 0)
		goto done;

	switch (cmd) {
	case ADD_VOLUME:
		err = add_volume(target, arg);
		break;

	case DEL_VOLUME:
		err = del_volume(target, arg);
		break;

	case ADD_SESSION:
		err = add_session(target, arg);
		break;

	case DEL_SESSION:
		err = del_session(target, arg);
		break;

	case GET_SESSION_INFO:
		err = get_session_info(target, arg);
		break;

	case ISCSI_PARAM_SET:
		err = iscsi_param_config(target, arg, 1);
		break;

	case ISCSI_PARAM_GET:
		err = iscsi_param_config(target, arg, 0);
		break;

	case ADD_CONN:
		err = add_conn(target, arg);
		break;

	case DEL_CONN:
		err = del_conn(target, arg);
		break;

	case GET_CONN_INFO:
		err = get_conn_info(target, arg);
		break;
	default:
		eprintk("invalid ioctl cmd %x\n", cmd);
		err = -EINVAL;
	}

	target_unlock(target);
done:
	up(&ioctl_sem);

	return err;
}
コード例 #3
0
ファイル: flowman.c プロジェクト: berkus/nemesis
static bool_t ReAttach_m(
        FlowMan_cl      *self,
	FlowMan_Flow	flow,
        FlowMan_ConnID  cid     /* IN */,
        const FlowMan_SAP       *lsap   /* IN */,
        const FlowMan_SAP       *rsap   /* IN */ )
{
    flowman_st UNUSED *st = self->st;
    conn_t	*c = (conn_t *)cid;
    flow_t	*f = (flow_t *)flow;
    port_alloc_t *p;

    switch (lsap->tag) {
    case FlowMan_PT_TCP:
	p = st->host->TCPportuse;
	break;
    case FlowMan_PT_UDP:
	p = st->host->UDPportuse;
	break;
    default:
	printf("FlowMan$ReAttach: unknown protocol %d\n", lsap->tag);
	return False;
    }

    /* check the client owns the local port in question */
    while(p)
    {
	if (p->port == lsap->u.UDP.port)
	    break;
	 p = p->next;
    }
    if (!p)
    {
	printf("FlowMan$ReAttach: domain %qx attempted to attach "
	       "to unbound port %d\n",
	       st->dom,
	       ntohs(lsap->u.UDP.port));
	return False;
    }

    /* check client specified the correct local IP address */
    if (lsap->u.UDP.addr.a != f->intf->ipaddr)
    {
	printf("FlowMan$ReAttach: domain %qx attempted to attach "
	       "with bogus local IP address (%x != %x)\n",
	       st->dom,
	       ntohl(lsap->u.UDP.addr.a), ntohl(f->intf->ipaddr));
	return 0;
    }

    /* remove old demux for this flow, and put the new one in */
    /* XXX TX stuff isn't changed */

    /* XXX race between del and add; need to make these atomic. */
    del_conn(f, c);
    /* take a copy of the new connection endpoints */
    c->lsap = *lsap;
    c->rsap = *rsap;
    add_conn(f, c);

    return True;
}
コード例 #4
0
ファイル: config.c プロジェクト: delphij/ietbsd
int iet_ioctl(struct cdev *dev, unsigned long cmd, caddr_t iarg, int fflag, struct thread *td)
#endif
{
	struct iscsi_target *target = NULL;
	long err;
	u32 id;
#ifdef FREEBSD
	unsigned long arg = (unsigned long)(iarg); /* Avoid make warnings */
#endif

	err = mutex_lock_interruptible(&ioctl_mutex);
	if (err != 0)
		return err;

	if (cmd == GET_MODULE_INFO) {
		err = get_module_info(arg);
		goto done;
	}

	if (cmd == ADD_TARGET) {
		err = add_target(arg);
		goto done;
	}

	err = copy_from_user(&id, (u32 *) (unsigned long)arg, sizeof(u32));
	if (err < 0)
		goto done;

	/* locking handled in target_del */
	if (cmd == DEL_TARGET) {
		err = target_del(id);
		goto done;
	}

	target = target_lookup_by_id(id);
	if (!target) {
		err = -ENOENT;
		goto done;
	}

	err = target_lock(target, 1);
	if (err < 0)
		goto done;

	switch (cmd) {
	case ADD_VOLUME:
		err = add_volume(target, arg);
		break;

	case DEL_VOLUME:
		err = del_volume(target, arg);
		break;

	case ADD_SESSION:
		err = add_session(target, arg);
		break;

	case DEL_SESSION:
		err = del_session(target, arg);
		break;

	case GET_SESSION_INFO:
		err = get_session_info(target, arg);
		break;

	case ISCSI_PARAM_SET:
		err = iscsi_param_config(target, arg, 1);
		break;

	case ISCSI_PARAM_GET:
		err = iscsi_param_config(target, arg, 0);
		break;

	case ADD_CONN:
		err = add_conn(target, arg);
		break;

	case DEL_CONN:
		err = del_conn(target, arg);
		break;

	case GET_CONN_INFO:
		err = get_conn_info(target, arg);
		break;
	default:
		eprintk("invalid ioctl cmd %lx\n", (unsigned long)cmd);
		err = -EINVAL;
	}

	target_unlock(target);
done:
	mutex_unlock(&ioctl_mutex);

#ifdef FREEBSD
	if (err < 0)
		err = -(err);
#endif
	return err;
}