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);
228 static void ng_worklist_add(node_p node);
231 static int ng_apply_item(node_p node, item_p item, int rw);
233 static void ng_flush_input_queue(node_p node);
236 static int ng_con_nodes(item_p item, node_p node, const char *name,
238 static int ng_con_part2(node_p node, item_p item, hook_p hook);
239 static int ng_con_part3(node_p node, item_p item, hook_p hook);
240 static int ng_mkpeer(node_p node, const char *name, const char *name2,
250 int ng_path_parse(char *addr, char **node, char **path, char **hook);
251 void ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3);
252 void ng_unname(node_p node);
268 #define _NG_ALLOC_NODE(node) \ argument
269 node = malloc(sizeof(*node), M_NETGRAPH_NODE, M_NOWAIT | M_ZERO)
327 node_p node; in ng_alloc_node() local
330 node = LIST_FIRST(&ng_freenodes); in ng_alloc_node()
331 if (node) { in ng_alloc_node()
332 LIST_REMOVE(node, nd_nodes); in ng_alloc_node()
333 bcopy(&node->nd_all, &temp, sizeof(temp)); in ng_alloc_node()
334 bzero(node, sizeof(struct ng_node)); in ng_alloc_node()
335 bcopy(&temp, &node->nd_all, sizeof(temp)); in ng_alloc_node()
337 node->nd_magic = ND_MAGIC; in ng_alloc_node()
340 _NG_ALLOC_NODE(node); in ng_alloc_node()
341 if (node) { in ng_alloc_node()
342 node->nd_magic = ND_MAGIC; in ng_alloc_node()
344 SLIST_INSERT_HEAD(&ng_allnodes, node, nd_all); in ng_alloc_node()
348 return (node); in ng_alloc_node()
352 #define NG_ALLOC_NODE(node) do { (node) = ng_alloc_node(); } while (0) argument
362 #define NG_FREE_NODE(node) \ argument
365 LIST_INSERT_HEAD(&ng_freenodes, node, nd_nodes); \
366 node->nd_magic = 0; \
373 #define NG_ALLOC_NODE(node) _NG_ALLOC_NODE(node) argument
376 #define NG_FREE_NODE(node) do { free((node), M_NETGRAPH_NODE); } while (0) argument
648 node_p node; in ng_make_node_common() local
657 NG_ALLOC_NODE(node); in ng_make_node_common()
658 if (node == NULL) { in ng_make_node_common()
662 node->nd_type = type; in ng_make_node_common()
664 node->nd_vnet = curvnet; in ng_make_node_common()
666 NG_NODE_REF(node); /* note reference */ in ng_make_node_common()
669 NG_QUEUE_LOCK_INIT(&node->nd_input_queue); in ng_make_node_common()
670 STAILQ_INIT(&node->nd_input_queue.queue); in ng_make_node_common()
671 node->nd_input_queue.q_flags = 0; in ng_make_node_common()
674 LIST_INIT(&node->nd_hooks); in ng_make_node_common()
680 node->nd_ID = V_nextID++; /* 137/sec for 1 year before wrap */ in ng_make_node_common()
683 NG_IDHASH_FIND(node->nd_ID, node2); /* already taken? */ in ng_make_node_common()
684 if ((node->nd_ID != 0) && (node2 == NULL)) { in ng_make_node_common()
691 LIST_INSERT_HEAD(&V_ng_ID_hash[NG_IDHASH_FN(node->nd_ID)], node, in ng_make_node_common()
696 *nodepp = node; in ng_make_node_common()
719 ng_rmnode(node_p node, hook_p dummy1, void *dummy2, int dummy3) in ng_rmnode() argument
724 if ((node->nd_flags & NGF_CLOSING) != 0) in ng_rmnode()
727 if (node == &ng_deadnode) { in ng_rmnode()
733 NG_NODE_REF(node); in ng_rmnode()
741 node->nd_flags |= NGF_INVALID|NGF_CLOSING; in ng_rmnode()
744 if (node->nd_type && node->nd_type->close) in ng_rmnode()
745 (*node->nd_type->close)(node); in ng_rmnode()
748 while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL) in ng_rmnode()
759 ng_flush_input_queue(node); in ng_rmnode()
763 if (node->nd_type && node->nd_type->shutdown) { in ng_rmnode()
764 (*node->nd_type->shutdown)(node); in ng_rmnode()
765 if (NG_NODE_IS_VALID(node)) { in ng_rmnode()
774 node->nd_flags &= ~(NGF_INVALID|NGF_CLOSING); in ng_rmnode()
775 NG_NODE_UNREF(node); /* Assume they still have theirs */ in ng_rmnode()
779 NG_NODE_UNREF(node); in ng_rmnode()
782 ng_unname(node); /* basically a NOP these days */ in ng_rmnode()
791 NG_NODE_UNREF(node); in ng_rmnode()
799 ng_unref_node(node_p node) in ng_unref_node() argument
802 if (node == &ng_deadnode) in ng_unref_node()
805 CURVNET_SET(node->nd_vnet); in ng_unref_node()
807 if (refcount_release(&node->nd_refs)) { /* we were the last */ in ng_unref_node()
809 node->nd_type->refs--; /* XXX maybe should get types lock? */ in ng_unref_node()
811 if (NG_NODE_HAS_NAME(node)) { in ng_unref_node()
813 LIST_REMOVE(node, nd_nodes); in ng_unref_node()
819 LIST_REMOVE(node, nd_idnodes); in ng_unref_node()
822 mtx_destroy(&node->nd_input_queue.q_mtx); in ng_unref_node()
823 NG_FREE_NODE(node); in ng_unref_node()
834 node_p node; in ng_ID2noderef() local
837 NG_IDHASH_FIND(ID, node); in ng_ID2noderef()
838 if (node) in ng_ID2noderef()
839 NG_NODE_REF(node); in ng_ID2noderef()
841 return(node); in ng_ID2noderef()
845 ng_node2ID(node_p node) in ng_node2ID() argument
847 return (node ? NG_NODE_ID(node) : 0); in ng_node2ID()
858 ng_name_node(node_p node, const char *name) in ng_name_node() argument
891 if (NG_NODE_HAS_NAME(node)) in ng_name_node()
892 LIST_REMOVE(node, nd_nodes); in ng_name_node()
896 strlcpy(NG_NODE_NAME(node), name, NG_NODESIZ); in ng_name_node()
898 LIST_INSERT_HEAD(&V_ng_name_hash[hash], node, nd_nodes); in ng_name_node()
917 node_p node; in ng_name2noderef() local
935 LIST_FOREACH(node, &V_ng_name_hash[hash], nd_nodes) in ng_name2noderef()
936 if (NG_NODE_IS_VALID(node) && in ng_name2noderef()
937 (strcmp(NG_NODE_NAME(node), name) == 0)) { in ng_name2noderef()
938 NG_NODE_REF(node); in ng_name2noderef()
943 return (node); in ng_name2noderef()
975 ng_unname(node_p node) in ng_unname() argument
988 node_p node, node2; in ng_name_rehash() local
997 LIST_FOREACH_SAFE(node, &V_ng_name_hash[i], nd_nodes, node2) { in ng_name_rehash()
999 LIST_REMOVE(node, nd_nodes); in ng_name_rehash()
1001 hash = hash32_str(NG_NODE_NAME(node), HASHINIT) & hmask; in ng_name_rehash()
1002 LIST_INSERT_HEAD(&new[hash], node, nd_nodes); in ng_name_rehash()
1019 node_p node, node2; in ng_ID_rehash() local
1028 LIST_FOREACH_SAFE(node, &V_ng_ID_hash[i], nd_idnodes, node2) { in ng_ID_rehash()
1030 LIST_REMOVE(node, nd_idnodes); in ng_ID_rehash()
1032 hash = (node->nd_ID % (hmask + 1)); in ng_ID_rehash()
1033 LIST_INSERT_HEAD(&new[hash], node, nd_idnodes); in ng_ID_rehash()
1070 ng_add_hook(node_p node, const char *name, hook_p *hookp) in ng_add_hook() argument
1080 if (ng_findhook(node, name) != NULL) { in ng_add_hook()
1094 hook->hk_node = node; in ng_add_hook()
1095 NG_NODE_REF(node); /* each hook counts as a reference */ in ng_add_hook()
1104 if (node->nd_type->newhook != NULL) { in ng_add_hook()
1105 if ((error = (*node->nd_type->newhook)(node, hook, name))) { in ng_add_hook()
1114 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_add_hook()
1115 node->nd_numhooks++; in ng_add_hook()
1131 ng_findhook(node_p node, const char *name) in ng_findhook() argument
1135 if (node->nd_type->findhook != NULL) in ng_findhook()
1136 return (*node->nd_type->findhook)(node, name); in ng_findhook()
1137 LIST_FOREACH(hook, &node->nd_hooks, hk_hooks) { in ng_findhook()
1167 node_p node; in ng_destroy_hook() local
1183 node = NG_HOOK_NODE(hook); in ng_destroy_hook()
1214 if (node == &ng_deadnode) { /* happens if called from ng_con_nodes() */ in ng_destroy_hook()
1218 node->nd_numhooks--; in ng_destroy_hook()
1219 if (node->nd_type->disconnect) { in ng_destroy_hook()
1226 (*node->nd_type->disconnect) (hook); in ng_destroy_hook()
1234 NG_NODE_UNREF(node); /* We no longer point to it so adjust count */ in ng_destroy_hook()
1347 ng_con_part3(node_p node, item_p item, hook_p hook) in ng_con_part3() argument
1390 ng_con_part2(node_p node, item_p item, hook_p hook) in ng_con_part2() argument
1405 if (ng_findhook(node, NG_HOOK_NAME(hook)) != NULL) { in ng_con_part2()
1417 if (node->nd_type->newhook != NULL) { in ng_con_part2()
1418 if ((error = (*node->nd_type->newhook)(node, hook, in ng_con_part2()
1430 hook->hk_node = node; /* just overwrite ng_deadnode */ in ng_con_part2()
1431 NG_NODE_REF(node); /* each hook counts as a reference */ in ng_con_part2()
1432 LIST_INSERT_HEAD(&node->nd_hooks, hook, hk_hooks); in ng_con_part2()
1433 node->nd_numhooks++; in ng_con_part2()
1484 ng_con_nodes(item_p item, node_p node, const char *name, in ng_con_nodes() argument
1494 if ((error = ng_add_hook(node, name, &hook))) /* gives us a ref */ in ng_con_nodes()
1547 ng_mkpeer(node_p node, const char *name, const char *name2, char *type) in ng_mkpeer() argument
1557 if ((error = ng_add_hook(node, name, &hook1))) { /* gives us a ref */ in ng_mkpeer()
1611 ng_rmnode_self(node_p node) in ng_rmnode_self() argument
1615 if (node == &ng_deadnode) in ng_rmnode_self()
1617 node->nd_flags |= NGF_INVALID; in ng_rmnode_self()
1618 if (node->nd_flags & NGF_CLOSING) in ng_rmnode_self()
1621 error = ng_send_fn(node, NULL, &ng_rmnode, NULL, 0); in ng_rmnode_self()
1626 ng_rmhook_part2(node_p node, hook_p hook, void *arg1, int arg2) in ng_rmhook_part2() argument
1636 node_p node = NG_HOOK_NODE(hook); in ng_rmhook_self() local
1638 if (node == &ng_deadnode) in ng_rmhook_self()
1641 error = ng_send_fn(node, hook, &ng_rmhook_part2, NULL, 0); in ng_rmhook_self()
1663 char *node, *path, *hook; in ng_path_parse() local
1671 node = addr; /* Here's the NODE */ in ng_path_parse()
1675 if (!*node) in ng_path_parse()
1679 if (strcmp(node, ".") != 0) { in ng_path_parse()
1680 for (k = 0; node[k]; k++) in ng_path_parse()
1681 if (node[k] == '.') in ng_path_parse()
1685 node = NULL; /* No absolute NODE */ in ng_path_parse()
1717 *nodep = node; in ng_path_parse()
1735 node_p node, oldnode; in ng_path2noderef() local
1760 node = ng_name2noderef(here, nodename); in ng_path2noderef()
1761 if (node == NULL) { in ng_path2noderef()
1770 node = here; in ng_path2noderef()
1771 NG_NODE_REF(node); in ng_path2noderef()
1777 *destp = node; in ng_path2noderef()
1806 hook = ng_findhook(node, segment); in ng_path2noderef()
1814 NG_NODE_UNREF(node); in ng_path2noderef()
1826 oldnode = node; in ng_path2noderef()
1827 if ((node = NG_PEER_NODE(hook))) in ng_path2noderef()
1828 NG_NODE_REF(node); /* XXX RACE */ in ng_path2noderef()
1830 if (NG_NODE_NOT_VALID(node)) { in ng_path2noderef()
1831 NG_NODE_UNREF(node); /* XXX more races */ in ng_path2noderef()
1846 *destp = node; in ng_path2noderef()
1863 static __inline void ng_queue_rw(node_p node, item_p item, int rw);
1864 static __inline item_p ng_dequeue(node_p node, int *rw);
1865 static __inline item_p ng_acquire_read(node_p node, item_p item);
1866 static __inline item_p ng_acquire_write(node_p node, item_p item);
1867 static __inline void ng_leave_read(node_p node);
1868 static __inline void ng_leave_write(node_p node);
1951 ng_dequeue(node_p node, int *rw) in ng_dequeue() argument
1954 struct ng_queue *ngq = &node->nd_input_queue; in ng_dequeue()
1963 node->nd_ID, node, ngq->q_flags); in ng_dequeue()
1979 __func__, node->nd_ID, node, t); in ng_dequeue()
1996 "proceed; queue flags 0x%lx", __func__, node->nd_ID, node, in ng_dequeue()
2010 "flags 0x%lx", __func__, node->nd_ID, node, item, *rw ? "WRITER" : in ng_dequeue()
2020 ng_queue_rw(node_p node, item_p item, int rw) in ng_queue_rw() argument
2022 struct ng_queue *ngq = &node->nd_input_queue; in ng_queue_rw()
2035 node->nd_ID, node, item, rw ? "WRITER" : "READER" ); in ng_queue_rw()
2042 ng_worklist_add(node); in ng_queue_rw()
2048 ng_acquire_read(node_p node, item_p item) in ng_acquire_read() argument
2050 KASSERT(node != &ng_deadnode, in ng_acquire_read()
2055 long t = node->nd_input_queue.q_flags; in ng_acquire_read()
2058 if (atomic_cmpset_acq_int(&node->nd_input_queue.q_flags, t, in ng_acquire_read()
2062 __func__, node->nd_ID, node, item); in ng_acquire_read()
2069 ng_queue_rw(node, item, NGQRW_R); in ng_acquire_read()
2076 ng_acquire_write(node_p node, item_p item) in ng_acquire_write() argument
2078 KASSERT(node != &ng_deadnode, in ng_acquire_write()
2082 if (atomic_cmpset_acq_int(&node->nd_input_queue.q_flags, 0, in ng_acquire_write()
2086 __func__, node->nd_ID, node, item); in ng_acquire_write()
2091 ng_queue_rw(node, item, NGQRW_W); in ng_acquire_write()
2098 ng_upgrade_write(node_p node, item_p item)
2100 struct ng_queue *ngq = &node->nd_input_queue;
2101 KASSERT(node != &ng_deadnode,
2124 ng_apply_item(node, item, 0);
2147 node->nd_ID, node);
2151 __func__, node->nd_ID, node, item );
2156 ng_worklist_add(node);
2165 ng_leave_read(node_p node) in ng_leave_read() argument
2167 atomic_subtract_rel_int(&node->nd_input_queue.q_flags, READER_INCREMENT); in ng_leave_read()
2172 ng_leave_write(node_p node) in ng_leave_write() argument
2174 atomic_clear_rel_int(&node->nd_input_queue.q_flags, WRITER_ACTIVE); in ng_leave_write()
2179 ng_flush_input_queue(node_p node) in ng_flush_input_queue() argument
2181 struct ng_queue *ngq = &node->nd_input_queue; in ng_flush_input_queue()
2234 node_p node; in ng_snd_item() local
2252 node = NGI_NODE(item); in ng_snd_item()
2254 KASSERT(node != NULL, ("ng_snd_item: node is NULL")); in ng_snd_item()
2272 (node->nd_flags & NGF_FORCE_WRITER) || in ng_snd_item()
2303 ((node->nd_flags & NGF_HI_STACK) || (hook && in ng_snd_item()
2311 ng_queue_rw(node, item, rw); in ng_snd_item()
2320 item = ng_acquire_read(node, item); in ng_snd_item()
2322 item = ng_acquire_write(node, item); in ng_snd_item()
2329 NGI_GET_NODE(item, node); /* zaps stored node */ in ng_snd_item()
2333 error = ng_apply_item(node, item, rw); /* drops r/w lock when done */ in ng_snd_item()
2335 error = ng_apply_item(node, item, 0); in ng_snd_item()
2340 ngq = &node->nd_input_queue; in ng_snd_item()
2344 ng_worklist_add(node); in ng_snd_item()
2353 NG_NODE_UNREF(node); in ng_snd_item()
2379 ng_apply_item(node_p node, item_p item, int rw) in ng_apply_item() argument
2388 KASSERT(node != NULL, ("ng_apply_item: node is NULL")); in ng_apply_item()
2406 NG_NODE_NOT_VALID(node)) { in ng_apply_item()
2437 if (NG_NODE_NOT_VALID(node)) { in ng_apply_item()
2455 error = ng_generic_msg(node, item, hook); in ng_apply_item()
2459 (!(rcvmsg = node->nd_type->rcvmsg))) { in ng_apply_item()
2465 error = (*rcvmsg)(node, item, hook); in ng_apply_item()
2473 if (NG_NODE_NOT_VALID(node) && in ng_apply_item()
2492 (*NGI_FN(item))(node, hook, NGI_ARG1(item), in ng_apply_item()
2496 error = (*NGI_FN2(item))(node, item, hook); in ng_apply_item()
2509 ng_leave_read(node); in ng_apply_item()
2511 ng_leave_write(node); in ng_apply_item()
2682 node_p node; in ng_generic_msg() local
2699 LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) { in ng_generic_msg()
2703 if (NG_NODE_NOT_VALID(node)) in ng_generic_msg()
2705 if (NG_NODE_HAS_NAME(node)) in ng_generic_msg()
2706 strcpy(np->name, NG_NODE_NAME(node)); in ng_generic_msg()
2707 strcpy(np->type, node->nd_type->name); in ng_generic_msg()
2708 np->id = ng_node2ID(node); in ng_generic_msg()
2709 np->hooks = node->nd_numhooks; in ng_generic_msg()
2721 node_p node; in ng_generic_msg() local
2738 LIST_FOREACH(node, &V_ng_name_hash[i], nd_nodes) { in ng_generic_msg()
2742 if (NG_NODE_NOT_VALID(node)) in ng_generic_msg()
2744 strcpy(np->name, NG_NODE_NAME(node)); in ng_generic_msg()
2745 strcpy(np->type, node->nd_type->name); in ng_generic_msg()
2746 np->id = ng_node2ID(node); in ng_generic_msg()
2747 np->hooks = node->nd_numhooks; in ng_generic_msg()
3172 node_p node = NULL, last_killed = NULL; in vnet_netgraph_uninit() local
3179 LIST_FOREACH(node, &V_ng_ID_hash[i], nd_idnodes) { in vnet_netgraph_uninit()
3180 if (node != &ng_deadnode) { in vnet_netgraph_uninit()
3181 NG_NODE_REF(node); in vnet_netgraph_uninit()
3185 if (node != NULL) in vnet_netgraph_uninit()
3191 if (node != NULL) { in vnet_netgraph_uninit()
3192 if (node == last_killed) { in vnet_netgraph_uninit()
3193 if (node->nd_flags & NGF_REALLY_DIE) in vnet_netgraph_uninit()
3195 node->nd_name); in vnet_netgraph_uninit()
3197 node->nd_flags |= NGF_REALLY_DIE; in vnet_netgraph_uninit()
3199 ng_rmnode(node, NULL, NULL, 0); in vnet_netgraph_uninit()
3200 NG_NODE_UNREF(node); in vnet_netgraph_uninit()
3201 last_killed = node; in vnet_netgraph_uninit()
3203 } while (node != NULL); in vnet_netgraph_uninit()
3300 dumpnode(node_p node, char *file, int line) in dumpnode() argument
3303 _NG_NODE_ID(node), node->nd_type->name, in dumpnode()
3304 node->nd_numhooks, node->nd_flags, in dumpnode()
3305 node->nd_refs, node->nd_name); in dumpnode()
3307 node->lastfile, node->lastline); in dumpnode()
3370 node_p node; in ng_dumpnodes() local
3373 SLIST_FOREACH(node, &ng_allnodes, nd_all) { in ng_dumpnodes()
3375 dumpnode(node, NULL, 0); in ng_dumpnodes()
3432 node_p node; in ngthread() local
3436 while ((node = STAILQ_FIRST(&ng_worklist)) == NULL) in ngthread()
3440 CURVNET_SET(node->nd_vnet); in ngthread()
3442 __func__, node->nd_ID, node); in ngthread()
3457 NG_QUEUE_LOCK(&node->nd_input_queue); in ngthread()
3458 item = ng_dequeue(node, &rw); in ngthread()
3460 node->nd_input_queue.q_flags2 &= ~NGQ2_WORKQ; in ngthread()
3461 NG_QUEUE_UNLOCK(&node->nd_input_queue); in ngthread()
3464 NG_QUEUE_UNLOCK(&node->nd_input_queue); in ngthread()
3465 NGI_GET_NODE(item, node); /* zaps stored node */ in ngthread()
3466 ng_apply_item(node, item, rw); in ngthread()
3467 NG_NODE_UNREF(node); in ngthread()
3471 NG_NODE_UNREF(node); in ngthread()
3482 ng_worklist_add(node_p node) in ng_worklist_add() argument
3485 mtx_assert(&node->nd_input_queue.q_mtx, MA_OWNED); in ng_worklist_add()
3487 if ((node->nd_input_queue.q_flags2 & NGQ2_WORKQ) == 0) { in ng_worklist_add()
3492 node->nd_input_queue.q_flags2 |= NGQ2_WORKQ; in ng_worklist_add()
3493 NG_NODE_REF(node); /* XXX safe in mutex? */ in ng_worklist_add()
3495 STAILQ_INSERT_TAIL(&ng_worklist, node, nd_input_queue.q_work); in ng_worklist_add()
3498 node->nd_ID, node); in ng_worklist_add()
3502 __func__, node->nd_ID, node); in ng_worklist_add()
3727 ng_send_fn(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2) in ng_send_fn() argument
3730 return ng_send_fn1(node, hook, fn, arg1, arg2, NG_NOFLAGS); in ng_send_fn()
3734 ng_send_fn1(node_p node, hook_p hook, ng_item_fn *fn, void * arg1, int arg2, in ng_send_fn1() argument
3743 NG_NODE_REF(node); /* and one for the item */ in ng_send_fn1()
3744 NGI_SET_NODE(item, node); in ng_send_fn1()
3764 ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, void *arg1, in ng_send_fn2() argument
3787 NG_NODE_REF(node); /* and one for the item */ in ng_send_fn2()
3788 NGI_SET_NODE(item, node); in ng_send_fn2()
3816 ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, in ng_callout() argument
3825 NG_NODE_REF(node); /* and one for the item */ in ng_callout()
3826 NGI_SET_NODE(item, node); in ng_callout()
3843 ng_uncallout(struct callout *c, node_p node) in ng_uncallout() argument
3849 KASSERT(node != NULL, ("ng_uncallout: NULL node")); in ng_uncallout()
3855 (item != NULL) && (NGI_NODE(item) == node)) { in ng_uncallout()