Exemple #1
0
odp_pktio_t odp_pktio_lookup(const char *dev)
{
	odp_pktio_t id = ODP_PKTIO_INVALID;
	pktio_entry_t *entry;
	int i;

	odp_spinlock_lock(&pktio_tbl->lock);

	for (i = 1; i <= ODP_CONFIG_PKTIO_ENTRIES; ++i) {
		entry = get_pktio_entry(_odp_cast_scalar(odp_pktio_t, i));
		if (!entry || is_free(entry))
			continue;

		lock_entry(entry);

		if (!is_free(entry) &&
		    strncmp(entry->s.name, dev, IF_NAMESIZE) == 0)
			id = _odp_cast_scalar(odp_pktio_t, i);

		unlock_entry(entry);

		if (id != ODP_PKTIO_INVALID)
			break;
	}

	odp_spinlock_unlock(&pktio_tbl->lock);

	return id;
}
int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
{
	pktio_entry_t *pktio_entry = get_entry(id);
	int pkts;

	if (pktio_entry == NULL)
		return -1;

	lock_entry(pktio_entry);
	switch (pktio_entry->s.params.type) {
	case ODP_PKTIO_TYPE_SOCKET_BASIC:
		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
				pkt_table, len);
		break;
	case ODP_PKTIO_TYPE_SOCKET_MMSG:
		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
				pkt_table, len);
		break;
	case ODP_PKTIO_TYPE_SOCKET_MMAP:
		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
				pkt_table, len);
		break;
#ifdef ODP_HAVE_NETMAP
	case ODP_PKTIO_TYPE_NETMAP:
		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
				pkt_table, len);
		break;
