diff options
author | ps <ps@FreeBSD.org> | 2004-12-15 22:20:22 +0000 |
---|---|---|
committer | ps <ps@FreeBSD.org> | 2004-12-15 22:20:22 +0000 |
commit | 7c0944d56c2504d71b846fe79d625028c80cdfd8 (patch) | |
tree | c7f222f7a8c32bdc81d83fd0f9f6321889902c8b /sys/nfsclient/nfs_vnops.c | |
parent | ede2fb9751ccd8ce53c764a80e9c92cf19817e80 (diff) | |
download | FreeBSD-src-7c0944d56c2504d71b846fe79d625028c80cdfd8.zip FreeBSD-src-7c0944d56c2504d71b846fe79d625028c80cdfd8.tar.gz |
First cut of NFS direct IO support.
- NFS direct IO completely bypasses the buffer and page caches.
If a file is open for direct IO all caching is disabled.
- Direct IO for Directories will be addressed later.
- 2 new NFS directio related sysctls are added. One is a knob to
disable NFS direct IO completely (direct IO is enabled by default).
The other is to disallow mmaped IO on a file that has at least one
O_DIRECT open (see the comment in nfs_vnops.c for more details).
The default is to allow mmaps on a file that has O_DIRECT opens.
Submitted by: Mohan Srinivasan mohans at yahoo-inc dot com
Obtained from: Yahoo!
Diffstat (limited to 'sys/nfsclient/nfs_vnops.c')
-rw-r--r-- | sys/nfsclient/nfs_vnops.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c index 294f9c3..dd88e42 100644 --- a/sys/nfsclient/nfs_vnops.c +++ b/sys/nfsclient/nfs_vnops.c @@ -211,6 +211,24 @@ static int nfs_clean_pages_on_close = 1; SYSCTL_INT(_vfs_nfs, OID_AUTO, clean_pages_on_close, CTLFLAG_RW, &nfs_clean_pages_on_close, 0, "NFS clean dirty pages on close"); +int nfs_directio_enable = 1; +SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_directio_enable, CTLFLAG_RW, + &nfs_directio_enable, 0, "Enable NFS directio"); + +/* + * This sysctl allows other processes to mmap a file that has been opened O_DIRECT + * by a process. In general, having processes mmap the file while Direct IO is in + * progress can lead to Data Inconsistencies. But, we allow this by default to + * prevent DoS attacks - to prevent a malicious user from opening up files O_DIRECT + * preventing other users from mmap'ing these files. "Protected" environments where + * stricter consistency guarantees are required can disable this knob. + * The process that opened the file O_DIRECT cannot mmap() the file, because + * mmap'ed IO on an O_DIRECT open() is not meaningful. + */ +int nfs_directio_allow_mmap = 1; +SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_directio_allow_mmap, CTLFLAG_RW, + &nfs_directio_allow_mmap, 0, "Enable mmaped IO on file with O_DIRECT opens"); + #if 0 SYSCTL_INT(_vfs_nfs, OID_AUTO, access_cache_hits, CTLFLAG_RD, &nfsstats.accesscache_hits, 0, "NFS ACCESS cache hit count"); @@ -401,6 +419,7 @@ nfs_open(struct vop_open_args *ap) struct nfsnode *np = VTONFS(vp); struct vattr vattr; int error; + int fmode = ap->a_mode; if (vp->v_type != VREG && vp->v_type != VDIR && vp->v_type != VLNK) return (EOPNOTSUPP); @@ -434,6 +453,18 @@ nfs_open(struct vop_open_args *ap) np->n_mtime = vattr.va_mtime; } } + /* + * If the object has >= 1 O_DIRECT active opens, we disable caching. + */ + if (nfs_directio_enable && (fmode & O_DIRECT) && (vp->v_type == VREG)) { + if (np->n_directio_opens == 0) { + error = nfs_vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_td, 1); + if (error) + return (error); + np->n_flag |= NNONCACHE; + } + np->n_directio_opens++; + } np->ra_expect_lbn = 0; return (0); } @@ -472,6 +503,7 @@ nfs_close(struct vop_close_args *ap) struct vnode *vp = ap->a_vp; struct nfsnode *np = VTONFS(vp); int error = 0; + int fmode = ap->a_fflag; if (vp->v_type == VREG) { /* @@ -520,6 +552,13 @@ nfs_close(struct vop_close_args *ap) error = np->n_error; } } + if (nfs_directio_enable && (fmode & O_DIRECT) && (vp->v_type == VREG)) { + KASSERT((np->n_directio_opens > 0), + ("nfs_close: unexpectedly value (0) of n_directio_opens\n")); + np->n_directio_opens--; + if (np->n_directio_opens == 0) + np->n_flag &= ~NNONCACHE; + } return (error); } |