Index: share/man/man9/Makefile =================================================================== RCS file: /cvs/src/share/man/man9/Makefile,v retrieving revision 1.248 diff -u -p -r1.248 Makefile --- share/man/man9/Makefile 22 Oct 2015 05:26:06 -0000 1.248 +++ share/man/man9/Makefile 30 Oct 2015 11:31:38 -0000 @@ -269,6 +269,7 @@ MLINKS+=microtime.9 getmicrotime.9 micro MLINKS+=ml_init.9 ml_enqueue.9 ml_init.9 ml_dequeue.9 ml_init.9 ml_requeue.9 \ ml_init.9 ml_enlist.9 ml_init.9 ml_dechain.9 \ ml_init.9 ml_filter.9 ml_init.9 ml_len.9 ml_init.9 ml_empty.9 \ + ml_init.9 ml_purge.9 \ ml_init.9 MBUF_LIST_INITIALIZER.9 ml_init.9 MBUF_LIST_FOREACH.9 MLINKS+=mountroothook_establish.9 mountroothook_disestablish.9 MLINKS+=mutex.9 mtx_init.9 mutex.9 mtx_enter.9 mutex.9 mtx_leave.9 \ @@ -277,7 +278,7 @@ MLINKS+=mutex.9 mtx_init.9 mutex.9 mtx_e MLINKS+=mutex.9 mtx_enter_try.9 MLINKS+=mq_init.9 mq_enqueue.9 mq_init.9 mq_dequeue.9 mq_init.9 mq_requeue.9 \ mq_init.9 mq_enlist.9 mq_init.9 mq_delist.9 \ - mq_init.9 mq_dechain.9 mq_init.9 mq_filter.9 \ + mq_init.9 mq_dechain.9 mq_init.9 mq_filter.9 mq_init.9 mq_purge.9 \ mq_init.9 mq_len.9 mq_init.9 mq_empty.9 mq_init.9 mq_drops.9 \ mq_init.9 mq_set_maxlen.9 mq_init.9 MBUF_QUEUE_INITIALIZER.9 MLINKS+=namei.9 vfs_lookup.9 namei.9 vfs_relookup.9 namei.9 NDINIT.9 Index: share/man/man9/ml_init.9 =================================================================== RCS file: /cvs/src/share/man/man9/ml_init.9,v retrieving revision 1.7 diff -u -p -r1.7 ml_init.9 --- share/man/man9/ml_init.9 22 Oct 2015 05:26:06 -0000 1.7 +++ share/man/man9/ml_init.9 30 Oct 2015 11:31:38 -0000 @@ -53,6 +53,8 @@ .Fn ml_len "struct mbuf_list *ml" .Ft int .Fn ml_empty "struct mbuf_list *ml" +.Ft unsigned int +.Fn ml_purge "struct mbuf_list *ml" .Ft struct mbuf_list .Fn MBUF_LIST_INITIALIZER .Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME" @@ -132,6 +134,10 @@ mbuf list. Return if the .Fa ml mbuf list is empty. +.It Fn ml_purge "struct mbuf_list *ml" +Free all the mbufs on the +.Fa ml +mbuf list. .It Fn MBUF_LIST_FOREACH "struct mbuf_list *ml" "VARNAME" A convenience macro that can be used to iterate over the contents of the .Fa ml @@ -150,6 +156,7 @@ Note that it is unsafe to modify the lis .Fn ml_dechain , .Fn ml_len , .Fn ml_empty , +.Fn ml_purge , .Fn MBUF_LIST_INITIALIZER , and .Fn MBUF_LIST_FOREACH @@ -180,5 +187,8 @@ returns the number of mbufs on the list. .Pp .Fn ml_empty return a non-zero value if the list is empty, otherwise 0. +.Pp +.Fn ml_purge +return the number of mbufs that were freed. .Sh SEE ALSO .Xr mbuf 9 Index: share/man/man9/mq_init.9 =================================================================== RCS file: /cvs/src/share/man/man9/mq_init.9,v retrieving revision 1.4 diff -u -p -r1.4 mq_init.9 --- share/man/man9/mq_init.9 23 Sep 2015 12:44:35 -0000 1.4 +++ share/man/man9/mq_init.9 30 Oct 2015 11:31:38 -0000 @@ -27,6 +27,7 @@ .Nm mq_dechain , .Nm mq_len , .Nm mq_empty , +.Nm mq_purge , .Nm mq_drops , .Nm mq_set_maxlen , .Nm MBUF_QUEUE_INITIALIZER @@ -58,6 +59,8 @@ .Ft int .Fn mq_empty "struct mbuf_queue *mq" .Ft unsigned int +.Fn mq_purge "struct mbuf_queue *mq" +.Ft unsigned int .Fn mq_drops "struct mbuf_queue *mq" .Ft void .Fn mq_set_maxlen "struct mbuf_queue *mq" "unsigned int" @@ -168,6 +171,10 @@ mbuf queue. Return if the .Fa mq mbuf queue is empty. +.It Fn mq_purge "struct mbuf_queue *mq" +Free all the mbufs on the +.Fa mq +mbuf queue. .It Fn mq_drops "struct mbuf_queue *mq" Return how many mbufs were dropped and freed by .Xr m_freem 9 @@ -193,6 +200,7 @@ already exist on the queue. .Fn mq_dechain , .Fn mq_len , .Fn mq_empty , +.Fn mq_purge , .Fn mq_drops , .Fn mq_set_maxlen , and @@ -237,6 +245,9 @@ length. .Fn mq_enlist returns the number of mbufs that were dropped from the list if the length of the queue exceeded its maximum length. +.Pp +.Fn mq_purge +return the number of mbufs that were freed. .Pp .Fn mq_drops returns the number of mbufs that were freed during Index: sys/sys/mbuf.h =================================================================== RCS file: /cvs/src/sys/sys/mbuf.h,v retrieving revision 1.198 diff -u -p -r1.198 mbuf.h --- sys/sys/mbuf.h 22 Oct 2015 05:26:06 -0000 1.198 +++ sys/sys/mbuf.h 30 Oct 2015 11:31:38 -0000 @@ -491,6 +491,7 @@ void ml_enlist(struct mbuf_list *, str struct mbuf * ml_dechain(struct mbuf_list *); struct mbuf * ml_filter(struct mbuf_list *, int (*)(void *, const struct mbuf *), void *); +unsigned int ml_purge(struct mbuf_list *); #define ml_len(_ml) ((_ml)->ml_len) #define ml_empty(_ml) ((_ml)->ml_len == 0) @@ -521,6 +522,7 @@ void mq_delist(struct mbuf_queue *, st struct mbuf * mq_dechain(struct mbuf_queue *); struct mbuf * mq_filter(struct mbuf_queue *, int (*)(void *, const struct mbuf *), void *); +unsigned int mq_purge(struct mbuf_queue *); #define mq_len(_mq) ml_len(&(_mq)->mq_list) #define mq_empty(_mq) ml_empty(&(_mq)->mq_list) Index: sys/kern/uipc_mbuf.c =================================================================== RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.208 diff -u -p -r1.208 uipc_mbuf.c --- sys/kern/uipc_mbuf.c 22 Oct 2015 05:26:06 -0000 1.208 +++ sys/kern/uipc_mbuf.c 30 Oct 2015 11:31:38 -0000 @@ -1351,6 +1351,23 @@ ml_filter(struct mbuf_list *ml, return (matches.ml_head); /* ml_dechain */ } +unsigned int +ml_purge(struct mbuf_list *ml) +{ + struct mbuf *m, *n; + unsigned int len; + + for (m = ml->ml_head; m != NULL; m = n) { + n = m->m_nextpkt; + m_freem(m); + } + + len = ml->ml_len; + ml_init(ml); + + return (len); +} + /* * mbuf queues */ @@ -1463,4 +1480,14 @@ mq_filter(struct mbuf_queue *mq, mtx_leave(&mq->mq_mtx); return (m0); +} + +unsigned int +mq_purge(struct mbuf_queue *mq) +{ + struct mbuf_list ml; + + mq_delist(mq, &ml); + + return (ml_purge(&ml)); }