]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
dio: add dio_post_submission() helper function
authorDave Kleikamp <dave.kleikamp@oracle.com>
Wed, 11 Jan 2012 22:45:15 +0000 (16:45 -0600)
committerDave Kleikamp <dave.kleikamp@oracle.com>
Fri, 13 Jan 2012 00:15:35 +0000 (18:15 -0600)
This creates a function that contains all the code that is executed
after IO is submitted.  It takes code from the end of
do_blockdev_direct_IO().  This will be called by another entry point
that will be added in an upcoming patch.

Signed-off-by: Zach Brown <zach.brown@oracle.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
fs/direct-io.c

index ba4063e88fe962be4aade3263df4229822897908..409a98f4a641b8273e48308529bb99e10eb50a0a 100644 (file)
@@ -1147,6 +1147,73 @@ static int dio_lock_and_flush(struct dio *dio, loff_t offset, loff_t end)
        return 0;
 }
 
+static ssize_t dio_post_submission(int rw, loff_t offset, struct dio *dio,
+                                  struct dio_submit *sdio,
+                                  struct buffer_head *map_bh, ssize_t ret)
+{
+       if (ret == -ENOTBLK) {
+               /*
+                * The remaining part of the request will be
+                * be handled by buffered I/O when we return
+                */
+               ret = 0;
+       }
+       /*
+        * There may be some unwritten disk at the end of a part-written
+        * fs-block-sized block.  Go zero that now.
+        */
+       dio_zero_block(dio, sdio, 1, map_bh);
+
+       if (sdio->cur_page) {
+               ssize_t ret2;
+
+               ret2 = dio_send_cur_page(dio, sdio, map_bh);
+               if (ret == 0)
+                       ret = ret2;
+               page_cache_release(sdio->cur_page);
+               sdio->cur_page = NULL;
+       }
+       if (sdio->bio)
+               dio_bio_submit(dio, sdio);
+
+       /*
+        * It is possible that, we return short IO due to end of file.
+        * In that case, we need to release all the pages we got hold on.
+        */
+       dio_cleanup(dio, sdio);
+
+       /*
+        * All block lookups have been performed. For READ requests
+        * we can let i_mutex go now that its achieved its purpose
+        * of protecting us from looking up uninitialized blocks.
+        */
+       if (rw == READ && (dio->flags & DIO_LOCKING))
+               mutex_unlock(&dio->inode->i_mutex);
+
+       /*
+        * The only time we want to leave bios in flight is when a successful
+        * partial aio read or full aio write have been setup.  In that case
+        * bio completion will call aio_complete.  The only time it's safe to
+        * call aio_complete is when we return -EIOCBQUEUED, so we key on that.
+        * This had *better* be the only place that raises -EIOCBQUEUED.
+        */
+       BUG_ON(ret == -EIOCBQUEUED);
+       if (dio->is_async && ret == 0 && dio->result &&
+           ((rw & READ) || (dio->result == sdio->size)))
+               ret = -EIOCBQUEUED;
+
+       if (ret != -EIOCBQUEUED)
+               dio_await_completion(dio);
+
+       if (drop_refcount(dio) == 0) {
+               ret = dio_complete(dio, offset, ret, false);
+               kmem_cache_free(dio_cache, dio);
+       } else
+               BUG_ON(ret != -EIOCBQUEUED);
+
+       return ret;
+}
+
 /*
  * This is a library function for use by filesystem drivers.
  *
@@ -1257,65 +1324,7 @@ do_blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
                }
        } /* end iovec loop */
 
-       if (retval == -ENOTBLK) {
-               /*
-                * The remaining part of the request will be
-                * be handled by buffered I/O when we return
-                */
-               retval = 0;
-       }
-       /*
-        * There may be some unwritten disk at the end of a part-written
-        * fs-block-sized block.  Go zero that now.
-        */
-       dio_zero_block(dio, &sdio, 1, &map_bh);
-
-       if (sdio.cur_page) {
-               ssize_t ret2;
-
-               ret2 = dio_send_cur_page(dio, &sdio, &map_bh);
-               if (retval == 0)
-                       retval = ret2;
-               page_cache_release(sdio.cur_page);
-               sdio.cur_page = NULL;
-       }
-       if (sdio.bio)
-               dio_bio_submit(dio, &sdio);
-
-       /*
-        * It is possible that, we return short IO due to end of file.
-        * In that case, we need to release all the pages we got hold on.
-        */
-       dio_cleanup(dio, &sdio);
-
-       /*
-        * All block lookups have been performed. For READ requests
-        * we can let i_mutex go now that its achieved its purpose
-        * of protecting us from looking up uninitialized blocks.
-        */
-       if (rw == READ && (dio->flags & DIO_LOCKING))
-               mutex_unlock(&dio->inode->i_mutex);
-
-       /*
-        * The only time we want to leave bios in flight is when a successful
-        * partial aio read or full aio write have been setup.  In that case
-        * bio completion will call aio_complete.  The only time it's safe to
-        * call aio_complete is when we return -EIOCBQUEUED, so we key on that.
-        * This had *better* be the only place that raises -EIOCBQUEUED.
-        */
-       BUG_ON(retval == -EIOCBQUEUED);
-       if (dio->is_async && retval == 0 && dio->result &&
-           ((rw & READ) || (dio->result == sdio.size)))
-               retval = -EIOCBQUEUED;
-
-       if (retval != -EIOCBQUEUED)
-               dio_await_completion(dio);
-
-       if (drop_refcount(dio) == 0) {
-               retval = dio_complete(dio, offset, retval, false);
-               kmem_cache_free(dio_cache, dio);
-       } else
-               BUG_ON(retval != -EIOCBQUEUED);
+       retval = dio_post_submission(rw, offset, dio, &sdio, &map_bh, retval);
 
 out:
        return retval;