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
547051cf
Commit
547051cf
authored
Apr 22, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collapse arrays into one array of operationHandler.
parent
87625729
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
108 deletions
+52
-108
fuse/fuse.go
fuse/fuse.go
+20
-31
fuse/opcode.go
fuse/opcode.go
+32
-77
No files found.
fuse/fuse.go
View file @
547051cf
...
...
@@ -254,74 +254,68 @@ func (me *MountState) Loop(threaded bool) {
}
func
(
me
*
MountState
)
chopMessage
(
req
*
request
)
bool
{
func
(
me
*
MountState
)
chopMessage
(
req
*
request
)
*
operationHandler
{
inHSize
:=
unsafe
.
Sizeof
(
InHeader
{})
if
len
(
req
.
inputBuf
)
<
inHSize
{
me
.
Error
(
os
.
NewError
(
fmt
.
Sprintf
(
"Short read for input header: %v"
,
req
.
inputBuf
)))
return
false
return
nil
}
req
.
inHeader
=
(
*
InHeader
)(
unsafe
.
Pointer
(
&
req
.
inputBuf
[
0
]))
req
.
arg
=
req
.
inputBuf
[
inHSize
:
]
argSize
,
ok
:=
inputSize
(
req
.
inHeader
.
Opcode
)
if
!
ok
{
handler
:=
getHandler
(
req
.
inHeader
.
Opcode
)
if
handler
==
nil
||
handler
.
Func
==
nil
{
log
.
Println
(
"Unknown opcode %d (input)"
,
req
.
inHeader
.
Opcode
)
req
.
status
=
ENOSYS
return
true
return
handler
}
if
len
(
req
.
arg
)
<
arg
Size
{
if
len
(
req
.
arg
)
<
handler
.
Input
Size
{
log
.
Println
(
"Short read for %v: %v"
,
req
.
inHeader
.
Opcode
,
req
.
arg
)
req
.
status
=
EIO
return
true
return
handler
}
if
arg
Size
>
0
{
if
handler
.
Input
Size
>
0
{
req
.
inData
=
unsafe
.
Pointer
(
&
req
.
arg
[
0
])
req
.
arg
=
req
.
arg
[
arg
Size
:
]
req
.
arg
=
req
.
arg
[
handler
.
Input
Size
:
]
}
return
true
return
handler
}
func
(
me
*
MountState
)
handle
(
req
*
request
)
{
defer
me
.
discardRequest
(
req
)
if
!
me
.
chopMessage
(
req
)
{
handler
:=
me
.
chopMessage
(
req
)
if
handler
==
nil
{
return
}
if
req
.
status
==
OK
{
me
.
dispatch
(
req
)
me
.
dispatch
(
req
,
handler
)
}
// If we try to write OK, nil, we will get
// error: writer: Writev [[16 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0]]
// failed, err: writev: no such file or directory
if
req
.
inHeader
.
Opcode
!=
FUSE_FORGET
{
serialize
(
req
,
me
.
Debug
)
serialize
(
req
,
handler
,
me
.
Debug
)
req
.
preWriteNs
=
time
.
Nanoseconds
()
me
.
Write
(
req
)
}
}
func
(
me
*
MountState
)
dispatch
(
req
*
request
)
{
func
(
me
*
MountState
)
dispatch
(
req
*
request
,
handler
*
operationHandler
)
{
req
.
dispatchNs
=
time
.
Nanoseconds
()
f
:=
lookupOperation
(
req
.
inHeader
.
Opcode
)
if
f
==
nil
{
msg
:=
fmt
.
Sprintf
(
"Unsupported OpCode: %d=%v"
,
req
.
inHeader
.
Opcode
,
operationName
(
req
.
inHeader
.
Opcode
))
me
.
Error
(
os
.
NewError
(
msg
))
req
.
status
=
ENOSYS
return
}
if
me
.
Debug
{
nm
:=
""
// TODO - reinstate filename printing.
log
.
Printf
(
"Dispatch: %v, NodeId: %v %s
\n
"
,
operationName
(
req
.
inHeader
.
Opcode
),
req
.
inHeader
.
NodeId
,
nm
)
}
f
(
me
,
req
)
handler
.
Func
(
me
,
req
)
}
// Thanks to Andrew Gerrand for this hack.
...
...
@@ -330,13 +324,8 @@ func asSlice(ptr unsafe.Pointer, byteCount int) []byte {
return
*
(
*
[]
byte
)(
unsafe
.
Pointer
(
h
))
}
func
serialize
(
req
*
request
,
debug
bool
)
{
dataLength
,
ok
:=
outputSize
(
req
.
inHeader
.
Opcode
)
if
!
ok
{
log
.
Println
(
"Unknown opcode %d (output)"
,
req
.
inHeader
.
Opcode
)
req
.
status
=
ENOSYS
return
}
func
serialize
(
req
*
request
,
handler
*
operationHandler
,
debug
bool
)
{
dataLength
:=
handler
.
OutputSize
if
req
.
outData
==
nil
||
req
.
status
!=
OK
{
dataLength
=
0
}
...
...
fuse/opcode.go
View file @
547051cf
...
...
@@ -231,138 +231,94 @@ func doRename(state *MountState, req *request) {
////////////////////////////////////////////////////////////////
var
operationNames
[]
string
var
inputSizes
[]
int
var
outputSizes
[]
int
type
operationFunc
func
(
*
MountState
,
*
request
)
type
operation
func
(
*
MountState
,
*
request
)
type
operationHandler
struct
{
Name
string
Func
operationFunc
InputSize
int
OutputSize
int
}
var
operation
Funcs
[]
operation
var
operation
Handlers
[]
*
operationHandler
func
operationName
(
opcode
Opcode
)
string
{
if
opcode
>
OPCODE_COUNT
{
h
:=
getHandler
(
opcode
)
if
h
==
nil
{
return
"unknown"
}
return
operationNames
[
opcode
]
}
func
inputSize
(
o
Opcode
)
(
int
,
bool
)
{
return
lookupSize
(
o
,
inputSizes
)
}
func
outputSize
(
o
Opcode
)
(
int
,
bool
)
{
return
lookupSize
(
o
,
outputSizes
)
return
h
.
Name
}
func
lookupSize
(
o
Opcode
,
sMap
[]
int
)
(
int
,
bool
)
{
func
getHandler
(
o
Opcode
)
*
operationHandler
{
if
o
>=
OPCODE_COUNT
{
return
-
1
,
false
}
return
sMap
[
int
(
o
)],
true
}
func
lookupOperation
(
o
Opcode
)
operation
{
return
operationFuncs
[
o
]
}
func
makeSizes
(
dict
map
[
int
]
int
)
[]
int
{
out
:=
make
([]
int
,
OPCODE_COUNT
)
for
i
,
_
:=
range
out
{
out
[
i
]
=
-
1
}
for
code
,
val
:=
range
dict
{
out
[
code
]
=
val
return
nil
}
return
o
ut
return
o
perationHandlers
[
o
]
}
func
init
()
{
inputSizes
=
makeSizes
(
map
[
int
]
int
{
FUSE_LOOKUP
:
0
,
operationHandlers
=
make
([]
*
operationHandler
,
OPCODE_COUNT
)
for
i
,
_
:=
range
operationHandlers
{
operationHandlers
[
i
]
=
&
operationHandler
{
Name
:
"UNKNOWN"
}
}
for
op
,
sz
:=
range
map
[
int
]
int
{
FUSE_FORGET
:
unsafe
.
Sizeof
(
ForgetIn
{}),
FUSE_GETATTR
:
unsafe
.
Sizeof
(
GetAttrIn
{}),
FUSE_SETATTR
:
unsafe
.
Sizeof
(
SetAttrIn
{}),
FUSE_READLINK
:
0
,
FUSE_SYMLINK
:
0
,
FUSE_MKNOD
:
unsafe
.
Sizeof
(
MknodIn
{}),
FUSE_MKDIR
:
unsafe
.
Sizeof
(
MkdirIn
{}),
FUSE_UNLINK
:
0
,
FUSE_RMDIR
:
0
,
FUSE_RENAME
:
unsafe
.
Sizeof
(
RenameIn
{}),
FUSE_LINK
:
unsafe
.
Sizeof
(
LinkIn
{}),
FUSE_OPEN
:
unsafe
.
Sizeof
(
OpenIn
{}),
FUSE_READ
:
unsafe
.
Sizeof
(
ReadIn
{}),
FUSE_WRITE
:
unsafe
.
Sizeof
(
WriteIn
{}),
FUSE_STATFS
:
0
,
FUSE_RELEASE
:
unsafe
.
Sizeof
(
ReleaseIn
{}),
FUSE_FSYNC
:
unsafe
.
Sizeof
(
FsyncIn
{}),
FUSE_SETXATTR
:
unsafe
.
Sizeof
(
SetXAttrIn
{}),
FUSE_GETXATTR
:
unsafe
.
Sizeof
(
GetXAttrIn
{}),
FUSE_LISTXATTR
:
unsafe
.
Sizeof
(
GetXAttrIn
{}),
FUSE_REMOVEXATTR
:
0
,
FUSE_FLUSH
:
unsafe
.
Sizeof
(
FlushIn
{}),
FUSE_INIT
:
unsafe
.
Sizeof
(
InitIn
{}),
FUSE_OPENDIR
:
unsafe
.
Sizeof
(
OpenIn
{}),
FUSE_READDIR
:
unsafe
.
Sizeof
(
ReadIn
{}),
FUSE_RELEASEDIR
:
unsafe
.
Sizeof
(
ReleaseIn
{}),
FUSE_FSYNCDIR
:
unsafe
.
Sizeof
(
FsyncIn
{}),
FUSE_GETLK
:
0
,
FUSE_SETLK
:
0
,
FUSE_SETLKW
:
0
,
FUSE_ACCESS
:
unsafe
.
Sizeof
(
AccessIn
{}),
FUSE_CREATE
:
unsafe
.
Sizeof
(
CreateIn
{}),
FUSE_INTERRUPT
:
unsafe
.
Sizeof
(
InterruptIn
{}),
FUSE_BMAP
:
unsafe
.
Sizeof
(
BmapIn
{}),
FUSE_DESTROY
:
0
,
FUSE_IOCTL
:
unsafe
.
Sizeof
(
IoctlIn
{}),
FUSE_POLL
:
unsafe
.
Sizeof
(
PollIn
{}),
})
}
{
operationHandlers
[
op
]
.
InputSize
=
sz
}
outputSizes
=
makeSizes
(
map
[
int
]
int
{
for
op
,
sz
:=
range
map
[
int
]
int
{
FUSE_LOOKUP
:
unsafe
.
Sizeof
(
EntryOut
{}),
FUSE_FORGET
:
0
,
FUSE_GETATTR
:
unsafe
.
Sizeof
(
AttrOut
{}),
FUSE_SETATTR
:
unsafe
.
Sizeof
(
AttrOut
{}),
FUSE_READLINK
:
0
,
FUSE_SYMLINK
:
unsafe
.
Sizeof
(
EntryOut
{}),
FUSE_MKNOD
:
unsafe
.
Sizeof
(
EntryOut
{}),
FUSE_MKDIR
:
unsafe
.
Sizeof
(
EntryOut
{}),
FUSE_UNLINK
:
0
,
FUSE_RMDIR
:
0
,
FUSE_RENAME
:
0
,
FUSE_LINK
:
unsafe
.
Sizeof
(
EntryOut
{}),
FUSE_OPEN
:
unsafe
.
Sizeof
(
OpenOut
{}),
FUSE_READ
:
0
,
FUSE_WRITE
:
unsafe
.
Sizeof
(
WriteOut
{}),
FUSE_STATFS
:
unsafe
.
Sizeof
(
StatfsOut
{}),
FUSE_RELEASE
:
0
,
FUSE_FSYNC
:
0
,
FUSE_SETXATTR
:
0
,
FUSE_GETXATTR
:
unsafe
.
Sizeof
(
GetXAttrOut
{}),
FUSE_LISTXATTR
:
unsafe
.
Sizeof
(
GetXAttrOut
{}),
FUSE_REMOVEXATTR
:
0
,
FUSE_FLUSH
:
0
,
FUSE_INIT
:
unsafe
.
Sizeof
(
InitOut
{}),
FUSE_OPENDIR
:
unsafe
.
Sizeof
(
OpenOut
{}),
FUSE_READDIR
:
0
,
FUSE_RELEASEDIR
:
0
,
FUSE_FSYNCDIR
:
0
,
// TODO
FUSE_GETLK
:
0
,
FUSE_SETLK
:
0
,
FUSE_SETLKW
:
0
,
FUSE_ACCESS
:
0
,
FUSE_CREATE
:
unsafe
.
Sizeof
(
CreateOut
{}),
FUSE_INTERRUPT
:
0
,
FUSE_BMAP
:
unsafe
.
Sizeof
(
BmapOut
{}),
FUSE_DESTROY
:
0
,
FUSE_IOCTL
:
unsafe
.
Sizeof
(
IoctlOut
{}),
FUSE_POLL
:
unsafe
.
Sizeof
(
PollOut
{}),
})
operationNames
=
make
([]
string
,
OPCODE_COUNT
)
for
k
,
v
:=
range
map
[
int
]
string
{
}
{
operationHandlers
[
op
]
.
OutputSize
=
sz
}
for
op
,
v
:=
range
map
[
int
]
string
{
FUSE_LOOKUP
:
"FUSE_LOOKUP"
,
FUSE_FORGET
:
"FUSE_FORGET"
,
FUSE_GETATTR
:
"FUSE_GETATTR"
,
...
...
@@ -401,11 +357,10 @@ func init() {
FUSE_DESTROY
:
"FUSE_DESTROY"
,
FUSE_IOCTL
:
"FUSE_IOCTL"
,
FUSE_POLL
:
"FUSE_POLL"
}
{
operation
Names
[
k
]
=
v
operation
Handlers
[
op
]
.
Name
=
v
}
operationFuncs
=
make
([]
operation
,
OPCODE_COUNT
)
for
k
,
v
:=
range
map
[
Opcode
]
operation
{
for
op
,
v
:=
range
map
[
Opcode
]
operationFunc
{
FUSE_OPEN
:
doOpen
,
FUSE_READDIR
:
doReadDir
,
FUSE_WRITE
:
doWrite
,
...
...
@@ -437,6 +392,6 @@ func init() {
FUSE_SYMLINK
:
doSymlink
,
FUSE_RENAME
:
doRename
,
}
{
operation
Funcs
[
k
]
=
v
operation
Handlers
[
op
]
.
Func
=
v
}
}
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