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
bf30f7b8
Commit
bf30f7b8
authored
May 25, 2012
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle EOF when splicing.
parent
ce49cdd4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
11 deletions
+44
-11
fuse/loopback_test.go
fuse/loopback_test.go
+3
-2
fuse/mountstate.go
fuse/mountstate.go
+30
-8
fuse/read.go
fuse/read.go
+3
-1
splice/pair.go
splice/pair.go
+8
-0
No files found.
fuse/loopback_test.go
View file @
bf30f7b8
...
...
@@ -139,13 +139,14 @@ func TestReadLarge(t *testing.T) {
ts
:=
NewTestCase
(
t
)
defer
ts
.
Cleanup
()
content
:=
make
([]
byte
,
1024
*
1024
)
// Add a bit more to test the splicing at the end.
content
:=
make
([]
byte
,
1024
*
1024
+
43
)
for
i
:=
range
content
{
content
[
i
]
=
byte
(
i
)
}
err
:=
ioutil
.
WriteFile
(
ts
.
origFile
,
[]
byte
(
content
),
0644
)
CheckSuccess
(
err
)
back
,
err
:=
ioutil
.
ReadFile
(
ts
.
mountFile
)
CheckSuccess
(
err
)
if
bytes
.
Compare
(
content
,
back
)
!=
0
{
...
...
fuse/mountstate.go
View file @
bf30f7b8
...
...
@@ -3,6 +3,7 @@ package fuse
import
(
"fmt"
"log"
"io"
"os"
"strings"
"sync"
...
...
@@ -156,7 +157,7 @@ func (ms *MountState) OperationCounts() map[string]int {
func
(
ms
*
MountState
)
BufferPoolStats
()
string
{
s
:=
ms
.
buffers
.
String
()
var
r
int
var
r
int
ms
.
reqMu
.
Lock
()
r
=
len
(
ms
.
readPool
)
+
ms
.
reqReaders
ms
.
reqMu
.
Unlock
()
...
...
@@ -279,7 +280,7 @@ func (ms *MountState) loop(exitIdle bool) {
if
req
==
nil
{
break
exit
}
case
ENOENT
:
case
ENOENT
:
continue
case
ENODEV
:
// unmount
...
...
@@ -326,7 +327,7 @@ func (ms *MountState) handleRequest(req *request) {
func
(
ms
*
MountState
)
AllocOut
(
req
*
request
,
size
uint32
)
[]
byte
{
if
cap
(
req
.
bufferPoolOutputBuf
)
>=
int
(
size
)
{
req
.
bufferPoolOutputBuf
=
req
.
bufferPoolOutputBuf
[
:
size
]
return
req
.
bufferPoolOutputBuf
return
req
.
bufferPoolOutputBuf
}
if
req
.
bufferPoolOutputBuf
!=
nil
{
ms
.
buffers
.
FreeBuffer
(
req
.
bufferPoolOutputBuf
)
...
...
@@ -364,6 +365,7 @@ func (ms *MountState) write(req *request) Status {
if
err
:=
ms
.
TrySplice
(
header
,
req
);
err
==
nil
{
return
OK
}
else
{
log
.
Println
(
"Splice error"
,
err
)
buf
:=
ms
.
AllocOut
(
req
,
uint32
(
req
.
flatData
.
FdSize
))
req
.
flatData
.
Read
(
buf
)
header
=
req
.
serializeHeader
()
...
...
@@ -385,25 +387,45 @@ func (ms *MountState) TrySplice(header []byte, req *request) error {
if
!
finalSplice
.
Grow
(
total
)
{
return
fmt
.
Errorf
(
"splice.Grow failed."
)
}
_
,
err
=
finalSplice
.
Write
(
header
)
if
err
!=
nil
{
return
err
}
n
,
err
:=
finalSplice
.
LoadFromAt
(
req
.
flatData
.
Fd
,
req
.
flatData
.
FdSize
,
req
.
flatData
.
FdOff
)
var
n
int
if
req
.
flatData
.
FdOff
<
0
{
n
,
err
=
finalSplice
.
LoadFrom
(
req
.
flatData
.
Fd
,
req
.
flatData
.
FdSize
)
}
else
{
n
,
err
=
finalSplice
.
LoadFromAt
(
req
.
flatData
.
Fd
,
req
.
flatData
.
FdSize
,
req
.
flatData
.
FdOff
)
}
if
err
==
io
.
EOF
||
(
err
==
nil
&&
n
<
req
.
flatData
.
FdSize
&&
n
>
0
)
{
discard
:=
make
([]
byte
,
len
(
header
))
_
,
err
=
finalSplice
.
Read
(
discard
)
if
err
!=
nil
{
return
err
}
// TODO - fix debug output.
req
.
flatData
.
FdSize
=
n
req
.
flatData
.
Fd
=
finalSplice
.
ReadFd
()
req
.
flatData
.
FdOff
=
-
1
header
=
req
.
serializeHeader
()
return
ms
.
TrySplice
(
header
,
req
)
}
if
err
!=
nil
{
// TODO - handle EOF.
// TODO - extract the data from splice.
return
err
}
if
n
!=
req
.
flatData
.
FdSize
{
return
fmt
.
Errorf
(
"
Size mismatch %d %d"
,
n
,
req
.
flatData
.
FdSize
)
return
fmt
.
Errorf
(
"
splice: wrote %d, want %d"
,
n
,
req
.
flatData
.
FdSize
)
}
_
,
err
=
finalSplice
.
WriteTo
(
ms
.
mountFile
.
Fd
(),
total
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"
Splice write
%v"
,
err
)
return
fmt
.
Errorf
(
"
splice write:
%v"
,
err
)
}
return
nil
}
...
...
fuse/read.go
View file @
bf30f7b8
...
...
@@ -12,6 +12,8 @@ type ReadResult struct {
// If Data is nil and Status OK, splice from the following
// file.
Fd
uintptr
// Offset within Fd, or -1 to use current offset.
FdOff
int64
FdSize
int
}
...
...
@@ -47,6 +49,6 @@ func (r *ReadResult) Read(buf []byte) Status {
r
.
Fd
=
0
r
.
FdOff
=
0
r
.
FdSize
=
0
return
r
.
Status
}
splice/pair.go
View file @
bf30f7b8
...
...
@@ -52,6 +52,14 @@ func (p *Pair) Read(d []byte) (n int, err error) {
return
p
.
r
.
Read
(
d
)
}
func
(
p
*
Pair
)
ReadFd
()
uintptr
{
return
p
.
r
.
Fd
()
}
func
(
p
*
Pair
)
WriteFd
()
uintptr
{
return
p
.
w
.
Fd
()
}
func
(
p
*
Pair
)
Write
(
d
[]
byte
)
(
n
int
,
err
error
)
{
return
p
.
w
.
Write
(
d
)
}
...
...
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