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.
25 #include <linux/config.h>
26 #include <linux/kernel.h>
28 #include <linux/string.h>
29 #include <linux/stat.h>
30 #include <linux/errno.h>
31 #include <linux/locks.h>
32 #include <linux/unistd.h>
33 #include <linux/version.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
39 #include <linux/stat.h>
40 #include <asm/uaccess.h>
41 #include <asm/segment.h>
43 #include <linux/pagemap.h>
44 #include <linux/smp_lock.h>
46 #define DEBUG_SUBSYSTEM S_OST
48 #include <linux/obd_class.h>
49 #include <linux/lustre_lib.h>
52 * Remove page from dirty list
54 static void __set_page_clean(struct page *page)
56 struct address_space *mapping = page->mapping;
62 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,9))
63 spin_lock(&pagecache_lock);
66 list_del(&page->list);
67 list_add(&page->list, &mapping->clean_pages);
69 inode = mapping->host;
70 if (list_empty(&mapping->dirty_pages)) {
71 CDEBUG(D_INODE, "inode clean\n");
72 inode->i_state &= ~I_DIRTY_PAGES;
74 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,10))
75 spin_unlock(&pagecache_lock);
80 inline void set_page_clean(struct page *page)
82 if (PageDirty(page)) {
84 __set_page_clean(page);
88 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10))
90 * Add a page to the dirty page list.
92 void __set_page_dirty(struct page *page)
94 struct address_space *mapping;
97 pg_lock = PAGECACHE_LOCK(page);
100 mapping = page->mapping;
101 spin_lock(&mapping->page_lock);
103 list_del(&page->list);
104 list_add(&page->list, &mapping->dirty_pages);
106 spin_unlock(&mapping->page_lock);
107 spin_unlock(pg_lock);
110 mark_inode_dirty_pages(mapping->host);
114 * Add a page to the dirty page list.
116 void set_page_dirty(struct page *page)
118 if (!test_and_set_bit(PG_dirty, &page->flags)) {
119 struct address_space *mapping = page->mapping;
122 spin_lock(&pagecache_lock);
123 list_del(&page->list);
124 list_add(&page->list, &mapping->dirty_pages);
125 spin_unlock(&pagecache_lock);
128 mark_inode_dirty_pages(mapping->host);
134 inline void lustre_put_page(struct page *page)
137 page_cache_release(page);
140 struct page *lustre_get_page_read(struct inode *inode, unsigned long index)
142 struct address_space *mapping = inode->i_mapping;
146 page = read_cache_page(mapping, index,
147 (filler_t*)mapping->a_ops->readpage, NULL);
151 if (!Page_Uptodate(page)) {
152 CERROR("page index %lu not uptodate\n", index);
153 GOTO(err_page, rc = -EIO);
155 if (PageError(page)) {
156 CERROR("page index %lu has error\n", index);
157 GOTO(err_page, rc = -EIO);
163 lustre_put_page(page);
167 struct page *lustre_get_page_write(struct inode *inode, unsigned long index)
169 struct address_space *mapping = inode->i_mapping;
173 page = grab_cache_page(mapping, index); /* locked page */
176 /* Note: Called with "O" and "PAGE_SIZE" this is essentially
177 * a no-op for most filesystems, because we write the whole
178 * page. For partial-page I/O this will read in the page.
180 rc = mapping->a_ops->prepare_write(NULL, page, 0, PAGE_SIZE);
182 CERROR("page index %lu, rc = %d\n", index, rc);
185 GOTO(err_unlock, rc);
187 /* XXX not sure if we need this if we are overwriting page */
188 if (PageError(page)) {
189 CERROR("error on page index %lu, rc = %d\n", index, rc);
191 GOTO(err_unlock, rc = -EIO);
200 lustre_put_page(page);
204 int lustre_commit_page(struct page *page, unsigned from, unsigned to)
206 struct inode *inode = page->mapping->host;
209 SetPageUptodate(page);
210 set_page_clean(page);
212 page->mapping->a_ops->commit_write(NULL, page, from, to);
214 err = waitfor_one_page(page);
216 lustre_put_page(page);