Commit d5011053 authored by Kirill Smelkov's avatar Kirill Smelkov

.

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