@@ -152,7 +152,8 @@ impl BDA {
152152 F : Read + Seek + SyncAll ,
153153 {
154154 let header = match StaticHeader :: setup ( f) ? {
155- Some ( header) => header,
155+ Some ( SetupResult :: Ok ( header) ) => header,
156+ Some ( SetupResult :: OkWithError ( header, _err) ) => header,
156157 None => return Ok ( None ) ,
157158 } ;
158159
@@ -241,6 +242,22 @@ impl BDA {
241242 }
242243}
243244
245+ #[ derive( Debug ) ]
246+ pub enum SetupResult {
247+ Ok ( StaticHeader ) ,
248+ OkWithError ( StaticHeader , StratisError ) ,
249+ }
250+
251+ impl SetupResult {
252+ fn new ( header : StaticHeader ) -> SetupResult {
253+ SetupResult :: Ok ( header)
254+ }
255+
256+ fn new_with_error ( header : StaticHeader , error : StratisError ) -> SetupResult {
257+ SetupResult :: OkWithError ( header, error)
258+ }
259+ }
260+
244261#[ derive( Eq , PartialEq ) ]
245262pub struct StaticHeader {
246263 blkdev_size : Sectors ,
@@ -283,7 +300,7 @@ impl StaticHeader {
283300 /// Return an error if the sigblocks differ in some unaccountable way.
284301 /// Returns an error if a write intended to repair an ill-formed,
285302 /// unreadable, or stale signature block failed.
286- fn setup < F > ( f : & mut F ) -> StratisResult < Option < StaticHeader > >
303+ fn setup < F > ( f : & mut F ) -> StratisResult < Option < SetupResult > >
287304 where
288305 F : Read + Seek + SyncAll ,
289306 {
@@ -298,41 +315,44 @@ impl StaticHeader {
298315 match ( loc_1, loc_2) {
299316 ( Some ( loc_1) , Some ( loc_2) ) => {
300317 if loc_1 == loc_2 {
301- Ok ( Some ( loc_1) )
318+ Ok ( Some ( SetupResult :: new ( loc_1) ) )
302319 } else if loc_1. initialization_time == loc_2. initialization_time {
303320 // Inexplicable disagreement among static headers
304321 let err_str = "Appeared to be a Stratis device, but signature blocks disagree." ;
305- Err ( StratisError :: Engine ( ErrorEnum :: Invalid , err_str. into ( ) ) )
322+ Ok ( Some (
323+ SetupResult :: new_with_error (
324+ loc_1,
325+ StratisError :: Engine ( ErrorEnum :: Invalid , err_str. into ( ) ) ) ) )
306326 } else if loc_1. initialization_time > loc_2. initialization_time {
307327 // If the first header block is newer, overwrite second with
308328 // contents of first.
309329 BDA :: write ( f, & buf_loc_1, MetadataLocation :: Second ) ?;
310- Ok ( Some ( loc_1) )
330+ Ok ( Some ( SetupResult :: new ( loc_1) ) )
311331 } else {
312332 // The second header block must be newer, so overwrite first
313333 // with contents of second.
314334 BDA :: write ( f, & buf_loc_2, MetadataLocation :: First ) ?;
315- Ok ( Some ( loc_2) )
335+ Ok ( Some ( SetupResult :: new ( loc_2) ) )
316336 }
317337 }
318338 ( None , None ) => Ok ( None ) ,
319339 ( Some ( loc_1) , None ) => {
320340 // Copy 1 has valid Stratis BDA, copy 2 has no magic, re-write copy 2
321341 BDA :: write ( f, & buf_loc_1, MetadataLocation :: Second ) ?;
322- Ok ( Some ( loc_1) )
342+ Ok ( Some ( SetupResult :: new ( loc_1) ) )
323343 }
324344 ( None , Some ( loc_2) ) => {
325345 // Copy 2 has valid Stratis BDA, copy 1 has no magic, re-write copy 1
326346 BDA :: write ( f, & buf_loc_2, MetadataLocation :: First ) ?;
327- Ok ( Some ( loc_2) )
347+ Ok ( Some ( SetupResult :: new ( loc_2) ) )
328348 }
329349 }
330350 }
331351 ( Ok ( loc_1) , Err ( loc_2) ) => {
332352 // Re-write copy 2
333- if loc_1 . is_some ( ) {
353+ if let Some ( loc_1 ) = loc_1 {
334354 BDA :: write ( f, & buf_loc_1, MetadataLocation :: Second ) ?;
335- Ok ( loc_1)
355+ Ok ( Some ( SetupResult :: new ( loc_1) ) )
336356 } else {
337357 // Location 1 doesn't have a signature, but location 2 did, but it got an error,
338358 // lets return the error instead as this appears to be a stratis device that
@@ -342,9 +362,9 @@ impl StaticHeader {
342362 }
343363 ( Err ( loc_1) , Ok ( loc_2) ) => {
344364 // Re-write copy 1
345- if loc_2 . is_some ( ) {
365+ if let Some ( loc_2 ) = loc_2 {
346366 BDA :: write ( f, & buf_loc_2, MetadataLocation :: First ) ?;
347- Ok ( loc_2)
367+ Ok ( Some ( SetupResult :: new ( loc_2) ) )
348368 } else {
349369 // Location 2 doesn't have a signature, but location 1 did, but it got an error,
350370 // lets return the error instead as this appears to be a stratis device that
@@ -363,10 +383,12 @@ impl StaticHeader {
363383 // Copy 1 read OK, 2 resulted in an IO error
364384 match StaticHeader :: sigblock_from_buf ( & buf_loc_1) {
365385 Ok ( loc_1) => {
366- if loc_1 . is_some ( ) {
386+ if let Some ( loc_1 ) = loc_1 {
367387 BDA :: write ( f, & buf_loc_1, MetadataLocation :: Second ) ?;
388+ Ok ( Some ( SetupResult :: new ( loc_1) ) )
389+ } else {
390+ Ok ( None )
368391 }
369- Ok ( loc_1)
370392 }
371393 Err ( e) => {
372394 // Unable to determine if location 2 has a signature, but location 1 did,
@@ -380,10 +402,12 @@ impl StaticHeader {
380402 // Copy 2 read OK, 1 resulted in IO Error
381403 match StaticHeader :: sigblock_from_buf ( & buf_loc_2) {
382404 Ok ( loc_2) => {
383- if loc_2 . is_some ( ) {
405+ if let Some ( loc_2 ) = loc_2 {
384406 BDA :: write ( f, & buf_loc_2, MetadataLocation :: First ) ?;
407+ Ok ( Some ( SetupResult :: new ( loc_2) ) )
408+ } else {
409+ Ok ( None )
385410 }
386- Ok ( loc_2)
387411 }
388412 Err ( e) => {
389413 // Unable to determine if location 1 has a signature, but location 2 did,
@@ -411,7 +435,8 @@ impl StaticHeader {
411435 // it must also have correct CRC, no weird stuff in fields,
412436 // etc!
413437 match StaticHeader :: setup ( f) {
414- Ok ( Some ( sh) ) => Ok ( Some ( ( sh. pool_uuid , sh. dev_uuid ) ) ) ,
438+ Ok ( Some ( SetupResult :: Ok ( sh) ) ) => Ok ( Some ( ( sh. pool_uuid , sh. dev_uuid ) ) ) ,
439+ Ok ( Some ( SetupResult :: OkWithError ( sh, _err) ) ) => Ok ( Some ( ( sh. pool_uuid , sh. dev_uuid ) ) ) ,
415440 Ok ( None ) => Ok ( None ) ,
416441 Err ( err) => Err ( err) ,
417442 }
0 commit comments