Commit e83b9085 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent eab13d28
...@@ -61,11 +61,15 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) { ...@@ -61,11 +61,15 @@ static int zfile_remmap_blk_read(VMA *vma, BigFile *file, blk_t blk) {
static void zfile_munmap(VMA *vma, BigFile *file) { static void zfile_munmap(VMA *vma, BigFile *file) {
error err;
// NOTE taking 1 ref back from vma->mmap_overlay_server // NOTE taking 1 ref back from vma->mmap_overlay_server
wcfs::Mapping mmap = adoptref(static_cast<wcfs::_Mapping*>(vma->mmap_overlay_server)); wcfs::Mapping mmap = adoptref(static_cast<wcfs::_Mapping*>(vma->mmap_overlay_server));
vma->mmap_overlay_server = NULL; vma->mmap_overlay_server = NULL;
mmap->unmap(); err = mmap->unmap();
if (err != nil)
panic(v(err)); // XXX
// XXX close mmap->fileh // XXX close mmap->fileh
} }
......
...@@ -111,7 +111,7 @@ cdef extern from "wcfs/client/wcfs.h" namespace "wcfs" nogil: ...@@ -111,7 +111,7 @@ cdef extern from "wcfs/client/wcfs.h" namespace "wcfs" nogil:
uint8_t *mem_start uint8_t *mem_start
uint8_t *mem_stop uint8_t *mem_stop
void unmap() error unmap()
cppclass Mapping (refptr[_Mapping]): cppclass Mapping (refptr[_Mapping]):
# Mapping.X = Mapping->X in C++ # Mapping.X = Mapping->X in C++
...@@ -121,7 +121,7 @@ cdef extern from "wcfs/client/wcfs.h" namespace "wcfs" nogil: ...@@ -121,7 +121,7 @@ cdef extern from "wcfs/client/wcfs.h" namespace "wcfs" nogil:
uint8_t *mem_start "_ptr()->mem_start" uint8_t *mem_start "_ptr()->mem_start"
uint8_t *mem_stop "_ptr()->mem_stop" uint8_t *mem_stop "_ptr()->mem_stop"
void unmap "_ptr()->unmap" () error unmap "_ptr()->unmap" ()
cxx.dict[int64_t, Tid] _tfileh_pinned(FileH wfileh) cxx.dict[int64_t, Tid] _tfileh_pinned(FileH wfileh)
......
...@@ -155,7 +155,9 @@ cdef class PyMapping: ...@@ -155,7 +155,9 @@ cdef class PyMapping:
def unmap(PyMapping pywmmap): def unmap(PyMapping pywmmap):
with nogil: with nogil:
wmmap_unmap_pyexc(pywmmap.wmmap) # XXX +err err = wmmap_unmap_pyexc(pywmmap.wmmap)
if err != nil:
raise pyerr(err)
# ---------------------------------------- # ----------------------------------------
...@@ -291,8 +293,8 @@ cdef nogil: ...@@ -291,8 +293,8 @@ cdef nogil:
pair[Mapping, error] wfileh_mmap_pyexc(FileH wfileh, int64_t blk_start, int64_t blk_len) except +topyexc: pair[Mapping, error] wfileh_mmap_pyexc(FileH wfileh, int64_t blk_start, int64_t blk_len) except +topyexc:
return wfileh.mmap(blk_start, blk_len) return wfileh.mmap(blk_start, blk_len)
void wmmap_unmap_pyexc(Mapping wmmap) except +topyexc: error wmmap_unmap_pyexc(Mapping wmmap) except +topyexc:
wmmap.unmap() return wmmap.unmap()
error wlink_close_pyexc(WatchLink wlink) except +topyexc: error wlink_close_pyexc(WatchLink wlink) except +topyexc:
return wlink.close() return wlink.close()
......
...@@ -606,25 +606,29 @@ void _Mapping::remmap_blk(int64_t blk) { ...@@ -606,25 +606,29 @@ void _Mapping::remmap_blk(int64_t blk) {
// unmap removes mapping memory from address space. // unmap removes mapping memory from address space.
// virtmem calls this when VMA is unmapped. // virtmem calls this when VMA is unmapped.
void _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;
xerr::Contextf E("wcfs %s: conn @%s: f<%s>: unmap",
v(f->wconn->_wc->mountpoint), v(f->wconn->at), v(f->foid));
// XXX locking // XXX locking
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);
if (err != nil) if (err != nil)
panic(v(err)); // XXX return E(err);
mmap->mem_start = NULL; mmap->mem_start = NULL;
mmap->mem_stop = NULL; mmap->mem_stop = NULL;
// XXX clear other fields? // XXX clear other fields?
FileH f = mmap->fileh;
//f->_mmaps.remove(mmap); //f->_mmaps.remove(mmap);
// FIXME keep mmaps sorted // FIXME keep mmaps sorted
f->_mmaps.erase( f->_mmaps.erase(
std::remove(f->_mmaps.begin(), f->_mmaps.end(), mmap), std::remove(f->_mmaps.begin(), f->_mmaps.end(), mmap),
f->_mmaps.end()); f->_mmaps.end());
return nil;
} }
......
...@@ -141,6 +141,7 @@ struct PinReq; ...@@ -141,6 +141,7 @@ struct PinReq;
// XXX raw files? // XXX raw files?
// //
// WCFS logically mirrors ZODB.DB . // WCFS logically mirrors ZODB.DB .
// It is safe to use WCFS from multiple threads simultaneously.
struct WCFS { struct WCFS {
string mountpoint; string mountpoint;
...@@ -162,10 +163,11 @@ struct WCFS { ...@@ -162,10 +163,11 @@ struct WCFS {
// Use .resync to resync Conn onto different database view. // Use .resync to resync Conn onto different database view.
// //
// Conn logically mirrors ZODB.Connection . // Conn logically mirrors ZODB.Connection .
// It is safe to use Conn from multiple threads simultaneously.
typedef refptr<struct _Conn> Conn; typedef refptr<struct _Conn> Conn;
struct _Conn : object { struct _Conn : object {
WCFS *_wc; WCFS *_wc;
zodb::Tid at; zodb::Tid at; // XXX -> under mu
WatchLink _wlink; // watch/receive pins for mappings created under this conn WatchLink _wlink; // watch/receive pins for mappings created under this conn
// XXX kill downMu? (move under filehmu so that e.g. .open() can check downErr without race) // XXX kill downMu? (move under filehmu so that e.g. .open() can check downErr without race)
...@@ -205,6 +207,8 @@ private: ...@@ -205,6 +207,8 @@ private:
// /head/<file>/data primarily and /@revX/<file>/data pin overrides. // /head/<file>/data primarily and /@revX/<file>/data pin overrides.
// //
// Use .mmap to map file view into memory. // Use .mmap to map file view into memory.
//
// It is safe to use FileH from multiple threads simultaneously.
typedef refptr<struct _FileH> FileH; typedef refptr<struct _FileH> FileH;
struct _FileH : object { struct _FileH : object {
Conn wconn; Conn wconn;
...@@ -232,6 +236,9 @@ public: ...@@ -232,6 +236,9 @@ public:
// Mapping represents one memory mapping of FileH. // Mapping represents one memory mapping of FileH.
// //
// The mapped memory is [.mem_start, .mem_stop) // The mapped memory is [.mem_start, .mem_stop)
// Use .unmap to release virtual memory resources used by mapping.
//
// XXX It is safe to use Mapping from multiple threads simultaneously.
typedef refptr<struct _Mapping> Mapping; typedef refptr<struct _Mapping> Mapping;
struct _Mapping : object { struct _Mapping : object {
FileH fileh; FileH fileh;
...@@ -247,8 +254,8 @@ struct _Mapping : object { ...@@ -247,8 +254,8 @@ struct _Mapping : object {
} }
error _remmapblk(int64_t blk, zodb::Tid at); error _remmapblk(int64_t blk, zodb::Tid at);
void remmap_blk(int64_t blk); void remmap_blk(int64_t blk); // for virtmem-only
void unmap(); error unmap();
// don't new - create via FileH.mmap // don't new - create via FileH.mmap
private: private:
......
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