PG_BUFFER set appropriately
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 5 Feb 2014 06:34:33 +0000 (22:34 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sun, 9 Feb 2014 07:22:59 +0000 (23:22 -0800)
Code that needs to use buffer heads sets the flag, not the page map.

kern/src/blockdev.c
kern/src/ext2fs.c
kern/src/kfs.c
kern/src/pagemap.c

index 1f12299..90b90de 100644 (file)
@@ -191,7 +191,7 @@ struct buffer_head *bdev_get_buffer(struct block_device *bdev,
        if (error)
                panic("Failed to load page! (%d)", error);
        my_buf = page2kva(page) + blk_offset;
-       assert(atomic_read(&page->pg_flags) & PG_BUFFER);
+       atomic_or(&page->pg_flags, PG_BUFFER);
 retry:
        bh = (struct buffer_head*)page->pg_private;
        prev = 0;
index 78e66bf..1a0b7bb 100644 (file)
@@ -704,7 +704,7 @@ int ext2_readpage(struct page_map *pm, struct page *page)
        struct block_request *breq;
        void *eobh;
 
-       assert(atomic_read(&page->pg_flags) & PG_BUFFER);
+       atomic_or(&page->pg_flags, PG_BUFFER);
        retval = ext2_mappage(pm, page);
        if (retval)
                return retval;
index a3d1e12..e36175f 100644 (file)
@@ -139,6 +139,7 @@ int kfs_readpage(struct page_map *pm, struct page *page)
        struct buffer_head *bh = kmem_cache_alloc(bh_kcache, 0);
        if (!bh)
                return -1;                      /* untested, un-thought-through */
+       atomic_or(&page->pg_flags, PG_BUFFER);
        /* KFS does a 1:1 BH to page mapping */
        bh->bh_page = page;                                                             /* weak ref */
        bh->bh_buffer = page2kva(page);
index 38dc45d..30d13c2 100644 (file)
@@ -200,11 +200,8 @@ int pm_load_page(struct page_map *pm, unsigned long index, struct page **pp)
                if (kpage_alloc(&page))
                        return -ENOMEM;
                /* important that UP_TO_DATE is not set.  once we put it in the PM,
-                * others can find it, and we still need to fill it.
-                *
-                * TODO: seems shitty: setting PG_BUF since we know it'll be used for IO
-                * later... */
-               atomic_set(&page->pg_flags, PG_LOCKED | PG_BUFFER | PG_PAGEMAP);
+                * others can find it, and we still need to fill it. */
+               atomic_set(&page->pg_flags, PG_LOCKED | PG_PAGEMAP);
                page->pg_sem.nr_signals = 0;    /* preemptively locking */
                error = pm_insert_page(pm, index, page);
                switch (error) {
@@ -240,7 +237,6 @@ int pm_load_page(struct page_map *pm, unsigned long index, struct page **pp)
        }
        /* fall through */
 load_locked_page:
-       /* TODO: this is slightly shitty: readpage sets UPTODATE */
        error = pm->pm_op->readpage(pm, page);
        assert(!error);
        assert(atomic_read(&page->pg_flags) & PG_UPTODATE);