Whamcloud - gitweb
- ll_writepages() waits for I/O completion if filesystem is being umounted
[fs/lustre-release.git] / lustre / llite / rw26.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Lite I/O page cache routines for the 2.5/2.6 kernel version
5  *
6  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #include <linux/config.h>
25 #include <linux/kernel.h>
26 #include <linux/mm.h>
27 #include <linux/string.h>
28 #include <linux/stat.h>
29 #include <linux/errno.h>
30 #include <linux/smp_lock.h>
31 #include <linux/unistd.h>
32 #include <linux/version.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
35
36 #include <linux/fs.h>
37 #include <linux/buffer_head.h>
38 #include <linux/mpage.h>
39 #include <linux/writeback.h>
40 #include <linux/stat.h>
41 #include <asm/uaccess.h>
42 #include <asm/segment.h>
43 #include <linux/mm.h>
44 #include <linux/pagemap.h>
45 #include <linux/smp_lock.h>
46 #include <linux/writeback.h>
47
48 #define DEBUG_SUBSYSTEM S_LLITE
49
50 #include <linux/lustre_mds.h>
51 #include <linux/lustre_lite.h>
52 #include "llite_internal.h"
53 #include <linux/lustre_compat25.h>
54
55 static int ll_writepage_26(struct page *page, struct writeback_control *wbc)
56 {
57         return ll_writepage(page);
58 }
59
60 /* It is safe to not check anything in invalidatepage/releasepage below
61    because they are run with page locked and all our io is happening with
62    locked page too */
63 static int ll_invalidatepage(struct page *page, unsigned long offset)
64 {
65         if (offset)
66                 return 0;
67         if (PagePrivate(page))
68                 ll_removepage(page);
69         return 1;
70 }
71
72 static int ll_releasepage(struct page *page, int gfp_mask)
73 {
74         if (PagePrivate(page))
75                 ll_removepage(page);
76         return 1;
77 }
78
79 static int ll_writepages(struct address_space *mapping,
80                          struct writeback_control *wbc)
81 {
82         struct ll_sb_info *sbi = ll_s2sbi(mapping->host->i_sb);
83         int rc;
84         struct timeval tstart, now;
85         do_gettimeofday(&tstart);
86         rc =  generic_writepages(mapping, wbc);
87         /* this syncronization (even being implemented via Writeback)
88          * makes recovery much more sad, because iget() can get stuck
89          * on I_LOCK the kernel helds over ->writepages() -bzzz */
90         if (rc == 0 && wbc->sync_mode == WB_SYNC_ALL
91                         && sbi->ll_flags & LL_SBI_UMOUNT) {
92                 /* as we don't use Writeback bit to track pages
93                  * under I/O, filemap_fdatawait() doesn't work
94                  * for us. let's wait for I/O completion here */
95                 struct ll_inode_info *lli = ll_i2info(mapping->host);
96                 wait_event(lli->lli_dirty_wait,
97                            ll_is_inode_dirty(mapping->host) == 0);
98                 do_gettimeofday(&now);
99                 if (now.tv_sec - tstart.tv_sec > obd_timeout * 6) {
100                         CDEBUG(D_ERROR, "synching inode 0x%p "DLID4" took %ds\n",
101                                mapping->host, OLID4(&lli->lli_id),
102                                (int) (now.tv_sec - tstart.tv_sec));
103                         portals_debug_dumplog();
104                 }
105         }
106         return rc;
107 }
108
109 struct address_space_operations ll_aops = {
110         .readpage       = ll_readpage,
111 //        .readpages      = ll_readpages,
112 //        .direct_IO      = ll_direct_IO_26,
113         .writepage      = ll_writepage_26,
114         .writepages     = ll_writepages,
115         .set_page_dirty = __set_page_dirty_nobuffers,
116         .sync_page      = NULL,
117         .prepare_write  = ll_prepare_write,
118         .commit_write   = ll_commit_write,
119         .invalidatepage = ll_invalidatepage,
120         .releasepage    = ll_releasepage,
121         .bmap           = NULL
122 };