44package bridge
55
66import (
7- "encoding/base64 "
7+ "encoding/hex "
88 "encoding/json"
99 "fmt"
1010 "os"
@@ -589,20 +589,40 @@ func (b *Bridge) modifySettings(req *request) (err error) {
589589 containerID := wcowBlockCimMounts .ContainerID
590590 log .G (ctx ).Tracef ("WCOWBlockCIMMounts Add { %v}" , wcowBlockCimMounts )
591591
592- // The block device takes some time to show up. Wait for a few seconds.
593- time .Sleep (2 * time .Second )
594-
595592 var layerCIMs []* cimfs.BlockCIM
596593 layerHashes := make ([]string , len (wcowBlockCimMounts .BlockCIMs ))
597594 layerDigests := make ([][]byte , len (wcowBlockCimMounts .BlockCIMs ))
598595 for i , blockCimDevice := range wcowBlockCimMounts .BlockCIMs {
599596 // Get the scsi device path for the blockCim lun
600- devNumber , err := windevice .GetDeviceNumberFromControllerLUN (
601- req .ctx ,
602- 0 , /* controller is always 0 for wcow */
603- uint8 (blockCimDevice .Lun ))
604- if err != nil {
605- return fmt .Errorf ("err getting scsiDevPath: %w" , err )
597+ // The block device takes some time to show up. Retry for up to 2 seconds.
598+ var devNumber uint32
599+ waitStartTime := time .Now ()
600+ logTime := waitStartTime .Add (time .Second )
601+ logged := false
602+ for {
603+ devNumber , err = windevice .GetDeviceNumberFromControllerLUN (
604+ req .ctx ,
605+ 0 , /* controller is always 0 for wcow */
606+ uint8 (blockCimDevice .Lun ))
607+ if err == nil {
608+ break
609+ }
610+
611+ // Check if we've exceeded max wait time
612+ if time .Since (waitStartTime ) >= 2 * time .Second {
613+ return fmt .Errorf ("err getting scsiDevPath after 2s: %w" , err )
614+ }
615+
616+ // Log if taking longer than expected
617+ if ! logged && logTime .Before (time .Now ()) {
618+ log .G (ctx ).WithFields (map [string ]interface {}{
619+ "lun" : blockCimDevice .Lun ,
620+ "elapsed" : time .Since (waitStartTime ),
621+ }).Warn ("waiting for block CIM device to show up" )
622+ logged = true
623+ }
624+
625+ time .Sleep (10 * time .Millisecond )
606626 }
607627 physicalDevPath := fmt .Sprintf (devPathFormat , devNumber )
608628 layerCim := cimfs.BlockCIM {
@@ -615,7 +635,7 @@ func (b *Bridge) modifySettings(req *request) (err error) {
615635 return fmt .Errorf ("failed to get CIM verification info: %w" , err )
616636 }
617637 layerDigests [i ] = cimRootDigestBytes
618- layerHashes [i ] = base64 . URLEncoding .EncodeToString (cimRootDigestBytes )
638+ layerHashes [i ] = hex .EncodeToString (cimRootDigestBytes )
619639 layerCIMs = append (layerCIMs , & layerCim )
620640
621641 log .G (ctx ).Debugf ("block CIM layer digest %s, path: %s\n " , layerHashes [i ], physicalDevPath )
0 commit comments