#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 */
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);
+ file->f_dentry->d_inode, page, 0);
if (rc == PAGE_SIZE ) {
SetPageUptodate(page);
UnlockPage(page);
long status;
struct obdfs_sb_info *sbi = file->f_dentry->d_inode->i_sb->u.generic_sbp;
+ 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,
+ file->f_dentry->d_inode,
page, 1);
if (status == PAGE_SIZE ) {
SetPageUptodate(page);
status = -EFAULT;
if (bytes) {
+
lock_kernel();
status = obdfs_writepage(file, page);
unlock_kernel();
}
+ EXIT;
if ( status != PAGE_SIZE )
return status;
else
/* 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);
+ file->f_dentry->d_inode, 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 page * page;
struct obdfs_sb_info *sbi;
struct super_block *sb = inode->i_sb;
+ int rc;
ENTRY;
+ offset = offset & PAGE_CACHE_MASK;
sbi = sb->u.generic_sbp;
+ 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 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);
- PDEBUG(page, "GETPAGE");
- if (!add_to_page_cache_unique(page, inode, offset, hash)) {
- CDEBUG(D_INODE, "Page not found. Reading it.\n");
- PDEBUG(page,"GETPAGE");
- 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");
+ /* it's not: read it */
+ if (! page) {
+ printk("get_page_map says no dice ...\n");
+ return 0;
+ }
+
+
+
+ rc = sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
+ 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 */