Page MenuHomeFreeBSD

D20051.id62743.diff
No OneTemporary

D20051.id62743.diff

Index: sys/net/if.c
===================================================================
--- sys/net/if.c
+++ sys/net/if.c
@@ -1088,10 +1088,9 @@
struct ifnet *iter;
int found = 0;
#ifdef VIMAGE
- int shutdown;
+ bool shutdown;
- shutdown = (ifp->if_vnet->vnet_state > SI_SUB_VNET &&
- ifp->if_vnet->vnet_state < SI_SUB_VNET_DONE) ? 1 : 0;
+ shutdown = !vnet_is_running(ifp->if_vnet);
#endif
IFNET_WLOCK();
CK_STAILQ_FOREACH(iter, &V_ifnet, if_link)
@@ -1341,7 +1340,7 @@
{
struct prison *pr;
struct ifnet *difp;
- int shutdown;
+ bool shutdown;
/* Try to find the prison within our visibility. */
sx_slock(&allprison_lock);
@@ -1369,8 +1368,7 @@
}
/* Make sure the VNET is stable. */
- shutdown = (ifp->if_vnet->vnet_state > SI_SUB_VNET &&
- ifp->if_vnet->vnet_state < SI_SUB_VNET_DONE) ? 1 : 0;
+ shutdown = !vnet_is_running(ifp->if_vnet);
if (shutdown) {
CURVNET_RESTORE();
prison_free(pr);
@@ -1394,7 +1392,7 @@
struct prison *pr;
struct vnet *vnet_dst;
struct ifnet *ifp;
- int shutdown;
+ bool shutdown;
/* Try to find the prison within our visibility. */
sx_slock(&allprison_lock);
@@ -1423,8 +1421,7 @@
}
/* Make sure the VNET is stable. */
- shutdown = (ifp->if_vnet->vnet_state > SI_SUB_VNET &&
- ifp->if_vnet->vnet_state < SI_SUB_VNET_DONE) ? 1 : 0;
+ shutdown = !vnet_is_running(ifp->if_vnet);
if (shutdown) {
CURVNET_RESTORE();
prison_free(pr);
@@ -2997,14 +2994,13 @@
int error;
int oif_flags;
#ifdef VIMAGE
- int shutdown;
+ bool shutdown;
#endif
CURVNET_SET(so->so_vnet);
#ifdef VIMAGE
/* Make sure the VNET is stable. */
- shutdown = (so->so_vnet->vnet_state > SI_SUB_VNET &&
- so->so_vnet->vnet_state < SI_SUB_VNET_DONE) ? 1 : 0;
+ shutdown = !vnet_is_running(so->so_vnet);
if (shutdown) {
CURVNET_RESTORE();
return (EBUSY);
Index: sys/net/vnet.h
===================================================================
--- sys/net/vnet.h
+++ sys/net/vnet.h
@@ -72,7 +72,7 @@
u_int vnet_magic_n;
u_int vnet_ifcnt;
u_int vnet_sockcnt;
- u_int vnet_state; /* SI_SUB_* */
+ u_int vnet_is_running;
void *vnet_data_mem;
uintptr_t vnet_data_base;
};
@@ -326,6 +326,8 @@
};
#define VNET_SYSINIT(ident, subsystem, order, func, arg) \
+ CTASSERT((subsystem) > SI_SUB_VNET && \
+ (subsystem) <= SI_SUB_VNET_DONE); \
static struct vnet_sysinit ident ## _vnet_init = { \
subsystem, \
order, \
@@ -338,6 +340,8 @@
vnet_deregister_sysinit, &ident ## _vnet_init)
#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \
+ CTASSERT((subsystem) > SI_SUB_VNET && \
+ (subsystem) <= SI_SUB_VNET_DONE); \
static struct vnet_sysinit ident ## _vnet_uninit = { \
subsystem, \
order, \
@@ -350,6 +354,11 @@
vnet_deregister_sysuninit, &ident ## _vnet_uninit)
/*
+ * Check if VNET is ready.
+ */
+bool vnet_is_running(struct vnet *);
+
+/*
* Run per-vnet sysinits or sysuninits during vnet creation/destruction.
*/
void vnet_sysinit(void);
Index: sys/net/vnet.c
===================================================================
--- sys/net/vnet.c
+++ sys/net/vnet.c
@@ -235,7 +235,6 @@
SDT_PROBE1(vnet, functions, vnet_alloc, entry, __LINE__);
vnet = malloc(sizeof(struct vnet), M_VNET, M_WAITOK | M_ZERO);
vnet->vnet_magic_n = VNET_MAGIC_N;
- vnet->vnet_state = 0;
SDT_PROBE2(vnet, functions, vnet_alloc, alloc, __LINE__, vnet);
/*
@@ -351,17 +350,35 @@
}
SYSINIT(vnet_data, SI_SUB_KLD, SI_ORDER_FIRST, vnet_data_startup, NULL);
-/* Dummy VNET_SYSINIT to make sure we always reach the final end state. */
static void
-vnet_sysinit_done(void *unused __unused)
+vnet_sysinit_running(void *unused __unused)
{
- return;
+ curvnet->vnet_is_running = 1;
}
-VNET_SYSINIT(vnet_sysinit_done, SI_SUB_VNET_DONE, SI_ORDER_ANY,
- vnet_sysinit_done, NULL);
+VNET_SYSINIT(vnet_sysinit_running, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+ vnet_sysinit_running, NULL);
+static void
+vnet_sysuninit_running(void *unused __unused)
+{
+
+ curvnet->vnet_is_running = 0;
+}
+VNET_SYSUNINIT(vnet_sysuninit_running, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+ vnet_sysuninit_running, NULL);
+
/*
+ * Check if VNET is running.
+ */
+bool
+vnet_is_running(struct vnet *vnet)
+{
+
+ return (vnet->vnet_is_running);
+}
+
+/*
* When a module is loaded and requires storage for a virtualized global
* variable, allocate space from the modspace free list. This interface
* should be used only by the kernel linker.
@@ -573,10 +590,8 @@
struct vnet_sysinit *vs;
VNET_SYSINIT_RLOCK();
- TAILQ_FOREACH(vs, &vnet_constructors, link) {
- curvnet->vnet_state = vs->subsystem;
+ TAILQ_FOREACH(vs, &vnet_constructors, link)
vs->func(vs->arg);
- }
VNET_SYSINIT_RUNLOCK();
}
@@ -593,7 +608,6 @@
VNET_SYSINIT_RLOCK();
TAILQ_FOREACH_REVERSE(vs, &vnet_destructors, vnet_sysuninit_head,
link) {
- curvnet->vnet_state = vs->subsystem;
vs->func(vs->arg);
}
VNET_SYSINIT_RUNLOCK();
@@ -709,7 +723,7 @@
db_printf(" vnet_data_mem = %p\n", vnet->vnet_data_mem);
db_printf(" vnet_data_base = %#jx\n",
(uintmax_t)vnet->vnet_data_base);
- db_printf(" vnet_state = %#08x\n", vnet->vnet_state);
+ db_printf(" vnet_is_running = %u\n", vnet->vnet_is_running);
db_printf("\n");
}

File Metadata

Mime Type
text/plain
Expires
Tue, Jun 16, 3:21 PM (12 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33991289
Default Alt Text
D20051.id62743.diff (5 KB)

Event Timeline