Commit 7d32b54
T3871: order bootstrap naming by PCIe distance from the root complex
compute_bootstrap_plan() sorted candidates purely by MAC address, which
is fully deterministic but has no relationship to physical topology: a
NIC wired directly to the CPU's PCIe root complex (e.g. an onboard LOM)
could end up sorted last just because its MAC happens to be numerically
higher than an add-in card several PCIe-switch hops away.
Add pcie_distance(): counts PCI domain:bus:device.function segments
(e.g. 0000:00:1f.6) in the fully-resolved sysfs path of an interface's
'device' symlink. Non-PCI hops in that path (virtioN, usbN, the
net/<ifname> tail) simply don't match the pattern and are skipped, so
virtio's device->virtioN->real-PCI-parent indirection (confirmed on a
real virtio_net host) needs no special-casing, and multi-function
siblings at the same slot aren't double-counted. Returns a sort-last
sentinel (PCIE_DISTANCE_UNKNOWN) if the device symlink is missing/
unresolvable or the path has no PCI segment at all (e.g. a USB NIC).
compute_bootstrap_plan()'s sort key becomes (pcie_distance, mac) instead
of mac alone - topology first, MAC only as a tie-break among NICs at the
same depth. Both are static hardware properties (slot wiring, permanent
address), so this stays a pure, deterministic function of the discovered
hardware - the core T3871 guarantee (same hardware, same names, every
boot) is unaffected.
Chose raw sysfs path parsing over pyudev's find_parent('pci') (both
viable; pyudev is already a project dependency used elsewhere) to keep
this boot-critical script's existing dependency-light style - stdlib
only, matching is_wireless_interface()'s sysfs-symlink-check pattern
right next to it.
Adds TestPcieDistance (shallow device, cascaded bridges, the virtio
indirection case, missing/broken device symlink, no-PCI-segment/USB
case) and extends TestComputeBootstrapPlan with distance-vs-MAC
ordering cases; existing tests default pcie_distance to a constant via
setUp() so they keep exercising pure MAC-rank ordering unmodified.
Verified the two new distance-ordering tests actually fail against the
prior MAC-only sort before confirming they pass with the fix.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent f319d10 commit 7d32b54
2 files changed
Lines changed: 160 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
200 | 232 | | |
201 | 233 | | |
202 | 234 | | |
| |||
284 | 316 | | |
285 | 317 | | |
286 | 318 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
294 | 331 | | |
295 | 332 | | |
296 | 333 | | |
| |||
313 | 350 | | |
314 | 351 | | |
315 | 352 | | |
316 | | - | |
| 353 | + | |
317 | 354 | | |
318 | 355 | | |
319 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
252 | 318 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
257 | 326 | | |
258 | 327 | | |
259 | 328 | | |
| |||
262 | 331 | | |
263 | 332 | | |
264 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
265 | 339 | | |
266 | 340 | | |
267 | 341 | | |
| |||
328 | 402 | | |
329 | 403 | | |
330 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
331 | 442 | | |
332 | 443 | | |
333 | 444 | | |
| |||
0 commit comments