Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Nov 2017 06:12:15 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325264 - head/sys/kern
Message-ID:  <201711010612.vA16CF1S042388@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Wed Nov  1 06:12:14 2017
New Revision: 325264
URL: https://svnweb.freebsd.org/changeset/base/325264

Log:
  Save on loginclass list locking by checking if caller already uses the struct

Modified:
  head/sys/kern/init_main.c
  head/sys/kern/kern_loginclass.c

Modified: head/sys/kern/init_main.c
==============================================================================
--- head/sys/kern/init_main.c	Wed Nov  1 05:51:20 2017	(r325263)
+++ head/sys/kern/init_main.c	Wed Nov  1 06:12:14 2017	(r325264)
@@ -421,6 +421,9 @@ proc0_init(void *dummy __unused)
 	struct thread *td;
 	struct ucred *newcred;
 	struct uidinfo tmpuinfo;
+	struct loginclass tmplc = {
+		.lc_name = "",
+	};
 	vm_paddr_t pageablemem;
 	int i;
 
@@ -509,10 +512,11 @@ proc0_init(void *dummy __unused)
 	newcred->cr_uidinfo = newcred->cr_ruidinfo = &tmpuinfo;
 	newcred->cr_uidinfo = uifind(0);
 	newcred->cr_ruidinfo = uifind(0);
+	newcred->cr_loginclass = &tmplc;
+	newcred->cr_loginclass = loginclass_find("default");
 	/* End hack. creds get properly set later with thread_cow_get_proc */
 	curthread->td_ucred = NULL;
 	newcred->cr_prison = &prison0;
-	newcred->cr_loginclass = loginclass_find("default");
 	proc_set_cred_init(p, newcred);
 #ifdef AUDIT
 	audit_cred_kproc0(newcred);

Modified: head/sys/kern/kern_loginclass.c
==============================================================================
--- head/sys/kern/kern_loginclass.c	Wed Nov  1 05:51:20 2017	(r325263)
+++ head/sys/kern/kern_loginclass.c	Wed Nov  1 06:12:14 2017	(r325264)
@@ -131,9 +131,16 @@ struct loginclass *
 loginclass_find(const char *name)
 {
 	struct loginclass *lc, *new_lc;
+	struct ucred *cred;
 
 	if (name[0] == '\0' || strlen(name) >= MAXLOGNAME)
 		return (NULL);
+
+	lc = cred->cr_loginclass;
+	if (strcmp(name, lc->lc_name) == 0) {
+		loginclass_hold(lc);
+		return (lc);
+	}
 
 	rw_rlock(&loginclasses_lock);
 	lc = loginclass_lookup(name);



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