Commit b546edf6 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ded803b0
...@@ -129,7 +129,7 @@ struct bigfile_ops { ...@@ -129,7 +129,7 @@ struct bigfile_ops {
* virt_unlock() * virt_unlock()
* *
* XXX mention VMA.mmap_overlay_server? * XXX mention VMA.mmap_overlay_server?
* XXX called under virtmem lock? * called under virtmem lock
* *
* NOTE blk and blklen are in blocks, not pages. * NOTE blk and blklen are in blocks, not pages.
* *
...@@ -142,14 +142,14 @@ struct bigfile_ops { ...@@ -142,14 +142,14 @@ struct bigfile_ops {
// remmap_blk_read is called to remmap a block into vma again, after e.g. // remmap_blk_read is called to remmap a block into vma again, after e.g.
// RW dirty page was discarded. // RW dirty page was discarded.
// //
// XXX called under virtmem lock? // called under virtmem lock.
// //
// XXX error -> bug (must not fail) // XXX error -> bug (must not fail)
int (*remmap_blk_read) (VMA *vma, BigFile *file, blk_t blk); int (*remmap_blk_read) (VMA *vma, BigFile *file, blk_t blk);
/* munmap is called when vma set up via mmap_setup_read is going to be unmapped. /* munmap is called when vma set up via mmap_setup_read is going to be unmapped.
* *
* XXX called under virtmem lock? * called under virtmem lock.
* Must not fail. * Must not fail.
*/ */
void (*munmap) (VMA *vma, BigFile *file); void (*munmap) (VMA *vma, BigFile *file);
......
...@@ -259,6 +259,7 @@ error _Conn::__pin1(PinReq *req) { ...@@ -259,6 +259,7 @@ error _Conn::__pin1(PinReq *req) {
bool do_pin= true; bool do_pin= true;
error err; error err;
if (mmap->vma != nil) { if (mmap->vma != nil) {
mmap->assertVMAOk();
virt_lock(); virt_lock();
BigFileH *virt_fileh = mmap->vma->fileh; BigFileH *virt_fileh = mmap->vma->fileh;
TODO (mmap->fileh->blksize != virt_fileh->ramh->ram->pagesize); TODO (mmap->fileh->blksize != virt_fileh->ramh->ram->pagesize);
...@@ -459,6 +460,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) ...@@ -459,6 +460,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
vma->mmap_overlay_server = mmap._ptr(); vma->mmap_overlay_server = mmap._ptr();
vma->addr_start = (uintptr_t)mmap->mem_start; vma->addr_start = (uintptr_t)mmap->mem_start;
vma->addr_stop = (uintptr_t)mmap->mem_stop; vma->addr_stop = (uintptr_t)mmap->mem_stop;
mmap.assertVMAOk(); // just in case
} }
f._mmaps.push_back(mmap); // TODO keep f._mmaps ↑blk_start f._mmaps.push_back(mmap); // TODO keep f._mmaps ↑blk_start
...@@ -481,6 +483,12 @@ error _Mapping::unmap() { ...@@ -481,6 +483,12 @@ error _Mapping::unmap() {
// XXX make sure mmap cannot be XXX // XXX make sure mmap cannot be XXX
if (mmap->vma != nil) { if (mmap->vma != nil) {
// must be called under virtmem lock fo virtmem-intergrated case (?)
mmap->assertVMAOk();
VMA *vma = mmap->vma;
vma->mmap_overlay_server = NULL;
vma->addr_start = 0;
vma->addr_stop = 0;
} }
error err = mm::unmap(mmap->mem_start, mmap->mem_stop - mmap->mem_start); error err = mm::unmap(mmap->mem_start, mmap->mem_stop - mmap->mem_start);
...@@ -728,6 +736,22 @@ void _Mapping::decref() { ...@@ -728,6 +736,22 @@ void _Mapping::decref() {
delete this; delete this;
} }
// 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() {
_Mapping* mmap = this;
VMA *vma = mmap.vma;
if (!(vma->mmap_overlay_server == mmap._ptr()))
panic("BUG: mmap and vma do not link to each other");
if (!(vma->addr_start == mmap->mem_start && vma->addr_stop == mmap->mem_stop))
panic("BUG: mmap and vma cover different virtual memory ranges");
// verified ok
}
dict<int64_t, zodb::Tid> _tfileh_pinned(FileH fileh) { dict<int64_t, zodb::Tid> _tfileh_pinned(FileH fileh) {
return fileh->_pinned; return fileh->_pinned;
......
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