/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*
- * linux/fs/obdfilter/filter_io.c
+ * GPL HEADER START
*
- * Copyright (c) 2001-2003 Cluster File Systems, Inc.
- * Author: Peter Braam <braam@clusterfs.com>
- * Author: Andreas Dilger <adilger@clusterfs.com>
- * Author: Phil Schwan <phil@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of the Lustre file system, http://www.lustre.org
- * Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
*
- * You may have signed or agreed to another license before downloading
- * this software. If so, you are bound by the terms and conditions
- * of that agreement, and the following does not apply to you. See the
- * LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
*
- * If you did not agree to a different license, then this copy of Lustre
- * is open source software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
- * In either case, Lustre is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/obdfilter/filter_io_26.c
+ *
+ * Author: Peter Braam <braam@clusterfs.com>
+ * Author: Andreas Dilger <adilger@clusterfs.com>
+ * Author: Phil Schwan <phil@clusterfs.com>
*/
#ifndef AUTOCONF_INCLUDED
int dr_error;
struct page **dr_pages;
unsigned long *dr_blocks;
- spinlock_t dr_lock; /* IRQ lock */
unsigned int dr_ignore_quota:1;
struct filter_obd *dr_filter;
};
{
struct filter_obd *filter = iobuf->dr_filter;
- /* CAVEAT EMPTOR: possibly in IRQ context
+ /* CAVEAT EMPTOR: possibly in IRQ context
* DO NOT record procfs stats here!!! */
if (rw == OBD_BRW_READ)
static int dio_complete_routine(struct bio *bio, unsigned int done, int error)
{
struct filter_iobuf *iobuf = bio->bi_private;
- unsigned long flags;
+ struct bio_vec *bvl;
+ int i;
- /* CAVEAT EMPTOR: possibly in IRQ context
+ /* CAVEAT EMPTOR: possibly in IRQ context
* DO NOT record procfs stats here!!! */
if (bio->bi_size) /* Not complete */
return 1;
- if (iobuf == NULL) {
+ if (unlikely(iobuf == NULL)) {
CERROR("***** bio->bi_private is NULL! This should never "
"happen. Normally, I would crash here, but instead I "
"will dump the bio contents to the console. Please "
- "report this to CFS, along with any interesting "
- "messages leading up to this point (like SCSI errors, "
- "perhaps). Because bi_private is NULL, I can't wake up "
- "the thread that initiated this I/O -- so you will "
- "probably have to reboot this node.\n");
+ "report this to <http://bugzilla.lustre.org/> , along "
+ "with any interesting messages leading up to this point "
+ "(like SCSI errors, perhaps). Because bi_private is "
+ "NULL, I can't wake up the thread that initiated this "
+ "IO - you will probably have to reboot this node.\n");
CERROR("bi_next: %p, bi_flags: %lx, bi_rw: %lu, bi_vcnt: %d, "
"bi_idx: %d, bi->size: %d, bi_end_io: %p, bi_cnt: %d, "
"bi_private: %p\n", bio->bi_next, bio->bi_flags,
return 0;
}
- spin_lock_irqsave(&iobuf->dr_lock, flags);
- if (iobuf->dr_error == 0)
- iobuf->dr_error = error;
- spin_unlock_irqrestore(&iobuf->dr_lock, flags);
+ /* the check is outside of the cycle for performance reason -bzzz */
+ if (!test_bit(BIO_RW, &bio->bi_rw)) {
+ bio_for_each_segment(bvl, bio, i) {
+ if (likely(error == 0))
+ SetPageUptodate(bvl->bv_page);
+ LASSERT(PageLocked(bvl->bv_page));
+ ClearPageConstant(bvl->bv_page);
+ }
+ record_finish_io(iobuf, OBD_BRW_READ, error);
+ } else {
+ if (mapping_cap_page_constant_write(iobuf->dr_pages[0]->mapping)){
+ bio_for_each_segment(bvl, bio, i) {
+ ClearPageConstant(bvl->bv_page);
+ }
+ }
+ record_finish_io(iobuf, OBD_BRW_WRITE, error);
+ }
- record_finish_io(iobuf, test_bit(BIO_RW, &bio->bi_rw) ?
- OBD_BRW_WRITE : OBD_BRW_READ, error);
+ /* any real error is good enough -bzzz */
+ if (error != 0 && iobuf->dr_error == 0)
+ iobuf->dr_error = error;
/* Completed bios used to be chained off iobuf->dr_bios and freed in
* filter_clear_dreq(). It was then possible to exhaust the biovec-256
iobuf->dr_filter = filter;
init_waitqueue_head(&iobuf->dr_wait);
atomic_set(&iobuf->dr_numreqs, 0);
- spin_lock_init(&iobuf->dr_lock);
iobuf->dr_max_pages = num_pages;
iobuf->dr_npages = 0;
iobuf->dr_error = 0;
void filter_iobuf_put(struct filter_obd *filter, struct filter_iobuf *iobuf,
struct obd_trans_info *oti)
{
- int thread_id = oti ? oti->oti_thread_id : -1;
+ int thread_id = (oti && oti->oti_thread) ?
+ oti->oti_thread->t_id : -1;
if (unlikely(thread_id < 0)) {
filter_free_iobuf(iobuf);
sector_bits))
nblocks++;
+ /* I only set the page to be constant only if it
+ * is mapped to a contiguous underlying disk block(s).
+ * It will then make sure the corresponding device
+ * cache of raid5 will be overwritten by this page.
+ * - jay */
+ if ((rw == OBD_BRW_WRITE) &&
+ (nblocks == blocks_per_page) &&
+ mapping_cap_page_constant_write(inode->i_mapping))
+ SetPageConstant(page);
+
if (bio != NULL &&
can_be_merged(bio, sector) &&
bio_add_page(bio, page,
frags++;
}
- /* allocate new bio */
- bio = bio_alloc(GFP_NOIO,
- (npages - page_idx) * blocks_per_page);
+ /* allocate new bio, limited by max BIO size, b=9945 */
+ bio = bio_alloc(GFP_NOIO, max(BIO_MAX_PAGES,
+ (npages - page_idx) *
+ blocks_per_page));
if (bio == NULL) {
CERROR("Can't allocate bio %u*%u = %u pages\n",
(npages - page_idx), blocks_per_page,
lprocfs_oh_tally_log2(&obd->u.filter.fo_filter_stats.hist[BRW_R_IO_TIME],
jiffies - start_time);
lprocfs_oh_tally_log2(&exp->exp_filter_data.fed_brw_stats.hist[BRW_R_IO_TIME], jiffies - start_time);
+ if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
+ lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_R_DIO_FRAGS],
+ frags);
+ lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_R_IO_TIME],
+ jiffies - start_time);
+ }
} else {
lprocfs_oh_tally(&obd->u.filter.fo_filter_stats.hist[BRW_W_DIO_FRAGS],
frags);
lprocfs_oh_tally_log2(&obd->u.filter.fo_filter_stats.hist[BRW_W_IO_TIME],
jiffies - start_time);
lprocfs_oh_tally_log2(&exp->exp_filter_data.fed_brw_stats.hist[BRW_W_IO_TIME], jiffies - start_time);
+ if (exp->exp_nid_stats && exp->exp_nid_stats->nid_brw_stats) {
+ lprocfs_oh_tally(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_DIO_FRAGS],
+ frags);
+ lprocfs_oh_tally_log2(&exp->exp_nid_stats->nid_brw_stats->hist[BRW_W_IO_TIME],
+ jiffies - start_time);
+ }
}
if (rc == 0)
RETURN(rc);
}
-/* These are our hacks to keep our directio/bh IO coherent with ext3's
- * page cache use. Most notably ext3 reads file data into the page
- * cache when it is zeroing the tail of partial-block truncates and
- * leaves it there, sometimes generating io from it at later truncates.
- * This removes the partial page and its buffers from the page cache,
- * so it should only ever cause a wait in rare cases, as otherwise we
- * always do full-page IO to the OST.
- *
- * The call to truncate_complete_page() will call journal_invalidatepage()
- * to free the buffers and drop the page from cache. The buffers should
- * not be dirty, because we already called fdatasync/fdatawait on them.
- */
-static int filter_sync_inode_data(struct inode *inode, int locked)
-{
- int rc = 0;
-
- /* This is nearly do_fsync(), without the waiting on the inode */
- /* XXX: in 2.6.16 (at least) we don't need to hold i_mutex over
- * filemap_fdatawrite() and filemap_fdatawait(), so we may no longer
- * need this lock here at all. */
- if (!locked)
- LOCK_INODE_MUTEX(inode);
- if (inode->i_mapping->nrpages) {
-#ifdef PF_SYNCWRITE
- current->flags |= PF_SYNCWRITE;
-#endif
- rc = filemap_fdatawrite(inode->i_mapping);
- if (rc == 0)
- rc = filemap_fdatawait(inode->i_mapping);
-#ifdef PF_SYNCWRITE
- current->flags &= ~PF_SYNCWRITE;
-#endif
- }
- if (!locked)
- UNLOCK_INODE_MUTEX(inode);
-
- return rc;
-}
-/* Clear pages from the mapping before we do direct IO to that offset.
- * Now that the only source of such pages in the truncate path flushes
- * these pages to disk and then discards them, this is error condition.
- * If add back read cache this will happen again. This could be disabled
- * until that time if we never see the below error. */
-static int filter_clear_page_cache(struct inode *inode,
- struct filter_iobuf *iobuf)
-{
- struct page *page;
- int i, rc;
-
- rc = filter_sync_inode_data(inode, 0);
- if (rc != 0)
- RETURN(rc);
-
- /* be careful to call this after fsync_inode_data_buffers has waited
- * for IO to complete before we evict it from the cache */
- for (i = 0; i < iobuf->dr_npages; i++) {
- page = find_lock_page(inode->i_mapping,
- iobuf->dr_pages[i]->index);
- if (page == NULL)
- continue;
- if (page->mapping != NULL) {
- CERROR("page %lu (%d/%d) in page cache during write!\n",
- page->index, i, iobuf->dr_npages);
- wait_on_page_writeback(page);
- ll_truncate_complete_page(page);
- }
-
- unlock_page(page);
- page_cache_release(page);
- }
-
- return 0;
-}
-
-int filter_clear_truncated_page(struct inode *inode)
-{
- struct page *page;
- int rc;
-
- /* Truncate on page boundary, so nothing to flush? */
- if (!(i_size_read(inode) & ~CFS_PAGE_MASK))
- return 0;
-
- rc = filter_sync_inode_data(inode, 1);
- if (rc != 0)
- RETURN(rc);
-
- /* be careful to call this after fsync_inode_data_buffers has waited
- * for IO to complete before we evict it from the cache */
- page = find_lock_page(inode->i_mapping,
- i_size_read(inode) >> CFS_PAGE_SHIFT);
- if (page) {
- if (page->mapping != NULL) {
- wait_on_page_writeback(page);
- ll_truncate_complete_page(page);
- }
- unlock_page(page);
- page_cache_release(page);
- }
-
- return 0;
-}
-
/* Must be called with i_mutex taken for writes; this will drop it */
int filter_direct_io(int rw, struct dentry *dchild, struct filter_iobuf *iobuf,
struct obd_export *exp, struct iattr *attr,
create = 1;
sem = &obd->u.filter.fo_alloc_lock;
- lquota_enforce(filter_quota_interface_ref, obd, iobuf->dr_ignore_quota);
+ lquota_enforce(filter_quota_interface_ref, obd,
+ iobuf->dr_ignore_quota);
}
rc = fsfilt_map_inode_pages(obd, inode, iobuf->dr_pages,
iobuf->dr_blocks, blocks_per_page, 0);
}
- rc = filter_clear_page_cache(inode, iobuf);
- if (rc != 0)
- RETURN(rc);
-
RETURN(filter_do_bio(exp, inode, iobuf, rw));
}
return 1;
}
+/*
+ * interesting use cases on how it interacts with VM:
+ *
+ * - vm writeout -- shouldn't see our pages as we don't mark them dirty
+ * though vm can find partial page left dirty by truncate. in this
+ * usual writeout is used unless our write rewrite that page - then we
+ * drop PG_dirty with PG_lock held.
+ *
+ * - else?
+ *
+ */
int filter_commitrw_write(struct obd_export *exp, struct obdo *oa,
- int objcount, struct obd_ioobj *obj, int niocount,
+ int objcount, struct obd_ioobj *obj,
+ struct niobuf_remote *nb, int niocount,
struct niobuf_local *res, struct obd_trans_info *oti,
int rc)
{
struct lvfs_run_ctxt saved;
struct fsfilt_objinfo fso;
struct iattr iattr = { 0 };
- struct inode *inode = NULL;
+ struct inode *inode = res->dentry->d_inode;
unsigned long now = jiffies;
int i, err, cleanup_phase = 0;
struct obd_device *obd = exp->exp_obd;
+ struct filter_obd *fo = &obd->u.filter;
void *wait_handle;
- int total_size = 0, rc2;
+ int total_size = 0;
+ int rec_pending = 0;
unsigned int qcids[MAXQUOTAS] = {0, 0};
ENTRY;
if (rc != 0)
GOTO(cleanup, rc);
- /* Unfortunately, if quota master is too busy to handle the
- * pre-dqacq in time and quota hash on ost is used up, we
- * have to wait for the completion of in flight dqacq/dqrel,
- * then try again */
- if ((rc2 = lquota_chkquota(filter_quota_interface_ref, obd, oa->o_uid,
- oa->o_gid, niocount)) == QUOTA_RET_ACQUOTA) {
- OBD_FAIL_TIMEOUT(OBD_FAIL_OST_HOLD_WRITE_RPC, 90);
- lquota_acquire(filter_quota_interface_ref, obd, oa->o_uid,
- oa->o_gid);
- }
-
- if (rc2 < 0) {
- rc = rc2;
- GOTO(cleanup, rc);
- }
+ /* we try to get enough quota to write here, and let ldiskfs
+ * decide if it is out of quota or not b=14783 */
+ lquota_chkquota(filter_quota_interface_ref, obd, oa->o_uid,
+ oa->o_gid, niocount, &rec_pending, oti,
+ LQUOTA_FLAGS_BLK, (void *)inode, obj->ioo_bufcnt);
iobuf = filter_iobuf_get(&obd->u.filter, oti);
if (IS_ERR(iobuf))
fso.fso_dentry = res->dentry;
fso.fso_bufcnt = obj->ioo_bufcnt;
- inode = res->dentry->d_inode;
iobuf->dr_ignore_quota = 0;
- for (i = 0, lnb = res; i < obj->ioo_bufcnt; i++, lnb++) {
+ for (i = 0, lnb = res; i < niocount; i++, lnb++) {
loff_t this_size;
+ __u32 flags = lnb->flags;
/* If overwriting an existing block, we don't need a grant */
- if (!(lnb->flags & OBD_BRW_GRANTED) && lnb->rc == -ENOSPC &&
+ if (!(flags & OBD_BRW_GRANTED) && lnb->rc == -ENOSPC &&
filter_range_is_mapped(inode, lnb->offset, lnb->len))
lnb->rc = 0;
continue;
}
+ LASSERT(PageLocked(lnb->page));
+ LASSERT(!PageWriteback(lnb->page));
+
+ /* preceding filemap_write_and_wait() should have clean pages */
+ if (fo->fo_writethrough_cache)
+ clear_page_dirty_for_io(lnb->page);
+ LASSERT(!PageDirty(lnb->page));
+
+ SetPageUptodate(lnb->page);
+
err = filter_iobuf_add_page(obd, iobuf, inode, lnb->page);
LASSERT (err == 0);
if (this_size > iattr.ia_size)
iattr.ia_size = this_size;
- /* if one page is a write-back page from client cache, or it's
- * written by root, then mark the whole io request as ignore
- * quota request */
- if (lnb->flags & (OBD_BRW_FROM_GRANT | OBD_BRW_NOQUOTA))
+ /* if one page is a write-back page from client cache and
+ * not from direct_io, or it's written by root, then mark
+ * the whole io request as ignore quota request, remote
+ * client can not break through quota. */
+ if (exp_connect_rmtclient(exp))
+ flags &= ~OBD_BRW_NOQUOTA;
+ if ((flags & OBD_BRW_NOQUOTA) ||
+ (flags & (OBD_BRW_FROM_GRANT | OBD_BRW_SYNC)) ==
+ OBD_BRW_FROM_GRANT)
iobuf->dr_ignore_quota = 1;
}
DQUOT_INIT(inode);
LOCK_INODE_MUTEX(inode);
- fsfilt_check_slow(obd, now, obd_timeout, "i_mutex");
+ fsfilt_check_slow(obd, now, "i_mutex");
oti->oti_handle = fsfilt_brw_start(obd, objcount, &fso, niocount, res,
oti);
if (IS_ERR(oti->oti_handle)) {
}
/* have to call fsfilt_commit() from this point on */
- fsfilt_check_slow(obd, now, obd_timeout, "brw_start");
+ fsfilt_check_slow(obd, now, "brw_start");
i = OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
CDEBUG(D_INODE, "update UID/GID to %lu/%lu\n",
(unsigned long)oa->o_uid, (unsigned long)oa->o_gid);
- cap_raise(current->cap_effective, CAP_SYS_RESOURCE);
+ cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
iattr.ia_valid |= ATTR_MODE;
iattr.ia_mode = inode->i_mode;
* in the inode before filter_direct_io() - see bug 10357. */
save = iattr.ia_valid;
iattr.ia_valid &= (ATTR_UID | ATTR_GID);
- rc = fsfilt_setattr(obd, res->dentry, oti->oti_handle, &iattr, 0);
- CDEBUG(D_QUOTA, "set uid(%u)/gid(%u) to ino(%lu). rc(%d)\n",
+ rc = fsfilt_setattr(obd, res->dentry, oti->oti_handle,&iattr,0);
+ CDEBUG(D_QUOTA, "set uid(%u)/gid(%u) to ino(%lu). rc(%d)\n",
iattr.ia_uid, iattr.ia_gid, inode->i_ino, rc);
iattr.ia_valid = save & ~(ATTR_UID | ATTR_GID);
}
lquota_getflag(filter_quota_interface_ref, obd, oa);
- fsfilt_check_slow(obd, now, obd_timeout, "direct_io");
+ fsfilt_check_slow(obd, now, "direct_io");
err = fsfilt_commit_wait(obd, inode, wait_handle);
if (err) {
"oti_transno "LPU64" last_committed "LPU64"\n",
oti->oti_transno, obd->obd_last_committed);
- fsfilt_check_slow(obd, now, obd_timeout, "commitrw commit");
+ fsfilt_check_slow(obd, now, "commitrw commit");
cleanup:
+ if (rec_pending)
+ lquota_pending_commit(filter_quota_interface_ref, obd, oa->o_uid,
+ oa->o_gid, rec_pending, 1);
+
filter_grant_commit(exp, niocount, res);
switch (cleanup_phase) {
CDEBUG(err ? D_ERROR : D_QUOTA,
"filter adjust qunit! (rc:%d)\n", err);
+ for (i = 0, lnb = res; i < niocount; i++, lnb++) {
+ if (lnb->page == NULL)
+ continue;
+
+ LASSERT(PageLocked(lnb->page));
+ unlock_page(lnb->page);
+
+ page_cache_release(lnb->page);
+ lnb->page = NULL;
+ }
+
+ if (inode && (fo->fo_writethrough_cache == 0 ||
+ i_size_read(inode) > fo->fo_readcache_max_filesize))
+ filter_invalidate_cache(obd, obj, nb, inode);
+
RETURN(rc);
}