Skip to content

Commit c3659b4

Browse files
committed
CWCOW: roothash and graceful timeout fixes
Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
1 parent 9e4e729 commit c3659b4

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

internal/gcs-sidecar/handlers.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package bridge
55

66
import (
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)

pkg/ociwclayer/cim/import.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"archive/tar"
88
"bufio"
99
"context"
10-
"encoding/base64"
10+
"encoding/hex"
1111
"errors"
1212
"fmt"
1313
"io"
@@ -98,7 +98,7 @@ func WithParentLayers(parentLayers []*cimfs.BlockCIM) BlockCIMLayerImportOpt {
9898

9999
func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error {
100100
log.G(ctx).Debugf("writing integrity checksum file for block CIM `%s`", blockPath)
101-
// for convenience write a file that has the base64 encoded root digest of the generated verified CIM.
101+
// for convenience write a file that has the hex encoded root digest of the generated verified CIM.
102102
// this same base64 string can be used in the confidential policy.
103103
digest, err := cimfs.GetVerificationInfo(blockPath)
104104
if err != nil {
@@ -111,7 +111,7 @@ func writeIntegrityChecksumInfoFile(ctx context.Context, blockPath string) error
111111
}
112112
defer digestFile.Close()
113113

114-
digestStr := base64.URLEncoding.EncodeToString(digest)
114+
digestStr := hex.EncodeToString(digest)
115115
if wn, err := digestFile.WriteString(digestStr); err != nil {
116116
return fmt.Errorf("failed to write verification info: %w", err)
117117
} else if wn != len(digestStr) {
@@ -358,5 +358,6 @@ func MergeBlockCIMLayersWithOpts(ctx context.Context, sourceCIMs []*cimfs.BlockC
358358
return fmt.Errorf("append VHD footer to block CIM: %w", err)
359359
}
360360
}
361+
361362
return nil
362363
}

0 commit comments

Comments
 (0)