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 <../obd/linux/obd_support.h>
32 #include <../obd/linux/obd_sim.h>
35 /* VFS super_block ops */
37 /* returns the page unlocked, but with a reference */
38 int obdfs_readpage(struct file *file, struct page *page)
40 struct obdfs_sb_info *sbi;
41 struct super_block *sb = file->f_dentry->d_inode->i_sb;
47 sbi = sb->u.generic_sbp;
49 rc = sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
50 file->f_dentry->d_inode->i_ino, page, 0);
51 if (rc == PAGE_SIZE ) {
52 SetPageUptodate(page);
56 if ( rc == PAGE_SIZE )
63 * This does the "real" work of the write. The generic routine has
64 * allocated the page, locked it, done all the page alignment stuff
65 * calculations etc. Now we should just copy the data from user
66 * space and write it back to the real medium..
68 * If the writer ends up delaying the write, the writer needs to
69 * increment the page use counts until he is done with the page.
71 int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
74 struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
77 if ( !Page_Uptodate(page) ) {
78 status = sbi->osi_ops->o_brw(READ,
79 sbi->osi_conn_info.conn_id,
80 file->f_dentry->d_inode->i_ino,
82 if (status == PAGE_SIZE ) {
83 SetPageUptodate(page);
88 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
93 status = obdfs_writepage(file, page);
97 if ( status != PAGE_SIZE )
106 /* returns the page unlocked, but with a reference */
107 int obdfs_writepage(struct file *file, struct page *page)
109 struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
113 PDEBUG(page, "WRITEPAGE");
114 /* XXX flush stuff */
116 rc = sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id,
117 file->f_dentry->d_inode->i_ino, page, 1);
118 SetPageUptodate(page);
119 PDEBUG(page,"WRITEPAGE");
125 page is returned unlocked, with the up to date flag set,
126 and held, i.e. caller must do a page_put
128 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
130 unsigned long new_page;
133 struct obdfs_sb_info *sbi;
134 struct super_block *sb = inode->i_sb;
138 sbi = sb->u.generic_sbp;
140 page = find_lock_page(inode, offset);
141 if (page && Page_Uptodate(page)) {
142 PDEBUG(page,"GETPAGE");
149 if (page && !Page_Uptodate(page) ) {
150 CDEBUG(D_INODE, "Page found but not up to date\n");
153 /* page_cache_alloc returns the VM address of page */
154 new_page = page_cache_alloc();
158 /* corresponding struct page in the mmap */
159 hash = page_hash(inode, offset);
160 page = page_cache_entry(new_page);
161 if (!add_to_page_cache_unique(page, inode, offset, hash)) {
162 CDEBUG(D_INODE, "Page not found. Reading it.\n");
163 PDEBUG(page,"GETPAGE - before reading");
164 sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
165 inode->i_ino, page, create);
168 SetPageUptodate(page);
169 PDEBUG(page,"GETPAGE - after reading");
174 * We arrive here in the unlikely event that someone
175 * raced with us and added our page to the cache first.
177 CDEBUG(D_INODE, "Page not found. Someone raced us.\n");
178 PDEBUG(page,"GETPAGE");
185 struct file_operations obdfs_file_ops = {
186 NULL, /* lseek - default */
187 generic_file_read, /* read */
188 obdfs_file_write, /* write - bad */
189 obdfs_readdir, /* readdir */
190 NULL, /* poll - default */
193 NULL, /* no special open code */
195 NULL, /* no special release code */
198 NULL, /* check_media_change */
199 NULL /* revalidate */
202 struct inode_operations obdfs_inode_ops = {
203 &obdfs_file_ops, /* default directory file-ops */
204 obdfs_create, /* create */
205 obdfs_lookup, /* lookup */
206 obdfs_link, /* link */
207 obdfs_unlink, /* unlink */
208 obdfs_symlink, /* symlink */
209 obdfs_mkdir, /* mkdir */
210 obdfs_rmdir, /* rmdir */
211 obdfs_mknod, /* mknod */
212 obdfs_rename, /* rename */
214 NULL, /* follow_link */
215 NULL, /* get_block */
216 obdfs_readpage, /* readpage */
217 obdfs_writepage, /* writepage */
218 NULL, /* flushpage */
220 NULL, /* permission */
222 NULL /* revalidate */