Whamcloud - gitweb
land b_v26 (20040316_1603)
[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
47 #define DEBUG_SUBSYSTEM S_LLITE
48
49 #include <linux/lustre_mds.h>
50 #include <linux/lustre_lite.h>
51 #include "llite_internal.h"
52 #include <linux/lustre_compat25.h>
53
54 /* called for each page in a completed rpc.*/
55 void ll_ap_completion_26(void *data, int cmd, int rc)
56 {
57         struct ll_async_page *llap;
58         struct page *page;
59
60         llap = llap_from_cookie(data);
61         if (IS_ERR(llap)) {
62                 EXIT;
63                 return;
64         }
65
66         page = llap->llap_page;
67         LASSERT(PageLocked(page));
68
69         if (rc == 0)  {
70                 if (cmd == OBD_BRW_READ) {
71                         if (!llap->llap_defer_uptodate)
72                                 SetPageUptodate(page);
73                 } else {
74                         llap->llap_write_queued = 0;
75                 }
76         } else {
77                 SetPageError(page);
78         }
79
80         LL_CDEBUG_PAGE(D_PAGE, page, "io complete, unlocking\n");
81
82         unlock_page(page);
83
84         if (0 && cmd == OBD_BRW_WRITE) {
85                 llap_write_complete(page->mapping->host, llap);
86                 ll_try_done_writing(page->mapping->host);
87         }
88
89         page_cache_release(page);
90 }
91
92 static int ll_writepage_26(struct page *page, struct writeback_control *wbc)
93 {
94         struct inode *inode = page->mapping->host;
95         struct obd_export *exp;
96         struct ll_async_page *llap;
97         int rc;
98         ENTRY;
99
100         LASSERT(!PageDirty(page));
101         LASSERT(PageLocked(page));
102
103         exp = ll_i2obdexp(inode);
104         if (exp == NULL)
105                 GOTO(out, rc = -EINVAL);
106
107         llap = llap_from_page(page);
108         if (IS_ERR(llap))
109                 GOTO(out, rc = PTR_ERR(llap));
110
111         page_cache_get(page);
112         if (llap->llap_write_queued) {
113                 LL_CDEBUG_PAGE(D_PAGE, page, "marking urgent\n");
114                 rc = obd_set_async_flags(exp, ll_i2info(inode)->lli_smd, NULL,
115                                          llap->llap_cookie,
116                                          ASYNC_READY | ASYNC_URGENT);
117         } else {
118                 llap->llap_write_queued = 1;
119                 rc = obd_queue_async_io(exp, ll_i2info(inode)->lli_smd, NULL,
120                                         llap->llap_cookie, OBD_BRW_WRITE, 0, 0,
121                                         0, ASYNC_READY | ASYNC_URGENT);
122                 if (rc == 0)
123                         LL_CDEBUG_PAGE(D_PAGE, page, "mmap write queued\n");
124                 else
125                         llap->llap_write_queued = 0;
126         }
127         if (rc)
128                 page_cache_release(page);
129 out:
130         if (rc)
131                 unlock_page(page);
132         RETURN(rc);
133 }
134
135 struct address_space_operations ll_aops = {
136         readpage: ll_readpage,
137 //        readpages: ll_readpages,
138 //        direct_IO: ll_direct_IO_26,
139         writepage: ll_writepage_26,
140         writepages: generic_writepages,
141         set_page_dirty: __set_page_dirty_nobuffers,
142         sync_page: NULL,
143         prepare_write: ll_prepare_write,
144         commit_write: ll_commit_write,
145         removepage: ll_removepage,
146         bmap: NULL
147 };