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
2db031aa
Commit
2db031aa
authored
Feb 17, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lock StatFs too, and make sure no methods can ever be forgotten.
.
parent
4ad779ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
56 deletions
+84
-56
fuse/lockingfs.go
fuse/lockingfs.go
+84
-56
No files found.
fuse/lockingfs.go
View file @
2db031aa
package
fuse
import
(
"fmt"
"sync"
"time"
...
...
@@ -13,7 +14,7 @@ import (
type
LockingFileSystem
struct
{
// Should be public so people reusing can access the wrapped
// FS.
FileSystem
fs
FileSystem
lock
sync
.
Mutex
}
...
...
@@ -21,10 +22,20 @@ var _ = ((FileSystem)((*LockingFileSystem)(nil)))
func
NewLockingFileSystem
(
pfs
FileSystem
)
*
LockingFileSystem
{
l
:=
new
(
LockingFileSystem
)
l
.
FileSystem
=
pfs
l
.
fs
=
pfs
return
l
}
func
(
fs
*
LockingFileSystem
)
String
()
string
{
defer
fs
.
locked
()()
return
fs
.
fs
.
String
()
}
func
(
fs
*
LockingFileSystem
)
StatFs
(
name
string
)
*
StatfsOut
{
defer
fs
.
locked
()()
return
fs
.
fs
.
StatFs
(
name
)
}
func
(
fs
*
LockingFileSystem
)
locked
()
func
()
{
fs
.
lock
.
Lock
()
return
func
()
{
fs
.
lock
.
Unlock
()
}
...
...
@@ -32,126 +43,128 @@ func (fs *LockingFileSystem) locked() func() {
func
(
fs
*
LockingFileSystem
)
GetAttr
(
name
string
,
context
*
Context
)
(
*
Attr
,
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
GetAttr
(
name
,
context
)
return
fs
.
fs
.
GetAttr
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Readlink
(
name
string
,
context
*
Context
)
(
string
,
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Readlink
(
name
,
context
)
return
fs
.
fs
.
Readlink
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
,
context
*
Context
)
Status
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Mknod
(
name
,
mode
,
dev
,
context
)
return
fs
.
fs
.
Mknod
(
name
,
mode
,
dev
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
Context
)
Status
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Mkdir
(
name
,
mode
,
context
)
return
fs
.
fs
.
Mkdir
(
name
,
mode
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Unlink
(
name
string
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Unlink
(
name
,
context
)
return
fs
.
fs
.
Unlink
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Rmdir
(
name
string
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Rmdir
(
name
,
context
)
return
fs
.
fs
.
Rmdir
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Symlink
(
value
string
,
linkName
string
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Symlink
(
value
,
linkName
,
context
)
return
fs
.
fs
.
Symlink
(
value
,
linkName
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Rename
(
oldName
string
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Rename
(
oldName
,
newName
,
context
)
return
fs
.
fs
.
Rename
(
oldName
,
newName
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Link
(
oldName
string
,
newName
string
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Link
(
oldName
,
newName
,
context
)
return
fs
.
fs
.
Link
(
oldName
,
newName
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Chmod
(
name
string
,
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Chmod
(
name
,
mode
,
context
)
return
fs
.
fs
.
Chmod
(
name
,
mode
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Chown
(
name
string
,
uid
uint32
,
gid
uint32
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Chown
(
name
,
uid
,
gid
,
context
)
return
fs
.
fs
.
Chown
(
name
,
uid
,
gid
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Truncate
(
name
string
,
offset
uint64
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Truncate
(
name
,
offset
,
context
)
return
fs
.
fs
.
Truncate
(
name
,
offset
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
return
fs
.
FileSystem
.
Open
(
name
,
flags
,
context
)
return
fs
.
fs
.
Open
(
name
,
flags
,
context
)
}
func
(
fs
*
LockingFileSystem
)
OpenDir
(
name
string
,
context
*
Context
)
(
stream
[]
DirEntry
,
status
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
OpenDir
(
name
,
context
)
return
fs
.
fs
.
OpenDir
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
OnMount
(
nodeFs
*
PathNodeFs
)
{
defer
fs
.
locked
()()
fs
.
FileSystem
.
OnMount
(
nodeFs
)
fs
.
fs
.
OnMount
(
nodeFs
)
}
func
(
fs
*
LockingFileSystem
)
OnUnmount
()
{
defer
fs
.
locked
()()
fs
.
FileSystem
.
OnUnmount
()
fs
.
fs
.
OnUnmount
()
}
func
(
fs
*
LockingFileSystem
)
Access
(
name
string
,
mode
uint32
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Access
(
name
,
mode
,
context
)
return
fs
.
fs
.
Access
(
name
,
mode
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
Context
)
(
file
File
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Create
(
name
,
flags
,
mode
,
context
)
return
fs
.
fs
.
Create
(
name
,
flags
,
mode
,
context
)
}
func
(
fs
*
LockingFileSystem
)
Utimens
(
name
string
,
Atime
*
time
.
Time
,
Mtime
*
time
.
Time
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
Utimens
(
name
,
Atime
,
Mtime
,
context
)
return
fs
.
fs
.
Utimens
(
name
,
Atime
,
Mtime
,
context
)
}
func
(
fs
*
LockingFileSystem
)
GetXAttr
(
name
string
,
attr
string
,
context
*
Context
)
([]
byte
,
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
GetXAttr
(
name
,
attr
,
context
)
return
fs
.
fs
.
GetXAttr
(
name
,
attr
,
context
)
}
func
(
fs
*
LockingFileSystem
)
SetXAttr
(
name
string
,
attr
string
,
data
[]
byte
,
flags
int
,
context
*
Context
)
Status
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
SetXAttr
(
name
,
attr
,
data
,
flags
,
context
)
return
fs
.
fs
.
SetXAttr
(
name
,
attr
,
data
,
flags
,
context
)
}
func
(
fs
*
LockingFileSystem
)
ListXAttr
(
name
string
,
context
*
Context
)
([]
string
,
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
ListXAttr
(
name
,
context
)
return
fs
.
fs
.
ListXAttr
(
name
,
context
)
}
func
(
fs
*
LockingFileSystem
)
RemoveXAttr
(
name
string
,
attr
string
,
context
*
Context
)
Status
{
defer
fs
.
locked
()()
return
fs
.
FileSystem
.
RemoveXAttr
(
name
,
attr
,
context
)
return
fs
.
fs
.
RemoveXAttr
(
name
,
attr
,
context
)
}
////////////////////////////////////////////////////////////////
// Locking raw FS.
type
LockingRawFileSystem
struct
{
RawFileSystem
raw
RawFileSystem
lock
sync
.
Mutex
}
var
_
=
(
RawFileSystem
)((
*
LockingRawFileSystem
)(
nil
))
func
(
fs
*
LockingRawFileSystem
)
locked
()
func
()
{
fs
.
lock
.
Lock
()
return
func
()
{
fs
.
lock
.
Unlock
()
}
...
...
@@ -159,152 +172,167 @@ func (fs *LockingRawFileSystem) locked() func() {
func
NewLockingRawFileSystem
(
rfs
RawFileSystem
)
*
LockingRawFileSystem
{
l
:=
&
LockingRawFileSystem
{}
l
.
RawFileSystem
=
rfs
l
.
raw
=
rfs
return
l
}
func
(
fs
*
LockingRawFileSystem
)
Lookup
(
out
*
raw
.
EntryOut
,
h
*
Context
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Lookup
(
out
,
h
,
name
)
return
fs
.
raw
.
Lookup
(
out
,
h
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
Forget
(
nodeID
uint64
,
nlookup
uint64
)
{
defer
fs
.
locked
()()
fs
.
RawFileSystem
.
Forget
(
nodeID
,
nlookup
)
fs
.
raw
.
Forget
(
nodeID
,
nlookup
)
}
func
(
fs
*
LockingRawFileSystem
)
GetAttr
(
out
*
raw
.
AttrOut
,
header
*
Context
,
input
*
raw
.
GetAttrIn
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
GetAttr
(
out
,
header
,
input
)
return
fs
.
raw
.
GetAttr
(
out
,
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Open
(
out
*
raw
.
OpenOut
,
header
*
Context
,
input
*
raw
.
OpenIn
)
(
status
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Open
(
out
,
header
,
input
)
return
fs
.
raw
.
Open
(
out
,
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
SetAttr
(
out
*
raw
.
AttrOut
,
header
*
Context
,
input
*
raw
.
SetAttrIn
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
SetAttr
(
out
,
header
,
input
)
return
fs
.
raw
.
SetAttr
(
out
,
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Readlink
(
header
*
Context
)
(
out
[]
byte
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Readlink
(
header
)
return
fs
.
raw
.
Readlink
(
header
)
}
func
(
fs
*
LockingRawFileSystem
)
Mknod
(
out
*
raw
.
EntryOut
,
header
*
Context
,
input
*
raw
.
MknodIn
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Mknod
(
out
,
header
,
input
,
name
)
return
fs
.
raw
.
Mknod
(
out
,
header
,
input
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
Mkdir
(
out
*
raw
.
EntryOut
,
header
*
Context
,
input
*
raw
.
MkdirIn
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Mkdir
(
out
,
header
,
input
,
name
)
return
fs
.
raw
.
Mkdir
(
out
,
header
,
input
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
Unlink
(
header
*
Context
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Unlink
(
header
,
name
)
return
fs
.
raw
.
Unlink
(
header
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
Rmdir
(
header
*
Context
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Rmdir
(
header
,
name
)
return
fs
.
raw
.
Rmdir
(
header
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
Symlink
(
out
*
raw
.
EntryOut
,
header
*
Context
,
pointedTo
string
,
linkName
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Symlink
(
out
,
header
,
pointedTo
,
linkName
)
return
fs
.
raw
.
Symlink
(
out
,
header
,
pointedTo
,
linkName
)
}
func
(
fs
*
LockingRawFileSystem
)
Rename
(
header
*
Context
,
input
*
raw
.
RenameIn
,
oldName
string
,
newName
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Rename
(
header
,
input
,
oldName
,
newName
)
return
fs
.
raw
.
Rename
(
header
,
input
,
oldName
,
newName
)
}
func
(
fs
*
LockingRawFileSystem
)
Link
(
out
*
raw
.
EntryOut
,
header
*
Context
,
input
*
raw
.
LinkIn
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Link
(
out
,
header
,
input
,
name
)
return
fs
.
raw
.
Link
(
out
,
header
,
input
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
SetXAttr
(
header
*
Context
,
input
*
raw
.
SetXAttrIn
,
attr
string
,
data
[]
byte
)
Status
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
SetXAttr
(
header
,
input
,
attr
,
data
)
return
fs
.
raw
.
SetXAttr
(
header
,
input
,
attr
,
data
)
}
func
(
fs
*
LockingRawFileSystem
)
GetXAttrData
(
header
*
Context
,
attr
string
)
(
data
[]
byte
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
GetXAttrData
(
header
,
attr
)
return
fs
.
raw
.
GetXAttrData
(
header
,
attr
)
}
func
(
fs
*
LockingRawFileSystem
)
GetXAttrSize
(
header
*
Context
,
attr
string
)
(
sz
int
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
GetXAttrSize
(
header
,
attr
)
return
fs
.
raw
.
GetXAttrSize
(
header
,
attr
)
}
func
(
fs
*
LockingRawFileSystem
)
ListXAttr
(
header
*
Context
)
(
data
[]
byte
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
ListXAttr
(
header
)
return
fs
.
raw
.
ListXAttr
(
header
)
}
func
(
fs
*
LockingRawFileSystem
)
RemoveXAttr
(
header
*
Context
,
attr
string
)
Status
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
RemoveXAttr
(
header
,
attr
)
return
fs
.
raw
.
RemoveXAttr
(
header
,
attr
)
}
func
(
fs
*
LockingRawFileSystem
)
Access
(
header
*
Context
,
input
*
raw
.
AccessIn
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Access
(
header
,
input
)
return
fs
.
raw
.
Access
(
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Create
(
out
*
raw
.
CreateOut
,
header
*
Context
,
input
*
raw
.
CreateIn
,
name
string
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Create
(
out
,
header
,
input
,
name
)
return
fs
.
raw
.
Create
(
out
,
header
,
input
,
name
)
}
func
(
fs
*
LockingRawFileSystem
)
OpenDir
(
out
*
raw
.
OpenOut
,
header
*
Context
,
input
*
raw
.
OpenIn
)
(
status
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
OpenDir
(
out
,
header
,
input
)
return
fs
.
raw
.
OpenDir
(
out
,
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Release
(
header
*
Context
,
input
*
raw
.
ReleaseIn
)
{
defer
fs
.
locked
()()
fs
.
RawFileSystem
.
Release
(
header
,
input
)
fs
.
raw
.
Release
(
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
ReleaseDir
(
header
*
Context
,
h
*
raw
.
ReleaseIn
)
{
defer
fs
.
locked
()()
fs
.
RawFileSystem
.
ReleaseDir
(
header
,
h
)
fs
.
raw
.
ReleaseDir
(
header
,
h
)
}
func
(
fs
*
LockingRawFileSystem
)
Read
(
header
*
Context
,
input
*
raw
.
ReadIn
,
buf
[]
byte
)
(
ReadResult
,
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Read
(
header
,
input
,
buf
)
return
fs
.
raw
.
Read
(
header
,
input
,
buf
)
}
func
(
fs
*
LockingRawFileSystem
)
Write
(
header
*
Context
,
input
*
raw
.
WriteIn
,
data
[]
byte
)
(
written
uint32
,
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Write
(
header
,
input
,
data
)
return
fs
.
raw
.
Write
(
header
,
input
,
data
)
}
func
(
fs
*
LockingRawFileSystem
)
Flush
(
header
*
Context
,
input
*
raw
.
FlushIn
)
Status
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Flush
(
header
,
input
)
return
fs
.
raw
.
Flush
(
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Fsync
(
header
*
Context
,
input
*
raw
.
FsyncIn
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
Fsync
(
header
,
input
)
return
fs
.
raw
.
Fsync
(
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
ReadDir
(
out
*
DirEntryList
,
header
*
Context
,
input
*
raw
.
ReadIn
)
Status
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
ReadDir
(
out
,
header
,
input
)
return
fs
.
raw
.
ReadDir
(
out
,
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
FsyncDir
(
header
*
Context
,
input
*
raw
.
FsyncIn
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
RawFileSystem
.
FsyncDir
(
header
,
input
)
return
fs
.
raw
.
FsyncDir
(
header
,
input
)
}
func
(
fs
*
LockingRawFileSystem
)
Init
(
params
*
RawFsInit
)
{
defer
fs
.
locked
()()
fs
.
raw
.
Init
(
params
)
}
func
(
fs
*
LockingRawFileSystem
)
StatFs
(
out
*
StatfsOut
,
context
*
Context
)
(
code
Status
)
{
defer
fs
.
locked
()()
return
fs
.
raw
.
StatFs
(
out
,
context
)
}
func
(
fs
*
LockingRawFileSystem
)
String
()
string
{
defer
fs
.
locked
()()
return
fmt
.
Sprintf
(
"Locked(%s)"
,
fs
.
raw
.
String
())
}
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