From owner-svn-src-stable-7@FreeBSD.ORG Thu May 28 04:00:04 2009 Return-Path: Delivered-To: svn-src-stable-7@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5A2D106566C; Thu, 28 May 2009 04:00:03 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BAF618FC14; Thu, 28 May 2009 04:00:03 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4S403HN021813; Thu, 28 May 2009 04:00:03 GMT (envelope-from dchagin@svn.freebsd.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4S403NM021811; Thu, 28 May 2009 04:00:03 GMT (envelope-from dchagin@svn.freebsd.org) Message-Id: <200905280400.n4S403NM021811@svn.freebsd.org> From: Dmitry Chagin Date: Thu, 28 May 2009 04:00:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192950 - in stable/7/sys: . compat/linux contrib/pf dev/ath/ath_hal dev/cxgb X-BeenThere: svn-src-stable-7@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 7-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 May 2009 04:00:04 -0000 Author: dchagin Date: Thu May 28 04:00:03 2009 New Revision: 192950 URL: http://svn.freebsd.org/changeset/base/192950 Log: Merge r191972 from HEAD to stable/7: Introduce linux_kernver() interface which is intended for an exact designation of the emulated kernel version. linux_kernver() returns integer value formatted as 'VVVMMMIII' where VVV - version, MMM - major revision, III - minor revision. Approved by: kib (mentor) Modified: stable/7/sys/ (props changed) stable/7/sys/compat/linux/linux_mib.c stable/7/sys/compat/linux/linux_mib.h stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/ath/ath_hal/ (props changed) stable/7/sys/dev/cxgb/ (props changed) Modified: stable/7/sys/compat/linux/linux_mib.c ============================================================================== --- stable/7/sys/compat/linux/linux_mib.c Thu May 28 02:39:07 2009 (r192949) +++ stable/7/sys/compat/linux/linux_mib.c Thu May 28 04:00:03 2009 (r192950) @@ -52,7 +52,7 @@ struct linux_prison { 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 */ + int pr_osrel; }; SYSCTL_NODE(_compat, OID_AUTO, linux, CTLFLAG_RW, 0, @@ -83,7 +83,7 @@ SYSCTL_PROC(_compat_linux, OID_AUTO, osn "Linux kernel OS name"); static char linux_osrelease[LINUX_MAX_UTSNAME] = "2.4.2"; -static int linux_use_linux26 = 0; +static int linux_osrel = 2004002; static int linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS) @@ -126,6 +126,37 @@ SYSCTL_PROC(_compat_linux, OID_AUTO, oss "Linux OSS version"); /* + * Map the osrelease into integer + */ +static int +linux_map_osrel(char *osrelease, int *osrel) +{ + char *sep, *eosrelease; + int len, v0, v1, v2, v; + + len = strlen(osrelease); + eosrelease = osrelease + len; + v0 = strtol(osrelease, &sep, 10); + if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') + return (EINVAL); + osrelease = sep + 1; + v1 = strtol(osrelease, &sep, 10); + if (osrelease == sep || sep + 1 >= eosrelease || *sep != '.') + return (EINVAL); + osrelease = sep + 1; + v2 = strtol(osrelease, &sep, 10); + if (osrelease == sep || sep != eosrelease) + return (EINVAL); + + v = v0 * 1000000 + v1 * 1000 + v2; + if (v < 1000000) + return (EINVAL); + + *osrel = v; + return (0); +} + +/* * Returns holding the prison mutex if return non-NULL. */ static struct prison * @@ -229,21 +260,21 @@ linux_get_osrelease(struct thread *td, c } int -linux_use26(struct thread *td) +linux_kernver(struct thread *td) { struct prison *pr; struct linux_prison *lpr; - int use26 = linux_use_linux26; + int osrel; pr = td->td_ucred->cr_prison; if (pr != NULL) { if (pr->pr_linux != NULL) { lpr = (struct linux_prison *)pr->pr_linux; - use26 = lpr->pr_use_linux26; + osrel = lpr->pr_osrel; } - } - - return (use26); + } else + osrel = linux_osrel; + return (osrel); } int @@ -251,20 +282,26 @@ linux_set_osrelease(struct thread *td, c { struct prison *pr; struct linux_prison *lpr; - int use26; - - use26 = (strlen(osrelease) >= 3 && osrelease[2] == '6'); + int error; pr = linux_get_prison(td); if (pr != NULL) { lpr = (struct linux_prison *)pr->pr_linux; + error = linux_map_osrel(osrelease, &lpr->pr_osrel); + if (error) { + mtx_unlock(&pr->pr_mtx); + return (error); + } strcpy(lpr->pr_osrelease, osrelease); - lpr->pr_use_linux26 = use26; mtx_unlock(&pr->pr_mtx); } else { mtx_lock(&osname_lock); + error = linux_map_osrel(osrelease, &linux_osrel); + if (error) { + mtx_unlock(&osname_lock); + return (error); + } strcpy(linux_osrelease, osrelease); - linux_use_linux26 = use26; mtx_unlock(&osname_lock); } Modified: stable/7/sys/compat/linux/linux_mib.h ============================================================================== --- stable/7/sys/compat/linux/linux_mib.h Thu May 28 02:39:07 2009 (r192949) +++ stable/7/sys/compat/linux/linux_mib.h Thu May 28 04:00:03 2009 (r192950) @@ -40,6 +40,10 @@ int linux_set_osrelease(struct thread *t 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); +int linux_kernver(struct thread *td); + +#define LINUX_KERNVER_2006000 2006000 + +#define linux_use26(t) (linux_kernver(t) >= LINUX_KERNVER_2006000) #endif /* _LINUX_MIB_H_ */