Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / llite / rw24.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 for the 2.4 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/iobuf.h>
38 #include <linux/stat.h>
39 #include <asm/uaccess.h>
40 #include <asm/segment.h>
41 #include <linux/mm.h>
42 #include <linux/pagemap.h>
43 #include <linux/smp_lock.h>
44
45 #define DEBUG_SUBSYSTEM S_LLITE
46
47 #include <linux/lustre_mds.h>
48 #include <linux/lustre_lite.h>
49 #include "llite_internal.h"
50 #include <linux/lustre_compat25.h>
51
52 /* called for each page in a completed rpc.*/
53 void ll_ap_completion_24(void *data, int cmd, int rc)
54 {
55         struct ll_async_page *llap;
56         struct page *page;
57         ENTRY;
58
59         llap = llap_from_cookie(data);
60         if (IS_ERR(llap)) {
61                 EXIT;
62                 return;
63         }
64
65         page = llap->llap_page;
66         LASSERT(PageLocked(page));
67
68         LL_CDEBUG_PAGE(D_PAGE, page, "completing cmd %d with %d\n", cmd, rc);
69
70         if (rc == 0)  {
71                 if (cmd == OBD_BRW_READ) {
72                         if (!llap->llap_defer_uptodate)
73                                 SetPageUptodate(page);
74                 } else {
75                         llap->llap_write_queued = 0;
76                 }
77                 ClearPageError(page);
78         } else {
79                 if (cmd == OBD_BRW_READ)
80                         llap->llap_defer_uptodate = 0;
81                 SetPageError(page);
82         }
83
84
85         unlock_page(page);
86
87         if (0 && cmd == OBD_BRW_WRITE) {
88                 llap_write_complete(page->mapping->host, llap);
89                 ll_try_done_writing(page->mapping->host);
90         }
91
92         page_cache_release(page);
93         EXIT;
94 }
95
96 static int ll_writepage_24(struct page *page)
97 {
98         struct inode *inode = page->mapping->host;
99         struct obd_export *exp;
100         struct ll_async_page *llap;
101         int rc = 0;
102         ENTRY;
103
104         LASSERT(!PageDirty(page));
105         LASSERT(PageLocked(page));
106
107         exp = ll_i2obdexp(inode);
108         if (exp == NULL)
109                 GOTO(out, rc = -EINVAL);
110
111         llap = llap_from_page(page);
112         if (IS_ERR(llap))
113                 GOTO(out, rc = PTR_ERR(llap));
114
115         page_cache_get(page);
116         if (llap->llap_write_queued) {
117                 LL_CDEBUG_PAGE(D_PAGE, page, "marking urgent\n");
118                 rc = obd_set_async_flags(exp, ll_i2info(inode)->lli_smd, NULL,
119                                          llap->llap_cookie,
120                                          ASYNC_READY | ASYNC_URGENT);
121         } else {
122                 llap->llap_write_queued = 1;
123                 rc = obd_queue_async_io(exp, ll_i2info(inode)->lli_smd, NULL,
124                                         llap->llap_cookie, OBD_BRW_WRITE, 0, 0,
125                                         0, ASYNC_READY | ASYNC_URGENT);
126                 if (rc == 0)
127                         LL_CDEBUG_PAGE(D_PAGE, page, "mmap write queued\n");
128                 else
129                         llap->llap_write_queued = 0;
130         }
131         if (rc)
132                 page_cache_release(page);
133 out:
134         if (rc)
135                 unlock_page(page);
136         RETURN(rc);
137 }
138
139 static int ll_direct_IO_24(int rw,
140 #ifdef HAVE_DIO_FILE
141                            struct file *file,
142 #else
143                            struct inode *inode,
144 #endif
145                            struct kiobuf *iobuf, unsigned long blocknr,
146                            int blocksize)
147 {
148 #ifdef HAVE_DIO_FILE
149         struct inode *inode = file->f_dentry->d_inode;
150 #endif
151         struct ll_inode_info *lli = ll_i2info(inode);
152         struct lov_stripe_md *lsm = lli->lli_smd;
153         struct brw_page *pga;
154         struct ptlrpc_request_set *set;
155         struct obdo oa;
156         int length, i, flags, rc = 0;
157         loff_t offset;
158         ENTRY;
159
160         if (!lsm || !lsm->lsm_object_id)
161                 RETURN(-EBADF);
162
163         /* FIXME: io smaller than PAGE_SIZE is broken on ia64 */
164         if ((iobuf->offset & (PAGE_SIZE - 1)) ||
165             (iobuf->length & (PAGE_SIZE - 1)))
166                 RETURN(-EINVAL);
167
168         set = ptlrpc_prep_set();
169         if (set == NULL)
170                 RETURN(-ENOMEM);
171
172         OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
173         if (!pga) {
174                 ptlrpc_set_destroy(set);
175                 RETURN(-ENOMEM);
176         }
177
178         flags = 0 /* | OBD_BRW_DIRECTIO */;
179         offset = ((obd_off)blocknr << inode->i_blkbits);
180         length = iobuf->length;
181
182         for (i = 0, length = iobuf->length; length > 0;
183              length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
184                 pga[i].pg = iobuf->maplist[i];
185                 pga[i].off = offset;
186                 /* To the end of the page, or the length, whatever is less */
187                 pga[i].count = min_t(int, PAGE_SIZE - (offset & ~PAGE_MASK),
188                                      length);
189                 pga[i].flag = flags;
190                 if (rw == READ)
191                         POISON_PAGE(iobuf->maplist[i], 0x0d);
192         }
193
194         ll_inode_fill_obdo(inode, rw, &oa);
195
196         if (rw == WRITE)
197                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
198                                     LPROC_LL_DIRECT_WRITE, iobuf->length);
199         else
200                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
201                                     LPROC_LL_DIRECT_READ, iobuf->length);
202         rc = obd_brw_async(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
203                            ll_i2obdexp(inode), &oa, lsm, iobuf->nr_pages, pga,
204                            set, NULL);
205         if (rc) {
206                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
207                        "error from obd_brw_async: rc = %d\n", rc);
208         } else {
209                 rc = ptlrpc_set_wait(set);
210                 if (rc)
211                         CERROR("error from callback: rc = %d\n", rc);
212         }
213         ptlrpc_set_destroy(set);
214         if (rc == 0) {
215                 rc = iobuf->length;
216                 obdo_to_inode(inode, &oa, OBD_MD_FLBLOCKS);
217         }
218
219         OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
220         RETURN(rc);
221 }
222
223 struct address_space_operations ll_aops = {
224         readpage: ll_readpage,
225         direct_IO: ll_direct_IO_24,
226         writepage: ll_writepage_24,
227         prepare_write: ll_prepare_write,
228         commit_write: ll_commit_write,
229         removepage: ll_removepage,
230         sync_page: NULL,
231         bmap: NULL
232 };