kernel -- Add O_FRNONBLOCKING, to allow reads which do not block on disk accesses.
authorVenkatesh Srinivas <me@endeavour.zapto.org>
Wed, 23 Feb 2011 15:12:20 +0000 (07:12 -0800)
committerVenkatesh Srinivas <me@endeavour.zapto.org>
Wed, 23 Feb 2011 15:12:20 +0000 (07:12 -0800)
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.

sys/kern/vfs_vnops.c
sys/sys/fcntl.h
sys/sys/vnode.h
sys/vfs/hammer/hammer_vnops.c

index 5acce8e..60f3237 100644 (file)
@@ -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;
index 8faca3e..353ab9b 100644 (file)
 #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() */
 
 #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 */
index e9c6ced..5adb977 100644 (file)
@@ -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 */
index fa1d68b..ba7f37a 100644 (file)
@@ -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);
                }
 
                /*