Lines Matching refs:node

204 #define NG_IDHASH_FIND(ID, node)					\  argument
207 LIST_FOREACH(node, &V_ng_ID_hash[NG_IDHASH_FN(ID)], \
209 if (NG_NODE_IS_VALID(node) \
210 && (NG_NODE_ID(node) == ID)) { \
223 static int ng_add_hook(node_p node, const char *name, hook_p * hookp);
227 static void ng_worklist_add(node_p node);
229 static int ng_apply_item(node_p node, item_p item, int rw);
230 static void ng_flush_input_queue(node_p node);
232 static int ng_con_nodes(item_p item, node_p node, const char *name,
234 static int ng_con_part2(node_p node, item_p item, hook_p hook);
235 static int ng_con_part3(node_p node, item_p item, hook_p hook);
236 static int ng_mkpeer(node_p node, const char *name, const char *name2,
246 int ng_path_parse(char *addr, char **node, char **path, char **hook);
247 void ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3);
248 void ng_unname(node_p node);
264 #define _NG_ALLOC_NODE(node) \ argument
265 node = malloc(sizeof(*node), M_NETGRAPH_NODE, M_NOWAIT | M_ZERO)
323 node_p node; in ng_alloc_node() local
326 node = LIST_FIRST(&ng_freenodes); in ng_alloc_node()
327 if (node) { in ng_alloc_node()
328 LIST_REMOVE(node, nd_nodes); in ng_alloc_node()
329 bcopy(&node->nd_all, &temp, sizeof(temp)); in ng_alloc_node()
330 bzero(node, sizeof(struct ng_node)); in ng_alloc_node()
331 bcopy(&temp, &node->nd_all, sizeof(temp)); in ng_alloc_node()
333 node->nd_magic = ND_MAGIC; in ng_alloc_node()
336 _NG_ALLOC_NODE(node); in ng_alloc_node()
337 if (node) { in ng_alloc_node()
338 node->nd_magic = ND_MAGIC; in ng_alloc_node()
340 SLIST_INSERT_HEAD(&ng_allnodes, node, nd_all); in ng_alloc_node()
344 return (node); in ng_alloc_node()
348 #define NG_ALLOC_NODE(node) do { (node) = ng_alloc_node(); } while (0) argument
358 #define NG_FREE_NODE(node) \ argument
361 LIST_INSERT_HEAD(&ng_freenodes, node, nd_nodes); \
362 node->nd_magic = 0; \
369 #define NG_ALLOC_NODE(node) _NG_ALLOC_NODE(node) argument
372 #define NG_FREE_NODE(node) do { free((node), M_NETGRAPH_NODE); } while (0) argument
644 node_p node; in ng_make_node_common() local
653 NG_ALLOC_NODE(node); in ng_make_node_common()
654 if (node == NULL) { in ng_make_node_common()
658 node->nd_type = type; in ng_make_node_common()
660 node->nd_vnet = curvnet; in ng_make_node_common()
662 NG_NODE_REF(node); /* note reference */ in ng_make_node_common()
665 NG_QUEUE_LOCK_INIT(&node->nd_input_queue); in ng_make_node_common()
666 STAILQ_INIT(&node->nd_input_queue.queue); in ng_make_node_common()
667 node->nd_input_queue.q_flags = 0; in ng_make_node_common()
670 LIST_INIT(&node->nd_hooks); in ng_make_node_common()
676 node->nd_ID = V_nextID++; /* 137/sec for 1 year before wrap */ in ng_make_node_common()
679 NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */ in ng_make_node_common()
680 if ((node->nd_ID != 0) && (node2 == NULL)) { in ng_make_node_common()
687 LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], node, in ng_make_node_common()
692 *nodepp = node; in ng_make_node_common()
715 ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3) in ng_rmnode() argument
720 if ((node->nd_flags & NGF_CLOSING) != 0) in ng_rmnode()
723 if (node == &ng_deadnode) { in ng_rmnode()
729 NG_NODE_REF(node); in ng_rmnode()
737 node->nd_flags |= NGF_INVALID|NGF_CLOSING; in ng_rmnode()
740 if (node->nd_type && node->nd_type->close) in ng_rmnode()
741 (*node->nd_type->close)(node); in ng_rmnode()
744 while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL) in ng_rmnode()
754 ng_flush_input_queue(node); in ng_rmnode()
757 if (node->nd_type && node->nd_type->shutdown) { in ng_rmnode()
758 (*node->nd_type->shutdown)(node); in ng_rmnode()
759 if (NG_NODE_IS_VALID(node)) { in ng_rmnode()
768 node->nd_flags &= ~(NGF_INVALID|NGF_CLOSING); in ng_rmnode()
769 NG_NODE_UNREF(node); /* Assume they still have theirs */ in ng_rmnode()
773 NG_NODE_UNREF(node); in ng_rmnode()
776 ng_unname(node); /* basically a NOP these days */ in ng_rmnode()
785 NG_NODE_UNREF(node); in ng_rmnode()
793 ng_unref_node(node_p node) in ng_unref_node() argument
796 if (node == &ng_deadnode) in ng_unref_node()
799 CURVNET_SET(node->nd_vnet); in ng_unref_node()
801 if (refcount_release(&node->nd_refs)) { /* we were the last */ in ng_unref_node()
803 node->nd_type->refs--; /* XXX maybe should get types lock? */ in ng_unref_node()
805 if (NG_NODE_HAS_NAME(node)) { in ng_unref_node()
807 LIST_REMOVE(node, nd_nodes); in ng_unref_node()
813 LIST_REMOVE(node, nd_idnodes); in ng_unref_node()
816 mtx_destroy(&node->nd_input_queue.q_mtx); in ng_unref_node()
817 NG_FREE_NODE(node); in ng_unref_node()
828 node_p node; in ng_ID2noderef() local
831 NG_IDHASH_FIND(ID, node); in ng_ID2noderef()
832 if (node) in ng_ID2noderef()
833 NG_NODE_REF(node); in ng_ID2noderef()
835 return(node); in ng_ID2noderef()
839 ng_node2ID(node_p node) in ng_node2ID() argument
841 return (node ? NG_NODE_ID(node) : 0); in ng_node2ID()
852 ng_name_node(node_p node, const char *name) in ng_name_node() argument
885 if (NG_NODE_HAS_NAME(node)) in ng_name_node()
886 LIST_REMOVE(node, nd_nodes); in ng_name_node()
890 strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ); in ng_name_node()
892 LIST_INSERT_HEAD(&V_ng_name_hash[hash], node, nd_nodes); in ng_name_node()
911 node_p node; in ng_name2noderef() local
929 LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes) in ng_name2noderef()
930 if (NG_NODE_IS_VALID(node) && in ng_name2noderef()
931 (strcmp(NG_NODE_NAME(node), name) == 0)) { in ng_name2noderef()
932 NG_NODE_REF(node); in ng_name2noderef()
937 return (node); in ng_name2noderef()
969 ng_unname(node_p node) in ng_unname() argument
982 node_p node, node2; in ng_name_rehash() local
991 LIST_FOREACH_SAFE(node, &V_ng_name_hash[i], nd_nodes, node2) { in ng_name_rehash()
993 LIST_REMOVE(node, nd_nodes); in ng_name_rehash()
995 hash = hash32_str(NG_NODE_NAME(node), HASHINIT) & hmask; in ng_name_rehash()
996 LIST_INSERT_HEAD(&new[hash], node, nd_nodes); in ng_name_rehash()
1013 node_p node, node2; in ng_ID_rehash() local
1022 LIST_FOREACH_SAFE(node, &V_ng_ID_hash[i], nd_idnodes, node2) { in ng_ID_rehash()
1024 LIST_REMOVE(node, nd_idnodes); in ng_ID_rehash()
1026 hash = (node->nd_ID % (hmask + 1)); in ng_ID_rehash()
1027 LIST_INSERT_HEAD(&new[hash], node, nd_idnodes); in ng_ID_rehash()
1064 ng_add_hook(node_p node, const char *name, hook_p *hookp) in ng_add_hook() argument
1074 if (ng_findhook(node, name) != NULL) { in ng_add_hook()
1088 hook->hk_node = node; in ng_add_hook()
1089 NG_NODE_REF(node); /* each hook counts as a reference */ in ng_add_hook()
1098 if (node->nd_type->newhook != NULL) { in ng_add_hook()
1099 if ((error = (*node->nd_type->newhook)(node, hook, name))) { in ng_add_hook()
1108 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_add_hook()
1109 node->nd_numhooks++; in ng_add_hook()
1125 ng_findhook(node_p node, const char *name) in ng_findhook() argument
1129 if (node->nd_type->findhook != NULL) in ng_findhook()
1130 return (*node->nd_type->findhook)(node, name); in ng_findhook()
1131 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { in ng_findhook()
1161 node_p node; in ng_destroy_hook() local
1177 node = NG_HOOK_NODE(hook); in ng_destroy_hook()
1208 if (node == &ng_deadnode) { /* happens if called from ng_con_nodes() */ in ng_destroy_hook()
1212 node->nd_numhooks--; in ng_destroy_hook()
1213 if (node->nd_type->disconnect) { in ng_destroy_hook()
1220 (*node->nd_type->disconnect) (hook); in ng_destroy_hook()
1228 NG_NODE_UNREF(node); /* We no longer point to it so adjust count */ in ng_destroy_hook()
1341 ng_con_part3(node_p node, item_p item, hook_p hook) in ng_con_part3() argument
1384 ng_con_part2(node_p node, item_p item, hook_p hook) in ng_con_part2() argument
1399 if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) { in ng_con_part2()
1411 if (node->nd_type->newhook != NULL) { in ng_con_part2()
1412 if ((error = (*node->nd_type->newhook)(node, hook, in ng_con_part2()
1424 hook->hk_node = node; /* just overwrite ng_deadnode */ in ng_con_part2()
1425 NG_NODE_REF(node); /* each hook counts as a reference */ in ng_con_part2()
1426 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_con_part2()
1427 node->nd_numhooks++; in ng_con_part2()
1478 ng_con_nodes(item_p item, node_p node, const char *name, in ng_con_nodes() argument
1488 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */ in ng_con_nodes()
1541 ng_mkpeer(node_p node, const char *name, const char *name2, char *type) in ng_mkpeer() argument
1551 if ((error = ng_add_hook(node, name, &hook1))) { /* gives us a ref */ in ng_mkpeer()
1605 ng_rmnode_self(node_p node) in ng_rmnode_self() argument
1609 if (node == &ng_deadnode) in ng_rmnode_self()
1611 node->nd_flags |= NGF_INVALID; in ng_rmnode_self()
1612 if (node->nd_flags & NGF_CLOSING) in ng_rmnode_self()
1615 error = ng_send_fn(node, NULL, &ng_rmnode, NULL, 0); in ng_rmnode_self()
1620 ng_rmhook_part2(node_p node, hook_p hook, void *arg1, int arg2) in ng_rmhook_part2() argument
1630 node_p node = NG_HOOK_NODE(hook); in ng_rmhook_self() local
1632 if (node == &ng_deadnode) in ng_rmhook_self()
1635 error = ng_send_fn(node, hook, &ng_rmhook_part2, NULL, 0); in ng_rmhook_self()
1657 char *node, *path, *hook; in ng_path_parse() local
1665 node = addr; /* Here's the NODE */ in ng_path_parse()
1669 if (!*node) in ng_path_parse()
1673 if (strcmp(node, ".") != 0) { in ng_path_parse()
1674 for (k = 0; node[k]; k++) in ng_path_parse()
1675 if (node[k] == '.') in ng_path_parse()
1679 node = NULL; /* No absolute NODE */ in ng_path_parse()
1711 *nodep = node; in ng_path_parse()
1729 node_p node, oldnode; in ng_path2noderef() local
1754 node = ng_name2noderef(here, nodename); in ng_path2noderef()
1755 if (node == NULL) { in ng_path2noderef()
1764 node = here; in ng_path2noderef()
1765 NG_NODE_REF(node); in ng_path2noderef()
1771 *destp = node; in ng_path2noderef()
1800 hook = ng_findhook(node, segment); in ng_path2noderef()
1808 NG_NODE_UNREF(node); in ng_path2noderef()
1820 oldnode = node; in ng_path2noderef()
1821 if ((node = NG_PEER_NODE(hook))) in ng_path2noderef()
1822 NG_NODE_REF(node); /* XXX RACE */ in ng_path2noderef()
1824 if (NG_NODE_NOT_VALID(node)) { in ng_path2noderef()
1825 NG_NODE_UNREF(node); /* XXX more races */ in ng_path2noderef()
1840 *destp = node; in ng_path2noderef()
1856 static __inline void ng_queue_rw(node_p node, item_p item, int rw);
1857 static __inline item_p ng_dequeue(node_p node, int *rw);
1858 static __inline item_p ng_acquire_read(node_p node, item_p item);
1859 static __inline item_p ng_acquire_write(node_p node, item_p item);
1860 static __inline void ng_leave_read(node_p node);
1861 static __inline void ng_leave_write(node_p node);
1944 ng_dequeue(node_p node, int *rw) in ng_dequeue() argument
1947 struct ng_queue *ngq = &node->nd_input_queue; in ng_dequeue()
1956 node->nd_ID, node, ngq->q_flags); in ng_dequeue()
1972 __func__, node->nd_ID, node, t); in ng_dequeue()
1989 "proceed; queue flags 0x%lx", __func__, node->nd_ID, node, in ng_dequeue()
2003 "flags 0x%lx", __func__, node->nd_ID, node, item, *rw ? "WRITER" : in ng_dequeue()
2013 ng_queue_rw(node_p node, item_p item, int rw) in ng_queue_rw() argument
2015 struct ng_queue *ngq = &node->nd_input_queue; in ng_queue_rw()
2028 node->nd_ID, node, item, rw ? "WRITER" : "READER" ); in ng_queue_rw()
2035 ng_worklist_add(node); in ng_queue_rw()
2041 ng_acquire_read(node_p node, item_p item) in ng_acquire_read() argument
2043 KASSERT(node != &ng_deadnode, in ng_acquire_read()
2048 long t = node->nd_input_queue.q_flags; in ng_acquire_read()
2051 if (atomic_cmpset_acq_int(&node->nd_input_queue.q_flags, t, in ng_acquire_read()
2055 __func__, node->nd_ID, node, item); in ng_acquire_read()
2062 ng_queue_rw(node, item, NGQRW_R); in ng_acquire_read()
2069 ng_acquire_write(node_p node, item_p item) in ng_acquire_write() argument
2071 KASSERT(node != &ng_deadnode, in ng_acquire_write()
2075 if (atomic_cmpset_acq_int(&node->nd_input_queue.q_flags, 0, in ng_acquire_write()
2079 __func__, node->nd_ID, node, item); in ng_acquire_write()
2084 ng_queue_rw(node, item, NGQRW_W); in ng_acquire_write()
2091 ng_upgrade_write(node_p node, item_p item)
2093 struct ng_queue *ngq = &node->nd_input_queue;
2094 KASSERT(node != &ng_deadnode,
2117 ng_apply_item(node, item, 0);
2140 node->nd_ID, node);
2144 __func__, node->nd_ID, node, item );
2149 ng_worklist_add(node);
2158 ng_leave_read(node_p node) in ng_leave_read() argument
2160 atomic_subtract_rel_int(&node->nd_input_queue.q_flags, READER_INCREMENT); in ng_leave_read()
2165 ng_leave_write(node_p node) in ng_leave_write() argument
2167 atomic_clear_rel_int(&node->nd_input_queue.q_flags, WRITER_ACTIVE); in ng_leave_write()
2172 ng_flush_input_queue(node_p node) in ng_flush_input_queue() argument
2174 struct ng_queue *ngq = &node->nd_input_queue; in ng_flush_input_queue()
2226 node_p node; in ng_snd_item() local
2242 node = NGI_NODE(item); in ng_snd_item()
2244 KASSERT(node != NULL, ("ng_snd_item: node is NULL")); in ng_snd_item()
2261 (node->nd_flags & NGF_FORCE_WRITER) || in ng_snd_item()
2292 ((node->nd_flags & NGF_HI_STACK) || (hook && in ng_snd_item()
2300 ng_queue_rw(node, item, rw); in ng_snd_item()
2309 item = ng_acquire_read(node, item); in ng_snd_item()
2311 item = ng_acquire_write(node, item); in ng_snd_item()
2317 NGI_GET_NODE(item, node); /* zaps stored node */ in ng_snd_item()
2320 error = ng_apply_item(node, item, rw); /* drops r/w lock when done */ in ng_snd_item()
2323 ngq = &node->nd_input_queue; in ng_snd_item()
2327 ng_worklist_add(node); in ng_snd_item()
2335 NG_NODE_UNREF(node); in ng_snd_item()
2361 ng_apply_item(node_p node, item_p item, int rw) in ng_apply_item() argument
2370 KASSERT(node != NULL, ("ng_apply_item: node is NULL")); in ng_apply_item()
2388 NG_NODE_NOT_VALID(node)) { in ng_apply_item()
2419 if (NG_NODE_NOT_VALID(node)) { in ng_apply_item()
2437 error = ng_generic_msg(node, item, hook); in ng_apply_item()
2441 (!(rcvmsg = node->nd_type->rcvmsg))) { in ng_apply_item()
2447 error = (*rcvmsg)(node, item, hook); in ng_apply_item()
2455 if (NG_NODE_NOT_VALID(node) && in ng_apply_item()
2474 (*NGI_FN(item))(node, hook, NGI_ARG1(item), in ng_apply_item()
2478 error = (*NGI_FN2(item))(node, item, hook); in ng_apply_item()
2490 ng_leave_read(node); in ng_apply_item()
2492 ng_leave_write(node); in ng_apply_item()
2662 node_p node; in ng_generic_msg() local
2679 LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) { in ng_generic_msg()
2683 if (NG_NODE_NOT_VALID(node)) in ng_generic_msg()
2685 if (NG_NODE_HAS_NAME(node)) in ng_generic_msg()
2686 strcpy(np->name, NG_NODE_NAME(node)); in ng_generic_msg()
2687 strcpy(np->type, node->nd_type->name); in ng_generic_msg()
2688 np->id = ng_node2ID(node); in ng_generic_msg()
2689 np->hooks = node->nd_numhooks; in ng_generic_msg()
2701 node_p node; in ng_generic_msg() local
2718 LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) { in ng_generic_msg()
2722 if (NG_NODE_NOT_VALID(node)) in ng_generic_msg()
2724 strcpy(np->name, NG_NODE_NAME(node)); in ng_generic_msg()
2725 strcpy(np->type, node->nd_type->name); in ng_generic_msg()
2726 np->id = ng_node2ID(node); in ng_generic_msg()
2727 np->hooks = node->nd_numhooks; in ng_generic_msg()
3148 node_p node = NULL, last_killed = NULL; in vnet_netgraph_uninit() local
3155 LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) { in vnet_netgraph_uninit()
3156 if (node != &ng_deadnode) { in vnet_netgraph_uninit()
3157 NG_NODE_REF(node); in vnet_netgraph_uninit()
3161 if (node != NULL) in vnet_netgraph_uninit()
3167 if (node != NULL) { in vnet_netgraph_uninit()
3168 if (node == last_killed) { in vnet_netgraph_uninit()
3169 if (node->nd_flags & NGF_REALLY_DIE) in vnet_netgraph_uninit()
3171 node->nd_name); in vnet_netgraph_uninit()
3173 node->nd_flags |= NGF_REALLY_DIE; in vnet_netgraph_uninit()
3175 ng_rmnode(node, NULL, NULL, 0); in vnet_netgraph_uninit()
3176 NG_NODE_UNREF(node); in vnet_netgraph_uninit()
3177 last_killed = node; in vnet_netgraph_uninit()
3179 } while (node != NULL); in vnet_netgraph_uninit()
3272 dumpnode(node_p node, char *file, int line) in dumpnode() argument
3275 _NG_NODE_ID(node), node->nd_type->name, in dumpnode()
3276 node->nd_numhooks, node->nd_flags, in dumpnode()
3277 node->nd_refs, node->nd_name); in dumpnode()
3279 node->lastfile, node->lastline); in dumpnode()
3342 node_p node; in ng_dumpnodes() local
3345 SLIST_FOREACH(node, &ng_allnodes, nd_all) { in ng_dumpnodes()
3347 dumpnode(node, NULL, 0); in ng_dumpnodes()
3403 node_p node; in ngthread() local
3407 while ((node = STAILQ_FIRST(&ng_worklist)) == NULL) in ngthread()
3411 CURVNET_SET(node->nd_vnet); in ngthread()
3413 __func__, node->nd_ID, node); in ngthread()
3428 NG_QUEUE_LOCK(&node->nd_input_queue); in ngthread()
3429 item = ng_dequeue(node, &rw); in ngthread()
3431 node->nd_input_queue.q_flags2 &= ~NGQ2_WORKQ; in ngthread()
3432 NG_QUEUE_UNLOCK(&node->nd_input_queue); in ngthread()
3435 NG_QUEUE_UNLOCK(&node->nd_input_queue); in ngthread()
3436 NGI_GET_NODE(item, node); /* zaps stored node */ in ngthread()
3437 ng_apply_item(node, item, rw); in ngthread()
3438 NG_NODE_UNREF(node); in ngthread()
3442 NG_NODE_UNREF(node); in ngthread()
3453 ng_worklist_add(node_p node) in ng_worklist_add() argument
3456 mtx_assert(&node->nd_input_queue.q_mtx, MA_OWNED); in ng_worklist_add()
3458 if ((node->nd_input_queue.q_flags2 & NGQ2_WORKQ) == 0) { in ng_worklist_add()
3463 node->nd_input_queue.q_flags2 |= NGQ2_WORKQ; in ng_worklist_add()
3464 NG_NODE_REF(node); /* XXX safe in mutex? */ in ng_worklist_add()
3466 STAILQ_INSERT_TAIL(&ng_worklist, node, nd_input_queue.q_work); in ng_worklist_add()
3469 node->nd_ID, node); in ng_worklist_add()
3473 __func__, node->nd_ID, node); in ng_worklist_add()
3697 ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2) in ng_send_fn() argument
3700 return ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS); in ng_send_fn()
3704 ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2, in ng_send_fn1() argument
3713 NG_NODE_REF(node); /* and one for the item */ in ng_send_fn1()
3714 NGI_SET_NODE(item, node); in ng_send_fn1()
3734 ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1, in ng_send_fn2() argument
3757 NG_NODE_REF(node); /* and one for the item */ in ng_send_fn2()
3758 NGI_SET_NODE(item, node); in ng_send_fn2()
3786 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, in ng_callout() argument
3795 NG_NODE_REF(node); /* and one for the item */ in ng_callout()
3796 NGI_SET_NODE(item, node); in ng_callout()
3813 ng_uncallout(struct callout *c, node_p node) in ng_uncallout() argument
3819 KASSERT(node != NULL, ("ng_uncallout: NULL node")); in ng_uncallout()
3825 (item != NULL) && (NGI_NODE(item) == node)) { in ng_uncallout()