Lines Matching refs:item

81 static struct mtx	ngq_mtx;	/* protects the queue item list */
217 static int ng_generic_msg(node_p here, item_p item, hook_p lasthook);
222 static int ng_apply_item(node_p node, item_p item, int rw);
225 static int ng_con_nodes(item_p item, node_p node, const char *name,
227 static int ng_con_part2(node_p node, item_p item, hook_p hook);
228 static int ng_con_part3(node_p node, item_p item, hook_p hook);
251 "netgraph item structures");
1334 ng_con_part3(node_p node, item_p item, hook_p hook)
1372 NG_FREE_ITEM(item);
1377 ng_con_part2(node_p node, item_p item, hook_p hook)
1453 if ((error = ng_send_fn2(peer->hk_node, peer, item, &ng_con_part3,
1457 return (error); /* item was consumed. */
1460 return (0); /* item was consumed. */
1462 NG_FREE_ITEM(item);
1471 ng_con_nodes(item_p item, node_p node, const char *name,
1505 if ((error = ng_send_fn2(node2, hook2, item, &ng_con_part2, NULL, 0,
1850 static __inline void ng_queue_rw(node_p node, item_p item, int rw);
1852 static __inline item_p ng_acquire_read(node_p node, item_p item);
1853 static __inline item_p ng_acquire_write(node_p node, item_p item);
1910 /* How to decide what the next queued item is. */
1914 /* Read the status to decide if the next item on the queue can now run. */
1934 * because the node was in a state where it cannot yet process the next item
1940 item_p item;
1955 * From here, we can assume there is a head item.
1992 item = STAILQ_FIRST(&ngq->queue);
1996 CTR6(KTR_NET, "%20s: node [%x] (%p) returning item %p as %s; queue "
1997 "flags 0x%lx", __func__, node->nd_ID, node, item, *rw ? "WRITER" :
1999 return (item);
2007 ng_queue_rw(node_p node, item_p item, int rw)
2011 NGI_SET_WRITER(item);
2013 NGI_SET_READER(item);
2014 item->depth = 1;
2017 /* Set OP_PENDING flag and enqueue the item. */
2019 STAILQ_INSERT_TAIL(&ngq->queue, item, el_next);
2021 CTR5(KTR_NET, "%20s: node [%x] (%p) queued item %p as %s", __func__,
2022 node->nd_ID, node, item, rw ? "WRITER" : "READER" );
2035 ng_acquire_read(node_p node, item_p item)
2048 CTR4(KTR_NET, "%20s: node [%x] (%p) acquired item %p",
2049 __func__, node->nd_ID, node, item);
2050 return (item);
2056 ng_queue_rw(node, item, NGQRW_R);
2063 ng_acquire_write(node_p node, item_p item)
2072 CTR4(KTR_NET, "%20s: node [%x] (%p) acquired item %p",
2073 __func__, node->nd_ID, node, item);
2074 return (item);
2078 ng_queue_rw(node, item, NGQRW_W);
2085 ng_upgrade_write(node_p node, item_p item)
2091 NGI_SET_WRITER(item);
2109 /* It's just us, act on the item. */
2111 ng_apply_item(node, item, 0);
2114 * Having acted on the item, atomically
2130 /* We've gone from, 0 to 1 item in the queue */
2136 STAILQ_INSERT_HEAD(&ngq->queue, item, el_next);
2137 CTR4(KTR_NET, "%20s: node [%x] (%p) requeued item %p as WRITER",
2138 __func__, node->nd_ID, node, item );
2169 item_p item;
2172 while ((item = STAILQ_FIRST(&ngq->queue)) != NULL) {
2178 /* If the item is supplying a callback, call it with an error */
2179 if (item->apply != NULL) {
2180 if (item->depth == 1)
2181 item->apply->error = ENOENT;
2182 if (refcount_release(&item->apply->refs)) {
2183 (*item->apply->apply)(item->apply->context,
2184 item->apply->error);
2187 NG_FREE_ITEM(item);
2198 * The module code should have filled out the item correctly by this stage:
2217 ng_snd_item(item_p item, int flags)
2225 /* We are sending item, so it must be present! */
2226 KASSERT(item != NULL, ("ng_snd_item: item is NULL"));
2229 _ngi_check(item, __FILE__, __LINE__);
2233 if (item->apply)
2234 refcount_acquire(&item->apply->refs);
2236 node = NGI_NODE(item);
2240 hook = NGI_HOOK(item);
2242 if ((item->el_flags & NGQF_TYPE) == NGQF_DATA) {
2244 if (NGI_M(item) == NULL)
2246 CHECK_DATA_MBUF(NGI_M(item));
2250 * If the item or the node specifies single threading, force
2254 if (((item->el_flags & NGQF_RW) == NGQF_WRITER) ||
2294 ng_queue_rw(node, item, rw);
2303 item = ng_acquire_read(node, item);
2305 item = ng_acquire_write(node, item);
2308 if (item == NULL)
2311 NGI_GET_NODE(item, node); /* zaps stored node */
2313 item->depth++;
2314 error = ng_apply_item(node, item, rw); /* drops r/w lock when done */
2335 if (item->apply != NULL) {
2336 if (item->depth == 0 && error != 0)
2337 item->apply->error = error;
2338 if (refcount_release(&item->apply->refs)) {
2339 (*item->apply->apply)(item->apply->context,
2340 item->apply->error);
2344 NG_FREE_ITEM(item);
2349 * We have an item that was possibly queued somewhere.
2355 ng_apply_item(node_p node, item_p item, int rw)
2363 /* Node and item are never optional. */
2365 KASSERT(item != NULL, ("ng_apply_item: item is NULL"));
2367 NGI_GET_HOOK(item, hook); /* clears stored hook */
2369 _ngi_check(item, __FILE__, __LINE__);
2372 apply = item->apply;
2373 depth = item->depth;
2375 switch (item->el_flags & NGQF_TYPE) {
2384 NG_FREE_ITEM(item);
2394 NG_FREE_ITEM(item);
2397 error = (*rcvdata)(hook, item);
2416 NG_FREE_ITEM(item);
2429 if ((NGI_MSG(item)->header.typecookie == NGM_GENERIC_COOKIE) &&
2430 ((NGI_MSG(item)->header.flags & NGF_RESP) == 0)) {
2431 error = ng_generic_msg(node, item, hook);
2438 NG_FREE_ITEM(item);
2441 error = (*rcvmsg)(node, item, hook);
2450 NGI_FN(item) != &ng_rmnode) {
2453 NG_FREE_ITEM(item);
2458 NGI_FN2(item) != &ng_con_part2 &&
2459 NGI_FN2(item) != &ng_con_part3 &&
2460 NGI_FN(item) != &ng_rmhook_part2) {
2463 NG_FREE_ITEM(item);
2467 if ((item->el_flags & NGQF_TYPE) == NGQF_FN) {
2468 (*NGI_FN(item))(node, hook, NGI_ARG1(item),
2469 NGI_ARG2(item));
2470 NG_FREE_ITEM(item);
2472 error = (*NGI_FN2(item))(node, item, hook);
2477 * that we took from the item. Now that we have
2503 ng_generic_msg(node_p here, item_p item, hook_p lasthook)
2509 NGI_GET_MSG(item, msg);
2552 error = ng_con_nodes(item, here, con->ourhook,
2916 * This means we must assume that the item/msg is already freed
2920 NGI_MSG(item) = msg; /* put it back as we found it */
2921 return((*here->nd_type->rcvmsg)(here, item, lasthook));
2932 * I break them appart here, because erros may cause a free if the item
2937 NG_RESPOND_MSG(error, here, item, resp);
2977 item_p item;
2980 ("%s: incorrect item type: %d", __func__, type));
2982 item = uma_zalloc((type == NGQF_DATA) ? ng_qdzone : ng_qzone,
2985 if (item) {
2986 item->el_flags = type;
2989 TAILQ_INSERT_TAIL(&ng_itemlist, item, all);
2995 return (item);
3002 ng_free_item(item_p item)
3005 * The item may hold resources on it's own. We need to free
3006 * these before we can free the item. What they are depends upon
3007 * what kind of item it is. it is important that nodes zero
3008 * out pointers to resources that they remove from the item
3011 switch (item->el_flags & NGQF_TYPE) {
3014 NG_FREE_M(_NGI_M(item));
3017 _NGI_RETADDR(item) = 0;
3018 NG_FREE_MSG(_NGI_MSG(item));
3023 _NGI_FN(item) = NULL;
3024 _NGI_ARG1(item) = NULL;
3025 _NGI_ARG2(item) = 0;
3029 _NGI_CLR_NODE(item);
3030 _NGI_CLR_HOOK(item);
3034 TAILQ_REMOVE(&ng_itemlist, item, all);
3038 uma_zfree(((item->el_flags & NGQF_TYPE) == NGQF_DATA) ?
3039 ng_qdzone : ng_qzone, item);
3049 item_p item;
3054 ("%s: incorrect item type: %d", __func__, type));
3059 /* If reallocation is required do it and copy item. */
3060 if ((item = ng_alloc_item(type, flags)) == NULL) {
3064 *item = *pitem;
3067 item = pitem;
3068 item->el_flags = (item->el_flags & ~NGQF_TYPE) | type;
3070 return (item);
3210 mtx_init(&ngq_mtx, "netgraph item list mutex", NULL,
3288 dumpitem(item_p item, char *file, int line)
3290 printf(" ACTIVE item, last used at %s, line %d",
3291 item->lastfile, item->lastline);
3292 switch(item->el_flags & NGQF_TYPE) {
3297 printf(" - retaddr[%d]:\n", _NGI_RETADDR(item));
3301 _NGI_FN(item),
3302 _NGI_NODE(item),
3303 _NGI_HOOK(item),
3304 item->body.fn.fn_arg1,
3305 item->body.fn.fn_arg2,
3306 item->body.fn.fn_arg2);
3310 _NGI_FN2(item),
3311 _NGI_NODE(item),
3312 _NGI_HOOK(item),
3313 item->body.fn.fn_arg1,
3314 item->body.fn.fn_arg2,
3315 item->body.fn.fn_arg2);
3320 if (_NGI_NODE(item)) {
3322 _NGI_NODE(item), ng_node2ID(_NGI_NODE(item)));
3330 item_p item;
3332 TAILQ_FOREACH(item, &ng_itemlist, all) {
3334 dumpitem(item, NULL, 0);
3393 * try get an item to process off it. Remove the node from the list.
3414 * let you have another item off the queue.
3420 item_p item;
3424 item = ng_dequeue(node, &rw);
3425 if (item == NULL) {
3431 NGI_GET_NODE(item, node); /* zaps stored node */
3432 ng_apply_item(node, item, rw);
3472 * Externally useable functions to set up a queue item ready for sending
3478 if (NGI_NODE(item) ) { \
3479 printf("item already has node"); \
3481 NGI_CLR_NODE(item); \
3483 if (NGI_HOOK(item) ) { \
3484 printf("item already has hook"); \
3486 NGI_CLR_HOOK(item); \
3494 * Put mbuf into the item.
3495 * Hook and node references will be removed when the item is dequeued.
3500 * a writer item on both nodes and we must have at least a reader
3509 item_p item;
3511 if ((item = ng_alloc_item(NGQF_DATA, flags)) == NULL) {
3516 item->el_flags |= NGQF_READER;
3517 NGI_M(item) = m;
3518 return (item);
3522 * Allocate a queue item and put items into it..
3525 * Hook and node references will be removed when the item is dequeued.
3531 item_p item;
3533 if ((item = ng_alloc_item(NGQF_MESG, flags)) == NULL) {
3540 item->el_flags |= NGQF_READER;
3542 item->el_flags |= NGQF_WRITER;
3544 * Set the current lasthook into the queue item
3546 NGI_MSG(item) = msg;
3547 NGI_RETADDR(item) = 0;
3548 return (item);
3551 #define SET_RETADDR(item, here, retaddr) \
3553 if ((item->el_flags & NGQF_TYPE) == NGQF_MESG) { \
3555 NGI_RETADDR(item) = retaddr; \
3562 if (NGI_RETADDR(item) == 0) { \
3563 NGI_RETADDR(item) \
3571 ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr)
3586 NG_FREE_ITEM(item);
3597 NGI_SET_HOOK(item, peer);
3598 NGI_SET_NODE(item, peernode);
3599 SET_RETADDR(item, here, retaddr);
3607 ng_address_path(node_p here, item_p item, const char *address, ng_ID_t retaddr)
3620 NG_FREE_ITEM(item);
3623 NGI_SET_NODE(item, dest);
3625 NGI_SET_HOOK(item, hook);
3627 SET_RETADDR(item, here, retaddr);
3632 ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr)
3642 NG_FREE_ITEM(item);
3647 NGI_SET_NODE(item, dest);
3648 NGI_CLR_HOOK(item);
3649 SET_RETADDR(item, here, retaddr);
3661 item_p item;
3668 if ((item = ng_alloc_item(NGQF_MESG, NG_NOFLAGS)) == NULL) {
3674 item->el_flags |= NGQF_WRITER;
3676 NGI_SET_NODE(item, here);
3679 NGI_SET_HOOK(item, hook);
3681 NGI_MSG(item) = msg;
3682 NGI_RETADDR(item) = ng_node2ID(here);
3683 return (item);
3701 item_p item;
3703 if ((item = ng_alloc_item(NGQF_FN, flags)) == NULL) {
3706 item->el_flags |= NGQF_WRITER;
3707 NG_NODE_REF(node); /* and one for the item */
3708 NGI_SET_NODE(item, node);
3711 NGI_SET_HOOK(item, hook);
3713 NGI_FN(item) = fn;
3714 NGI_ARG1(item) = arg1;
3715 NGI_ARG2(item) = arg2;
3716 return(ng_snd_item(item, flags));
3723 * callback will be copied to the new item. If also NG_REUSE_ITEM
3724 * flag is set, no new item will be allocated, but pitem will
3731 item_p item;
3737 * Allocate a new item if no supplied or
3741 if ((item = ng_alloc_item(NGQF_FN2, flags)) == NULL)
3744 item->apply = pitem->apply;
3746 if ((item = ng_realloc_item(pitem, NGQF_FN2, flags)) == NULL)
3750 item->el_flags = (item->el_flags & ~NGQF_RW) | NGQF_WRITER;
3751 NG_NODE_REF(node); /* and one for the item */
3752 NGI_SET_NODE(item, node);
3755 NGI_SET_HOOK(item, hook);
3757 NGI_FN2(item) = fn;
3758 NGI_ARG1(item) = arg1;
3759 NGI_ARG2(item) = arg2;
3760 return(ng_snd_item(item, flags));
3769 item_p item = arg;
3771 CURVNET_SET(NGI_NODE(item)->nd_vnet);
3772 ng_snd_item(item, 0);
3780 item_p item, oitem;
3782 if ((item = ng_alloc_item(NGQF_FN, NG_NOFLAGS)) == NULL)
3785 item->el_flags |= NGQF_WRITER;
3786 NG_NODE_REF(node); /* and one for the item */
3787 NGI_SET_NODE(item, node);
3790 NGI_SET_HOOK(item, hook);
3792 NGI_FN(item) = fn;
3793 NGI_ARG1(item) = arg1;
3794 NGI_ARG2(item) = arg2;
3796 if (callout_reset(c, ticks, &ng_callout_trampoline, item) == 1 &&
3806 item_p item;
3813 item = c->c_arg;
3816 (NGI_NODE(item) == node)) {
3822 NG_FREE_ITEM(item);
3833 ng_replace_retaddr(node_p here, item_p item, ng_ID_t retaddr)
3836 NGI_RETADDR(item) = retaddr;
3842 NGI_RETADDR(item) = ng_node2ID(here);