Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/netmap_user.h
Show First 20 Lines • Show All 975 Lines • ▼ Show 20 Lines | nm_close(struct nm_desc *d) | ||||
free(d); | free(d); | ||||
return 0; | return 0; | ||||
} | } | ||||
static int | static int | ||||
nm_mmap(struct nm_desc *d, const struct nm_desc *parent) | nm_mmap(struct nm_desc *d, const struct nm_desc *parent) | ||||
{ | { | ||||
//XXX TODO: check if mmap is already done | if (d->done_mmap) | ||||
return 0; | |||||
vmaffione: I would just return here. If done_mmap == 1, it means that somebody already went through the… | |||||
if (IS_NETMAP_DESC(parent) && parent->mem && | if (IS_NETMAP_DESC(parent) && parent->mem && | ||||
parent->req.nr_arg2 == d->req.nr_arg2) { | parent->req.nr_arg2 == d->req.nr_arg2) { | ||||
/* do not mmap, inherit from parent */ | /* do not mmap, inherit from parent */ | ||||
D("do not mmap, inherit from parent"); | D("do not mmap, inherit from parent"); | ||||
d->memsize = parent->memsize; | d->memsize = parent->memsize; | ||||
d->mem = parent->mem; | d->mem = parent->mem; | ||||
} else { | } else { | ||||
/* XXX TODO: check if memsize is too large (or there is overflow) */ | /* XXX TODO: check if memsize is too large (or there is overflow) */ | ||||
d->memsize = d->req.nr_memsize; | d->memsize = d->req.nr_memsize; | ||||
d->mem = mmap(0, d->memsize, PROT_WRITE | PROT_READ, MAP_SHARED, | d->mem = mmap(0, d->memsize, PROT_WRITE | PROT_READ, MAP_SHARED, | ||||
d->fd, 0); | d->fd, 0); | ||||
if (d->mem == MAP_FAILED) { | if (d->mem == MAP_FAILED) { | ||||
goto fail; | goto fail; | ||||
} | } | ||||
d->done_mmap = 1; | d->done_mmap = 1; | ||||
} | } | ||||
{ | { | ||||
Not Done Inline ActionsThis can go away (see above). vmaffione: This can go away (see above). | |||||
struct netmap_if *nifp = NETMAP_IF(d->mem, d->req.nr_offset); | struct netmap_if *nifp = NETMAP_IF(d->mem, d->req.nr_offset); | ||||
struct netmap_ring *r = NETMAP_RXRING(nifp, d->first_rx_ring); | struct netmap_ring *r = NETMAP_RXRING(nifp, d->first_rx_ring); | ||||
if ((void *)r == (void *)nifp) { | if ((void *)r == (void *)nifp) { | ||||
/* the descriptor is open for TX only */ | /* the descriptor is open for TX only */ | ||||
r = NETMAP_TXRING(nifp, d->first_tx_ring); | r = NETMAP_TXRING(nifp, d->first_tx_ring); | ||||
} | } | ||||
*(struct netmap_if **)(uintptr_t)&(d->nifp) = nifp; | *(struct netmap_if **)(uintptr_t)&(d->nifp) = nifp; | ||||
▲ Show 20 Lines • Show All 164 Lines • Show Last 20 Lines |
I would just return here. If done_mmap == 1, it means that somebody already went through the initializations a the end of this function.