Date: Fri, 28 May 2004 15:08:32 +0400 From: Gleb Smirnoff <glebius@cell.sick.ru> To: Julian Elischer <julian@elischer.org> Cc: Harti Brandt <harti@freebsd.org> Subject: Re: shutdown node VS disconnect all hooks Message-ID: <20040528110832.GA43696@cell.sick.ru> In-Reply-To: <Pine.BSF.4.21.0405280128570.63204-100000@InterJet.elischer.org> References: <Pine.GSO.4.60.0405281022360.18426@zeus> <Pine.BSF.4.21.0405280128570.63204-100000@InterJet.elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--CE+1k2dSO48ffgeK Content-Type: text/plain; charset=koi8-r Content-Disposition: inline On Fri, May 28, 2004 at 01:31:09AM -0700, Julian Elischer wrote: J> It'd be best to make the change to sparse initialisers a separate patch J> that I cold commit separatly, J> so reduce teh size of the functionality change patch. And here is next patch, that must be applied after c99-patch. It introduces a pre-shutdown method - ng_close_t. And it makes ng_tee behave exactly the way it does in STABLE. -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE --CE+1k2dSO48ffgeK Content-Type: text/plain; charset=koi8-r Content-Disposition: attachment; filename="ng_tee_bypass.diff" diff -ur netgraph.c99/netgraph.h netgraph/netgraph.h --- netgraph.c99/netgraph.h Fri May 28 14:12:30 2004 +++ netgraph/netgraph.h Fri May 28 15:05:48 2004 @@ -83,6 +83,7 @@ /* node method definitions */ typedef int ng_constructor_t(node_p node); +typedef int ng_close_t(node_p node); typedef int ng_shutdown_t(node_p node); typedef int ng_newhook_t(node_p node, hook_p hook, const char *name); typedef hook_p ng_findhook_t(node_p node, const char *name); @@ -1052,6 +1053,7 @@ modeventhand_t mod_event; /* Module event handler (optional) */ ng_constructor_t *constructor; /* Node constructor */ ng_rcvmsg_t *rcvmsg; /* control messages come here */ + ng_close_t *close; /* warn about forthcoming shutdown */ ng_shutdown_t *shutdown; /* reset, and free resources */ ng_newhook_t *newhook; /* first notification of new hook */ ng_findhook_t *findhook; /* only if you have lots of hooks */ @@ -1112,6 +1114,7 @@ int ng_address_ID(node_p here, item_p item, ng_ID_t ID, ng_ID_t retaddr); int ng_address_hook(node_p here, item_p item, hook_p hook, ng_ID_t retaddr); int ng_address_path(node_p here, item_p item, char *address, ng_ID_t raddr); +int ng_bypass(hook_p hook1, hook_p hook2); meta_p ng_copy_meta(meta_p meta); hook_p ng_findhook(node_p node, const char *name); int ng_make_node_common(struct ng_type *typep, node_p *nodep); diff -ur netgraph.c99/ng_base.c netgraph/ng_base.c --- netgraph.c99/ng_base.c Fri May 28 14:12:30 2004 +++ netgraph/ng_base.c Fri May 28 14:29:28 2004 @@ -199,7 +199,6 @@ const char *name2, char *type); /* imported , these used to be externally visible, some may go back */ -int ng_bypass(hook_p hook1, hook_p hook2); void ng_destroy_hook(hook_p hook); node_p ng_name2noderef(node_p node, const char *name); int ng_path2noderef(node_p here, const char *path, @@ -693,6 +692,10 @@ * creation */ node->nd_flags |= NG_INVALID|NG_CLOSING; + + /* If node has its pre-shutdown method, then call it first*/ + if (node->nd_type && node->nd_type->close) + (*node->nd_type->close)(node); /* Notify all remaining connected nodes to disconnect */ while ((hook = LIST_FIRST(&node->nd_hooks)) != NULL) diff -ur netgraph.c99/ng_tee.c netgraph/ng_tee.c --- netgraph.c99/ng_tee.c Fri May 28 14:12:30 2004 +++ netgraph/ng_tee.c Fri May 28 14:17:20 2004 @@ -79,6 +79,7 @@ /* Netgraph methods */ static ng_constructor_t ngt_constructor; static ng_rcvmsg_t ngt_rcvmsg; +static ng_close_t ngt_close; static ng_shutdown_t ngt_shutdown; static ng_newhook_t ngt_newhook; static ng_rcvdata_t ngt_rcvdata; @@ -132,6 +133,7 @@ .name = NG_TEE_NODE_TYPE, .constructor = ngt_constructor, .rcvmsg = ngt_rcvmsg, + .close = ngt_close, .shutdown = ngt_shutdown, .newhook = ngt_newhook, .rcvdata = ngt_rcvdata, @@ -358,15 +360,25 @@ } /* - * Shutdown processing - * - * This is tricky. If we have both a left and right hook, then we - * probably want to extricate ourselves and leave the two peers - * still linked to each other. Otherwise we should just shut down as - * a normal node would. + * We are going to be shut down soon * - * To keep the scope of info correct the routine to "extract" a node - * from two links is in ng_base.c. + * If we have both a left and right hook, then we probably want to extricate + * ourselves and leave the two peers still linked to each other. Otherwise we + * should just shut down as a normal node would. + */ +static int +ngt_close(node_p node) +{ + const sc_p privdata = NG_NODE_PRIVATE(node); + + if (privdata->left.hook && privdata->right.hook) + ng_bypass(privdata->left.hook, privdata->right.hook); + + return (0); +} + +/* + * Shutdown processing */ static int ngt_shutdown(node_p node) --CE+1k2dSO48ffgeK--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040528110832.GA43696>