Commit a80e3140 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b546edf6
......@@ -66,10 +66,13 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
static void zfile_munmap(VMA *vma, BigFile *file) {
error err;
wcfs::_Mapping *mmap = static_cast<wcfs::_Mapping*>(vma->mmap_overlay_server);
#if 0
// NOTE taking 1 ref back from vma->mmap_overlay_server
wcfs::Mapping mmap = adoptref(static_cast<wcfs::_Mapping*>(vma->mmap_overlay_server));
vma->mmap_overlay_server = NULL;
#endif
err = mmap->unmap();
if (err != nil)
......
......@@ -259,7 +259,7 @@ error _Conn::__pin1(PinReq *req) {
bool do_pin= true;
error err;
if (mmap->vma != nil) {
mmap->assertVMAOk();
mmap->_assertVMAOk();
virt_lock();
BigFileH *virt_fileh = mmap->vma->fileh;
TODO (mmap->fileh->blksize != virt_fileh->ramh->ram->pagesize);
......@@ -460,7 +460,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
vma->mmap_overlay_server = mmap._ptr();
vma->addr_start = (uintptr_t)mmap->mem_start;
vma->addr_stop = (uintptr_t)mmap->mem_stop;
mmap.assertVMAOk(); // just in case
mmap->_assertVMAOk(); // just in case
}
f._mmaps.push_back(mmap); // TODO keep f._mmaps ↑blk_start
......@@ -472,7 +472,9 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
// unmap releases mapping memory from address space.
//
// After call to unmap the mapping must no longer be used.
// virtmem calls unmap when VMA is unmapped.
//
// virtmem calls unmap when VMA is unmapped, thus
// unmap must be called under virtmem lock for mappings associated with a VMA.
error _Mapping::unmap() {
Mapping mmap = newref(this); // XXX newref for std::remove
FileH f = mmap->fileh;
......@@ -483,12 +485,13 @@ error _Mapping::unmap() {
// XXX make sure mmap cannot be XXX
if (mmap->vma != nil) {
// must be called under virtmem lock fo virtmem-intergrated case (?)
mmap->assertVMAOk();
mmap->_assertVMAOk();
VMA *vma = mmap->vma;
vma->mmap_overlay_server = NULL;
vma->mmap_overlay_server = nil;
mmap->decref(); // vma->mmap_overlay_server was holding a ref to mmap
vma->addr_start = 0;
vma->addr_stop = 0;
mmap->vma = nil;
}
error err = mm::unmap(mmap->mem_start, mmap->mem_stop - mmap->mem_start);
......@@ -736,18 +739,19 @@ void _Mapping::decref() {
delete this;
}
// assertVMAOk() verifies that mmap and vma are related to each other and cover
// _assertVMAOk() verifies that mmap and vma are related to each other and cover
// exactly the same virtual memory rane.
//
// It panics if mmap and vma do not exactly relate to each other or cover
// different virtual memory range.
void _Mapping::assertVMAOk() {
void _Mapping::_assertVMAOk() {
_Mapping* mmap = this;
VMA *vma = mmap.vma;
VMA *vma = mmap->vma;
if (!(vma->mmap_overlay_server == mmap._ptr()))
if (!(vma->mmap_overlay_server == static_cast<void*>(mmap)))
panic("BUG: mmap and vma do not link to each other");
if (!(vma->addr_start == mmap->mem_start && vma->addr_stop == mmap->mem_stop))
if (!(vma->addr_start == uintptr_t(mmap->mem_start) &&
vma->addr_stop == uintptr_t(mmap->mem_stop)))
panic("BUG: mmap and vma cover different virtual memory ranges");
// verified ok
......
......@@ -262,6 +262,7 @@ struct _Mapping : object {
return blk_start + (mem_stop - mem_start) / fileh->blksize;
}
void _assertVMAOk();
error _remmapblk(int64_t blk, zodb::Tid at);
error remmap_blk(int64_t blk); // for virtmem-only
error unmap();
......
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