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 */
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 file *file, struct page *page)
49 struct inode *inode = file->f_dentry->d_inode;
56 rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
57 if (rc == PAGE_SIZE ) {
58 SetPageUptodate(page);
62 if ( rc == PAGE_SIZE )
69 * This does the "real" work of the write. The generic routine has
70 * allocated the page, locked it, done all the page alignment stuff
71 * calculations etc. Now we should just copy the data from user
72 * space and write it back to the real medium..
74 * If the writer ends up delaying the write, the writer needs to
75 * increment the page use counts until he is done with the page.
77 int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
80 struct inode *inode = file->f_dentry->d_inode;
83 if ( !Page_Uptodate(page) ) {
84 status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
85 if (status == PAGE_SIZE ) {
86 SetPageUptodate(page);
91 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
97 status = obdfs_writepage(file, page);
101 if ( status != PAGE_SIZE )
110 /* returns the page unlocked, but with a reference */
111 int obdfs_writepage(struct file *file, struct page *page)
113 struct inode *inode = file->f_dentry->d_inode;
117 PDEBUG(page, "WRITEPAGE");
118 /* XXX flush stuff */
120 rc = iops(inode)->o_brw(WRITE, iid(inode), inode, page, 1);
122 SetPageUptodate(page);
123 PDEBUG(page,"WRITEPAGE");
128 void report_inode(struct page * page) {
129 struct inode *inode = (struct inode *)0;
130 int offset = (int)&inode->i_data;
131 inode = (struct inode *)( (char *)page->mapping - offset);
132 if ( inode->i_sb->s_magic == 0x4711 )
133 printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
137 return an up to date page:
138 - if locked is true then is returned locked
139 - if create is true the corresponding disk blocks are created
140 - page is held, i.e. caller must release the page
144 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
146 struct page *page_cache;
153 offset = offset & PAGE_CACHE_MASK;
154 CDEBUG(D_INODE, "\n");
157 page_cache = page_cache_alloc();
160 CDEBUG(D_INODE, "page_cache %p\n", page_cache);
162 hash = page_hash(&inode->i_data, offset);
164 CDEBUG(D_INODE, "Finding page\n");
167 page = __find_lock_page(&inode->i_data, offset, hash);
169 CDEBUG(D_INODE, "Page found freeing\n");
170 page_cache_free(page_cache);
173 if ( page->buffers ) {
174 PDEBUG(page, "GETPAGE: buffers bug\n");
178 if (add_to_page_cache_unique(page, &inode->i_data, offset, hash)) {
179 page_cache_release(page);
180 CDEBUG(D_INODE, "Someone raced: try again\n");
185 PDEBUG(page, "GETPAGE: got page - before reading\n");
186 /* now check if the data in the page is up to date */
187 if ( Page_Uptodate(page)) {
194 /* it's not: read it */
196 printk("get_page_map says no dice ...\n");
202 rc = iops(inode)->o_brw(READ, iid(inode), inode, page, create);
203 if ( rc != PAGE_SIZE ) {
211 SetPageUptodate(page);
212 PDEBUG(page,"GETPAGE - after reading");
218 struct file_operations obdfs_file_ops = {
219 NULL, /* lseek - default */
220 generic_file_read, /* read */
221 obdfs_file_write, /* write - bad */
222 obdfs_readdir, /* readdir */
223 NULL, /* poll - default */
226 NULL, /* no special open code */
228 NULL, /* no special release code */
231 NULL, /* check_media_change */
232 NULL /* revalidate */
235 struct inode_operations obdfs_inode_ops = {
236 &obdfs_file_ops, /* default directory file-ops */
237 obdfs_create, /* create */
238 obdfs_lookup, /* lookup */
239 obdfs_link, /* link */
240 obdfs_unlink, /* unlink */
241 obdfs_symlink, /* symlink */
242 obdfs_mkdir, /* mkdir */
243 obdfs_rmdir, /* rmdir */
244 obdfs_mknod, /* mknod */
245 obdfs_rename, /* rename */
247 NULL, /* follow_link */
248 NULL, /* get_block */
249 obdfs_readpage, /* readpage */
250 obdfs_writepage, /* writepage */
251 NULL, /* flushpage */
253 NULL, /* permission */
255 NULL /* revalidate */