Commit f9efdbc0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5d67756e
...@@ -215,7 +215,7 @@ error _Conn::__pin1(PinReq *req) { ...@@ -215,7 +215,7 @@ error _Conn::__pin1(PinReq *req) {
if (mmap->vma != NULL) { if (mmap->vma != NULL) {
virt_lock(); virt_lock();
BigFileH *virt_fileh = mmap->vma->fileh; BigFileH *virt_fileh = mmap->vma->fileh;
TODO (mmap->fileh->_blksize != virt_fileh->ramh->ram->pagesize); TODO (mmap->fileh->blksize != virt_fileh->ramh->ram->pagesize);
do_pin = !__fileh_page_isdirty(virt_fileh, req->blk); do_pin = !__fileh_page_isdirty(virt_fileh, req->blk);
} }
...@@ -264,7 +264,7 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) { ...@@ -264,7 +264,7 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) {
f = adoptref(new _FileH()); f = adoptref(new _FileH());
f->wconn = newref(&wconn); // XXX newref -> simpler? f->wconn = newref(&wconn); // XXX newref -> simpler?
f->_foid = foid; f->foid = foid;
tie(f->_headf, err) tie(f->_headf, err)
= wconn._wc->_open(fmt::sprintf("head/bigfile/%s", h_(foid))); = wconn._wc->_open(fmt::sprintf("head/bigfile/%s", h_(foid)));
if (err != nil) if (err != nil)
...@@ -274,9 +274,9 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) { ...@@ -274,9 +274,9 @@ pair<FileH, error> _Conn::open(zodb::Oid foid) {
err = f->_headf->stat(&st); err = f->_headf->stat(&st);
if (err != nil) if (err != nil)
return make_pair(nil, err); return make_pair(nil, err);
f->_blksize = st.st_blksize; f->blksize = st.st_blksize;
f->_headfsize = st.st_size; f->_headfsize = st.st_size;
if (!(f->_headfsize % f->_blksize == 0)) if (!(f->_headfsize % f->blksize == 0))
return make_pair(nil, fmt::errorf("wcfs bug: head/file size %% blksize != 0")); return make_pair(nil, fmt::errorf("wcfs bug: head/file size %% blksize != 0"));
wconn._filehtab[foid] = f; wconn._filehtab[foid] = f;
...@@ -315,14 +315,14 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma) ...@@ -315,14 +315,14 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
// create memory with head/f mapping and applied pins // create memory with head/f mapping and applied pins
// mmap-in zeros after f.size (else access to memory after file.size will raise SIGBUS) // mmap-in zeros after f.size (else access to memory after file.size will raise SIGBUS)
int64_t start = blk_start*f._blksize; int64_t start = blk_start*f.blksize;
uint8_t *mem_start, *mem_stop; uint8_t *mem_start, *mem_stop;
tie(mem_start, err) = mmap_ro(f._headf, start, blk_len*f._blksize); tie(mem_start, err) = mmap_ro(f._headf, start, blk_len*f.blksize);
if (err != nil) if (err != nil)
return make_pair(nil, err); return make_pair(nil, err);
mem_stop = mem_start + blk_len*f._blksize; mem_stop = mem_start + blk_len*f.blksize;
int64_t stop = blk_stop*f._blksize; int64_t stop = blk_stop*f.blksize;
if (stop > f._headfsize) { if (stop > f._headfsize) {
uint8_t *zmem_start = mem_start + (max(f._headfsize/*XXX -1 ?*/, start) - start); uint8_t *zmem_start = mem_start + (max(f._headfsize/*XXX -1 ?*/, start) - start);
err = mmap_zero_into_ro(zmem_start, mem_stop - zmem_start); err = mmap_zero_into_ro(zmem_start, mem_stop - zmem_start);
...@@ -374,20 +374,20 @@ error _Conn::resync(zodb::Tid at) { ...@@ -374,20 +374,20 @@ error _Conn::resync(zodb::Tid at) {
if (err != nil) if (err != nil)
return err; return err;
if ((size_t)st.st_blksize != f->_blksize) // blksize must not change if ((size_t)st.st_blksize != f->blksize) // blksize must not change
return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->_blksize, st.st_blksize); return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->blksize, st.st_blksize);
auto headfsize = st.st_size; auto headfsize = st.st_size;
if (!(f->_headfsize <= headfsize)) // head/file size ↑= if (!(f->_headfsize <= headfsize)) // head/file size ↑=
return fmt::errorf("wcfs bug: head/file size not ↑="); return fmt::errorf("wcfs bug: head/file size not ↑=");
if (!(headfsize % f->_blksize == 0)) if (!(headfsize % f->blksize == 0))
return fmt::errorf("wcfs bug: head/file size %% blksize != 0"); return fmt::errorf("wcfs bug: head/file size %% blksize != 0");
for (auto mmap : f->_mmaps) { for (auto mmap : f->_mmaps) {
printf(" resync -> %s: unzero [%lu:%lu)", h_(at), f->_headfsize/f->_blksize, headfsize/f->_blksize); printf(" resync -> %s: unzero [%lu:%lu)", h_(at), f->_headfsize/f->blksize, headfsize/f->blksize);
uint8_t *mem_unzero_start = min(mmap->mem_stop, uint8_t *mem_unzero_start = min(mmap->mem_stop,
mmap->mem_start + (f->_headfsize - mmap->blk_start*f->_blksize)); mmap->mem_start + (f->_headfsize - mmap->blk_start*f->blksize));
uint8_t *mem_unzero_stop = min(mmap->mem_stop, uint8_t *mem_unzero_stop = min(mmap->mem_stop,
mmap->mem_start + (headfsize - mmap->blk_start*f->_blksize)); mmap->mem_start + (headfsize - mmap->blk_start*f->blksize));
if (mem_unzero_stop - mem_unzero_start > 0) { if (mem_unzero_stop - mem_unzero_start > 0) {
err = mmap_into_ro(mem_unzero_start, mem_unzero_stop-mem_unzero_start, f->_headf, f->_headfsize); err = mmap_into_ro(mem_unzero_start, mem_unzero_stop-mem_unzero_start, f->_headf, f->_headfsize);
...@@ -426,7 +426,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) { ...@@ -426,7 +426,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
FileH f = mmap->fileh; FileH f = mmap->fileh;
error err; error err;
uint8_t *blkmem = mmap->mem_start + (blk - mmap->blk_start)*f->_blksize; uint8_t *blkmem = mmap->mem_start + (blk - mmap->blk_start)*f->blksize;
os::File fsfile; os::File fsfile;
bool fclose = false; bool fclose = false;
if (at == TidHead) { if (at == TidHead) {
...@@ -435,7 +435,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) { ...@@ -435,7 +435,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
else { else {
// TODO share @rev fd until wconn is resynced? // TODO share @rev fd until wconn is resynced?
tie(fsfile, err) = f->wconn->_wc->_open( tie(fsfile, err) = f->wconn->_wc->_open(
fmt::sprintf("@%s/bigfile/%s", h_(at), h_(f->_foid))); fmt::sprintf("@%s/bigfile/%s", h_(at), h_(f->foid)));
if (err != nil) if (err != nil)
return err; return err;
fclose = true; fclose = true;
...@@ -449,19 +449,19 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) { ...@@ -449,19 +449,19 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
err = fsfile->stat(&st); err = fsfile->stat(&st);
if (err != nil) if (err != nil)
return err; return err;
if ((size_t)st.st_blksize != f->_blksize) if ((size_t)st.st_blksize != f->blksize)
return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->_blksize, st.st_blksize); return fmt::errorf("wcfs bug: blksize changed: %zd -> %ld", f->blksize, st.st_blksize);
// block is beyond file size - mmap with zeros - else access to memory // block is beyond file size - mmap with zeros - else access to memory
// after file.size will raise SIGBUS. (assumes head/f size ↑=) // after file.size will raise SIGBUS. (assumes head/f size ↑=)
if ((blk+1)*f->_blksize > (size_t)st.st_size) { if ((blk+1)*f->blksize > (size_t)st.st_size) {
err = mmap_zero_into_ro(blkmem, 1*f->_blksize); err = mmap_zero_into_ro(blkmem, 1*f->blksize);
if (err != nil) if (err != nil)
return err; return err;
} }
// block is inside file - mmap file data // block is inside file - mmap file data
else { else {
err = mmap_into_ro(blkmem, 1*f->_blksize, fsfile, blk*f->_blksize); err = mmap_into_ro(blkmem, 1*f->blksize, fsfile, blk*f->blksize);
if (err != nil) if (err != nil)
return err; return err;
} }
......
...@@ -138,8 +138,8 @@ private: ...@@ -138,8 +138,8 @@ private:
typedef refptr<struct _FileH> FileH; typedef refptr<struct _FileH> FileH;
struct _FileH : object { struct _FileH : object {
Conn wconn; Conn wconn;
zodb::Oid _foid; // ZBigFile root object ID zodb::Oid foid; // ZBigFile root object ID
size_t _blksize; // block size of this file XXX -> off_t ? size_t blksize; // block size of this file XXX -> off_t ?
os::File _headf; // file object of head/file os::File _headf; // file object of head/file
off_t _headfsize; // head/file size is known to be at least headfsize (size ↑=) off_t _headfsize; // head/file size is known to be at least headfsize (size ↑=)
...@@ -169,8 +169,8 @@ struct _Mapping : object { ...@@ -169,8 +169,8 @@ struct _Mapping : object {
VMA *vma; // mmapped under this virtmem VMA | nil if created standalone from virtmem VMA *vma; // mmapped under this virtmem VMA | nil if created standalone from virtmem
int64_t blk_stop() const { int64_t blk_stop() const {
ASSERT((mem_stop - mem_start) % fileh->_blksize == 0); ASSERT((mem_stop - mem_start) % fileh->blksize == 0);
return blk_start + (mem_stop - mem_start) / fileh->_blksize; return blk_start + (mem_stop - mem_start) / fileh->blksize;
} }
error _remmapblk(int64_t blk, zodb::Tid at); error _remmapblk(int64_t blk, zodb::Tid at);
......
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