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
e663cddc
Commit
e663cddc
authored
Jun 28, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
In pathfs.LockingFileSystem, lock file operations too.
parent
d7ac6b93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
4 deletions
+107
-4
fuse/nodefs/lockingfile.go
fuse/nodefs/lockingfile.go
+100
-0
fuse/pathfs/locking.go
fuse/pathfs/locking.go
+7
-4
No files found.
fuse/nodefs/lockingfile.go
0 → 100644
View file @
e663cddc
package
nodefs
import
(
"fmt"
"time"
"sync"
"github.com/hanwen/go-fuse/fuse"
)
type
lockingFile
struct
{
mu
*
sync
.
Mutex
file
File
}
// NewDefaultFile returns a File instance that returns ENOSYS for
// every operation.
func
NewLockingFile
(
mu
*
sync
.
Mutex
,
f
File
)
File
{
return
&
lockingFile
{
mu
:
mu
,
file
:
f
,
}
}
func
(
f
*
lockingFile
)
SetInode
(
*
Inode
)
{
}
func
(
f
*
lockingFile
)
InnerFile
()
File
{
return
nil
}
func
(
f
*
lockingFile
)
String
()
string
{
return
fmt
.
Sprintf
(
"lockingFile(%s)"
,
f
.
file
.
String
())
}
func
(
f
*
lockingFile
)
Read
(
buf
[]
byte
,
off
int64
)
(
fuse
.
ReadResult
,
fuse
.
Status
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Read
(
buf
,
off
)
}
func
(
f
*
lockingFile
)
Write
(
data
[]
byte
,
off
int64
)
(
uint32
,
fuse
.
Status
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Write
(
data
,
off
)
}
func
(
f
*
lockingFile
)
Flush
()
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Flush
()
}
func
(
f
*
lockingFile
)
Release
()
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
f
.
file
.
Release
()
}
func
(
f
*
lockingFile
)
GetAttr
(
a
*
fuse
.
Attr
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
GetAttr
(
a
)
}
func
(
f
*
lockingFile
)
Fsync
(
flags
int
)
(
code
fuse
.
Status
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Fsync
(
flags
)
}
func
(
f
*
lockingFile
)
Utimens
(
atime
*
time
.
Time
,
mtime
*
time
.
Time
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Utimens
(
atime
,
mtime
)
}
func
(
f
*
lockingFile
)
Truncate
(
size
uint64
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Truncate
(
size
)
}
func
(
f
*
lockingFile
)
Chown
(
uid
uint32
,
gid
uint32
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Chown
(
uid
,
gid
)
}
func
(
f
*
lockingFile
)
Chmod
(
perms
uint32
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Chmod
(
perms
)
}
func
(
f
*
lockingFile
)
Allocate
(
off
uint64
,
size
uint64
,
mode
uint32
)
(
code
fuse
.
Status
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
f
.
file
.
Allocate
(
off
,
size
,
mode
)
}
fuse/pathfs/locking.go
View file @
e663cddc
...
...
@@ -15,8 +15,6 @@ type lockingFileSystem struct {
lock
sync
.
Mutex
}
var
_
=
((
FileSystem
)((
*
lockingFileSystem
)(
nil
)))
// NewLockingFileSystem is a wrapper that makes a FileSystem
// threadsafe by serializing each operation.
func
NewLockingFileSystem
(
pfs
FileSystem
)
FileSystem
{
...
...
@@ -101,7 +99,9 @@ func (fs *lockingFileSystem) Truncate(name string, offset uint64, context *fuse.
}
func
(
fs
*
lockingFileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
return
fs
.
FS
.
Open
(
name
,
flags
,
context
)
file
,
code
=
fs
.
FS
.
Open
(
name
,
flags
,
context
)
file
=
nodefs
.
NewLockingFile
(
&
fs
.
lock
,
file
)
return
}
func
(
fs
*
lockingFileSystem
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
stream
[]
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
...
...
@@ -126,7 +126,10 @@ func (fs *lockingFileSystem) Access(name string, mode uint32, context *fuse.Cont
func
(
fs
*
lockingFileSystem
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
defer
fs
.
locked
()()
return
fs
.
FS
.
Create
(
name
,
flags
,
mode
,
context
)
file
,
code
=
fs
.
FS
.
Create
(
name
,
flags
,
mode
,
context
)
file
=
nodefs
.
NewLockingFile
(
&
fs
.
lock
,
file
)
return
file
,
code
}
func
(
fs
*
lockingFileSystem
)
Utimens
(
name
string
,
Atime
*
time
.
Time
,
Mtime
*
time
.
Time
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
...
...
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