FuseDaemon: Rework inode tracking.
This change contains two related fixes :
(a) Clean up a couple of places where nodes were being Released but
not tracked. To do this in non-brittle way, the calls to NodeCreated
and NodeDeleted have been moved to the point of creation and deletion
(i.e, the calls to new and delete).
(b) Move node::Create+NodeCreated to the same critical section,
and the same for node::Release+NodeReleased. Otherwise it's possible to
hit the following race conition:
T1: p1->Release()
T2: p1 = node::Create()
T2: NodeCreated(p1)
T1: NodeDeleted(p1)
T?: Lookup(p1)
(c) This change also tightens up inode tracking by making sure we never
insert a duplicate element into set of known inodes. This would have
made this problem a little more obvious.
(d) Also fix up fuse_node_test to reflect this new API, and fix a bug
in node::DeleteTree that was made very obvious by this fix, given the
extra work we do during deletion.
Test: atest FuseDaemonHostTest
Test: adb shell /data/local/fsstress-run.sh
Bug: 148709965
Change-Id: I6eea19020007eb56e6111f60cc9e5a4924b592a4
diff --git a/jni/node.cpp b/jni/node.cpp
index 8898b7b..e3f9a3e 100644
--- a/jni/node.cpp
+++ b/jni/node.cpp
@@ -80,13 +80,15 @@
std::lock_guard<std::recursive_mutex> guard(*tree->lock_);
if (tree) {
- for (node* child : tree->children_) {
+ // Make a copy of the list of children because calling Delete tree
+ // will modify the list of children, which will cause issues while
+ // iterating over them.
+ std::vector<node*> children(tree->children_.begin(), tree->children_.end());
+ for (node* child : children) {
DeleteTree(child);
}
- tree->children_.clear();
- LOG(DEBUG) << "DELETE node " << tree->GetName();
- tree->RemoveFromParent();
+ CHECK(tree->children_.empty());
delete tree;
}
}