summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2022-03-17 14:23:35 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2022-03-17 14:23:35 +0000
commit4ad2bbef46d93bf6f9a02ed42b0cb053d77b2580 (patch)
tree08a661a1d050f0b5b726da51a80d6f4e8d13aa35 /sys
parentf9fe30a36c2e53bb8a75bff1780a42f637d80144 (diff)
Use the refcnt API with struct ucred.
OK bluhm@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_fork.c5
-rw-r--r--sys/kern/kern_prot.c19
-rw-r--r--sys/nfs/nfs_socket.c4
-rw-r--r--sys/sys/ucred.h5
4 files changed, 17 insertions, 16 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index 6f400f4e457..330c7a06a8e 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.238 2021/12/10 05:34:42 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.239 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -190,7 +190,8 @@ process_initialize(struct process *pr, struct proc *p)
/* give the process the same creds as the initial thread */
pr->ps_ucred = p->p_ucred;
crhold(pr->ps_ucred);
- KASSERT(p->p_ucred->cr_ref >= 2); /* new thread and new process */
+ /* new thread and new process */
+ KASSERT(p->p_ucred->cr_refcnt.r_refs >= 2);
LIST_INIT(&pr->ps_children);
LIST_INIT(&pr->ps_orphans);
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 2d2d74ac7aa..77b5bc002b3 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_prot.c,v 1.78 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.79 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
@@ -57,7 +57,7 @@
inline void
crset(struct ucred *newcr, const struct ucred *cr)
{
- KASSERT(cr->cr_ref > 0);
+ KASSERT(cr->cr_refcnt.r_refs > 0);
memcpy(
(char *)newcr + offsetof(struct ucred, cr_startcopy),
(const char *)cr + offsetof(struct ucred, cr_startcopy),
@@ -945,7 +945,7 @@ crget(void)
struct ucred *cr;
cr = pool_get(&ucred_pool, PR_WAITOK|PR_ZERO);
- cr->cr_ref = 1;
+ refcnt_init(&cr->cr_refcnt);
return (cr);
}
@@ -956,7 +956,7 @@ crget(void)
struct ucred *
crhold(struct ucred *cr)
{
- atomic_inc_int(&cr->cr_ref);
+ refcnt_take(&cr->cr_refcnt);
return (cr);
}
@@ -967,8 +967,7 @@ crhold(struct ucred *cr)
void
crfree(struct ucred *cr)
{
-
- if (atomic_dec_int_nv(&cr->cr_ref) == 0)
+ if (refcnt_rele(&cr->cr_refcnt))
pool_put(&ucred_pool, cr);
}
@@ -980,12 +979,12 @@ crcopy(struct ucred *cr)
{
struct ucred *newcr;
- if (cr->cr_ref == 1)
+ if (!refcnt_shared(&cr->cr_refcnt))
return (cr);
newcr = crget();
*newcr = *cr;
crfree(cr);
- newcr->cr_ref = 1;
+ refcnt_init(&newcr->cr_refcnt);
return (newcr);
}
@@ -999,7 +998,7 @@ crdup(struct ucred *cr)
newcr = crget();
*newcr = *cr;
- newcr->cr_ref = 1;
+ refcnt_init(&newcr->cr_refcnt);
return (newcr);
}
@@ -1011,7 +1010,7 @@ crfromxucred(struct ucred *cr, const struct xucred *xcr)
{
if (xcr->cr_ngroups < 0 || xcr->cr_ngroups > NGROUPS_MAX)
return (EINVAL);
- cr->cr_ref = 1;
+ refcnt_init(&cr->cr_refcnt);
cr->cr_uid = xcr->cr_uid;
cr->cr_gid = xcr->cr_gid;
cr->cr_ngroups = xcr->cr_ngroups;
diff --git a/sys/nfs/nfs_socket.c b/sys/nfs/nfs_socket.c
index 53f813bcc1b..a20986e4a81 100644
--- a/sys/nfs/nfs_socket.c
+++ b/sys/nfs/nfs_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_socket.c,v 1.139 2022/02/22 01:15:02 guenther Exp $ */
+/* $OpenBSD: nfs_socket.c,v 1.140 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: nfs_socket.c,v 1.27 1996/04/15 20:20:00 thorpej Exp $ */
/*
@@ -1493,7 +1493,7 @@ nfs_getreq(struct nfsrv_descript *nd, struct nfsd *nfsd, int has_header)
nfsm_adv(nfsm_rndup(len));
nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
memset(&nd->nd_cr, 0, sizeof (struct ucred));
- nd->nd_cr.cr_ref = 1;
+ refcnt_init(&nd->nd_cr.cr_refcnt);
nd->nd_cr.cr_uid = fxdr_unsigned(uid_t, *tl++);
nd->nd_cr.cr_gid = fxdr_unsigned(gid_t, *tl++);
len = fxdr_unsigned(int, *tl);
diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
index 7ce0fd60b2c..139812491b3 100644
--- a/sys/sys/ucred.h
+++ b/sys/sys/ucred.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ucred.h,v 1.13 2018/06/21 13:58:21 visa Exp $ */
+/* $OpenBSD: ucred.h,v 1.14 2022/03/17 14:23:34 visa Exp $ */
/* $NetBSD: ucred.h,v 1.12 1995/06/01 22:44:50 jtc Exp $ */
/*
@@ -35,13 +35,14 @@
#ifndef _SYS_UCRED_H_
#define _SYS_UCRED_H_
+#include <sys/refcnt.h>
#include <sys/syslimits.h>
/*
* Credentials.
*/
struct ucred {
- u_int cr_ref; /* reference count */
+ struct refcnt cr_refcnt; /* reference count */
/* The following fields are all copied by crset() */
#define cr_startcopy cr_uid