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
31ba13cc
Commit
31ba13cc
authored
Feb 22, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodefs: avoid slice creation for LOOKUP locking
parent
6470cf03
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
nodefs/bridge.go
nodefs/bridge.go
+2
-2
nodefs/inode.go
nodefs/inode.go
+22
-3
No files found.
nodefs/bridge.go
View file @
31ba13cc
...
...
@@ -140,7 +140,7 @@ func (b *rawBridge) Create(input *fuse.CreateIn, name string, out *fuse.CreateOu
return
code
}
lockNode
s
(
parent
,
child
)
lockNode
2
(
parent
,
child
)
parent
.
setEntry
(
name
,
child
)
b
.
mu
.
Lock
()
if
child
.
nodeID
==
0
{
...
...
@@ -150,7 +150,7 @@ func (b *rawBridge) Create(input *fuse.CreateIn, name string, out *fuse.CreateOu
out
.
NodeId
=
child
.
nodeID
out
.
Generation
=
b
.
nodes
[
child
.
nodeID
]
.
generation
b
.
mu
.
Unlock
()
unlockNode
s
(
parent
,
child
)
unlockNode
2
(
parent
,
child
)
if
b
.
options
.
AttrTimeout
!=
nil
{
out
.
SetAttrTimeout
(
*
b
.
options
.
AttrTimeout
)
...
...
nodefs/inode.go
View file @
31ba13cc
...
...
@@ -92,18 +92,20 @@ func newInode(node Node, mode uint32) *Inode {
// locks on inode group.
func
sortNodes
(
ns
[]
*
Inode
)
{
sort
.
Slice
(
ns
,
func
(
i
,
j
int
)
bool
{
return
uintptr
(
unsafe
.
Pointer
(
ns
[
i
]))
<
uintptr
(
unsafe
.
Pointer
(
ns
[
j
])
)
return
nodeLess
(
ns
[
i
],
ns
[
j
]
)
})
}
func
nodeLess
(
a
,
b
*
Inode
)
bool
{
return
uintptr
(
unsafe
.
Pointer
(
a
))
<
uintptr
(
unsafe
.
Pointer
(
b
))
}
// lockNodes locks group of inodes.
//
// It always lock the inodes in the same order - to avoid deadlocks.
// It also avoids locking an inode more than once, if it was specified multiple times.
// An example when an inode might be given multiple times is if dir/a and dir/b
// are hardlinked to the same inode and the caller needs to take locks on dir children.
//
// It is valid to give nil nodes - those are simply ignored.
func
lockNodes
(
ns
...*
Inode
)
{
sortNodes
(
ns
)
...
...
@@ -117,6 +119,23 @@ func lockNodes(ns ...*Inode) {
}
}
// lockNode2 locks a and b in order consistent with lockNodes.
func
lockNode2
(
a
,
b
*
Inode
)
{
if
nodeLess
(
a
,
b
)
{
a
.
mu
.
Lock
()
b
.
mu
.
Lock
()
}
else
{
b
.
mu
.
Lock
()
a
.
mu
.
Lock
()
}
}
// unlockNode2 unlocks a and b
func
unlockNode2
(
a
,
b
*
Inode
)
{
a
.
mu
.
Unlock
()
b
.
mu
.
Unlock
()
}
// unlockNodes releases locks taken by lockNodes.
func
unlockNodes
(
ns
...*
Inode
)
{
// we don't need to unlock in the same order that was used in lockNodes.
...
...
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