Commit 0eb229fd authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Don't hold locks while unmounting zip FS.

parent c29cdc95
......@@ -32,6 +32,9 @@ type MultiZipFs struct {
zips map[string]nodefs.Node
dirZipFileMap map[string]string
// zip files that we are in the process of unmounting.
zombie map[string]bool
nodeFs *pathfs.PathNodeFs
pathfs.FileSystem
}
......@@ -39,6 +42,7 @@ type MultiZipFs struct {
func NewMultiZipFs() *MultiZipFs {
m := &MultiZipFs{
zips: make(map[string]nodefs.Node),
zombie: make(map[string]bool),
dirZipFileMap: make(map[string]string),
FileSystem: pathfs.NewDefaultFileSystem(),
}
......@@ -116,19 +120,30 @@ func (fs *MultiZipFs) Unlink(name string, context *fuse.Context) (code fuse.Stat
if dir == CONFIG_PREFIX {
fs.lock.Lock()
defer fs.lock.Unlock()
if fs.zombie[basename] {
return fuse.ENOENT
}
root, ok := fs.zips[basename]
if ok {
code = fs.nodeFs.UnmountNode(root.Inode())
if !code.Ok() {
return code
}
delete(fs.zips, basename)
delete(fs.dirZipFileMap, basename)
return fuse.OK
} else {
if !ok {
return fuse.ENOENT
}
name := fs.dirZipFileMap[basename]
fs.zombie[basename] = true
delete(fs.zips, basename)
delete(fs.dirZipFileMap, basename)
// Drop lock to ensure that notify doesn't cause deadlock.
fs.lock.Unlock()
code = fs.nodeFs.UnmountNode(root.Inode())
fs.lock.Lock()
delete(fs.zombie, basename)
if !code.Ok() {
// Failed: reinstate
fs.zips[basename] = root
fs.dirZipFileMap[basename] = name
}
return code
}
return fuse.EPERM
}
......@@ -141,7 +156,9 @@ func (fs *MultiZipFs) Readlink(path string, context *fuse.Context) (val string,
fs.lock.Lock()
defer fs.lock.Unlock()
if fs.zombie[base] {
return "", fuse.ENOENT
}
zipfile, ok := fs.dirZipFileMap[base]
if !ok {
return "", fuse.ENOENT
......@@ -157,6 +174,9 @@ func (fs *MultiZipFs) Symlink(value string, linkName string, context *fuse.Conte
fs.lock.Lock()
defer fs.lock.Unlock()
if fs.zombie[base] {
return fuse.EBUSY
}
_, ok := fs.dirZipFileMap[base]
if ok {
......
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