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
2fc99324
Commit
2fc99324
authored
May 09, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement content caching too, and disable due to memory overflow.
parent
83a89fc7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
unionfs/cachingfs.go
unionfs/cachingfs.go
+57
-0
No files found.
unionfs/cachingfs.go
View file @
2fc99324
package
unionfs
package
unionfs
import
(
import
(
"bytes"
"fmt"
"fmt"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse"
"os"
"os"
...
@@ -31,6 +32,11 @@ type linkResponse struct {
...
@@ -31,6 +32,11 @@ type linkResponse struct {
fuse
.
Status
fuse
.
Status
}
}
type
openResponse
struct
{
fuse
.
File
fuse
.
Status
}
// Caches readdir and getattr()
// Caches readdir and getattr()
type
CachingFileSystem
struct
{
type
CachingFileSystem
struct
{
fuse
.
FileSystem
fuse
.
FileSystem
...
@@ -39,6 +45,7 @@ type CachingFileSystem struct {
...
@@ -39,6 +45,7 @@ type CachingFileSystem struct {
dirs
*
TimedCache
dirs
*
TimedCache
links
*
TimedCache
links
*
TimedCache
xattr
*
TimedCache
xattr
*
TimedCache
files
*
TimedCache
}
}
func
readDir
(
fs
fuse
.
FileSystem
,
name
string
)
*
dirResponse
{
func
readDir
(
fs
fuse
.
FileSystem
,
name
string
)
*
dirResponse
{
...
@@ -67,6 +74,43 @@ func getAttr(fs fuse.FileSystem, name string) *attrResponse {
...
@@ -67,6 +74,43 @@ func getAttr(fs fuse.FileSystem, name string) *attrResponse {
}
}
}
}
func
openFile
(
fs
fuse
.
FileSystem
,
name
string
)
(
result
*
openResponse
)
{
result
=
&
openResponse
{}
flags
:=
uint32
(
os
.
O_RDONLY
)
f
,
code
:=
fs
.
Open
(
name
,
flags
)
if
!
code
.
Ok
()
{
result
.
Status
=
code
return
}
defer
f
.
Release
()
defer
f
.
Flush
()
buf
:=
bytes
.
NewBuffer
(
nil
)
input
:=
fuse
.
ReadIn
{
Offset
:
0
,
Size
:
128
*
(
1
<<
10
),
Flags
:
flags
,
}
bp
:=
fuse
.
NewGcBufferPool
()
for
{
data
,
status
:=
f
.
Read
(
&
input
,
bp
)
buf
.
Write
(
data
)
if
!
status
.
Ok
()
{
result
.
Status
=
status
return
}
if
len
(
data
)
<
int
(
input
.
Size
)
{
break
}
input
.
Offset
+=
uint64
(
len
(
data
))
}
result
.
File
=
fuse
.
NewReadOnlyFile
(
buf
.
Bytes
())
return
}
func
getXAttr
(
fs
fuse
.
FileSystem
,
nameAttr
string
)
*
xattrResponse
{
func
getXAttr
(
fs
fuse
.
FileSystem
,
nameAttr
string
)
*
xattrResponse
{
ns
:=
strings
.
Split
(
nameAttr
,
_XATTRSEP
,
2
)
ns
:=
strings
.
Split
(
nameAttr
,
_XATTRSEP
,
2
)
a
,
code
:=
fs
.
GetXAttr
(
ns
[
0
],
ns
[
1
])
a
,
code
:=
fs
.
GetXAttr
(
ns
[
0
],
ns
[
1
])
...
@@ -93,6 +137,9 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem {
...
@@ -93,6 +137,9 @@ func NewCachingFileSystem(fs fuse.FileSystem, ttlNs int64) *CachingFileSystem {
c
.
xattr
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
c
.
xattr
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
getXAttr
(
fs
,
n
)
return
getXAttr
(
fs
,
n
)
},
ttlNs
)
},
ttlNs
)
c
.
files
=
NewTimedCache
(
func
(
n
string
)
interface
{}
{
return
openFile
(
fs
,
n
)
},
ttlNs
)
return
c
return
c
}
}
...
@@ -131,3 +178,13 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
...
@@ -131,3 +178,13 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
return
nil
,
r
.
Status
return
nil
,
r
.
Status
}
}
// Caching file contents easily overflows available memory.
func
(
me
*
CachingFileSystem
)
DisabledOpen
(
name
string
,
flags
uint32
)
(
f
fuse
.
File
,
status
fuse
.
Status
)
{
if
flags
&
fuse
.
O_ANYWRITE
!=
0
{
return
nil
,
fuse
.
EPERM
}
r
:=
me
.
files
.
Get
(
name
)
.
(
*
openResponse
)
return
r
.
File
,
r
.
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