projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add copyright
[unix-history]
/
usr
/
src
/
sys
/
kern
/
uipc_mbuf.c
diff --git
a/usr/src/sys/kern/uipc_mbuf.c
b/usr/src/sys/kern/uipc_mbuf.c
index
6bd164d
..
ca8d4af
100644
(file)
--- a/
usr/src/sys/kern/uipc_mbuf.c
+++ b/
usr/src/sys/kern/uipc_mbuf.c
@@
-1,57
+1,66
@@
-/* uipc_mbuf.c 6.1 83/07/29 */
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ * @(#)uipc_mbuf.c 6.5 (Berkeley) %G%
+ */
#include "../machine/pte.h"
#include "../machine/pte.h"
-#include "
../h/
param.h"
-#include "
../h/
dir.h"
-#include "
../h/
user.h"
-#include "
../h/
proc.h"
-#include "
../h/
cmap.h"
-#include "
../h/
map.h"
-#include "
../h/
mbuf.h"
-#include "
../h/
vm.h"
-#include "
../h/
kernel.h"
+#include "param.h"
+#include "dir.h"
+#include "user.h"
+#include "proc.h"
+#include "cmap.h"
+#include "map.h"
+#include "mbuf.h"
+#include "vm.h"
+#include "kernel.h"
mbinit()
{
mbinit()
{
+ int s;
- if (m_clalloc(4096/CLBYTES, MPG_MBUFS) == 0)
+ s = splimp();
+ if (m_clalloc(4096/CLBYTES, MPG_MBUFS, M_DONTWAIT) == 0)
goto bad;
goto bad;
- if (m_clalloc(8*4096/CLBYTES, MPG_CLUSTERS) == 0)
+ if (m_clalloc(8*4096/CLBYTES, MPG_CLUSTERS
, M_DONTWAIT
) == 0)
goto bad;
goto bad;
+ splx(s);
return;
bad:
panic("mbinit");
}
return;
bad:
panic("mbinit");
}
+/*
+ * Must be called at splimp.
+ */
caddr_t
caddr_t
-m_clalloc(ncl, how)
+m_clalloc(ncl, how
, canwait
)
register int ncl;
int how;
{
int npg, mbx;
register struct mbuf *m;
register int i;
register int ncl;
int how;
{
int npg, mbx;
register struct mbuf *m;
register int i;
- int s;
npg = ncl * CLSIZE;
npg = ncl * CLSIZE;
- s = splimp(); /* careful: rmalloc isn't reentrant */
mbx = rmalloc(mbmap, (long)npg);
mbx = rmalloc(mbmap, (long)npg);
- splx(s);
- if (mbx == 0)
+ if (mbx == 0) {
+ if (canwait == M_WAIT)
+ panic("out of mbuf map");
return (0);
return (0);
+ }
m = cltom(mbx / CLSIZE);
if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
m = cltom(mbx / CLSIZE);
if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
- s = splimp();
rmfree(mbmap, (long)npg, (long)mbx);
rmfree(mbmap, (long)npg, (long)mbx);
- splx(s);
return (0);
}
vmaccess(&Mbmap[mbx], (caddr_t)m, npg);
switch (how) {
case MPG_CLUSTERS:
return (0);
}
vmaccess(&Mbmap[mbx], (caddr_t)m, npg);
switch (how) {
case MPG_CLUSTERS:
- s = splimp();
for (i = 0; i < ncl; i++) {
m->m_off = 0;
m->m_next = mclfree;
for (i = 0; i < ncl; i++) {
m->m_off = 0;
m->m_next = mclfree;
@@
-60,7
+69,6
@@
m_clalloc(ncl, how)
mbstat.m_clfree++;
}
mbstat.m_clusters += ncl;
mbstat.m_clfree++;
}
mbstat.m_clusters += ncl;
- splx(s);
break;
case MPG_MBUFS:
break;
case MPG_MBUFS:
@@
-87,10
+95,14
@@
m_pgfree(addr, n)
#endif
}
#endif
}
-m_expand()
+/*
+ * Must be called at splimp.
+ */
+m_expand(canwait)
+ int canwait;
{
{
- if (m_clalloc(1, MPG_MBUFS) == 0)
+ if (m_clalloc(1, MPG_MBUFS
, canwait
) == 0)
goto steal;
return (1);
steal:
goto steal;
return (1);
steal:
@@
-121,7
+133,7
@@
m_getclr(canwait, type)
{
register struct mbuf *m;
{
register struct mbuf *m;
-
m = m_get(
canwait, type);
+
MGET(m,
canwait, type);
if (m == 0)
return (0);
bzero(mtod(m, caddr_t), MLEN);
if (m == 0)
return (0);
bzero(mtod(m, caddr_t), MLEN);
@@
-138,6
+150,10
@@
m_free(m)
return (n);
}
return (n);
}
+/*
+ * Get more mbufs; called from MGET macro if mfree list is empty.
+ * Must be called at splimp.
+ */
/*ARGSUSED*/
struct mbuf *
m_more(canwait, type)
/*ARGSUSED*/
struct mbuf *
m_more(canwait, type)
@@
-145,9
+161,14
@@
m_more(canwait, type)
{
register struct mbuf *m;
{
register struct mbuf *m;
- if (!m_expand()) {
- mbstat.m_drops++;
- return (NULL);
+ while (m_expand(canwait) == 0) {
+ if (canwait == M_WAIT) {
+ m_want++;
+ sleep((caddr_t)mfree, PZERO - 1);
+ } else {
+ mbstat.m_drops++;
+ return (NULL);
+ }
}
#define m_more(x,y) (panic("m_more"), (struct mbuf *)0)
MGET(m, canwait, type);
}
#define m_more(x,y) (panic("m_more"), (struct mbuf *)0)
MGET(m, canwait, type);
@@
-173,6
+194,12
@@
m_freem(m)
/*
* Mbuffer utility routines.
*/
/*
* Mbuffer utility routines.
*/
+
+/*
+ * Make a copy of an mbuf chain starting "off" bytes from the beginning,
+ * continuing for "len" bytes. If len is M_COPYALL, copy to end of mbuf.
+ * Should get M_WAIT/M_DONTWAIT from caller.
+ */
struct mbuf *
m_copy(m, off, len)
register struct mbuf *m;
struct mbuf *
m_copy(m, off, len)
register struct mbuf *m;
@@
-181,13
+208,11
@@
m_copy(m, off, len)
{
register struct mbuf *n, **np;
struct mbuf *top, *p;
{
register struct mbuf *n, **np;
struct mbuf *top, *p;
- int type;
if (len == 0)
return (0);
if (off < 0 || len < 0)
panic("m_copy");
if (len == 0)
return (0);
if (off < 0 || len < 0)
panic("m_copy");
- type = m->m_type;
while (off > 0) {
if (m == 0)
panic("m_copy");
while (off > 0) {
if (m == 0)
panic("m_copy");
@@
-204,7
+229,7
@@
m_copy(m, off, len)
panic("m_copy");
break;
}
panic("m_copy");
break;
}
- MGET(n, M_
WAIT,
type);
+ MGET(n, M_
DONTWAIT, m->m_
type);
*np = n;
if (n == 0)
goto nospace;
*np = n;
if (n == 0)
goto nospace;