44package bridge
55
66import (
7- "encoding/base64 "
7+ "encoding/hex "
88 "encoding/json"
99 "fmt"
1010 "os"
@@ -579,20 +579,40 @@ func (b *Bridge) modifySettings(req *request) (err error) {
579579 containerID := wcowBlockCimMounts .ContainerID
580580 log .G (ctx ).Tracef ("WCOWBlockCIMMounts { %v}" , wcowBlockCimMounts )
581581
582- // The block device takes some time to show up. Wait for a few seconds.
583- time .Sleep (2 * time .Second )
584-
585582 var layerCIMs []* cimfs.BlockCIM
586583 layerHashes := make ([]string , len (wcowBlockCimMounts .BlockCIMs ))
587584 layerDigests := make ([][]byte , len (wcowBlockCimMounts .BlockCIMs ))
588585 for i , blockCimDevice := range wcowBlockCimMounts .BlockCIMs {
589586 // Get the scsi device path for the blockCim lun
590- devNumber , err := windevice .GetDeviceNumberFromControllerLUN (
591- req .ctx ,
592- 0 , /* controller is always 0 for wcow */
593- uint8 (blockCimDevice .Lun ))
594- if err != nil {
595- return fmt .Errorf ("err getting scsiDevPath: %w" , err )
587+ // The block device takes some time to show up. Retry for up to 2 seconds.
588+ var devNumber uint32
589+ waitStartTime := time .Now ()
590+ logTime := waitStartTime .Add (time .Second )
591+ logged := false
592+ for {
593+ devNumber , err = windevice .GetDeviceNumberFromControllerLUN (
594+ req .ctx ,
595+ 0 , /* controller is always 0 for wcow */
596+ uint8 (blockCimDevice .Lun ))
597+ if err == nil {
598+ break
599+ }
600+
601+ // Check if we've exceeded max wait time
602+ if time .Since (waitStartTime ) >= 2 * time .Second {
603+ return fmt .Errorf ("err getting scsiDevPath after 2s: %w" , err )
604+ }
605+
606+ // Log if taking longer than expected
607+ if ! logged && logTime .Before (time .Now ()) {
608+ log .G (ctx ).WithFields (map [string ]interface {}{
609+ "lun" : blockCimDevice .Lun ,
610+ "elapsed" : time .Since (waitStartTime ),
611+ }).Warn ("waiting for block CIM device to show up" )
612+ logged = true
613+ }
614+
615+ time .Sleep (10 * time .Millisecond )
596616 }
597617 physicalDevPath := fmt .Sprintf (devPathFormat , devNumber )
598618 layerCim := cimfs.BlockCIM {
@@ -605,7 +625,7 @@ func (b *Bridge) modifySettings(req *request) (err error) {
605625 return fmt .Errorf ("failed to get CIM verification info: %w" , err )
606626 }
607627 layerDigests [i ] = cimRootDigestBytes
608- layerHashes [i ] = base64 . URLEncoding .EncodeToString (cimRootDigestBytes )
628+ layerHashes [i ] = hex .EncodeToString (cimRootDigestBytes )
609629 layerCIMs = append (layerCIMs , & layerCim )
610630
611631 log .G (ctx ).Debugf ("block CIM layer digest %s, path: %s\n " , layerHashes [i ], physicalDevPath )
0 commit comments