Commit 4a38e910 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7a2b1dad
...@@ -129,7 +129,8 @@ struct bigfile_ops { ...@@ -129,7 +129,8 @@ struct bigfile_ops {
* virt_unlock() * virt_unlock()
* *
* XXX mention VMA.mmap_overlay_server? * XXX mention VMA.mmap_overlay_server?
* 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 +143,14 @@ struct bigfile_ops { ...@@ -142,14 +143,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.
// //
// 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.
* *
* 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);
......
...@@ -390,6 +390,7 @@ error _FileH::close() { ...@@ -390,6 +390,7 @@ error _FileH::close() {
xerr::Contextf E("wcfs %s: conn @%s: close f<%s>", v(wconn->_wc->mountpoint), v(wconn->at), v(fileh.foid)); xerr::Contextf E("wcfs %s: conn @%s: close f<%s>", v(wconn->_wc->mountpoint), v(wconn->at), v(fileh.foid));
// XXX change all fileh.mmaps to cause EFAULT on any access after fileh.close // XXX change all fileh.mmaps to cause EFAULT on any access after fileh.close
// XXX "watch foid -" -> wconn.wlink (stop watchingthe file)
// remove fileh from wconn._filehtab // remove fileh from wconn._filehtab
// fileh.close can be called several times and after first call another // fileh.close can be called several times and after first call another
...@@ -405,7 +406,8 @@ error _FileH::close() { ...@@ -405,7 +406,8 @@ error _FileH::close() {
// mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state. // mmap creates file mapping representing file[blk_start +blk_len) data as of wconn.at database state.
// //
// If vma != nil, created mapping is associated with that vma of user-space virtual memory manager. // If vma != nil, created mapping is associated with that vma of user-space virtual memory manager:
// virtmem calls FileH::mmap under virtmem lock when virtmem fileh is mmapped into vma.
pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) { pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) {
_FileH& f = *this; _FileH& f = *this;
xerr::Contextf E("wcfs %s: conn @%s: mmap f<%s> [blk%ld +blk%ld)", xerr::Contextf E("wcfs %s: conn @%s: mmap f<%s> [blk%ld +blk%ld)",
...@@ -430,6 +432,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) ...@@ -430,6 +432,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
// XXX wconn.atMu.RLock() // XXX wconn.atMu.RLock()
// XXX defer wconn.atMu.RUnlock() // XXX defer wconn.atMu.RUnlock()
// NOTE virtmem lock is held by virtmem caller
// XXX f locking? // XXX f locking?
// create memory with head/f mapping and applied pins // create memory with head/f mapping and applied pins
...@@ -491,18 +494,17 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) ...@@ -491,18 +494,17 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
// unmap releases mapping memory from address space. // unmap releases mapping memory from address space.
// //
// After call to unmap the mapping must no longer be used. // After call to unmap the mapping must no longer be used.
// The association in between mapping and linked virtmem VMA is reset.
// //
// virtmem calls unmap when VMA is unmapped, thus // Virtmem calls Mapping.unmap under virtmem lock when VMA is unmapped.
// unmap must be called under virtmem lock for mappings associated with a VMA.
// The association in between mapping and linked VMA is reset.
error _Mapping::unmap() { error _Mapping::unmap() {
Mapping mmap = newref(this); // XXX newref for std::remove Mapping mmap = newref(this); // XXX newref for std::remove
FileH f = mmap->fileh; FileH f = mmap->fileh;
xerr::Contextf E("wcfs %s: conn @%s: f<%s>: unmap", xerr::Contextf E("wcfs %s: conn @%s: f<%s>: unmap",
v(f->wconn->_wc->mountpoint), v(f->wconn->at), v(f->foid)); v(f->wconn->_wc->mountpoint), v(f->wconn->at), v(f->foid));
// NOTE virtmem lock is held by virtmem caller
// XXX locking // XXX locking
// XXX make sure mmap cannot be XXX
if (mmap->vma != nil) { if (mmap->vma != nil) {
mmap->_assertVMAOk(); mmap->_assertVMAOk();
...@@ -615,6 +617,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) { ...@@ -615,6 +617,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
xerr::Contextf E("wcfs %s: conn @%s: f<%s>: remmapblk #%ld @%s", xerr::Contextf E("wcfs %s: conn @%s: f<%s>: remmapblk #%ld @%s",
v(f->wconn->_wc->mountpoint), v(f->wconn->at), v(f->foid), blk, v(at)); v(f->wconn->_wc->mountpoint), v(f->wconn->at), v(f->foid), blk, v(at));
// XXX locking done by callers (document)
ASSERT(mmap->blk_start <= blk && blk < mmap->blk_stop()); ASSERT(mmap->blk_start <= blk && blk < mmap->blk_stop());
error err; error err;
...@@ -663,11 +666,15 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) { ...@@ -663,11 +666,15 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
} }
// remmap_blk remmaps file[blk] in its place again. // remmap_blk remmaps file[blk] in its place again.
// virtmem calls this to remmap a block after RW dirty page was e.g. discarded. //
// Virtmem calls Mapping.remmap_blk under virtmem lock to remmap a block after
// RW dirty page was e.g. discarded.
error _Mapping::remmap_blk(int64_t blk) { error _Mapping::remmap_blk(int64_t blk) {
_Mapping& mmap = *this; _Mapping& mmap = *this;
// NOTE virtmem lock is held by virtmem caller
// XXX locking // XXX locking
if (!(mmap.blk_start <= blk && blk < mmap.blk_stop())) if (!(mmap.blk_start <= blk && blk < mmap.blk_stop()))
panic("remmap_blk: blk out of Mapping range"); panic("remmap_blk: blk out of Mapping range");
......
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