source: mainline/uspace/srv/vfs/vfs_pager.c@ 3c5b86c

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3c5b86c was 3233adb, checked in by Jakub Jermar <jakub@…>, 9 years ago

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.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2016 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup fs
30 * @{
31 */
32
33/**
34 * @file vfs_pager.c
35 * @brief VFS pager operations.
36 */
37
38#include "vfs.h"
39#include <async.h>
40#include <fibril_synch.h>
41#include <errno.h>
42#include <as.h>
43
44void vfs_page_in(ipc_callid_t rid, ipc_call_t *request)
45{
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);
100}
101
102/**
103 * @}
104 */
Note: See TracBrowser for help on using the repository browser.