Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5bceefb
add functions for getting vm state
nagiesek Nov 8, 2019
502ee56
Add CommonParams to get the status for hcn objects
nagiesek Dec 5, 2019
e6631fb
Add Hot Attach/Detach Endpoints to VirtualMachineSpec
johnsonshih Mar 12, 2021
2bbea47
Merge pull request #1 from johnsonshih/addHotAttach-Detach-endpoint
nagiesek Mar 26, 2021
f3b1ed7
Add Wait() to compute system
johnsonshih Mar 15, 2021
40314a1
Merge pull request #2 from johnsonshih/computesystem-wait
nagiesek Apr 5, 2021
190507a
Revert "Add CommonParams to get the status for hcn objects"
johnsonshih Apr 13, 2021
67c329d
Correct HcnRegisterServiceCallback function prototype
johnsonshih Apr 15, 2021
db417e2
Add HcnRegister/UnregisterNetworkCallback
johnsonshih Apr 15, 2021
cd5981c
Implement HCN Service Watcher
johnsonshih Apr 15, 2021
2851884
add option for enabling GuestConnection
johnsonshih Apr 19, 2021
6186f57
Merge pull request #3 from johnsonshih/network-monitor-pr
nagiesek Apr 19, 2021
1335add
Use VirtualMachineOptions to create vm spec
johnsonshih Apr 20, 2021
e96ea0a
Merge pull request #1 from johnsonshih/virtual-machine-options-pr
johnsonshih Apr 20, 2021
cb9d84a
Add support for plan9 file sharing
johnsonshih Apr 20, 2021
75a3786
Merge pull request #2 from johnsonshih/plan9-sharing-pr
johnsonshih Apr 20, 2021
87bdee7
Add support for plan9 file sharing
johnsonshih Apr 20, 2021
c4d7774
Merge pull request #3 from johnsonshih/plan9-sharing-pr1
johnsonshih Apr 20, 2021
c592abc
Use VirtualMachineOptions to create vm spec
johnsonshih Apr 19, 2021
face9d3
Add support for plan9 file sharing
johnsonshih Apr 20, 2021
0d44227
Merge branch 'addPropertiesCheck' into private-peek
johnsonshih Apr 20, 2021
d13cef5
Add UpdateGpuConfiguration for GPU-PV
johnsonshih Apr 21, 2021
8a87d4a
Merge pull request #4 from johnsonshih/update-gpuconfiguration-pr
johnsonshih Apr 21, 2021
42e78ce
Grant Vm access to vhd and iso files
johnsonshih Apr 29, 2021
16f61d4
Merge pull request #5 from johnsonshih/grant-vm-access-pr
johnsonshih Apr 29, 2021
553268e
Remove redundant type
johnsonshih Apr 29, 2021
1bcce1f
Add ShutdownOptions support
johnsonshih Apr 29, 2021
eddd272
Merge pull request #6 from johnsonshih/shutdown-options-pr
johnsonshih Apr 29, 2021
e4d2344
Add API to Add/Remove virtual device (#7)
jagadishmurugan May 28, 2021
cf4c60c
skip if notificationData is null (#8)
johnsonshih Jun 11, 2021
de80406
correct logic for EndpointNotFoundError (#9)
johnsonshih Jul 23, 2021
c1966bd
Add shutdown option parameter (#10)
johnsonshih Jul 27, 2021
dd5c444
Merge pull request #4 from johnsonshih/plan9-sharing-pr
nagiesek Jul 28, 2021
648cac1
Add UpdateGpuConfiguration for GPU-PV
johnsonshih Apr 21, 2021
bb5d724
Grant Vm access to vhd and iso files
johnsonshih Apr 29, 2021
bb6bcc3
Remove redundant type
johnsonshih Apr 29, 2021
573ae70
skip if notificationData is null
johnsonshih Jun 11, 2021
11c6616
correct logic for EndpointNotFoundError
johnsonshih Jul 23, 2021
08847c6
Merge pull request #5 from johnsonshih/UpdateGpuConfiguration-pr
nagiesek Jul 28, 2021
5a94048
Add ShutdownOptions support
johnsonshih Apr 29, 2021
61bcc32
Merge pull request #6 from johnsonshih/ShutdownOptions-pr
nagiesek Jul 29, 2021
c18e3d4
Add API to Add/Remove virtual device
jagadishmurugan May 28, 2021
6dd72f5
Merge pull request #7 from johnsonshih/virtual-device-pr
nagiesek Jul 29, 2021
9ee216c
Query for specific network instead of enumerating all networks and fi…
jagadishmurugan Jan 27, 2022
6cd66d9
Implement HCNNetworkWatcher (#11)
jagadishmurugan Mar 13, 2022
742da33
Add options to support secure boot and guest connection useVsock (#14)
johnsonshih Mar 18, 2022
6cd86d8
Merge remote-tracking branch 'upstream/addpropertiescheck' into priva…
johnsonshih Mar 18, 2022
1d14bf5
Merge pull request #9 from johnsonshih/private-peek
johnsonshih Apr 1, 2022
ffcf64a
add mmio space configuration, RunCommand and query supported schema v…
johnsonshih Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func (ht *hcsTask) close(ctx context.Context) {
werr = ht.c.Wait()
close(ch)
}()
err := ht.c.Shutdown(ctx)
err := ht.c.Shutdown(ctx, "")
if err != nil {
log.G(ctx).WithError(err).Error("failed to shutdown container")
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/runhcs/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var shimCommand = cli.Command{
// Shutdown the container, waiting 5 minutes before terminating is
// forcefully.
const shutdownTimeout = time.Minute * 5
err := c.hc.Shutdown(gcontext.Background())
err := c.hc.Shutdown(gcontext.Background(), "")
if err != nil {
select {
case <-containerExitCh:
Expand Down
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (container *container) Start() error {

// Shutdown requests a container shutdown, but it may not actually be shutdown until Wait() succeeds.
func (container *container) Shutdown() error {
err := container.system.Shutdown(context.Background())
err := container.system.Shutdown(context.Background(), "")
if err != nil {
return convertSystemError(err, container)
}
Expand Down
4 changes: 3 additions & 1 deletion hcn/hcn.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
//sys hcnQueryNetworkProperties(network hcnNetwork, query string, properties **uint16, result **uint16) (hr error) = computenetwork.HcnQueryNetworkProperties?
//sys hcnDeleteNetwork(id *_guid, result **uint16) (hr error) = computenetwork.HcnDeleteNetwork?
//sys hcnCloseNetwork(network hcnNetwork) (hr error) = computenetwork.HcnCloseNetwork?
//sys hcsRegisterNetworkCallback(network hcnNetwork, callback uintptr, context uintptr, callbackHandle *hcnCallbackHandle) (hr error) = computenetwork.HcnRegisterNetworkCallback?
//sys hcsUnregisterNetworkCallback(callbackHandle hcnCallbackHandle) (hr error) = computenetwork.HcnUnregisterNetworkCallback?

// Endpoint
//sys hcnEnumerateEndpoints(query string, endpoints **uint16, result **uint16) (hr error) = computenetwork.HcnEnumerateEndpoints?
Expand Down Expand Up @@ -57,7 +59,7 @@ import (

// Service
//sys hcnOpenService(service *hcnService, result **uint16) (hr error) = computenetwork.HcnOpenService?
//sys hcnRegisterServiceCallback(service hcnService, callback int32, context int32, callbackHandle *hcnCallbackHandle) (hr error) = computenetwork.HcnRegisterServiceCallback?
//sys hcnRegisterServiceCallback(callback uintptr, context uintptr, callbackHandle *hcnCallbackHandle) (hr error) = computenetwork.HcnRegisterServiceCallback?
//sys hcnUnregisterServiceCallback(callbackHandle hcnCallbackHandle) (hr error) = computenetwork.HcnUnregisterServiceCallback?
//sys hcnCloseService(service hcnService) (hr error) = computenetwork.HcnCloseService?

Expand Down
125 changes: 125 additions & 0 deletions hcn/hcncallback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package hcn

import (
"encoding/json"
"fmt"
"sync"
"syscall"
"unsafe"

"github.com/Microsoft/hcsshim/internal/interop"
)

var (
nextCallback uintptr
callbackMap = map[uintptr]*notifcationWatcherContext{}
callbackMapLock = sync.RWMutex{}

notificationWatcherCallback = syscall.NewCallback(notificationWatcher)

// Notifications for HCN_SERVICE handles
HcnNotificationNetworkPreCreate HcnNotification = 0x00000001
HcnNotificationNetworkCreate HcnNotification = 0x00000002
HcnNotificationNetworkPreDelete HcnNotification = 0x00000003
HcnNotificationNetworkDelete HcnNotification = 0x00000004

// Namespace Notifications
HcnNotificationNamespaceCreate HcnNotification = 0x00000005
HcnNotificationNamespaceDelete HcnNotification = 0x00000006

// Notifications for HCN_SERVICE handles
HcnNotificationGuestNetworkServiceCreate HcnNotification = 0x00000007
HcnNotificationGuestNetworkServiceDelete HcnNotification = 0x00000008

// Notifications for HCN_NETWORK handles
HcnNotificationNetworkEndpointAttached HcnNotification = 0x00000009
HcnNotificationNetworkEndpointDetached HcnNotification = 0x00000010

// Notifications for HCN_GUESTNETWORKSERVICE handles
HcnNotificationGuestNetworkServiceStateChanged HcnNotification = 0x00000011
HcnNotificationGuestNetworkServiceInterfaceStateChanged HcnNotification = 0x00000012

// Common notifications
HcnNotificationServiceDisconnect HcnNotification = 0x01000000
)

type HcnNotification uint32

func (hn HcnNotification) String() string {
switch hn {
case HcnNotificationNetworkPreCreate:
return "NetworkPreCreate"
case HcnNotificationNetworkCreate:
return "NetworkCreate"
case HcnNotificationNetworkPreDelete:
return "NetworkPreDelete"
case HcnNotificationNetworkDelete:
return "NetworkDelete"
case HcnNotificationNamespaceCreate:
return "NamespaceCreate"
case HcnNotificationNamespaceDelete:
return "NamespaceDelete"
case HcnNotificationGuestNetworkServiceCreate:
return "GuestNetworkServiceCreate"
case HcnNotificationGuestNetworkServiceDelete:
return "GuestNetworkServiceDelete"
case HcnNotificationNetworkEndpointAttached:
return "NetworkEndpointAttached"
case HcnNotificationNetworkEndpointDetached:
return "NetworkEndpointDetached"
case HcnNotificationGuestNetworkServiceStateChanged:
return "GuestNetworkServiceStateChanged"
case HcnNotificationGuestNetworkServiceInterfaceStateChanged:
return "GuestNetworkServiceInterfaceStateChanged"
case HcnNotificationServiceDisconnect:
return "ServiceDisconnect"
default:
return fmt.Sprintf("Unknown: %d", hn)
}
}

type HcnNotificationData struct {
Type HcnNotification
Status error
Data NotificationBase
}

type notificationChannel chan HcnNotificationData

type notifcationWatcherContext struct {
channel notificationChannel
handle hcnCallbackHandle
}

func notificationWatcher(notificationType HcnNotification, callbackNumber uintptr, notificationStatus uintptr, notificationData *uint16) uintptr {
var result error
if int32(notificationStatus) < 0 {
result = interop.Win32FromHresult(notificationStatus)
}

callbackMapLock.RLock()
context := callbackMap[callbackNumber]
callbackMapLock.RUnlock()

if context == nil {
return 0
}

if notificationData == nil {
return 0
}

tmpString := syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(notificationData))[:])

var notifData NotificationBase
err := json.Unmarshal([]byte(tmpString), &notifData)
if err == nil {
context.channel <- HcnNotificationData{
Type: notificationType,
Status: result,
Data: notifData,
}
}

return 0
}
4 changes: 2 additions & 2 deletions hcn/hcnerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type NetworkNotFoundError struct {
}

func (e NetworkNotFoundError) Error() string {
if e.NetworkName == "" {
if e.NetworkName != "" {
return fmt.Sprintf("Network Name %s not found", e.NetworkName)
}
return fmt.Sprintf("Network Id %s not found", e.NetworkID)
Expand All @@ -62,7 +62,7 @@ type EndpointNotFoundError struct {
}

func (e EndpointNotFoundError) Error() string {
if e.EndpointName == "" {
if e.EndpointName != "" {
return fmt.Sprintf("Endpoint Name %s not found", e.EndpointName)
}
return fmt.Sprintf("Endpoint Id %s not found", e.EndpointID)
Expand Down
Loading