Factor out VNET shutdown check into an own vnet structure field.

Remove the now obsolete vnet_state field. This greatly simplifies the
detection of VNET shutdown and avoids code duplication.

Discussed with:	bz@
MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2019-10-07 14:15:41 +00:00
parent ac66be4122
commit 204e2f30d9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=353274
4 changed files with 13 additions and 27 deletions

View File

@ -1088,10 +1088,9 @@ if_detach_internal(struct ifnet *ifp, int vmove, struct if_clone **ifcp)
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 = ifp->if_vnet->vnet_shutdown;
#endif
IFNET_WLOCK();
CK_STAILQ_FOREACH(iter, &V_ifnet, if_link)
@ -1341,7 +1340,6 @@ if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid)
{
struct prison *pr;
struct ifnet *difp;
int shutdown;
/* Try to find the prison within our visibility. */
sx_slock(&allprison_lock);
@ -1369,9 +1367,7 @@ if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid)
}
/* 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;
if (shutdown) {
if (ifp->if_vnet->vnet_shutdown) {
CURVNET_RESTORE();
prison_free(pr);
return (EBUSY);
@ -1394,7 +1390,6 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid)
struct prison *pr;
struct vnet *vnet_dst;
struct ifnet *ifp;
int shutdown;
/* Try to find the prison within our visibility. */
sx_slock(&allprison_lock);
@ -1423,9 +1418,7 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid)
}
/* 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;
if (shutdown) {
if (ifp->if_vnet->vnet_shutdown) {
CURVNET_RESTORE();
prison_free(pr);
return (EBUSY);
@ -2996,16 +2989,11 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td)
struct ifreq *ifr;
int error;
int oif_flags;
#ifdef VIMAGE
int 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;
if (shutdown) {
if (so->so_vnet->vnet_shutdown) {
CURVNET_RESTORE();
return (EBUSY);
}

View File

@ -235,7 +235,6 @@ vnet_alloc(void)
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);
/*
@ -280,6 +279,9 @@ vnet_destroy(struct vnet *vnet)
LIST_REMOVE(vnet, vnet_le);
VNET_LIST_WUNLOCK();
/* Signal that VNET is being shutdown. */
vnet->vnet_shutdown = 1;
CURVNET_SET_QUIET(vnet);
vnet_sysuninit();
CURVNET_RESTORE();
@ -573,10 +575,8 @@ vnet_sysinit(void)
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();
}
@ -592,10 +592,8 @@ vnet_sysuninit(void)
VNET_SYSINIT_RLOCK();
TAILQ_FOREACH_REVERSE(vs, &vnet_destructors, vnet_sysuninit_head,
link) {
curvnet->vnet_state = vs->subsystem;
link)
vs->func(vs->arg);
}
VNET_SYSINIT_RUNLOCK();
}
@ -709,7 +707,7 @@ db_vnet_print(struct vnet *vnet)
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_shutdown = %#08x\n", vnet->vnet_shutdown);
db_printf("\n");
}

View File

@ -72,7 +72,7 @@ struct vnet {
u_int vnet_magic_n;
u_int vnet_ifcnt;
u_int vnet_sockcnt;
u_int vnet_state; /* SI_SUB_* */
u_int vnet_shutdown; /* Shutdown in progress. */
void *vnet_data_mem;
uintptr_t vnet_data_base;
};

View File

@ -60,7 +60,7 @@
* in the range 5 to 9.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1300048 /* Master, propagated to newvers */
#define __FreeBSD_version 1300049 /* Master, propagated to newvers */
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,