From owner-p4-projects@FreeBSD.ORG Sun Sep 9 23:30:50 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 369A216A420; Sun, 9 Sep 2007 23:30:50 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D99B316A417 for ; Sun, 9 Sep 2007 23:30:49 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B228213C45E for ; Sun, 9 Sep 2007 23:30:49 +0000 (UTC) (envelope-from zec@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l89NUn6V097140 for ; Sun, 9 Sep 2007 23:30:49 GMT (envelope-from zec@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l89NUnVK097137 for perforce@freebsd.org; Sun, 9 Sep 2007 23:30:49 GMT (envelope-from zec@FreeBSD.org) Date: Sun, 9 Sep 2007 23:30:49 GMT Message-Id: <200709092330.l89NUnVK097137@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to zec@FreeBSD.org using -f From: Marko Zec To: Perforce Change Reviews Cc: Subject: PERFORCE change 126243 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: Sun, 09 Sep 2007 23:30:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=126243 Change 126243 by zec@zec_tpx32 on 2007/09/09 23:30:14 Modify vi_destroy() to return an error if attempting to kill a vnet with live sockets. This is completely unprotected from races and needs more thought / work. In addition to ethernet/VLAN ifnets, allow for ng_iface ifnets to be reassigned from one vnet to another as well. Affected files ... .. //depot/projects/vimage/src/sys/kern/kern_vimage.c#36 edit Differences ... ==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#36 (text+ko) ==== @@ -51,12 +51,14 @@ #include #include +//#define DEBUG_ORDERING + MALLOC_DEFINE(M_VIMAGE, "vimage", "virtual image resource container"); MALLOC_DEFINE(M_VNET, "vnet", "network stack control block"); MALLOC_DEFINE(M_VPROCG, "vprocg", "process group control block"); MALLOC_DEFINE(M_VCPU, "vcpu", "cpu resource control block"); -static void vi_destroy(struct vimage *); +static int vi_destroy(struct vimage *); static void vnet_mod_complete_registration(struct vnet_modlink *); static int vnet_mod_constructor(struct vnet_modlink *); static int vnet_mod_destructor(struct vnet_modlink *); @@ -333,6 +335,9 @@ bcopy(IF_LLADDR(ifp), eaddr, 6); ether_ifdetach(ifp); break; + case IFT_PROPVIRTUAL: /* XXX ng_eiface */ + if_detach(ifp); + break; default: panic("don't know yet how to handle iftype %d", ifp->if_type); /* if_detach(ifp); */ @@ -374,21 +379,22 @@ int unit = 0; struct ifnet *iter; +#define FINDFREEUNIT(dname) \ + do { \ + snprintf(ifp->if_xname, IFNAMSIZ, "%s%d", dname, unit); \ + TAILQ_FOREACH(iter, &V_ifnet, if_link) \ + if (strcmp(ifp->if_xname, iter->if_xname) == 0) \ + break; \ + unit++; \ + } while (iter); + switch (ifp->if_type) { case IFT_ETHER: case IFT_L2VLAN: - do { - snprintf(ifp->if_xname, - IFNAMSIZ, "eth%d", unit); - TAILQ_FOREACH(iter, &V_ifnet, - if_link) - if (strcmp( - ifp->if_xname, - iter->if_xname) - == 0) - break; - unit++; - } while (iter); + FINDFREEUNIT("eth"); + break; + case IFT_PROPVIRTUAL: + FINDFREEUNIT("ser"); break; default: break; @@ -401,6 +407,9 @@ case IFT_L2VLAN: ether_ifattach(ifp, eaddr); break; + case IFT_PROPVIRTUAL: /* XXX ng_eiface */ + if_attach(ifp); + break; default: panic("don't know yet how to handle iftype %d", ifp->if_type); /* if_attach(ifp); */ @@ -484,7 +493,7 @@ case SIOCSPVIMAGE: if (vi_req->req_action == VI_DESTROY) { - vi_destroy(vip_r); + error = vi_destroy(vip_r); break; } @@ -627,7 +636,7 @@ * the timers... How can one ever be sure to have done *all* the necessary * steps? */ -static void +static int vi_destroy(struct vimage *vip) { struct vnet *vnet = vip->v_vnet; @@ -636,6 +645,10 @@ struct ifnet *ifp, *nifp; struct vnet_modlink *vml; + /* XXX Beware of races -> more locking to be done... */ + if (vnet->sockcnt != 0) + return (EBUSY); + VNET_LIST_LOCK(); LIST_REMOVE(vnet, vnet_le); VNET_LIST_UNLOCK(); @@ -679,6 +692,8 @@ LIST_REMOVE(vip, vi_le); vi_free(vip, M_VIMAGE); + + return (0); } static int vnet_mod_constructor(vml)