#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);
+ PDEBUG(page, "READ");
+ rc = iops(inode)->o_brw(READ, iid(inode),inode, page, 0);
if (rc == PAGE_SIZE ) {
SetPageUptodate(page);
UnlockPage(page);
}
- PDEBUG(page, READ);
+ PDEBUG(page, "READ");
if ( rc == PAGE_SIZE )
rc = 0;
return rc;
}
+/* 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 inode *inode = file->f_dentry->d_inode;
+
+ ENTRY;
+ if ( !Page_Uptodate(page) ) {
+ status = iops(inode)->o_brw(READ, iid(inode), inode, page, 1);
+ if (status == PAGE_SIZE ) {
+ SetPageUptodate(page);
+ } else {
+ return status;
+ }
+ }
bytes -= copy_from_user((u8*)page_address(page) + offset, buf, bytes);
status = -EFAULT;
- 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));
+
if (bytes) {
+
lock_kernel();
- status = obdfs_writepage(file, page);
+ status = obdfs_writepage(file->f_dentry, page);
unlock_kernel();
}
+ EXIT;
if ( status != PAGE_SIZE )
return status;
else
-/* returns the page unlocked, but with a reference */
-int obdfs_writepage(struct file *file, struct page *page)
-{
- struct obdfs_sb_info *sbi;
- struct super_block *sb = file->f_dentry->d_inode->i_sb;
- int rc;
-
- ENTRY;
- PDEBUG(page,WRITE);
- /* XXX flush stuff */
- sbi = sb->u.generic_sbp;
- rc = sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id,
- file->f_dentry->d_inode->i_ino, page);
- SetPageUptodate(page);
- PDEBUG(page,WRITE);
- 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)
+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_get_page(inode, offset);
- if (page && Page_Uptodate(page)) {
- PDEBUG(page,READ);
+ 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);
- if (!add_to_page_cache_unique(page, inode, offset, hash)) {
- CDEBUG(D_INODE, "Page not found. Reading it.\n");
- PDEBUG(page,READ);
- sbi->osi_ops->o_brw(READ, sbi->osi_conn_info.conn_id,
- inode->i_ino, page);
+ /* 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);
- SetPageUptodate(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,READ);
+
+ if ( !locked )
+ UnlockPage(page);
+ SetPageUptodate(page);
+ PDEBUG(page,"GETPAGE - after reading");
+ EXIT;
return page;
}
-
-struct file_operations obdfs_file_operations = {
+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 */
};
struct inode_operations obdfs_inode_ops = {
- &obdfs_file_operations, /* default directory file-ops */
- NULL, /* create */
+ &obdfs_file_ops, /* default directory file-ops */
+ obdfs_create, /* create */
obdfs_lookup, /* lookup */
- NULL, /* link */
- NULL, /* unlink */
- NULL, /* symlink */
- NULL, /* mkdir */
- NULL, /* rmdir */
- NULL, /* mknod */
- NULL, /* rename */
+ obdfs_link, /* link */
+ obdfs_unlink, /* unlink */
+ obdfs_symlink, /* symlink */
+ obdfs_mkdir, /* mkdir */
+ obdfs_rmdir, /* rmdir */
+ obdfs_mknod, /* mknod */
+ obdfs_rename, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* get_block */