PERFORCE change 127921 for review

Marko Zec zec at FreeBSD.org
Mon Oct 22 06:16:17 PDT 2007


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

Change 127921 by zec at zec_tpx32 on 2007/10/22 13:15:44

	Refcount ucred -> vimage bindings in struct vimage.  Obviously,
	we shouldn't release a vimage if other objects point to it.
	
	NB it is still not completely clear to me whether this additional
	refcounting would need additional protection / locking...

Affected files ...

.. //depot/projects/vimage/src/sys/kern/init_main.c#14 edit
.. //depot/projects/vimage/src/sys/kern/kern_prot.c#7 edit
.. //depot/projects/vimage/src/sys/kern/kern_vimage.c#49 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#47 edit

Differences ...

==== //depot/projects/vimage/src/sys/kern/init_main.c#14 (text+ko) ====

@@ -67,6 +67,7 @@
 #include <sys/vnode.h>
 #include <sys/sysent.h>
 #include <sys/reboot.h>
+#include <sys/refcount.h>
 #include <sys/sched.h>
 #include <sys/sx.h>
 #include <sys/sysproto.h>
@@ -447,9 +448,9 @@
 	p->p_ucred->cr_ruidinfo = uifind(0);
 	p->p_ucred->cr_prison = NULL;	/* Don't jail it. */
 #ifdef VIMAGE
-	p->p_ucred->cr_vimage =  LIST_FIRST(&vimage_head);
-	p->p_ucred->cr_rvimage = p->p_ucred->cr_vimage;
-	LIST_FIRST(&vprocg_head)->nprocs = 1;
+	P_TO_VIMAGE(p) =  LIST_FIRST(&vimage_head);
+	refcount_acquire(&P_TO_VIMAGE(p)->vi_ucredrefc);
+	LIST_FIRST(&vprocg_head)->nprocs++;
 #endif
 #ifdef AUDIT
 	audit_cred_kproc0(p->p_ucred);

==== //depot/projects/vimage/src/sys/kern/kern_prot.c#7 (text+ko) ====

@@ -1794,6 +1794,10 @@
 		 */
 		if (jailed(cr))
 			prison_free(cr->cr_prison);
+#ifdef VIMAGE
+		if (cr->cr_vimage != NULL)
+			refcount_release(&cr->cr_vimage->vi_ucredrefc);
+#endif
 #ifdef AUDIT
 		audit_cred_destroy(cr);
 #endif
@@ -1829,6 +1833,10 @@
 	uihold(dest->cr_ruidinfo);
 	if (jailed(dest))
 		prison_hold(dest->cr_prison);
+#ifdef VIMAGE
+	KASSERT(src->cr_vimage != NULL, ("cr_vimage == NULL"));
+	refcount_acquire(&dest->cr_vimage->vi_ucredrefc);
+#endif
 #ifdef AUDIT
 	audit_cred_copy(src, dest);
 #endif

==== //depot/projects/vimage/src/sys/kern/kern_vimage.c#49 (text+ko) ====

@@ -40,6 +40,7 @@
 #include <sys/malloc.h>
 #include <sys/priv.h>
 #include <sys/proc.h>
+#include <sys/refcount.h>
 #include <sys/sched.h>
 #include <sys/sockio.h>
 #include <sys/sx.h>
@@ -527,12 +528,14 @@
 			oldcred = p->p_ucred;
 			setsugid(p);
 			crcopy(newcred, oldcred);
+			refcount_release(&newcred->cr_vimage->vi_ucredrefc);
 			newcred->cr_vimage = vip_r;
-			newcred->cr_rvimage = vip_r;	/* XXX */
+			refcount_acquire(&newcred->cr_vimage->vi_ucredrefc);
 			p->p_ucred = newcred;
 			PROC_UNLOCK(p);
 			sx_xlock(&allproc_lock);
 			oldcred->cr_vimage->v_procg->nprocs--;
+			refcount_release(&oldcred->cr_vimage->vi_ucredrefc);
 			P_TO_VPROCG(p)->nprocs++;
 			sched_load_reassign(oldcred->cr_vimage->v_procg,
 			    newcred->cr_vimage->v_procg);
@@ -682,6 +685,10 @@
 	if (vnet->sockcnt != 0)
 		return (EBUSY);
 
+	if (vip->vi_ucredrefc != 0)
+		printf("vi_destroy: %s ucredrefc %d\n",
+		    vip->vi_name, vip->vi_ucredrefc);
+
 	VNET_LIST_LOCK();
 	LIST_REMOVE(vnet, vnet_le);
 	VNET_LIST_UNLOCK();

==== //depot/projects/vimage/src/sys/sys/vimage.h#47 (text+ko) ====

@@ -383,6 +383,7 @@
 	LIST_HEAD(, vimage) vi_child_head;	/* direct offspring list */
 	struct	vimage *vi_parent;	/* ptr to parent vimage */
 	u_int	vi_id;			/* ID num */
+	u_int	vi_ucredrefc;		/* refc of ucreds pointing to us */
 
 	char	vi_name[MAXHOSTNAMELEN]; /* assigned by parent */
 


More information about the p4-projects mailing list