Changeset 3233adb in mainline for uspace/srv/vfs/vfs_pager.c


Ignore:
Timestamp:
2016-09-02T17:43:06Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2c2d54a, d078c9b9
Parents:
b1956e3
Message:

Implement simple file pager for private mappings

The pager is extremely simple and can be used to create private mappings
of open files. Changes made via different mappings are not coherent and
are not written back to the underlying file. The pager does not cache
any pages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_pager.c

    rb1956e3 r3233adb  
    3838#include "vfs.h"
    3939#include <async.h>
     40#include <fibril_synch.h>
    4041#include <errno.h>
     42#include <as.h>
    4143
    4244void vfs_page_in(ipc_callid_t rid, ipc_call_t *request)
    4345{
    44         async_answer_0(rid, ENOTSUP);
     46        aoff64_t offset = IPC_GET_ARG1(*request);
     47        size_t page_size = IPC_GET_ARG2(*request);
     48        int fd = IPC_GET_ARG3(*request);
     49        void *page;
     50        int rc;
     51
     52        vfs_file_t *file = vfs_file_get(fd);
     53        if (!file) {
     54                async_answer_0(rid, ENOENT);
     55                return;
     56        }
     57
     58        page = as_area_create(AS_AREA_ANY, page_size,
     59            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
     60            AS_AREA_UNPAGED);
     61
     62        if (page == AS_MAP_FAILED) {
     63                vfs_file_put(file);
     64                async_answer_0(rid, ENOMEM);
     65                return;
     66        }
     67
     68        rdwr_io_chunk_t chunk = {
     69                .buffer = page,
     70                .size = page_size
     71        };
     72
     73        fibril_mutex_lock(&file->lock);
     74        file->pos = offset;
     75        fibril_mutex_unlock(&file->lock);
     76
     77        size_t total = 0;
     78        do {
     79                rc = vfs_rdwr_internal(fd, true, &chunk);
     80                if (rc != EOK)
     81                        break;
     82                if (chunk.size == 0)
     83                        break;
     84                total += chunk.size;
     85                chunk.buffer += chunk.size;
     86                chunk.size = page_size - total;
     87        } while (total < page_size);
     88
     89        vfs_file_put(file);
     90
     91        async_answer_1(rid, rc, (sysarg_t) page);
     92
     93        /*
     94         * FIXME:
     95         * This is just for now until we implement proper page cache
     96         * management.  Not keeping the pages around in a cache results in
     97         * inherently non-coherent private mappings.
     98         */
     99        as_area_destroy(page);
    45100}
    46101
Note: See TracChangeset for help on using the changeset viewer.