#endif
	default:
		pkts = -1;
	}
	unlock_entry(pktio_entry);

	return pkts;
}
Exemple #3
0
static int open_unlock_delegate(
    IN nfs41_open_state *open,
    IN const nfs41_lock_state *input)
{
    struct list_entry *entry;
    int status = ERROR_NOT_LOCKED;

    AcquireSRWLockExclusive(&open->lock);

    /* find lock state that matches this range */
    entry = list_search(&open->locks.list, input, lock_range_cmp);
    if (entry) {
        nfs41_lock_state *lock = lock_entry(entry);
        if (lock->delegated) {
            /* if the lock was delegated, remove/free it and return success */
            list_remove(entry);
            free(lock);
            status = NO_ERROR;
        } else
            status = ERROR_LOCKED;
    }

    ReleaseSRWLockExclusive(&open->lock);
    return status;
}
Exemple #4
0
static int lock_range_cmp(const struct list_entry *entry, const void *value)
{
    const nfs41_lock_state *lhs = lock_entry(entry);
    const nfs41_lock_state *rhs = (const nfs41_lock_state*)value;
    if (lhs->offset != rhs->offset) return -1;
    if (lhs->length != rhs->length) return -1;
    return 0;
}
Exemple #5
0
int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], int len)
{
	pktio_entry_t *pktio_entry = get_pktio_entry(id);
	int pkts;

	if (pktio_entry == NULL)
		return -1;

	lock_entry(pktio_entry);
	pkts = pktio_entry->s.ops->send(pktio_entry, pkt_table, len);
	unlock_entry(pktio_entry);

	return pkts;
}
int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
{
	pktio_entry_t *pktio_entry = get_entry(id);
	unsigned pkts = 0;
	odp_buffer_t buf;

	if (pktio_entry == NULL)
		return -1;

	lock_entry(pktio_entry);

	if (pktio_entry->s.inq_default == ODP_QUEUE_INVALID) {
		char name[ODP_QUEUE_NAME_LEN];
		odp_queue_param_t qparam;
		odp_queue_t inq_def;
		/*
		 * Create a default input queue.
		 * FIXME: IT is a kind of WA for current ODP API usage.
		 * It should be revised.
		 */
		ODP_DBG("Creating default input queue\n");
		qparam.sched.prio  = ODP_SCHED_PRIO_DEFAULT;
		qparam.sched.sync  = ODP_SCHED_SYNC_NONE;
		qparam.sched.group = ODP_SCHED_GROUP_DEFAULT;
		snprintf(name, sizeof(name), "%i-pktio_inq_default", (int)id);
		name[ODP_QUEUE_NAME_LEN-1] = '\0';
		inq_def = odp_queue_create(name, ODP_QUEUE_TYPE_PKTIN, &qparam);
		if (inq_def == ODP_QUEUE_INVALID) {
			ODP_ERR("pktio queue creation failed\n");
			goto unlock;
		}

		if (odp_pktio_inq_setdef(id, inq_def)) {
			ODP_ERR("default input-Q setup\n");
			goto unlock;
		}
	}

	for (pkts = 0; pkts < len; pkts++) {
		buf = odp_queue_deq(pktio_entry->s.inq_default);
		if (!odp_buffer_is_valid(buf))
			break;

		pkt_table[pkts] = odp_packet_from_buffer(buf);
	}
unlock:
	unlock_entry(pktio_entry);
	return pkts;
}
Exemple #7
0
int odp_pktio_inq_setdef(odp_pktio_t id, odp_queue_t queue)
{
	pktio_entry_t *pktio_entry = get_pktio_entry(id);
	queue_entry_t *qentry;

	if (pktio_entry == NULL || queue == ODP_QUEUE_INVALID)
		return -1;

	qentry = queue_to_qentry(queue);

	if (qentry->s.type != ODP_QUEUE_TYPE_PKTIN)
		return -1;

	lock_entry(pktio_entry);
	pktio_entry->s.inq_default = queue;
	unlock_entry(pktio_entry);

	switch (qentry->s.type) {
	/* Change to ODP_QUEUE_TYPE_POLL when ODP_QUEUE_TYPE_PKTIN is removed */
	case ODP_QUEUE_TYPE_PKTIN:

		/* User polls the input queue */
		queue_lock(qentry);
		qentry->s.pktin = id;
		queue_unlock(qentry);

		/* Uncomment when ODP_QUEUE_TYPE_PKTIN is removed
		        break;
		   case ODP_QUEUE_TYPE_SCHED:
		 */

		/* Packet input through the scheduler */
		if (schedule_pktio_start(id, ODP_SCHED_PRIO_LOWEST)) {
			ODP_ERR("Schedule pktio start failed\n");
			return -1;
		}

		break;
	default:
		ODP_ABORT("Bad queue type\n");
	}

	return 0;
}
Exemple #8
0
static void open_unlock_remove(
    IN nfs41_open_state *open,
    IN const stateid_arg *stateid,
    IN const nfs41_lock_state *input)
{
    struct list_entry *entry;

    AcquireSRWLockExclusive(&open->lock);
    if (stateid->type == STATEID_LOCK)
        lock_stateid_update(open, &stateid->stateid);

    /* find and remove the unlocked range */
    entry = list_search(&open->locks.list, input, lock_range_cmp);
    if (entry) {
        list_remove(entry);
        free(lock_entry(entry));
    }
    ReleaseSRWLockExclusive(&open->lock);
}
Exemple #9
0
void ts_onreply(struct cell* t, int type, struct tmcb_params *param)
{
	ts_urecord_t* _r;
	ts_entry_t* _e;
	ts_transaction_t *cb_ptr, *ptr;

	if(t_table==0) return;
	if((type & (TMCB_DESTROY)) && destroy_modules_phase()) return;

	cb_ptr = (ts_transaction_t*)(*param->param);
	if (cb_ptr == NULL) {
		LM_DBG("NULL param for type %d\n", type);
		return;
	}

	if (type &(TMCB_DESTROY)) {
		LM_DBG("TMCB_DESTROY called for transaction %u:%u\n", cb_ptr->tindex, cb_ptr->tlabel);
		_r = cb_ptr->urecord;
		_e = _r->entry;
		lock_entry(_e);
		ptr = _r->transactions;
		while(ptr) {
			if ((ptr->tindex == cb_ptr->tindex) && (ptr->tlabel == cb_ptr->tlabel)) {
				remove_ts_transaction(ptr);

				if (_r->transactions == NULL) {
					LM_DBG("last transaction for %.*s, removing urecord\n", _r->ruri.len, _r->ruri.s);
					remove_ts_urecord(_r);
				}
				unlock_entry(_e);
				return;
			}
			ptr = ptr->next;
		}
		LM_DBG("transaction %u:%u not found\n",cb_ptr->tindex, cb_ptr->tlabel);
		unlock_entry(_e);
	} else {
		LM_DBG("called with uknown type %d\n", type);
	}

	return;
}
int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
{
	pktio_entry_t *pktio_entry = get_entry(id);
	unsigned pkts;
	int ret;

	if (pktio_entry == NULL)
		return -1;

	lock_entry(pktio_entry);

	for (pkts = 0; pkts < len; pkts++) {
		ret = odp_queue_enq(pktio_entry->s.outq_default,
				    odp_buffer_from_packet(pkt_table[pkts]));
		if (ret)
			break;
	}
	unlock_entry(pktio_entry);
	return pkts;
}
static odp_pktio_t alloc_lock_pktio_entry(odp_pktio_params_t *params)
{
	odp_pktio_t id;
	pktio_entry_t *entry;
	int i;

	for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) {
		entry = &pktio_tbl->entries[i];
		if (is_free(entry)) {
			lock_entry(entry);
			if (is_free(entry)) {
				init_pktio_entry(entry, params);
				id = i + 1;
				return id; /* return with entry locked! */
			}
			unlock_entry(entry);
		}
	}

	return ODP_PKTIO_INVALID;
}
Exemple #12
0
int odp_pktio_inq_remdef(odp_pktio_t id)
{
	pktio_entry_t *pktio_entry = get_pktio_entry(id);
	odp_queue_t queue;
	queue_entry_t *qentry;

	if (pktio_entry == NULL)
		return -1;

	lock_entry(pktio_entry);
	queue  = pktio_entry->s.inq_default;
	qentry = queue_to_qentry(queue);

	queue_lock(qentry);
	qentry->s.pktin = ODP_PKTIO_INVALID;
	queue_unlock(qentry);

	pktio_entry->s.inq_default = ODP_QUEUE_INVALID;
	unlock_entry(pktio_entry);

	return 0;
}
int odp_pktio_close(odp_pktio_t id)
{
	pktio_entry_t *entry;
	int res = -1;

	entry = get_entry(id);
	if (entry == NULL)
		return -1;

	lock_entry(entry);
	if (!is_free(entry)) {
		/* FIXME: Here rx/tx channels should be closed */
		res |= free_pktio_entry(id);
	}

	unlock_entry(entry);

	if (res != 0)
		return -1;

	return 0;
}
Exemple #14
0
int odp_pktio_close(odp_pktio_t id)
{
	pktio_entry_t *entry;
	int res = -1;

	entry = get_pktio_entry(id);
	if (entry == NULL)
		return -1;

	lock_entry(entry);
	if (!is_free(entry)) {
		res  = entry->s.ops->close(entry);
		res |= free_pktio_entry(id);
	}

	unlock_entry(entry);

	if (res != 0)
		return -1;

	return 0;
}
static odp_pktio_t alloc_lock_pktio_entry(odp_pktio_params_t *params)
{
	odp_pktio_t id;
	pktio_entry_t *entry;
	int i;
	(void)params;
	for (i = 0; i < ODP_CONFIG_PKTIO_ENTRIES; ++i) {
		entry = &pktio_tbl->entries[i];
		if (is_free(entry)) {
			lock_entry(entry);
			if (is_free(entry)) {
				set_taken(entry);
				entry->s.inq_default = ODP_QUEUE_INVALID;
				entry->s.outq_default = ODP_QUEUE_INVALID;
				id = i + 1;
				return id; /* return with entry locked! */
			}
			unlock_entry(entry);
		}
	}

	return ODP_PKTIO_INVALID;
}
int odp_pktio_inq_setdef(odp_pktio_t id, odp_queue_t queue)
{
	pktio_entry_t *pktio_entry = get_entry(id);
	queue_entry_t *qentry = queue_to_qentry(queue);

	if (pktio_entry == NULL || qentry == NULL)
		return -1;

	if (qentry->s.type != ODP_QUEUE_TYPE_PKTIN)
		return -1;

	lock_entry(pktio_entry);
	pktio_entry->s.inq_default = queue;
	unlock_entry(pktio_entry);

	queue_lock(qentry);
	qentry->s.pktin = id;
	qentry->s.status = QUEUE_STATUS_SCHED;
	queue_unlock(qentry);

	odp_schedule_queue(queue, qentry->s.param.sched.prio);

	return 0;
}
int odp_pktio_close(odp_pktio_t id)
{
	pktio_entry_t *entry;
	int res = -1;

	entry = get_entry(id);
	if (entry == NULL)
		return -1;

	lock_entry(entry);
	if (!is_free(entry)) {
		switch (entry->s.params.type) {
		case ODP_PKTIO_TYPE_SOCKET_BASIC:
		case ODP_PKTIO_TYPE_SOCKET_MMSG:
			res  = close_pkt_sock(&entry->s.pkt_sock);
			break;
		case ODP_PKTIO_TYPE_SOCKET_MMAP:
			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
			break;
#ifdef ODP_HAVE_NETMAP
		case ODP_PKTIO_TYPE_NETMAP:
			res  = close_pkt_netmap(&entry->s.pkt_nm);
			break;
#endif
		default:
			break;
		res |= free_pktio_entry(id);
		}
	}
	unlock_entry(entry);

	if (res != 0)
		return -1;

	return 0;
}
Exemple #18
0
/*!
 * \brief Dump the content of the tsilo table
 * \param rpc RPC node that should be filled
 * \param c RPC void pointer
 */
