diff options
author | marius <marius@FreeBSD.org> | 2010-02-09 23:45:14 +0000 |
---|---|---|
committer | marius <marius@FreeBSD.org> | 2010-02-09 23:45:14 +0000 |
commit | efffc45c735166ffa1717576e4807cba15304cad (patch) | |
tree | 7818cc46c36d665fc28d90982bdd75b487296427 /sys/nfs | |
parent | 8c1dfdc492d1c6bd09a599013e66bb05a06a1d5c (diff) | |
download | FreeBSD-src-efffc45c735166ffa1717576e4807cba15304cad.zip FreeBSD-src-efffc45c735166ffa1717576e4807cba15304cad.tar.gz |
- Move nfs_realign() from the NFS client to the shared NFS code and
remove the NFS server version in order to reduce code duplication.
The shared version now uses a second parameter how, which is passed
on to m_get(9) and m_getcl(9) as the server used M_WAIT while the
client requires M_DONTWAIT, and replaces the the previously unused
parameter hsiz.
- Change nfs_realign() to use nfsm_aligned() so as with other NFS code
the alignment check isn't actually performed on platforms without
strict alignment requirements for performance reasons because as the
comment suggests unaligned data only occasionally occurs with TCP.
- Change fha_extract_info() to use nfs_realign() with M_DONTWAIT rather
than M_WAIT because it's called with the RPC sp_lock held.
Reviewed by: jhb, rmacklem
MFC after: 1 week
Diffstat (limited to 'sys/nfs')
-rw-r--r-- | sys/nfs/nfs_common.c | 67 | ||||
-rw-r--r-- | sys/nfs/nfs_common.h | 1 |
2 files changed, 68 insertions, 0 deletions
diff --git a/sys/nfs/nfs_common.c b/sys/nfs/nfs_common.c index 6f42645..abf575f 100644 --- a/sys/nfs/nfs_common.c +++ b/sys/nfs/nfs_common.c @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include <sys/malloc.h> #include <sys/sysent.h> #include <sys/syscall.h> +#include <sys/sysctl.h> #include <vm/vm.h> #include <vm/vm_object.h> @@ -78,6 +79,16 @@ nfstype nfsv3_type[9] = { static void *nfsm_dissect_xx_sub(int s, struct mbuf **md, caddr_t *dpos, int how); +SYSCTL_DECL(_vfs_nfs); + +static int nfs_realign_test; +SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RD, &nfs_realign_test, + 0, "Number of realign tests done"); + +static int nfs_realign_count; +SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RD, &nfs_realign_count, + 0, "Number of mbuf realignments done"); + u_quad_t nfs_curusec(void) { @@ -337,3 +348,59 @@ nfsm_adv_xx(int s, struct mbuf **md, caddr_t *dpos) return (t1); return (0); } + +/* + * Check for badly aligned mbuf data and realign by copying the unaligned + * portion of the data into a new mbuf chain and freeing the portions of the + * old chain that were replaced. + * + * We cannot simply realign the data within the existing mbuf chain because + * the underlying buffers may contain other rpc commands and we cannot afford + * to overwrite them. + * + * We would prefer to avoid this situation entirely. The situation does not + * occur with NFS/UDP and is supposed to only occassionally occur with TCP. + * Use vfs.nfs.realign_count and realign_test to check this. + */ +int +nfs_realign(struct mbuf **pm, int how) +{ + struct mbuf *m, *n; + int off; + + ++nfs_realign_test; + while ((m = *pm) != NULL) { + if (!nfsm_aligned(m->m_len, u_int32_t) || + !nfsm_aligned(mtod(m, intptr_t), u_int32_t)) { + /* + * NB: we can't depend on m_pkthdr.len to help us + * decide what to do here. May not be worth doing + * the m_length calculation as m_copyback will + * expand the mbuf chain below as needed. + */ + if (m_length(m, NULL) >= MINCLSIZE) { + /* NB: m_copyback handles space > MCLBYTES */ + n = m_getcl(how, MT_DATA, 0); + } else + n = m_get(how, MT_DATA); + if (n == NULL) + return (ENOMEM); + /* + * Align the remainder of the mbuf chain. + */ + n->m_len = 0; + off = 0; + while (m != NULL) { + m_copyback(n, off, m->m_len, mtod(m, caddr_t)); + off += m->m_len; + m = m->m_next; + } + m_freem(*pm); + *pm = n; + ++nfs_realign_count; + break; + } + pm = &m->m_next; + } + return (0); +} diff --git a/sys/nfs/nfs_common.h b/sys/nfs/nfs_common.h index 9ad1c11..1c0b315 100644 --- a/sys/nfs/nfs_common.h +++ b/sys/nfs/nfs_common.h @@ -48,6 +48,7 @@ extern nfstype nfsv3_type[]; int nfs_adv(struct mbuf **, caddr_t *, int, int); u_quad_t nfs_curusec(void); void *nfsm_disct(struct mbuf **, caddr_t *, int, int, int); +int nfs_realign(struct mbuf **, int); /* ****************************** */ /* Build request/reply phase macros */ |