From 352d050e790e3ee7e8441dfd38d23bbd62c337a8 Mon Sep 17 00:00:00 2001 From: Mike Silbersack Date: Tue, 15 Apr 2003 02:14:43 +0000 Subject: [PATCH] Add another MBUF_STRESS_TEST feature, m_defragrandomfailures. When enabled, this causes m_defrag to randomly return NULL (following its normal failure case so that extra memory leaks are not introduced.) Code similar to this was used to find / fix a few bugs last week. --- sys/kern/uipc_mbuf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 08a7246409e..8810358ed9c 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -36,6 +36,7 @@ #include "opt_mac.h" #include "opt_param.h" +#include "opt_mbuf_stress_test.h" #include #include @@ -56,6 +57,9 @@ int m_defragpackets; int m_defragbytes; int m_defraguseless; int m_defragfailure; +#ifdef MBUF_STRESS_TEST +int m_defragrandomfailures; +#endif /* * sysctl(8) exported objects @@ -76,6 +80,10 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, m_defraguseless, CTLFLAG_RD, &m_defraguseless, 0, ""); SYSCTL_INT(_kern_ipc, OID_AUTO, m_defragfailure, CTLFLAG_RD, &m_defragfailure, 0, ""); +#ifdef MBUF_STRESS_TEST +SYSCTL_INT(_kern_ipc, OID_AUTO, m_defragrandomfailures, CTLFLAG_RW, + &m_defragrandomfailures, 0, ""); +#endif /* * "Move" mbuf pkthdr from "from" to "to". @@ -802,6 +810,13 @@ m_defrag(struct mbuf *m0, int how) if (!(m0->m_flags & M_PKTHDR)) return (m0); +#ifdef MBUF_STRESS_TEST + if (m_defragrandomfailures) { + int temp = arc4random() & 0xff; + if (temp == 0xba) + goto nospace; + } +#endif if (m0->m_pkthdr.len > MHLEN) m_final = m_getcl(how, MT_DATA, M_PKTHDR);