Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redoxfs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bjorn3
redoxfs
Commits
1d55c5aa
Commit
1d55c5aa
authored
4 months ago
by
Andrey Turkin
Browse files
Options
Downloads
Patches
Plain Diff
Don't leak node block on node remove.
Refs #50
parent
59dbfee1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tests.rs
+48
-22
48 additions, 22 deletions
src/tests.rs
src/transaction.rs
+26
-10
26 additions, 10 deletions
src/transaction.rs
with
74 additions
and
32 deletions
src/tests.rs
+
48
−
22
View file @
1d55c5aa
use
std
::
ops
::
DerefMut
;
use
std
::
path
::
Path
;
use
std
::
process
::
Command
;
use
std
::{
fs
,
sync
,
thread
,
time
};
use
crate
::{
unmount_path
,
DiskSparse
,
FileSystem
};
use
std
::{
fs
,
thread
,
time
};
use
crate
::{
unmount_path
,
DiskSparse
,
FileSystem
,
Node
,
TreePtr
};
fn
with_redoxfs
<
T
,
F
>
(
callback
:
F
)
->
T
where
T
:
Send
+
Sync
+
'static
,
F
:
Fn
Mut
(
&
Path
)
->
T
+
Send
+
Sync
+
'static
,
F
:
Fn
Once
(
FileSystem
<
DiskSparse
>
)
->
T
+
Send
+
Sync
+
'static
,
{
let
disk_path
=
"image.bin"
;
let
mount_path
=
"image"
;
let
res
=
{
let
disk
=
DiskSparse
::
create
(
dbg!
(
disk_path
),
1024
*
1024
*
1024
)
.unwrap
();
let
ctime
=
dbg!
(
time
::
SystemTime
::
now
()
.duration_since
(
time
::
UNIX_EPOCH
))
.unwrap
();
let
fs
=
FileSystem
::
create
(
disk
,
None
,
ctime
.as_secs
(),
ctime
.subsec_nanos
())
.unwrap
();
callback
(
fs
)
};
dbg!
(
fs
::
remove_file
(
dbg!
(
disk_path
)))
.unwrap
();
res
}
fn
with_mounted
<
T
,
F
>
(
callback
:
F
)
->
T
where
T
:
Send
+
Sync
+
'static
,
F
:
FnOnce
(
&
Path
)
->
T
+
Send
+
Sync
+
'static
,
{
let
mount_path
=
"image"
;
let
res
=
with_redoxfs
(
move
|
fs
|
{
if
cfg!
(
not
(
target_os
=
"redox"
))
{
if
!
Path
::
new
(
mount_path
)
.exists
()
{
dbg!
(
fs
::
create_dir
(
dbg!
(
mount_path
)))
.unwrap
();
}
}
let
ctime
=
dbg!
(
time
::
SystemTime
::
now
()
.duration_since
(
time
::
UNIX_EPOCH
))
.unwrap
();
let
fs
=
FileSystem
::
create
(
disk
,
None
,
ctime
.as_secs
(),
ctime
.subsec_nanos
())
.unwrap
();
let
callback_mutex
=
sync
::
Arc
::
new
(
sync
::
Mutex
::
new
(
callback
));
let
join_handle
=
crate
::
mount
(
fs
,
dbg!
(
mount_path
),
move
|
real_path
|
{
let
callback_mutex
=
callback_mutex
.clone
();
let
real_path
=
real_path
.to_owned
();
thread
::
spawn
(
move
||
{
let
res
=
{
let
mut
callback_guard
=
callback_mutex
.lock
()
.unwrap
();
let
callback
=
callback_guard
.deref_mut
();
callback
(
&
real_path
)
};
let
res
=
callback
(
&
real_path
);
if
cfg!
(
target_os
=
"redox"
)
{
dbg!
(
fs
::
remove_file
(
dbg!
(
format!
(
":{}"
,
mount_path
))))
.unwrap
();
...
...
@@ -54,9 +60,7 @@ where
.unwrap
();
join_handle
.join
()
.unwrap
()
};
dbg!
(
fs
::
remove_file
(
dbg!
(
disk_path
)))
.unwrap
();
});
if
cfg!
(
not
(
target_os
=
"redox"
))
{
dbg!
(
fs
::
remove_dir
(
dbg!
(
mount_path
)))
.unwrap
();
...
...
@@ -67,7 +71,7 @@ where
#[test]
fn
simple
()
{
with_
redoxfs
(|
path
|
{
with_
mounted
(|
path
|
{
dbg!
(
fs
::
create_dir
(
&
path
.join
(
"test"
)))
.unwrap
();
})
}
...
...
@@ -78,7 +82,7 @@ fn mmap() {
use
syscall
;
//TODO
with_
redoxfs
(|
path
|
{
with_
mounted
(|
path
|
{
use
std
::
slice
;
let
path
=
dbg!
(
path
.join
(
"test"
));
...
...
@@ -129,3 +133,25 @@ fn mmap() {
mmap_inner
(
false
);
})
}
#[test]
fn
create_remove_should_not_increase_size
()
{
with_redoxfs
(|
mut
fs
|
{
let
initially_free
=
fs
.allocator
()
.free
();
let
tree_ptr
=
TreePtr
::
<
Node
>
::
root
();
let
name
=
"test"
;
let
_
=
fs
.tx
(|
tx
|
{
tx
.create_node
(
tree_ptr
,
name
,
Node
::
MODE_FILE
|
0644
,
1
,
0
,
)
?
;
tx
.remove_node
(
tree_ptr
,
name
,
Node
::
MODE_FILE
)
})
.unwrap
();
assert_eq!
(
fs
.allocator
()
.free
(),
initially_free
);
});
}
This diff is collapsed.
Click to expand it.
src/transaction.rs
+
26
−
10
View file @
1d55c5aa
...
...
@@ -372,10 +372,10 @@ impl<'a, D: Disk> Transaction<'a, D> {
Ok
(
block
.create_ptr
())
}
pub
fn
read_tree
<
T
:
BlockTrait
+
DerefMut
<
Target
=
[
u8
]
>>
(
fn
read_tree
_and_addr
<
T
:
BlockTrait
+
DerefMut
<
Target
=
[
u8
]
>>
(
&
mut
self
,
ptr
:
TreePtr
<
T
>
,
)
->
Result
<
TreeData
<
T
>>
{
)
->
Result
<
(
TreeData
<
T
>
,
BlockAddr
)
>
{
if
ptr
.is_null
()
{
// ID is invalid (should this return None?)
#[cfg(feature
=
"log"
)]
...
...
@@ -401,7 +401,14 @@ impl<'a, D: Disk> Transaction<'a, D> {
};
data
.copy_from_slice
(
raw
.data
());
Ok
(
TreeData
::
new
(
ptr
.id
(),
data
))
Ok
((
TreeData
::
new
(
ptr
.id
(),
data
),
raw
.addr
()))
}
pub
fn
read_tree
<
T
:
BlockTrait
+
DerefMut
<
Target
=
[
u8
]
>>
(
&
mut
self
,
ptr
:
TreePtr
<
T
>
,
)
->
Result
<
TreeData
<
T
>>
{
Ok
(
self
.read_tree_and_addr
(
ptr
)
?
.0
)
}
//TODO: improve performance, reduce writes
...
...
@@ -666,7 +673,7 @@ impl<'a, D: Disk> Transaction<'a, D> {
if
let
Some
(
entry_name
)
=
entry
.name
()
{
if
entry_name
==
name
{
// Read node and test type against requested type
let
node
=
self
.read_tree
(
node_ptr
)
?
;
let
(
node
,
addr
)
=
self
.read_tree
_and_addr
(
node_ptr
)
?
;
if
node
.data
()
.mode
()
&
Node
::
MODE_TYPE
==
mode
{
if
node
.data
()
.is_dir
()
&&
node
.data
()
.size
()
>
0
...
...
@@ -677,7 +684,7 @@ impl<'a, D: Disk> Transaction<'a, D> {
}
// Save node and clear entry
node_opt
=
Some
(
node
);
node_opt
=
Some
(
(
node
,
addr
)
);
*
entry
=
DirEntry
::
default
();
break
;
}
else
if
node
.data
()
.is_dir
()
{
...
...
@@ -691,14 +698,16 @@ impl<'a, D: Disk> Transaction<'a, D> {
}
}
if
let
Some
(
mut
node
)
=
node_opt
{
if
let
Some
(
(
mut
node
,
addr
)
)
=
node_opt
{
let
links
=
node
.data
()
.links
();
if
links
>
1
{
let
remove_node
=
if
links
>
1
{
node
.data_mut
()
.set_links
(
links
-
1
);
false
}
else
{
node
.data_mut
()
.set_links
(
0
);
self
.truncate_node_inner
(
&
mut
node
,
0
)
?
;
}
true
};
if
record_offset
==
records
-
1
&&
dir
.data
()
.is_empty
()
{
let
mut
remove_record
=
record_offset
;
...
...
@@ -728,8 +737,15 @@ impl<'a, D: Disk> Transaction<'a, D> {
self
.sync_node_record_ptr
(
&
mut
parent
,
record_offset
,
dir_record_ptr
)
?
;
}
// Sync both parent and node at the same time
self
.sync_trees
(
&
[
parent
,
node
])
?
;
if
remove_node
{
self
.sync_tree
(
parent
)
?
;
unsafe
{
self
.deallocate
(
addr
);
}
}
else
{
// Sync both parent and node at the same time
self
.sync_trees
(
&
[
parent
,
node
])
?
;
}
return
Ok
(());
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment