Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110669399
D33259.id99447.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D33259.id99447.diff
View Options
Index: sys/net/if.c
===================================================================
--- sys/net/if.c
+++ sys/net/if.c
@@ -331,13 +331,6 @@
SX_SYSINIT_FLAGS(ifnet_detach, &ifnet_detach_sxlock, "ifnet_detach_sx",
SX_RECURSE);
-/*
- * The allocation of network interfaces is a rather non-atomic affair; we
- * need to select an index before we are ready to expose the interface for
- * use, so will use this pointer value to indicate reservation.
- */
-#define IFNET_HOLD (void *)(uintptr_t)(-1)
-
#ifdef VIMAGE
#define VNET_IS_SHUTTING_DOWN(_vnet) \
((_vnet)->vnet_shutdown && (_vnet)->vnet_state < SI_SUB_VNET_DONE)
@@ -353,13 +346,11 @@
struct ifnet *
ifnet_byindex(u_short idx)
{
- struct ifnet *ifp;
if (__predict_false(idx > V_if_index))
return (NULL);
- ifp = *(struct ifnet * const volatile *)(V_ifindex_table + idx);
- return (__predict_false(ifp == IFNET_HOLD) ? NULL : ifp);
+ return (V_ifindex_table[idx]);
}
struct ifnet *
@@ -422,6 +413,7 @@
ifnet_setbyindex(u_short idx, struct ifnet *ifp)
{
+ ifp->if_index = idx;
V_ifindex_table[idx] = ifp;
}
@@ -608,18 +600,6 @@
else
ifp = malloc_domainset(sizeof(struct ifnet), M_IFNET,
DOMAINSET_PREF(numa_domain), M_WAITOK | M_ZERO);
- restart:
- IFNET_WLOCK();
- idx = ifindex_alloc(&old);
- if (__predict_false(idx == USHRT_MAX)) {
- IFNET_WUNLOCK();
- epoch_wait_preempt(net_epoch_preempt);
- free(old, M_IFNET);
- goto restart;
- }
- ifnet_setbyindex(idx, IFNET_HOLD);
- IFNET_WUNLOCK();
- ifp->if_index = idx;
ifp->if_type = type;
ifp->if_alloctype = type;
ifp->if_numa_domain = numa_domain;
@@ -650,7 +630,19 @@
ifp->if_counters[i] = counter_u64_alloc(M_WAITOK);
ifp->if_get_counter = if_get_counter_default;
ifp->if_pcp = IFNET_PCP_NONE;
- ifnet_setbyindex(ifp->if_index, ifp);
+
+restart:
+ IFNET_WLOCK();
+ idx = ifindex_alloc(&old);
+ if (__predict_false(idx == USHRT_MAX)) {
+ IFNET_WUNLOCK();
+ epoch_wait_preempt(net_epoch_preempt);
+ free(old, M_IFNET);
+ goto restart;
+ }
+ ifnet_setbyindex(idx, ifp);
+ IFNET_WUNLOCK();
+
return (ifp);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 22, 5:15 PM (4 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16775569
Default Alt Text
D33259.id99447.diff (2 KB)
Attached To
Mode
D33259: ifnet: allocate index at the end of if_alloc_domain()
Attached
Detach File
Event Timeline
Log In to Comment