Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[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 static int ll_writepage_24(struct page *page)
53 {
54         struct inode *inode = page->mapping->host;
55         struct obd_export *exp;
56         struct ll_async_page *llap;
57         int rc = 0;
58         ENTRY;
59
60         LASSERT(!PageDirty(page));
61         LASSERT(PageLocked(page));
62
63         exp = ll_i2obdexp(inode);
64         if (exp == NULL)
65                 GOTO(out, rc = -EINVAL);
66
67         llap = llap_from_page(page);
68         if (IS_ERR(llap))
69                 GOTO(out, rc = PTR_ERR(llap));
70
71         page_cache_get(page);
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,
75                                          llap->llap_cookie,
76                                          ASYNC_READY | ASYNC_URGENT);
77         } else {
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);
82                 if (rc == 0)
83                         LL_CDEBUG_PAGE(D_PAGE, page, "mmap write queued\n");
84                 else
85                         llap->llap_write_queued = 0;
86         }
87         if (rc)
88                 page_cache_release(page);
89 out:
90         if (rc)
91                 unlock_page(page);
92         RETURN(rc);
93 }
94
95 static int ll_direct_IO_24(int rw,
96 #ifdef HAVE_DIO_FILE
97                            struct file *file,
98 #else
99                            struct inode *inode,
100 #endif
101                            struct kiobuf *iobuf, unsigned long blocknr,
102                            int blocksize)
103 {
104 #ifdef HAVE_DIO_FILE
105         struct inode *inode = file->f_dentry->d_inode;
106 #endif
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;
111         struct obdo oa;
112         int length, i, flags, rc = 0;
113         loff_t offset;
114         ENTRY;
115
116         if (!lsm || !lsm->lsm_object_id)
117                 RETURN(-EBADF);
118
119         set = ptlrpc_prep_set();
120         if (set == NULL)
121                 RETURN(-ENOMEM);
122
123         OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
124         if (!pga) {
125                 ptlrpc_set_destroy(set);
126                 RETURN(-ENOMEM);
127         }
128
129         flags = 0 /* | OBD_BRW_DIRECTIO */;
130         offset = ((obd_off)blocknr * blocksize);
131         length = iobuf->length;
132         LASSERT(iobuf->offset < PAGE_SIZE);
133
134         for (i = 0, length = iobuf->length; length > 0;
135              length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
136                 pga[i].pg = iobuf->maplist[i];
137                 pga[i].off = offset;
138                 /* To the end of the page, or the length, whatever is less */
139                 pga[i].count = min_t(int, PAGE_SIZE - (offset & ~PAGE_MASK),
140                                      length);
141                 pga[i].flag = flags;
142                 if (rw == READ)
143                         POISON_PAGE(iobuf->maplist[i], 0x0d);
144         }
145
146         ll_inode_fill_obdo(inode, rw, &oa);
147
148         if (rw == WRITE)
149                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
150                                     LPROC_LL_DIRECT_WRITE, iobuf->length);
151         else
152                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
153                                     LPROC_LL_DIRECT_READ, iobuf->length);
154         rc = obd_brw_async(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
155                            ll_i2obdexp(inode), &oa, lsm, iobuf->nr_pages, pga,
156                            set, NULL);
157         if (rc) {
158                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
159                        "error from obd_brw_async: rc = %d\n", rc);
160         } else {
161                 rc = ptlrpc_set_wait(set);
162                 if (rc)
163                         CERROR("error from callback: rc = %d\n", rc);
164         }
165         ptlrpc_set_destroy(set);
166         if (rc == 0 && rw == WRITE) {
167                 void lov_increase_kms(struct obd_export *,
168                                       struct lov_stripe_md *, obd_off size);
169                 obd_off size = offset + length;
170                 lov_increase_kms(ll_i2obdexp(inode), lsm, size);
171                 if (size > inode->i_size)
172                         inode->i_size = size;
173         }
174         if (rc == 0) {
175                 rc = iobuf->length;
176                 obdo_to_inode(inode, &oa, OBD_MD_FLBLOCKS);
177         }
178
179         OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
180         RETURN(rc);
181 }
182
183 struct address_space_operations ll_aops = {
184         .readpage       = ll_readpage,
185         .direct_IO      = ll_direct_IO_24,
186         .writepage      = ll_writepage_24,
187         .prepare_write  = ll_prepare_write,
188         .commit_write   = ll_commit_write,
189         .removepage     = ll_removepage,
190         .sync_page      = NULL,
191         .bmap           = NULL
192 };