From: Venkatesh Srinivas Date: Wed, 23 Feb 2011 15:12:20 +0000 (-0800) Subject: kernel -- Add O_FRNONBLOCKING, to allow reads which do not block on disk accesses. X-Git-Tag: v2.11.0~267^2~23 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/638e2d2dbe6f53c8cedaba64a0c882abf747f667 kernel -- Add O_FRNONBLOCKING, to allow reads which do not block on disk accesses. Using extpread() or extpreadv() with O_FRNONBLOCKING on HAMMER file systems now allows reads to return EWOULDBLOCK when the requested data is not in the buffer cache. --- diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 5acce8e6bb..60f3237f3d 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -643,7 +643,9 @@ vn_read(struct file *fp, struct uio *uio, struct ucred *cred, int flags) vp = (struct vnode *)fp->f_data; ioflag = 0; - if (flags & O_FBLOCKING) { + if (flags & O_FRNONBLOCKING) { + ioflag |= (IO_NDELAY | IO_NRDELAY); + } else if (flags & O_FBLOCKING) { /* ioflag &= ~IO_NDELAY; */ } else if (flags & O_FNONBLOCKING) { ioflag |= IO_NDELAY; diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index 8faca3e0f8..353ab9b643 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -110,6 +110,7 @@ #define O_FUNBUFFERED 0x01000000 /* force unbuffered (direct) I/O */ #define O_FBUFFERED 0x02000000 /* force buffered I/O */ #define O_MAPONREAD 0x04000000 /* memory map read buffer */ +#define O_FRNONBLOCKING 0x08000000 /* nonblocking I/O no disk wait */ #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) #define FREVOKED 0x10000000 /* revoked by fdrevoke() */ @@ -120,7 +121,7 @@ #define O_FMASK (O_FBLOCKING|O_FNONBLOCKING|O_FAPPEND|O_FOFFSET|\ O_FSYNCWRITE|O_FASYNCWRITE|O_FUNBUFFERED|O_FBUFFERED|\ - O_MAPONREAD) + O_MAPONREAD|O_FRNONBLOCKING) #ifdef _KERNEL /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index e9c6cedbdd..5adb977bc8 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -329,6 +329,7 @@ struct vnode { #define IO_DIRECT 0x0100 /* attempt to bypass buffer cache */ #define IO_RECURSE 0x0200 /* possibly device-recursive (vn) */ #define IO_CORE 0x0400 /* I/O is part of core dump */ +#define IO_NRDELAY 0x8000 /* do not block on disk reads */ #define IO_SEQMAX 0x7F /* seq heuristic max value */ #define IO_SEQSHIFT 16 /* seq heuristic in upper 16 bits */ diff --git a/sys/vfs/hammer/hammer_vnops.c b/sys/vfs/hammer/hammer_vnops.c index fa1d68bdf9..ba7f37ae3b 100644 --- a/sys/vfs/hammer/hammer_vnops.c +++ b/sys/vfs/hammer/hammer_vnops.c @@ -374,6 +374,9 @@ hammer_vop_read(struct vop_read_args *ap) if (bp) { error = 0; goto skip; + } else { + if (ap->a_ioflag & (IO_NDELAY | IO_NRDELAY)) + return (EWOULDBLOCK); } /*