From owner-p4-projects@FreeBSD.ORG Mon May 7 23:23:13 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4715D16A404; Mon, 7 May 2007 23:23:13 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0FADA16A402 for ; Mon, 7 May 2007 23:23:13 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outL.internet-mail-service.net (outL.internet-mail-service.net [216.240.47.235]) by mx1.freebsd.org (Postfix) with ESMTP id EC1C413C447 for ; Mon, 7 May 2007 23:23:12 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Mon, 07 May 2007 16:23:01 -0700 Received: from julian-mac.elischer.org (nat.ironport.com [63.251.108.100]) by idiom.com (Postfix) with ESMTP id 951A9125B34; Mon, 7 May 2007 16:23:00 -0700 (PDT) Message-ID: <463FB4D3.8080402@elischer.org> Date: Mon, 07 May 2007 16:22:59 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.0 (Macintosh/20070326) MIME-Version: 1.0 To: Marko Zec References: <200705072252.l47Mq4xX044896@repoman.freebsd.org> In-Reply-To: <200705072252.l47Mq4xX044896@repoman.freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Perforce Change Reviews Subject: Re: PERFORCE change 119444 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 May 2007 23:23:13 -0000 Marko Zec wrote: > http://perforce.freebsd.org/chv.cgi?CH=119444 > > Change 119444 by zec@zec_tpx32 on 2007/05/07 22:51:07 > > Add support for free-floating ng_hub and ng_bridge instances. > > If a hook named "anchor" is created on a ng_hub or ng_bridge > node instance, the node will not self-destruct even if it > has no hooks connected. Reminder: normal behavior is that > hub or bridge nodes automatically destroy themselves when > the last hook is disconnected. What is this hook attached to? One could just as easily send them a 'become persistant' message.. It would be a good candidate for a generic message. Data is still sent to this hook. is that what is expected? > > Affected files ... > > .. //depot/projects/vimage/src/sys/netgraph/ng_bridge.c#2 edit > .. //depot/projects/vimage/src/sys/netgraph/ng_hub.c#2 edit > > Differences ... > > ==== //depot/projects/vimage/src/sys/netgraph/ng_bridge.c#2 (text+ko) ==== > > @@ -95,13 +95,14 @@ > /* Per-node private data */ > struct ng_bridge_private { > struct ng_bridge_bucket *tab; /* hash table bucket array */ > - struct ng_bridge_link *links[NG_BRIDGE_MAX_LINKS]; > + struct ng_bridge_link *links[NG_BRIDGE_MAX_LINKS + 1]; > struct ng_bridge_config conf; /* node configuration */ > node_p node; /* netgraph node */ > u_int numHosts; /* num entries in table */ > u_int numBuckets; /* num buckets in table */ > u_int hashMask; /* numBuckets - 1 */ > int numLinks; /* num connected links */ > + int persistent; /* can exist w/o any hooks */ > struct callout timer; /* one second periodic timer */ > }; > typedef struct ng_bridge_private *priv_p; > @@ -342,13 +343,13 @@ > ng_bridge_newhook(node_p node, hook_p hook, const char *name) > { > const priv_p priv = NG_NODE_PRIVATE(node); > + int linkNum = -1; > > /* Check for a link hook */ > if (strncmp(name, NG_BRIDGE_HOOK_LINK_PREFIX, > strlen(NG_BRIDGE_HOOK_LINK_PREFIX)) == 0) { > const char *cp; > char *eptr; > - u_long linkNum; > > cp = name + strlen(NG_BRIDGE_HOOK_LINK_PREFIX); > if (!isdigit(*cp) || (cp[0] == '0' && cp[1] != '\0')) > @@ -356,6 +357,14 @@ > linkNum = strtoul(cp, &eptr, 10); > if (*eptr != '\0' || linkNum >= NG_BRIDGE_MAX_LINKS) > return (EINVAL); > + } else if (strcmp(name, "anchor") == 0) { > + linkNum = NG_BRIDGE_MAX_LINKS; > + if (priv->persistent) > + return (EISCONN); > + priv->persistent = 1; > + } > + > + if (linkNum >= 0 ) { > if (priv->links[linkNum] != NULL) > return (EISCONN); > MALLOC(priv->links[linkNum], struct ng_bridge_link *, > @@ -366,7 +375,7 @@ > NG_HOOK_SET_PRIVATE(hook, (void *)linkNum); > priv->numLinks++; > return (0); > - } > + } > > /* Unknown hook name */ > return (EINVAL); > @@ -796,7 +805,8 @@ > > /* If no more hooks, go away */ > if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) > - && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) { > + && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))) > + && !priv->persistent) { > ng_rmnode_self(NG_HOOK_NODE(hook)); > } > return (0); > > ==== //depot/projects/vimage/src/sys/netgraph/ng_hub.c#2 (text+ko) ==== > > @@ -37,6 +37,7 @@ > #include > > static ng_constructor_t ng_hub_constructor; > +static ng_newhook_t ng_hub_newhook; > static ng_rcvdata_t ng_hub_rcvdata; > static ng_disconnect_t ng_hub_disconnect; > > @@ -44,6 +45,7 @@ > .version = NG_ABI_VERSION, > .name = NG_HUB_NODE_TYPE, > .constructor = ng_hub_constructor, > + .newhook = ng_hub_newhook, > .rcvdata = ng_hub_rcvdata, > .disconnect = ng_hub_disconnect, > }; > @@ -57,6 +59,14 @@ > return (0); > } > > +static int > +ng_hub_newhook(node_p node, hook_p hook, const char *name) > +{ > + if (strcmp(name, "anchor") == 0) > + node->nd_private = (void *) 1; > + return 0; > +} > + > static int > ng_hub_rcvdata(hook_p hook, item_p item) > { > @@ -94,7 +104,7 @@ > { > > if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0 && > - NG_NODE_IS_VALID(NG_HOOK_NODE(hook))) > + NG_NODE_IS_VALID(NG_HOOK_NODE(hook)) && !hook->hk_node->nd_private) > ng_rmnode_self(NG_HOOK_NODE(hook)); > return (0); > }