1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Lite I/O page cache for the 2.4 kernel version
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #include <linux/config.h>
25 #include <linux/kernel.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>
37 #include <linux/iobuf.h>
38 #include <linux/stat.h>
39 #include <asm/uaccess.h>
40 #include <asm/segment.h>
42 #include <linux/pagemap.h>
43 #include <linux/smp_lock.h>
45 #define DEBUG_SUBSYSTEM S_LLITE
47 #include <linux/lustre_mds.h>
48 #include <linux/lustre_lite.h>
49 #include "llite_internal.h"
50 #include <linux/lustre_compat25.h>
52 static int ll_writepage_24(struct page *page)
54 struct inode *inode = page->mapping->host;
55 struct obd_export *exp;
56 struct ll_async_page *llap;
60 LASSERT(!PageDirty(page));
61 LASSERT(PageLocked(page));
63 exp = ll_i2obdexp(inode);
65 GOTO(out, rc = -EINVAL);
67 llap = llap_from_page(page);
69 GOTO(out, rc = PTR_ERR(llap));
72 if (llap->llap_write_queued) {
73 LL_CDEBUG_PAGE(D_PAGE, page, "marking urgent\n");
74 rc = obd_set_async_flags(exp, ll_i2info(inode)->lli_smd, NULL,
76 ASYNC_READY | ASYNC_URGENT);
78 llap->llap_write_queued = 1;
79 rc = obd_queue_async_io(exp, ll_i2info(inode)->lli_smd, NULL,
80 llap->llap_cookie, OBD_BRW_WRITE, 0, 0,
81 0, ASYNC_READY | ASYNC_URGENT);
83 LL_CDEBUG_PAGE(D_PAGE, page, "mmap write queued\n");
85 llap->llap_write_queued = 0;
88 page_cache_release(page);
95 static int ll_direct_IO_24(int rw,
101 struct kiobuf *iobuf, unsigned long blocknr,
105 struct inode *inode = file->f_dentry->d_inode;
107 struct ll_inode_info *lli = ll_i2info(inode);
108 struct lov_stripe_md *lsm = lli->lli_smd;
109 struct brw_page *pga;
110 struct ptlrpc_request_set *set;
112 int length, i, flags, rc = 0;
116 if (!lsm || !lsm->lsm_object_id)
119 /* FIXME: io smaller than PAGE_SIZE is broken on ia64 */
120 if ((iobuf->offset & (PAGE_SIZE - 1)) ||
121 (iobuf->length & (PAGE_SIZE - 1)))
124 set = ptlrpc_prep_set();
128 OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
130 ptlrpc_set_destroy(set);
134 flags = 0 /* | OBD_BRW_DIRECTIO */;
135 offset = ((obd_off)blocknr << inode->i_blkbits);
136 length = iobuf->length;
138 for (i = 0, length = iobuf->length; length > 0;
139 length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
140 pga[i].pg = iobuf->maplist[i];
142 /* To the end of the page, or the length, whatever is less */
143 pga[i].count = min_t(int, PAGE_SIZE - (offset & ~PAGE_MASK),
147 POISON_PAGE(iobuf->maplist[i], 0x0d);
150 ll_inode_fill_obdo(inode, rw, &oa);
153 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
154 LPROC_LL_DIRECT_WRITE, iobuf->length);
156 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
157 LPROC_LL_DIRECT_READ, iobuf->length);
158 rc = obd_brw_async(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
159 ll_i2obdexp(inode), &oa, lsm, iobuf->nr_pages, pga,
162 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
163 "error from obd_brw_async: rc = %d\n", rc);
165 rc = ptlrpc_set_wait(set);
167 CERROR("error from callback: rc = %d\n", rc);
169 ptlrpc_set_destroy(set);
172 obdo_to_inode(inode, &oa, OBD_MD_FLBLOCKS);
175 OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
179 struct address_space_operations ll_aops = {
180 .readpage = ll_readpage,
181 .direct_IO = ll_direct_IO_24,
182 .writepage = ll_writepage_24,
183 .prepare_write = ll_prepare_write,
184 .commit_write = ll_commit_write,
185 .removepage = ll_removepage,