1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/obdfilter/filter_io.c
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
9 * Author: Phil Schwan <phil@clusterfs.com>
11 * This file is part of Lustre, http://www.lustre.org.
13 * Lustre is free software; you can redistribute it and/or
14 * modify it under the terms of version 2 of the GNU General Public
15 * License as published by the Free Software Foundation.
17 * Lustre is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Lustre; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DEBUG_SUBSYSTEM S_FILTER
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/pagemap.h> // XXX kill me soon
32 #include <linux/version.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_fsfilt.h>
36 #include "filter_internal.h"
38 static int filter_start_page_read(struct inode *inode, struct niobuf_local *lnb)
40 struct address_space *mapping = inode->i_mapping;
42 unsigned long index = lnb->offset >> PAGE_SHIFT;
45 page = grab_cache_page(mapping, index); /* locked page */
47 return lnb->rc = -ENOMEM;
49 LASSERT(page->mapping == mapping);
53 if (inode->i_size < lnb->offset + lnb->len - 1)
54 lnb->rc = inode->i_size - lnb->offset;
58 if (PageUptodate(page)) {
63 rc = mapping->a_ops->readpage(NULL, page);
65 CERROR("page index %lu, rc = %d\n", index, rc);
67 page_cache_release(page);
74 static int filter_finish_page_read(struct niobuf_local *lnb)
76 if (lnb->page == NULL)
79 if (PageUptodate(lnb->page))
82 wait_on_page(lnb->page);
83 if (!PageUptodate(lnb->page)) {
84 CERROR("page index %lu/offset "LPX64" not uptodate\n",
85 lnb->page->index, lnb->offset);
86 GOTO(err_page, lnb->rc = -EIO);
88 if (PageError(lnb->page)) {
89 CERROR("page index %lu/offset "LPX64" has error\n",
90 lnb->page->index, lnb->offset);
91 GOTO(err_page, lnb->rc = -EIO);
97 page_cache_release(lnb->page);
102 /* Grab the dirty and seen grant announcements from the incoming obdo.
103 * We will later calculate the clients new grant and return it.
104 * Caller must hold osfs lock */
105 static void filter_grant_incoming(struct obd_export *exp, struct obdo *oa)
107 struct filter_export_data *fed;
108 struct obd_device *obd = exp->exp_obd;
109 static unsigned long last_msg;
110 static int last_count;
114 LASSERT_SPIN_LOCKED(&obd->obd_osfs_lock);
116 if ((oa->o_valid & (OBD_MD_FLBLOCKS|OBD_MD_FLGRANT)) !=
117 (OBD_MD_FLBLOCKS|OBD_MD_FLGRANT)) {
118 oa->o_valid &= ~OBD_MD_FLGRANT;
123 fed = &exp->exp_filter_data;
125 /* Don't print this to the console the first time it happens, since
126 * it can happen legitimately on occasion, but only rarely. */
127 if (time_after(jiffies, last_msg + 60 * HZ)) {
131 if ((last_count & (-last_count)) == last_count)
135 /* Add some margin, since there is a small race if other RPCs arrive
136 * out-or-order and have already consumed some grant. We want to
137 * leave this here in case there is a large error in accounting. */
138 CDEBUG(oa->o_grant > fed->fed_grant + FILTER_GRANT_CHUNK ? mask:D_CACHE,
139 "%s: cli %s/%p reports grant: "LPU64" dropped: %u, local: %lu\n",
140 obd->obd_name, exp->exp_client_uuid.uuid, exp, oa->o_grant,
141 oa->o_dropped, fed->fed_grant);
143 /* Update our accounting now so that statfs takes it into account.
144 * Note that fed_dirty is only approximate and can become incorrect
145 * if RPCs arrive out-of-order. No important calculations depend
146 * on fed_dirty however. */
147 obd->u.filter.fo_tot_dirty += oa->o_dirty - fed->fed_dirty;
148 if (fed->fed_grant < oa->o_dropped) {
149 CERROR("%s: cli %s/%p reports %u dropped > fed_grant %lu\n",
150 obd->obd_name, exp->exp_client_uuid.uuid, exp,
151 oa->o_dropped, fed->fed_grant);
154 if (obd->u.filter.fo_tot_granted < oa->o_dropped) {
155 CERROR("%s: cli %s/%p reports %u dropped > tot_grant "LPU64"\n",
156 obd->obd_name, exp->exp_client_uuid.uuid, exp,
157 oa->o_dropped, obd->u.filter.fo_tot_granted);
160 obd->u.filter.fo_tot_granted -= oa->o_dropped;
161 fed->fed_grant -= oa->o_dropped;
162 fed->fed_dirty = oa->o_dirty;
166 #define GRANT_FOR_LLOG(obd) 16
168 /* Figure out how much space is available between what we've granted
169 * and what remains in the filesystem. Compensate for ext3 indirect
170 * block overhead when computing how much free space is left ungranted.
172 * Caller must hold obd_osfs_lock. */
173 obd_size filter_grant_space_left(struct obd_export *exp)
175 struct obd_device *obd = exp->exp_obd;
176 int blockbits = obd->u.filter.fo_sb->s_blocksize_bits;
177 obd_size tot_granted = obd->u.filter.fo_tot_granted, avail, left = 0;
178 int rc, statfs_done = 0;
180 LASSERT_SPIN_LOCKED(&obd->obd_osfs_lock);
182 if (time_before(obd->obd_osfs_age, jiffies - HZ)) {
184 rc = fsfilt_statfs(obd, obd->u.filter.fo_sb, jiffies + 1);
185 if (rc) /* N.B. statfs can't really fail */
190 avail = obd->obd_osfs.os_bavail;
191 left = avail - (avail >> (blockbits - 3)); /* (d)indirect */
192 if (left > GRANT_FOR_LLOG(obd)) {
193 left = (left - GRANT_FOR_LLOG(obd)) << blockbits;
195 left = 0 /* << blockbits */;
198 if (!statfs_done && left < 32 * FILTER_GRANT_CHUNK + tot_granted) {
199 CDEBUG(D_CACHE, "fs has no space left and statfs too old\n");
203 if (left >= tot_granted) {
206 static unsigned long next;
207 if (left < tot_granted - obd->u.filter.fo_tot_pending &&
208 time_after(jiffies, next)) {
209 spin_unlock(&obd->obd_osfs_lock);
210 CERROR("%s: cli %s/%p grant "LPU64" > available "
211 LPU64" and pending "LPU64"\n", obd->obd_name,
212 exp->exp_client_uuid.uuid, exp, tot_granted,
213 left, obd->u.filter.fo_tot_pending);
215 portals_debug_dumplog();
216 next = jiffies + 20 * HZ;
217 spin_lock(&obd->obd_osfs_lock);
222 CDEBUG(D_CACHE, "%s: cli %s/%p free: "LPU64" avail: "LPU64" grant "LPU64
223 " left: "LPU64" pending: "LPU64"\n", obd->obd_name,
224 exp->exp_client_uuid.uuid, exp,
225 obd->obd_osfs.os_bfree << blockbits, avail << blockbits,
226 tot_granted, left, obd->u.filter.fo_tot_pending);
231 /* Calculate how much grant space to allocate to this client, based on how
232 * much space is currently free and how much of that is already granted.
234 * Caller must hold obd_osfs_lock. */
235 long filter_grant(struct obd_export *exp, obd_size current_grant,
236 obd_size want, obd_size fs_space_left)
238 struct obd_device *obd = exp->exp_obd;
239 struct filter_export_data *fed = &exp->exp_filter_data;
240 int blockbits = obd->u.filter.fo_sb->s_blocksize_bits;
243 LASSERT_SPIN_LOCKED(&obd->obd_osfs_lock);
245 /* Grant some fraction of the client's requested grant space so that
246 * they are not always waiting for write credits (not all of it to
247 * avoid overgranting in face of multiple RPCs in flight). This
248 * essentially will be able to control the OSC_MAX_RIF for a client.
250 * If we do have a large disparity between what the client thinks it
251 * has and what we think it has, don't grant very much and let the
252 * client consume its grant first. Either it just has lots of RPCs
253 * in flight, or it was evicted and its grants will soon be used up. */
254 if (current_grant < want &&
255 current_grant < fed->fed_grant + FILTER_GRANT_CHUNK) {
256 grant = min((want >> blockbits) / 2,
257 (fs_space_left >> blockbits) / 8);
261 if (grant > FILTER_GRANT_CHUNK)
262 grant = FILTER_GRANT_CHUNK;
264 obd->u.filter.fo_tot_granted += grant;
265 fed->fed_grant += grant;
269 CDEBUG(D_CACHE,"%s: cli %s/%p wants: "LPU64" granting: "LPU64"\n",
270 obd->obd_name, exp->exp_client_uuid.uuid, exp, want, grant);
272 "%s: cli %s/%p tot cached:"LPU64" granted:"LPU64
273 " num_exports: %d\n", obd->obd_name, exp->exp_client_uuid.uuid,
274 exp, obd->u.filter.fo_tot_dirty,
275 obd->u.filter.fo_tot_granted, obd->obd_num_exports);
280 static int filter_preprw_read(int cmd, struct obd_export *exp, struct obdo *oa,
281 int objcount, struct obd_ioobj *obj,
282 int niocount, struct niobuf_remote *nb,
283 struct niobuf_local *res,
284 struct obd_trans_info *oti)
286 struct obd_device *obd = exp->exp_obd;
287 struct obd_run_ctxt saved;
289 struct niobuf_remote *rnb;
290 struct niobuf_local *lnb = NULL;
291 struct fsfilt_objinfo *fso;
292 struct dentry *dentry;
294 int rc = 0, i, j, tot_bytes = 0, cleanup_phase = 0;
295 unsigned long now = jiffies;
298 /* We are currently not supporting multi-obj BRW_READ RPCS at all.
299 * When we do this function's dentry cleanup will need to be fixed */
300 LASSERT(objcount == 1);
301 LASSERT(obj->ioo_bufcnt > 0);
303 if (oa && oa->o_valid & OBD_MD_FLGRANT) {
304 spin_lock(&obd->obd_osfs_lock);
305 filter_grant_incoming(exp, oa);
308 /* Reads do not increase grants */
309 oa->o_grant = filter_grant(exp, oa->o_grant, oa->o_undirty,
310 filter_grant_space_left(exp));
314 spin_unlock(&obd->obd_osfs_lock);
317 OBD_ALLOC(fso, objcount * sizeof(*fso));
321 memset(res, 0, niocount * sizeof(*res));
323 push_ctxt(&saved, &exp->exp_obd->obd_ctxt, NULL);
324 for (i = 0, o = obj; i < objcount; i++, o++) {
325 LASSERT(o->ioo_bufcnt);
327 dentry = filter_oa2dentry(obd, oa);
329 GOTO(cleanup, rc = PTR_ERR(dentry));
331 if (dentry->d_inode == NULL) {
332 CERROR("trying to BRW to non-existent file "LPU64"\n",
335 GOTO(cleanup, rc = -ENOENT);
338 fso[i].fso_dentry = dentry;
339 fso[i].fso_bufcnt = o->ioo_bufcnt;
342 if (time_after(jiffies, now + 15 * HZ))
343 CERROR("slow preprw_read setup %lus\n", (jiffies - now) / HZ);
345 CDEBUG(D_INFO, "preprw_read setup: %lu jiffies\n",
348 for (i = 0, o = obj, rnb = nb, lnb = res; i < objcount; i++, o++) {
349 dentry = fso[i].fso_dentry;
350 inode = dentry->d_inode;
352 for (j = 0; j < o->ioo_bufcnt; j++, rnb++, lnb++) {
353 lnb->dentry = dentry;
354 lnb->offset = rnb->offset;
356 lnb->flags = rnb->flags;
358 if (inode->i_size <= rnb->offset) {
359 /* If there's no more data, abort early.
360 * lnb->page == NULL and lnb->rc == 0, so it's
361 * easy to detect later. */
364 rc = filter_start_page_read(inode, lnb);
368 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
369 "page err %u@"LPU64" %u/%u %p: rc %d\n",
370 lnb->len, lnb->offset, j, o->ioo_bufcnt,
376 tot_bytes += lnb->rc;
377 if (lnb->rc < lnb->len) {
378 /* short read, be sure to wait on it */
385 if (time_after(jiffies, now + 15 * HZ))
386 CERROR("slow start_page_read %lus\n", (jiffies - now) / HZ);
388 CDEBUG(D_INFO, "start_page_read: %lu jiffies\n",
391 lprocfs_counter_add(obd->obd_stats, LPROC_FILTER_READ_BYTES, tot_bytes);
392 while (lnb-- > res) {
393 rc = filter_finish_page_read(lnb);
395 CERROR("error page %u@"LPU64" %u %p: rc %d\n", lnb->len,
396 lnb->offset, (int)(lnb - res), lnb->dentry, rc);
402 if (time_after(jiffies, now + 15 * HZ))
403 CERROR("slow finish_page_read %lus\n", (jiffies - now) / HZ);
405 CDEBUG(D_INFO, "finish_page_read: %lu jiffies\n",
408 filter_tally_read(&exp->exp_obd->u.filter, res, niocount);
413 switch (cleanup_phase) {
415 for (lnb = res; lnb < (res + niocount); lnb++) {
417 page_cache_release(lnb->page);
419 if (res->dentry != NULL)
422 CERROR("NULL dentry in cleanup -- tell CFS\n");
424 OBD_FREE(fso, objcount * sizeof(*fso));
425 pop_ctxt(&saved, &exp->exp_obd->obd_ctxt, NULL);
430 /* When clients have dirtied as much space as they've been granted they
431 * fall through to sync writes. These sync writes haven't been expressed
432 * in grants and need to error with ENOSPC when there isn't room in the
433 * filesystem for them after grants are taken into account. However,
434 * writeback of the dirty data that was already granted space can write
437 * Caller must hold obd_osfs_lock. */
438 static int filter_grant_check(struct obd_export *exp, int objcount,
439 struct fsfilt_objinfo *fso, int niocount,
440 struct niobuf_remote *rnb,
441 struct niobuf_local *lnb, obd_size *left,
444 struct filter_export_data *fed = &exp->exp_filter_data;
445 int blocksize = exp->exp_obd->u.filter.fo_sb->s_blocksize;
446 unsigned long used = 0, ungranted = 0, using;
447 int i, rc = -ENOSPC, obj, n = 0, mask = D_CACHE;
449 LASSERT_SPIN_LOCKED(&exp->exp_obd->obd_osfs_lock);
451 for (obj = 0; obj < objcount; obj++) {
452 for (i = 0; i < fso[obj].fso_bufcnt; i++, n++) {
455 /* FIXME: this is calculated with PAGE_SIZE on client */
457 bytes += rnb[n].offset & (blocksize - 1);
458 tmp = (rnb[n].offset + rnb[n].len) & (blocksize - 1);
460 bytes += blocksize - tmp;
462 if (rnb[n].flags & OBD_BRW_FROM_GRANT) {
463 if (fed->fed_grant < used + bytes) {
465 "%s: cli %s/%p claims %ld+%d "
466 "GRANT, real grant %lu idx %d\n",
467 exp->exp_obd->obd_name,
468 exp->exp_client_uuid.uuid, exp,
469 used, bytes, fed->fed_grant, n);
473 rnb[n].flags |= OBD_BRW_GRANTED;
474 lnb[n].lnb_grant_used = bytes;
475 CDEBUG(0, "idx %d used=%lu\n", n, used);
480 if (*left > ungranted) {
481 /* if enough space, pretend it was granted */
483 rnb[n].flags |= OBD_BRW_GRANTED;
484 CDEBUG(0, "idx %d ungranted=%lu\n",n,ungranted);
489 /* We can't check for already-mapped blocks here, as
490 * it requires dropping the osfs lock to do the bmap.
491 * Instead, we return ENOSPC and in that case we need
492 * to go through and verify if all of the blocks not
493 * marked BRW_GRANTED are already mapped and we can
494 * ignore this error. */
496 rnb[n].flags &= OBD_BRW_GRANTED;
497 CDEBUG(D_CACHE,"%s: cli %s/%p idx %d no space for %d\n",
498 exp->exp_obd->obd_name,
499 exp->exp_client_uuid.uuid, exp, n, bytes);
503 /* Now substract what client have used already. We don't subtract
504 * this from the tot_granted yet, so that other client's can't grab
505 * that space before we have actually allocated our blocks. That
506 * happens in filter_grant_commit() after the writes are done. */
508 fed->fed_grant -= used;
509 fed->fed_pending += used;
510 exp->exp_obd->u.filter.fo_tot_pending += used;
513 "%s: cli %s/%p used: %lu ungranted: %lu grant: %lu dirty: %lu\n",
514 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp, used,
515 ungranted, fed->fed_grant, fed->fed_dirty);
517 /* Rough calc in case we don't refresh cached statfs data */
518 using = (used + ungranted + 1 ) >>
519 exp->exp_obd->u.filter.fo_sb->s_blocksize_bits;
520 if (exp->exp_obd->obd_osfs.os_bavail > using)
521 exp->exp_obd->obd_osfs.os_bavail -= using;
523 exp->exp_obd->obd_osfs.os_bavail = 0;
525 if (fed->fed_dirty < used) {
526 CERROR("%s: cli %s/%p claims used %lu > fed_dirty %lu\n",
527 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
528 used, fed->fed_dirty);
529 used = fed->fed_dirty;
531 exp->exp_obd->u.filter.fo_tot_dirty -= used;
532 fed->fed_dirty -= used;
537 static int filter_start_page_write(struct inode *inode,
538 struct niobuf_local *lnb)
540 struct page *page = alloc_pages(GFP_HIGHUSER, 0);
542 CERROR("no memory for a temp page\n");
543 RETURN(lnb->rc = -ENOMEM);
545 POISON_PAGE(page, 0xf1);
546 if (lnb->len != PAGE_SIZE) {
547 memset(kmap(page) + lnb->len, 0, PAGE_SIZE - lnb->len);
550 page->index = lnb->offset >> PAGE_SHIFT;
556 /* If we ever start to support multi-object BRW RPCs, we will need to get locks
557 * on mulitple inodes. That isn't all, because there still exists the
558 * possibility of a truncate starting a new transaction while holding the ext3
559 * rwsem = write while some writes (which have started their transactions here)
560 * blocking on the ext3 rwsem = read => lock inversion.
562 * The handling gets very ugly when dealing with locked pages. It may be easier
563 * to just get rid of the locked page code (which has problems of its own) and
564 * either discover we do not need it anymore (i.e. it was a symptom of another
565 * bug) or ensure we get the page locks in an appropriate order. */
566 static int filter_preprw_write(int cmd, struct obd_export *exp, struct obdo *oa,
567 int objcount, struct obd_ioobj *obj,
568 int niocount, struct niobuf_remote *nb,
569 struct niobuf_local *res,
570 struct obd_trans_info *oti)
572 struct obd_run_ctxt saved;
573 struct niobuf_remote *rnb;
574 struct niobuf_local *lnb;
575 struct fsfilt_objinfo fso;
576 struct dentry *dentry;
578 unsigned long now = jiffies;
579 int rc = 0, i, tot_bytes = 0, cleanup_phase = 1;
581 LASSERT(objcount == 1);
582 LASSERT(obj->ioo_bufcnt > 0);
584 memset(res, 0, niocount * sizeof(*res));
586 push_ctxt(&saved, &exp->exp_obd->obd_ctxt, NULL);
587 dentry = filter_fid2dentry(exp->exp_obd, NULL, obj->ioo_gr,
590 GOTO(cleanup, rc = PTR_ERR(dentry));
592 if (dentry->d_inode == NULL) {
593 CERROR("trying to BRW to non-existent file "LPU64"\n",
596 GOTO(cleanup, rc = -ENOENT);
599 fso.fso_dentry = dentry;
600 fso.fso_bufcnt = obj->ioo_bufcnt;
602 if (time_after(jiffies, now + 15 * HZ))
603 CERROR("slow preprw_write setup %lus\n", (jiffies - now) / HZ);
605 CDEBUG(D_INFO, "preprw_write setup: %lu jiffies\n",
608 spin_lock(&exp->exp_obd->obd_osfs_lock);
610 filter_grant_incoming(exp, oa);
613 left = filter_grant_space_left(exp);
615 rc = filter_grant_check(exp, objcount, &fso, niocount, nb, res,
616 &left, dentry->d_inode);
617 if (oa && oa->o_valid & OBD_MD_FLGRANT)
618 oa->o_grant = filter_grant(exp,oa->o_grant,oa->o_undirty,left);
620 spin_unlock(&exp->exp_obd->obd_osfs_lock);
627 for (i = 0, rnb = nb, lnb = res; i < obj->ioo_bufcnt;
629 /* We still set up for ungranted pages so that granted pages
630 * can be written to disk as they were promised, and portals
631 * needs to keep the pages all aligned properly. */
632 lnb->dentry = dentry;
633 lnb->offset = rnb->offset;
635 lnb->flags = rnb->flags;
637 rc = filter_start_page_write(dentry->d_inode, lnb);
639 CERROR("page err %u@"LPU64" %u/%u %p: rc %d\n",
640 lnb->len, lnb->offset,
641 i, obj->ioo_bufcnt, dentry, rc);
643 __free_pages(lnb->page, 0);
648 tot_bytes += lnb->len;
651 if (time_after(jiffies, now + 15 * HZ))
652 CERROR("slow start_page_write %lus\n", (jiffies - now) / HZ);
654 CDEBUG(D_INFO, "start_page_write: %lu jiffies\n",
657 lprocfs_counter_add(exp->exp_obd->obd_stats, LPROC_FILTER_WRITE_BYTES,
661 switch(cleanup_phase) {
663 spin_lock(&exp->exp_obd->obd_osfs_lock);
665 filter_grant_incoming(exp, oa);
666 spin_unlock(&exp->exp_obd->obd_osfs_lock);
669 pop_ctxt(&saved, &exp->exp_obd->obd_ctxt, NULL);
673 int filter_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
674 int objcount, struct obd_ioobj *obj, int niocount,
675 struct niobuf_remote *nb, struct niobuf_local *res,
676 struct obd_trans_info *oti)
678 if (cmd == OBD_BRW_WRITE)
679 return filter_preprw_write(cmd, exp, oa, objcount, obj,
680 niocount, nb, res, oti);
682 if (cmd == OBD_BRW_READ)
683 return filter_preprw_read(cmd, exp, oa, objcount, obj,
684 niocount, nb, res, oti);
690 static int filter_commitrw_read(struct obd_export *exp, struct obdo *oa,
691 int objcount, struct obd_ioobj *obj,
692 int niocount, struct niobuf_local *res,
693 struct obd_trans_info *oti, int rc)
696 struct niobuf_local *lnb;
700 if (res->dentry != NULL)
701 drop = (res->dentry->d_inode->i_size >
702 exp->exp_obd->u.filter.fo_readcache_max_filesize);
704 for (i = 0, o = obj, lnb = res; i < objcount; i++, o++) {
705 for (j = 0 ; j < o->ioo_bufcnt ; j++, lnb++) {
706 if (lnb->page == NULL)
708 /* drop from cache like truncate_list_pages() */
709 if (drop && !TryLockPage(lnb->page)) {
710 if (lnb->page->mapping)
711 ll_truncate_complete_page(lnb->page);
712 unlock_page(lnb->page);
714 page_cache_release(lnb->page);
718 if (res->dentry != NULL)
723 void flip_into_page_cache(struct inode *inode, struct page *new_page)
725 struct page *old_page;
729 /* the dlm is protecting us from read/write concurrency, so we
730 * expect this find_lock_page to return quickly. even if we
731 * race with another writer it won't be doing much work with
732 * the page locked. we do this 'cause t_c_p expects a
733 * locked page, and it wants to grab the pagecache lock
735 old_page = find_lock_page(inode->i_mapping, new_page->index);
737 ll_truncate_complete_page(old_page);
738 unlock_page(old_page);
739 page_cache_release(old_page);
742 #if 0 /* this should be a /proc tunable someday */
743 /* racing o_directs (no locking ioctl) could race adding
744 * their pages, so we repeat the page invalidation unless
745 * we successfully added our new page */
746 rc = add_to_page_cache_unique(new_page, inode->i_mapping,
748 page_hash(inode->i_mapping,
751 /* add_to_page_cache clears uptodate|dirty and locks
753 SetPageUptodate(new_page);
754 unlock_page(new_page);
762 void filter_grant_commit(struct obd_export *exp, int niocount,
763 struct niobuf_local *res)
765 struct filter_obd *filter = &exp->exp_obd->u.filter;
766 struct niobuf_local *lnb = res;
767 unsigned long pending = 0;
770 spin_lock(&exp->exp_obd->obd_osfs_lock);
771 for (i = 0, lnb = res; i < niocount; i++, lnb++)
772 pending += lnb->lnb_grant_used;
774 LASSERTF(exp->exp_filter_data.fed_pending >= pending,
775 "%s: cli %s/%p fed_pending: %lu grant_used: %lu\n",
776 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
777 exp->exp_filter_data.fed_pending, pending);
778 exp->exp_filter_data.fed_pending -= pending;
779 LASSERTF(filter->fo_tot_granted >= pending,
780 "%s: cli %s/%p tot_granted: "LPU64" grant_used: %lu\n",
781 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
782 exp->exp_obd->u.filter.fo_tot_granted, pending);
783 filter->fo_tot_granted -= pending;
784 LASSERTF(filter->fo_tot_pending >= pending,
785 "%s: cli %s/%p tot_pending: "LPU64" grant_used: %lu\n",
786 exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
787 filter->fo_tot_pending, pending);
788 filter->fo_tot_pending -= pending;
790 spin_unlock(&exp->exp_obd->obd_osfs_lock);
793 int filter_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
794 int objcount, struct obd_ioobj *obj, int niocount,
795 struct niobuf_local *res, struct obd_trans_info *oti,int rc)
797 if (cmd == OBD_BRW_WRITE)
798 return filter_commitrw_write(exp, oa, objcount, obj, niocount,
800 if (cmd == OBD_BRW_READ)
801 return filter_commitrw_read(exp, oa, objcount, obj, niocount,
807 int filter_brw(int cmd, struct obd_export *exp, struct obdo *oa,
808 struct lov_stripe_md *lsm, obd_count oa_bufs,
809 struct brw_page *pga, struct obd_trans_info *oti)
811 struct obd_ioobj ioo;
812 struct niobuf_local *lnb;
813 struct niobuf_remote *rnb;
818 OBD_ALLOC(lnb, oa_bufs * sizeof(struct niobuf_local));
819 OBD_ALLOC(rnb, oa_bufs * sizeof(struct niobuf_remote));
821 if (lnb == NULL || rnb == NULL)
822 GOTO(out, ret = -ENOMEM);
824 for (i = 0; i < oa_bufs; i++) {
825 rnb[i].offset = pga[i].off;
826 rnb[i].len = pga[i].count;
829 obdo_to_ioobj(oa, &ioo);
830 ioo.ioo_bufcnt = oa_bufs;
832 ret = filter_preprw(cmd, exp, oa, 1, &ioo, oa_bufs, rnb, lnb, oti);
836 for (i = 0; i < oa_bufs; i++) {
837 void *virt = kmap(pga[i].pg);
838 obd_off off = pga[i].off & ~PAGE_MASK;
839 void *addr = kmap(lnb[i].page);
841 /* 2 kmaps == vanishingly small deadlock opportunity */
843 if (cmd & OBD_BRW_WRITE)
844 memcpy(addr + off, virt + off, pga[i].count);
846 memcpy(virt + off, addr + off, pga[i].count);
852 ret = filter_commitrw(cmd, exp, oa, 1, &ioo, oa_bufs, lnb, oti, ret);
856 OBD_FREE(lnb, oa_bufs * sizeof(struct niobuf_local));
858 OBD_FREE(rnb, oa_bufs * sizeof(struct niobuf_remote));