static void rpc_tsilo_dump(rpc_t *rpc, void *c)
{
	ts_transaction_t* trans;
	struct ts_urecord* record;
	struct ts_entry* entry;

	str brief = {0, 0};

	int max, res, n, ntrans, i;
	int short_dump = 0;

	void* th;
	void* ah;
	void* ih;
	void* sh;

	rpc->scan(c, "*S", &brief);

	if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0))
		/* short version */
		short_dump = 1;

	if (rpc->add(c, "{", &th) < 0)
	{
		rpc->fault(c, 500, "Internal error creating top rpc");
		return;
	}

	if (short_dump==0) {
		res = rpc->struct_add(th, "d{",
			"Size",		t_table->size,
			"R-URIs",	&ah);
	} else {
		res = rpc->struct_add(th, "d",
			"Size",		t_table->size);
	}
	if (res<0)
	{
		rpc->fault(c, 500, "Internal error creating inner struct");
		return;
	}

	/* add the entries per hash */
	for(i=0,n=0,max=0,ntrans=0; i<t_table->size; i++) {
		entry = &t_table->entries[i];
		lock_entry(entry);

		n += entry->n;
		if(max<entry->n)
			max= entry->n;
		for( record = entry->first ; record ; record=record->next ) {
			/* add entry */
			if(short_dump==0)
			{
				if(rpc->struct_add(ah, "Sd{",
					"R-URI", &record->ruri,
					"Hash", record->rurihash,
					"Transactions", &ih)<0)
				{
					unlock_entry(entry);
					rpc->fault(c, 500, "Internal error creating ruri struct");
					return;
				}
			}
			for( trans=record->transactions ; trans ; trans=trans->next) {
				ntrans += 1;
				if (short_dump==0) {
					if (rpc_dump_transaction(rpc, c, ih, trans) == -1) {
						unlock_entry(entry);
						return;
					}
				}
			}
		}
		unlock_entry(entry);
	}

	/* extra attributes node */
	if(rpc->struct_add(th, "{", "Stats",    &sh)<0)	{
		rpc->fault(c, 500, "Internal error creating stats struct");
		return;
	}
	if(rpc->struct_add(sh, "ddd",
		"RURIs", n,
		"Max-Slots", max,
		"Transactions", ntrans)<0)
	{
		rpc->fault(c, 500, "Internal error adding stats");
		return;
	}
}