Skip to content

Commit 0c807d6

Browse files
committed
block cim create and mount check update
Signed-off-by: Pooja Mahadev Soundalgekar <pomahade@microsoft.com>
1 parent 84e7d69 commit 0c807d6

8 files changed

Lines changed: 82 additions & 35 deletions

File tree

internal/wclayer/cim/cim_writer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestSingleFileWriterTypeMismatch(t *testing.T) {
14-
if !cimfs.IsBlockCimSupported() {
14+
if !cimfs.IsBlockCimWriteSupported() {
1515
t.Skipf("BlockCIM not supported")
1616
}
1717

@@ -34,7 +34,7 @@ func TestSingleFileWriterTypeMismatch(t *testing.T) {
3434
}
3535

3636
func TestSingleFileWriterInvalidBlockType(t *testing.T) {
37-
if !cimfs.IsBlockCimSupported() {
37+
if !cimfs.IsBlockCimWriteSupported() {
3838
t.Skipf("BlockCIM not supported")
3939
}
4040

internal/winapi/utils.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"unsafe"
99

1010
"golang.org/x/sys/windows"
11-
12-
"github.com/Microsoft/hcsshim/internal/winapi/cimfs"
1311
)
1412

1513
// Uint16BufferToSlice wraps a uint16 pointer-and-length into a slice
@@ -83,8 +81,3 @@ func ConvertStringSetToSlice(buf []byte) ([]string, error) {
8381
func ParseUtf16LE(b []byte) string {
8482
return windows.UTF16PtrToString((*uint16)(unsafe.Pointer(&b[0])))
8583
}
86-
87-
// CimFsSupported checks if either CIMFS dll is present on the system.
88-
func CimFsSupported() bool {
89-
return cimfs.Supported()
90-
}

pkg/cimfs/cim_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func TestCimReadWrite(t *testing.T) {
226226
}
227227

228228
func TestBlockCIMInvalidCimName(t *testing.T) {
229-
if !IsBlockCimSupported() {
229+
if !IsBlockCimWriteSupported() {
230230
t.Skip("blockCIM not supported on this OS version")
231231
}
232232

@@ -239,7 +239,7 @@ func TestBlockCIMInvalidCimName(t *testing.T) {
239239
}
240240

241241
func TestBlockCIMInvalidBlockPath(t *testing.T) {
242-
if !IsBlockCimSupported() {
242+
if !IsBlockCimWriteSupported() {
243243
t.Skip("blockCIM not supported on this OS version")
244244
}
245245

@@ -252,7 +252,7 @@ func TestBlockCIMInvalidBlockPath(t *testing.T) {
252252
}
253253

254254
func TestBlockCIMInvalidType(t *testing.T) {
255-
if !IsBlockCimSupported() {
255+
if !IsBlockCimWriteSupported() {
256256
t.Skip("blockCIM not supported on this OS version")
257257
}
258258

@@ -265,7 +265,7 @@ func TestBlockCIMInvalidType(t *testing.T) {
265265
}
266266

267267
func TestCIMMergeInvalidType(t *testing.T) {
268-
if !IsBlockCimSupported() {
268+
if !IsBlockCimMountSupported() {
269269
t.Skip("blockCIM not supported on this OS version")
270270
}
271271

@@ -282,7 +282,7 @@ func TestCIMMergeInvalidType(t *testing.T) {
282282
}
283283

284284
func TestCIMMergeInvalidSourceType(t *testing.T) {
285-
if !IsBlockCimSupported() {
285+
if !IsBlockCimMountSupported() {
286286
t.Skip("blockCIM not supported on this OS version")
287287
}
288288

@@ -313,7 +313,7 @@ func TestCIMMergeInvalidSourceType(t *testing.T) {
313313
}
314314

315315
func TestCIMMergeInvalidLength(t *testing.T) {
316-
if !IsBlockCimSupported() {
316+
if !IsBlockCimMountSupported() {
317317
t.Skip("blockCIM not supported on this OS version")
318318
}
319319

@@ -329,7 +329,7 @@ func TestCIMMergeInvalidLength(t *testing.T) {
329329
}
330330

331331
func TestBlockCIMEmpty(t *testing.T) {
332-
if !IsBlockCimSupported() {
332+
if !IsBlockCimWriteSupported() {
333333
t.Skip("blockCIM not supported on this OS version")
334334
}
335335

@@ -347,7 +347,7 @@ func TestBlockCIMEmpty(t *testing.T) {
347347
}
348348

349349
func TestBlockCIMSingleFileReadWrite(t *testing.T) {
350-
if !IsBlockCimSupported() {
350+
if !IsBlockCimMountSupported() {
351351
t.Skip("blockCIM not supported on this OS version")
352352
}
353353

@@ -411,7 +411,7 @@ func createBlockDevice(t *testing.T, dir string) string {
411411
}
412412

413413
func TestBlockCIMBlockDeviceReadWrite(t *testing.T) {
414-
if !IsBlockCimSupported() {
414+
if !IsBlockCimMountSupported() {
415415
t.Skip("blockCIM not supported on this OS version")
416416
}
417417

@@ -440,7 +440,7 @@ func TestBlockCIMBlockDeviceReadWrite(t *testing.T) {
440440
}
441441

442442
func TestMergedBlockCIMs(rootT *testing.T) {
443-
if !IsBlockCimSupported() {
443+
if !IsBlockCimMountSupported() {
444444
rootT.Skipf("BlockCIM not supported")
445445
}
446446

@@ -534,7 +534,7 @@ func TestMergedBlockCIMs(rootT *testing.T) {
534534
}
535535

536536
func TestTombstoneInMergedBlockCIMs(rootT *testing.T) {
537-
if !IsBlockCimSupported() {
537+
if !IsBlockCimMountSupported() {
538538
rootT.Skipf("BlockCIM not supported")
539539
}
540540

@@ -608,7 +608,7 @@ func TestTombstoneInMergedBlockCIMs(rootT *testing.T) {
608608
}
609609

610610
func TestMergedLinksInMergedBlockCIMs(rootT *testing.T) {
611-
if !IsBlockCimSupported() {
611+
if !IsBlockCimMountSupported() {
612612
rootT.Skipf("BlockCIM not supported")
613613
}
614614

@@ -688,7 +688,7 @@ func TestMergedLinksInMergedBlockCIMs(rootT *testing.T) {
688688
}
689689

690690
func TestVerifiedSingleFileBlockCIMMount(t *testing.T) {
691-
if !IsVerifiedCimSupported() {
691+
if !IsVerifiedCimMountSupported() {
692692
t.Skipf("verified CIMs are not supported")
693693
}
694694

@@ -733,7 +733,7 @@ func TestVerifiedSingleFileBlockCIMMount(t *testing.T) {
733733
}
734734

735735
func TestVerifiedSingleFileBlockCIMMountReadFailure(t *testing.T) {
736-
if !IsVerifiedCimSupported() {
736+
if !IsVerifiedCimMountSupported() {
737737
t.Skipf("verified CIMs are not supported")
738738
}
739739

@@ -777,7 +777,7 @@ func TestVerifiedSingleFileBlockCIMMountReadFailure(t *testing.T) {
777777
}
778778

779779
func TestMergedVerifiedBlockCIMs(rootT *testing.T) {
780-
if !IsVerifiedCimSupported() {
780+
if !IsVerifiedCimWriteSupported() {
781781
rootT.Skipf("verified BlockCIMs are not supported")
782782
}
783783

pkg/cimfs/cim_writer_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func CreateBlockCIMWithOptions(ctx context.Context, bCIM *BlockCIM, options ...B
118118
}
119119

120120
// Check OS support
121-
if !IsBlockCimSupported() {
121+
if !IsBlockCimWriteSupported() {
122122
return nil, fmt.Errorf("block CIM not supported on this OS version")
123123
}
124124

125-
if config.dataIntegrity && !IsVerifiedCimSupported() {
125+
if config.dataIntegrity && !IsVerifiedCimWriteSupported() {
126126
return nil, fmt.Errorf("verified CIMs are not supported on this OS version")
127127
}
128128

@@ -436,7 +436,7 @@ func GetCimUsage(ctx context.Context, cimPath string) (uint64, error) {
436436
// files with the same path at all other CIMs) When mounting this merged CIM the source
437437
// CIMs MUST be provided in the exact same order.
438438
func MergeBlockCIMsWithOpts(ctx context.Context, mergedCIM *BlockCIM, sourceCIMs []*BlockCIM, opts ...BlockCIMOpt) (err error) {
439-
if !IsMergedCimSupported() {
439+
if !IsMergedCimWriteSupported() {
440440
return fmt.Errorf("merged CIMs aren't supported on this OS version")
441441
} else if len(sourceCIMs) < 2 {
442442
return fmt.Errorf("need at least 2 source CIMs, got %d: %w", len(sourceCIMs), os.ErrInvalid)

pkg/cimfs/cimfs.go

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package cimfs
55

66
import (
7-
"github.com/Microsoft/hcsshim/internal/winapi"
7+
"github.com/Microsoft/hcsshim/internal/winapi/cimfs"
8+
"github.com/Microsoft/hcsshim/internal/winapi/cimwriter"
9+
810
"path/filepath"
911

1012
"github.com/Microsoft/hcsshim/osversion"
@@ -19,7 +21,7 @@ func IsCimFSSupported() bool {
1921
build := osversion.Build()
2022
// CimFS support is backported to LTSC2022 starting with revision 2031 and should
2123
// otherwise be available on all builds >= V25H1Server
22-
return (build >= osversion.V25H1Server || (build == osversion.V21H2Server && rv >= 2031)) && winapi.CimFsSupported()
24+
return (build >= osversion.V25H1Server || (build == osversion.V21H2Server && rv >= 2031)) && cimfs.Supported()
2325
}
2426

2527
// IsBlockCimSupported returns true if block formatted CIMs (i.e block device CIM &
@@ -29,7 +31,27 @@ func IsBlockCimSupported() bool {
2931
// TODO(ambarve): Currently we are checking against a higher build number since there is no
3032
// official build with block CIM support yet. Once we have that build, we should
3133
// update the build number here.
32-
return build >= 27766 && winapi.CimFsSupported()
34+
return build >= 27766 && cimfs.Supported()
35+
}
36+
37+
// IsBlockCimWriteSupported returns true if block formatted CIMs (i.e block device CIM &
38+
// single file CIM) are supported on the current OS build or if CimWriter is present.
39+
func IsBlockCimWriteSupported() bool {
40+
build := osversion.Build()
41+
// TODO(ambarve): Currently we are checking against a higher build number since there is no
42+
// official build with block CIM support yet. Once we have that build, we should
43+
// update the build number here.
44+
return (build >= 27766 && cimfs.Supported()) || cimwriter.Supported()
45+
}
46+
47+
// IsBlockCimMountSupported returns true if block formatted CIMs (i.e block device CIM &
48+
// single file CIM) are supported on the current OS build.
49+
func IsBlockCimMountSupported() bool {
50+
build := osversion.Build()
51+
// TODO(ambarve): Currently we are checking against a higher build number since there is no
52+
// official build with block CIM support yet. Once we have that build, we should
53+
// update the build number here.
54+
return build >= 27766 && cimfs.Supported()
3355
}
3456

3557
// IsVerifiedCimSupported returns true if block CIM format supports also writing verification information in the CIM.
@@ -38,7 +60,26 @@ func IsVerifiedCimSupported() bool {
3860
// TODO(ambarve): Currently we are checking against a higher build number since there is no
3961
// official build with block CIM support yet. Once we have that build, we should
4062
// update the build number here.
41-
return build >= 27800 && winapi.CimFsSupported()
63+
return build >= 27800 && cimfs.Supported()
64+
}
65+
66+
67+
// IsVerifiedCimWriteSupported returns true if block CIM format supports also writing verification information in the CIM.
68+
func IsVerifiedCimWriteSupported() bool {
69+
build := osversion.Build()
70+
// TODO(ambarve): Currently we are checking against a higher build number since there is no
71+
// official build with block CIM support yet. Once we have that build, we should
72+
// update the build number here.
73+
return (build >= 27800 && cimfs.Supported()) || cimwriter.Supported()
74+
}
75+
76+
// IsVerifiedCimMountSupported returns true if block CIM format supports mounting.
77+
func IsVerifiedCimMountSupported() bool {
78+
build := osversion.Build()
79+
// TODO(ambarve): Currently we are checking against a higher build number since there is no
80+
// official build with block CIM support yet. Once we have that build, we should
81+
// update the build number here.
82+
return build >= 27800 && cimfs.Supported()
4283
}
4384

4485
func IsMergedCimSupported() bool {
@@ -48,6 +89,19 @@ func IsMergedCimSupported() bool {
4889
return IsBlockCimSupported()
4990
}
5091

92+
func IsMergedCimWriteSupported() bool {
93+
// The merged CIM support was originally added before block CIM support. However,
94+
// some of the merged CIM features that we use (e.g. merged hard links) were added
95+
// later along with block CIM support. So use the same check as block CIM here.
96+
return IsBlockCimWriteSupported()
97+
}
98+
99+
func IsMergedCimMountSupported() bool {
100+
// The merged CIM support was originally added before block CIM support. However,
101+
// some of the merged CIM features that we use (e.g. merged hard links) were added
102+
// later along with block CIM support. So use the same check as block CIM here.
103+
return IsBlockCimMountSupported()
104+
}
51105
type BlockCIMType uint32
52106

53107
const (

pkg/cimfs/mount_cim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func Unmount(volumePath string) error {
7575
// `MergeBlockCIMs`) at a volume with given GUID. The `sourceCIMs` MUST be identical
7676
// to the `sourceCIMs` passed to `MergeBlockCIMs` when creating this merged CIM.
7777
func MountMergedBlockCIMs(mergedCIM *BlockCIM, sourceCIMs []*BlockCIM, mountFlags uint32, volumeGUID guid.GUID) (string, error) {
78-
if !IsMergedCimSupported() {
78+
if !IsMergedCimMountSupported() {
7979
return "", fmt.Errorf("merged CIMs aren't supported on this OS version")
8080
} else if len(sourceCIMs) < 2 {
8181
return "", fmt.Errorf("need at least 2 source CIMs, got %d: %w", len(sourceCIMs), os.ErrInvalid)
@@ -162,7 +162,7 @@ func MountVerifiedBlockCIM(bCIM *BlockCIM, mountFlags uint32, volumeGUID guid.GU
162162
// to match against the provided root hash if it doesn't, the read will fail. The source
163163
// CIMs and the merged CIM MUST have been created with the verified creation flag.
164164
func MountMergedVerifiedBlockCIMs(mergedCIM *BlockCIM, sourceCIMs []*BlockCIM, mountFlags uint32, volumeGUID guid.GUID, rootHash []byte) (string, error) {
165-
if !IsVerifiedCimSupported() {
165+
if !IsVerifiedCimMountSupported() {
166166
return "", fmt.Errorf("verified CIMs aren't supported on this OS version")
167167
} else if len(sourceCIMs) < 2 {
168168
return "", fmt.Errorf("need at least 2 source CIMs, got %d: %w", len(sourceCIMs), os.ErrInvalid)

pkg/extractuvm/bcim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func extractAndVerifyTarToCIM(t *testing.T, tarContents []testFile, contentsToVe
153153
}
154154

155155
func TestTarUtilityVMExtract(t *testing.T) {
156-
if !cimfs.IsVerifiedCimSupported() {
156+
if !cimfs.IsVerifiedCimMountSupported() {
157157
t.Skip("block CIMs are not supported on this build")
158158
}
159159

test/functional/make_uvm_cim_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func mountBlockCIM(t *testing.T, bCIM *cimfs.BlockCIM, mountFlags uint32) string
192192

193193
// TestCompareUtilityVMCIM compares generated UtilityVM CIM's contents against the WCIFS based layer and ensures that they match.
194194
func TestCompareUtilityVMCIM(t *testing.T) {
195-
if !cimfs.IsBlockCimSupported() {
195+
if !cimfs.IsBlockCimMountSupported() {
196196
t.Skip("block CIMs are not supported on this build")
197197
}
198198

0 commit comments

Comments
 (0)