Browse code

Revender hcsshim to v0.3.5

Signed-off-by: Darren Stahl <darst@microsoft.com>

Darren Stahl authored on 2016/06/21 08:56:13
Showing 6 changed files
... ...
@@ -43,7 +43,7 @@ esac
43 43
 
44 44
 # the following lines are in sorted order, FYI
45 45
 clone git github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62
46
-clone git github.com/Microsoft/hcsshim v0.3.4
46
+clone git github.com/Microsoft/hcsshim v0.3.5
47 47
 clone git github.com/Microsoft/go-winio v0.3.4
48 48
 clone git github.com/Sirupsen/logrus v0.10.0 # logrus is a common dependency among multiple deps
49 49
 clone git github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
... ...
@@ -2,8 +2,6 @@ package hcsshim
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"errors"
6
-	"fmt"
7 5
 	"runtime"
8 6
 	"syscall"
9 7
 	"time"
... ...
@@ -17,14 +15,6 @@ var (
17 17
 
18 18
 const pendingUpdatesQuery = `{ "PropertyTypes" : ["PendingUpdates"]}`
19 19
 
20
-// ContainerError is an error encountered in HCS
21
-type ContainerError struct {
22
-	Container *container
23
-	Operation string
24
-	ExtraInfo string
25
-	Err       error
26
-}
27
-
28 20
 type container struct {
29 21
 	handle         hcsSystem
30 22
 	id             string
... ...
@@ -253,7 +243,7 @@ func (container *container) properties(query string) (*containerProperties, erro
253 253
 	}
254 254
 
255 255
 	if propertiesp == nil {
256
-		return nil, errors.New("Unexpected result from hcsGetComputeSystemProperties, properties should never be nil")
256
+		return nil, ErrUnexpectedValue
257 257
 	}
258 258
 	propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
259 259
 
... ...
@@ -486,46 +476,3 @@ func (container *container) unregisterCallback() error {
486 486
 
487 487
 	return nil
488 488
 }
489
-
490
-func (e *ContainerError) Error() string {
491
-	if e == nil {
492
-		return "<nil>"
493
-	}
494
-
495
-	if e.Container == nil {
496
-		return "unexpected nil container for error: " + e.Err.Error()
497
-	}
498
-
499
-	s := "container " + e.Container.id
500
-
501
-	if e.Operation != "" {
502
-		s += " encountered an error during " + e.Operation
503
-	}
504
-
505
-	if e.Err != nil {
506
-		s += fmt.Sprintf(" failed in Win32: %s (0x%x)", e.Err, win32FromError(e.Err))
507
-	}
508
-
509
-	if e.ExtraInfo != "" {
510
-		s += " extra info: " + e.ExtraInfo
511
-	}
512
-
513
-	return s
514
-}
515
-
516
-func makeContainerError(container *container, operation string, extraInfo string, err error) error {
517
-	// Don't wrap errors created in hcsshim
518
-	if err == ErrTimeout ||
519
-		err == ErrUnexpectedProcessAbort ||
520
-		err == ErrUnexpectedContainerExit ||
521
-		err == ErrHandleClose ||
522
-		err == ErrInvalidProcessState ||
523
-		err == ErrInvalidNotificationType ||
524
-		err == ErrVmcomputeOperationPending {
525
-		return err
526
-	}
527
-
528
-	containerError := &ContainerError{Container: container, Operation: operation, ExtraInfo: extraInfo, Err: err}
529
-	logrus.Error(containerError)
530
-	return containerError
531
-}
532 489
new file mode 100644
... ...
@@ -0,0 +1,149 @@
0
+package hcsshim
1
+
2
+import (
3
+	"errors"
4
+	"fmt"
5
+	"syscall"
6
+
7
+	"github.com/Sirupsen/logrus"
8
+)
9
+
10
+var (
11
+	// ErrHandleClose is an error returned when the handle generating the notification being waited on has been closed
12
+	ErrHandleClose = errors.New("hcsshim: the handle generating this notification has been closed")
13
+
14
+	// ErrInvalidNotificationType is an error encountered when an invalid notification type is used
15
+	ErrInvalidNotificationType = errors.New("hcsshim: invalid notification type")
16
+
17
+	// ErrInvalidProcessState is an error encountered when the process is not in a valid state for the requested operation
18
+	ErrInvalidProcessState = errors.New("the process is in an invalid state for the attempted operation")
19
+
20
+	// ErrTimeout is an error encountered when waiting on a notification times out
21
+	ErrTimeout = errors.New("hcsshim: timeout waiting for notification")
22
+
23
+	// ErrUnexpectedContainerExit is the error returned when a container exits while waiting for
24
+	// a different expected notification
25
+	ErrUnexpectedContainerExit = errors.New("unexpected container exit")
26
+
27
+	// ErrUnexpectedProcessAbort is the error returned when communication with the compute service
28
+	// is lost while waiting for a notification
29
+	ErrUnexpectedProcessAbort = errors.New("lost communication with compute service")
30
+
31
+	// ErrUnexpectedValue is an error returned when hcs returns an invalid value
32
+	ErrUnexpectedValue = errors.New("unexpected value returned from hcs")
33
+
34
+	// ErrVmcomputeAlreadyStopped is an error returned when a shutdown or terminate request is made on a stopped container
35
+	ErrVmcomputeAlreadyStopped = syscall.Errno(0xc0370110)
36
+
37
+	// ErrVmcomputeOperationPending is an error returned when the operation is being completed asynchronously
38
+	ErrVmcomputeOperationPending = syscall.Errno(0xC0370103)
39
+)
40
+
41
+// ProcessError is an error encountered in HCS during an operation on a Process object
42
+type ProcessError struct {
43
+	Process   *process
44
+	Operation string
45
+	ExtraInfo string
46
+	Err       error
47
+}
48
+
49
+// ContainerError is an error encountered in HCS during an operation on a Container object
50
+type ContainerError struct {
51
+	Container *container
52
+	Operation string
53
+	ExtraInfo string
54
+	Err       error
55
+}
56
+
57
+func isKnownError(err error) bool {
58
+	// Don't wrap errors created in hcsshim
59
+	if err == ErrHandleClose ||
60
+		err == ErrInvalidNotificationType ||
61
+		err == ErrInvalidProcessState ||
62
+		err == ErrTimeout ||
63
+		err == ErrUnexpectedContainerExit ||
64
+		err == ErrUnexpectedProcessAbort ||
65
+		err == ErrUnexpectedValue ||
66
+		err == ErrVmcomputeAlreadyStopped ||
67
+		err == ErrVmcomputeOperationPending {
68
+		return true
69
+	}
70
+
71
+	return false
72
+}
73
+
74
+func (e *ContainerError) Error() string {
75
+	if e == nil {
76
+		return "<nil>"
77
+	}
78
+
79
+	if e.Container == nil {
80
+		return "unexpected nil container for error: " + e.Err.Error()
81
+	}
82
+
83
+	s := "container " + e.Container.id
84
+
85
+	if e.Operation != "" {
86
+		s += " encountered an error during " + e.Operation
87
+	}
88
+
89
+	if e.Err != nil {
90
+		s += fmt.Sprintf(" failed in Win32: %s (0x%x)", e.Err, win32FromError(e.Err))
91
+	}
92
+
93
+	if e.ExtraInfo != "" {
94
+		s += " extra info: " + e.ExtraInfo
95
+	}
96
+
97
+	return s
98
+}
99
+
100
+func makeContainerError(container *container, operation string, extraInfo string, err error) error {
101
+	// Return known errors to the client
102
+	if isKnownError(err) {
103
+		return err
104
+	}
105
+
106
+	// Log any unexpected errors
107
+	containerError := &ContainerError{Container: container, Operation: operation, ExtraInfo: extraInfo, Err: err}
108
+	logrus.Error(containerError)
109
+	return containerError
110
+}
111
+
112
+func (e *ProcessError) Error() string {
113
+	if e == nil {
114
+		return "<nil>"
115
+	}
116
+
117
+	if e.Process == nil {
118
+		return "Unexpected nil process for error: " + e.Err.Error()
119
+	}
120
+
121
+	s := fmt.Sprintf("process %d", e.Process.processID)
122
+
123
+	if e.Process.container != nil {
124
+		s += " in container " + e.Process.container.id
125
+	}
126
+
127
+	if e.Operation != "" {
128
+		s += " " + e.Operation
129
+	}
130
+
131
+	if e.Err != nil {
132
+		s += fmt.Sprintf(" failed in Win32: %s (0x%x)", e.Err, win32FromError(e.Err))
133
+	}
134
+
135
+	return s
136
+}
137
+
138
+func makeProcessError(process *process, operation string, extraInfo string, err error) error {
139
+	// Return known errors to the client
140
+	if isKnownError(err) {
141
+		return err
142
+	}
143
+
144
+	// Log any unexpected errors
145
+	processError := &ProcessError{Process: process, Operation: operation, ExtraInfo: extraInfo, Err: err}
146
+	logrus.Error(processError)
147
+	return processError
148
+}
... ...
@@ -97,8 +97,6 @@ const (
97 97
 	ERROR_SHUTDOWN_IN_PROGRESS = syscall.Errno(1115)
98 98
 	WSAEINVAL                  = syscall.Errno(10022)
99 99
 
100
-	ErrVmcomputeOperationPending = syscall.Errno(0xC0370103)
101
-
102 100
 	// Timeout on wait calls
103 101
 	TimeoutInfinite = 0xFFFFFFFF
104 102
 )
... ...
@@ -1,33 +1,10 @@
1 1
 package hcsshim
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"io"
6 5
 	"time"
7 6
 )
8 7
 
9
-var (
10
-	// ErrInvalidNotificationType is an error encountered when an invalid notification type is used
11
-	ErrInvalidNotificationType = errors.New("hcsshim: invalid notification type")
12
-
13
-	// ErrTimeout is an error encountered when waiting on a notification times out
14
-	ErrTimeout = errors.New("hcsshim: timeout waiting for notification")
15
-
16
-	// ErrHandleClose is an error returned when the handle generating the notification being waited on has been closed
17
-	ErrHandleClose = errors.New("hcsshim: the handle generating this notification has been closed")
18
-
19
-	// ErrInvalidProcessState is an error encountered when the process is not in a valid state for the requested operation
20
-	ErrInvalidProcessState = errors.New("the process is in an invalid state for the attempted operation")
21
-
22
-	// ErrUnexpectedContainerExit is the error returned when a container exits while waiting for
23
-	// a different expected notification
24
-	ErrUnexpectedContainerExit = errors.New("unexpected container exit")
25
-
26
-	// ErrUnexpectedProcessAbort is the error returned when communication with the compute service
27
-	// is lost while waiting for a notification
28
-	ErrUnexpectedProcessAbort = errors.New("lost communication with compute service")
29
-)
30
-
31 8
 // ProcessConfig is used as both the input of Container.CreateProcess
32 9
 // and to convert the parameters to JSON for passing onto the HCS
33 10
 type ProcessConfig struct {
... ...
@@ -2,8 +2,6 @@ package hcsshim
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"errors"
6
-	"fmt"
7 5
 	"io"
8 6
 	"syscall"
9 7
 	"time"
... ...
@@ -11,13 +9,7 @@ import (
11 11
 	"github.com/Sirupsen/logrus"
12 12
 )
13 13
 
14
-type ProcessError struct {
15
-	Process   *process
16
-	Operation string
17
-	ExtraInfo string
18
-	Err       error
19
-}
20
-
14
+// ContainerError is an error encountered in HCS
21 15
 type process struct {
22 16
 	handle         hcsProcess
23 17
 	processID      int
... ...
@@ -48,7 +40,7 @@ type closeHandle struct {
48 48
 }
49 49
 
50 50
 type processStatus struct {
51
-	ProcessId      uint32
51
+	ProcessID      uint32
52 52
 	Exited         bool
53 53
 	ExitCode       uint32
54 54
 	LastWaitResult int32
... ...
@@ -223,7 +215,7 @@ func (process *process) properties() (*processStatus, error) {
223 223
 	}
224 224
 
225 225
 	if propertiesp == nil {
226
-		return nil, errors.New("Unexpected result from hcsGetProcessProperties, properties should never be nil")
226
+		return nil, ErrUnexpectedValue
227 227
 	}
228 228
 	propertiesRaw := convertAndFreeCoTaskMemBytes(propertiesp)
229 229
 
... ...
@@ -396,46 +388,3 @@ func (process *process) unregisterCallback() error {
396 396
 
397 397
 	return nil
398 398
 }
399
-
400
-func (e *ProcessError) Error() string {
401
-	if e == nil {
402
-		return "<nil>"
403
-	}
404
-
405
-	if e.Process == nil {
406
-		return "Unexpected nil process for error: " + e.Err.Error()
407
-	}
408
-
409
-	s := fmt.Sprintf("process %d", e.Process.processID)
410
-
411
-	if e.Process.container != nil {
412
-		s += " in container " + e.Process.container.id
413
-	}
414
-
415
-	if e.Operation != "" {
416
-		s += " " + e.Operation
417
-	}
418
-
419
-	if e.Err != nil {
420
-		s += fmt.Sprintf(" failed in Win32: %s (0x%x)", e.Err, win32FromError(e.Err))
421
-	}
422
-
423
-	return s
424
-}
425
-
426
-func makeProcessError(process *process, operation string, extraInfo string, err error) error {
427
-	// Don't wrap errors created in hcsshim
428
-	if err == ErrTimeout ||
429
-		err == ErrUnexpectedProcessAbort ||
430
-		err == ErrUnexpectedContainerExit ||
431
-		err == ErrHandleClose ||
432
-		err == ErrInvalidProcessState ||
433
-		err == ErrInvalidNotificationType ||
434
-		err == ErrVmcomputeOperationPending {
435
-		return err
436
-	}
437
-
438
-	processError := &ProcessError{Process: process, Operation: operation, ExtraInfo: extraInfo, Err: err}
439
-	logrus.Error(processError)
440
-	return processError
441
-}