Whamcloud - gitweb
file jbd-stats-2.6.9.patch was initially added on branch b1_4.
[fs/lustre-release.git] / lustre / llite / rw26.c
index 640cf05..ea8ae29 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/smp_lock.h>
+#include <linux/writeback.h>
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
 #include "llite_internal.h"
 #include <linux/lustre_compat25.h>
 
-/* called for each page in a completed rpc.*/
-void ll_ap_completion_26(void *data, int cmd, int rc)
+static int ll_writepage_26(struct page *page, struct writeback_control *wbc)
 {
-        struct ll_async_page *llap;
-        struct page *page;
-
-        llap = llap_from_cookie(data);
-        if (IS_ERR(llap)) {
-                EXIT;
-                return;
-        }
-
-        page = llap->llap_page;
-        LASSERT(PageLocked(page));
-
-        if (rc == 0)  {
-                if (cmd == OBD_BRW_READ) {
-                        if (!llap->llap_defer_uptodate)
-                                SetPageUptodate(page);
-                } else {
-                        llap->llap_write_queued = 0;
-                }
-        } else {
-                SetPageError(page);
-        }
-
-        LL_CDEBUG_PAGE(D_PAGE, page, "io complete, unlocking\n");
-
-        unlock_page(page);
+        return ll_writepage(page);
+}
 
-        if (0 && cmd == OBD_BRW_WRITE) {
-                llap_write_complete(page->mapping->host, llap);
-                ll_try_done_writing(page->mapping->host);
-        }
+/* It is safe to not check anything in invalidatepage/releasepage below
+   because they are run with page locked and all our io is happening with
+   locked page too */
+static int ll_invalidatepage(struct page *page, unsigned long offset)
+{
+       if (offset)
+               return 0;
+        if (PagePrivate(page))
+                ll_removepage(page);
+        return 1;
+}
 
-        page_cache_release(page);
+static int ll_releasepage(struct page *page, int gfp_mask)
+{
+        if (PagePrivate(page))
+                ll_removepage(page);
+        return 1;
 }
 
-static int ll_writepage_26(struct page *page, struct writeback_control *wbc)
+static int ll_writepages(struct address_space *mapping,
+                         struct writeback_control *wbc)
 {
-        struct inode *inode = page->mapping->host;
-        struct obd_export *exp;
-        struct ll_async_page *llap;
+        struct ll_sb_info *sbi = ll_s2sbi(mapping->host->i_sb);
         int rc;
-        ENTRY;
-
-        LASSERT(!PageDirty(page));
-        LASSERT(PageLocked(page));
-
-        exp = ll_i2obdexp(inode);
-        if (exp == NULL)
-                GOTO(out, rc = -EINVAL);
-
-        llap = llap_from_page(page);
-        if (IS_ERR(llap))
-                GOTO(out, rc = PTR_ERR(llap));
-
-        page_cache_get(page);
-        if (llap->llap_write_queued) {
-                LL_CDEBUG_PAGE(D_PAGE, page, "marking urgent\n");
-                rc = obd_set_async_flags(exp, ll_i2info(inode)->lli_smd, NULL,
-                                         llap->llap_cookie,
-                                         ASYNC_READY | ASYNC_URGENT);
-        } else {
-                llap->llap_write_queued = 1;
-                rc = obd_queue_async_io(exp, ll_i2info(inode)->lli_smd, NULL,
-                                        llap->llap_cookie, OBD_BRW_WRITE, 0, 0,
-                                        0, ASYNC_READY | ASYNC_URGENT);
-                if (rc == 0)
-                        LL_CDEBUG_PAGE(D_PAGE, page, "mmap write queued\n");
-                else
-                        llap->llap_write_queued = 0;
+        struct timeval tstart, now;
+        do_gettimeofday(&tstart);
+        rc =  generic_writepages(mapping, wbc);
+        /* this synchronization (even being implemented via Writeback)
+         * makes recovery much more sad, because iget() can get stuck
+         * on I_LOCK the kernel helds over ->writepages() -bzzz */
+        if (rc == 0 && wbc->sync_mode == WB_SYNC_ALL
+                        && sbi->ll_flags & LL_SBI_UMOUNT) {
+                /* as we don't use Writeback bit to track pages
+                 * under I/O, filemap_fdatawait() doesn't work
+                 * for us. let's wait for I/O completion here */
+                struct ll_inode_info *lli = ll_i2info(mapping->host);
+                wait_event(lli->lli_dirty_wait,
+                           ll_is_inode_dirty(mapping->host) == 0);
+                do_gettimeofday(&now);
+                if (now.tv_sec - tstart.tv_sec > obd_timeout * 6) {
+                        CDEBUG(D_ERROR, "synching inode 0x%p "DLID4" took %ds\n",
+                               mapping->host, OLID4(&lli->lli_id),
+                               (int) (now.tv_sec - tstart.tv_sec));
+                        portals_debug_dumplog();
+                }
         }
-        if (rc)
-                page_cache_release(page);
-out:
-        if (rc)
-                unlock_page(page);
-        RETURN(rc);
+        return rc;
 }
 
 struct address_space_operations ll_aops = {
-        readpage: ll_readpage,
-//        readpages: ll_readpages,
-//        direct_IO: ll_direct_IO_26,
-        writepage: ll_writepage_26,
-        writepages: generic_writepages,
-        set_page_dirty: __set_page_dirty_nobuffers,
-        sync_page: ll_sync_page,
-        prepare_write: ll_prepare_write,
-        commit_write: ll_commit_write,
-        removepage: ll_removepage,
-        bmap: NULL
+        .readpage       = ll_readpage,
+//        .readpages      = ll_readpages,
+//        .direct_IO      = ll_direct_IO_26,
+        .writepage      = ll_writepage_26,
+        .writepages     = ll_writepages,
+        .set_page_dirty = __set_page_dirty_nobuffers,
+        .sync_page      = NULL,
+        .prepare_write  = ll_prepare_write,
+        .commit_write   = ll_commit_write,
+        .invalidatepage = ll_invalidatepage,
+        .releasepage    = ll_releasepage,
+        .bmap           = NULL
 };