Syscall debugging helper
[akaros.git] / kern / src / pagemap.c
index 38dc45d..4a28841 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);
@@ -251,6 +247,21 @@ load_locked_page:
        return 0;
 }
 
+int pm_load_page_nowait(struct page_map *pm, unsigned long index,
+                        struct page **pp)
+{
+       struct page *page = pm_find_page(pm, index);
+       if (!page)
+               return -EAGAIN;
+       if (!(atomic_read(&page->pg_flags) & PG_UPTODATE)) {
+               /* TODO: could have a read_nowait pm_op */
+               pm_put_page(page);
+               return -EAGAIN;
+       }
+       *pp = page;
+       return 0;
+}
+
 static bool vmr_has_page_idx(struct vm_region *vmr, unsigned long pg_idx)
 {
        unsigned long nr_pgs = (vmr->vm_end - vmr->vm_base) >> PGSHIFT;