Make lock_page_async() accept the wait queue
authorJens Axboe <jens.axboe@oracle.com>
Sat, 26 Sep 2009 15:34:25 +0000 (17:34 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 26 Sep 2009 15:34:25 +0000 (17:34 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
include/linux/pagemap.h
mm/filemap.c

index 59fc8999e9f05921db29f10a8a9c86dfdd6b2a12..6b55e4cffffbeb8f66ef15f8c8a5fb6187aa034e 100644 (file)
@@ -325,17 +325,19 @@ static inline void lock_page_nosync(struct page *page)
  * lock_page(). If that happens, this helper may also return fatal signals
  * terminating the wait, even if the page isn't locked yet.
  */
-static inline int lock_page_async(struct page *page)
+static inline int lock_page_async(struct page *page, struct wait_bit_queue *wq)
 {
        might_sleep();
 
        if (!trylock_page(page)) {
-               struct wait_bit_queue *wq;
                DEFINE_WAIT_BIT(wq_stack, &page->flags, PG_locked);
                
-               wq = current->io_wait;
                if (!wq)
                        wq = &wq_stack;
+               else {
+                       wq->key.flags = &page->flags;
+                       wq->key.bit_nr = PG_locked;
+               }
 
                return __lock_page_async(page, wq);
        }
@@ -348,12 +350,8 @@ static inline int lock_page_async(struct page *page)
  */
 static inline void lock_page(struct page *page)
 {
-       might_sleep();
-
-       if (!trylock_page(page)) {
-               int ret = __lock_page_async(page, NULL);
-               WARN_ON(ret);
-       }
+       WARN_ON(current->io_wait);
+       lock_page_async(page, NULL);
 }
 
 /*
index 24124388e8d4c03e4610098234a317e6755eb923..91d24ff033245f7b3e3a314d4ce50cf84af812ee 100644 (file)
@@ -623,14 +623,10 @@ EXPORT_SYMBOL(end_page_writeback);
  */
 int __lock_page_async(struct page *page, struct wait_bit_queue *wq)
 {
-       int (*fn)(void *);
+       int (*fn)(void *) = sync_page;
 
-       if (wq) {
-               wq->key.flags = &page->flags;
-               wq->key.bit_nr = PG_locked;
+       if (!is_sync_wait_bit_queue(wq))
                fn = sync_page_killable;
-       } else
-               fn = sync_page;
 
        return __wait_on_bit_lock(page_waitqueue(page), wq, fn,
                                                        TASK_UNINTERRUPTIBLE);
@@ -1126,7 +1122,7 @@ page_ok:
 
 page_not_up_to_date:
                /* Get exclusive access to the page ... */
-               error = lock_page_async(page);
+               error = lock_page_async(page, current->io_wait);
                if (unlikely(error))
                        goto readpage_error;
 
@@ -1157,7 +1153,7 @@ readpage:
                }
 
                if (!PageUptodate(page)) {
-                       error = lock_page_async(page);
+                       error = lock_page_async(page, current->io_wait);
                        if (unlikely(error))
                                goto readpage_error;
                        if (!PageUptodate(page)) {