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
9723c2be
Commit
9723c2be
authored
Apr 01, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example/statfs: use new nodefs library
parent
afbcb85e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
75 deletions
+72
-75
benchmark/stat_test.go
benchmark/stat_test.go
+16
-21
benchmark/statfs.go
benchmark/statfs.go
+42
-41
example/statfs/main.go
example/statfs/main.go
+14
-13
No files found.
benchmark/stat_test.go
View file @
9723c2be
...
...
@@ -13,32 +13,27 @@ import (
"path/filepath"
"runtime"
"sort"
"syscall"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
"github.com/hanwen/go-fuse/nodefs"
)
func
setupFs
(
fs
pathfs
.
FileSystem
,
N
int
)
(
string
,
func
())
{
opts
:=
&
nodefs
.
Options
{
EntryTimeout
:
0.0
,
AttrTimeout
:
0.0
,
NegativeTimeout
:
0.0
,
}
func
setupFs
(
fs
nodefs
.
InodeEmbedder
,
N
int
)
(
string
,
func
())
{
opts
:=
&
nodefs
.
Options
{}
opts
.
Debug
=
testutil
.
VerboseTest
()
mountPoint
:=
testutil
.
TempDir
()
nfs
:=
pathfs
.
NewPathNodeFs
(
fs
,
nil
)
state
,
_
,
err
:=
nodefs
.
MountRoot
(
mountPoint
,
nfs
.
Root
(),
opts
)
server
,
err
:=
nodefs
.
Mount
(
mountPoint
,
fs
,
opts
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"cannot mount %v"
,
err
))
// ugh - benchmark has no error methods.
log
.
Panicf
(
"cannot mount %v"
,
err
)
}
lmap
:=
NewLatencyMap
()
if
testutil
.
VerboseTest
()
{
s
tate
.
RecordLatencies
(
lmap
)
s
erver
.
RecordLatencies
(
lmap
)
}
go
state
.
Serve
()
return
mountPoint
,
func
()
{
if
testutil
.
VerboseTest
()
{
var
total
time
.
Duration
...
...
@@ -55,7 +50,7 @@ func setupFs(fs pathfs.FileSystem, N int) (string, func()) {
log
.
Printf
(
"total %v, %v/bench op"
,
total
,
total
/
time
.
Duration
(
N
))
}
err
:=
s
tate
.
Unmount
()
err
:=
s
erver
.
Unmount
()
if
err
!=
nil
{
log
.
Println
(
"error during unmount"
,
err
)
}
else
{
...
...
@@ -65,11 +60,11 @@ func setupFs(fs pathfs.FileSystem, N int) (string, func()) {
}
func
TestNewStatFs
(
t
*
testing
.
T
)
{
fs
:=
NewStatFS
()
fs
:=
&
StatFS
{}
for
_
,
n
:=
range
[]
string
{
"file.txt"
,
"sub/dir/foo.txt"
,
"sub/dir/bar.txt"
,
"sub/marine.txt"
}
{
fs
.
AddFile
(
n
)
fs
.
AddFile
(
n
,
fuse
.
Attr
{
Mode
:
syscall
.
S_IFREG
}
)
}
wd
,
clean
:=
setupFs
(
fs
,
1
)
...
...
@@ -116,13 +111,13 @@ func TestNewStatFs(t *testing.T) {
func
BenchmarkGoFuseStat
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
fs
:=
NewStatFS
()
fs
:=
&
StatFS
{}
wd
,
_
:=
os
.
Getwd
()
fileList
:=
wd
+
"/testpaths.txt"
files
:=
ReadLines
(
fileList
)
for
_
,
fn
:=
range
files
{
fs
.
AddFile
(
fn
)
fs
.
AddFile
(
fn
,
fuse
.
Attr
{
Mode
:
syscall
.
S_IFREG
}
)
}
wd
,
clean
:=
setupFs
(
fs
,
b
.
N
)
...
...
@@ -151,13 +146,13 @@ func readdir(d string) error {
func
BenchmarkGoFuseReaddir
(
b
*
testing
.
B
)
{
b
.
StopTimer
()
fs
:=
NewStatFS
()
fs
:=
&
StatFS
{}
wd
,
_
:=
os
.
Getwd
()
dirSet
:=
map
[
string
]
struct
{}{}
for
_
,
fn
:=
range
ReadLines
(
wd
+
"/testpaths.txt"
)
{
fs
.
AddFile
(
fn
)
fs
.
AddFile
(
fn
,
fuse
.
Attr
{
Mode
:
syscall
.
S_IFREG
}
)
dirSet
[
filepath
.
Dir
(
fn
)]
=
struct
{}{}
}
...
...
benchmark/statfs.go
View file @
9723c2be
...
...
@@ -5,65 +5,66 @@
package
benchmark
import
(
"context"
"path/filepath"
"strings"
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/
fuse/path
fs"
"github.com/hanwen/go-fuse/
node
fs"
)
type
StatFS
struct
{
pathfs
.
FileSystem
entries
map
[
string
]
*
fuse
.
Attr
dirs
map
[
string
][]
fuse
.
DirEntry
nodefs
.
Inode
files
map
[
string
]
fuse
.
Attr
}
func
(
fs
*
StatFS
)
Add
(
name
string
,
a
*
fuse
.
Attr
)
{
name
=
strings
.
TrimRight
(
name
,
"/"
)
_
,
ok
:=
fs
.
entries
[
name
]
if
ok
{
r
eturn
var
_
=
(
nodefs
.
OnAdder
)((
*
StatFS
)(
nil
))
func
(
r
*
StatFS
)
OnAdd
(
ctx
context
.
Context
)
{
for
nm
,
a
:=
range
r
.
files
{
r
.
addFile
(
nm
,
a
)
}
r
.
files
=
nil
}
fs
.
entries
[
name
]
=
a
if
name
==
"/"
||
name
==
""
{
r
eturn
func
(
r
*
StatFS
)
AddFile
(
name
string
,
a
fuse
.
Attr
)
{
if
r
.
files
==
nil
{
r
.
files
=
map
[
string
]
fuse
.
Attr
{}
}
dir
,
base
:=
filepath
.
Split
(
name
)
dir
=
strings
.
TrimRight
(
dir
,
"/"
)
fs
.
dirs
[
dir
]
=
append
(
fs
.
dirs
[
dir
],
fuse
.
DirEntry
{
Name
:
base
,
Mode
:
a
.
Mode
})
fs
.
Add
(
dir
,
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0755
})
r
.
files
[
name
]
=
a
}
func
(
fs
*
StatFS
)
AddFile
(
name
string
)
{
fs
.
Add
(
name
,
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0644
})
}
func
(
r
*
StatFS
)
addFile
(
name
string
,
a
fuse
.
Attr
)
{
dir
,
base
:=
filepath
.
Split
(
name
)
func
(
fs
*
StatFS
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
if
d
:=
fs
.
dirs
[
name
];
d
!=
nil
{
return
&
fuse
.
Attr
{
Mode
:
0755
|
fuse
.
S_IFDIR
},
fuse
.
OK
p
:=
r
.
EmbeddedInode
()
// Add directories leading up to the file.
for
_
,
component
:=
range
strings
.
Split
(
dir
,
"/"
)
{
if
len
(
component
)
==
0
{
continue
}
e
:=
fs
.
entries
[
name
]
if
e
==
nil
{
return
nil
,
fuse
.
ENOENT
ch
:=
p
.
GetChild
(
component
)
if
ch
==
nil
{
// Create a directory
ch
=
p
.
NewPersistentInode
(
context
.
Background
(),
&
nodefs
.
Inode
{},
nodefs
.
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
// Add it
p
.
AddChild
(
component
,
ch
,
true
)
}
return
e
,
fuse
.
OK
}
func
(
fs
*
StatFS
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
stream
[]
fuse
.
DirEntry
,
status
fuse
.
Status
)
{
entries
:=
fs
.
dirs
[
name
]
if
entries
==
nil
{
return
nil
,
fuse
.
ENOENT
p
=
ch
}
return
entries
,
fuse
.
OK
}
func
NewStatFS
()
*
StatFS
{
return
&
StatFS
{
FileSystem
:
pathfs
.
NewDefaultFileSystem
(),
entries
:
make
(
map
[
string
]
*
fuse
.
Attr
),
dirs
:
make
(
map
[
string
][]
fuse
.
DirEntry
),
}
// Create the file
child
:=
p
.
NewPersistentInode
(
context
.
Background
(),
&
nodefs
.
MemRegularFile
{
Data
:
make
([]
byte
,
a
.
Size
),
Attr
:
a
,
},
nodefs
.
NodeAttr
{})
// And add it
p
.
AddChild
(
base
,
child
,
true
)
}
example/statfs/main.go
View file @
9723c2be
...
...
@@ -14,11 +14,12 @@ import (
"runtime"
"runtime/pprof"
"strings"
"syscall"
"time"
"github.com/hanwen/go-fuse/benchmark"
"github.com/hanwen/go-fuse/fuse
/nodefs
"
"github.com/hanwen/go-fuse/
fuse/path
fs"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/
node
fs"
)
func
main
()
{
...
...
@@ -27,7 +28,7 @@ func main() {
profile
:=
flag
.
String
(
"profile"
,
""
,
"record cpu profile."
)
mem_profile
:=
flag
.
String
(
"mem-profile"
,
""
,
"record memory profile."
)
command
:=
flag
.
String
(
"run"
,
""
,
"run this command after mounting."
)
ttl
:=
flag
.
Float64
(
"ttl"
,
1.0
,
"attribute/entry cache TTL."
)
ttl
:=
flag
.
Duration
(
"ttl"
,
time
.
Second
,
"attribute/entry cache TTL."
)
flag
.
Parse
()
if
flag
.
NArg
()
<
2
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s MOUNTPOINT FILENAMES-FILE
\n
"
,
os
.
Args
[
0
])
...
...
@@ -48,21 +49,21 @@ func main() {
log
.
Fatalf
(
"os.Create: %v"
,
err
)
}
}
fs
:=
benchmark
.
NewStatFS
()
fs
:=
&
benchmark
.
StatFS
{}
lines
:=
benchmark
.
ReadLines
(
flag
.
Arg
(
1
))
for
_
,
l
:=
range
lines
{
fs
.
AddFile
(
l
)
fs
.
AddFile
(
strings
.
TrimSpace
(
l
),
fuse
.
Attr
{
Mode
:
syscall
.
S_IFREG
})
}
nfs
:=
pathfs
.
NewPathNodeFs
(
fs
,
nil
)
opts
:=
&
nodefs
.
Options
{
AttrTimeout
:
time
.
Duration
(
*
ttl
*
float64
(
time
.
Second
)),
EntryTimeout
:
time
.
Duration
(
*
ttl
*
float64
(
time
.
Second
)),
Debug
:
*
debug
,
AttrTimeout
:
ttl
,
EntryTimeout
:
ttl
,
}
state
,
_
,
err
:=
nodefs
.
MountRoot
(
flag
.
Arg
(
0
),
nfs
.
Root
(),
opts
)
opts
.
Debug
=
*
debug
server
,
err
:=
nodefs
.
Mount
(
flag
.
Arg
(
0
),
fs
,
opts
)
if
err
!=
nil
{
fmt
.
Printf
(
"Mount fail: %v
\n
"
,
err
)
os
.
Exit
(
1
)
log
.
Fatalf
(
"Mount fail: %v
\n
"
,
err
)
}
runtime
.
GC
()
...
...
@@ -78,7 +79,7 @@ func main() {
cmd
.
Start
()
}
s
tate
.
Serve
()
s
erver
.
Wait
()
if
memProfFile
!=
nil
{
pprof
.
WriteHeapProfile
(
memProfFile
)
}
...
...
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