1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdfilter/filter_io_26.c
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Andreas Dilger <adilger@clusterfs.com>
40 * Author: Phil Schwan <phil@clusterfs.com>
43 #ifndef AUTOCONF_INCLUDED
44 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/pagemap.h> // XXX kill me soon
48 #include <linux/version.h>
49 #include <linux/buffer_head.h>
51 #define DEBUG_SUBSYSTEM S_FILTER
53 #include <obd_class.h>
54 #include <lustre_fsfilt.h>
55 #include <lustre_quota.h>
56 #include "filter_internal.h"
58 /* 512byte block min */
59 #define MAX_BLOCKS_PER_PAGE (CFS_PAGE_SIZE / 512)
61 cfs_atomic_t dr_numreqs; /* number of reqs being processed */
66 struct page **dr_pages;
67 unsigned long *dr_blocks;
68 unsigned int dr_ignore_quota:1;
69 struct filter_obd *dr_filter;
72 static void record_start_io(struct filter_iobuf *iobuf, int rw, int size,
73 struct obd_export *exp)
75 struct filter_obd *filter = iobuf->dr_filter;
77 cfs_atomic_inc(&iobuf->dr_numreqs);
79 if (rw == OBD_BRW_READ) {
80 cfs_atomic_inc(&filter->fo_r_in_flight);
81 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_R_RPC_HIST],
82 cfs_atomic_read(&filter->fo_r_in_flight));
83 lprocfs_oh_tally_log2(&filter->
84 fo_filter_stats.hist[BRW_R_DISK_IOSIZE],
86 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
87 lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->
89 cfs_atomic_read(&filter-> \
91 lprocfs_oh_tally_log2(&exp->exp_nid_stats->
92 nid_brw_stats->hist[BRW_R_DISK_IOSIZE],
96 cfs_atomic_inc(&filter->fo_w_in_flight);
97 lprocfs_oh_tally(&filter->fo_filter_stats.hist[BRW_W_RPC_HIST],
98 cfs_atomic_read(&filter->fo_w_in_flight));
99 lprocfs_oh_tally_log2(&filter->
100 fo_filter_stats.hist[BRW_W_DISK_IOSIZE],
102 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
103 lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->
104 hist[BRW_W_RPC_HIST],
105 cfs_atomic_read(&filter-> \
107 lprocfs_oh_tally_log2(&exp->exp_nid_stats->
108 nid_brw_stats->hist[BRW_W_DISK_IOSIZE],
114 static void record_finish_io(struct filter_iobuf *iobuf, int rw, int rc)
116 struct filter_obd *filter = iobuf->dr_filter;
118 /* CAVEAT EMPTOR: possibly in IRQ context
119 * DO NOT record procfs stats here!!! */
121 if (rw == OBD_BRW_READ)
122 cfs_atomic_dec(&filter->fo_r_in_flight);
124 cfs_atomic_dec(&filter->fo_w_in_flight);
126 if (cfs_atomic_dec_and_test(&iobuf->dr_numreqs))
127 cfs_waitq_signal(&iobuf->dr_wait);
130 static int dio_complete_routine(struct bio *bio, unsigned int done, int error)
132 struct filter_iobuf *iobuf = bio->bi_private;
136 if (bio->bi_rw == WRITE &&
137 unlikely(test_and_clear_bit(BIO_RDONLY, &bio->bi_flags))) {
138 struct block_device *bdev = bio->bi_bdev;
140 CWARN("Write to readonly device %s (%#x) bi_flags: %lx, "
141 "bi_vcnt: %d, bi_idx: %d, bi->size: %d, bi_cnt: %d, "
142 "bi_private: %p, done: %u, error: %d\n",
143 bdev->bd_disk ? bdev->bd_disk->disk_name : "",
144 bdev->bd_dev, bio->bi_flags, bio->bi_vcnt, bio->bi_idx,
145 bio->bi_size, atomic_read(&bio->bi_cnt), bio->bi_private,
149 /* CAVEAT EMPTOR: possibly in IRQ context
150 * DO NOT record procfs stats here!!! */
152 if (bio->bi_size) /* Not complete */
155 if (unlikely(iobuf == NULL)) {
156 CERROR("***** bio->bi_private is NULL! This should never "
157 "happen. Normally, I would crash here, but instead I "
158 "will dump the bio contents to the console. Please "
159 "report this to <http://bugzilla.lustre.org/> , along "
160 "with any interesting messages leading up to this point "
161 "(like SCSI errors, perhaps). Because bi_private is "
162 "NULL, I can't wake up the thread that initiated this "
163 "IO - you will probably have to reboot this node.\n");
164 CERROR("bi_next: %p, bi_flags: %lx, bi_rw: %lu, bi_vcnt: %d, "
165 "bi_idx: %d, bi->size: %d, bi_end_io: %p, bi_cnt: %d, "
166 "bi_private: %p\n", bio->bi_next, bio->bi_flags,
167 bio->bi_rw, bio->bi_vcnt, bio->bi_idx, bio->bi_size,
168 bio->bi_end_io, cfs_atomic_read(&bio->bi_cnt),
173 /* the check is outside of the cycle for performance reason -bzzz */
174 if (!cfs_test_bit(BIO_RW, &bio->bi_rw)) {
175 bio_for_each_segment(bvl, bio, i) {
176 if (likely(error == 0))
177 SetPageUptodate(bvl->bv_page);
178 LASSERT(PageLocked(bvl->bv_page));
179 ClearPageConstant(bvl->bv_page);
181 record_finish_io(iobuf, OBD_BRW_READ, error);
183 if (mapping_cap_page_constant_write(iobuf->dr_pages[0]->mapping)){
184 bio_for_each_segment(bvl, bio, i) {
185 ClearPageConstant(bvl->bv_page);
188 record_finish_io(iobuf, OBD_BRW_WRITE, error);
191 /* any real error is good enough -bzzz */
192 if (error != 0 && iobuf->dr_error == 0)
193 iobuf->dr_error = error;
195 /* Completed bios used to be chained off iobuf->dr_bios and freed in
196 * filter_clear_dreq(). It was then possible to exhaust the biovec-256
197 * mempool when serious on-disk fragmentation was encountered,
198 * deadlocking the OST. The bios are now released as soon as complete
199 * so the pool cannot be exhausted while IOs are competing. bug 10076 */
204 static int can_be_merged(struct bio *bio, sector_t sector)
211 size = bio->bi_size >> 9;
212 return bio->bi_sector + size == sector ? 1 : 0;
215 struct filter_iobuf *filter_alloc_iobuf(struct filter_obd *filter,
216 int rw, int num_pages)
218 struct filter_iobuf *iobuf;
220 LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
222 OBD_ALLOC(iobuf, sizeof(*iobuf));
226 OBD_ALLOC(iobuf->dr_pages, num_pages * sizeof(*iobuf->dr_pages));
227 if (iobuf->dr_pages == NULL)
230 OBD_ALLOC(iobuf->dr_blocks,
231 MAX_BLOCKS_PER_PAGE * num_pages * sizeof(*iobuf->dr_blocks));
232 if (iobuf->dr_blocks == NULL)
235 iobuf->dr_filter = filter;
236 cfs_waitq_init(&iobuf->dr_wait);
237 cfs_atomic_set(&iobuf->dr_numreqs, 0);
238 iobuf->dr_max_pages = num_pages;
239 iobuf->dr_npages = 0;
245 OBD_FREE(iobuf->dr_pages,
246 num_pages * sizeof(*iobuf->dr_pages));
248 OBD_FREE(iobuf, sizeof(*iobuf));
250 RETURN(ERR_PTR(-ENOMEM));
253 static void filter_clear_iobuf(struct filter_iobuf *iobuf)
255 iobuf->dr_npages = 0;
257 cfs_atomic_set(&iobuf->dr_numreqs, 0);
260 void filter_free_iobuf(struct filter_iobuf *iobuf)
262 int num_pages = iobuf->dr_max_pages;
264 filter_clear_iobuf(iobuf);
266 OBD_FREE(iobuf->dr_blocks,
267 MAX_BLOCKS_PER_PAGE * num_pages * sizeof(*iobuf->dr_blocks));
268 OBD_FREE(iobuf->dr_pages,
269 num_pages * sizeof(*iobuf->dr_pages));
273 void filter_iobuf_put(struct filter_obd *filter, struct filter_iobuf *iobuf,
274 struct obd_trans_info *oti)
276 int thread_id = (oti && oti->oti_thread) ?
277 oti->oti_thread->t_id : -1;
279 if (unlikely(thread_id < 0)) {
280 filter_free_iobuf(iobuf);
284 LASSERTF(filter->fo_iobuf_pool[thread_id] == iobuf,
285 "iobuf mismatch for thread %d: pool %p iobuf %p\n",
286 thread_id, filter->fo_iobuf_pool[thread_id], iobuf);
287 filter_clear_iobuf(iobuf);
290 int filter_iobuf_add_page(struct obd_device *obd, struct filter_iobuf *iobuf,
291 struct inode *inode, struct page *page)
293 LASSERT(iobuf->dr_npages < iobuf->dr_max_pages);
294 iobuf->dr_pages[iobuf->dr_npages++] = page;
299 int filter_do_bio(struct obd_export *exp, struct inode *inode,
300 struct filter_iobuf *iobuf, int rw)
302 struct obd_device *obd = exp->exp_obd;
303 int blocks_per_page = CFS_PAGE_SIZE >> inode->i_blkbits;
304 struct page **pages = iobuf->dr_pages;
305 int npages = iobuf->dr_npages;
306 unsigned long *blocks = iobuf->dr_blocks;
307 int total_blocks = npages * blocks_per_page;
308 int sector_bits = inode->i_sb->s_blocksize_bits - 9;
309 unsigned int blocksize = inode->i_sb->s_blocksize;
310 struct bio *bio = NULL;
312 unsigned long start_time = jiffies;
314 unsigned int page_offset;
323 LASSERT(iobuf->dr_npages == npages);
324 LASSERT(total_blocks <= OBDFILTER_CREATED_SCRATCHPAD_ENTRIES);
326 for (page_idx = 0, block_idx = 0;
328 page_idx++, block_idx += blocks_per_page) {
330 page = pages[page_idx];
331 LASSERT (block_idx + blocks_per_page <= total_blocks);
333 for (i = 0, page_offset = 0;
335 i += nblocks, page_offset += blocksize * nblocks) {
339 if (blocks[block_idx + i] == 0) { /* hole */
340 LASSERT(rw == OBD_BRW_READ);
341 memset(kmap(page) + page_offset, 0, blocksize);
346 sector = (sector_t)blocks[block_idx + i] << sector_bits;
348 /* Additional contiguous file blocks? */
349 while (i + nblocks < blocks_per_page &&
350 (sector + (nblocks << sector_bits)) ==
351 ((sector_t)blocks[block_idx + i + nblocks] <<
355 /* I only set the page to be constant only if it
356 * is mapped to a contiguous underlying disk block(s).
357 * It will then make sure the corresponding device
358 * cache of raid5 will be overwritten by this page.
360 if ((rw == OBD_BRW_WRITE) &&
361 (nblocks == blocks_per_page) &&
362 mapping_cap_page_constant_write(inode->i_mapping))
363 SetPageConstant(page);
366 can_be_merged(bio, sector) &&
367 bio_add_page(bio, page,
368 blocksize * nblocks, page_offset) != 0)
369 continue; /* added this frag OK */
373 bdev_get_queue(bio->bi_bdev);
375 /* Dang! I have to fragment this I/O */
376 CDEBUG(D_INODE, "bio++ sz %d vcnt %d(%d) "
377 "sectors %d(%d) psg %d(%d) hsg %d(%d)\n",
379 bio->bi_vcnt, bio->bi_max_vecs,
380 bio->bi_size >> 9, q->max_sectors,
381 bio_phys_segments(q, bio),
382 q->max_phys_segments,
383 bio_hw_segments(q, bio),
386 record_start_io(iobuf, rw, bio->bi_size, exp);
387 rc = fsfilt_send_bio(rw, obd, inode, bio);
389 CERROR("Can't send bio: %d\n", rc);
390 record_finish_io(iobuf, rw, rc);
396 /* allocate new bio, limited by max BIO size, b=9945 */
397 bio = bio_alloc(GFP_NOIO, max(BIO_MAX_PAGES,
398 (npages - page_idx) *
401 CERROR("Can't allocate bio %u*%u = %u pages\n",
402 (npages - page_idx), blocks_per_page,
403 (npages - page_idx) * blocks_per_page);
408 bio->bi_bdev = inode->i_sb->s_bdev;
409 bio->bi_sector = sector;
410 bio->bi_end_io = dio_complete_routine;
411 bio->bi_private = iobuf;
413 rc = bio_add_page(bio, page,
414 blocksize * nblocks, page_offset);
420 record_start_io(iobuf, rw, bio->bi_size, exp);
421 rc = fsfilt_send_bio(rw, obd, inode, bio);
426 CERROR("Can't send bio: %d\n", rc);
427 record_finish_io(iobuf, rw, rc);
432 cfs_wait_event(iobuf->dr_wait,
433 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
435 if (rw == OBD_BRW_READ) {
436 lprocfs_oh_tally(&obd->u.filter.fo_filter_stats.
437 hist[BRW_R_DIO_FRAGS],
439 lprocfs_oh_tally_log2(&obd->u.filter.
440 fo_filter_stats.hist[BRW_R_IO_TIME],
441 jiffies - start_time);
442 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
443 lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->
444 hist[BRW_R_DIO_FRAGS],
446 lprocfs_oh_tally_log2(&exp->exp_nid_stats->
447 nid_brw_stats->hist[BRW_R_IO_TIME],
448 jiffies - start_time);
451 lprocfs_oh_tally(&obd->u.filter.fo_filter_stats.
452 hist[BRW_W_DIO_FRAGS], frags);
453 lprocfs_oh_tally_log2(&obd->u.filter.fo_filter_stats.
455 jiffies - start_time);
456 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
457 lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->
458 hist[BRW_W_DIO_FRAGS],
460 lprocfs_oh_tally_log2(&exp->exp_nid_stats->
461 nid_brw_stats->hist[BRW_W_IO_TIME],
462 jiffies - start_time);
467 rc = iobuf->dr_error;
471 /* Must be called with i_mutex taken for writes; this will drop it */
472 int filter_direct_io(int rw, struct dentry *dchild, struct filter_iobuf *iobuf,
473 struct obd_export *exp, struct iattr *attr,
474 struct obd_trans_info *oti, void **wait_handle)
476 struct obd_device *obd = exp->exp_obd;
477 struct inode *inode = dchild->d_inode;
478 int blocks_per_page = CFS_PAGE_SIZE >> inode->i_blkbits;
480 cfs_semaphore_t *sem;
483 LASSERTF(iobuf->dr_npages <= iobuf->dr_max_pages, "%d,%d\n",
484 iobuf->dr_npages, iobuf->dr_max_pages);
485 LASSERT(iobuf->dr_npages <= OBDFILTER_CREATED_SCRATCHPAD_ENTRIES);
487 if (rw == OBD_BRW_READ) {
488 if (iobuf->dr_npages == 0)
493 LASSERTF(rw == OBD_BRW_WRITE, "%x\n", rw);
494 LASSERT(iobuf->dr_npages > 0);
496 sem = &obd->u.filter.fo_alloc_lock;
498 lquota_enforce(filter_quota_interface_ref, obd,
499 iobuf->dr_ignore_quota);
502 rc = fsfilt_map_inode_pages(obd, inode, iobuf->dr_pages,
503 iobuf->dr_npages, iobuf->dr_blocks,
504 obdfilter_created_scratchpad, create, sem);
506 if (rw == OBD_BRW_WRITE) {
508 filter_tally(exp, iobuf->dr_pages,
509 iobuf->dr_npages, iobuf->dr_blocks,
511 if (attr->ia_size > i_size_read(inode))
512 attr->ia_valid |= ATTR_SIZE;
513 rc = fsfilt_setattr(obd, dchild,
514 oti->oti_handle, attr, 0);
517 UNLOCK_INODE_MUTEX(inode);
519 rc2 = filter_finish_transno(exp, inode, oti, 0, 0);
521 CERROR("can't close transaction: %d\n", rc2);
526 rc2 = fsfilt_commit_async(obd,inode,oti->oti_handle,
532 } else if (rc == 0) {
533 filter_tally(exp, iobuf->dr_pages, iobuf->dr_npages,
534 iobuf->dr_blocks, blocks_per_page, 0);
537 RETURN(filter_do_bio(exp, inode, iobuf, rw));
540 /* See if there are unallocated parts in given file region */
541 static int filter_range_is_mapped(struct inode *inode, obd_size offset, int len)
543 sector_t (*fs_bmap)(struct address_space *, sector_t) =
544 inode->i_mapping->a_ops->bmap;
547 /* We can't know if we are overwriting or not */
551 offset >>= inode->i_blkbits;
552 len >>= inode->i_blkbits;
554 for (j = 0; j <= len; j++)
555 if (fs_bmap(inode->i_mapping, offset + j) == 0)
562 * interesting use cases on how it interacts with VM:
564 * - vm writeout -- shouldn't see our pages as we don't mark them dirty
565 * though vm can find partial page left dirty by truncate. in this
566 * usual writeout is used unless our write rewrite that page - then we
567 * drop PG_dirty with PG_lock held.
572 int filter_commitrw_write(struct obd_export *exp, struct obdo *oa,
573 int objcount, struct obd_ioobj *obj,
574 struct niobuf_remote *nb, int niocount,
575 struct niobuf_local *res, struct obd_trans_info *oti,
578 struct niobuf_local *lnb;
579 struct filter_iobuf *iobuf = NULL;
580 struct lvfs_run_ctxt saved;
581 struct fsfilt_objinfo fso;
582 struct iattr iattr = { 0 };
583 struct inode *inode = res->dentry->d_inode;
584 unsigned long now = jiffies;
585 int i, err, cleanup_phase = 0;
586 struct obd_device *obd = exp->exp_obd;
587 struct filter_obd *fo = &obd->u.filter;
590 unsigned int qcids[MAXQUOTAS] = { oa->o_uid, oa->o_gid };
591 int rec_pending[MAXQUOTAS] = { 0, 0 }, quota_pages = 0;
594 LASSERT(oti != NULL);
595 LASSERT(objcount == 1);
596 LASSERT(current->journal_info == NULL);
601 iobuf = filter_iobuf_get(&obd->u.filter, oti);
603 GOTO(cleanup, rc = PTR_ERR(iobuf));
606 fso.fso_dentry = res->dentry;
607 fso.fso_bufcnt = obj->ioo_bufcnt;
609 iobuf->dr_ignore_quota = 0;
610 for (i = 0, lnb = res; i < niocount; i++, lnb++) {
612 __u32 flags = lnb->flags;
614 if (filter_range_is_mapped(inode, lnb->offset, lnb->len)) {
615 /* If overwriting an existing block,
616 * we don't need a grant */
617 if (!(flags & OBD_BRW_GRANTED) && lnb->rc == -ENOSPC)
623 if (lnb->rc) { /* ENOSPC, network RPC error, etc. */
624 CDEBUG(D_INODE, "Skipping [%d] == %d\n", i, lnb->rc);
628 LASSERT(PageLocked(lnb->page));
629 LASSERT(!PageWriteback(lnb->page));
631 /* preceding filemap_write_and_wait() should have clean pages */
632 if (fo->fo_writethrough_cache)
633 clear_page_dirty_for_io(lnb->page);
634 LASSERT(!PageDirty(lnb->page));
636 SetPageUptodate(lnb->page);
638 err = filter_iobuf_add_page(obd, iobuf, inode, lnb->page);
641 total_size += lnb->len;
643 /* we expect these pages to be in offset order, but we'll
645 this_size = lnb->offset + lnb->len;
646 if (this_size > iattr.ia_size)
647 iattr.ia_size = this_size;
649 /* if one page is a write-back page from client cache and
650 * not from direct_io, or it's written by root, then mark
651 * the whole io request as ignore quota request, remote
652 * client can not break through quota. */
653 if (exp_connect_rmtclient(exp))
654 flags &= ~OBD_BRW_NOQUOTA;
655 if ((flags & OBD_BRW_NOQUOTA) ||
656 (flags & (OBD_BRW_FROM_GRANT | OBD_BRW_SYNC)) ==
658 iobuf->dr_ignore_quota = 1;
661 /* we try to get enough quota to write here, and let ldiskfs
662 * decide if it is out of quota or not b=14783 */
663 rc = lquota_chkquota(filter_quota_interface_ref, obd, exp, qcids,
664 rec_pending, quota_pages, oti, LQUOTA_FLAGS_BLK,
665 (void *)inode, obj->ioo_bufcnt);
669 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
674 LOCK_INODE_MUTEX(inode);
675 fsfilt_check_slow(obd, now, "i_mutex");
676 oti->oti_handle = fsfilt_brw_start(obd, objcount, &fso, niocount, res,
678 if (IS_ERR(oti->oti_handle)) {
679 UNLOCK_INODE_MUTEX(inode);
680 rc = PTR_ERR(oti->oti_handle);
681 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
682 "error starting transaction: rc = %d\n", rc);
683 oti->oti_handle = NULL;
686 /* have to call fsfilt_commit() from this point on */
688 fsfilt_check_slow(obd, now, "brw_start");
690 i = OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
692 /* If the inode still has SUID+SGID bits set (see filter_precreate())
693 * then we will accept the UID+GID if sent by the client for
694 * initializing the ownership of this inode. We only allow this to
695 * happen once (so clear these bits) and later only allow setattr. */
696 if (inode->i_mode & S_ISUID)
698 if (inode->i_mode & S_ISGID)
701 iattr_from_obdo(&iattr, oa, i);
702 if (iattr.ia_valid & (ATTR_UID | ATTR_GID)) {
705 CDEBUG(D_INODE, "update UID/GID to %lu/%lu\n",
706 (unsigned long)oa->o_uid, (unsigned long)oa->o_gid);
708 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
710 iattr.ia_valid |= ATTR_MODE;
711 iattr.ia_mode = inode->i_mode;
712 if (iattr.ia_valid & ATTR_UID)
713 iattr.ia_mode &= ~S_ISUID;
714 if (iattr.ia_valid & ATTR_GID)
715 iattr.ia_mode &= ~S_ISGID;
717 rc = filter_update_fidea(exp, inode, oti->oti_handle, oa);
719 /* To avoid problems with quotas, UID and GID must be set
720 * in the inode before filter_direct_io() - see bug 10357. */
721 save = iattr.ia_valid;
722 iattr.ia_valid &= (ATTR_UID | ATTR_GID);
723 rc = fsfilt_setattr(obd, res->dentry, oti->oti_handle,&iattr,0);
724 CDEBUG(D_QUOTA, "set uid(%u)/gid(%u) to ino(%lu). rc(%d)\n",
725 iattr.ia_uid, iattr.ia_gid, inode->i_ino, rc);
726 iattr.ia_valid = save & ~(ATTR_UID | ATTR_GID);
729 /* filter_direct_io drops i_mutex */
730 rc = filter_direct_io(OBD_BRW_WRITE, res->dentry, iobuf, exp, &iattr,
733 obdo_from_inode(oa, inode,
734 FILTER_VALID_FLAGS |OBD_MD_FLUID |OBD_MD_FLGID);
736 obdo_from_inode(oa, inode, OBD_MD_FLUID | OBD_MD_FLGID);
738 lquota_getflag(filter_quota_interface_ref, obd, oa);
740 fsfilt_check_slow(obd, now, "direct_io");
742 err = fsfilt_commit_wait(obd, inode, wait_handle);
744 CERROR("Failure to commit OST transaction (%d)?\n", err);
748 if (obd->obd_replayable && !rc)
749 LASSERTF(oti->oti_transno <= obd->obd_last_committed,
750 "oti_transno "LPU64" last_committed "LPU64"\n",
751 oti->oti_transno, obd->obd_last_committed);
753 fsfilt_check_slow(obd, now, "commitrw commit");
756 lquota_pending_commit(filter_quota_interface_ref, obd, qcids,
759 filter_grant_commit(exp, niocount, res);
761 switch (cleanup_phase) {
763 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
764 LASSERT(current->journal_info == NULL);
766 filter_iobuf_put(&obd->u.filter, iobuf, oti);
769 * lnb->page automatically returns back into per-thread page
775 /* trigger quota pre-acquire */
776 err = lquota_adjust(filter_quota_interface_ref, obd, qcids, NULL, rc,
778 CDEBUG(err ? D_ERROR : D_QUOTA, "filter adjust qunit! "
779 "(rc:%d, uid:%u, gid:%u)\n",
780 err, qcids[USRQUOTA], qcids[GRPQUOTA]);
781 if (qcids[USRQUOTA] != oa->o_uid || qcids[GRPQUOTA] != oa->o_gid) {
782 qcids[USRQUOTA] = oa->o_uid;
783 qcids[GRPQUOTA] = oa->o_gid;
784 err = lquota_adjust(filter_quota_interface_ref, obd, qcids,
785 NULL, rc, FSFILT_OP_CREATE);
786 CDEBUG(err ? D_ERROR : D_QUOTA, "filter adjust qunit! "
787 "(rc:%d, uid:%u, gid:%u)\n",
788 err, qcids[USRQUOTA], qcids[GRPQUOTA]);
791 for (i = 0, lnb = res; i < niocount; i++, lnb++) {
792 if (lnb->page == NULL)
796 /* If the write has failed, the page cache may
797 * not be consitent with what is on disk, so
798 * force pages to be reread next time it is
800 ClearPageUptodate(lnb->page);
802 LASSERT(PageLocked(lnb->page));
803 unlock_page(lnb->page);
805 page_cache_release(lnb->page);
811 if (fo->fo_writethrough_cache == 0 ||
812 i_size_read(inode) > fo->fo_readcache_max_filesize)
813 filter_release_cache(obd, obj, nb, inode);
814 up_read(&inode->i_alloc_sem);