Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
76583006
Commit
76583006
authored
Sep 05, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide members of inode.
parent
94429a4b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
70 deletions
+69
-70
fuse/fsconnector.go
fuse/fsconnector.go
+28
-29
fuse/fsmount.go
fuse/fsmount.go
+9
-9
fuse/fsops.go
fuse/fsops.go
+4
-4
fuse/inode.go
fuse/inode.go
+28
-28
No files found.
fuse/fsconnector.go
View file @
76583006
package
fuse
// This file contains the internal logic of the
// FileSystemConnector. The functions for satisfying the raw interface are in
// fsops.go
...
...
@@ -43,7 +42,7 @@ func NewFileSystemConnector(fs FileSystem, opts *FileSystemOptions) (me *FileSys
}
me
.
inodeMap
=
NewHandleMap
(
!
opts
.
SkipCheckHandles
)
me
.
rootNode
=
me
.
newInode
(
true
)
me
.
rootNode
.
N
odeId
=
FUSE_ROOT_ID
me
.
rootNode
.
n
odeId
=
FUSE_ROOT_ID
me
.
verify
()
me
.
mountRoot
(
fs
,
opts
)
return
me
...
...
@@ -59,11 +58,11 @@ func (me *FileSystemConnector) verify() {
func
(
me
*
FileSystemConnector
)
newInode
(
isDir
bool
)
*
inode
{
data
:=
new
(
inode
)
data
.
NodeId
=
me
.
inodeMap
.
Register
(
&
data
.
H
andled
)
data
.
nodeId
=
me
.
inodeMap
.
Register
(
&
data
.
h
andled
)
data
.
fsInode
=
new
(
fsInode
)
data
.
fsInode
.
inode
=
data
if
isDir
{
data
.
C
hildren
=
make
(
map
[
string
]
*
inode
,
initDirSize
)
data
.
c
hildren
=
make
(
map
[
string
]
*
inode
,
initDirSize
)
}
return
data
...
...
@@ -75,29 +74,29 @@ func (me *FileSystemConnector) lookupUpdate(parent *inode, name string, isDir bo
parent
.
treeLock
.
Lock
()
defer
parent
.
treeLock
.
Unlock
()
data
,
ok
:=
parent
.
C
hildren
[
name
]
data
,
ok
:=
parent
.
c
hildren
[
name
]
if
!
ok
{
data
=
me
.
newInode
(
isDir
)
parent
.
addChild
(
name
,
data
)
data
.
mount
=
parent
.
mount
data
.
treeLock
=
&
data
.
mount
.
treeLock
}
data
.
L
ookupCount
+=
lookupCount
data
.
l
ookupCount
+=
lookupCount
return
data
}
func
(
me
*
FileSystemConnector
)
lookupMount
(
parent
*
inode
,
name
string
,
lookupCount
int
)
(
mount
*
fileSystemMount
)
{
parent
.
treeLock
.
RLock
()
defer
parent
.
treeLock
.
RUnlock
()
if
parent
.
M
ounts
==
nil
{
if
parent
.
m
ounts
==
nil
{
return
nil
}
mount
,
ok
:=
parent
.
M
ounts
[
name
]
mount
,
ok
:=
parent
.
m
ounts
[
name
]
if
ok
{
mount
.
treeLock
.
Lock
()
defer
mount
.
treeLock
.
Unlock
()
mount
.
mountInode
.
L
ookupCount
+=
lookupCount
mount
.
mountInode
.
l
ookupCount
+=
lookupCount
return
mount
}
return
nil
...
...
@@ -118,13 +117,13 @@ func (me *FileSystemConnector) forgetUpdate(nodeId uint64, forgetCount int) {
node
.
treeLock
.
Lock
()
defer
node
.
treeLock
.
Unlock
()
node
.
L
ookupCount
-=
forgetCount
node
.
l
ookupCount
-=
forgetCount
me
.
considerDropInode
(
node
)
}
func
(
me
*
FileSystemConnector
)
considerDropInode
(
n
*
inode
)
(
drop
bool
)
{
delChildren
:=
[]
string
{}
for
k
,
v
:=
range
n
.
C
hildren
{
for
k
,
v
:=
range
n
.
c
hildren
{
if
v
.
mountPoint
==
nil
&&
me
.
considerDropInode
(
v
)
{
delChildren
=
append
(
delChildren
,
k
)
}
...
...
@@ -134,19 +133,19 @@ func (me *FileSystemConnector) considerDropInode(n *inode) (drop bool) {
if
ch
==
nil
{
panic
(
fmt
.
Sprintf
(
"trying to del child %q, but not present"
,
k
))
}
me
.
inodeMap
.
Forget
(
ch
.
N
odeId
)
me
.
inodeMap
.
Forget
(
ch
.
n
odeId
)
}
if
len
(
n
.
Children
)
>
0
||
n
.
L
ookupCount
>
0
{
if
len
(
n
.
children
)
>
0
||
n
.
l
ookupCount
>
0
{
return
false
}
if
n
==
me
.
rootNode
||
n
.
mountPoint
!=
nil
{
return
false
}
n
.
O
penFilesMutex
.
Lock
()
defer
n
.
O
penFilesMutex
.
Unlock
()
return
len
(
n
.
O
penFiles
)
==
0
n
.
o
penFilesMutex
.
Lock
()
defer
n
.
o
penFilesMutex
.
Unlock
()
return
len
(
n
.
o
penFiles
)
==
0
}
func
(
me
*
FileSystemConnector
)
renameUpdate
(
oldParent
*
inode
,
oldName
string
,
newParent
*
inode
,
newName
string
)
{
...
...
@@ -196,7 +195,7 @@ func (me *FileSystemConnector) findLastKnownInode(fullPath string) (*inode, []st
defer
node
.
mountPoint
.
treeLock
.
RUnlock
()
}
next
:=
node
.
C
hildren
[
component
]
next
:=
node
.
c
hildren
[
component
]
if
next
==
nil
{
return
node
,
comps
[
i
:
]
}
...
...
@@ -250,7 +249,7 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
if
parent
.
mount
==
nil
{
return
ENOENT
}
node
:=
parent
.
C
hildren
[
base
]
node
:=
parent
.
c
hildren
[
base
]
if
node
!=
nil
{
return
EBUSY
}
...
...
@@ -263,10 +262,10 @@ func (me *FileSystemConnector) Mount(mountPoint string, fs FileSystem, opts *Fil
node
.
mountFs
(
fs
,
opts
)
parent
.
addChild
(
base
,
node
)
if
parent
.
M
ounts
==
nil
{
parent
.
M
ounts
=
make
(
map
[
string
]
*
fileSystemMount
)
if
parent
.
m
ounts
==
nil
{
parent
.
m
ounts
=
make
(
map
[
string
]
*
fileSystemMount
)
}
parent
.
M
ounts
[
base
]
=
node
.
mountPoint
parent
.
m
ounts
[
base
]
=
node
.
mountPoint
if
me
.
Debug
{
log
.
Println
(
"Mount: "
,
fs
,
"on dir"
,
mountPoint
,
"parent"
,
parent
)
...
...
@@ -301,7 +300,7 @@ func (me *FileSystemConnector) Unmount(path string) Status {
parentNode
.
treeLock
.
Lock
()
defer
parentNode
.
treeLock
.
Unlock
()
mount
:=
parentNode
.
M
ounts
[
name
]
mount
:=
parentNode
.
m
ounts
[
name
]
if
mount
==
nil
{
return
EINVAL
}
...
...
@@ -318,11 +317,11 @@ func (me *FileSystemConnector) Unmount(path string) Status {
mount
.
mountInode
=
nil
mountInode
.
mountPoint
=
nil
parentNode
.
M
ounts
[
name
]
=
nil
,
false
parentNode
.
C
hildren
[
name
]
=
nil
,
false
parentNode
.
m
ounts
[
name
]
=
nil
,
false
parentNode
.
c
hildren
[
name
]
=
nil
,
false
mount
.
fs
.
Unmount
()
me
.
fsInit
.
EntryNotify
(
parentNode
.
N
odeId
,
name
)
me
.
fsInit
.
EntryNotify
(
parentNode
.
n
odeId
,
name
)
return
OK
}
...
...
@@ -336,7 +335,7 @@ func (me *FileSystemConnector) FileNotify(path string, off int64, length int64)
out
:=
NotifyInvalInodeOut
{
Length
:
length
,
Off
:
off
,
Ino
:
node
.
N
odeId
,
Ino
:
node
.
n
odeId
,
}
return
me
.
fsInit
.
InodeNotify
(
&
out
)
}
...
...
@@ -347,16 +346,16 @@ func (me *FileSystemConnector) EntryNotify(dir string, name string) Status {
return
ENOENT
}
return
me
.
fsInit
.
EntryNotify
(
node
.
N
odeId
,
name
)
return
me
.
fsInit
.
EntryNotify
(
node
.
n
odeId
,
name
)
}
func
(
me
*
FileSystemConnector
)
Notify
(
path
string
)
Status
{
node
,
rest
:=
me
.
findLastKnownInode
(
path
)
if
len
(
rest
)
>
0
{
return
me
.
fsInit
.
EntryNotify
(
node
.
N
odeId
,
rest
[
0
])
return
me
.
fsInit
.
EntryNotify
(
node
.
n
odeId
,
rest
[
0
])
}
out
:=
NotifyInvalInodeOut
{
Ino
:
node
.
N
odeId
,
Ino
:
node
.
n
odeId
,
}
return
me
.
fsInit
.
InodeNotify
(
&
out
)
}
fuse/fsmount.go
View file @
76583006
...
...
@@ -70,27 +70,27 @@ func (me *FileSystemConnector) getOpenedFile(h uint64) *openedFile {
func
(
me
*
fileSystemMount
)
unregisterFileHandle
(
handle
uint64
,
node
*
inode
)
*
openedFile
{
obj
:=
me
.
openFiles
.
Forget
(
handle
)
opened
:=
(
*
openedFile
)(
unsafe
.
Pointer
(
obj
))
node
.
O
penFilesMutex
.
Lock
()
defer
node
.
O
penFilesMutex
.
Unlock
()
node
.
o
penFilesMutex
.
Lock
()
defer
node
.
o
penFilesMutex
.
Unlock
()
idx
:=
-
1
for
i
,
v
:=
range
node
.
O
penFiles
{
for
i
,
v
:=
range
node
.
o
penFiles
{
if
v
==
opened
{
idx
=
i
break
}
}
l
:=
len
(
node
.
O
penFiles
)
node
.
OpenFiles
[
idx
]
=
node
.
O
penFiles
[
l
-
1
]
node
.
OpenFiles
=
node
.
O
penFiles
[
:
l
-
1
]
l
:=
len
(
node
.
o
penFiles
)
node
.
openFiles
[
idx
]
=
node
.
o
penFiles
[
l
-
1
]
node
.
openFiles
=
node
.
o
penFiles
[
:
l
-
1
]
return
opened
}
func
(
me
*
fileSystemMount
)
registerFileHandle
(
node
*
inode
,
dir
rawDir
,
f
File
,
flags
uint32
)
(
uint64
,
*
openedFile
)
{
node
.
O
penFilesMutex
.
Lock
()
defer
node
.
O
penFilesMutex
.
Unlock
()
node
.
o
penFilesMutex
.
Lock
()
defer
node
.
o
penFilesMutex
.
Unlock
()
b
:=
&
openedFile
{
dir
:
dir
,
file
:
f
,
...
...
@@ -103,7 +103,7 @@ func (me *fileSystemMount) registerFileHandle(node *inode, dir rawDir, f File, f
f
=
withFlags
.
File
}
node
.
OpenFiles
=
append
(
node
.
O
penFiles
,
b
)
node
.
openFiles
=
append
(
node
.
o
penFiles
,
b
)
handle
:=
me
.
openFiles
.
Register
(
&
b
.
Handled
)
return
handle
,
b
}
fuse/fsops.go
View file @
76583006
...
...
@@ -32,9 +32,9 @@ func (me *FileSystemConnector) internalMountLookup(mount *fileSystemMount, looku
}
mount
.
treeLock
.
Lock
()
defer
mount
.
treeLock
.
Unlock
()
mount
.
mountInode
.
L
ookupCount
+=
lookupCount
mount
.
mountInode
.
l
ookupCount
+=
lookupCount
out
=
&
EntryOut
{
NodeId
:
mount
.
mountInode
.
N
odeId
,
NodeId
:
mount
.
mountInode
.
n
odeId
,
Generation
:
1
,
// where to get the generation?
}
mount
.
fileInfoToEntry
(
fi
,
out
)
...
...
@@ -56,11 +56,11 @@ func (me *FileSystemConnector) internalLookup(parent *inode, name string, lookup
}
node
=
me
.
lookupUpdate
(
parent
,
name
,
fi
.
IsDirectory
(),
lookupCount
)
out
=
&
EntryOut
{
NodeId
:
node
.
N
odeId
,
NodeId
:
node
.
n
odeId
,
Generation
:
1
,
// where to get the generation?
}
parent
.
mount
.
fileInfoToEntry
(
fi
,
out
)
out
.
Attr
.
Ino
=
node
.
N
odeId
out
.
Attr
.
Ino
=
node
.
n
odeId
return
out
,
OK
,
node
}
...
...
fuse/inode.go
View file @
76583006
...
...
@@ -7,14 +7,14 @@ import (
// The inode reflects the kernel's idea of the inode.
type
inode
struct
{
Handled
handled
Handled
// Constant during lifetime.
N
odeId
uint64
n
odeId
uint64
// Number of open files and its protection.
O
penFilesMutex
sync
.
Mutex
O
penFiles
[]
*
openedFile
o
penFilesMutex
sync
.
Mutex
o
penFiles
[]
*
openedFile
// treeLock is a pointer to me.mount.treeLock; we need store
// this mutex separately, since unmount may set me.mount = nil
...
...
@@ -27,12 +27,12 @@ type inode struct {
// All data below is protected by treeLock.
fsInode
*
fsInode
C
hildren
map
[
string
]
*
inode
c
hildren
map
[
string
]
*
inode
// Contains directories that function as mounts. The entries
// are duplicated in
C
hildren.
M
ounts
map
[
string
]
*
fileSystemMount
L
ookupCount
int
// are duplicated in
c
hildren.
m
ounts
map
[
string
]
*
fileSystemMount
l
ookupCount
int
// Non-nil if this is a mountpoint.
mountPoint
*
fileSystemMount
...
...
@@ -46,21 +46,21 @@ type inode struct {
// Must be called with treeLock for the mount held.
func
(
me
*
inode
)
addChild
(
name
string
,
child
*
inode
)
{
if
paranoia
{
ch
:=
me
.
C
hildren
[
name
]
ch
:=
me
.
c
hildren
[
name
]
if
ch
!=
nil
{
panic
(
fmt
.
Sprintf
(
"Already have an inode with same name: %v: %v"
,
name
,
ch
))
}
}
me
.
C
hildren
[
name
]
=
child
me
.
c
hildren
[
name
]
=
child
me
.
fsInode
.
addChild
(
name
,
child
.
fsInode
)
}
// Must be called with treeLock for the mount held.
func
(
me
*
inode
)
rmChild
(
name
string
)
(
ch
*
inode
)
{
ch
=
me
.
C
hildren
[
name
]
ch
=
me
.
c
hildren
[
name
]
if
ch
!=
nil
{
me
.
C
hildren
[
name
]
=
nil
,
false
me
.
c
hildren
[
name
]
=
nil
,
false
me
.
fsInode
.
rmChild
(
name
,
ch
.
fsInode
)
}
return
ch
...
...
@@ -80,7 +80,7 @@ func (me *inode) mountFs(fs FileSystem, opts *FileSystemOptions) {
// Must be called with treeLock held.
func
(
me
*
inode
)
canUnmount
()
bool
{
for
_
,
v
:=
range
me
.
C
hildren
{
for
_
,
v
:=
range
me
.
c
hildren
{
if
v
.
mountPoint
!=
nil
{
// This access may be out of date, but it is no
// problem to err on the safe side.
...
...
@@ -91,20 +91,20 @@ func (me *inode) canUnmount() bool {
}
}
me
.
O
penFilesMutex
.
Lock
()
defer
me
.
O
penFilesMutex
.
Unlock
()
return
len
(
me
.
O
penFiles
)
==
0
me
.
o
penFilesMutex
.
Lock
()
defer
me
.
o
penFilesMutex
.
Unlock
()
return
len
(
me
.
o
penFiles
)
==
0
}
func
(
me
*
inode
)
IsDir
()
bool
{
return
me
.
C
hildren
!=
nil
return
me
.
c
hildren
!=
nil
}
func
(
me
*
inode
)
getMountDirEntries
()
(
out
[]
DirEntry
)
{
me
.
treeLock
.
RLock
()
defer
me
.
treeLock
.
RUnlock
()
for
k
,
_
:=
range
me
.
M
ounts
{
for
k
,
_
:=
range
me
.
m
ounts
{
out
=
append
(
out
,
DirEntry
{
Name
:
k
,
Mode
:
S_IFDIR
,
...
...
@@ -115,10 +115,10 @@ func (me *inode) getMountDirEntries() (out []DirEntry) {
// Returns any open file, preferably a r/w one.
func
(
me
*
inode
)
getAnyFile
()
(
file
File
)
{
me
.
O
penFilesMutex
.
Lock
()
defer
me
.
O
penFilesMutex
.
Unlock
()
me
.
o
penFilesMutex
.
Lock
()
defer
me
.
o
penFilesMutex
.
Unlock
()
for
_
,
f
:=
range
me
.
O
penFiles
{
for
_
,
f
:=
range
me
.
o
penFiles
{
if
file
==
nil
||
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
file
=
f
.
file
}
...
...
@@ -128,10 +128,10 @@ func (me *inode) getAnyFile() (file File) {
// Returns an open writable file for the given inode.
func
(
me
*
inode
)
getWritableFiles
()
(
files
[]
File
)
{
me
.
O
penFilesMutex
.
Lock
()
defer
me
.
O
penFilesMutex
.
Unlock
()
me
.
o
penFilesMutex
.
Lock
()
defer
me
.
o
penFilesMutex
.
Unlock
()
for
_
,
f
:=
range
me
.
O
penFiles
{
for
_
,
f
:=
range
me
.
o
penFiles
{
if
f
.
OpenFlags
&
O_ANYWRITE
!=
0
{
files
=
append
(
files
,
f
.
file
)
}
...
...
@@ -152,14 +152,14 @@ func (me *inode) verify(cur *fileSystemMount) {
panic
(
fmt
.
Sprintf
(
"me.mount not set correctly %v %v"
,
me
.
mount
,
cur
))
}
for
name
,
m
:=
range
me
.
M
ounts
{
if
m
.
mountInode
!=
me
.
C
hildren
[
name
]
{
for
name
,
m
:=
range
me
.
m
ounts
{
if
m
.
mountInode
!=
me
.
c
hildren
[
name
]
{
panic
(
fmt
.
Sprintf
(
"mountpoint parent mismatch: node:%v name:%v ch:%v"
,
me
.
mountPoint
,
name
,
me
.
C
hildren
))
me
.
mountPoint
,
name
,
me
.
c
hildren
))
}
}
for
_
,
ch
:=
range
me
.
C
hildren
{
for
_
,
ch
:=
range
me
.
c
hildren
{
if
ch
==
nil
{
panic
(
"Found nil child."
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment