Changeset View
Standalone View
sys/kern/uipc_mbuf.c
Show First 20 Lines • Show All 1,133 Lines • ▼ Show 20 Lines | while (totlen > 0) { | ||||
buf += len; | buf += len; | ||||
*mp = m; | *mp = m; | ||||
mp = &m->m_next; | mp = &m->m_next; | ||||
totlen -= len; | totlen -= len; | ||||
} | } | ||||
return (top); | return (top); | ||||
} | } | ||||
static void | |||||
m_copytounmapped(const struct mbuf *m, int off, int len, c_caddr_t cp) | |||||
{ | |||||
struct iovec iov; | |||||
struct uio uio; | |||||
int error; | |||||
KASSERT(off >= 0, ("m_copytounmapped: negative off %d", off)); | |||||
KASSERT(len >= 0, ("m_copytounmapped: negative len %d", len)); | |||||
KASSERT(off < m->m_len, ("m_copytounmapped: len exceeds mbuf length")); | |||||
iov.iov_base = __DECONST(caddr_t, cp); | |||||
iov.iov_len = len; | |||||
uio.uio_resid = len; | |||||
uio.uio_iov = &iov; | |||||
uio.uio_segflg = UIO_SYSSPACE; | |||||
uio.uio_iovcnt = 1; | |||||
uio.uio_offset = 0; | |||||
uio.uio_rw = UIO_WRITE; | |||||
error = m_unmappedtouio(m, off, &uio, len); | |||||
KASSERT(error == 0, ("m_unmappedtouio failed: off %d, len %d", off, | |||||
len)); | |||||
} | |||||
/* | /* | ||||
* Copy data from a buffer back into the indicated mbuf chain, | * Copy data from a buffer back into the indicated mbuf chain, | ||||
* starting "off" bytes from the beginning, extending the mbuf | * starting "off" bytes from the beginning, extending the mbuf | ||||
* chain if necessary. | * chain if necessary. | ||||
*/ | */ | ||||
void | void | ||||
m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp) | m_copyback(struct mbuf *m0, int off, int len, c_caddr_t cp) | ||||
{ | { | ||||
Show All 17 Lines | while (off > (mlen = m->m_len)) { | ||||
m = m->m_next; | m = m->m_next; | ||||
} | } | ||||
while (len > 0) { | while (len > 0) { | ||||
if (m->m_next == NULL && (len > m->m_len - off)) { | if (m->m_next == NULL && (len > m->m_len - off)) { | ||||
m->m_len += min(len - (m->m_len - off), | m->m_len += min(len - (m->m_len - off), | ||||
M_TRAILINGSPACE(m)); | M_TRAILINGSPACE(m)); | ||||
} | } | ||||
mlen = min (m->m_len - off, len); | mlen = min (m->m_len - off, len); | ||||
if ((m->m_flags & M_EXTPG) != 0) | |||||
m_copytounmapped(m, off, mlen, cp); | |||||
else | |||||
bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen); | bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen); | ||||
cp += mlen; | cp += mlen; | ||||
len -= mlen; | len -= mlen; | ||||
mlen += off; | mlen += off; | ||||
off = 0; | off = 0; | ||||
totlen += mlen; | totlen += mlen; | ||||
if (len == 0) | if (len == 0) | ||||
break; | break; | ||||
if (m->m_next == NULL) { | if (m->m_next == NULL) { | ||||
▲ Show 20 Lines • Show All 671 Lines • ▼ Show 20 Lines | if (flags & M_PKTHDR) | ||||
m->m_pkthdr.len += length; | m->m_pkthdr.len += length; | ||||
} | } | ||||
KASSERT(progress == total, ("%s: progress != total", __func__)); | KASSERT(progress == total, ("%s: progress != total", __func__)); | ||||
return (m); | return (m); | ||||
} | } | ||||
/* | /* | ||||
* Copy data from an unmapped mbuf into a uio limited by len if set. | * Copy data to/from an unmapped mbuf into a uio limited by len if set. | ||||
markj: m_unmappeduiomove() or so might be a better name then. Not sure if it's worth the churn. | |||||
gallatinUnsubmitted Not Done Inline ActionsWe also have m_copyfromunmapped(). We could add a m_unmappeduiomove(.. int direction) and make the existing functions wrappers.. gallatin: We also have m_copyfromunmapped(). We could add a m_unmappeduiomove(.. int direction) and make… | |||||
jhbAuthorUnsubmitted Done Inline Actionsm_copy{to,from}unmapped() are kind of wrappers already, they just construct different uio's to pass to this routine. In that regard they are similar to the physcopy{in,out} wrappers around uiomove_fromphys(). uiomove_fromphys() suffers similar naming issues (it copies to/from physical pages, not only from physical pages). This routine is also used by m_mbuftouio() which is where it gets is original name from. I don't mind renaming this. It isn't a lot of churn. The one use case outside of this file is in soreceive() where it is paired with uiomove(), so something in the uiomove_* namespace ala uiomove_fromphys() might not be a bad name for it. jhb: m_copy{to,from}unmapped() are kind of wrappers already, they just construct different uio's to… | |||||
markjUnsubmitted Not Done Inline ActionsI don't have strong feelings about it. The m_* namespace makes more sense to me for this routine, so I'm inclined to prefer m_unmapped_uiomove(), but uiomove_mbuf_unmapped() or so would be ok. The name uiomove_fromphys() has always bugged me for exactly the reason you point out. markj: I don't have strong feelings about it. The m_* namespace makes more sense to me for this… | |||||
jhbAuthorUnsubmitted Done Inline ActionsI'll add a followup commit after this one that renames it to m_unmapped_uiomove(). jhb: I'll add a followup commit after this one that renames it to m_unmapped_uiomove(). | |||||
*/ | */ | ||||
int | int | ||||
m_unmappedtouio(const struct mbuf *m, int m_off, struct uio *uio, int len) | m_unmappedtouio(const struct mbuf *m, int m_off, struct uio *uio, int len) | ||||
{ | { | ||||
vm_page_t pg; | vm_page_t pg; | ||||
int error, i, off, pglen, pgoff, seglen, segoff; | int error, i, off, pglen, pgoff, seglen, segoff; | ||||
M_ASSERTEXTPG(m); | M_ASSERTEXTPG(m); | ||||
▲ Show 20 Lines • Show All 355 Lines • Show Last 20 Lines |
m_unmappeduiomove() or so might be a better name then. Not sure if it's worth the churn.