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 static kmem_cache_t *obdfs_wreq_cachep;
48 int obdfs_init_wreqcache(void)
50 /* XXX need to free this somewhere? */
52 obdfs_wreq_cachep = kmem_cache_create("obdfs_wreq",
53 sizeof(struct obdfs_wreq),
54 0, SLAB_HWCACHE_ALIGN,
56 if (obdfs_wreq_cachep == NULL) {
65 * Find a specific page in the page cache. If it is found, we return
66 * the write request struct associated with it, if not found return NULL.
68 static struct obdfs_wreq *
69 obdfs_find_in_page_cache(struct inode *inode, struct page *page)
71 struct list_head *list_head = &OBD_LIST(inode);
72 struct obdfs_wreq *head, *wreq;
75 CDEBUG(D_INODE, "looking for inode %ld page %p\n", inode->i_ino, page);
76 if (list_empty(list_head)) {
77 CDEBUG(D_INODE, "empty list\n");
81 wreq = head = WREQ(list_head->next);
83 CDEBUG(D_INODE, "checking page %p\n", wreq->wb_page);
84 if (wreq->wb_page == page) {
85 CDEBUG(D_INODE, "found page %p in list\n", page);
89 } while ((wreq = WB_NEXT(wreq)) != head);
95 /* returns the page unlocked, but with a reference */
96 int obdfs_readpage(struct dentry *dentry, struct page *page)
98 struct inode *inode = dentry->d_inode;
99 struct obdfs_wreq *wreq;
103 /* XXX flush stuff */
104 wreq = obdfs_find_in_page_cache(inode, page);
106 PDEBUG(page, "READ");
107 rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
108 if (rc == PAGE_SIZE ) {
109 SetPageUptodate(page);
112 PDEBUG(page, "READ");
113 if ( rc == PAGE_SIZE )
121 * Remove a writeback request from a list
124 obdfs_remove_from_page_cache(struct obdfs_wreq *wreq)
126 struct inode *inode = wreq->wb_inode;
127 struct page *page = wreq->wb_page;
131 CDEBUG(D_INODE, "removing inode %ld page %p, wreq: %p\n",
132 inode->i_ino, page, wreq);
133 rc = iops(inode)->o_brw(WRITE, iid(inode), inode, page, 1);
134 /* XXX probably should handle error here somehow. I think that
135 * ext2 also does the same thing - discard write even if error?
138 list_del(&wreq->wb_list);
139 kmem_cache_free(obdfs_wreq_cachep, wreq);
146 * Add a page to the write request cache list for later writing
149 obdfs_add_to_page_cache(struct inode *inode, struct page *page)
151 struct obdfs_wreq *wreq;
154 wreq = kmem_cache_alloc(obdfs_wreq_cachep, SLAB_KERNEL);
155 CDEBUG(D_INODE, "adding inode %ld page %p, wreq: %p\n",
156 inode->i_ino, page, wreq);
161 memset(wreq, 0, sizeof(*wreq));
163 wreq->wb_page = page;
164 wreq->wb_inode = inode;
166 get_page(wreq->wb_page);
167 list_add(&wreq->wb_list, &OBD_LIST(inode));
169 /* For testing purposes, we write out the page here.
170 * In the future, a flush daemon will write out the page.
172 wreq = obdfs_find_in_page_cache(inode, page);
174 CDEBUG(D_INODE, "XXXX Can't find page after adding it!!!\n");
177 return obdfs_remove_from_page_cache(wreq);
183 /* returns the page unlocked, but with a reference */
184 int obdfs_writepage(struct dentry *dentry, struct page *page)
186 struct inode *inode = dentry->d_inode;
190 PDEBUG(page, "WRITEPAGE");
191 /* XXX flush stuff */
192 rc = obdfs_add_to_page_cache(inode, page);
195 SetPageUptodate(page);
196 PDEBUG(page,"WRITEPAGE");
201 * This does the "real" work of the write. The generic routine has
202 * allocated the page, locked it, done all the page alignment stuff
203 * calculations etc. Now we should just copy the data from user
204 * space and write it back to the real medium..
206 * If the writer ends up delaying the write, the writer needs to
207 * increment the page use counts until he is done with the page.
209 int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
212 struct inode *inode = file->f_dentry->d_inode;
215 if ( !Page_Uptodate(page) ) {
216 status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
217 if (status == PAGE_SIZE ) {
218 SetPageUptodate(page);
223 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
228 status = obdfs_writepage(file->f_dentry, page);
232 if ( status != PAGE_SIZE )
242 void report_inode(struct page * page) {
243 struct inode *inode = (struct inode *)0;
244 int offset = (int)&inode->i_data;
245 inode = (struct inode *)( (char *)page->mapping - offset);
246 if ( inode->i_sb->s_magic == 0x4711 )
247 printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
251 return an up to date page:
252 - if locked is true then is returned locked
253 - if create is true the corresponding disk blocks are created
254 - page is held, i.e. caller must release the page
258 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
260 struct page *page_cache;
267 offset = offset & PAGE_CACHE_MASK;
268 CDEBUG(D_INODE, "\n");
271 page_cache = page_cache_alloc();
274 CDEBUG(D_INODE, "page_cache %p\n", page_cache);
276 hash = page_hash(&inode->i_data, offset);
277 page = grab_cache_page(&inode->i_data, offset);
279 PDEBUG(page, "GETPAGE: got page - before reading\n");
280 /* now check if the data in the page is up to date */
281 if ( Page_Uptodate(page)) {
288 /* it's not: read it */
290 printk("get_page_map says no dice ...\n");
294 rc = iops(inode)->o_brw(READ, iid(inode), inode, page, create);
295 if ( rc != PAGE_SIZE ) {
303 SetPageUptodate(page);
304 PDEBUG(page,"GETPAGE - after reading");