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);
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)
75 bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
77 CDEBUG(D_INODE, "page offset %ld, bytes %ld, offset %ld, page addr %lx, writing: %s, beg of page %s\n", page->offset, bytes, offset, page_address(page), ((char *) page_address(page)) + offset, (char *)page_address(page));
80 status = obdfs_writepage(file, page);
83 if ( status != PAGE_SIZE )
92 /* returns the page unlocked, but with a reference */
93 int obdfs_writepage(struct file *file, struct page *page)
95 struct obdfs_sb_info *sbi;
96 struct super_block *sb = file->f_dentry->d_inode->i_sb;
101 /* XXX flush stuff */
102 sbi = sb->u.generic_sbp;
104 rc = sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id,
105 file->f_dentry->d_inode->i_ino, page);
106 SetPageUptodate(page);
113 page is returned unlocked, with the up to date flag set,
114 and held, i.e. caller must do a page_put
116 struct page *obdfs_getpage(struct inode *inode, unsigned long offset)
118 unsigned long new_page;
121 struct obdfs_sb_info *sbi;
122 struct super_block *sb = inode->i_sb;
126 sbi = sb->u.generic_sbp;
128 page = find_get_page(inode, offset);
129 if (page && Page_Uptodate(page)) {
134 if (page && !Page_Uptodate(page) ) {
135 CDEBUG(D_INODE, "Page found but not up to date\n");
138 /* page_cache_alloc returns address of page */
139 new_page = page_cache_alloc();
143 /* corresponding struct page in the mmap */
144 hash = page_hash(inode, offset);
145 page = page_cache_entry(new_page);
146 if (!add_to_page_cache_unique(page, inode, offset, hash)) {
147 CDEBUG(D_INODE, "Page not found. Reading it.\n");
149 sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
152 SetPageUptodate(page);
156 * We arrive here in the unlikely event that someone
157 * raced with us and added our page to the cache first.
159 CDEBUG(D_INODE, "Page not found. Someone raced us.\n");
166 struct file_operations obdfs_file_operations = {
167 NULL, /* lseek - default */
168 generic_file_read, /* read */
169 obdfs_file_write, /* write - bad */
170 obdfs_readdir, /* readdir */
171 NULL, /* poll - default */
174 NULL, /* no special open code */
176 NULL, /* no special release code */
179 NULL, /* check_media_change */
180 NULL /* revalidate */
183 struct inode_operations obdfs_inode_ops = {
184 &obdfs_file_operations, /* default directory file-ops */
186 obdfs_lookup, /* lookup */
195 NULL, /* follow_link */
196 NULL, /* get_block */
197 obdfs_readpage, /* readpage */
198 obdfs_writepage, /* writepage */
199 NULL, /* flushpage */
201 NULL, /* permission */
203 NULL /* revalidate */