Use if_acquire and if_release instead of using psref API directly

- Provide if_release for consistency to if_acquire
- Use if_acquire and if_release for ifp iterations
- Make ifnet_psref_class static
This commit is contained in:
ozaki-r 2017-03-14 09:03:08 +00:00
parent 2fe5debf56
commit 0eaf4e5356
11 changed files with 45 additions and 48 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: altq_subr.c,v 1.32 2016/06/20 08:30:58 knakahara Exp $ */
/* $NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $ */
/* $KAME: altq_subr.c,v 1.24 2005/04/13 03:44:25 suz Exp $ */
/*
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.32 2016/06/20 08:30:58 knakahara Exp $");
__KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_altq.h"
@ -360,7 +360,7 @@ tbr_timeout(void *arg)
struct psref psref;
if (!TBR_IS_ENABLED(&ifp->if_snd))
continue;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
pserialize_read_exit(s);
active++;
@ -371,7 +371,7 @@ tbr_timeout(void *arg)
}
s = pserialize_read_enter();
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);

View File

@ -1,9 +1,9 @@
/* $NetBSD: uipc_syscalls_40.c,v 1.12 2016/08/01 03:15:30 ozaki-r Exp $ */
/* $NetBSD: uipc_syscalls_40.c,v 1.13 2017/03/14 09:03:08 ozaki-r Exp $ */
/* written by Pavel Cahyna, 2006. Public domain. */
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.12 2016/08/01 03:15:30 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.13 2017/03/14 09:03:08 ozaki-r Exp $");
/*
* System call interface to the socket abstraction.
@ -52,7 +52,7 @@ compat_ifconf(u_long cmd, void *data)
IFNET_READER_FOREACH(ifp) {
struct ifaddr *ifa;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
(void)strncpy(ifr.ifr_name, ifp->if_xname,
sizeof(ifr.ifr_name));
@ -126,7 +126,7 @@ compat_ifconf(u_long cmd, void *data)
space -= sz;
}
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);
@ -139,7 +139,7 @@ compat_ifconf(u_long cmd, void *data)
release_exit:
pserialize_read_exit(s);
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
curlwp_bindx(bound);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_socket.c,v 1.137 2017/02/03 16:57:39 christos Exp $ */
/* $NetBSD: linux_socket.c,v 1.138 2017/03/14 09:03:08 ozaki-r Exp $ */
/*-
* Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.137 2017/02/03 16:57:39 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.138 2017/03/14 09:03:08 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -1143,7 +1143,7 @@ linux_getifconf(struct lwp *l, register_t *retval, void *data)
s = pserialize_read_enter();
IFNET_READER_FOREACH(ifp) {
struct ifaddr *ifa;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
(void)strncpy(ifr.ifr_name, ifp->if_xname,
sizeof(ifr.ifr_name));
@ -1179,7 +1179,7 @@ linux_getifconf(struct lwp *l, register_t *retval, void *data)
ifa_release(ifa, &psref_ifa);
}
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);
@ -1193,7 +1193,7 @@ linux_getifconf(struct lwp *l, register_t *retval, void *data)
release_exit:
pserialize_read_exit(s);
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
curlwp_bindx(bound);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux32_socket.c,v 1.26 2016/08/01 03:15:30 ozaki-r Exp $ */
/* $NetBSD: linux32_socket.c,v 1.27 2017/03/14 09:03:08 ozaki-r Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.26 2016/08/01 03:15:30 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.27 2017/03/14 09:03:08 ozaki-r Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -441,7 +441,7 @@ linux32_getifconf(struct lwp *l, register_t *retval, void *data)
s = pserialize_read_enter();
IFNET_READER_FOREACH(ifp) {
struct ifaddr *ifa;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
(void)strncpy(ifr.ifr_name, ifp->if_xname,
sizeof(ifr.ifr_name));
@ -477,7 +477,7 @@ linux32_getifconf(struct lwp *l, register_t *retval, void *data)
ifa_release(ifa, &psref_ifa);
}
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);
@ -491,7 +491,7 @@ linux32_getifconf(struct lwp *l, register_t *retval, void *data)
release_exit:
pserialize_read_exit(s);
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
curlwp_bindx(bound);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pf_if.c,v 1.32 2016/12/26 23:21:49 christos Exp $ */
/* $NetBSD: pf_if.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $ */
/* $OpenBSD: pf_if.c,v 1.47 2007/07/13 09:17:48 markus Exp $ */
/*
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pf_if.c,v 1.32 2016/12/26 23:21:49 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: pf_if.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -126,14 +126,14 @@ pfi_initialize(void)
s = pserialize_read_enter();
IFNET_READER_FOREACH(ifp) {
struct psref psref;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
pserialize_read_exit(s);
pfi_init_groups(ifp);
pfi_attach_ifnet(ifp);
s = pserialize_read_enter();
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);
@ -159,14 +159,14 @@ pfi_destroy(void)
s = pserialize_read_enter();
IFNET_READER_FOREACH(ifp) {
struct psref psref;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
pserialize_read_exit(s);
pfi_detach_ifnet(ifp);
pfi_destroy_groups(ifp);
s = pserialize_read_enter();
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_mbuf.c,v 1.170 2017/01/09 14:25:52 christos Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.171 2017/03/14 09:03:08 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.170 2017/01/09 14:25:52 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_mbuf.c,v 1.171 2017/03/14 09:03:08 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_mbuftrace.h"
@ -562,14 +562,12 @@ m_reclaim(void *arg, int flags)
IFNET_READER_FOREACH(ifp) {
struct psref psref;
psref_acquire(&psref, &ifp->if_psref,
ifnet_psref_class);
if_acquire(ifp, &psref);
if (ifp->if_drain)
(*ifp->if_drain)(ifp);
psref_release(&psref, &ifp->if_psref,
ifnet_psref_class);
if_release(ifp, &psref);
}
curlwp_bindx(bound);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.384 2017/03/14 04:25:10 ozaki-r Exp $ */
/* $NetBSD: if.c,v 1.385 2017/03/14 09:03:08 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.384 2017/03/14 04:25:10 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.385 2017/03/14 09:03:08 ozaki-r Exp $");
#if defined(_KERNEL_OPT)
#include "opt_inet.h"
@ -176,7 +176,7 @@ static size_t if_indexlim = 0;
static uint64_t index_gen;
/* Mutex to protect the above objects. */
kmutex_t ifnet_mtx __cacheline_aligned;
struct psref_class *ifnet_psref_class __read_mostly;
static struct psref_class *ifnet_psref_class __read_mostly;
static pserialize_t ifnet_psz;
static kmutex_t if_clone_mtx;

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.h,v 1.235 2017/02/23 07:57:10 ozaki-r Exp $ */
/* $NetBSD: if.h,v 1.236 2017/03/14 09:03:08 ozaki-r Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@ -975,6 +975,7 @@ ifnet_t *if_byindex(u_int);
ifnet_t *if_get_byindex(u_int, struct psref *);
void if_put(const struct ifnet *, struct psref *);
void if_acquire(struct ifnet *, struct psref *);
#define if_release if_put
static inline if_index_t
if_get_index(const struct ifnet *ifp)
@ -1170,7 +1171,6 @@ __END_DECLS
} while (0)
extern struct pslist_head ifnet_pslist;
extern struct psref_class *ifnet_psref_class;
extern kmutex_t ifnet_mtx;
extern struct ifnet *lo0ifp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsock.c,v 1.206 2017/03/14 08:35:55 ozaki-r Exp $ */
/* $NetBSD: rtsock.c,v 1.207 2017/03/14 09:03:08 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.206 2017/03/14 08:35:55 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.207 2017/03/14 09:03:08 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -1685,7 +1685,7 @@ sysctl_iflist(int af, struct rt_walkarg *w, int type)
if (IFADDR_READER_EMPTY(ifp))
continue;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
pserialize_read_exit(s);
info.rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr;
@ -1719,7 +1719,7 @@ sysctl_iflist(int af, struct rt_walkarg *w, int type)
info.rti_info[RTAX_BRD] = NULL;
s = pserialize_read_enter();
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);
@ -1727,7 +1727,7 @@ sysctl_iflist(int af, struct rt_walkarg *w, int type)
return 0;
release_exit:
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
curlwp_bindx(bound);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_carp.c,v 1.85 2017/02/27 08:26:53 ozaki-r Exp $ */
/* $NetBSD: ip_carp.c,v 1.86 2017/03/14 09:03:08 ozaki-r Exp $ */
/* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */
/*
@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.85 2017/02/27 08:26:53 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.86 2017/03/14 09:03:08 ozaki-r Exp $");
/*
* TODO:
@ -975,7 +975,7 @@ carp_send_ad_all(void)
if (ifp->if_carp == NULL || ifp->if_type == IFT_CARP)
continue;
psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class);
if_acquire(ifp, &psref);
pserialize_read_exit(s);
cif = (struct carp_if *)ifp->if_carp;
@ -986,7 +986,7 @@ carp_send_ad_all(void)
}
s = pserialize_read_enter();
psref_release(&psref, &ifp->if_psref, ifnet_psref_class);
if_release(ifp, &psref);
}
pserialize_read_exit(s);
curlwp_bindx(bound);

View File

@ -1,4 +1,4 @@
/* $NetBSD: net_stub.c,v 1.24 2016/11/26 03:17:58 ozaki-r Exp $ */
/* $NetBSD: net_stub.c,v 1.25 2017/03/14 09:03:09 ozaki-r Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.24 2016/11/26 03:17:58 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: net_stub.c,v 1.25 2017/03/14 09:03:09 ozaki-r Exp $");
#include <sys/mutex.h>
#include <sys/param.h>
@ -73,7 +73,6 @@ __weak_alias(vlan_ifdetach,rumpnet_stub);
struct ifnet_head ifnet_list;
struct pslist_head ifnet_pslist;
struct psref_class *ifnet_psref_class;
kmutex_t ifnet_mtx;
int