Commit 03aa7ebd authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ef0de564
......@@ -920,7 +920,7 @@ out:
/* PyBigFile: mmap methods.
* They redirect op X to type.blkmmapper.X without going to Python level */
static void*
static int
pybigfile_mmap_setup_read(VMA *vma, BigFile *file0, blk_t blk, size_t blklen)
{
PyBigFile *file = container_of(file0, PyBigFile, file);
......
......@@ -27,7 +27,7 @@
#include "bigfile/_file_zodb.h"
#include <ccan/container_of/container_of.h>
static void* zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
static int zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
_ZBigFile* _zfile = container_of(file, _ZBigFile, __pyx_base.file);
wcfs::FileH fileh = _zfile->wfileh;
......@@ -38,10 +38,13 @@ static void* zfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t bl
panic("BUG: zfile_mmap_setup_read: ZBigFile.fileh_open did not set .wfileh");
tie(mmap, err) = fileh->mmap(blk, blklen, vma);
if (err != nil)
panic(v(err)); // XXX
if (err != nil) {
// XXX no way to return error details to virtmem
log::Errorf("%s: mmap_setup_read #[%d +%d): %s", v(fileh), blk, blklen, v(err));
return -1;
}
return (void*)vma->addr_start; // XXX (?) kill - we set vma->addr_*
return 0;
}
static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
......
......@@ -1161,15 +1161,18 @@ int mmapfile_storeblk(BigFile *file, blk_t blk, const void *buf) {
return 0;
}
void *mmapfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
int mmapfile_mmap_setup_read(VMA *vma, BigFile *file, blk_t blk, size_t blklen) {
BigFileMMap *f = upcast(BigFileMMap*, file);
size_t len = blklen*f->blksize;
void *addr;
addr = mmap(NULL, blklen*f->blksize, PROT_READ, MAP_SHARED, f->fd, blk*f->blksize);
addr = mmap(NULL, len, PROT_READ, MAP_SHARED, f->fd, blk*f->blksize);
if (addr == MAP_FAILED)
addr = NULL;
return -1;
return addr;
vma->addr_start = (uintptr_t)addr;
vma->addr_stop = vma->addr_start + len;
return 0;
}
int mmapfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
......
......@@ -240,7 +240,6 @@ void fileh_close(BigFileH *fileh)
int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen)
{
void *addr;
size_t len = pglen * fileh->ramh->ram->pagesize;
BigFile *file = fileh->file;
const bigfile_ops *fops = file->file_ops;
......@@ -261,19 +260,21 @@ int fileh_mmap(VMA *vma, BigFileH *fileh, pgoff_t pgoffset, pgoff_t pglen)
goto fail;
if (fileh->mmap_overlay) {
/* wcfs: mmap(base, READ) */
/* wcfs: mmap(base, READ)
* vma->addr_{start,stop} are initialized by mmap_setup_read */
TODO (file->blksize != fileh->ramh->ram->pagesize);
addr = fops->mmap_setup_read(vma, file, pgoffset, pglen);
err = fops->mmap_setup_read(vma, file, pgoffset, pglen);
if (err)
goto fail;
} else {
/* !wcfs: allocate address space somewhere */
addr = mem_valloc(NULL, len);
void *addr = mem_valloc(NULL, len);
if (!addr)
goto fail;
/* vma address range known */
vma->addr_start = (uintptr_t)addr;
vma->addr_stop = vma->addr_start + len;
}
if (!addr)
goto fail;
/* vma address range known */
vma->addr_start = (uintptr_t)addr;
vma->addr_stop = vma->addr_start + len;
/* wcfs: mmap(fileh->dirty_pages) over base */
if (fileh->mmap_overlay) {
......
......@@ -46,7 +46,7 @@ typedef struct VMA VMA;
/* BigFile base class
*
* BigFile is a file of fixed size blocks. It knows how to load/store blocks
* to/from memory. It can be also optionally memory mmaped.
* to/from memory. It can be also optionally mmaped into memory.
*
* Concrete file implementations subclass BigFile and define their file_ops.
*/
......@@ -106,7 +106,7 @@ struct bigfile_ops {
*
* The functions to setup memory mappings are:
*
* - mmap_setup_read(vma, file[blk +blklen)) -> addr setup initial read-only mmap to serve vma
* - mmap_setup_read(vma, file[blk +blklen)) setup initial read-only mmap to serve vma
* - remmap_blk_read(vma, file[blk]) remmap blk into vma again, after e.g.
* RW dirty page was discarded
* - munmap(vma) before VMA is unmapped
......@@ -137,17 +137,20 @@ struct bigfile_ops {
* }
* virt_unlock()
*
* mmap_setup_read must set vma.addr_start and vma.addr_stop according to
* created memory mapping.
*
* mmap_setup_read can use vma.mmap_overlay_server to associate vma with
* object pointer specific to serving created mapping.
*
* Called under virtmem lock. XXX easy to rework to call with !virt_lock
* Called under virtmem lock. TODO easy to rework to call with !virt_lock
*
* NOTE blk and blklen are in blocks, not pages.
*
* @addr NULL - mmap at anywhere, !NULL - mmap exactly at addr.
* @return !NULL - mapped there, NULL - error.
* @return 0 - ok !0 - fail
*/
void* (*mmap_setup_read) (VMA *vma, BigFile *file, blk_t blk, size_t blklen);
int (*mmap_setup_read) (VMA *vma, BigFile *file, blk_t blk, size_t blklen);
/* remmap_blk_read is called to remmap a block into vma again, after e.g.
......@@ -161,7 +164,7 @@ struct bigfile_ops {
/* munmap is called when vma set up via mmap_setup_read is going to be unmapped.
*
* Called under virtmem lock. XXX easy to rework to call with !virt_lock
* Called under virtmem lock. TODO easy to rework to call with !virt_lock
* Must not fail.
*/
void (*munmap) (VMA *vma, BigFile *file);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment