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;
76 if ( !Page_Uptodate(page) ) {
77 status = sbi->osi_ops->o_brw(READ,
78 sbi->osi_conn_info.conn_id,
79 file->f_dentry->d_inode->i_ino,
81 if (status == PAGE_SIZE ) {
82 SetPageUptodate(page);
87 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
92 status = obdfs_writepage(file, page);
95 if ( status != PAGE_SIZE )
104 /* returns the page unlocked, but with a reference */
105 int obdfs_writepage(struct file *file, struct page *page)
107 struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
111 PDEBUG(page, "WRITEPAGE");
112 /* XXX flush stuff */
114 rc = sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id,
115 file->f_dentry->d_inode->i_ino, page, 1);
116 SetPageUptodate(page);
117 PDEBUG(page,"WRITEPAGE");
123 page is returned unlocked, with the up to date flag set,
124 and held, i.e. caller must do a page_put
126 struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
128 unsigned long new_page;
131 struct obdfs_sb_info *sbi;
132 struct super_block *sb = inode->i_sb;
136 sbi = sb->u.generic_sbp;
138 page = find_lock_page(inode, offset);
139 if (page && Page_Uptodate(page)) {
140 PDEBUG(page,"GETPAGE");
146 if (page && !Page_Uptodate(page) ) {
147 CDEBUG(D_INODE, "Page found but not up to date\n");
150 /* page_cache_alloc returns address of page */
151 new_page = page_cache_alloc();
155 /* corresponding struct page in the mmap */
156 hash = page_hash(inode, offset);
157 page = page_cache_entry(new_page);
158 PDEBUG(page, "GETPAGE");
159 if (!add_to_page_cache_unique(page, inode, offset, hash)) {
160 CDEBUG(D_INODE, "Page not found. Reading it.\n");
161 PDEBUG(page,"GETPAGE");
162 sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
163 inode->i_ino, page, create);
166 SetPageUptodate(page);
167 PDEBUG(page,"GETPAGE");
171 * We arrive here in the unlikely event that someone
172 * raced with us and added our page to the cache first.
174 CDEBUG(D_INODE, "Page not found. Someone raced us.\n");
175 PDEBUG(page,"GETPAGE");
181 struct file_operations obdfs_file_ops = {
182 NULL, /* lseek - default */
183 generic_file_read, /* read */
184 obdfs_file_write, /* write - bad */
185 obdfs_readdir, /* readdir */
186 NULL, /* poll - default */
189 NULL, /* no special open code */
191 NULL, /* no special release code */
194 NULL, /* check_media_change */
195 NULL /* revalidate */
198 struct inode_operations obdfs_inode_ops = {
199 &obdfs_file_ops, /* default directory file-ops */
200 obdfs_create, /* create */
201 obdfs_lookup, /* lookup */
202 obdfs_link, /* link */
203 obdfs_unlink, /* unlink */
204 obdfs_symlink, /* symlink */
205 obdfs_mkdir, /* mkdir */
206 obdfs_rmdir, /* rmdir */
207 obdfs_mknod, /* mknod */
208 obdfs_rename, /* rename */
210 NULL, /* follow_link */
211 NULL, /* get_block */
212 obdfs_readpage, /* readpage */
213 obdfs_writepage, /* writepage */
214 NULL, /* flushpage */
216 NULL, /* permission */
218 NULL /* revalidate */