tmpfs - fix failing writes with no swap
authorAlex Hornung <ahornung@gmail.com>
Sat, 10 Jul 2010 21:10:27 +0000 (22:10 +0100)
committerAlex Hornung <ahornung@gmail.com>
Sat, 10 Jul 2010 22:09:48 +0000 (23:09 +0100)
* When no swap is available, tmpfs was trying to use bawrite, causing
  some further problems down the line. We avoid this by now forcing the
  use of buwrite() for this case (no swap).

Suggested-by: Matt Dillon
sys/vfs/tmpfs/tmpfs_vnops.c

index ce250d8..a582618 100644 (file)
@@ -56,6 +56,7 @@
 #include <vm/vm_object.h>
 #include <vm/vm_page.h>
 #include <vm/vm_pager.h>
+#include <vm/swap_pager.h>
 
 #include <vfs/fifofs/fifo.h>
 #include <vfs/tmpfs/tmpfs_vnops.h>
@@ -598,13 +599,22 @@ tmpfs_write (struct vop_write_args *ap)
                 * XXX unfortunately this catches msync() system calls too
                 * for the moment.
                 */
-               if (ap->a_ioflag & IO_SYNC) {
-                       bwrite(bp);
-               } else if ((ap->a_ioflag & IO_ASYNC) ||
-                        (uio->uio_segflg == UIO_NOCOPY)) {
-                       bawrite(bp);
-               } else {
+               if (vm_swap_size == 0) {
+                       /*
+                        * if swap isn't configured yet, force a buwrite() to
+                        * avoid problems further down the line, due to flushing
+                        * to swap.
+                        */
                        buwrite(bp);
+               } else {
+                       if (ap->a_ioflag & IO_SYNC) {
+                               bwrite(bp);
+                       } else if ((ap->a_ioflag & IO_ASYNC) ||
+                                (uio->uio_segflg == UIO_NOCOPY)) {
+                               bawrite(bp);
+                       } else {
+                               buwrite(bp);
+                       }
                }
 
                if (bp->b_error) {