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, 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;
57 printk("obdfs_readpage: obdo_alloc failure\n");
62 oa->o_id = inode->i_ino;
63 err = IOPS(inode, brw)(READ, IID(inode), oa, (char *)page_address(page),
64 PAGE_SIZE, (page->index) << PAGE_SHIFT, 0);
65 obdo_to_inode(inode, oa); /* copy o_blocks to i_blocks */
68 if (err == PAGE_SIZE ) {
69 SetPageUptodate(page);
73 if ( err == PAGE_SIZE )
79 static kmem_cache_t *obdfs_wreq_cachep;
81 int obdfs_init_wreqcache(void)
83 /* XXX need to free this somewhere? */
85 obdfs_wreq_cachep = kmem_cache_create("obdfs_wreq",
86 sizeof(struct obdfs_wreq),
87 0, SLAB_HWCACHE_ALIGN,
89 if (obdfs_wreq_cachep == NULL) {
98 * Find a specific page in the page cache. If it is found, we return
99 * the write request struct associated with it, if not found return NULL.
101 static struct obdfs_wreq *
102 obdfs_find_in_page_cache(struct inode *inode, struct page *page)
104 struct list_head *list_head = &OBD_LIST(inode);
105 struct obdfs_wreq *head, *wreq;
108 CDEBUG(D_INODE, "looking for inode %ld page %p\n", inode->i_ino, page);
109 if (list_empty(list_head)) {
110 CDEBUG(D_INODE, "empty list\n");
114 wreq = head = WREQ(list_head->next);
116 CDEBUG(D_INODE, "checking page %p\n", wreq->wb_page);
117 if (wreq->wb_page == page) {
118 CDEBUG(D_INODE, "found page %p in list\n", page);
122 } while ((wreq = WB_NEXT(wreq)) != head);
130 * Remove a writeback request from a list
133 obdfs_remove_from_page_cache(struct obdfs_wreq *wreq)
135 struct inode *inode = wreq->wb_inode;
136 struct page *page = wreq->wb_page;
141 CDEBUG(D_INODE, "removing inode %ld page %p, wreq: %p\n",
142 inode->i_ino, page, wreq);
145 printk("obdfs_remove_from_page_cache: obdo_alloc failure\n");
149 oa->o_id = inode->i_ino;
150 err = IOPS(inode, brw)(WRITE, IID(inode), oa,(char *)page_address(page),
151 PAGE_SIZE, (page->index) << PAGE_SHIFT, 1);
152 obdo_to_inode(inode, oa); /* copy o_blocks to i_blocks */
153 /* XXX probably should handle error here somehow. I think that
154 * ext2 also does the same thing - discard write even if error?
157 list_del(&wreq->wb_list);
158 kmem_cache_free(obdfs_wreq_cachep, wreq);
165 * Add a page to the write request cache list for later writing
168 obdfs_add_to_page_cache(struct inode *inode, struct page *page)
170 struct obdfs_wreq *wreq;
173 wreq = kmem_cache_alloc(obdfs_wreq_cachep, SLAB_KERNEL);
174 CDEBUG(D_INODE, "adding inode %ld page %p, wreq: %p\n",
175 inode->i_ino, page, wreq);
180 memset(wreq, 0, sizeof(*wreq));
182 wreq->wb_page = page;
183 wreq->wb_inode = inode;
185 get_page(wreq->wb_page);
186 list_add(&wreq->wb_list, &OBD_LIST(inode));
188 /* For testing purposes, we write out the page here.
189 * In the future, a flush daemon will write out the page.
191 wreq = obdfs_find_in_page_cache(inode, page);
193 CDEBUG(D_INODE, "XXXX Can't find page after adding it!!!\n");
196 return obdfs_remove_from_page_cache(wreq);
202 /* returns the page unlocked, but with a reference */
203 int obdfs_writepage(struct dentry *dentry, struct page *page)
205 struct inode *inode = dentry->d_inode;
209 PDEBUG(page, "WRITEPAGE");
210 /* XXX flush stuff */
211 err = obdfs_add_to_page_cache(inode, page);
214 SetPageUptodate(page);
215 PDEBUG(page,"WRITEPAGE");
220 * This does the "real" work of the write. The generic routine has
221 * allocated the page, locked it, done all the page alignment stuff
222 * calculations etc. Now we should just copy the data from user
223 * space and write it back to the real medium..
225 * If the writer ends up delaying the write, the writer needs to
226 * increment the page use counts until he is done with the page.
228 int obdfs_write_one_page(struct file *file, struct page *page,
229 unsigned long offset, unsigned long bytes,
233 struct inode *inode = file->f_dentry->d_inode;
236 if ( !Page_Uptodate(page) ) {
240 printk("obdfs_write_one_page: obdo_alloc failure\n");
244 oa->o_id = inode->i_ino;
245 status = IOPS(inode, brw)(READ, IID(inode), oa,
246 (char *)page_address(page), PAGE_SIZE, (page->index) << PAGE_SHIFT, 1);
247 obdo_to_inode(inode, oa); /* copy o_blocks to i_blocks */
250 if (status == PAGE_SIZE ) {
251 SetPageUptodate(page);
256 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
261 status = obdfs_writepage(file->f_dentry, page);
265 if ( status != PAGE_SIZE )
275 void report_inode(struct page * page) {
276 struct inode *inode = (struct inode *)0;
277 int offset = (int)&inode->i_data;
278 inode = (struct inode *)( (char *)page->mapping - offset);
279 if ( inode->i_sb->s_magic == 0x4711 )
280 printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
284 return an up to date page:
285 - if locked is true then is returned locked
286 - if create is true the corresponding disk blocks are created
287 - page is held, i.e. caller must release the page
291 struct page *obdfs_getpage(struct inode *inode, unsigned long offset,
292 int create, int locked)
294 struct page *page_cache;
302 offset = offset & PAGE_CACHE_MASK;
303 CDEBUG(D_INODE, "\n");
306 page_cache = page_cache_alloc();
309 CDEBUG(D_INODE, "page_cache %p\n", page_cache);
311 hash = page_hash(&inode->i_data, offset);
312 page = grab_cache_page(&inode->i_data, offset);
314 PDEBUG(page, "obdfs_getpage: got page - before reading\n");
315 /* now check if the data in the page is up to date */
316 if ( Page_Uptodate(page)) {
323 /* it's not: read it */
325 printk("obdfs_getpage: says no dice ...\n");
331 printk("obdfs_getpage: obdo_alloc failure\n");
335 oa->o_id = inode->i_ino;
336 err = IOPS(inode, brw)(READ, IID(inode), oa, (char *)page_address(page),
337 PAGE_SIZE, (page->index) << PAGE_SHIFT, create);
339 obdo_to_inode(inode, oa); /* XXX to copy o_blocks */
342 if ( err != PAGE_SIZE ) {
350 SetPageUptodate(page);
351 PDEBUG(page,"GETPAGE - after reading");