PERFORCE change 126243 for review

Marko Zec zec at FreeBSD.org
Sun Sep 9 16:30:50 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=126243

Change 126243 by zec at 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 <net/if_clone.h>
 #include <net/ethernet.h>
 
+//#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)


More information about the p4-projects mailing list