Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Nov 2006 17:08:28 GMT
From:      Roman Divacky <rdivacky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 110216 for review
Message-ID:  <200611211708.kALH8SD2064839@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110216

Change 110216 by rdivacky@rdivacky_witten on 2006/11/18 13:55:33

	Redo the checking for 2.6 emulation. We now cache the value of
	use26 and replace calls to linux_get_osrelease() + parsing with
	a call to linux_use26(). Typical path is lockless now.
	
	This commit also lets linux_chroot compile.
	
	This is untested version commited to let IFC proceed.
	
	Pointed out by: kib

Affected files ...

.. //depot/projects/linuxolator/src/sys/compat/linux/linux_mib.c#2 edit
.. //depot/projects/linuxolator/src/sys/compat/linux/linux_mib.h#2 edit
.. //depot/projects/linuxolator/src/sys/compat/linux/linux_misc.c#35 edit

Differences ...

==== //depot/projects/linuxolator/src/sys/compat/linux/linux_mib.c#2 (text+ko) ====

@@ -52,6 +52,7 @@
 	char	pr_osname[LINUX_MAX_UTSNAME];
 	char	pr_osrelease[LINUX_MAX_UTSNAME];
 	int	pr_oss_version;
+	int	pr_use_linux26;	/* flag to determine whether to use 2.6 emulation */
 };
 
 SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0,
@@ -82,6 +83,7 @@
 	    "Linux kernel OS name");
 
 static char	linux_osrelease[LINUX_MAX_UTSNAME] = "2.4.2";
+static int	linux_use_linux26 = 0;
 
 static int
 linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
@@ -227,19 +229,45 @@
 }
 
 int
+linux_use26(struct thread *td)
+{
+	struct prison *pr;
+	struct linux_prison *lpr;
+	int use26 = 0;		/* defaults to off */
+
+	pr = td->td_ucred->cr_prison;
+	if (pr != NULL) {
+	   	mtx_lock(&pr->pr_mtx);
+		if (pr->pr_linux != NULL) {
+		   	lpr = (struct linux_prison *)pr->pr_linux;
+			use26 = lpr->pr_use_linux26;
+		}
+	   	mtx_unlock(&pr->pr_mtx);
+	} else
+	   	use26 = linux_use_linux26;
+	
+	return (use26);
+}
+
+int
 linux_set_osrelease(struct thread *td, char *osrelease)
 {
 	struct prison *pr;
 	struct linux_prison *lpr;
+	int use26;
 
+	use26 = (strlen(osrelease) >= 3 && osrelease[2] == '6');
+
 	pr = linux_get_prison(td);
 	if (pr != NULL) {
 		lpr = (struct linux_prison *)pr->pr_linux;
 		strcpy(lpr->pr_osrelease, osrelease);
+		lpr->pr_use_linux26 = use26;
 		mtx_unlock(&pr->pr_mtx);
 	} else {
 		mtx_lock(&osname_lock);
 		strcpy(linux_osrelease, osrelease);
+		linux_use_linux26 = use26;
 		mtx_unlock(&osname_lock);
 	}
 

==== //depot/projects/linuxolator/src/sys/compat/linux/linux_mib.h#2 (text+ko) ====

@@ -40,4 +40,6 @@
 int	linux_get_oss_version(struct thread *td);
 int	linux_set_oss_version(struct thread *td, int oss_version);
 
+int	linux_use26(struct thread *td);
+
 #endif /* _LINUX_MIB_H_ */

==== //depot/projects/linuxolator/src/sys/compat/linux/linux_misc.c#35 (text+ko) ====

@@ -1407,15 +1407,13 @@
 linux_getpid(struct thread *td, struct linux_getpid_args *args)
 {
    	struct linux_emuldata *em;
-	char osrel[LINUX_MAX_UTSNAME];
 
 #ifdef DEBUG
 	if (ldebug(getpid))
 		printf(ARGS(getpid, ""));
 #endif
 
-	linux_get_osrelease(td, osrel);
-	if (strlen(osrel) >= 3 && osrel[2] == '6') {
+	if (linux_use26(td)) {
    	   	em = em_find(td->td_proc, EMUL_UNLOCKED);
 		KASSERT(em != NULL, ("getpid: emuldata not found.\n"));
    		td->td_retval[0] = em->shared->group_pid;
@@ -1445,15 +1443,13 @@
 {
    	struct linux_emuldata *em;
 	struct proc *p, *pp;
-	char osrel[LINUX_MAX_UTSNAME];
 
 #ifdef DEBUG
 	if (ldebug(getppid))
 		printf(ARGS(getppid, ""));
 #endif
 
-	linux_get_osrelease(td, osrel);
-	if (strlen(osrel) >= 3 && osrel[2] != '6') {
+	if (!linux_use26(td)) {
 	   	PROC_LOCK(td->td_proc);
 	   	td->td_retval[0] = td->td_proc->p_pptr->p_pid;
 	   	PROC_UNLOCK(td->td_proc);
@@ -1581,15 +1577,13 @@
 {
    	struct linux_emuldata *em, *td_em, *tmp_em;
 	struct proc *sp;
-	char osrel[LINUX_MAX_UTSNAME];
 
 #ifdef DEBUG
 	if (ldebug(exit_group))
 		printf(ARGS(exit_group, "%i"), args->error_code);
 #endif
 
-	linux_get_osrelease(td, osrel);
-	if (strlen(osrel) >= 3 && osrel[2] == '6') {
+	if (linux_use26(td)) {
    	   	td_em = em_find(td->td_proc, EMUL_UNLOCKED);
 
 		KASSERT(td_em != NULL, ("exit_group: emuldata not found.\n"));
@@ -1676,5 +1670,5 @@
 int
 linux_chroot(struct thread *td, struct linux_chroot_args *args)
 {
-   	return (chroot(td, args));
+   	return (chroot(td, (struct chroot_args *) args));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611211708.kALH8SD2064839>