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
1adf79ce
Commit
1adf79ce
authored
Jul 19, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unionfs: test xattr caching
parent
2fd32745
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
9 deletions
+117
-9
unionfs/create.go
unionfs/create.go
+1
-1
unionfs/unionfs.go
unionfs/unionfs.go
+3
-5
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+9
-3
unionfs/unionfs_xattr_test.go
unionfs/unionfs_xattr_test.go
+104
-0
No files found.
unionfs/create.go
View file @
1adf79ce
...
...
@@ -28,5 +28,5 @@ func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (
fses
=
append
(
fses
,
fs
)
}
return
NewUnionFs
(
fses
,
*
opts
)
,
nil
return
NewUnionFs
(
fses
,
*
opts
)
}
unionfs/unionfs.go
View file @
1adf79ce
...
...
@@ -86,7 +86,7 @@ const (
_DROP_CACHE
=
".drop_cache"
)
func
NewUnionFs
(
fileSystems
[]
pathfs
.
FileSystem
,
options
UnionFsOptions
)
pathfs
.
FileSystem
{
func
NewUnionFs
(
fileSystems
[]
pathfs
.
FileSystem
,
options
UnionFsOptions
)
(
pathfs
.
FileSystem
,
error
)
{
g
:=
&
unionFS
{
options
:
&
options
,
fileSystems
:
fileSystems
,
...
...
@@ -96,8 +96,7 @@ func NewUnionFs(fileSystems []pathfs.FileSystem, options UnionFsOptions) pathfs.
writable
:=
g
.
fileSystems
[
0
]
code
:=
g
.
createDeletionStore
()
if
!
code
.
Ok
()
{
log
.
Printf
(
"could not create deletion path %v: %v"
,
options
.
DeletionDirName
,
code
)
return
nil
return
nil
,
fmt
.
Errorf
(
"could not create deletion path %v: %v"
,
options
.
DeletionDirName
,
code
)
}
g
.
deletionCache
=
newDirCache
(
writable
,
options
.
DeletionDirName
,
options
.
DeletionCacheTTL
)
...
...
@@ -110,7 +109,7 @@ func NewUnionFs(fileSystems []pathfs.FileSystem, options UnionFsOptions) pathfs.
g
.
hiddenFiles
[
name
]
=
true
}
return
g
return
g
,
nil
}
func
(
fs
*
unionFS
)
OnMount
(
nodeFs
*
pathfs
.
PathNodeFs
)
{
...
...
@@ -707,7 +706,6 @@ func (fs *unionFS) GetXAttr(name string, attr string, context *fuse.Context) ([]
if
name
==
_DROP_CACHE
{
return
nil
,
fuse
.
ENODATA
}
r
:=
fs
.
getBranch
(
name
)
if
r
.
branch
>=
0
{
return
fs
.
fileSystems
[
r
.
branch
]
.
GetXAttr
(
name
,
attr
,
context
)
...
...
unionfs/unionfs_test.go
View file @
1adf79ce
...
...
@@ -78,8 +78,10 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
fses
=
append
(
fses
,
pathfs
.
NewLoopbackFileSystem
(
wd
+
"/rw"
))
fses
=
append
(
fses
,
NewCachingFileSystem
(
pathfs
.
NewLoopbackFileSystem
(
wd
+
"/ro"
),
0
))
ufs
:=
NewUnionFs
(
fses
,
testOpts
)
ufs
,
err
:=
NewUnionFs
(
fses
,
testOpts
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewUnionFs: %v"
,
err
)
}
// We configure timeouts are smaller, so we can check for
// UnionFs's cache consistency.
opts
:=
&
nodefs
.
Options
{
...
...
@@ -96,6 +98,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
}
conn
.
SetDebug
(
VerboseTest
())
state
.
SetDebug
(
VerboseTest
())
pathfs
.
SetDebug
(
VerboseTest
())
go
state
.
Serve
()
return
wd
,
func
()
{
...
...
@@ -1143,7 +1146,10 @@ func TestUnionFsDisappearing(t *testing.T) {
var
fses
[]
pathfs
.
FileSystem
fses
=
append
(
fses
,
pathfs
.
NewLockingFileSystem
(
wrFs
))
fses
=
append
(
fses
,
pathfs
.
NewLoopbackFileSystem
(
wd
+
"/ro"
))
ufs
:=
NewUnionFs
(
fses
,
testOpts
)
ufs
,
err
:=
NewUnionFs
(
fses
,
testOpts
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewUnionFs: %v"
,
err
)
}
opts
:=
&
nodefs
.
Options
{
EntryTimeout
:
entryTtl
,
...
...
unionfs/unionfs_xattr_test.go
0 → 100644
View file @
1adf79ce
package
unionfs
import
(
"io/ioutil"
"os"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
)
type
TestFS
struct
{
pathfs
.
FileSystem
xattrRead
int
}
func
(
fs
*
TestFS
)
GetAttr
(
path
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
switch
path
{
case
""
:
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
},
fuse
.
OK
case
"file"
:
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0755
},
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
}
func
(
fs
*
TestFS
)
GetXAttr
(
path
string
,
name
string
,
context
*
fuse
.
Context
)
([]
byte
,
fuse
.
Status
)
{
if
path
==
"file"
&&
name
==
"user.attr"
{
fs
.
xattrRead
++
return
[]
byte
{
42
},
fuse
.
OK
}
return
nil
,
fuse
.
ENODATA
}
func
TestXAttrCaching
(
t
*
testing
.
T
)
{
wd
,
_
:=
ioutil
.
TempDir
(
""
,
"unionfs"
)
defer
os
.
RemoveAll
(
wd
)
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
err
:=
os
.
Mkdir
(
wd
+
"/rw"
,
0700
)
if
err
!=
nil
{
t
.
Fatalf
(
"Mkdir failed: %v"
,
err
)
}
rwFS
:=
pathfs
.
NewLoopbackFileSystem
(
wd
+
"/rw"
)
roFS
:=
&
TestFS
{
FileSystem
:
pathfs
.
NewDefaultFileSystem
(),
}
ufs
,
err
:=
NewUnionFs
([]
pathfs
.
FileSystem
{
rwFS
,
NewCachingFileSystem
(
roFS
,
entryTtl
)},
testOpts
)
if
err
!=
nil
{
t
.
Fatalf
(
"NewUnionFs: %v"
,
err
)
}
opts
:=
&
nodefs
.
Options
{
EntryTimeout
:
entryTtl
/
2
,
AttrTimeout
:
entryTtl
/
2
,
NegativeTimeout
:
entryTtl
/
2
,
}
pathfs
:=
pathfs
.
NewPathNodeFs
(
ufs
,
&
pathfs
.
PathNodeFsOptions
{
ClientInodes
:
true
})
server
,
conn
,
err
:=
nodefs
.
MountFileSystem
(
wd
+
"/mnt"
,
pathfs
,
opts
)
if
err
!=
nil
{
t
.
Fatalf
(
"MountNodeFileSystem failed: %v"
,
err
)
}
server
.
SetDebug
(
VerboseTest
())
conn
.
SetDebug
(
VerboseTest
())
pathfs
.
SetDebug
(
VerboseTest
())
defer
server
.
Unmount
()
go
server
.
Serve
()
if
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt"
);
err
!=
nil
||
!
fi
.
IsDir
()
{
t
.
Fatalf
(
"root not readable: %v, %v"
,
err
,
fi
)
}
buf
:=
make
([]
byte
,
1024
)
n
,
err
:=
syscall
.
Getxattr
(
wd
+
"/mnt/file"
,
"user.attr"
,
buf
)
if
err
!=
nil
{
t
.
Fatalf
(
"Getxattr: %v"
,
err
)
}
want
:=
"
\x2a
"
got
:=
string
(
buf
[
:
n
])
if
got
!=
want
{
t
.
Fatalf
(
"Got %q want %q"
,
got
,
err
)
}
time
.
Sleep
(
entryTtl
/
2
)
n
,
err
=
syscall
.
Getxattr
(
wd
+
"/mnt/file"
,
"user.attr"
,
buf
)
if
err
!=
nil
{
t
.
Fatalf
(
"Getxattr: %v"
,
err
)
}
got
=
string
(
buf
[
:
n
])
if
got
!=
want
{
t
.
Fatalf
(
"Got %q want %q"
,
got
,
err
)
}
server
.
Unmount
()
if
roFS
.
xattrRead
!=
1
{
t
.
Errorf
(
"got xattrRead=%d, want 1"
,
roFS
.
xattrRead
)
}
}
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