1
- use std:: {
2
- ops:: { Deref , Range } ,
3
- rc:: Rc ,
4
- } ;
1
+ use std:: ops:: { Deref , Range } ;
5
2
6
3
use super :: {
7
4
rebuild_descriptor:: RebuildDescriptor ,
@@ -13,7 +10,10 @@ use super::{
13
10
SEGMENT_TASKS ,
14
11
} ;
15
12
16
- use crate :: gen_rebuild_instances;
13
+ use crate :: {
14
+ gen_rebuild_instances,
15
+ rebuild:: rebuilders:: { FullRebuild , RangeRebuilder } ,
16
+ } ;
17
17
18
18
/// A Bdev rebuild job is responsible for managing a rebuild (copy) which reads
19
19
/// from source_hdl and writes into destination_hdl from specified start to end.
@@ -59,47 +59,50 @@ gen_rebuild_instances!(BdevRebuildJob);
59
59
/// A rebuild job which is responsible for rebuilding from
60
60
/// source to target of the `RebuildDescriptor`.
61
61
pub ( super ) struct BdevRebuildJobBackend {
62
- /// The next block to be rebuilt.
63
- next : u64 ,
64
62
/// A pool of tasks which perform the actual data rebuild.
65
63
task_pool : RebuildTasks ,
66
64
/// A generic rebuild descriptor.
67
- descriptor : Rc < RebuildDescriptor > ,
65
+ copier : FullRebuild < RebuildDescriptor > ,
68
66
/// Notification callback with src and dst uri's.
69
67
notify_fn : fn ( & str , & str ) -> ( ) ,
70
68
}
71
69
72
70
#[ async_trait:: async_trait( ?Send ) ]
73
71
impl RebuildBackend for BdevRebuildJobBackend {
74
72
fn on_state_change ( & mut self ) {
75
- ( self . notify_fn ) ( & self . descriptor . src_uri , & self . descriptor . dst_uri ) ;
73
+ let desc = self . common_desc ( ) ;
74
+ ( self . notify_fn ) ( & desc. src_uri , & desc. dst_uri ) ;
76
75
}
77
76
78
77
fn common_desc ( & self ) -> & RebuildDescriptor {
79
- & self . descriptor
78
+ self . copier . desc ( )
79
+ }
80
+
81
+ fn blocks_remaining ( & self ) -> u64 {
82
+ self . copier . blocks_remaining ( )
83
+ }
84
+
85
+ fn is_partial ( & self ) -> bool {
86
+ self . copier . is_partial ( )
80
87
}
81
88
82
89
fn task_pool ( & self ) -> & RebuildTasks {
83
90
& self . task_pool
84
91
}
85
92
86
93
fn schedule_task_by_id ( & mut self , id : usize ) -> bool {
87
- if self . next >= self . descriptor . range . end {
88
- false
89
- } else {
90
- let next = std:: cmp:: min (
91
- self . next + self . descriptor . segment_size_blks ,
92
- self . descriptor . range . end ,
93
- ) ;
94
- self . task_pool . schedule_segment_rebuild (
95
- id,
96
- self . next ,
97
- self . descriptor . clone ( ) ,
98
- ) ;
99
- self . task_pool . active += 1 ;
100
- self . next = next;
101
- true
102
- }
94
+ self . copier
95
+ . next ( )
96
+ . map ( |blk| {
97
+ self . task_pool . schedule_segment_rebuild (
98
+ id,
99
+ blk,
100
+ self . copier . copier ( ) ,
101
+ ) ;
102
+ self . task_pool . active += 1 ;
103
+ true
104
+ } )
105
+ . unwrap_or_default ( )
103
106
}
104
107
105
108
async fn await_one_task ( & mut self ) -> Option < TaskResult > {
@@ -110,7 +113,7 @@ impl RebuildBackend for BdevRebuildJobBackend {
110
113
impl std:: fmt:: Debug for BdevRebuildJobBackend {
111
114
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
112
115
f. debug_struct ( "BdevRebuildJob" )
113
- . field ( "next" , & self . next )
116
+ . field ( "next" , & self . copier . peek_next ( ) )
114
117
. finish ( )
115
118
}
116
119
}
@@ -130,15 +133,10 @@ impl BdevRebuildJobBackend {
130
133
notify_fn : fn ( & str , & str ) -> ( ) ,
131
134
descriptor : RebuildDescriptor ,
132
135
) -> Result < Self , RebuildError > {
133
- let be = Self {
134
- next : descriptor. range . start ,
136
+ Ok ( Self {
135
137
task_pool,
136
- descriptor : Rc :: new ( descriptor) ,
138
+ copier : FullRebuild :: new ( descriptor) ,
137
139
notify_fn,
138
- } ;
139
-
140
- info ! ( "{be}: backend created" ) ;
141
-
142
- Ok ( be)
140
+ } )
143
141
}
144
142
}
0 commit comments