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
Levin Zimmermann
go-fuse
Commits
8cc0e864
Commit
8cc0e864
authored
Apr 11, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a locking filesystem wrapper.
parent
2d1f043d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
328 additions
and
0 deletions
+328
-0
fuse/Makefile
fuse/Makefile
+1
-0
fuse/lockingfs.go
fuse/lockingfs.go
+327
-0
No files found.
fuse/Makefile
View file @
8cc0e864
...
...
@@ -13,6 +13,7 @@ GOFILES=misc.go\
bufferpool.go
\
default.go
\
datafile.go
\
lockingfs.go
\
loopback.go
\
wrappedfs.go
\
timingfs.go
\
...
...
fuse/lockingfs.go
0 → 100644
View file @
8cc0e864
package
fuse
import
(
"sync"
)
// This is a wrapper that makes a PathFilesystem threadsafe by
// trivially locking all operations. For improved performance, you
// should probably invent do your own locking inside the file system.
type
LockingPathFilesystem
struct
{
// Should be public so people reusing can access the wrapped
// FS.
WrappingPathFilesystem
lock
sync
.
Mutex
}
func
NewLockingPathFilesystem
(
pfs
PathFilesystem
)
*
LockingPathFilesystem
{
l
:=
new
(
LockingPathFilesystem
)
l
.
Original
=
pfs
return
l
}
func
(
me
*
LockingPathFilesystem
)
GetAttr
(
name
string
)
(
*
Attr
,
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
GetAttr
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
Readlink
(
name
string
)
(
string
,
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Readlink
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
Mknod
(
name
string
,
mode
uint32
,
dev
uint32
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Mknod
(
name
,
mode
,
dev
)
}
func
(
me
*
LockingPathFilesystem
)
Mkdir
(
name
string
,
mode
uint32
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Mkdir
(
name
,
mode
)
}
func
(
me
*
LockingPathFilesystem
)
Unlink
(
name
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Unlink
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
Rmdir
(
name
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Rmdir
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
Symlink
(
value
string
,
linkName
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Symlink
(
value
,
linkName
)
}
func
(
me
*
LockingPathFilesystem
)
Rename
(
oldName
string
,
newName
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Rename
(
oldName
,
newName
)
}
func
(
me
*
LockingPathFilesystem
)
Link
(
oldName
string
,
newName
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Link
(
oldName
,
newName
)
}
func
(
me
*
LockingPathFilesystem
)
Chmod
(
name
string
,
mode
uint32
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Chmod
(
name
,
mode
)
}
func
(
me
*
LockingPathFilesystem
)
Chown
(
name
string
,
uid
uint32
,
gid
uint32
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Chown
(
name
,
uid
,
gid
)
}
func
(
me
*
LockingPathFilesystem
)
Truncate
(
name
string
,
offset
uint64
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Truncate
(
name
,
offset
)
}
func
(
me
*
LockingPathFilesystem
)
Open
(
name
string
,
flags
uint32
)
(
file
RawFuseFile
,
code
Status
)
{
return
me
.
Original
.
Open
(
name
,
flags
)
}
func
(
me
*
LockingPathFilesystem
)
OpenDir
(
name
string
)
(
stream
chan
DirEntry
,
status
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
OpenDir
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
Mount
(
conn
*
PathFileSystemConnector
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Mount
(
conn
)
}
func
(
me
*
LockingPathFilesystem
)
Unmount
()
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
me
.
Original
.
Unmount
()
}
func
(
me
*
LockingPathFilesystem
)
Access
(
name
string
,
mode
uint32
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Access
(
name
,
mode
)
}
func
(
me
*
LockingPathFilesystem
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
)
(
file
RawFuseFile
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Create
(
name
,
flags
,
mode
)
}
func
(
me
*
LockingPathFilesystem
)
Utimens
(
name
string
,
AtimeNs
uint64
,
CtimeNs
uint64
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Utimens
(
name
,
AtimeNs
,
CtimeNs
)
}
func
(
me
*
LockingPathFilesystem
)
GetXAttr
(
name
string
,
attr
string
)
([]
byte
,
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
GetXAttr
(
name
,
attr
)
}
func
(
me
*
LockingPathFilesystem
)
SetXAttr
(
name
string
,
attr
string
,
data
[]
byte
,
flags
int
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
SetXAttr
(
name
,
attr
,
data
,
flags
)
}
func
(
me
*
LockingPathFilesystem
)
ListXAttr
(
name
string
)
([]
string
,
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
ListXAttr
(
name
)
}
func
(
me
*
LockingPathFilesystem
)
RemoveXAttr
(
name
string
,
attr
string
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
RemoveXAttr
(
name
,
attr
)
}
////////////////////////////////////////////////////////////////
// Locking raw FS.
type
LockingRawFilesystem
struct
{
WrappingRawFilesystem
lock
sync
.
Mutex
}
func
(
me
*
LockingRawFilesystem
)
Init
(
h
*
InHeader
,
input
*
InitIn
)
(
*
InitOut
,
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Init
(
h
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Destroy
(
h
*
InHeader
,
input
*
InitIn
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
me
.
Original
.
Destroy
(
h
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Lookup
(
h
*
InHeader
,
name
string
)
(
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Lookup
(
h
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Forget
(
h
*
InHeader
,
input
*
ForgetIn
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
me
.
Original
.
Forget
(
h
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
GetAttr
(
header
*
InHeader
,
input
*
GetAttrIn
)
(
out
*
AttrOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
GetAttr
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Open
(
header
*
InHeader
,
input
*
OpenIn
)
(
flags
uint32
,
fuseFile
RawFuseFile
,
status
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Open
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
SetAttr
(
header
*
InHeader
,
input
*
SetAttrIn
)
(
out
*
AttrOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
SetAttr
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Readlink
(
header
*
InHeader
)
(
out
[]
byte
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Readlink
(
header
)
}
func
(
me
*
LockingRawFilesystem
)
Mknod
(
header
*
InHeader
,
input
*
MknodIn
,
name
string
)
(
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Mknod
(
header
,
input
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Mkdir
(
header
*
InHeader
,
input
*
MkdirIn
,
name
string
)
(
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Mkdir
(
header
,
input
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Unlink
(
header
*
InHeader
,
name
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Unlink
(
header
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Rmdir
(
header
*
InHeader
,
name
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Rmdir
(
header
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Symlink
(
header
*
InHeader
,
pointedTo
string
,
linkName
string
)
(
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Symlink
(
header
,
pointedTo
,
linkName
)
}
func
(
me
*
LockingRawFilesystem
)
Rename
(
header
*
InHeader
,
input
*
RenameIn
,
oldName
string
,
newName
string
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Rename
(
header
,
input
,
oldName
,
newName
)
}
func
(
me
*
LockingRawFilesystem
)
Link
(
header
*
InHeader
,
input
*
LinkIn
,
name
string
)
(
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Link
(
header
,
input
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
SetXAttr
(
header
*
InHeader
,
input
*
SetXAttrIn
,
attr
string
,
data
[]
byte
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
SetXAttr
(
header
,
input
,
attr
,
data
)
}
func
(
me
*
LockingRawFilesystem
)
GetXAttr
(
header
*
InHeader
,
attr
string
)
(
data
[]
byte
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
GetXAttr
(
header
,
attr
)
}
func
(
me
*
LockingRawFilesystem
)
ListXAttr
(
header
*
InHeader
)
(
data
[]
byte
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
ListXAttr
(
header
)
}
func
(
me
*
LockingRawFilesystem
)
RemoveXAttr
(
header
*
InHeader
,
attr
string
)
Status
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
RemoveXAttr
(
header
,
attr
)
}
func
(
me
*
LockingRawFilesystem
)
Access
(
header
*
InHeader
,
input
*
AccessIn
)
(
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Access
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Create
(
header
*
InHeader
,
input
*
CreateIn
,
name
string
)
(
flags
uint32
,
fuseFile
RawFuseFile
,
out
*
EntryOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Create
(
header
,
input
,
name
)
}
func
(
me
*
LockingRawFilesystem
)
Bmap
(
header
*
InHeader
,
input
*
BmapIn
)
(
out
*
BmapOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Bmap
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Ioctl
(
header
*
InHeader
,
input
*
IoctlIn
)
(
out
*
IoctlOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Ioctl
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Poll
(
header
*
InHeader
,
input
*
PollIn
)
(
out
*
PollOut
,
code
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
Poll
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
OpenDir
(
header
*
InHeader
,
input
*
OpenIn
)
(
flags
uint32
,
fuseFile
RawFuseDir
,
status
Status
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
return
me
.
Original
.
OpenDir
(
header
,
input
)
}
func
(
me
*
LockingRawFilesystem
)
Release
(
header
*
InHeader
,
f
RawFuseFile
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
me
.
Original
.
Release
(
header
,
f
)
}
func
(
me
*
LockingRawFilesystem
)
ReleaseDir
(
header
*
InHeader
,
f
RawFuseDir
)
{
me
.
lock
.
Lock
()
defer
me
.
lock
.
Unlock
()
me
.
Original
.
ReleaseDir
(
header
,
f
)
}
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