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_sim.h>
33 #include <linux/obdfs.h>
37 /* VFS super_block ops */
39 /* returns the page unlocked, but with a reference */
40 int obdfs_readpage(struct file *file, struct page *page)
42 struct inode *inode = file->f_dentry->d_inode;
49 rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
50 if (rc == PAGE_SIZE ) {
51 SetPageUptodate(page);
55 if ( rc == PAGE_SIZE )
62 * This does the "real" work of the write. The generic routine has
63 * allocated the page, locked it, done all the page alignment stuff
64 * calculations etc. Now we should just copy the data from user
65 * space and write it back to the real medium..
67 * If the writer ends up delaying the write, the writer needs to
68 * increment the page use counts until he is done with the page.
70 int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
73 struct inode *inode = file->f_dentry->d_inode;
76 if ( !Page_Uptodate(page) ) {
77 status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
78 if (status == PAGE_SIZE ) {
79 SetPageUptodate(page);
84 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
90 status = obdfs_writepage(file, page);
94 if ( status != PAGE_SIZE )
103 /* returns the page unlocked, but with a reference */
104 int obdfs_writepage(struct file *file, struct page *page)
106 struct inode *inode = file->f_dentry->d_inode;
110 PDEBUG(page, "WRITEPAGE");
111 /* XXX flush stuff */
113 rc = iops(inode)->o_brw(WRITE, iid(inode), inode, page, 1);
115 SetPageUptodate(page);
116 PDEBUG(page,"WRITEPAGE");
121 void report_inode(struct page * page) {
122 struct inode *inode = (struct inode *)0;
123 int offset = (int)&inode->i_data;
124 inode = (struct inode *)( (char *)page->mapping - offset);
125 if ( inode->i_sb->s_magic == 0x4711 )
126 printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
130 return an up to date page:
131 - if locked is true then is returned locked
132 - if create is true the corresponding disk blocks are created
133 - page is held, i.e. caller must release the page
137 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
139 struct page *page_cache;
146 offset = offset & PAGE_CACHE_MASK;
147 CDEBUG(D_INODE, "\n");
150 page_cache = page_cache_alloc();
153 CDEBUG(D_INODE, "page_cache %p\n", page_cache);
155 hash = page_hash(&inode->i_data, offset);
157 CDEBUG(D_INODE, "Finding page\n");
160 page = __find_lock_page(&inode->i_data, offset, hash);
162 CDEBUG(D_INODE, "Page found freeing\n");
163 page_cache_free(page_cache);
166 if ( page->buffers ) {
167 PDEBUG(page, "GETPAGE: buffers bug\n");
171 if (add_to_page_cache_unique(page, &inode->i_data, offset, hash)) {
172 page_cache_release(page);
173 CDEBUG(D_INODE, "Someone raced: try again\n");
178 PDEBUG(page, "GETPAGE: got page - before reading\n");
179 /* now check if the data in the page is up to date */
180 if ( Page_Uptodate(page)) {
187 /* it's not: read it */
189 printk("get_page_map says no dice ...\n");
195 rc = iops(inode)->o_brw(READ, iid(inode), inode, page, create);
196 if ( rc != PAGE_SIZE ) {
204 SetPageUptodate(page);
205 PDEBUG(page,"GETPAGE - after reading");
211 struct file_operations obdfs_file_ops = {
212 NULL, /* lseek - default */
213 generic_file_read, /* read */
214 obdfs_file_write, /* write - bad */
215 obdfs_readdir, /* readdir */
216 NULL, /* poll - default */
219 NULL, /* no special open code */
221 NULL, /* no special release code */
224 NULL, /* check_media_change */
225 NULL /* revalidate */
228 struct inode_operations obdfs_inode_ops = {
229 &obdfs_file_ops, /* default directory file-ops */
230 obdfs_create, /* create */
231 obdfs_lookup, /* lookup */
232 obdfs_link, /* link */
233 obdfs_unlink, /* unlink */
234 obdfs_symlink, /* symlink */
235 obdfs_mkdir, /* mkdir */
236 obdfs_rmdir, /* rmdir */
237 obdfs_mknod, /* mknod */
238 obdfs_rename, /* rename */
240 NULL, /* follow_link */
241 NULL, /* get_block */
242 obdfs_readpage, /* readpage */
243 obdfs_writepage, /* writepage */
244 NULL, /* flushpage */
246 NULL, /* permission */
248 NULL /* revalidate */