Whamcloud - gitweb
e11eae1c575afc5b531059a1a98618a617662f36
[fs/lustre-release.git] / lustre / llite / rw.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 shared by different kernel revs
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/stat.h>
38 #include <asm/uaccess.h>
39 #include <asm/segment.h>
40 #include <linux/mm.h>
41 #include <linux/pagemap.h>
42 #include <linux/smp_lock.h>
43
44 #define DEBUG_SUBSYSTEM S_LLITE
45
46 #include <linux/lustre_mds.h>
47 #include <linux/lustre_lite.h>
48 #include "llite_internal.h"
49 #include <linux/lustre_compat25.h>
50
51 #ifndef list_for_each_prev_safe
52 #define list_for_each_prev_safe(pos, n, head) \
53         for (pos = (head)->prev, n = pos->prev; pos != (head); \
54                 pos = n, n = pos->prev )
55 #endif
56
57 /* SYNCHRONOUS I/O to object storage for an inode */
58 static int ll_brw(int cmd, struct inode *inode, struct obdo *oa, 
59                   struct page *page, int flags)
60 {
61         struct ll_inode_info *lli = ll_i2info(inode);
62         struct lov_stripe_md *lsm = lli->lli_smd;
63         struct brw_page pg;
64         int rc;
65         ENTRY;
66
67         pg.pg = page;
68         pg.off = ((obd_off)page->index) << PAGE_SHIFT;
69
70         if (cmd == OBD_BRW_WRITE && (pg.off + PAGE_SIZE > inode->i_size))
71                 pg.count = inode->i_size % PAGE_SIZE;
72         else
73                 pg.count = PAGE_SIZE;
74
75         CDEBUG(D_PAGE, "%s %d bytes ino %lu at "LPU64"/"LPX64"\n",
76                cmd & OBD_BRW_WRITE ? "write" : "read", pg.count, inode->i_ino,
77                pg.off, pg.off);
78         if (pg.count == 0) {
79                 CERROR("ZERO COUNT: ino %lu: size %p:%Lu(%p:%Lu) idx %lu off "
80                        LPU64"\n",
81                        inode->i_ino, inode, inode->i_size, page->mapping->host,
82                        page->mapping->host->i_size, page->index, pg.off);
83         }
84
85         pg.flag = flags;
86
87         if (cmd == OBD_BRW_WRITE)
88                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
89                                     LPROC_LL_BRW_WRITE, pg.count);
90         else
91                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
92                                     LPROC_LL_BRW_READ, pg.count);
93         rc = obd_brw(cmd, ll_i2obdexp(inode), oa, lsm, 1, &pg, NULL);
94         if (rc == 0)
95                 obdo_to_inode(inode, oa, OBD_MD_FLBLOCKS);
96         else if (rc != -EIO)
97                 CERROR("error from obd_brw: rc = %d\n", rc);
98         RETURN(rc);
99 }
100
101 /* this isn't where truncate starts.   roughly:
102  * sys_truncate->ll_setattr_raw->vmtruncate->ll_truncate
103  * we grab the lock back in setattr_raw to avoid races. */
104 void ll_truncate(struct inode *inode)
105 {
106         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
107         struct obdo oa;
108         int rc;
109         ENTRY;
110         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
111                inode->i_generation, inode);
112
113         /* object not yet allocated - this is handled in ll_setattr_raw */
114         if (!lsm) {
115                 CERROR("truncate on inode %lu with no objects\n", inode->i_ino);
116                 EXIT;
117                 return;
118         }
119
120         oa.o_id = lsm->lsm_object_id;
121         oa.o_valid = OBD_MD_FLID;
122         obdo_from_inode(&oa, inode, OBD_MD_FLTYPE|OBD_MD_FLMODE|OBD_MD_FLATIME|
123                                     OBD_MD_FLMTIME | OBD_MD_FLCTIME);
124
125         CDEBUG(D_INFO, "calling punch for "LPX64" (all bytes after %Lu)\n",
126                oa.o_id, inode->i_size);
127
128         /* truncate == punch from new size to absolute end of file */
129         rc = obd_punch(ll_i2obdexp(inode), &oa, lsm, inode->i_size,
130                        OBD_OBJECT_EOF, NULL);
131         if (rc)
132                 CERROR("obd_truncate fails (%d) ino %lu\n", rc, inode->i_ino);
133         else
134                 obdo_to_inode(inode, &oa, OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
135                                           OBD_MD_FLATIME | OBD_MD_FLMTIME |
136                                           OBD_MD_FLCTIME);
137
138         EXIT;
139         return;
140 } /* ll_truncate */
141
142 int ll_prepare_write(struct file *file, struct page *page, unsigned from,
143                      unsigned to)
144 {
145         struct inode *inode = page->mapping->host;
146         struct ll_inode_info *lli = ll_i2info(inode);
147         struct lov_stripe_md *lsm = lli->lli_smd;
148         obd_off offset = ((obd_off)page->index) << PAGE_SHIFT;
149         struct brw_page pg;
150         struct obdo oa;
151         int rc = 0;
152         ENTRY;
153
154         if (!PageLocked(page))
155                 LBUG();
156
157         if (PageUptodate(page))
158                 RETURN(0);
159
160         /* Check to see if we should return -EIO right away */
161         pg.pg = page;
162         pg.off = offset;
163         pg.count = PAGE_SIZE;
164         pg.flag = 0;
165         rc = obd_brw(OBD_BRW_CHECK, ll_i2obdexp(inode), NULL, lsm, 1, &pg, 
166                      NULL);
167         if (rc)
168                 RETURN(rc);
169
170         /* We're completely overwriting an existing page, so _don't_ set it up
171          * to date until commit_write */
172         if (from == 0 && to == PAGE_SIZE) {
173                 POISON_PAGE(page, 0x11);
174                 RETURN(0);
175         }
176
177         /* If are writing to a new page, no need to read old data.
178          * the extent locking and getattr procedures in ll_file_write have
179          * guaranteed that i_size is stable enough for our zeroing needs */
180         if (inode->i_size <= offset) {
181                 memset(kmap(page), 0, PAGE_SIZE);
182                 kunmap(page);
183                 GOTO(prepare_done, rc = 0);
184         }
185
186         oa.o_id = lsm->lsm_object_id;
187         oa.o_mode = inode->i_mode;
188         oa.o_valid = OBD_MD_FLID | OBD_MD_FLMODE | OBD_MD_FLTYPE;
189         
190         /* XXX could be an async ocp read.. read-ahead? */
191         rc = ll_brw(OBD_BRW_READ, inode, &oa, page, 0);
192         if (rc == 0) {
193                 /* bug 1598: don't clobber blksize */
194                 oa.o_valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLKSZ);
195                 obdo_refresh_inode(inode, &oa, oa.o_valid);
196         }
197
198         EXIT;
199  prepare_done:
200         if (rc == 0)
201                 SetPageUptodate(page);
202
203         return rc;
204 }
205
206 int ll_write_count(struct page *page)
207 {
208         struct inode *inode = page->mapping->host;
209
210         /* catch race with truncate */
211         if (((loff_t)page->index << PAGE_SHIFT) >= inode->i_size)
212                 return 0;
213
214         /* catch sub-page write at end of file */
215         if (((loff_t)page->index << PAGE_SHIFT) + PAGE_SIZE > inode->i_size)
216                 return inode->i_size % PAGE_SIZE;
217
218         return PAGE_SIZE;
219 }
220
221 struct ll_async_page *llap_from_cookie(void *cookie)
222 {
223         struct ll_async_page *llap = cookie;
224         if (llap->llap_magic != LLAP_MAGIC)
225                 return ERR_PTR(-EINVAL);
226         return llap;
227 };
228
229 static int ll_ap_make_ready(void *data, int cmd)
230 {
231         struct ll_async_page *llap;
232         struct page *page;
233         ENTRY;
234         
235         /* reads are always locked between queueing and completion, 
236          * llite should never queue pages without _READY */
237         LASSERT(cmd != OBD_BRW_READ);
238
239         llap = llap_from_cookie(data);
240         if (IS_ERR(llap)) 
241                 RETURN(-EINVAL);
242
243         page = llap->llap_page;
244
245         if (TryLockPage(page))
246                 RETURN(-EBUSY);
247
248         LL_CDEBUG_PAGE(page, "made ready\n");
249         page_cache_get(page);
250
251         /* if we left PageDirty we might get another writepage call
252          * in the future.  list walkers are bright enough
253          * to check page dirty so we can leave it on whatever list
254          * its on.  XXX also, we're called with the cli list so if
255          * we got the page cache list we'd create a lock inversion
256          * with the removepage path which gets the page lock then the
257          * cli lock */
258         clear_page_dirty(page);
259         RETURN(0);
260 }
261
262 static int ll_ap_refresh_count(void *data, int cmd)
263 {
264         struct ll_async_page *llap;
265         ENTRY;
266
267         /* readpage queues with _COUNT_STABLE, shouldn't get here. */
268         LASSERT(cmd != OBD_BRW_READ);
269
270         llap = llap_from_cookie(data);
271         if (IS_ERR(llap))
272                 RETURN(PTR_ERR(llap));
273
274         return ll_write_count(llap->llap_page);
275 }
276
277 void ll_inode_fill_obdo(struct inode *inode, int cmd, struct obdo *oa)
278 {
279         struct lov_stripe_md *lsm;
280         obd_flag valid_flags;
281
282         lsm = ll_i2info(inode)->lli_smd;
283
284         oa->o_id = lsm->lsm_object_id;
285         oa->o_valid = OBD_MD_FLID;
286         valid_flags = OBD_MD_FLTYPE | OBD_MD_FLATIME;
287         if (cmd == OBD_BRW_WRITE) {
288                 oa->o_valid |= OBD_MD_FLIFID | OBD_MD_FLEPOCH;
289                 mdc_pack_fid(obdo_fid(oa), inode->i_ino, 0, inode->i_mode);
290                 oa->o_easize = ll_i2info(inode)->lli_io_epoch;
291
292                 valid_flags |= OBD_MD_FLMTIME | OBD_MD_FLCTIME;
293         }
294
295         obdo_from_inode(oa, inode, valid_flags);
296 }
297
298 static void ll_ap_fill_obdo(void *data, int cmd, struct obdo *oa)
299 {
300         struct ll_async_page *llap;
301         ENTRY;
302
303         llap = llap_from_cookie(data);
304         if (IS_ERR(llap)) {
305                 EXIT;
306                 return;
307         }
308
309         ll_inode_fill_obdo(llap->llap_page->mapping->host, cmd, oa);
310         EXIT;
311 }
312
313 static struct obd_async_page_ops ll_async_page_ops = {
314         .ap_make_ready =        ll_ap_make_ready,
315         .ap_refresh_count =     ll_ap_refresh_count,
316         .ap_fill_obdo =         ll_ap_fill_obdo,
317         .ap_completion =        ll_ap_completion,
318 };
319
320 /* XXX have the exp be an argument? */
321 struct ll_async_page *llap_from_page(struct page *page)
322 {
323         struct ll_async_page *llap;
324         struct obd_export *exp;
325         struct inode *inode = page->mapping->host;
326         struct ll_sb_info *sbi = ll_i2sbi(inode);
327         int rc;
328         ENTRY;
329
330         if (page->private != 0) {
331                 llap = (struct ll_async_page *)page->private;
332                 if (llap->llap_magic != LLAP_MAGIC)
333                         RETURN(ERR_PTR(-EINVAL));
334                 RETURN(llap);
335         } 
336
337         exp = ll_i2obdexp(page->mapping->host);
338         if (exp == NULL)
339                 RETURN(ERR_PTR(-EINVAL));
340
341         OBD_ALLOC(llap, sizeof(*llap));
342         llap->llap_magic = LLAP_MAGIC;
343         rc = obd_prep_async_page(exp, ll_i2info(inode)->lli_smd,
344                                  NULL, page, 
345                                  (obd_off)page->index << PAGE_SHIFT,
346                                  &ll_async_page_ops, llap, &llap->llap_cookie);
347         if (rc) {
348                 OBD_FREE(llap, sizeof(*llap));
349                 RETURN(ERR_PTR(rc));
350         }
351
352         CDEBUG(D_CACHE, "llap %p page %p cookie %p obj off "LPU64"\n", llap, 
353                page, llap->llap_cookie, (obd_off)page->index << PAGE_SHIFT);
354         page->private = (unsigned long)llap;
355         llap->llap_page = page;
356
357         spin_lock(&sbi->ll_pglist_lock);
358         sbi->ll_pglist_gen++;
359         list_add_tail(&llap->llap_proc_item, &sbi->ll_pglist);
360         spin_unlock(&sbi->ll_pglist_lock);
361
362         RETURN(llap);
363 }
364
365 /* update our write count to account for i_size increases that may have
366  * happened since we've queued the page for io. */
367
368 /* be careful not to return success without setting the page Uptodate or
369  * the next pass through prepare_write will read in stale data from disk. */
370 int ll_commit_write(struct file *file, struct page *page, unsigned from,
371                     unsigned to)
372 {
373         struct inode *inode = page->mapping->host;
374         struct ll_inode_info *lli = ll_i2info(inode);
375         struct lov_stripe_md *lsm = lli->lli_smd;
376         struct obd_export *exp = NULL;
377         struct ll_async_page *llap;
378         loff_t size;
379         int rc = 0;
380         ENTRY;
381
382         SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
383         LASSERT(inode == file->f_dentry->d_inode);
384         LASSERT(PageLocked(page));
385
386         CDEBUG(D_INODE, "inode %p is writing page %p from %d to %d at %lu\n",
387                inode, page, from, to, page->index);
388
389         llap = llap_from_page(page);
390         if (IS_ERR(llap))
391                 RETURN(PTR_ERR(llap));
392
393         /* queue a write for some time in the future the first time we
394          * dirty the page */
395         if (!PageDirty(page)) {
396                 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats,
397                                      LPROC_LL_DIRTY_MISSES);
398
399                 exp = ll_i2obdexp(inode);
400                 if (exp == NULL)
401                         RETURN(-EINVAL);
402
403                 rc = obd_queue_async_io(exp, lsm, NULL, llap->llap_cookie, 
404                                         OBD_BRW_WRITE, 0, 0, 0, 0);
405                 if (rc != 0) { /* async failed, try sync.. */
406                         struct obd_sync_io_container *osic;
407                         osic_init(&osic);
408
409                         rc = obd_queue_sync_io(exp, lsm, NULL, osic, 
410                                                llap->llap_cookie, 
411                                                OBD_BRW_WRITE, 0, to, 0);
412                         if (rc)
413                                 GOTO(free_osic, rc);
414
415                         rc = obd_trigger_sync_io(exp, lsm, NULL, osic);
416                         if (rc)
417                                 GOTO(free_osic, rc);
418
419                         rc = osic_wait(osic);
420 free_osic:
421                         osic_release(osic);
422                         GOTO(out, rc);
423                 }
424                 LL_CDEBUG_PAGE(page, "write queued\n");
425                 llap->llap_queued = 1;
426                 //llap_write_pending(inode, llap);
427         } else {
428                 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats,
429                                      LPROC_LL_DIRTY_HITS);
430         }
431
432         /* put the page in the page cache, from now on ll_removepage is 
433          * responsible for cleaning up the llap */
434         set_page_dirty(page);
435
436 out:
437         if (rc == 0) {
438                 /* XXX needs to be pushed down to the OSC as EOC */
439                 size = (((obd_off)page->index) << PAGE_SHIFT) + to;
440                 if (size > inode->i_size) {
441                         inode->i_size = size;
442                         /* see commentary in file.c:ll_inode_getattr() */
443                         set_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
444                 }
445                 SetPageUptodate(page);
446         }
447         RETURN(rc);
448 }
449
450 /* the kernel calls us here when a page is unhashed from the page cache.
451  * the page will be locked and the kernel is holding a spinlock, so
452  * we need to be careful.  we're just tearing down our book-keeping
453  * here. */
454 void ll_removepage(struct page *page)
455 {
456         struct inode *inode = page->mapping->host;
457         struct obd_export *exp;
458         struct ll_async_page *llap;
459         struct ll_sb_info *sbi = ll_i2sbi(inode);
460         int rc;
461         ENTRY;
462
463         LASSERT(!in_interrupt());
464
465         /* sync pages or failed read pages can leave pages in the page
466          * cache that don't have our data associated with them anymore */
467         if (page->private == 0) {
468                 EXIT;
469                 return;
470         }
471
472         LL_CDEBUG_PAGE(page, "being evicted\n");
473
474         exp = ll_i2obdexp(inode);
475         if (exp == NULL) {
476                 CERROR("page %p ind %lu gave null export\n", page, 
477                        page->index);
478                 EXIT;
479                 return;
480         }
481
482         llap = llap_from_page(page);
483         if (IS_ERR(llap)) {
484                 CERROR("page %p ind %lu couldn't find llap: %ld\n", page, 
485                        page->index, PTR_ERR(llap));
486                 EXIT;
487                 return;
488         }
489
490         //llap_write_complete(inode, llap);
491         rc = obd_teardown_async_page(exp, ll_i2info(inode)->lli_smd, NULL, 
492                                      llap->llap_cookie);
493         if (rc != 0)
494                 CERROR("page %p ind %lu failed: %d\n", page, page->index, rc);
495
496         /* this unconditional free is only safe because the page lock
497          * is providing exclusivity to memory pressure/truncate/writeback..*/
498         page->private = 0;
499
500         spin_lock(&sbi->ll_pglist_lock);
501         if (!list_empty(&llap->llap_proc_item))
502                 list_del_init(&llap->llap_proc_item);
503         sbi->ll_pglist_gen++;
504         spin_unlock(&sbi->ll_pglist_lock);
505         OBD_FREE(llap, sizeof(*llap));
506         EXIT;
507 }
508
509 static int ll_start_readpage(struct obd_export *exp, struct inode *inode, 
510                              struct page *page)
511 {
512         struct ll_async_page *llap;
513         int rc;
514         ENTRY;
515
516         llap = llap_from_page(page);
517         if (IS_ERR(llap))
518                 RETURN(PTR_ERR(llap));
519
520         page_cache_get(page);
521
522         rc = obd_queue_async_io(exp, ll_i2info(inode)->lli_smd, NULL, 
523                                 llap->llap_cookie, OBD_BRW_READ, 0, PAGE_SIZE, 
524                                 0, ASYNC_READY | ASYNC_URGENT | 
525                                    ASYNC_COUNT_STABLE);
526         /* XXX verify that failed pages here will make their way
527          * through ->removepage.. I suspect they will. */
528         if (rc)
529                 page_cache_release(page);
530         else  {
531                 llap->llap_queued = 1;
532                 LL_CDEBUG_PAGE(page, "read queued\n");
533         }
534         RETURN(rc);
535 }
536
537 static void ll_start_readahead(struct obd_export *exp, struct inode *inode, 
538                                unsigned long first_index)
539 {
540         struct lustre_handle match_lockh = {0};
541         struct ldlm_extent page_extent;
542         unsigned long index, end_index;
543         struct page *page;
544         int flags, matched, rc;
545
546         /* for good throughput we need to have many 'blksize' rpcs in
547          * flight per stripe, so we try to read-ahead a ridiculous amount
548          * of data. "- 3" for 8 rpcs */
549         end_index = first_index + (inode->i_blksize >> (PAGE_CACHE_SHIFT - 3));
550         if (end_index > (inode->i_size >> PAGE_CACHE_SHIFT))
551                 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
552
553         for (index = first_index + 1; index < end_index; index++) {
554                 /* try to get a ref on an existing page or create a new
555                  * one.  if we find a locked page or lose the race
556                  * with another reader we stop trying */
557                 page = grab_cache_page_nowait(inode->i_mapping, index);
558                 if (page == NULL)
559                         break;
560                 /* make sure we didn't race with other teardown/readers */
561                 if (!page->mapping || Page_Uptodate(page)) {
562                         unlock_page(page);
563                         page_cache_release(page);
564                         continue;
565                 }
566
567                 /* make sure the page we're about to read is covered
568                  * by a lock, stop when we go past the end of the lock */
569                 page_extent.start = (__u64)page->index << PAGE_CACHE_SHIFT;
570                 page_extent.end = page_extent.start + PAGE_CACHE_SIZE - 1;
571                 flags = LDLM_FL_CBPENDING | LDLM_FL_BLOCK_GRANTED;
572                 matched = obd_match(ll_i2sbi(inode)->ll_osc_exp, 
573                                     ll_i2info(inode)->lli_smd, LDLM_EXTENT,
574                                     &page_extent, sizeof(page_extent), LCK_PR, 
575                                     &flags, inode, &match_lockh);
576                 if (matched < 0) {
577                         LL_CDEBUG_PAGE(page, "lock match failed\n");
578                         unlock_page(page);
579                         page_cache_release(page);
580                         break;
581                 }
582                 if (matched == 0) {
583                         LL_CDEBUG_PAGE(page, "didn't match a lock\n");
584                         unlock_page(page);
585                         page_cache_release(page);
586                         break;
587                 }
588
589                 /* interestingly, we don't need to hold the lock across the IO.
590                  * As long as we match the lock while the page is locked in the
591                  * page cache we know that the lock's cancelation will wait for
592                  * the page to be unlocked.  XXX this should transition to
593                  * proper association of pages and locks in the future */
594                 obd_cancel(ll_i2sbi(inode)->ll_osc_exp,
595                            ll_i2info(inode)->lli_smd, LCK_PR, &match_lockh);
596
597                 rc = ll_start_readpage(exp, inode, page);
598                 if (rc != 0) {
599                         unlock_page(page);
600                         page_cache_release(page);
601                         break;
602                 }
603                 page_cache_release(page);
604         }
605 }
606 /*
607  * for now we do our readpage the same on both 2.4 and 2.5.  The kernel's
608  * read-ahead assumes it is valid to issue readpage all the way up to
609  * i_size, but our dlm locks make that not the case.  We disable the
610  * kernel's read-ahead and do our own by walking ahead in the page cache
611  * checking for dlm lock coverage.  the main difference between 2.4 and
612  * 2.6 is how read-ahead gets batched and issued, but we're using our own,
613  * so they look the same.
614  */
615 int ll_readpage(struct file *file, struct page *page)
616 {
617         struct inode *inode = page->mapping->host;
618         struct lustre_handle match_lockh = {0};
619         struct obd_export *exp;
620         struct ldlm_extent page_extent;
621         int flags, rc = 0, matched;
622         struct ll_sb_info *sbi = ll_i2sbi(inode);
623         ENTRY;
624
625         LASSERT(PageLocked(page));
626         LASSERT(!PageUptodate(page));
627         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),offset="LPX64"\n",
628                inode->i_ino, inode->i_generation, inode,
629                (((obd_off)page->index) << PAGE_SHIFT));
630         LASSERT(atomic_read(&file->f_dentry->d_inode->i_count) > 0);
631
632         if (inode->i_size <= ((obd_off)page->index) << PAGE_SHIFT) {
633                 CERROR("reading beyond EOF\n");
634                 memset(kmap(page), 0, PAGE_SIZE);
635                 kunmap(page);
636                 SetPageUptodate(page);
637                 GOTO(out, rc = 0);
638         }
639
640         exp = ll_i2obdexp(inode);
641         if (exp == NULL)
642                 GOTO(out, rc = -EINVAL);
643
644         page_extent.start = (__u64)page->index << PAGE_CACHE_SHIFT;
645         page_extent.end = page_extent.start + PAGE_CACHE_SIZE - 1;
646         flags = LDLM_FL_CBPENDING | LDLM_FL_BLOCK_GRANTED;
647         matched = obd_match(sbi->ll_osc_exp, ll_i2info(inode)->lli_smd, 
648                             LDLM_EXTENT, &page_extent, sizeof(page_extent), 
649                             LCK_PR, &flags, inode, &match_lockh);
650         if (matched < 0)
651                 GOTO(out, rc = matched);
652
653         if (matched == 0) {
654                 static unsigned long next_print;
655                 CDEBUG(D_INODE, "didn't match a lock");
656                 if (time_after(jiffies, next_print)) {
657                         next_print = jiffies + 30 * HZ;
658                         CERROR("not covered by a lock (mmap?).  check debug "
659                                "logs.\n");
660                 }
661         }
662
663         rc = ll_start_readpage(exp, inode, page);
664         if (rc == 0 && (sbi->ll_flags & LL_SBI_READAHEAD))
665                 ll_start_readahead(exp, inode, page->index);
666
667         if (matched == 1)
668                 obd_cancel(ll_i2sbi(inode)->ll_osc_exp, 
669                            ll_i2info(inode)->lli_smd, LCK_PR, &match_lockh);
670 out:
671         if (rc)
672                 unlock_page(page);
673         RETURN(rc);
674 }