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
ce00c912
Commit
ce00c912
authored
Jun 22, 2013
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fuse: remove HandleMap and Handled from the API.
parent
63eae3b7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
46 deletions
+46
-46
fuse/fsconnector.go
fuse/fsconnector.go
+2
-2
fuse/fsmount.go
fuse/fsmount.go
+3
-3
fuse/handle.go
fuse/handle.go
+29
-29
fuse/handle_test.go
fuse/handle_test.go
+10
-10
fuse/inode.go
fuse/inode.go
+2
-2
No files found.
fuse/fsconnector.go
View file @
ce00c912
...
...
@@ -40,7 +40,7 @@ type FileSystemConnector struct {
nodeFs
NodeFileSystem
// Translate between uint64 handles and *Inode.
inodeMap
H
andleMap
inodeMap
h
andleMap
// The root of the FUSE file system.
rootNode
*
Inode
...
...
@@ -61,7 +61,7 @@ func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (c *
opts
=
NewFileSystemOptions
()
}
c
.
nodeFs
=
nodeFs
c
.
inodeMap
=
N
ewHandleMap
(
opts
.
PortableInodes
)
c
.
inodeMap
=
n
ewHandleMap
(
opts
.
PortableInodes
)
c
.
rootNode
=
newInode
(
true
,
nodeFs
.
Root
())
// Make sure we don't reuse generation numbers.
...
...
fuse/fsmount.go
View file @
ce00c912
...
...
@@ -12,7 +12,7 @@ var _ = log.Println
// openedFile stores either an open dir or an open file.
type
openedFile
struct
{
H
andled
h
andled
WithFlags
...
...
@@ -40,7 +40,7 @@ type fileSystemMount struct {
treeLock
sync
.
RWMutex
// Manage filehandles of open files.
openFiles
H
andleMap
openFiles
h
andleMap
Debug
bool
...
...
@@ -133,7 +133,7 @@ func (m *fileSystemMount) registerFileHandle(node *Inode, dir rawDir, f File, fl
b
.
WithFlags
.
File
.
SetInode
(
node
)
}
node
.
openFiles
=
append
(
node
.
openFiles
,
b
)
handle
:=
m
.
openFiles
.
Register
(
&
b
.
H
andled
)
handle
:=
m
.
openFiles
.
Register
(
&
b
.
h
andled
)
node
.
openFilesMutex
.
Unlock
()
return
handle
,
b
}
...
...
fuse/handle.go
View file @
ce00c912
...
...
@@ -16,22 +16,22 @@ import (
// you wish to export.
//
// This structure is thread-safe.
type
H
andleMap
interface
{
Register
(
obj
*
H
andled
)
uint64
type
h
andleMap
interface
{
Register
(
obj
*
h
andled
)
uint64
Count
()
int
Decode
(
uint64
)
*
H
andled
Forget
(
handle
uint64
,
count
int
)
(
bool
,
*
H
andled
)
Handle
(
obj
*
H
andled
)
uint64
Decode
(
uint64
)
*
h
andled
Forget
(
handle
uint64
,
count
int
)
(
bool
,
*
h
andled
)
Handle
(
obj
*
h
andled
)
uint64
Has
(
uint64
)
bool
}
type
H
andled
struct
{
type
h
andled
struct
{
check
uint32
handle
uint64
count
int
}
func
(
h
*
H
andled
)
verify
()
{
func
(
h
*
h
andled
)
verify
()
{
if
h
.
count
<
0
{
log
.
Panicf
(
"negative lookup count %d"
,
h
.
count
)
}
...
...
@@ -48,18 +48,18 @@ const _ALREADY_MSG = "Object already has a handle"
type
portableHandleMap
struct
{
sync
.
RWMutex
used
int
handles
[]
*
H
andled
handles
[]
*
h
andled
freeIds
[]
uint64
}
func
newPortableHandleMap
()
*
portableHandleMap
{
return
&
portableHandleMap
{
// Avoid handing out ID 0 and 1.
handles
:
[]
*
H
andled
{
nil
,
nil
},
handles
:
[]
*
h
andled
{
nil
,
nil
},
}
}
func
(
m
*
portableHandleMap
)
Register
(
obj
*
H
andled
)
(
handle
uint64
)
{
func
(
m
*
portableHandleMap
)
Register
(
obj
*
h
andled
)
(
handle
uint64
)
{
m
.
Lock
()
if
obj
.
count
==
0
{
if
obj
.
check
!=
0
{
...
...
@@ -84,7 +84,7 @@ func (m *portableHandleMap) Register(obj *Handled) (handle uint64) {
return
handle
}
func
(
m
*
portableHandleMap
)
Handle
(
obj
*
H
andled
)
(
h
uint64
)
{
func
(
m
*
portableHandleMap
)
Handle
(
obj
*
h
andled
)
(
h
uint64
)
{
m
.
RLock
()
if
obj
.
count
==
0
{
h
=
0
...
...
@@ -102,14 +102,14 @@ func (m *portableHandleMap) Count() int {
return
c
}
func
(
m
*
portableHandleMap
)
Decode
(
h
uint64
)
*
H
andled
{
func
(
m
*
portableHandleMap
)
Decode
(
h
uint64
)
*
h
andled
{
m
.
RLock
()
v
:=
m
.
handles
[
h
]
m
.
RUnlock
()
return
v
}
func
(
m
*
portableHandleMap
)
Forget
(
h
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
H
andled
)
{
func
(
m
*
portableHandleMap
)
Forget
(
h
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
h
andled
)
{
m
.
Lock
()
obj
=
m
.
handles
[
h
]
obj
.
count
-=
count
...
...
@@ -136,10 +136,10 @@ func (m *portableHandleMap) Has(h uint64) bool {
// 32 bits version of HandleMap
type
int32HandleMap
struct
{
mutex
sync
.
Mutex
handles
map
[
uint32
]
*
H
andled
handles
map
[
uint32
]
*
h
andled
}
func
(
m
*
int32HandleMap
)
Register
(
obj
*
H
andled
)
(
handle
uint64
)
{
func
(
m
*
int32HandleMap
)
Register
(
obj
*
h
andled
)
(
handle
uint64
)
{
m
.
mutex
.
Lock
()
h
:=
uint32
(
uintptr
(
unsafe
.
Pointer
(
obj
)))
if
obj
.
count
==
0
{
...
...
@@ -159,7 +159,7 @@ func (m *int32HandleMap) Has(h uint64) bool {
return
ok
}
func
(
m
*
int32HandleMap
)
Handle
(
obj
*
H
andled
)
uint64
{
func
(
m
*
int32HandleMap
)
Handle
(
obj
*
h
andled
)
uint64
{
if
obj
.
count
==
0
{
return
0
}
...
...
@@ -175,7 +175,7 @@ func (m *int32HandleMap) Count() int {
return
c
}
func
(
m
*
int32HandleMap
)
Forget
(
handle
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
H
andled
)
{
func
(
m
*
int32HandleMap
)
Forget
(
handle
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
h
andled
)
{
obj
=
m
.
Decode
(
handle
)
m
.
mutex
.
Lock
()
...
...
@@ -192,13 +192,13 @@ func (m *int32HandleMap) Forget(handle uint64, count int) (forgotten bool, obj *
return
forgotten
,
obj
}
func
(
m
*
int32HandleMap
)
Decode
(
handle
uint64
)
*
H
andled
{
val
:=
(
*
H
andled
)(
unsafe
.
Pointer
(
uintptr
(
handle
&
((
1
<<
32
)
-
1
))))
func
(
m
*
int32HandleMap
)
Decode
(
handle
uint64
)
*
h
andled
{
val
:=
(
*
h
andled
)(
unsafe
.
Pointer
(
uintptr
(
handle
&
((
1
<<
32
)
-
1
))))
return
val
}
func
newInt32HandleMap
()
*
int32HandleMap
{
return
&
int32HandleMap
{
handles
:
make
(
map
[
uint32
]
*
H
andled
),
handles
:
make
(
map
[
uint32
]
*
h
andled
),
}
}
...
...
@@ -208,7 +208,7 @@ func newInt32HandleMap() *int32HandleMap {
// map, so the Go runtime will not garbage collect it.
type
int64HandleMap
struct
{
mutex
sync
.
Mutex
handles
map
[
uint64
]
*
H
andled
handles
map
[
uint64
]
*
h
andled
nextFree
uint32
}
...
...
@@ -228,19 +228,19 @@ func (m *int64HandleMap) verify() {
func
newInt64HandleMap
()
*
int64HandleMap
{
return
&
int64HandleMap
{
handles
:
make
(
map
[
uint64
]
*
H
andled
),
handles
:
make
(
map
[
uint64
]
*
h
andled
),
nextFree
:
1
,
// to make tests easier.
}
}
// NewHandleMap creates a new HandleMap. If verify is given, we
// use remaining bits in the handle to store sanity check bits.
func
NewHandleMap
(
portable
bool
)
(
hm
H
andleMap
)
{
func
newHandleMap
(
portable
bool
)
(
hm
h
andleMap
)
{
if
portable
{
return
newPortableHandleMap
()
}
var
obj
*
H
andled
var
obj
*
h
andled
switch
unsafe
.
Sizeof
(
obj
)
{
case
8
:
return
newInt64HandleMap
()
...
...
@@ -260,7 +260,7 @@ func (m *int64HandleMap) Count() int {
return
c
}
func
(
m
*
int64HandleMap
)
Register
(
obj
*
H
andled
)
(
handle
uint64
)
{
func
(
m
*
int64HandleMap
)
Register
(
obj
*
h
andled
)
(
handle
uint64
)
{
defer
m
.
verify
()
m
.
mutex
.
Lock
()
...
...
@@ -296,7 +296,7 @@ func (m *int64HandleMap) Register(obj *Handled) (handle uint64) {
return
handle
}
func
(
m
*
int64HandleMap
)
Handle
(
obj
*
H
andled
)
(
handle
uint64
)
{
func
(
m
*
int64HandleMap
)
Handle
(
obj
*
h
andled
)
(
handle
uint64
)
{
if
obj
.
count
==
0
{
return
0
}
...
...
@@ -307,7 +307,7 @@ func (m *int64HandleMap) Handle(obj *Handled) (handle uint64) {
return
handle
}
func
(
m
*
int64HandleMap
)
Forget
(
handle
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
H
andled
)
{
func
(
m
*
int64HandleMap
)
Forget
(
handle
uint64
,
count
int
)
(
forgotten
bool
,
obj
*
h
andled
)
{
defer
m
.
verify
()
obj
=
m
.
Decode
(
handle
)
...
...
@@ -332,10 +332,10 @@ func (m *int64HandleMap) Has(handle uint64) bool {
return
ok
}
func
(
m
*
int64HandleMap
)
Decode
(
handle
uint64
)
(
val
*
H
andled
)
{
func
(
m
*
int64HandleMap
)
Decode
(
handle
uint64
)
(
val
*
h
andled
)
{
ptrBits
:=
uintptr
(
handle
&
(
1
<<
45
-
1
))
check
:=
uint32
(
handle
>>
45
)
val
=
(
*
H
andled
)(
unsafe
.
Pointer
(
ptrBits
<<
3
))
val
=
(
*
h
andled
)(
unsafe
.
Pointer
(
ptrBits
<<
3
))
if
val
.
check
!=
check
{
msg
:=
fmt
.
Sprintf
(
"handle check mismatch; handle has 0x%x, object has 0x%x"
,
check
,
val
.
check
)
...
...
fuse/handle_test.go
View file @
ce00c912
...
...
@@ -25,10 +25,10 @@ func TestHandleMapUnaligned(t *testing.T) {
t
.
Log
(
"skipping test for 32 bits"
)
return
}
hm
:=
N
ewHandleMap
(
false
)
hm
:=
n
ewHandleMap
(
false
)
b
:=
make
([]
byte
,
100
)
v
:=
(
*
H
andled
)(
unsafe
.
Pointer
(
&
b
[
1
]))
v
:=
(
*
h
andled
)(
unsafe
.
Pointer
(
&
b
[
1
]))
defer
markSeen
(
t
,
"unaligned"
)
hm
.
Register
(
v
)
...
...
@@ -38,8 +38,8 @@ func TestHandleMapUnaligned(t *testing.T) {
func
TestHandleMapLookupCount
(
t
*
testing
.
T
)
{
for
_
,
portable
:=
range
[]
bool
{
true
,
false
}
{
t
.
Log
(
"portable:"
,
portable
)
v
:=
new
(
H
andled
)
hm
:=
N
ewHandleMap
(
portable
)
v
:=
new
(
h
andled
)
hm
:=
n
ewHandleMap
(
portable
)
h1
:=
hm
.
Register
(
v
)
h2
:=
hm
.
Register
(
v
)
...
...
@@ -80,8 +80,8 @@ func TestHandleMapLookupCount(t *testing.T) {
func
TestHandleMapBasic
(
t
*
testing
.
T
)
{
for
_
,
portable
:=
range
[]
bool
{
true
,
false
}
{
t
.
Log
(
"portable:"
,
portable
)
v
:=
new
(
H
andled
)
hm
:=
N
ewHandleMap
(
portable
)
v
:=
new
(
h
andled
)
hm
:=
n
ewHandleMap
(
portable
)
h
:=
hm
.
Register
(
v
)
t
.
Logf
(
"Got handle 0x%x"
,
h
)
if
!
hm
.
Has
(
h
)
{
...
...
@@ -110,9 +110,9 @@ func TestHandleMapBasic(t *testing.T) {
}
func
TestHandleMapMultiple
(
t
*
testing
.
T
)
{
hm
:=
N
ewHandleMap
(
false
)
hm
:=
n
ewHandleMap
(
false
)
for
i
:=
0
;
i
<
10
;
i
++
{
v
:=
&
H
andled
{}
v
:=
&
h
andled
{}
h
:=
hm
.
Register
(
v
)
if
hm
.
Decode
(
h
)
!=
v
{
t
.
Fatal
(
"address mismatch"
)
...
...
@@ -130,8 +130,8 @@ func TestHandleMapCheckFail(t *testing.T) {
}
defer
markSeen
(
t
,
"check mismatch"
)
v
:=
new
(
H
andled
)
hm
:=
N
ewHandleMap
(
false
)
v
:=
new
(
h
andled
)
hm
:=
n
ewHandleMap
(
false
)
h
:=
hm
.
Register
(
v
)
hm
.
Decode
(
h
|
(
uint64
(
1
)
<<
63
))
t
.
Error
(
"Borked decode did not panic"
)
...
...
fuse/inode.go
View file @
ce00c912
...
...
@@ -11,7 +11,7 @@ var _ = log.Println
// created automatically when the kernel does lookups inode, or by
// explicitly by calling Inode.New().
type
Inode
struct
{
handled
H
andled
handled
h
andled
// Generation number of the inode. Each (re)use of an inode
// should have a unique generation number.
...
...
@@ -166,7 +166,7 @@ func (n *Inode) rmChild(name string) (ch *Inode) {
func
(
n
*
Inode
)
mountFs
(
fs
NodeFileSystem
,
opts
*
FileSystemOptions
)
{
n
.
mountPoint
=
&
fileSystemMount
{
fs
:
fs
,
openFiles
:
N
ewHandleMap
(
false
),
openFiles
:
n
ewHandleMap
(
false
),
mountInode
:
n
,
options
:
opts
,
}
...
...
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