Skip to content

Commit 65c47da

Browse files
authored
Merge pull request #1576 from GuillaumeGomez/correct-excessive-indentation
Correct excessive indentation in StaticHeader::setup
2 parents 14614b4 + 1b1cc7b commit 65c47da

File tree

1 file changed

+82
-92
lines changed
  • src/engine/strat_engine/backstore/metadata

1 file changed

+82
-92
lines changed

src/engine/strat_engine/backstore/metadata/bda.rs

Lines changed: 82 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -327,111 +327,101 @@ impl StaticHeader {
327327
F: Read + Seek + SyncAll,
328328
{
329329
match BDA::read(f) {
330-
(Ok(buf_loc_1), Ok(buf_loc_2)) => {
331-
// We read both copies without an IO error.
332-
match (
333-
StaticHeader::sigblock_from_buf(&buf_loc_1),
334-
StaticHeader::sigblock_from_buf(&buf_loc_2),
335-
) {
336-
(Ok(loc_1), Ok(loc_2)) => {
337-
match (loc_1, loc_2) {
338-
(Some(loc_1), Some(loc_2)) => {
339-
if loc_1 == loc_2 {
340-
Ok(Some(loc_1))
341-
} else if loc_1.initialization_time == loc_2.initialization_time {
342-
// Inexplicable disagreement among static headers
343-
let err_str = "Appeared to be a Stratis device, but signature blocks disagree.";
344-
Err(StratisError::Engine(ErrorEnum::Invalid, err_str.into()))
345-
} else if loc_1.initialization_time > loc_2.initialization_time {
346-
// If the first header block is newer, overwrite second with
347-
// contents of first.
348-
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
349-
Ok(Some(loc_1))
350-
} else {
351-
// The second header block must be newer, so overwrite first
352-
// with contents of second.
353-
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
354-
Ok(Some(loc_2))
355-
}
356-
}
357-
(None, None) => Ok(None),
358-
(Some(loc_1), None) => {
359-
// Copy 1 has valid Stratis BDA, copy 2 has no magic, re-write copy 2
360-
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
361-
Ok(Some(loc_1))
362-
}
363-
(None, Some(loc_2)) => {
364-
// Copy 2 has valid Stratis BDA, copy 1 has no magic, re-write copy 1
365-
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
366-
Ok(Some(loc_2))
367-
}
368-
}
369-
}
370-
(Ok(loc_1), Err(loc_2)) => {
371-
// Re-write copy 2
372-
if loc_1.is_some() {
330+
// We read both copies without an IO error.
331+
(Ok(buf_loc_1), Ok(buf_loc_2)) => match (
332+
StaticHeader::sigblock_from_buf(&buf_loc_1),
333+
StaticHeader::sigblock_from_buf(&buf_loc_2),
334+
) {
335+
(Ok(loc_1), Ok(loc_2)) => match (loc_1, loc_2) {
336+
(Some(loc_1), Some(loc_2)) => {
337+
if loc_1 == loc_2 {
338+
Ok(Some(loc_1))
339+
} else if loc_1.initialization_time == loc_2.initialization_time {
340+
// Inexplicable disagreement among static headers
341+
let err_str =
342+
"Appeared to be a Stratis device, but signature blocks disagree.";
343+
Err(StratisError::Engine(ErrorEnum::Invalid, err_str.into()))
344+
} else if loc_1.initialization_time > loc_2.initialization_time {
345+
// If the first header block is newer, overwrite second with
346+
// contents of first.
373347
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
374-
Ok(loc_1)
348+
Ok(Some(loc_1))
375349
} else {
376-
// Location 1 doesn't have a signature, but location 2 did, but it got an error,
377-
// lets return the error instead as this appears to be a stratis device that
378-
// has gotten in a bad state.
379-
Err(loc_2)
380-
}
381-
}
382-
(Err(loc_1), Ok(loc_2)) => {
383-
// Re-write copy 1
384-
if loc_2.is_some() {
350+
// The second header block must be newer, so overwrite first
351+
// with contents of second.
385352
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
386-
Ok(loc_2)
387-
} else {
388-
// Location 2 doesn't have a signature, but location 1 did, but it got an error,
389-
// lets return the error instead as this appears to be a stratis device that
390-
// has gotten in a bad state.
391-
Err(loc_1)
353+
Ok(Some(loc_2))
392354
}
393355
}
394-
(Err(_), Err(_)) => {
395-
let err_str =
396-
"Appeared to be a Stratis device, but no valid sigblock found";
397-
Err(StratisError::Engine(ErrorEnum::Invalid, err_str.into()))
356+
(None, None) => Ok(None),
357+
(Some(loc_1), None) => {
358+
// Copy 1 has valid Stratis BDA, copy 2 has no magic, re-write copy 2
359+
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
360+
Ok(Some(loc_1))
398361
}
399-
}
400-
}
401-
(Ok(buf_loc_1), Err(_)) => {
402-
// Copy 1 read OK, 2 resulted in an IO error
403-
match StaticHeader::sigblock_from_buf(&buf_loc_1) {
404-
Ok(loc_1) => {
405-
if loc_1.is_some() {
406-
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
407-
}
408-
Ok(loc_1)
362+
(None, Some(loc_2)) => {
363+
// Copy 2 has valid Stratis BDA, copy 1 has no magic, re-write copy 1
364+
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
365+
Ok(Some(loc_2))
409366
}
410-
Err(e) => {
411-
// Unable to determine if location 2 has a signature, but location 1 did,
412-
// but it got an error, lets return the error instead as this appears to
413-
// be a stratis device that has gotten in a bad state.
414-
Err(e)
367+
},
368+
(Ok(loc_1), Err(loc_2)) => {
369+
if loc_1.is_some() {
370+
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
371+
Ok(loc_1)
372+
} else {
373+
// Location 1 doesn't have a signature, but location 2 did, but it got an error,
374+
// lets return the error instead as this appears to be a stratis device that
375+
// has gotten in a bad state.
376+
Err(loc_2)
415377
}
416378
}
417-
}
418-
(Err(_), Ok(buf_loc_2)) => {
419-
// Copy 2 read OK, 1 resulted in IO Error
420-
match StaticHeader::sigblock_from_buf(&buf_loc_2) {
421-
Ok(loc_2) => {
422-
if loc_2.is_some() {
423-
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
424-
}
379+
(Err(loc_1), Ok(loc_2)) => {
380+
if loc_2.is_some() {
381+
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
425382
Ok(loc_2)
383+
} else {
384+
// Location 2 doesn't have a signature, but location 1 did, but it got an error,
385+
// lets return the error instead as this appears to be a stratis device that
386+
// has gotten in a bad state.
387+
Err(loc_1)
426388
}
427-
Err(e) => {
428-
// Unable to determine if location 1 has a signature, but location 2 did,
429-
// but it got an error, lets return the error instead as this appears to
430-
// be a stratis device that has gotten in a bad state.
431-
Err(e)
389+
}
390+
(Err(_), Err(_)) => {
391+
let err_str = "Appeared to be a Stratis device, but no valid sigblock found";
392+
Err(StratisError::Engine(ErrorEnum::Invalid, err_str.into()))
393+
}
394+
},
395+
// Copy 1 read OK, 2 resulted in an IO error
396+
(Ok(buf_loc_1), Err(_)) => match StaticHeader::sigblock_from_buf(&buf_loc_1) {
397+
Ok(loc_1) => {
398+
if loc_1.is_some() {
399+
BDA::write(f, &buf_loc_1, MetadataLocation::Second)?;
432400
}
401+
Ok(loc_1)
433402
}
434-
}
403+
Err(e) => {
404+
// Unable to determine if location 2 has a signature, but location 1 did,
405+
// but it got an error, lets return the error instead as this appears to
406+
// be a stratis device that has gotten in a bad state.
407+
Err(e)
408+
}
409+
},
410+
// Copy 2 read OK, 1 resulted in IO Error
411+
(Err(_), Ok(buf_loc_2)) => match StaticHeader::sigblock_from_buf(&buf_loc_2) {
412+
Ok(loc_2) => {
413+
if loc_2.is_some() {
414+
BDA::write(f, &buf_loc_2, MetadataLocation::First)?;
415+
}
416+
Ok(loc_2)
417+
}
418+
Err(e) => {
419+
// Unable to determine if location 1 has a signature, but location 2 did,
420+
// but it got an error, lets return the error instead as this appears to
421+
// be a stratis device that has gotten in a bad state.
422+
Err(e)
423+
}
424+
},
435425
(Err(_), Err(_)) => {
436426
// Unable to read the device at all.
437427
let err_str = "Unable to read data at sigblock locations.";

0 commit comments

Comments
 (0)