Debug code to see remote kmsgs
[akaros.git] / kern / src / kfs.c
index f40149d..c5e876c 100644 (file)
@@ -119,11 +119,11 @@ struct fs_type kfs_fs_type = {"KFS", 0, kfs_get_sb, kfs_kill_sb, {0, 0},
 /* Fills page with its contents from its backing store file.  Note that we do
  * the zero padding here, instead of higher in the VFS.  Might change in the
  * future. */
-int kfs_readpage(struct file *file, struct page *page)
+int kfs_readpage(struct page_map *pm, struct page *page)
 {
        size_t pg_idx_byte = page->pg_index * PGSIZE;
        struct kfs_i_info *k_i_info = (struct kfs_i_info*)
-                                     file->f_dentry->d_inode->i_fs_info;
+                                     pm->pm_host->i_fs_info;
        uintptr_t begin = (size_t)k_i_info->filestart + pg_idx_byte;
        /* If we're beyond the initial start point, we just need a zero page.  This
         * is for a hole or for extending a file (even though it won't be saved).
@@ -136,11 +136,22 @@ int kfs_readpage(struct file *file, struct page *page)
                memcpy(page2kva(page), (void*)begin, copy_amt);
                memset(page2kva(page) + copy_amt, 0, PGSIZE - copy_amt);
        }
+       struct buffer_head *bh = kmem_cache_alloc(bh_kcache, 0);
+       if (!bh)
+               return -1;                      /* untested, un-thought-through */
+       /* KFS does a 1:1 BH to page mapping */
+       bh->bh_page = page;                                                             /* weak ref */
+       bh->bh_buffer = page2kva(page);
+       bh->bh_flags = 0;                                                               /* whatever... */
+       bh->bh_next = 0;                                                                /* only one BH needed */
+       bh->bh_bdev = pm->pm_host->i_sb->s_bdev;                /* uncounted */
+       bh->bh_sector = page->pg_index;
+       bh->bh_nr_sector = 1;                                                   /* sector size = PGSIZE */
+       page->pg_private = bh;
        /* This is supposed to be done in the IO system when the operation is
         * complete.  Since we aren't doing a real IO request, and it is already
         * done, we can do it here. */
        page->pg_flags |= PG_UPTODATE;
-       unlock_page(page);
        return 0;
 }
 
@@ -364,6 +375,7 @@ int kfs_unlink(struct inode *dir, struct dentry *dentry)
        /* Stop tracking our child */
        TAILQ_REMOVE(&((struct kfs_i_info*)dir->i_fs_info)->children, dentry,
                     d_subdirs_link);
+       kref_put(&dentry->d_kref);                              /* unpin the dentry, KFS-style */
        return 0;
 }
 
@@ -422,6 +434,8 @@ int kfs_rmdir(struct inode *dir, struct dentry *dentry)
        }
        if (!empty)
                return -ENOTEMPTY;
+       kref_put(&dentry->d_kref);                              /* unpin the dentry, KFS-style */
+       printk("DENTRY %s REFCNT %d\n", dentry->d_name.name, kref_refcnt(&dentry->d_kref));
        return 0;
 }
 
@@ -777,7 +791,7 @@ static int __add_kfs_entry(struct dentry *parent, char *path,
        size_t dirname_sz;                              /* not counting the \0 */
        struct dentry *dentry = 0;
        struct inode *inode;
-       int err;
+       int err, retval;
        char *symname, old_end;                 /* for symlink manipulation */
 
        if (first_slash) {
@@ -799,7 +813,9 @@ static int __add_kfs_entry(struct dentry *parent, char *path,
                        printk("Missing dir in CPIO archive or something, aborting.\n");
                        return -1;
                }
-               return __add_kfs_entry(dentry, first_slash + 1, c_bhdr);
+               retval = __add_kfs_entry(dentry, first_slash + 1, c_bhdr);
+               kref_put(&dentry->d_kref);
+               return retval;
        } else {
                /* no directories left in the path.  add the 'file' to the dentry */
                printd("Adding file/dir %s to dentry %s (start: %p, size %d)\n", path,
@@ -837,6 +853,7 @@ static int __add_kfs_entry(struct dentry *parent, char *path,
                        default:
                                printk("Unknown file type %d in the CPIO!",
                                       c_bhdr->c_mode & CPIO_FILE_MASK);
+                               kref_put(&dentry->d_kref);
                                return -1;
                }
                inode = dentry->d_inode;
@@ -851,6 +868,7 @@ static int __add_kfs_entry(struct dentry *parent, char *path,
                inode->i_bdev = 0;                                              /* assuming blockdev? */
                inode->i_socket = FALSE;
                inode->i_blocks = c_bhdr->c_filesize;   /* blocksize == 1 */
+               kref_put(&dentry->d_kref);
        }
        return 0;
 }
@@ -895,7 +913,7 @@ void parse_cpio_entries(struct super_block *sb, void *cpio_b)
                }
                c_bhdr->c_filename = (char*)c_hdr + sizeof(*c_hdr);
                namesize = cpio_strntol(buf, c_hdr->c_namesize, 8);
-               printd("Namesize: %d\n", size);
+               printd("Namesize: %d\n", namesize);
                if (!strcmp(c_bhdr->c_filename, "TRAILER!!!"))
                        break;
                c_bhdr->c_ino = cpio_strntol(buf, c_hdr->c_ino, 8);