Commit cd3f3f04 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c6e0e48e
......@@ -46,6 +46,9 @@ using std::vector;
typedef uint64_t Tid; // XXX ok?
typedef uint64_t Oid; // XXX ok?
// TidHead is invalid Tid which is larged Tid value and means @head
const Tid TidHead = -1ULL;
// XXX ok?
struct IContext {
virtual chan<structZ> done() = 0;
......@@ -108,6 +111,8 @@ struct _Mapping {
ASSERT((mem_stop - mem_start) % file->blksize == 0);
return blk_start + (mem_stop - mem_start) / file->blksize;
}
void _remmapblk(int64_t blk, Tid at);
};
......@@ -213,3 +218,36 @@ void Conn::_pin1(SrvReq *req) {
wconn->_filemu.unlock();
}
// _remmapblk remmaps mapping memory for file[blk] to be viewing database as of @at state.
//
// at=None means unpin to head/ . XXX -> C
// NOTE this does not check wrt virtmem already mapped blk as RW.
void _Mapping::_remmapblk(int64_t blk, Tid at) {
_Mapping *mmap = this;
ASSERT(mmap->blk_start <= blk && blk < mmap->blk_stop());
_File *f = mmap->file;
uint8_t *blkmem = mmap->mem_start + (blk - mmap->blk_start)*f->blksize;
if (at == TidHead) {
fsfile = f->headf;
}
else {
// TODO share @rev fd until wconn is resynced?
fsfile = f->wconn->_wc._open("@%s/bigfile/%s" % (h(at), h(f->foid)), "rb")
defer(fsfile.close)
}
_ = os.fstat(fsfile.fileno());
ASSERT(_.st_blksize == f->blksize); // FIXME assert
// block is beyond file size - mmap with zeros (assumes head/f size ↑=)
if ((blk+1)*f->blksize > _.st_size) {
mm.map_zero_into_ro(blkmem)
}
// block is inside file - mmap file data
else {
mm.map_into_ro(blkmem, fsfile.fileno(), blk*f->blksize)
}
}
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