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