Skip to content

Commit 6b567c4

Browse files
committed
minor refactor of CreateAddressInfo
add a generic function for creating HvSocket address info mapping. export a function that creates a mapping for containers only. Signed-off-by: Maksim An <[email protected]>
1 parent 517e1a1 commit 6b567c4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

internal/hcsoci/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C
291291
if err != nil {
292292
return nil, r, fmt.Errorf("convert to system GUID failed: %w", err)
293293
}
294-
addressInfoCloser, err := hvsocket.CreateAddressInfo(containerSystemGUID, coi.HostingSystem.RuntimeID(), true)
294+
addressInfoCloser, err := hvsocket.CreateContainerAddressInfo(containerSystemGUID, coi.HostingSystem.RuntimeID())
295295
if err != nil {
296296
return nil, r, fmt.Errorf("redirect container HvSocket failed: %w", err)
297297
}

internal/hvsocket/hvsocket.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,24 @@ func (aic addressInfoCloser) Release(_ context.Context) error {
3636
return windows.CloseHandle(aic.handle)
3737
}
3838

39-
func CreateAddressInfo(cid, vmid guid.GUID, passthru bool) (resources.ResourceCloser, error) {
40-
path := fmt.Sprintf(`\\.\HvSocketSystem\AddressInfo\{%s}`, cid)
39+
// CreateContainerAddressInfo creates an address info entry in HvSocket to redirect
40+
// the calls to the container silo inside UVM.
41+
func CreateContainerAddressInfo(containerID, uvmID guid.GUID) (resources.ResourceCloser, error) {
42+
return CreateAddressInfo(containerID, uvmID, guid.GUID{}, true)
43+
}
44+
45+
// CreateAddressInfo creates an address info entry in the HvSocket provider to map a
46+
// compute system GUID to a virtual machine ID or compartment ID.
47+
//
48+
// `systemID` is the compute system GUID to map.
49+
// `vmID` is the virtual machine ID to which the system GUID maps to. Must be guid.GUID{} to specify
50+
// that the system GUID maps to a network compartment ID on the hosting system.
51+
// `siloID` is the silo object ID to which the system GUID maps to.
52+
// `passthru` when vmID is not guid.GUID{}, specifies whether the systemID maps to the primary
53+
// compartment of the virtual machine (set to `false`) or to another compartment within the
54+
// virtual machine (set to `true`)
55+
func CreateAddressInfo(systemID, vmID, siloID guid.GUID, passthru bool) (resources.ResourceCloser, error) {
56+
path := fmt.Sprintf(`\\.\HvSocketSystem\AddressInfo\{%s}`, systemID)
4157
u16, err := windows.UTF16PtrFromString(path)
4258
if err != nil {
4359
return nil, err
@@ -56,9 +72,11 @@ func CreateAddressInfo(cid, vmid guid.GUID, passthru bool) (resources.ResourceCl
5672
}
5773

5874
addrInfo := addressInfo{
59-
systemID: cid,
60-
virtualMachineID: vmid,
75+
systemID: systemID,
76+
virtualMachineID: vmID,
77+
siloID: siloID,
6178
}
79+
6280
if passthru {
6381
addrInfo.flags |= addressFlagPassthru
6482
}

0 commit comments

Comments
 (0)