Skip to content

Commit e7ec4aa

Browse files
authored
CWCOW: roothash and graceful timeout fixes (#2593)
* CWCOW: roothash and graceful timeout fixes * C-WCOW: Update pkg/ociwclayer/cim/import.go comment --------- Signed-off-by: Mahati Chamarthy <mahati.chamarthy@gmail.com>
1 parent 9eea3de commit e7ec4aa

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
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"
@@ -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)

pkg/ociwclayer/cim/import.go

Lines changed: 4 additions & 4 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,8 +98,8 @@ 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.
102-
// this same base64 string can be used in the confidential policy.
101+
// for convenience write a file that has the hex encoded root digest of the generated verified CIM.
102+
// this same hex string can be used in the confidential policy.
103103
digest, err := cimfs.GetVerificationInfo(blockPath)
104104
if err != nil {
105105
return fmt.Errorf("failed to query verified info of the CIM layer: %w", err)
@@ -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) {

0 commit comments

Comments
 (0)