1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.sf.net/projects/lustre/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/config.h>
24 #include <linux/kernel.h>
26 #include <linux/string.h>
27 #include <linux/stat.h>
28 #include <linux/errno.h>
29 #include <linux/locks.h>
30 #include <linux/unistd.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
36 #include <linux/stat.h>
37 #include <asm/uaccess.h>
38 #include <asm/segment.h>
40 #include <linux/pagemap.h>
41 #include <linux/smp_lock.h>
43 #define DEBUG_SUBSYSTEM S_OST
45 #include <linux/obd_support.h>
46 #include <linux/lustre_lib.h>
47 #include <linux/lustre_idl.h>
48 #include <linux/lustre_mds.h>
49 #include <linux/lustre_light.h>
52 * Remove page from dirty list
54 static void __set_page_clean(struct page *page)
56 struct address_space *mapping = page->mapping;
62 spin_lock(&pagecache_lock);
63 list_del(&page->list);
64 list_add(&page->list, &mapping->clean_pages);
66 inode = mapping->host;
67 if (list_empty(&mapping->dirty_pages)) {
68 CDEBUG(D_INODE, "inode clean\n");
69 inode->i_state &= ~I_DIRTY_PAGES;
71 spin_unlock(&pagecache_lock);
75 inline void set_page_clean(struct page *page)
77 if (PageDirty(page)) {
79 __set_page_clean(page);
83 inline void lustre_put_page(struct page *page)
86 page_cache_release(page);
89 struct page * lustre_get_page(struct inode *dir, unsigned long n)
91 struct address_space *mapping = dir->i_mapping;
92 struct page *page = read_cache_page(mapping, n,
93 (filler_t*)mapping->a_ops->readpage, NULL);
97 if (!Page_Uptodate(page))
105 lustre_put_page(page);
106 return ERR_PTR(-EIO);
109 void lustre_prepare_page(unsigned from, unsigned to, struct page *page)
114 err = page->mapping->a_ops->prepare_write(NULL, page, from, to);
116 CERROR("page index %ld from %d to %d err %d\n",
117 page->index, from, to, err);
123 int lustre_commit_page(struct page *page, unsigned from, unsigned to)
125 struct inode *dir = page->mapping->host;
128 SetPageUptodate(page);
129 set_page_clean(page);
131 page->mapping->a_ops->commit_write(NULL, page, from, to);
133 err = waitfor_one_page(page);
135 lustre_put_page(page);