2 * OBDFS Super operations
4 * Copryright (C) 1999 Stelias Computing Inc,
5 * (author Peter J. Braam <braam@stelias.com>)
6 * Copryright (C) 1999 Seagate Technology Inc.
10 #include <linux/config.h>
11 #include <linux/kernel.h>
13 #include <linux/string.h>
14 #include <linux/stat.h>
15 #include <linux/errno.h>
16 #include <linux/locks.h>
17 #include <linux/unistd.h>
19 #include <asm/system.h>
20 #include <asm/uaccess.h>
23 #include <linux/stat.h>
24 #include <asm/uaccess.h>
25 #include <linux/vmalloc.h>
26 #include <asm/segment.h>
28 #include <linux/pagemap.h>
29 #include <linux/smp_lock.h>
31 #include <linux/obd_support.h>
32 #include <linux/obd_ext2.h>
33 #include <linux/obdfs.h>
37 /* VFS super_block ops */
40 int obdfs_brw(struct inode *dir, int rw, struct page *page, int create)
42 return iops(dir)->o_brw(rw, iid(dir), dir, page, create);
46 /* returns the page unlocked, but with a reference */
47 int obdfs_readpage(struct dentry *dentry, struct page *page)
49 struct inode *inode = dentry->d_inode;
50 struct obdfs_wreq *wreq;
55 rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
56 if (rc == PAGE_SIZE ) {
57 SetPageUptodate(page);
61 if ( rc == PAGE_SIZE )
68 static kmem_cache_t *obdfs_wreq_cachep;
70 int obdfs_init_wreqcache(void)
72 /* XXX need to free this somewhere? */
74 obdfs_wreq_cachep = kmem_cache_create("obdfs_wreq",
75 sizeof(struct obdfs_wreq),
76 0, SLAB_HWCACHE_ALIGN,
78 if (obdfs_wreq_cachep == NULL) {
87 * Find a specific page in the page cache. If it is found, we return
88 * the write request struct associated with it, if not found return NULL.
90 static struct obdfs_wreq *
91 obdfs_find_in_page_cache(struct inode *inode, struct page *page)
93 struct list_head *list_head = &OBD_LIST(inode);
94 struct obdfs_wreq *head, *wreq;
97 CDEBUG(D_INODE, "looking for inode %ld page %p\n", inode->i_ino, page);
98 if (list_empty(list_head)) {
99 CDEBUG(D_INODE, "empty list\n");
103 wreq = head = WREQ(list_head->next);
105 CDEBUG(D_INODE, "checking page %p\n", wreq->wb_page);
106 if (wreq->wb_page == page) {
107 CDEBUG(D_INODE, "found page %p in list\n", page);
111 } while ((wreq = WB_NEXT(wreq)) != head);
119 * Remove a writeback request from a list
122 obdfs_remove_from_page_cache(struct obdfs_wreq *wreq)
124 struct inode *inode = wreq->wb_inode;
125 struct page *page = wreq->wb_page;
129 CDEBUG(D_INODE, "removing inode %ld page %p, wreq: %p\n",
130 inode->i_ino, page, wreq);
131 rc = iops(inode)->o_brw(WRITE, iid(inode), inode, page, 1);
132 /* XXX probably should handle error here somehow. I think that
133 * ext2 also does the same thing - discard write even if error?
136 list_del(&wreq->wb_list);
137 kmem_cache_free(obdfs_wreq_cachep, wreq);
144 * Add a page to the write request cache list for later writing
147 obdfs_add_to_page_cache(struct inode *inode, struct page *page)
149 struct obdfs_wreq *wreq;
152 wreq = kmem_cache_alloc(obdfs_wreq_cachep, SLAB_KERNEL);
153 CDEBUG(D_INODE, "adding inode %ld page %p, wreq: %p\n",
154 inode->i_ino, page, wreq);
159 memset(wreq, 0, sizeof(*wreq));
161 wreq->wb_page = page;
162 wreq->wb_inode = inode;
164 get_page(wreq->wb_page);
165 list_add(&wreq->wb_list, &OBD_LIST(inode));
167 /* For testing purposes, we write out the page here.
168 * In the future, a flush daemon will write out the page.
170 wreq = obdfs_find_in_page_cache(inode, page);
172 CDEBUG(D_INODE, "XXXX Can't find page after adding it!!!\n");
175 return obdfs_remove_from_page_cache(wreq);
181 /* returns the page unlocked, but with a reference */
182 int obdfs_writepage(struct dentry *dentry, struct page *page)
184 struct inode *inode = dentry->d_inode;
188 PDEBUG(page, "WRITEPAGE");
189 /* XXX flush stuff */
190 rc = obdfs_add_to_page_cache(inode, page);
193 SetPageUptodate(page);
194 PDEBUG(page,"WRITEPAGE");
199 * This does the "real" work of the write. The generic routine has
200 * allocated the page, locked it, done all the page alignment stuff
201 * calculations etc. Now we should just copy the data from user
202 * space and write it back to the real medium..
204 * If the writer ends up delaying the write, the writer needs to
205 * increment the page use counts until he is done with the page.
207 int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
210 struct inode *inode = file->f_dentry->d_inode;
213 if ( !Page_Uptodate(page) ) {
214 status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
215 if (status == PAGE_SIZE ) {
216 SetPageUptodate(page);
221 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
226 status = obdfs_writepage(file->f_dentry, page);
230 if ( status != PAGE_SIZE )
240 void report_inode(struct page * page) {
241 struct inode *inode = (struct inode *)0;
242 int offset = (int)&inode->i_data;
243 inode = (struct inode *)( (char *)page->mapping - offset);
244 if ( inode->i_sb->s_magic == 0x4711 )
245 printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
249 return an up to date page:
250 - if locked is true then is returned locked
251 - if create is true the corresponding disk blocks are created
252 - page is held, i.e. caller must release the page
256 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
258 struct page *page_cache;
265 offset = offset & PAGE_CACHE_MASK;
266 CDEBUG(D_INODE, "\n");
269 page_cache = page_cache_alloc();
272 CDEBUG(D_INODE, "page_cache %p\n", page_cache);
274 hash = page_hash(&inode->i_data, offset);
275 page = grab_cache_page(&inode->i_data, offset);
277 PDEBUG(page, "GETPAGE: got page - before reading\n");
278 /* now check if the data in the page is up to date */
279 if ( Page_Uptodate(page)) {
286 /* it's not: read it */
288 printk("get_page_map says no dice ...\n");
292 rc = iops(inode)->o_brw(READ, iid(inode), inode, page, create);
293 if ( rc != PAGE_SIZE ) {
301 SetPageUptodate(page);
302 PDEBUG(page,"GETPAGE - after reading");