#include <linux/pagemap.h>
#include <linux/smp_lock.h>
-#include <../obd/linux/obd_support.h>
-#include <../obd/linux/obd_sim.h>
-#include <obdfs.h>
+#include <linux/obd_support.h>
+#include <linux/obd_sim.h>
+#include <linux/obdfs.h>
+
+int console_loglevel;
/* VFS super_block ops */
+#if 0
+int obdfs_brw(struct inode *dir, int rw, struct page *page, int create)
+{
+ return iops(dir)->o_brw(rw, iid(dir), dir, page, create);
+}
+#endif
+
/* returns the page unlocked, but with a reference */
-int obdfs_readpage(struct file *file, struct page *page)
+int obdfs_readpage(struct dentry *dentry, struct page *page)
{
- struct obdfs_sb_info *sbi;
- struct super_block *sb = file->f_dentry->d_inode->i_sb;
+ struct inode *inode = dentry->d_inode;
int rc;
ENTRY;
-
/* XXX flush stuff */
- sbi = sb->u.generic_sbp;
PDEBUG(page, "READ");
- rc = sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
- file->f_dentry->d_inode->i_ino, page, 0);
+ rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
if (rc == PAGE_SIZE ) {
SetPageUptodate(page);
UnlockPage(page);
}
+/* returns the page unlocked, but with a reference */
+static int obdfs_writepage(struct dentry *dentry, struct page *page)
+{
+ struct inode *inode = dentry->d_inode;
+ int rc;
+
+ ENTRY;
+ PDEBUG(page, "WRITEPAGE");
+ /* XXX flush stuff */
+
+ rc = iops(inode)->o_brw(WRITE, iid(inode), inode, page, 1);
+
+ SetPageUptodate(page);
+ PDEBUG(page,"WRITEPAGE");
+ return rc;
+}
+
/*
* This does the "real" work of the write. The generic routine has
* allocated the page, locked it, done all the page alignment stuff
int obdfs_write_one_page(struct file *file, struct page *page, unsigned long offset, unsigned long bytes, const char * buf)
{
long status;
- struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
+ struct inode *inode = file->f_dentry->d_inode;
ENTRY;
if ( !Page_Uptodate(page) ) {
- status = sbi->osi_ops->o_brw(READ,
- sbi->osi_conn_info.conn_id,
- file->f_dentry->d_inode->i_ino,
- page, 1);
+ status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
if (status == PAGE_SIZE ) {
SetPageUptodate(page);
} else {
status = -EFAULT;
if (bytes) {
+
lock_kernel();
- status = obdfs_writepage(file, page);
+ status = obdfs_writepage(file->f_dentry, page);
unlock_kernel();
}
EXIT;
-/* returns the page unlocked, but with a reference */
-int obdfs_writepage(struct file *file, struct page *page)
-{
- struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
- int rc;
-
- ENTRY;
- PDEBUG(page, "WRITEPAGE");
- /* XXX flush stuff */
- rc = sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id,
- file->f_dentry->d_inode->i_ino, page, 1);
- SetPageUptodate(page);
- PDEBUG(page,"WRITEPAGE");
- return rc;
+void report_inode(struct page * page) {
+ struct inode *inode = (struct inode *)0;
+ int offset = (int)&inode->i_data;
+ inode = (struct inode *)( (char *)page->mapping - offset);
+ if ( inode->i_sb->s_magic == 0x4711 )
+ printk("----> ino %ld , dev %d\n", inode->i_ino, inode->i_dev);
}
-
/*
- page is returned unlocked, with the up to date flag set,
- and held, i.e. caller must do a page_put
+ return an up to date page:
+ - if locked is true then is returned locked
+ - if create is true the corresponding disk blocks are created
+ - page is held, i.e. caller must release the page
+
+ modeled on NFS code.
*/
struct page *obdfs_getpage(struct inode *inode, unsigned long offset, int create, int locked)
{
- unsigned long new_page;
+ struct page *page_cache;
struct page ** hash;
- struct page * page;
- struct obdfs_sb_info *sbi;
- struct super_block *sb = inode->i_sb;
+ struct page * page;
+ int rc;
ENTRY;
- sbi = sb->u.generic_sbp;
+ offset = offset & PAGE_CACHE_MASK;
+ CDEBUG(D_INODE, "\n");
- page = find_lock_page(inode, offset);
- if (page && Page_Uptodate(page)) {
- PDEBUG(page,"GETPAGE");
+ page = NULL;
+ page_cache = page_cache_alloc();
+ if ( ! page_cache )
+ return NULL;
+ CDEBUG(D_INODE, "page_cache %p\n", page_cache);
+
+ hash = page_hash(&inode->i_data, offset);
+ repeat:
+ CDEBUG(D_INODE, "Finding page\n");
+ IDEBUG(inode);
+
+ page = __find_lock_page(&inode->i_data, offset, hash);
+ if ( page ) {
+ CDEBUG(D_INODE, "Page found freeing\n");
+ page_cache_free(page_cache);
+ } else {
+ page = page_cache;
+ if ( page->buffers ) {
+ PDEBUG(page, "GETPAGE: buffers bug\n");
+ UnlockPage(page);
+ return NULL;
+ }
+ if (add_to_page_cache_unique(page, &inode->i_data, offset, hash)) {
+ page_cache_release(page);
+ CDEBUG(D_INODE, "Someone raced: try again\n");
+ goto repeat;
+ }
+ }
+
+ PDEBUG(page, "GETPAGE: got page - before reading\n");
+ /* now check if the data in the page is up to date */
+ if ( Page_Uptodate(page)) {
if (!locked)
UnlockPage(page);
EXIT;
return page;
}
-
- if (page && !Page_Uptodate(page) ) {
- CDEBUG(D_INODE, "Page found but not up to date\n");
- }
- /* page_cache_alloc returns the VM address of page */
- new_page = page_cache_alloc();
- if (!new_page)
- return NULL;
-
- /* corresponding struct page in the mmap */
- hash = page_hash(inode, offset);
- page = page_cache_entry(new_page);
- if (!add_to_page_cache_unique(page, inode, offset, hash)) {
- CDEBUG(D_INODE, "Page not found. Reading it.\n");
- PDEBUG(page,"GETPAGE - before reading");
- sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
- inode->i_ino, page, create);
- if ( !locked )
- UnlockPage(page);
- SetPageUptodate(page);
- PDEBUG(page,"GETPAGE - after reading");
- EXIT;
+ /* it's not: read it */
+ if (! page) {
+ printk("get_page_map says no dice ...\n");
+ return 0;
+ }
+
+
+
+ rc = iops(inode)->o_brw(READ, iid(inode), inode, page, create);
+ if ( rc != PAGE_SIZE ) {
+ SetPageError(page);
+ UnlockPage(page);
return page;
}
- /*
- * We arrive here in the unlikely event that someone
- * raced with us and added our page to the cache first.
- */
- CDEBUG(D_INODE, "Page not found. Someone raced us.\n");
- PDEBUG(page,"GETPAGE");
+
+ if ( !locked )
+ UnlockPage(page);
+ SetPageUptodate(page);
+ PDEBUG(page,"GETPAGE - after reading");
EXIT;
return page;
}
-
struct file_operations obdfs_file_ops = {
NULL, /* lseek - default */
generic_file_read, /* read */
- obdfs_file_write, /* write - bad */
+ obdfs_file_write, /* write - bad */
obdfs_readdir, /* readdir */
NULL, /* poll - default */
NULL, /* ioctl */