Commit 38ddb8c7 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1bbf1c49
......@@ -832,7 +832,7 @@ error _FileH::close() {
return nil;
// last open went away - real close.
xerr::Contextf E("%s: close f<%s>", v(wconn), v(fileh.foid));
xerr::Contextf E("%s: %s: close", v(wconn), v(fileh));
etrace("");
ASSERT(fileh._state == _FileHOpened); // there can be no open-in-progress, because
......@@ -849,9 +849,6 @@ error _FileH::close() {
eret = err;
};
// XXX do something with f.mu ?
// XXX change all fileh.mmaps to cause EFAULT on any access after fileh.close
// stop watching f
string ack;
tie(ack, err) = wconn->_wlink->sendReq(context::background(),
......@@ -870,6 +867,19 @@ error _FileH::close() {
reterr1(fileh._headf->close());
// change all fileh.mmaps to cause EFAULT on any access after fileh.close
fileh._mu.lock();
defer([&]() {
fileh._mu.unlock();
});
for (auto mmap : fileh._mmaps) {
err = mmap->__remmapAsEfault();
if (err != nil)
reterr1(err);
}
// fileh close complete
fileh._state = _FileHClosed;
fileh._closedq.close();
......@@ -892,7 +902,7 @@ pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma)
f.wconn->_atMu.RUnlock();
});
xerr::Contextf E("%s: mmap f<%s> [blk%ld +blk%ld)", v(f.wconn), v(f.foid), blk_start, blk_len);
xerr::Contextf E("%s: %s: mmap [#%ld +%ld)", v(f.wconn), v(f), blk_start, blk_len);
etrace("");
if (f._state >= _FileHClosing) // XXX locking
......@@ -989,7 +999,7 @@ error _Mapping::unmap() {
f->wconn->_atMu.RUnlock();
});
xerr::Contextf E("%s: f<%s>: unmap", v(f->wconn), v(f->foid));
xerr::Contextf E("%s: %s: %s: unmap", v(f->wconn), v(f), v(mmap));
etrace("");
if (mmap->vma != nil) {
......@@ -1030,7 +1040,7 @@ error _Mapping::_remmapblk(int64_t blk, zodb::Tid at) {
_Mapping *mmap = this;
FileH f = mmap->fileh;
xerr::Contextf E("%s: f<%s>: remmapblk #%ld @%s", v(f->wconn), v(f->foid), blk, v(at));
xerr::Contextf E("%s: %s: %s: remmapblk #%ld @%s", v(f->wconn), v(f), v(mmap), blk, v(at));
etrace("");
ASSERT(mmap->blk_start <= blk && blk < mmap->blk_stop());
......@@ -1113,6 +1123,26 @@ error _Mapping::remmap_blk(int64_t blk) {
return nil;
}
// __remmapEfault remmaps Mapping memory to cause SIGSEGV on access.
//
// It is used on FileH shutdown to turn all fileh mappings into incorrect ones,
// because after fileh is down, it is not possible to continue to provide
// correct f@at data view.
//
// Must be called with the following locks held by caller:
// - virt_lock
// XXX more?
error _Mapping::__remmapAsEfault() {
_Mapping& mmap = *this;
FileH f = mmap.fileh;
xerr::Contextf E("%s: remmap as efault", v(mmap)); // XXX +wconn, +f ?
etrace("");
error err = mmap_efault_into(mmap.mem_start, mmap.mem_stop - mmap.mem_start);
return E(err);
}
// ---- WCFS raw file access ----
// _path returns path for object on wcfs.
......@@ -1216,6 +1246,18 @@ string _Conn::String() const {
return fmt::sprintf("%s: conn%d @%s", v(wconn._wc), wconn._wlink->fd(), v(wconn.at));
}
string _FileH::String() const {
const _FileH& f = *this;
return fmt::sprintf("f<%s>", v(f.foid));
}
string _Mapping::String() const {
const _Mapping& mmap = *this;
return fmt::sprintf("m[#%ld +%ld) v[%p +%lx)",
mmap.blk_start, mmap.blk_stop() - mmap.blk_start,
mmap.mem_start, mmap.mem_stop - mmap.mem_start);
}
_Conn::_Conn() {}
_Conn::~_Conn() {}
void _Conn::decref() {
......
......@@ -246,7 +246,7 @@ struct _FileH : object {
// protected by .wconn._atMu
off_t _headfsize;
sync::Mutex _mu; // atMu.W | atMu.R + _mu
sync::Mutex _mu; // atMu.W | atMu.R + _mu XXX -> mmapMu ?
dict<int64_t, zodb::Tid> _pinned; // {} blk -> rev that wcfs already sent us for this file
vector<Mapping> _mmaps; // []Mapping ↑blk_start mappings of this file
......@@ -263,6 +263,7 @@ public:
pair<Mapping, error> mmap(int64_t blk_start, int64_t blk_len, VMA *vma=nil);
error _open();
string String() const;
};
// Mapping represents one memory mapping of FileH.
......@@ -286,11 +287,13 @@ struct _Mapping : object {
return blk_start + (mem_stop - mem_start) / fileh->blksize;
}
void _assertVMAOk();
error _remmapblk(int64_t blk, zodb::Tid at);
error remmap_blk(int64_t blk); // for virtmem-only
error unmap();
void _assertVMAOk();
error _remmapblk(int64_t blk, zodb::Tid at);
error __remmapAsEfault();
// don't new - create via FileH.mmap
private:
_Mapping();
......@@ -298,6 +301,8 @@ private:
friend pair<Mapping, error> _FileH::mmap(int64_t blk_start, int64_t blk_len, VMA *vma);
public:
void decref();
string String() const;
};
......
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