Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Fix userland compilation: pull the ifioctl lock-rela...
details: https://anonhg.NetBSD.org/src/rev/89b2f4f7143b
branches: trunk
changeset: 770518:89b2f4f7143b
user: dyoung <dyoung%NetBSD.org@localhost>
date: Wed Oct 19 21:29:51 2011 +0000
description:
Fix userland compilation: pull the ifioctl lock-related data members
into a struct ifnet_lock that the ifnet has a pointer to. In a
non-_KERNEL environment, don't #include <sys/percpu.h> et cetera, and
don't define the struct ifnet_lock but *do* declare it.
diffstat:
sys/net/if.c | 67 +++++++++++++++++++++++++++++++++++++----------------------
sys/net/if.h | 27 ++++++++++++++++--------
2 files changed, 60 insertions(+), 34 deletions(-)
diffs (219 lines):
diff -r 1d09dc96f8b0 -r 89b2f4f7143b sys/net/if.c
--- a/sys/net/if.c Wed Oct 19 21:12:50 2011 +0000
+++ b/sys/net/if.c Wed Oct 19 21:29:51 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.253 2011/10/19 01:46:43 dyoung Exp $ */
+/* $NetBSD: if.c,v 1.254 2011/10/19 21:29:51 dyoung 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.253 2011/10/19 01:46:43 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.254 2011/10/19 21:29:51 dyoung Exp $");
#include "opt_inet.h"
@@ -112,6 +112,7 @@
#include <sys/sysctl.h>
#include <sys/syslog.h>
#include <sys/kauth.h>
+#include <sys/kmem.h>
#include <net/if.h>
#include <net/if_dl.h>
@@ -170,8 +171,8 @@
static int ifioctl_attach(struct ifnet *);
static void ifioctl_detach(struct ifnet *);
-static void ifioctl_enter(struct ifnet *);
-static void ifioctl_exit(struct ifnet *);
+static void ifnet_lock_enter(struct ifnet_lock *);
+static void ifnet_lock_exit(struct ifnet_lock *);
static void if_detach_queues(struct ifnet *, struct ifqueue *);
static void sysctl_sndq_setup(struct sysctllog **, const char *,
struct ifaltq *);
@@ -296,7 +297,7 @@
if_nullioctl(struct ifnet *ifp, u_long cmd, void *data)
{
- cv_signal(&ifp->if_ioctl_emptied);
+ cv_signal(&ifp->if_ioctl_lock->il_emptied);
return ENXIO;
}
@@ -1697,19 +1698,21 @@
}
static void
-ifioctl_enter(struct ifnet *ifp)
+ifnet_lock_enter(struct ifnet_lock *il)
{
- uint64_t *nenter = percpu_getref(ifp->if_ioctl_nenter);
+ uint64_t *nenter;
+
+ nenter = percpu_getref(il->il_nenter);
(*nenter)++;
- percpu_putref(ifp->if_ioctl_nenter);
- mutex_enter(&ifp->if_ioctl_lock);
+ percpu_putref(il->il_nenter);
+ mutex_enter(&il->il_lock);
}
static void
-ifioctl_exit(struct ifnet *ifp)
+ifnet_lock_exit(struct ifnet_lock *il)
{
- ifp->if_ioctl_nexit++;
- mutex_exit(&ifp->if_ioctl_lock);
+ il->il_nexit++;
+ mutex_exit(&il->il_lock);
}
/*
@@ -1820,7 +1823,7 @@
oif_flags = ifp->if_flags;
- ifioctl_enter(ifp);
+ ifnet_lock_enter(ifp->if_ioctl_lock);
error = (*ifp->if_ioctl)(ifp, cmd, data);
if (error != ENOTTY)
;
@@ -1850,12 +1853,12 @@
ifreqn2o(oifr, ifr);
#endif
- ifioctl_exit(ifp);
+ ifnet_lock_exit(ifp->if_ioctl_lock);
return error;
}
static void
-ifioctl_sum(void *p, void *arg, struct cpu_info *ci)
+ifnet_lock_sum(void *p, void *arg, struct cpu_info *ci)
{
uint64_t *sum = arg, *nenter = p;
@@ -1863,11 +1866,11 @@
}
static uint64_t
-ifioctl_entrances(struct ifnet *ifp)
+ifnet_lock_entrances(struct ifnet_lock *il)
{
uint64_t sum = 0;
- percpu_foreach(ifp->if_ioctl_nenter, ifioctl_sum, &sum);
+ percpu_foreach(il->il_nenter, ifnet_lock_sum, &sum);
return sum;
}
@@ -1875,15 +1878,24 @@
static int
ifioctl_attach(struct ifnet *ifp)
{
+ struct ifnet_lock *il;
+
if (ifp->if_ioctl == NULL)
ifp->if_ioctl = ifioctl_common;
- ifp->if_ioctl_nenter = percpu_alloc(sizeof(uint64_t));
- if (ifp->if_ioctl_nenter == NULL)
+ if ((il = kmem_zalloc(sizeof(*il), KM_SLEEP)) == NULL)
return ENOMEM;
- mutex_init(&ifp->if_ioctl_lock, MUTEX_DEFAULT, IPL_NONE);
- cv_init(&ifp->if_ioctl_emptied, ifp->if_xname);
+ il->il_nenter = percpu_alloc(sizeof(uint64_t));
+ if (il->il_nenter == NULL) {
+ kmem_free(il, sizeof(*il));
+ return ENOMEM;
+ }
+
+ mutex_init(&il->il_lock, MUTEX_DEFAULT, IPL_NONE);
+ cv_init(&il->il_emptied, ifp->if_xname);
+
+ ifp->if_ioctl_lock = il;
return 0;
}
@@ -1891,11 +1903,16 @@
static void
ifioctl_detach(struct ifnet *ifp)
{
- mutex_enter(&ifp->if_ioctl_lock);
+ struct ifnet_lock *il;
+
+ il = ifp->if_ioctl_lock;
+ mutex_enter(&il->il_lock);
ifp->if_ioctl = if_nullioctl;
- while (ifioctl_entrances(ifp) != ifp->if_ioctl_nexit)
- cv_wait(&ifp->if_ioctl_emptied, &ifp->if_ioctl_lock);
- mutex_exit(&ifp->if_ioctl_lock);
+ while (ifnet_lock_entrances(il) != il->il_nexit)
+ cv_wait(&il->il_emptied, &il->il_lock);
+ mutex_exit(&il->il_lock);
+ ifp->if_ioctl_lock = NULL;
+ kmem_free(il, sizeof(*il));
}
/*
diff -r 1d09dc96f8b0 -r 89b2f4f7143b sys/net/if.h
--- a/sys/net/if.h Wed Oct 19 21:12:50 2011 +0000
+++ b/sys/net/if.h Wed Oct 19 21:29:51 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.h,v 1.152 2011/10/19 01:34:37 dyoung Exp $ */
+/* $NetBSD: if.h,v 1.153 2011/10/19 21:29:51 dyoung Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -77,9 +77,6 @@
#if defined(_NETBSD_SOURCE)
-#include <sys/mutex.h>
-#include <sys/condvar.h>
-#include <sys/percpu.h>
#include <sys/socket.h>
#include <sys/queue.h>
#include <net/dlt.h>
@@ -204,6 +201,21 @@
int ifq_drops;
};
+struct ifnet_lock;
+
+#ifdef _KERNEL
+#include <sys/mutex.h>
+#include <sys/condvar.h>
+#include <sys/percpu.h>
+
+struct ifnet_lock {
+ kmutex_t il_lock;
+ uint64_t il_nexit;
+ percpu_t *il_nenter;
+ kcondvar_t il_emptied;
+};
+#endif /* _KERNEL */
+
/*
* Structure defining a queue for a network interface.
*
@@ -305,12 +317,9 @@
int (*if_mcastop)(struct ifnet *, const unsigned long,
const struct sockaddr *);
int (*if_setflags)(struct ifnet *, const short);
- kmutex_t if_ioctl_lock;
- uint64_t if_ioctl_nexit;
- percpu_t *if_ioctl_nenter;
- kcondvar_t if_ioctl_emptied;
+ struct ifnet_lock *if_ioctl_lock;
} ifnet_t;
-
+
#define if_mtu if_data.ifi_mtu
#define if_type if_data.ifi_type
#define if_addrlen if_data.ifi_addrlen
Home |
Main Index |
Thread Index |
Old Index