@@ -24,7 +24,7 @@ use crate::vmm::{VMRef, images::load_vm_image_from_memory};
24
24
/// Returns the generated DTB data
25
25
pub fn crate_guest_fdt (
26
26
fdt : & Fdt ,
27
- passthrough_device_names : & Vec < String > ,
27
+ passthrough_device_names : & [ String ] ,
28
28
crate_config : & AxVMCrateConfig ,
29
29
) -> Vec < u8 > {
30
30
let mut fdt_writer = FdtWriter :: new ( ) . unwrap ( ) ;
@@ -96,9 +96,7 @@ pub fn crate_guest_fdt(
96
96
}
97
97
assert_eq ! ( previous_node_level, 0 ) ;
98
98
99
- let guest_fdt_bytes = fdt_writer. finish ( ) . unwrap ( ) ;
100
-
101
- guest_fdt_bytes
99
+ fdt_writer. finish ( ) . unwrap ( )
102
100
}
103
101
104
102
/// Generate guest FDT cache the result
@@ -133,29 +131,29 @@ enum NodeAction {
133
131
fn determine_node_action (
134
132
node : & Node ,
135
133
node_path : & str ,
136
- passthrough_device_names : & Vec < String > ,
134
+ passthrough_device_names : & [ String ] ,
137
135
) -> NodeAction {
138
136
if node. name ( ) == "/" {
139
137
// Special handling for root node
140
- return NodeAction :: RootNode ;
138
+ NodeAction :: RootNode
141
139
} else if node. name ( ) . starts_with ( "memory" ) {
142
140
// Skip memory nodes, will add them later
143
- return NodeAction :: Skip ;
141
+ NodeAction :: Skip
144
142
} else if node_path. starts_with ( "/cpus" ) {
145
- return NodeAction :: CpuNode ;
143
+ NodeAction :: CpuNode
146
144
} else if passthrough_device_names. contains ( & node_path. to_string ( ) ) {
147
145
// Fully matched passthrough device node
148
- return NodeAction :: IncludeAsPassthroughDevice ;
146
+ NodeAction :: IncludeAsPassthroughDevice
149
147
}
150
148
// Check if the node is a descendant of a passthrough device (by path inclusion and level validation)
151
149
else if is_descendant_of_passthrough_device ( node_path, node. level , passthrough_device_names) {
152
- return NodeAction :: IncludeAsChildNode ;
150
+ NodeAction :: IncludeAsChildNode
153
151
}
154
152
// Check if the node is an ancestor of a passthrough device (by path inclusion and level validation)
155
153
else if is_ancestor_of_passthrough_device ( node_path, passthrough_device_names) {
156
- return NodeAction :: IncludeAsAncestorNode ;
154
+ NodeAction :: IncludeAsAncestorNode
157
155
} else {
158
- return NodeAction :: Skip ;
156
+ NodeAction :: Skip
159
157
}
160
158
}
161
159
@@ -165,7 +163,7 @@ fn determine_node_action(
165
163
fn is_descendant_of_passthrough_device (
166
164
node_path : & str ,
167
165
node_level : usize ,
168
- passthrough_device_names : & Vec < String > ,
166
+ passthrough_device_names : & [ String ] ,
169
167
) -> bool {
170
168
for passthrough_path in passthrough_device_names {
171
169
// Check if the current node is a descendant of a passthrough device
@@ -180,9 +178,9 @@ fn is_descendant_of_passthrough_device(
180
178
181
179
// If passthrough_path is the root node "/", then its child node level should be 2
182
180
// Otherwise, the child node level should be higher than the parent node level
183
- if passthrough_path == "/" && current_node_level >= 2 {
184
- return true ;
185
- } else if passthrough_path != "/" && current_node_level > expected_parent_level {
181
+ if ( passthrough_path == "/" && current_node_level >= 2 )
182
+ || ( passthrough_path != "/" && current_node_level > expected_parent_level )
183
+ {
186
184
return true ;
187
185
}
188
186
}
@@ -210,11 +208,11 @@ fn handle_node_level_change(
210
208
/// Determine if node is an ancestor of passthrough device
211
209
fn is_ancestor_of_passthrough_device (
212
210
node_path : & str ,
213
- passthrough_device_names : & Vec < String > ,
211
+ passthrough_device_names : & [ String ] ,
214
212
) -> bool {
215
213
for passthrough_path in passthrough_device_names {
216
214
// Check if the current node is an ancestor of a passthrough device
217
- if passthrough_path. starts_with ( & node_path) && passthrough_path. len ( ) > node_path. len ( ) {
215
+ if passthrough_path. starts_with ( node_path) && passthrough_path. len ( ) > node_path. len ( ) {
218
216
// Ensure it is a true ancestor path (separated by /)
219
217
let next_char = passthrough_path. chars ( ) . nth ( node_path. len ( ) ) . unwrap_or ( ' ' ) ;
220
218
if next_char == '/' || node_path == "/" {
@@ -226,36 +224,33 @@ fn is_ancestor_of_passthrough_device(
226
224
}
227
225
228
226
/// Determine if CPU node is needed
229
- fn need_cpu_node ( phys_cpu_ids : & Vec < usize > , node : & Node , node_path : & str ) -> bool {
227
+ fn need_cpu_node ( phys_cpu_ids : & [ usize ] , node : & Node , node_path : & str ) -> bool {
230
228
let mut should_include_node = false ;
231
229
232
230
if !node_path. starts_with ( "/cpus/cpu@" ) {
233
231
should_include_node = true ;
234
- } else {
235
- if let Some ( mut cpu_reg) = node. reg ( ) {
236
- if let Some ( reg_entry) = cpu_reg. next ( ) {
237
- let cpu_address = reg_entry. address as usize ;
238
- debug ! (
239
- "Checking CPU node {} with address 0x{:x}" ,
240
- node. name( ) ,
241
- cpu_address
242
- ) ;
243
- // Check if this CPU address is in the configured phys_cpu_ids
244
- if phys_cpu_ids. contains ( & cpu_address) {
245
- should_include_node = true ;
246
- debug ! (
247
- "CPU node {} with address 0x{:x} is in phys_cpu_ids, including in guest FDT" ,
248
- node. name( ) ,
249
- cpu_address
250
- ) ;
251
- } else {
252
- debug ! (
253
- "CPU node {} with address 0x{:x} is NOT in phys_cpu_ids, skipping" ,
254
- node. name( ) ,
255
- cpu_address
256
- ) ;
257
- }
258
- }
232
+ } else if let Some ( mut cpu_reg) = node. reg ( )
233
+ && let Some ( reg_entry) = cpu_reg. next ( ) {
234
+ let cpu_address = reg_entry. address as usize ;
235
+ debug ! (
236
+ "Checking CPU node {} with address 0x{:x}" ,
237
+ node. name( ) ,
238
+ cpu_address
239
+ ) ;
240
+ // Check if this CPU address is in the configured phys_cpu_ids
241
+ if phys_cpu_ids. contains ( & cpu_address) {
242
+ should_include_node = true ;
243
+ debug ! (
244
+ "CPU node {} with address 0x{:x} is in phys_cpu_ids, including in guest FDT" ,
245
+ node. name( ) ,
246
+ cpu_address
247
+ ) ;
248
+ } else {
249
+ debug ! (
250
+ "CPU node {} with address 0x{:x} is NOT in phys_cpu_ids, skipping" ,
251
+ node. name( ) ,
252
+ cpu_address
253
+ ) ;
259
254
}
260
255
}
261
256
should_include_node
@@ -415,7 +410,5 @@ pub fn update_cpu_node(fdt: &Fdt, host_fdt: &Fdt, crate_config: &AxVMCrateConfig
415
410
}
416
411
assert_eq ! ( previous_node_level, 0 ) ;
417
412
418
- let guest_fdt_bytes = new_fdt. finish ( ) . unwrap ( ) ;
419
-
420
- guest_fdt_bytes
413
+ new_fdt. finish ( ) . unwrap ( )
421
414
}
0 commit comments