Date: Thu, 16 Jul 2015 14:30:11 +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: r285633 - in head/sys: kern sys Message-ID: <201507161430.t6GEUCbH019751@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Thu Jul 16 14:30:11 2015 New Revision: 285633 URL: https://svnweb.freebsd.org/changeset/base/285633 Log: Get rid of lim_update_thread and cred_update_thread. Their primary use was in thread_cow_update to free up old resources. Freeing had to be done with proc lock held and _cow_ funcs already knew how to free old structs. Modified: head/sys/kern/init_main.c head/sys/kern/kern_prot.c head/sys/kern/kern_resource.c head/sys/kern/kern_thread.c head/sys/sys/resourcevar.h head/sys/sys/ucred.h Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/kern/init_main.c Thu Jul 16 14:30:11 2015 (r285633) @@ -827,6 +827,7 @@ static void create_init(const void *udata __unused) { struct ucred *newcred, *oldcred; + struct thread *td; int error; error = fork1(&thread0, RFFDG | RFPROC | RFSTOPPED, 0, &initproc, @@ -850,7 +851,9 @@ create_init(const void *udata __unused) audit_cred_proc1(newcred); #endif proc_set_cred(initproc, newcred); - cred_update_thread(FIRST_THREAD_IN_PROC(initproc)); + td = FIRST_THREAD_IN_PROC(initproc); + crfree(td->td_ucred); + td->td_ucred = crhold(initproc->p_ucred); PROC_UNLOCK(initproc); sx_xunlock(&proctree_lock); crfree(oldcred); Modified: head/sys/kern/kern_prot.c ============================================================================== --- head/sys/kern/kern_prot.c Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/kern/kern_prot.c Thu Jul 16 14:30:11 2015 (r285633) @@ -1935,24 +1935,6 @@ cru2x(struct ucred *cr, struct xucred *x } /* - * small routine to swap a thread's current ucred for the correct one taken - * from the process. - */ -void -cred_update_thread(struct thread *td) -{ - struct proc *p; - struct ucred *cred; - - p = td->td_proc; - cred = td->td_ucred; - PROC_LOCK_ASSERT(p, MA_OWNED); - td->td_ucred = crhold(p->p_ucred); - if (cred != NULL) - crfree(cred); -} - -/* * Set initial process credentials. * Callers are responsible for providing the reference for provided credentials. */ Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/kern/kern_resource.c Thu Jul 16 14:30:11 2015 (r285633) @@ -1436,17 +1436,3 @@ chgkqcnt(struct uidinfo *uip, int diff, return (chglimit(uip, &uip->ui_kqcnt, diff, max, "kqcnt")); } - -void -lim_update_thread(struct thread *td) -{ - struct proc *p; - struct plimit *lim; - - p = td->td_proc; - lim = td->td_limit; - PROC_LOCK_ASSERT(p, MA_OWNED); - td->td_limit = lim_hold(p->p_limit); - if (lim != NULL) - lim_free(lim); -} Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/kern/kern_thread.c Thu Jul 16 14:30:11 2015 (r285633) @@ -409,9 +409,9 @@ void thread_cow_free(struct thread *td) { - if (td->td_ucred) + if (td->td_ucred != NULL) crfree(td->td_ucred); - if (td->td_limit) + if (td->td_limit != NULL) lim_free(td->td_limit); } @@ -419,15 +419,27 @@ void thread_cow_update(struct thread *td) { struct proc *p; + struct ucred *oldcred; + struct plimit *oldlimit; p = td->td_proc; + oldcred = NULL; + oldlimit = NULL; PROC_LOCK(p); - if (td->td_ucred != p->p_ucred) - cred_update_thread(td); - if (td->td_limit != p->p_limit) - lim_update_thread(td); + if (td->td_ucred != p->p_ucred) { + oldcred = td->td_ucred; + td->td_ucred = crhold(p->p_ucred); + } + if (td->td_limit != p->p_limit) { + oldlimit = td->td_limit; + td->td_limit = lim_hold(p->p_limit); + } td->td_cowgen = p->p_cowgen; PROC_UNLOCK(p); + if (oldcred != NULL) + crfree(oldcred); + if (oldlimit != NULL) + lim_free(oldlimit); } /* Modified: head/sys/sys/resourcevar.h ============================================================================== --- head/sys/sys/resourcevar.h Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/sys/resourcevar.h Thu Jul 16 14:30:11 2015 (r285633) @@ -159,7 +159,5 @@ void ui_racct_foreach(void (*callback)( void *arg2, void *arg3), void *arg2, void *arg3); #endif -void lim_update_thread(struct thread *td); - #endif /* _KERNEL */ #endif /* !_SYS_RESOURCEVAR_H_ */ Modified: head/sys/sys/ucred.h ============================================================================== --- head/sys/sys/ucred.h Thu Jul 16 13:57:05 2015 (r285632) +++ head/sys/sys/ucred.h Thu Jul 16 14:30:11 2015 (r285633) @@ -105,7 +105,6 @@ void change_svuid(struct ucred *newcred, void crcopy(struct ucred *dest, struct ucred *src); struct ucred *crcopysafe(struct proc *p, struct ucred *cr); struct ucred *crdup(struct ucred *cr); -void cred_update_thread(struct thread *td); void proc_set_cred_init(struct proc *p, struct ucred *cr); struct ucred *proc_set_cred(struct proc *p, struct ucred *cr); void crfree(struct ucred *cr);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507161430.t6GEUCbH019751>