Commit 822366a7 authored by Kirill Smelkov's avatar Kirill Smelkov

X keeping fd to root opened prevents the filesystem from being unmounted

parent f8f027d4
......@@ -540,18 +540,18 @@ func (r *Root) zwatcher(ctx context.Context) (err error) {
}
// zhandle1 handles 1 event from ZODB notification.
// (called with .zheadMu wlocked)
func (r *Root) zhandle1(zevent zodb.WatchEvent) {
// XXX locking correct? XXX too coarse? -> lock only around "resync .zhead ..." ?
r.zheadMu.Lock()
defer r.zheadMu.Unlock()
r.head.zconnMu.Lock()
defer r.head.zconnMu.Unlock()
zhead := r.head.zconn
//toinvalidate := map[*ZBigFile]SetI64{} // {} zfile -> set(#blk)
toinvalidate := map[*BigFile]SetI64{} // {} zfile -> set(#blk)
// zevent = (tid^, []oid)
for _, oid := range zevent.Changev {
obj := r.zhead.Cache().Get(oid)
obj := zhead.Cache().Get(oid)
if obj == nil {
continue // nothing to do - see invariant
}
......@@ -597,12 +597,15 @@ func (r *Root) zhandle1(zevent zodb.WatchEvent) {
}
// invalidateBlk invalidates 1 file block. XXX
//
// called with f.head.zconnMu wlocked.
//
// XXX see "4.4) for all file/blk to in invalidate we do"
func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) error {
fsconn := f.root().fsconn
fsconn := gfsconn
off := blk*blksize
// try retrieve cache of current head/data[blk]
// try to retrieve cache of current head/data[blk]
//
// if less than blksize was cached - probably the kernel had to evict
// some data from its cache already. In such case we don't try to
......@@ -610,11 +613,13 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) error {
// system overloaded.
//
// XXX st != OK -> warn?
blkdata, st := fsconn.FileRetrieveCache(f.Inode(), off, blksize)
if len(blkdata) == blksize {
blkdata := make([]byte, blksize)
n, st := fsconn.FileRetrieveCache(f.Inode(), off, blkdata)
if n == blksize {
// XXX -> go
// store retrieved data back to OS cache for file @<rev>/data[blk]
frev, _ := f.bigfile.δFtail.LastRevOf(blk, at)
// store retrieved data back to OS cache for file @<rev>/file[blk]
blkrev, _ := f.δFtail.LastRevOf(blk, f.head.zconn.At())
frev := groot.revisionedFile(ctx, blkrev, f.zbf.POid())
st = fsconn.FileNotifyStoreCache(frev.Inode(), off, blkdata)
if st != fuse.OK {
// XXX log - dup wrt readBlk -> common func.
......@@ -627,6 +632,18 @@ func (f *BigFile) invalidateBlk(ctx context.Context, blk int64) error {
panic("TODO")
}
// mkrevfile makes sure inode of /@<rev>/bigfile/<fid> is known to kernel.
//
// We need node ID to be know to the kernel, when we need to store data into
// file's kernel cache.
//
// For kernel to know node IDmkrevfile has
//
// XXX why we go through kernel.lookup
func (root *Root) mkrevfile(ctx context.Context, rev zodb.Tid, fid zodb.Oid) (*BigFile, error) {
}
*/
// ----------------------------------------
......@@ -960,7 +977,7 @@ func (f *BigFile) readBlk(ctx context.Context, blk int64, dest []byte) error {
_ = revmax
/*
// XXX remmapping
// XXX remmapping - only if head.rev == 0
// XXX -> own func?
// XXX locking
for _, mapping := range f.mappings {
......@@ -1050,9 +1067,12 @@ func (h *Head) readAt() []byte {
// - Mount:
// .Root() -> root Inode of the fs
// .Connector() -> FileSystemConnector through which fs is mounted
//var groot *Root
var groot *Root
var gfsconn *nodefs.FileSystemConnector
// file descriptor for opened root of the filesystem
var grootf *os.File // XXX -> fd
func main() {
stdlog.SetPrefix("wcfs: ")
//log.CopyStandardLogTo("WARNING") // XXX -> "DEBUG" if -d ?
......@@ -1116,7 +1136,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
//groot = root // FIXME temp workaround (see ^^^)
groot = root // FIXME temp workaround (see ^^^)
gfsconn = fsconn // FIXME ----//----
// we require proper pagecache control (added to Linux 2.6.36 in 2010)
......@@ -1139,5 +1159,22 @@ func main() {
_ = autoexit
// serve client requests
fssrv.Serve() // XXX Serve returns no error
done := make(chan struct{})
go func() {
fssrv.Serve() // XXX Serve returns no error
close(done)
}()
err = fssrv.WaitMount()
if err != nil {
log.Fatal(err)
}
grootf, err = os.Open(mntpt)
if err != nil {
fssrv.Unmount()
log.Fatal(err)
}
<-done
}
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