Commit d5011053 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 09632ad8
......@@ -90,16 +90,7 @@ class Conn(object):
# ._filemu threading.Lock
# ._filetab {} foid -> _File
def __init__(wconn, wc, at):
# XXX support !isolated mode
wconn._wc = wc
wconn.at = at
wconn._wlink = WatchLink(wc)
wconn._filemu = threading.Lock()
wconn._filetab = {}
# XXX wg.go(wconn._pinner, xxxctx)
pass
# _File represent isolated file view under Conn.
class _File(object):
......@@ -124,7 +115,18 @@ class _Mapping(object):
# connect creates new Conn viewing WCFS state as of @at.
@func(WCFS)
def connect(wc, at): # -> Conn
return Conn(wc, at)
wconn = Conn()
# XXX support !isolated mode
wconn._wc = wc
wconn.at = at
wconn._wlink = WatchLink(wc)
wconn._filemu = threading.Lock()
wconn._filetab = {}
# XXX wg.go(wconn._pinner, xxxctx)
return wconn
# close releases resources associated with wconn.
# XXX what happens to file mmappings?
......@@ -171,14 +173,18 @@ def mmap(wconn, foid, offset, size): # -> Mapping XXX offset, size -> blko
with wconn._filemu:
f = wconn._filetab.get(foid)
if f is None:
headf = wconn._wc._open("head/bigfile/%s" % (ashex(foid),), "rb")
f = _File(headf)
f = _File()
f.wconn = wconn
f.foid = foid
f.headf = wconn._wc._open("head/bigfile/%s" % (ashex(foid),), "rb")
f.pinned = {}
f.mmaps = []
wconn._filetab[foid] = f
# XXX relock wconn -> f ?
# create memory with head/f mapping and applied pins
mem = mm.mmap_ro(f.headf.fileno(), offset, size)
mem = mm.map_ro(f.headf.fileno(), offset, size)
mmap = _Mapping(f, blk_start, mem)
for blk, rev in f.pinned.items(): # XXX keep f.pinned ↑blk and use binary search?
if not (blk_start <= blk < blk_stop):
......@@ -205,7 +211,7 @@ def _remmapblk(mmap, blk, at):
fsfile = f.wconn._wc._open("@%s/bigfile/%s" % (ashex(at), ashex(f.foid)), "rb")
defer(fsfile.close)
mm.mmap_into_ro(mmap.mem[(blk-mmap.blk_start)*blksize:][:blksize], fsfile.fileno(), blk*blksize)
mm.map_into_ro(mmap.mem[(blk-mmap.blk_start)*blksize:][:blksize], fsfile.fileno(), blk*blksize)
# remmap_blk remmaps file[blk] in its place again.
......
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