repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Microsoft/hcsshim | internal/hns/hnspolicylist.go | AddEndpoint | func (policylist *PolicyList) AddEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "AddEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
policylist.EndpointReferences = append(policylist.EndpointReferences, "/endpoints/"+endpoint.Id)
return policylist.Create()
} | go | func (policylist *PolicyList) AddEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "AddEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
policylist.EndpointReferences = append(policylist.EndpointReferences, "/endpoints/"+endpoint.Id)
return policylist.Create()
} | [
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"AddEndpoint",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"_",
",",
"err",
":=",
"policylist",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add Endpoint to the Existing List",
"policylist",
".",
"EndpointReferences",
"=",
"append",
"(",
"policylist",
".",
"EndpointReferences",
",",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
")",
"\n\n",
"return",
"policylist",
".",
"Create",
"(",
")",
"\n",
"}"
] | // AddEndpoint add an endpoint to a Policy List | [
"AddEndpoint",
"add",
"an",
"endpoint",
"to",
"a",
"Policy",
"List"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L101-L115 | train |
Microsoft/hcsshim | internal/hns/hnspolicylist.go | RemoveEndpoint | func (policylist *PolicyList) RemoveEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "RemoveEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
elementToRemove := "/endpoints/" + endpoint.Id
var references []string
for _, endpointReference := range policylist.EndpointReferences {
if endpointReference == elementToRemove {
continue
}
references = append(references, endpointReference)
}
policylist.EndpointReferences = references
return policylist.Create()
} | go | func (policylist *PolicyList) RemoveEndpoint(endpoint *HNSEndpoint) (*PolicyList, error) {
operation := "RemoveEndpoint"
title := "hcsshim::PolicyList::" + operation
logrus.Debugf(title+" id=%s, endpointId:%s", policylist.ID, endpoint.Id)
_, err := policylist.Delete()
if err != nil {
return nil, err
}
elementToRemove := "/endpoints/" + endpoint.Id
var references []string
for _, endpointReference := range policylist.EndpointReferences {
if endpointReference == elementToRemove {
continue
}
references = append(references, endpointReference)
}
policylist.EndpointReferences = references
return policylist.Create()
} | [
"func",
"(",
"policylist",
"*",
"PolicyList",
")",
"RemoveEndpoint",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"(",
"*",
"PolicyList",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"policylist",
".",
"ID",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"_",
",",
"err",
":=",
"policylist",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"elementToRemove",
":=",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
"\n\n",
"var",
"references",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"endpointReference",
":=",
"range",
"policylist",
".",
"EndpointReferences",
"{",
"if",
"endpointReference",
"==",
"elementToRemove",
"{",
"continue",
"\n",
"}",
"\n",
"references",
"=",
"append",
"(",
"references",
",",
"endpointReference",
")",
"\n",
"}",
"\n",
"policylist",
".",
"EndpointReferences",
"=",
"references",
"\n",
"return",
"policylist",
".",
"Create",
"(",
")",
"\n",
"}"
] | // RemoveEndpoint removes an endpoint from the Policy List | [
"RemoveEndpoint",
"removes",
"an",
"endpoint",
"from",
"the",
"Policy",
"List"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnspolicylist.go#L118-L140 | train |
Microsoft/hcsshim | internal/hcs/process.go | Signal | func (process *Process) Signal(options interface{}) (_ bool, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Signal"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
optionsb, err := json.Marshal(options)
if err != nil {
return false, err
}
optionsStr := string(optionsb)
var resultp *uint16
syscallWatcher(process.logctx, func() {
err = hcsSignalProcess(process.handle, optionsStr, &resultp)
})
events := processHcsResult(resultp)
delivered, err := process.processSignalResult(err)
if err != nil {
err = makeProcessError(process, operation, err, events)
}
return delivered, err
} | go | func (process *Process) Signal(options interface{}) (_ bool, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Signal"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return false, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
optionsb, err := json.Marshal(options)
if err != nil {
return false, err
}
optionsStr := string(optionsb)
var resultp *uint16
syscallWatcher(process.logctx, func() {
err = hcsSignalProcess(process.handle, optionsStr, &resultp)
})
events := processHcsResult(resultp)
delivered, err := process.processSignalResult(err)
if err != nil {
err = makeProcessError(process, operation, err, events)
}
return delivered, err
} | [
"func",
"(",
"process",
"*",
"Process",
")",
"Signal",
"(",
"options",
"interface",
"{",
"}",
")",
"(",
"_",
"bool",
",",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"false",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"optionsb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"optionsStr",
":=",
"string",
"(",
"optionsb",
")",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"process",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsSignalProcess",
"(",
"process",
".",
"handle",
",",
"optionsStr",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"delivered",
",",
"err",
":=",
"process",
".",
"processSignalResult",
"(",
"err",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n",
"return",
"delivered",
",",
"err",
"\n",
"}"
] | // Signal signals the process with `options`.
//
// For LCOW `guestrequest.SignalProcessOptionsLCOW`.
//
// For WCOW `guestrequest.SignalProcessOptionsWCOW`. | [
"Signal",
"signals",
"the",
"process",
"with",
"options",
".",
"For",
"LCOW",
"guestrequest",
".",
"SignalProcessOptionsLCOW",
".",
"For",
"WCOW",
"guestrequest",
".",
"SignalProcessOptionsWCOW",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L139-L168 | train |
Microsoft/hcsshim | internal/hcs/process.go | StdioLegacy | func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Stdio"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
var (
processInfo hcsProcessInformation
resultp *uint16
)
err = hcsGetProcessInfo(process.handle, &processInfo, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, events)
}
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, nil)
}
return pipes[0], pipes[1], pipes[2], nil
} | go | func (process *Process) StdioLegacy() (_ io.WriteCloser, _ io.ReadCloser, _ io.ReadCloser, err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::Stdio"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return nil, nil, nil, makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
var (
processInfo hcsProcessInformation
resultp *uint16
)
err = hcsGetProcessInfo(process.handle, &processInfo, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, events)
}
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, nil, nil, makeProcessError(process, operation, err, nil)
}
return pipes[0], pipes[1], pipes[2], nil
} | [
"func",
"(",
"process",
"*",
"Process",
")",
"StdioLegacy",
"(",
")",
"(",
"_",
"io",
".",
"WriteCloser",
",",
"_",
"io",
".",
"ReadCloser",
",",
"_",
"io",
".",
"ReadCloser",
",",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"var",
"(",
"processInfo",
"hcsProcessInformation",
"\n",
"resultp",
"*",
"uint16",
"\n",
")",
"\n",
"err",
"=",
"hcsGetProcessInfo",
"(",
"process",
".",
"handle",
",",
"&",
"processInfo",
",",
"&",
"resultp",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"pipes",
",",
"err",
":=",
"makeOpenFiles",
"(",
"[",
"]",
"syscall",
".",
"Handle",
"{",
"processInfo",
".",
"StdInput",
",",
"processInfo",
".",
"StdOutput",
",",
"processInfo",
".",
"StdError",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"return",
"pipes",
"[",
"0",
"]",
",",
"pipes",
"[",
"1",
"]",
",",
"pipes",
"[",
"2",
"]",
",",
"nil",
"\n",
"}"
] | // StdioLegacy returns the stdin, stdout, and stderr pipes, respectively. Closing
// these pipes does not close the underlying pipes; it should be possible to
// call this multiple times to get multiple interfaces. | [
"StdioLegacy",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"Closing",
"these",
"pipes",
"does",
"not",
"close",
"the",
"underlying",
"pipes",
";",
"it",
"should",
"be",
"possible",
"to",
"call",
"this",
"multiple",
"times",
"to",
"get",
"multiple",
"interfaces",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L327-L355 | train |
Microsoft/hcsshim | internal/hcs/process.go | Stdio | func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
return process.stdin, process.stdout, process.stderr
} | go | func (process *Process) Stdio() (stdin io.Writer, stdout, stderr io.Reader) {
return process.stdin, process.stdout, process.stderr
} | [
"func",
"(",
"process",
"*",
"Process",
")",
"Stdio",
"(",
")",
"(",
"stdin",
"io",
".",
"Writer",
",",
"stdout",
",",
"stderr",
"io",
".",
"Reader",
")",
"{",
"return",
"process",
".",
"stdin",
",",
"process",
".",
"stdout",
",",
"process",
".",
"stderr",
"\n",
"}"
] | // Stdio returns the stdin, stdout, and stderr pipes, respectively.
// To close them, close the process handle. | [
"Stdio",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"To",
"close",
"them",
"close",
"the",
"process",
"handle",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L359-L361 | train |
Microsoft/hcsshim | internal/hcs/process.go | CloseStdin | func (process *Process) CloseStdin() (err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::CloseStdin"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
modifyRequest := processModifyRequest{
Operation: modifyCloseHandle,
CloseHandle: &closeHandle{
Handle: stdIn,
},
}
modifyRequestb, err := json.Marshal(modifyRequest)
if err != nil {
return err
}
modifyRequestStr := string(modifyRequestb)
var resultp *uint16
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
events := processHcsResult(resultp)
if err != nil {
return makeProcessError(process, operation, err, events)
}
if process.stdin != nil {
process.stdin.Close()
}
return nil
} | go | func (process *Process) CloseStdin() (err error) {
process.handleLock.RLock()
defer process.handleLock.RUnlock()
operation := "hcsshim::Process::CloseStdin"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
if process.handle == 0 {
return makeProcessError(process, operation, ErrAlreadyClosed, nil)
}
modifyRequest := processModifyRequest{
Operation: modifyCloseHandle,
CloseHandle: &closeHandle{
Handle: stdIn,
},
}
modifyRequestb, err := json.Marshal(modifyRequest)
if err != nil {
return err
}
modifyRequestStr := string(modifyRequestb)
var resultp *uint16
err = hcsModifyProcess(process.handle, modifyRequestStr, &resultp)
events := processHcsResult(resultp)
if err != nil {
return makeProcessError(process, operation, err, events)
}
if process.stdin != nil {
process.stdin.Close()
}
return nil
} | [
"func",
"(",
"process",
"*",
"Process",
")",
"CloseStdin",
"(",
")",
"(",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"modifyRequest",
":=",
"processModifyRequest",
"{",
"Operation",
":",
"modifyCloseHandle",
",",
"CloseHandle",
":",
"&",
"closeHandle",
"{",
"Handle",
":",
"stdIn",
",",
"}",
",",
"}",
"\n\n",
"modifyRequestb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"modifyRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"modifyRequestStr",
":=",
"string",
"(",
"modifyRequestb",
")",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"err",
"=",
"hcsModifyProcess",
"(",
"process",
".",
"handle",
",",
"modifyRequestStr",
",",
"&",
"resultp",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"if",
"process",
".",
"stdin",
"!=",
"nil",
"{",
"process",
".",
"stdin",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CloseStdin closes the write side of the stdin pipe so that the process is
// notified on the read side that there is no more data in stdin. | [
"CloseStdin",
"closes",
"the",
"write",
"side",
"of",
"the",
"stdin",
"pipe",
"so",
"that",
"the",
"process",
"is",
"notified",
"on",
"the",
"read",
"side",
"that",
"there",
"is",
"no",
"more",
"data",
"in",
"stdin",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L365-L402 | train |
Microsoft/hcsshim | internal/hcs/process.go | Close | func (process *Process) Close() (err error) {
process.handleLock.Lock()
defer process.handleLock.Unlock()
operation := "hcsshim::Process::Close"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
// Don't double free this
if process.handle == 0 {
return nil
}
if process.stdin != nil {
process.stdin.Close()
}
if process.stdout != nil {
process.stdout.Close()
}
if process.stderr != nil {
process.stderr.Close()
}
if err = process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, err, nil)
}
if err = hcsCloseProcess(process.handle); err != nil {
return makeProcessError(process, operation, err, nil)
}
process.handle = 0
process.closedWaitOnce.Do(func() {
process.waitError = ErrAlreadyClosed
close(process.waitBlock)
})
return nil
} | go | func (process *Process) Close() (err error) {
process.handleLock.Lock()
defer process.handleLock.Unlock()
operation := "hcsshim::Process::Close"
process.logOperationBegin(operation)
defer func() { process.logOperationEnd(operation, err) }()
// Don't double free this
if process.handle == 0 {
return nil
}
if process.stdin != nil {
process.stdin.Close()
}
if process.stdout != nil {
process.stdout.Close()
}
if process.stderr != nil {
process.stderr.Close()
}
if err = process.unregisterCallback(); err != nil {
return makeProcessError(process, operation, err, nil)
}
if err = hcsCloseProcess(process.handle); err != nil {
return makeProcessError(process, operation, err, nil)
}
process.handle = 0
process.closedWaitOnce.Do(func() {
process.waitError = ErrAlreadyClosed
close(process.waitBlock)
})
return nil
} | [
"func",
"(",
"process",
"*",
"Process",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"process",
".",
"handleLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"process",
".",
"handleLock",
".",
"Unlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"process",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"process",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"// Don't double free this",
"if",
"process",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"process",
".",
"stdin",
"!=",
"nil",
"{",
"process",
".",
"stdin",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"process",
".",
"stdout",
"!=",
"nil",
"{",
"process",
".",
"stdout",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"process",
".",
"stderr",
"!=",
"nil",
"{",
"process",
".",
"stderr",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"process",
".",
"unregisterCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"hcsCloseProcess",
"(",
"process",
".",
"handle",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"makeProcessError",
"(",
"process",
",",
"operation",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"process",
".",
"handle",
"=",
"0",
"\n",
"process",
".",
"closedWaitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"process",
".",
"waitError",
"=",
"ErrAlreadyClosed",
"\n",
"close",
"(",
"process",
".",
"waitBlock",
")",
"\n",
"}",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close cleans up any state associated with the process but does not kill
// or wait on it. | [
"Close",
"cleans",
"up",
"any",
"state",
"associated",
"with",
"the",
"process",
"but",
"does",
"not",
"kill",
"or",
"wait",
"on",
"it",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/process.go#L406-L444 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | ListEndpoints | func ListEndpoints() ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
return endpoints, nil
} | go | func ListEndpoints() ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
return endpoints, nil
} | [
"func",
"ListEndpoints",
"(",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"endpoints",
",",
"nil",
"\n",
"}"
] | // ListEndpoints makes a call to list all available endpoints. | [
"ListEndpoints",
"makes",
"a",
"call",
"to",
"list",
"all",
"available",
"endpoints",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L221-L228 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | ListEndpointsQuery | func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
endpoints, err := enumerateEndpoints(string(queryJson))
if err != nil {
return nil, err
}
return endpoints, nil
} | go | func ListEndpointsQuery(query HostComputeQuery) ([]HostComputeEndpoint, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
endpoints, err := enumerateEndpoints(string(queryJson))
if err != nil {
return nil, err
}
return endpoints, nil
} | [
"func",
"ListEndpointsQuery",
"(",
"query",
"HostComputeQuery",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"queryJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"endpoints",
",",
"err",
":=",
"enumerateEndpoints",
"(",
"string",
"(",
"queryJson",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"endpoints",
",",
"nil",
"\n",
"}"
] | // ListEndpointsQuery makes a call to query the list of available endpoints. | [
"ListEndpointsQuery",
"makes",
"a",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"endpoints",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L231-L242 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | ListEndpointsOfNetwork | func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
mapA := map[string]string{"VirtualNetwork": networkId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
return ListEndpointsQuery(hcnQuery)
} | go | func ListEndpointsOfNetwork(networkId string) ([]HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}
mapA := map[string]string{"VirtualNetwork": networkId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
return ListEndpointsQuery(hcnQuery)
} | [
"func",
"ListEndpointsOfNetwork",
"(",
"networkId",
"string",
")",
"(",
"[",
"]",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"// TODO: Once query can convert schema, change to {HostComputeNetwork:networkId}",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"networkId",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"return",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"}"
] | // ListEndpointsOfNetwork queries the list of endpoints on a network. | [
"ListEndpointsOfNetwork",
"queries",
"the",
"list",
"of",
"endpoints",
"on",
"a",
"network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L245-L256 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | GetEndpointByID | func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": endpointId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointID: endpointId}
}
return &endpoints[0], err
} | go | func GetEndpointByID(endpointId string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": endpointId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointID: endpointId}
}
return &endpoints[0], err
} | [
"func",
"GetEndpointByID",
"(",
"endpointId",
"string",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"endpointId",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"endpoints",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"EndpointNotFoundError",
"{",
"EndpointID",
":",
"endpointId",
"}",
"\n",
"}",
"\n",
"return",
"&",
"endpoints",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] | // GetEndpointByID returns an endpoint specified by Id | [
"GetEndpointByID",
"returns",
"an",
"endpoint",
"specified",
"by",
"Id"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L259-L276 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | GetEndpointByName | func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": endpointName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointName: endpointName}
}
return &endpoints[0], err
} | go | func GetEndpointByName(endpointName string) (*HostComputeEndpoint, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": endpointName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
endpoints, err := ListEndpointsQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(endpoints) == 0 {
return nil, EndpointNotFoundError{EndpointName: endpointName}
}
return &endpoints[0], err
} | [
"func",
"GetEndpointByName",
"(",
"endpointName",
"string",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"endpointName",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"endpoints",
",",
"err",
":=",
"ListEndpointsQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"endpoints",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"EndpointNotFoundError",
"{",
"EndpointName",
":",
"endpointName",
"}",
"\n",
"}",
"\n",
"return",
"&",
"endpoints",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] | // GetEndpointByName returns an endpoint specified by Name | [
"GetEndpointByName",
"returns",
"an",
"endpoint",
"specified",
"by",
"Name"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L279-L296 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | Create | func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
if endpoint.HostComputeNamespace != "" {
return nil, errors.New("endpoint create error, endpoint json HostComputeNamespace is read only and should not be set")
}
jsonString, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return endpoint, nil
} | go | func (endpoint *HostComputeEndpoint) Create() (*HostComputeEndpoint, error) {
logrus.Debugf("hcn::HostComputeEndpoint::Create id=%s", endpoint.Id)
if endpoint.HostComputeNamespace != "" {
return nil, errors.New("endpoint create error, endpoint json HostComputeNamespace is read only and should not be set")
}
jsonString, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeEndpoint::Create JSON: %s", jsonString)
endpoint, hcnErr := createEndpoint(endpoint.HostComputeNetwork, string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return endpoint, nil
} | [
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"Create",
"(",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"if",
"endpoint",
".",
"HostComputeNamespace",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"jsonString",
")",
"\n",
"endpoint",
",",
"hcnErr",
":=",
"createEndpoint",
"(",
"endpoint",
".",
"HostComputeNetwork",
",",
"string",
"(",
"jsonString",
")",
")",
"\n",
"if",
"hcnErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"hcnErr",
"\n",
"}",
"\n",
"return",
"endpoint",
",",
"nil",
"\n",
"}"
] | // Create Endpoint. | [
"Create",
"Endpoint",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L299-L317 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | Delete | func (endpoint *HostComputeEndpoint) Delete() error {
logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
if err := deleteEndpoint(endpoint.Id); err != nil {
return err
}
return nil
} | go | func (endpoint *HostComputeEndpoint) Delete() error {
logrus.Debugf("hcn::HostComputeEndpoint::Delete id=%s", endpoint.Id)
if err := deleteEndpoint(endpoint.Id); err != nil {
return err
}
return nil
} | [
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"Delete",
"(",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"if",
"err",
":=",
"deleteEndpoint",
"(",
"endpoint",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete Endpoint. | [
"Delete",
"Endpoint",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L320-L327 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | NamespaceAttach | func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
return AddNamespaceEndpoint(namespaceId, endpoint.Id)
} | go | func (endpoint *HostComputeEndpoint) NamespaceAttach(namespaceId string) error {
return AddNamespaceEndpoint(namespaceId, endpoint.Id)
} | [
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"NamespaceAttach",
"(",
"namespaceId",
"string",
")",
"error",
"{",
"return",
"AddNamespaceEndpoint",
"(",
"namespaceId",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}"
] | // NamespaceAttach modifies a Namespace to add an endpoint. | [
"NamespaceAttach",
"modifies",
"a",
"Namespace",
"to",
"add",
"an",
"endpoint",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L363-L365 | train |
Microsoft/hcsshim | hcn/hcnendpoint.go | NamespaceDetach | func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
} | go | func (endpoint *HostComputeEndpoint) NamespaceDetach(namespaceId string) error {
return RemoveNamespaceEndpoint(namespaceId, endpoint.Id)
} | [
"func",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"NamespaceDetach",
"(",
"namespaceId",
"string",
")",
"error",
"{",
"return",
"RemoveNamespaceEndpoint",
"(",
"namespaceId",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}"
] | // NamespaceDetach modifies a Namespace to remove an endpoint. | [
"NamespaceDetach",
"modifies",
"a",
"Namespace",
"to",
"remove",
"an",
"endpoint",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnendpoint.go#L368-L370 | train |
Microsoft/hcsshim | internal/wcow/scratch.go | CreateUVMScratch | func CreateUVMScratch(imagePath, destDirectory, vmID string) error {
sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
logrus.Debugf("uvm::CreateUVMScratch %s from %s", targetScratch, sourceScratch)
if err := copyfile.CopyFile(sourceScratch, targetScratch, true); err != nil {
return err
}
if err := wclayer.GrantVmAccess(vmID, targetScratch); err != nil {
os.Remove(targetScratch)
return err
}
return nil
} | go | func CreateUVMScratch(imagePath, destDirectory, vmID string) error {
sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
logrus.Debugf("uvm::CreateUVMScratch %s from %s", targetScratch, sourceScratch)
if err := copyfile.CopyFile(sourceScratch, targetScratch, true); err != nil {
return err
}
if err := wclayer.GrantVmAccess(vmID, targetScratch); err != nil {
os.Remove(targetScratch)
return err
}
return nil
} | [
"func",
"CreateUVMScratch",
"(",
"imagePath",
",",
"destDirectory",
",",
"vmID",
"string",
")",
"error",
"{",
"sourceScratch",
":=",
"filepath",
".",
"Join",
"(",
"imagePath",
",",
"`UtilityVM\\SystemTemplate.vhdx`",
")",
"\n",
"targetScratch",
":=",
"filepath",
".",
"Join",
"(",
"destDirectory",
",",
"\"",
"\"",
")",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"targetScratch",
",",
"sourceScratch",
")",
"\n",
"if",
"err",
":=",
"copyfile",
".",
"CopyFile",
"(",
"sourceScratch",
",",
"targetScratch",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"wclayer",
".",
"GrantVmAccess",
"(",
"vmID",
",",
"targetScratch",
")",
";",
"err",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"targetScratch",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CreateUVMScratch is a helper to create a scratch for a Windows utility VM
// with permissions to the specified VM ID in a specified directory | [
"CreateUVMScratch",
"is",
"a",
"helper",
"to",
"create",
"a",
"scratch",
"for",
"a",
"Windows",
"utility",
"VM",
"with",
"permissions",
"to",
"the",
"specified",
"VM",
"ID",
"in",
"a",
"specified",
"directory"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wcow/scratch.go#L14-L26 | train |
Microsoft/hcsshim | cmd/containerd-shim-runhcs-v1/task_hcs.go | newHcsTask | func newHcsTask(
ctx context.Context,
events publisher,
parent *uvm.UtilityVM,
ownsParent bool,
req *task.CreateTaskRequest,
s *specs.Spec) (shimTask, error) {
logrus.WithFields(logrus.Fields{
"tid": req.ID,
"ownsParent": ownsParent,
}).Debug("newHcsTask")
owner := filepath.Base(os.Args[0])
io, err := newNpipeIO(ctx, req.ID, req.ID, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
if err != nil {
return nil, err
}
var netNS string
if s.Windows != nil &&
s.Windows.Network != nil {
netNS = s.Windows.Network.NetworkNamespace
}
opts := hcsoci.CreateOptions{
ID: req.ID,
Owner: owner,
Spec: s,
HostingSystem: parent,
NetworkNamespace: netNS,
}
system, resources, err := hcsoci.CreateContainer(&opts)
if err != nil {
return nil, err
}
ht := &hcsTask{
events: events,
id: req.ID,
isWCOW: oci.IsWCOW(s),
c: system,
cr: resources,
ownsHost: ownsParent,
host: parent,
closed: make(chan struct{}),
}
ht.init = newHcsExec(
ctx,
events,
req.ID,
parent,
system,
req.ID,
req.Bundle,
ht.isWCOW,
s.Process,
io)
if parent != nil {
// We have a parent UVM. Listen for its exit and forcibly close this
// task. This is not expected but in the event of a UVM crash we need to
// handle this case.
go ht.waitForHostExit()
}
// In the normal case the `Signal` call from the caller killed this task's
// init process.
go func() {
// Wait for our init process to exit.
ht.init.Wait(context.Background())
// Release all container resources for this task.
ht.close()
}()
// Publish the created event
ht.events(
runtime.TaskCreateEventTopic,
&eventstypes.TaskCreate{
ContainerID: req.ID,
Bundle: req.Bundle,
Rootfs: req.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
Terminal: req.Terminal,
},
Checkpoint: "",
Pid: uint32(ht.init.Pid()),
})
return ht, nil
} | go | func newHcsTask(
ctx context.Context,
events publisher,
parent *uvm.UtilityVM,
ownsParent bool,
req *task.CreateTaskRequest,
s *specs.Spec) (shimTask, error) {
logrus.WithFields(logrus.Fields{
"tid": req.ID,
"ownsParent": ownsParent,
}).Debug("newHcsTask")
owner := filepath.Base(os.Args[0])
io, err := newNpipeIO(ctx, req.ID, req.ID, req.Stdin, req.Stdout, req.Stderr, req.Terminal)
if err != nil {
return nil, err
}
var netNS string
if s.Windows != nil &&
s.Windows.Network != nil {
netNS = s.Windows.Network.NetworkNamespace
}
opts := hcsoci.CreateOptions{
ID: req.ID,
Owner: owner,
Spec: s,
HostingSystem: parent,
NetworkNamespace: netNS,
}
system, resources, err := hcsoci.CreateContainer(&opts)
if err != nil {
return nil, err
}
ht := &hcsTask{
events: events,
id: req.ID,
isWCOW: oci.IsWCOW(s),
c: system,
cr: resources,
ownsHost: ownsParent,
host: parent,
closed: make(chan struct{}),
}
ht.init = newHcsExec(
ctx,
events,
req.ID,
parent,
system,
req.ID,
req.Bundle,
ht.isWCOW,
s.Process,
io)
if parent != nil {
// We have a parent UVM. Listen for its exit and forcibly close this
// task. This is not expected but in the event of a UVM crash we need to
// handle this case.
go ht.waitForHostExit()
}
// In the normal case the `Signal` call from the caller killed this task's
// init process.
go func() {
// Wait for our init process to exit.
ht.init.Wait(context.Background())
// Release all container resources for this task.
ht.close()
}()
// Publish the created event
ht.events(
runtime.TaskCreateEventTopic,
&eventstypes.TaskCreate{
ContainerID: req.ID,
Bundle: req.Bundle,
Rootfs: req.Rootfs,
IO: &eventstypes.TaskIO{
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
Terminal: req.Terminal,
},
Checkpoint: "",
Pid: uint32(ht.init.Pid()),
})
return ht, nil
} | [
"func",
"newHcsTask",
"(",
"ctx",
"context",
".",
"Context",
",",
"events",
"publisher",
",",
"parent",
"*",
"uvm",
".",
"UtilityVM",
",",
"ownsParent",
"bool",
",",
"req",
"*",
"task",
".",
"CreateTaskRequest",
",",
"s",
"*",
"specs",
".",
"Spec",
")",
"(",
"shimTask",
",",
"error",
")",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"req",
".",
"ID",
",",
"\"",
"\"",
":",
"ownsParent",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"owner",
":=",
"filepath",
".",
"Base",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n\n",
"io",
",",
"err",
":=",
"newNpipeIO",
"(",
"ctx",
",",
"req",
".",
"ID",
",",
"req",
".",
"ID",
",",
"req",
".",
"Stdin",
",",
"req",
".",
"Stdout",
",",
"req",
".",
"Stderr",
",",
"req",
".",
"Terminal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"netNS",
"string",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Network",
"!=",
"nil",
"{",
"netNS",
"=",
"s",
".",
"Windows",
".",
"Network",
".",
"NetworkNamespace",
"\n",
"}",
"\n",
"opts",
":=",
"hcsoci",
".",
"CreateOptions",
"{",
"ID",
":",
"req",
".",
"ID",
",",
"Owner",
":",
"owner",
",",
"Spec",
":",
"s",
",",
"HostingSystem",
":",
"parent",
",",
"NetworkNamespace",
":",
"netNS",
",",
"}",
"\n",
"system",
",",
"resources",
",",
"err",
":=",
"hcsoci",
".",
"CreateContainer",
"(",
"&",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ht",
":=",
"&",
"hcsTask",
"{",
"events",
":",
"events",
",",
"id",
":",
"req",
".",
"ID",
",",
"isWCOW",
":",
"oci",
".",
"IsWCOW",
"(",
"s",
")",
",",
"c",
":",
"system",
",",
"cr",
":",
"resources",
",",
"ownsHost",
":",
"ownsParent",
",",
"host",
":",
"parent",
",",
"closed",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"ht",
".",
"init",
"=",
"newHcsExec",
"(",
"ctx",
",",
"events",
",",
"req",
".",
"ID",
",",
"parent",
",",
"system",
",",
"req",
".",
"ID",
",",
"req",
".",
"Bundle",
",",
"ht",
".",
"isWCOW",
",",
"s",
".",
"Process",
",",
"io",
")",
"\n\n",
"if",
"parent",
"!=",
"nil",
"{",
"// We have a parent UVM. Listen for its exit and forcibly close this",
"// task. This is not expected but in the event of a UVM crash we need to",
"// handle this case.",
"go",
"ht",
".",
"waitForHostExit",
"(",
")",
"\n",
"}",
"\n",
"// In the normal case the `Signal` call from the caller killed this task's",
"// init process.",
"go",
"func",
"(",
")",
"{",
"// Wait for our init process to exit.",
"ht",
".",
"init",
".",
"Wait",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"// Release all container resources for this task.",
"ht",
".",
"close",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"// Publish the created event",
"ht",
".",
"events",
"(",
"runtime",
".",
"TaskCreateEventTopic",
",",
"&",
"eventstypes",
".",
"TaskCreate",
"{",
"ContainerID",
":",
"req",
".",
"ID",
",",
"Bundle",
":",
"req",
".",
"Bundle",
",",
"Rootfs",
":",
"req",
".",
"Rootfs",
",",
"IO",
":",
"&",
"eventstypes",
".",
"TaskIO",
"{",
"Stdin",
":",
"req",
".",
"Stdin",
",",
"Stdout",
":",
"req",
".",
"Stdout",
",",
"Stderr",
":",
"req",
".",
"Stderr",
",",
"Terminal",
":",
"req",
".",
"Terminal",
",",
"}",
",",
"Checkpoint",
":",
"\"",
"\"",
",",
"Pid",
":",
"uint32",
"(",
"ht",
".",
"init",
".",
"Pid",
"(",
")",
")",
",",
"}",
")",
"\n",
"return",
"ht",
",",
"nil",
"\n",
"}"
] | // newHcsTask creates a container within `parent` and its init exec process in
// the `shimExecCreated` state and returns the task that tracks its lifetime.
//
// If `parent == nil` the container is created on the host. | [
"newHcsTask",
"creates",
"a",
"container",
"within",
"parent",
"and",
"its",
"init",
"exec",
"process",
"in",
"the",
"shimExecCreated",
"state",
"and",
"returns",
"the",
"task",
"that",
"tracks",
"its",
"lifetime",
".",
"If",
"parent",
"==",
"nil",
"the",
"container",
"is",
"created",
"on",
"the",
"host",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/task_hcs.go#L107-L197 | train |
Microsoft/hcsshim | internal/uvm/capabilities.go | SignalProcessSupported | func (uvm *UtilityVM) SignalProcessSupported() bool {
if props, err := uvm.hcsSystem.Properties(schema1.PropertyTypeGuestConnection); err == nil {
return props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported
}
return false
} | go | func (uvm *UtilityVM) SignalProcessSupported() bool {
if props, err := uvm.hcsSystem.Properties(schema1.PropertyTypeGuestConnection); err == nil {
return props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported
}
return false
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"SignalProcessSupported",
"(",
")",
"bool",
"{",
"if",
"props",
",",
"err",
":=",
"uvm",
".",
"hcsSystem",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeGuestConnection",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"props",
".",
"GuestConnectionInfo",
".",
"GuestDefinedCapabilities",
".",
"SignalProcessSupported",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // SignalProcessSupported returns `true` if the guest supports the capability to
// signal a process.
//
// This support was added RS5+ guests. | [
"SignalProcessSupported",
"returns",
"true",
"if",
"the",
"guest",
"supports",
"the",
"capability",
"to",
"signal",
"a",
"process",
".",
"This",
"support",
"was",
"added",
"RS5",
"+",
"guests",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/capabilities.go#L9-L14 | train |
Microsoft/hcsshim | internal/uvm/scsi.go | allocateSCSI | func (uvm *UtilityVM) allocateSCSI(hostPath string, uvmPath string, isLayer bool) (int, int32, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == "" {
uvm.scsiLocations[controller][lun].hostPath = hostPath
uvm.scsiLocations[controller][lun].uvmPath = uvmPath
uvm.scsiLocations[controller][lun].isLayer = isLayer
if isLayer {
uvm.scsiLocations[controller][lun].refCount = 1
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"isLayer": isLayer,
"refCount": uvm.scsiLocations[controller][lun].refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::allocateSCSI")
return controller, int32(lun), nil
}
}
}
return -1, -1, ErrNoAvailableLocation
} | go | func (uvm *UtilityVM) allocateSCSI(hostPath string, uvmPath string, isLayer bool) (int, int32, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == "" {
uvm.scsiLocations[controller][lun].hostPath = hostPath
uvm.scsiLocations[controller][lun].uvmPath = uvmPath
uvm.scsiLocations[controller][lun].isLayer = isLayer
if isLayer {
uvm.scsiLocations[controller][lun].refCount = 1
}
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"isLayer": isLayer,
"refCount": uvm.scsiLocations[controller][lun].refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::allocateSCSI")
return controller, int32(lun), nil
}
}
}
return -1, -1, ErrNoAvailableLocation
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"allocateSCSI",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"isLayer",
"bool",
")",
"(",
"int",
",",
"int32",
",",
"error",
")",
"{",
"for",
"controller",
",",
"luns",
":=",
"range",
"uvm",
".",
"scsiLocations",
"{",
"for",
"lun",
",",
"si",
":=",
"range",
"luns",
"{",
"if",
"si",
".",
"hostPath",
"==",
"\"",
"\"",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"hostPath",
"=",
"hostPath",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"uvmPath",
"=",
"uvmPath",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"isLayer",
"=",
"isLayer",
"\n",
"if",
"isLayer",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
"=",
"1",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"\"",
"\"",
":",
"uvmPath",
",",
"\"",
"\"",
":",
"isLayer",
",",
"\"",
"\"",
":",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
",",
"\"",
"\"",
":",
"controller",
",",
"\"",
"\"",
":",
"int32",
"(",
"lun",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"controller",
",",
"int32",
"(",
"lun",
")",
",",
"nil",
"\n\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"-",
"1",
",",
"ErrNoAvailableLocation",
"\n",
"}"
] | // allocateSCSI finds the next available slot on the
// SCSI controllers associated with a utility VM to use.
// Lock must be held when calling this function | [
"allocateSCSI",
"finds",
"the",
"next",
"available",
"slot",
"on",
"the",
"SCSI",
"controllers",
"associated",
"with",
"a",
"utility",
"VM",
"to",
"use",
".",
"Lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L26-L51 | train |
Microsoft/hcsshim | internal/uvm/scsi.go | findSCSIAttachment | func (uvm *UtilityVM) findSCSIAttachment(findThisHostPath string) (int, int32, string, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": si.uvmPath,
"isLayer": si.isLayer,
"refCount": si.refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::findSCSIAttachment")
return controller, int32(lun), si.uvmPath, nil
}
}
}
return -1, -1, "", ErrNotAttached
} | go | func (uvm *UtilityVM) findSCSIAttachment(findThisHostPath string) (int, int32, string, error) {
for controller, luns := range uvm.scsiLocations {
for lun, si := range luns {
if si.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": si.uvmPath,
"isLayer": si.isLayer,
"refCount": si.refCount,
"controller": controller,
"lun": int32(lun),
}).Debug("uvm::findSCSIAttachment")
return controller, int32(lun), si.uvmPath, nil
}
}
}
return -1, -1, "", ErrNotAttached
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"findSCSIAttachment",
"(",
"findThisHostPath",
"string",
")",
"(",
"int",
",",
"int32",
",",
"string",
",",
"error",
")",
"{",
"for",
"controller",
",",
"luns",
":=",
"range",
"uvm",
".",
"scsiLocations",
"{",
"for",
"lun",
",",
"si",
":=",
"range",
"luns",
"{",
"if",
"si",
".",
"hostPath",
"==",
"findThisHostPath",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"findThisHostPath",
",",
"\"",
"\"",
":",
"si",
".",
"uvmPath",
",",
"\"",
"\"",
":",
"si",
".",
"isLayer",
",",
"\"",
"\"",
":",
"si",
".",
"refCount",
",",
"\"",
"\"",
":",
"controller",
",",
"\"",
"\"",
":",
"int32",
"(",
"lun",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"controller",
",",
"int32",
"(",
"lun",
")",
",",
"si",
".",
"uvmPath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"-",
"1",
",",
"\"",
"\"",
",",
"ErrNotAttached",
"\n",
"}"
] | // Lock must be held when calling this function. | [
"Lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L72-L90 | train |
Microsoft/hcsshim | internal/uvm/scsi.go | RemoveSCSI | func (uvm *UtilityVM) RemoveSCSI(hostPath string) (err error) {
op := "uvm::RemoveSCSI"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if uvm.scsiControllerCount == 0 {
return ErrNoSCSIControllers
}
// Make sure is actually attached
controller, lun, uvmPath, err := uvm.findSCSIAttachment(hostPath)
if err != nil {
return err
}
if uvm.scsiLocations[controller][lun].isLayer {
uvm.scsiLocations[controller][lun].refCount--
if uvm.scsiLocations[controller][lun].refCount > 0 {
return nil
}
}
if err := uvm.removeSCSI(hostPath, uvmPath, controller, lun); err != nil {
return fmt.Errorf("failed to remove SCSI disk %s from container %s: %s", hostPath, uvm.id, err)
}
return nil
} | go | func (uvm *UtilityVM) RemoveSCSI(hostPath string) (err error) {
op := "uvm::RemoveSCSI"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if uvm.scsiControllerCount == 0 {
return ErrNoSCSIControllers
}
// Make sure is actually attached
controller, lun, uvmPath, err := uvm.findSCSIAttachment(hostPath)
if err != nil {
return err
}
if uvm.scsiLocations[controller][lun].isLayer {
uvm.scsiLocations[controller][lun].refCount--
if uvm.scsiLocations[controller][lun].refCount > 0 {
return nil
}
}
if err := uvm.removeSCSI(hostPath, uvmPath, controller, lun); err != nil {
return fmt.Errorf("failed to remove SCSI disk %s from container %s: %s", hostPath, uvm.id, err)
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveSCSI",
"(",
"hostPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"scsiControllerCount",
"==",
"0",
"{",
"return",
"ErrNoSCSIControllers",
"\n",
"}",
"\n\n",
"// Make sure is actually attached",
"controller",
",",
"lun",
",",
"uvmPath",
",",
"err",
":=",
"uvm",
".",
"findSCSIAttachment",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"isLayer",
"{",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
"--",
"\n",
"if",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
".",
"refCount",
">",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"removeSCSI",
"(",
"hostPath",
",",
"uvmPath",
",",
"controller",
",",
"lun",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
",",
"err",
")",
"\n\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemoveSCSI removes a SCSI disk from a utility VM. As an external API, it
// is "safe". Internal use can call removeSCSI. | [
"RemoveSCSI",
"removes",
"a",
"SCSI",
"disk",
"from",
"a",
"utility",
"VM",
".",
"As",
"an",
"external",
"API",
"it",
"is",
"safe",
".",
"Internal",
"use",
"can",
"call",
"removeSCSI",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L295-L336 | train |
Microsoft/hcsshim | internal/uvm/scsi.go | removeSCSI | func (uvm *UtilityVM) removeSCSI(hostPath string, uvmPath string, controller int, lun int32) error {
scsiModification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Scsi/%d/Attachments/%d", controller, lun),
}
// Include the GuestRequest so that the GCS ejects the disk cleanly if the
// disk was attached/mounted
//
// Note: We always send a guest eject even if there is no UVM path in lcow
// so that we synchronize the guest state. This seems to always avoid SCSI
// related errors if this index quickly reused by another container.
if uvm.operatingSystem == "windows" && uvmPath != "" {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.WCOWMappedVirtualDisk{
ContainerPath: uvmPath,
Lun: lun,
},
}
} else {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVirtualDisk{
MountPath: uvmPath, // May be blank in attach-only
Lun: uint8(lun),
Controller: uint8(controller),
},
}
}
if err := uvm.Modify(scsiModification); err != nil {
return err
}
uvm.scsiLocations[controller][lun] = scsiInfo{}
return nil
} | go | func (uvm *UtilityVM) removeSCSI(hostPath string, uvmPath string, controller int, lun int32) error {
scsiModification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Scsi/%d/Attachments/%d", controller, lun),
}
// Include the GuestRequest so that the GCS ejects the disk cleanly if the
// disk was attached/mounted
//
// Note: We always send a guest eject even if there is no UVM path in lcow
// so that we synchronize the guest state. This seems to always avoid SCSI
// related errors if this index quickly reused by another container.
if uvm.operatingSystem == "windows" && uvmPath != "" {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.WCOWMappedVirtualDisk{
ContainerPath: uvmPath,
Lun: lun,
},
}
} else {
scsiModification.GuestRequest = guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedVirtualDisk,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVirtualDisk{
MountPath: uvmPath, // May be blank in attach-only
Lun: uint8(lun),
Controller: uint8(controller),
},
}
}
if err := uvm.Modify(scsiModification); err != nil {
return err
}
uvm.scsiLocations[controller][lun] = scsiInfo{}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"removeSCSI",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"controller",
"int",
",",
"lun",
"int32",
")",
"error",
"{",
"scsiModification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"ResourcePath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"controller",
",",
"lun",
")",
",",
"}",
"\n\n",
"// Include the GuestRequest so that the GCS ejects the disk cleanly if the",
"// disk was attached/mounted",
"//",
"// Note: We always send a guest eject even if there is no UVM path in lcow",
"// so that we synchronize the guest state. This seems to always avoid SCSI",
"// related errors if this index quickly reused by another container.",
"if",
"uvm",
".",
"operatingSystem",
"==",
"\"",
"\"",
"&&",
"uvmPath",
"!=",
"\"",
"\"",
"{",
"scsiModification",
".",
"GuestRequest",
"=",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedVirtualDisk",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"WCOWMappedVirtualDisk",
"{",
"ContainerPath",
":",
"uvmPath",
",",
"Lun",
":",
"lun",
",",
"}",
",",
"}",
"\n",
"}",
"else",
"{",
"scsiModification",
".",
"GuestRequest",
"=",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedVirtualDisk",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"LCOWMappedVirtualDisk",
"{",
"MountPath",
":",
"uvmPath",
",",
"// May be blank in attach-only",
"Lun",
":",
"uint8",
"(",
"lun",
")",
",",
"Controller",
":",
"uint8",
"(",
"controller",
")",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"scsiModification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"uvm",
".",
"scsiLocations",
"[",
"controller",
"]",
"[",
"lun",
"]",
"=",
"scsiInfo",
"{",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // removeSCSI is the internally callable "unsafe" version of RemoveSCSI. The mutex
// MUST be held when calling this function. | [
"removeSCSI",
"is",
"the",
"internally",
"callable",
"unsafe",
"version",
"of",
"RemoveSCSI",
".",
"The",
"mutex",
"MUST",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L340-L378 | train |
Microsoft/hcsshim | internal/uvm/scsi.go | GetScsiUvmPath | func (uvm *UtilityVM) GetScsiUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetScsiUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
_, _, uvmPath, err := uvm.findSCSIAttachment(hostPath)
return uvmPath, err
} | go | func (uvm *UtilityVM) GetScsiUvmPath(hostPath string) (_ string, err error) {
op := "uvm::GetScsiUvmPath"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
_, _, uvmPath, err := uvm.findSCSIAttachment(hostPath)
return uvmPath, err
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"GetScsiUvmPath",
"(",
"hostPath",
"string",
")",
"(",
"_",
"string",
",",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"_",
",",
"uvmPath",
",",
"err",
":=",
"uvm",
".",
"findSCSIAttachment",
"(",
"hostPath",
")",
"\n",
"return",
"uvmPath",
",",
"err",
"\n",
"}"
] | // GetScsiUvmPath returns the guest mounted path of a SCSI drive.
//
// If `hostPath` is not mounted returns `ErrNotAttached`. | [
"GetScsiUvmPath",
"returns",
"the",
"guest",
"mounted",
"path",
"of",
"a",
"SCSI",
"drive",
".",
"If",
"hostPath",
"is",
"not",
"mounted",
"returns",
"ErrNotAttached",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/scsi.go#L383-L404 | train |
Microsoft/hcsshim | process.go | WaitTimeout | func (process *process) WaitTimeout(timeout time.Duration) error {
process.waitOnce.Do(func() {
process.waitCh = make(chan struct{})
go func() {
process.waitErr = process.Wait()
close(process.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ProcessError{Process: process, Err: ErrTimeout, Operation: "hcsshim::Process::Wait"}
case <-process.waitCh:
return process.waitErr
}
} | go | func (process *process) WaitTimeout(timeout time.Duration) error {
process.waitOnce.Do(func() {
process.waitCh = make(chan struct{})
go func() {
process.waitErr = process.Wait()
close(process.waitCh)
}()
})
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-t.C:
return &ProcessError{Process: process, Err: ErrTimeout, Operation: "hcsshim::Process::Wait"}
case <-process.waitCh:
return process.waitErr
}
} | [
"func",
"(",
"process",
"*",
"process",
")",
"WaitTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"process",
".",
"waitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"process",
".",
"waitCh",
"=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"process",
".",
"waitErr",
"=",
"process",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"process",
".",
"waitCh",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
")",
"\n",
"t",
":=",
"time",
".",
"NewTimer",
"(",
"timeout",
")",
"\n",
"defer",
"t",
".",
"Stop",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"t",
".",
"C",
":",
"return",
"&",
"ProcessError",
"{",
"Process",
":",
"process",
",",
"Err",
":",
"ErrTimeout",
",",
"Operation",
":",
"\"",
"\"",
"}",
"\n",
"case",
"<-",
"process",
".",
"waitCh",
":",
"return",
"process",
".",
"waitErr",
"\n",
"}",
"\n",
"}"
] | // WaitTimeout waits for the process to exit or the duration to elapse. It returns
// false if timeout occurs. | [
"WaitTimeout",
"waits",
"for",
"the",
"process",
"to",
"exit",
"or",
"the",
"duration",
"to",
"elapse",
".",
"It",
"returns",
"false",
"if",
"timeout",
"occurs",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/process.go#L43-L59 | train |
Microsoft/hcsshim | process.go | Stdio | func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
stdin, stdout, stderr, err := process.p.StdioLegacy()
if err != nil {
err = convertProcessError(err, process)
}
return stdin, stdout, stderr, err
} | go | func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
stdin, stdout, stderr, err := process.p.StdioLegacy()
if err != nil {
err = convertProcessError(err, process)
}
return stdin, stdout, stderr, err
} | [
"func",
"(",
"process",
"*",
"process",
")",
"Stdio",
"(",
")",
"(",
"io",
".",
"WriteCloser",
",",
"io",
".",
"ReadCloser",
",",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"stdin",
",",
"stdout",
",",
"stderr",
",",
"err",
":=",
"process",
".",
"p",
".",
"StdioLegacy",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"convertProcessError",
"(",
"err",
",",
"process",
")",
"\n",
"}",
"\n",
"return",
"stdin",
",",
"stdout",
",",
"stderr",
",",
"err",
"\n",
"}"
] | // Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
// these pipes does not close the underlying pipes; it should be possible to
// call this multiple times to get multiple interfaces. | [
"Stdio",
"returns",
"the",
"stdin",
"stdout",
"and",
"stderr",
"pipes",
"respectively",
".",
"Closing",
"these",
"pipes",
"does",
"not",
"close",
"the",
"underlying",
"pipes",
";",
"it",
"should",
"be",
"possible",
"to",
"call",
"this",
"multiple",
"times",
"to",
"get",
"multiple",
"interfaces",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/process.go#L79-L85 | train |
Microsoft/hcsshim | ext4/tar2ext4/tar2ext4.go | InlineData | func InlineData(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.InlineData)
} | go | func InlineData(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.InlineData)
} | [
"func",
"InlineData",
"(",
"p",
"*",
"params",
")",
"{",
"p",
".",
"ext4opts",
"=",
"append",
"(",
"p",
".",
"ext4opts",
",",
"compactext4",
".",
"InlineData",
")",
"\n",
"}"
] | // InlineData instructs the converter to write small files into the inode
// structures directly. This creates smaller images but currently is not
// compatible with DAX. | [
"InlineData",
"instructs",
"the",
"converter",
"to",
"write",
"small",
"files",
"into",
"the",
"inode",
"structures",
"directly",
".",
"This",
"creates",
"smaller",
"images",
"but",
"currently",
"is",
"not",
"compatible",
"with",
"DAX",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/tar2ext4/tar2ext4.go#L38-L40 | train |
Microsoft/hcsshim | ext4/tar2ext4/tar2ext4.go | MaximumDiskSize | func MaximumDiskSize(size int64) Option {
return func(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.MaximumDiskSize(size))
}
} | go | func MaximumDiskSize(size int64) Option {
return func(p *params) {
p.ext4opts = append(p.ext4opts, compactext4.MaximumDiskSize(size))
}
} | [
"func",
"MaximumDiskSize",
"(",
"size",
"int64",
")",
"Option",
"{",
"return",
"func",
"(",
"p",
"*",
"params",
")",
"{",
"p",
".",
"ext4opts",
"=",
"append",
"(",
"p",
".",
"ext4opts",
",",
"compactext4",
".",
"MaximumDiskSize",
"(",
"size",
")",
")",
"\n",
"}",
"\n",
"}"
] | // MaximumDiskSize instructs the writer to limit the disk size to the specified
// value. This also reserves enough metadata space for the specified disk size.
// If not provided, then 16GB is the default. | [
"MaximumDiskSize",
"instructs",
"the",
"writer",
"to",
"limit",
"the",
"disk",
"size",
"to",
"the",
"specified",
"value",
".",
"This",
"also",
"reserves",
"enough",
"metadata",
"space",
"for",
"the",
"specified",
"disk",
"size",
".",
"If",
"not",
"provided",
"then",
"16GB",
"is",
"the",
"default",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/tar2ext4/tar2ext4.go#L45-L49 | train |
Microsoft/hcsshim | internal/hcs/system.go | CreateComputeSystem | func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System, err error) {
operation := "hcsshim::CreateComputeSystem"
computeSystem := newSystem(id)
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
hcsDocumentB, err := json.Marshal(hcsDocumentInterface)
if err != nil {
return nil, err
}
hcsDocument := string(hcsDocumentB)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, hcsDocument).
Debug("HCS ComputeSystem Document")
var (
resultp *uint16
identity syscall.Handle
createError error
)
syscallWatcher(computeSystem.logctx, func() {
createError = hcsCreateComputeSystem(id, hcsDocument, identity, &computeSystem.handle, &resultp)
})
if createError == nil || IsPending(createError) {
if err = computeSystem.registerCallback(); err != nil {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
computeSystem.Terminate()
return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
}
events, err := processAsyncHcsResult(createError, resultp, computeSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCreate)
if err != nil {
if err == ErrTimeout {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
computeSystem.Terminate()
}
return nil, makeSystemError(computeSystem, operation, hcsDocument, err, events)
}
go computeSystem.waitBackground()
return computeSystem, nil
} | go | func CreateComputeSystem(id string, hcsDocumentInterface interface{}) (_ *System, err error) {
operation := "hcsshim::CreateComputeSystem"
computeSystem := newSystem(id)
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
hcsDocumentB, err := json.Marshal(hcsDocumentInterface)
if err != nil {
return nil, err
}
hcsDocument := string(hcsDocumentB)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, hcsDocument).
Debug("HCS ComputeSystem Document")
var (
resultp *uint16
identity syscall.Handle
createError error
)
syscallWatcher(computeSystem.logctx, func() {
createError = hcsCreateComputeSystem(id, hcsDocument, identity, &computeSystem.handle, &resultp)
})
if createError == nil || IsPending(createError) {
if err = computeSystem.registerCallback(); err != nil {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
computeSystem.Terminate()
return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
}
events, err := processAsyncHcsResult(createError, resultp, computeSystem.callbackNumber, hcsNotificationSystemCreateCompleted, &timeout.SystemCreate)
if err != nil {
if err == ErrTimeout {
// Terminate the compute system if it still exists. We're okay to
// ignore a failure here.
computeSystem.Terminate()
}
return nil, makeSystemError(computeSystem, operation, hcsDocument, err, events)
}
go computeSystem.waitBackground()
return computeSystem, nil
} | [
"func",
"CreateComputeSystem",
"(",
"id",
"string",
",",
"hcsDocumentInterface",
"interface",
"{",
"}",
")",
"(",
"_",
"*",
"System",
",",
"err",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n\n",
"computeSystem",
":=",
"newSystem",
"(",
"id",
")",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"hcsDocumentB",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"hcsDocumentInterface",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"hcsDocument",
":=",
"string",
"(",
"hcsDocumentB",
")",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"computeSystem",
".",
"logctx",
")",
".",
"WithField",
"(",
"logfields",
".",
"JSON",
",",
"hcsDocument",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"(",
"resultp",
"*",
"uint16",
"\n",
"identity",
"syscall",
".",
"Handle",
"\n",
"createError",
"error",
"\n",
")",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"createError",
"=",
"hcsCreateComputeSystem",
"(",
"id",
",",
"hcsDocument",
",",
"identity",
",",
"&",
"computeSystem",
".",
"handle",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n\n",
"if",
"createError",
"==",
"nil",
"||",
"IsPending",
"(",
"createError",
")",
"{",
"if",
"err",
"=",
"computeSystem",
".",
"registerCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"// Terminate the compute system if it still exists. We're okay to",
"// ignore a failure here.",
"computeSystem",
".",
"Terminate",
"(",
")",
"\n",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"operation",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"events",
",",
"err",
":=",
"processAsyncHcsResult",
"(",
"createError",
",",
"resultp",
",",
"computeSystem",
".",
"callbackNumber",
",",
"hcsNotificationSystemCreateCompleted",
",",
"&",
"timeout",
".",
"SystemCreate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"ErrTimeout",
"{",
"// Terminate the compute system if it still exists. We're okay to",
"// ignore a failure here.",
"computeSystem",
".",
"Terminate",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"operation",
",",
"hcsDocument",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"go",
"computeSystem",
".",
"waitBackground",
"(",
")",
"\n\n",
"return",
"computeSystem",
",",
"nil",
"\n",
"}"
] | // CreateComputeSystem creates a new compute system with the given configuration but does not start it. | [
"CreateComputeSystem",
"creates",
"a",
"new",
"compute",
"system",
"with",
"the",
"given",
"configuration",
"but",
"does",
"not",
"start",
"it",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L79-L128 | train |
Microsoft/hcsshim | internal/hcs/system.go | OpenComputeSystem | func OpenComputeSystem(id string) (_ *System, err error) {
operation := "hcsshim::OpenComputeSystem"
computeSystem := newSystem(id)
computeSystem.logOperationBegin(operation)
defer func() {
if IsNotExist(err) {
computeSystem.logOperationEnd(operation, nil)
} else {
computeSystem.logOperationEnd(operation, err)
}
}()
var (
handle hcsSystem
resultp *uint16
)
err = hcsOpenComputeSystem(id, &handle, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
}
computeSystem.handle = handle
if err = computeSystem.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
go computeSystem.waitBackground()
return computeSystem, nil
} | go | func OpenComputeSystem(id string) (_ *System, err error) {
operation := "hcsshim::OpenComputeSystem"
computeSystem := newSystem(id)
computeSystem.logOperationBegin(operation)
defer func() {
if IsNotExist(err) {
computeSystem.logOperationEnd(operation, nil)
} else {
computeSystem.logOperationEnd(operation, err)
}
}()
var (
handle hcsSystem
resultp *uint16
)
err = hcsOpenComputeSystem(id, &handle, &resultp)
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, events)
}
computeSystem.handle = handle
if err = computeSystem.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, operation, "", err, nil)
}
go computeSystem.waitBackground()
return computeSystem, nil
} | [
"func",
"OpenComputeSystem",
"(",
"id",
"string",
")",
"(",
"_",
"*",
"System",
",",
"err",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n\n",
"computeSystem",
":=",
"newSystem",
"(",
"id",
")",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"IsNotExist",
"(",
"err",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"(",
"handle",
"hcsSystem",
"\n",
"resultp",
"*",
"uint16",
"\n",
")",
"\n",
"err",
"=",
"hcsOpenComputeSystem",
"(",
"id",
",",
"&",
"handle",
",",
"&",
"resultp",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"operation",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"computeSystem",
".",
"handle",
"=",
"handle",
"\n\n",
"if",
"err",
"=",
"computeSystem",
".",
"registerCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"operation",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n",
"go",
"computeSystem",
".",
"waitBackground",
"(",
")",
"\n\n",
"return",
"computeSystem",
",",
"nil",
"\n",
"}"
] | // OpenComputeSystem opens an existing compute system by ID. | [
"OpenComputeSystem",
"opens",
"an",
"existing",
"compute",
"system",
"by",
"ID",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L131-L162 | train |
Microsoft/hcsshim | internal/hcs/system.go | GetComputeSystems | func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerProperties, err error) {
operation := "hcsshim::GetComputeSystems"
fields := logrus.Fields{}
logOperationBegin(
fields,
operation+" - Begin Operation")
defer func() {
var result string
if err == nil {
result = "Success"
} else {
result = "Error"
}
logOperationEnd(
fields,
operation+" - End Operation - "+result,
err)
}()
queryb, err := json.Marshal(q)
if err != nil {
return nil, err
}
query := string(queryb)
logrus.WithFields(fields).
WithField(logfields.JSON, query).
Debug("HCS ComputeSystem Query")
var (
resultp *uint16
computeSystemsp *uint16
)
syscallWatcher(fields, func() {
err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, &HcsError{Op: operation, Err: err, Events: events}
}
if computeSystemsp == nil {
return nil, ErrUnexpectedValue
}
computeSystemsRaw := interop.ConvertAndFreeCoTaskMemBytes(computeSystemsp)
computeSystems := []schema1.ContainerProperties{}
if err = json.Unmarshal(computeSystemsRaw, &computeSystems); err != nil {
return nil, err
}
return computeSystems, nil
} | go | func GetComputeSystems(q schema1.ComputeSystemQuery) (_ []schema1.ContainerProperties, err error) {
operation := "hcsshim::GetComputeSystems"
fields := logrus.Fields{}
logOperationBegin(
fields,
operation+" - Begin Operation")
defer func() {
var result string
if err == nil {
result = "Success"
} else {
result = "Error"
}
logOperationEnd(
fields,
operation+" - End Operation - "+result,
err)
}()
queryb, err := json.Marshal(q)
if err != nil {
return nil, err
}
query := string(queryb)
logrus.WithFields(fields).
WithField(logfields.JSON, query).
Debug("HCS ComputeSystem Query")
var (
resultp *uint16
computeSystemsp *uint16
)
syscallWatcher(fields, func() {
err = hcsEnumerateComputeSystems(query, &computeSystemsp, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, &HcsError{Op: operation, Err: err, Events: events}
}
if computeSystemsp == nil {
return nil, ErrUnexpectedValue
}
computeSystemsRaw := interop.ConvertAndFreeCoTaskMemBytes(computeSystemsp)
computeSystems := []schema1.ContainerProperties{}
if err = json.Unmarshal(computeSystemsRaw, &computeSystems); err != nil {
return nil, err
}
return computeSystems, nil
} | [
"func",
"GetComputeSystems",
"(",
"q",
"schema1",
".",
"ComputeSystemQuery",
")",
"(",
"_",
"[",
"]",
"schema1",
".",
"ContainerProperties",
",",
"err",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"}",
"\n",
"logOperationBegin",
"(",
"fields",
",",
"operation",
"+",
"\"",
"\"",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"var",
"result",
"string",
"\n",
"if",
"err",
"==",
"nil",
"{",
"result",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"result",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"logOperationEnd",
"(",
"fields",
",",
"operation",
"+",
"\"",
"\"",
"+",
"result",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n\n",
"queryb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"q",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"query",
":=",
"string",
"(",
"queryb",
")",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"WithField",
"(",
"logfields",
".",
"JSON",
",",
"query",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"(",
"resultp",
"*",
"uint16",
"\n",
"computeSystemsp",
"*",
"uint16",
"\n",
")",
"\n\n",
"syscallWatcher",
"(",
"fields",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsEnumerateComputeSystems",
"(",
"query",
",",
"&",
"computeSystemsp",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"HcsError",
"{",
"Op",
":",
"operation",
",",
"Err",
":",
"err",
",",
"Events",
":",
"events",
"}",
"\n",
"}",
"\n\n",
"if",
"computeSystemsp",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrUnexpectedValue",
"\n",
"}",
"\n",
"computeSystemsRaw",
":=",
"interop",
".",
"ConvertAndFreeCoTaskMemBytes",
"(",
"computeSystemsp",
")",
"\n",
"computeSystems",
":=",
"[",
"]",
"schema1",
".",
"ContainerProperties",
"{",
"}",
"\n",
"if",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"computeSystemsRaw",
",",
"&",
"computeSystems",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"computeSystems",
",",
"nil",
"\n",
"}"
] | // GetComputeSystems gets a list of the compute systems on the system that match the query | [
"GetComputeSystems",
"gets",
"a",
"list",
"of",
"the",
"compute",
"systems",
"on",
"the",
"system",
"that",
"match",
"the",
"query"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L165-L220 | train |
Microsoft/hcsshim | internal/hcs/system.go | Start | func (computeSystem *System) Start() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Start"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Start", "", ErrAlreadyClosed, nil)
}
// This is a very simple backoff-retry loop to limit the number
// of parallel container starts if environment variable
// HCSSHIM_MAX_PARALLEL_START is set to a positive integer.
// It should generally only be used as a workaround to various
// platform issues that exist between RS1 and RS4 as of Aug 2018
if currentContainerStarts.maxParallel > 0 {
for {
currentContainerStarts.Lock()
if currentContainerStarts.inProgress < currentContainerStarts.maxParallel {
currentContainerStarts.inProgress++
currentContainerStarts.Unlock()
break
}
if currentContainerStarts.inProgress == currentContainerStarts.maxParallel {
currentContainerStarts.Unlock()
time.Sleep(100 * time.Millisecond)
}
}
// Make sure we decrement the count when we are done.
defer func() {
currentContainerStarts.Lock()
currentContainerStarts.inProgress--
currentContainerStarts.Unlock()
}()
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsStartComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil {
return makeSystemError(computeSystem, "Start", "", err, events)
}
return nil
} | go | func (computeSystem *System) Start() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Start"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Start", "", ErrAlreadyClosed, nil)
}
// This is a very simple backoff-retry loop to limit the number
// of parallel container starts if environment variable
// HCSSHIM_MAX_PARALLEL_START is set to a positive integer.
// It should generally only be used as a workaround to various
// platform issues that exist between RS1 and RS4 as of Aug 2018
if currentContainerStarts.maxParallel > 0 {
for {
currentContainerStarts.Lock()
if currentContainerStarts.inProgress < currentContainerStarts.maxParallel {
currentContainerStarts.inProgress++
currentContainerStarts.Unlock()
break
}
if currentContainerStarts.inProgress == currentContainerStarts.maxParallel {
currentContainerStarts.Unlock()
time.Sleep(100 * time.Millisecond)
}
}
// Make sure we decrement the count when we are done.
defer func() {
currentContainerStarts.Lock()
currentContainerStarts.inProgress--
currentContainerStarts.Unlock()
}()
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsStartComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemStartCompleted, &timeout.SystemStart)
if err != nil {
return makeSystemError(computeSystem, "Start", "", err, events)
}
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"// This is a very simple backoff-retry loop to limit the number",
"// of parallel container starts if environment variable",
"// HCSSHIM_MAX_PARALLEL_START is set to a positive integer.",
"// It should generally only be used as a workaround to various",
"// platform issues that exist between RS1 and RS4 as of Aug 2018",
"if",
"currentContainerStarts",
".",
"maxParallel",
">",
"0",
"{",
"for",
"{",
"currentContainerStarts",
".",
"Lock",
"(",
")",
"\n",
"if",
"currentContainerStarts",
".",
"inProgress",
"<",
"currentContainerStarts",
".",
"maxParallel",
"{",
"currentContainerStarts",
".",
"inProgress",
"++",
"\n",
"currentContainerStarts",
".",
"Unlock",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n",
"if",
"currentContainerStarts",
".",
"inProgress",
"==",
"currentContainerStarts",
".",
"maxParallel",
"{",
"currentContainerStarts",
".",
"Unlock",
"(",
")",
"\n",
"time",
".",
"Sleep",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Make sure we decrement the count when we are done.",
"defer",
"func",
"(",
")",
"{",
"currentContainerStarts",
".",
"Lock",
"(",
")",
"\n",
"currentContainerStarts",
".",
"inProgress",
"--",
"\n",
"currentContainerStarts",
".",
"Unlock",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsStartComputeSystem",
"(",
"computeSystem",
".",
"handle",
",",
"\"",
"\"",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
",",
"err",
":=",
"processAsyncHcsResult",
"(",
"err",
",",
"resultp",
",",
"computeSystem",
".",
"callbackNumber",
",",
"hcsNotificationSystemStartCompleted",
",",
"&",
"timeout",
".",
"SystemStart",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Start synchronously starts the computeSystem. | [
"Start",
"synchronously",
"starts",
"the",
"computeSystem",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L223-L271 | train |
Microsoft/hcsshim | internal/hcs/system.go | Shutdown | func (computeSystem *System) Shutdown() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Shutdown"
computeSystem.logOperationBegin(operation)
defer func() {
computeSystem.logOperationEnd(operation, err)
}()
if computeSystem.handle == 0 {
return nil
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsShutdownComputeSystem(computeSystem.handle, "", &resultp)
})
events := processHcsResult(resultp)
switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
return makeSystemError(computeSystem, "Shutdown", "", err, events)
}
return nil
} | go | func (computeSystem *System) Shutdown() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Shutdown"
computeSystem.logOperationBegin(operation)
defer func() {
computeSystem.logOperationEnd(operation, err)
}()
if computeSystem.handle == 0 {
return nil
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsShutdownComputeSystem(computeSystem.handle, "", &resultp)
})
events := processHcsResult(resultp)
switch err {
case nil, ErrVmcomputeAlreadyStopped, ErrComputeSystemDoesNotExist, ErrVmcomputeOperationPending:
default:
return makeSystemError(computeSystem, "Shutdown", "", err, events)
}
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Shutdown",
"(",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsShutdownComputeSystem",
"(",
"computeSystem",
".",
"handle",
",",
"\"",
"\"",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"switch",
"err",
"{",
"case",
"nil",
",",
"ErrVmcomputeAlreadyStopped",
",",
"ErrComputeSystemDoesNotExist",
",",
"ErrVmcomputeOperationPending",
":",
"default",
":",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Shutdown requests a compute system shutdown. | [
"Shutdown",
"requests",
"a",
"compute",
"system",
"shutdown",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L279-L304 | train |
Microsoft/hcsshim | internal/hcs/system.go | ExitError | func (computeSystem *System) ExitError() (err error) {
select {
case <-computeSystem.waitBlock:
if computeSystem.waitError != nil {
return computeSystem.waitError
}
return computeSystem.exitError
default:
return errors.New("container not exited")
}
} | go | func (computeSystem *System) ExitError() (err error) {
select {
case <-computeSystem.waitBlock:
if computeSystem.waitError != nil {
return computeSystem.waitError
}
return computeSystem.exitError
default:
return errors.New("container not exited")
}
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"ExitError",
"(",
")",
"(",
"err",
"error",
")",
"{",
"select",
"{",
"case",
"<-",
"computeSystem",
".",
"waitBlock",
":",
"if",
"computeSystem",
".",
"waitError",
"!=",
"nil",
"{",
"return",
"computeSystem",
".",
"waitError",
"\n",
"}",
"\n",
"return",
"computeSystem",
".",
"exitError",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // ExitError returns an error describing the reason the compute system terminated. | [
"ExitError",
"returns",
"an",
"error",
"describing",
"the",
"reason",
"the",
"compute",
"system",
"terminated",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L367-L377 | train |
Microsoft/hcsshim | internal/hcs/system.go | Pause | func (computeSystem *System) Pause() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Pause"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Pause", "", ErrAlreadyClosed, nil)
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsPauseComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
if err != nil {
return makeSystemError(computeSystem, "Pause", "", err, events)
}
return nil
} | go | func (computeSystem *System) Pause() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Pause"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Pause", "", ErrAlreadyClosed, nil)
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsPauseComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemPauseCompleted, &timeout.SystemPause)
if err != nil {
return makeSystemError(computeSystem, "Pause", "", err, events)
}
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Pause",
"(",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsPauseComputeSystem",
"(",
"computeSystem",
".",
"handle",
",",
"\"",
"\"",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
",",
"err",
":=",
"processAsyncHcsResult",
"(",
"err",
",",
"resultp",
",",
"computeSystem",
".",
"callbackNumber",
",",
"hcsNotificationSystemPauseCompleted",
",",
"&",
"timeout",
".",
"SystemPause",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Pause pauses the execution of the computeSystem. This feature is not enabled in TP5. | [
"Pause",
"pauses",
"the",
"execution",
"of",
"the",
"computeSystem",
".",
"This",
"feature",
"is",
"not",
"enabled",
"in",
"TP5",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L419-L441 | train |
Microsoft/hcsshim | internal/hcs/system.go | Resume | func (computeSystem *System) Resume() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Resume"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Resume", "", ErrAlreadyClosed, nil)
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsResumeComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
if err != nil {
return makeSystemError(computeSystem, "Resume", "", err, events)
}
return nil
} | go | func (computeSystem *System) Resume() (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Resume"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Resume", "", ErrAlreadyClosed, nil)
}
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsResumeComputeSystem(computeSystem.handle, "", &resultp)
})
events, err := processAsyncHcsResult(err, resultp, computeSystem.callbackNumber, hcsNotificationSystemResumeCompleted, &timeout.SystemResume)
if err != nil {
return makeSystemError(computeSystem, "Resume", "", err, events)
}
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Resume",
"(",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsResumeComputeSystem",
"(",
"computeSystem",
".",
"handle",
",",
"\"",
"\"",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
",",
"err",
":=",
"processAsyncHcsResult",
"(",
"err",
",",
"resultp",
",",
"computeSystem",
".",
"callbackNumber",
",",
"hcsNotificationSystemResumeCompleted",
",",
"&",
"timeout",
".",
"SystemResume",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Resume resumes the execution of the computeSystem. This feature is not enabled in TP5. | [
"Resume",
"resumes",
"the",
"execution",
"of",
"the",
"computeSystem",
".",
"This",
"feature",
"is",
"not",
"enabled",
"in",
"TP5",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L444-L466 | train |
Microsoft/hcsshim | internal/hcs/system.go | CreateProcess | func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::CreateProcess"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
var (
processInfo hcsProcessInformation
processHandle hcsProcess
resultp *uint16
)
if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, "CreateProcess", "", ErrAlreadyClosed, nil)
}
configurationb, err := json.Marshal(c)
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
configuration := string(configurationb)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, configuration).
Debug("HCS ComputeSystem Process Document")
syscallWatcher(computeSystem.logctx, func() {
err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", configuration, err, events)
}
logrus.WithFields(computeSystem.logctx).
WithField(logfields.ProcessID, processInfo.ProcessId).
Debug("HCS ComputeSystem CreateProcess PID")
process := newProcess(processHandle, int(processInfo.ProcessId), computeSystem)
defer func() {
if err != nil {
process.Close()
}
}()
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
process.stdin = pipes[0]
process.stdout = pipes[1]
process.stderr = pipes[2]
if err = process.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
go process.waitBackground()
return process, nil
} | go | func (computeSystem *System) CreateProcess(c interface{}) (_ *Process, err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::CreateProcess"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
var (
processInfo hcsProcessInformation
processHandle hcsProcess
resultp *uint16
)
if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, "CreateProcess", "", ErrAlreadyClosed, nil)
}
configurationb, err := json.Marshal(c)
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
configuration := string(configurationb)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, configuration).
Debug("HCS ComputeSystem Process Document")
syscallWatcher(computeSystem.logctx, func() {
err = hcsCreateProcess(computeSystem.handle, configuration, &processInfo, &processHandle, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", configuration, err, events)
}
logrus.WithFields(computeSystem.logctx).
WithField(logfields.ProcessID, processInfo.ProcessId).
Debug("HCS ComputeSystem CreateProcess PID")
process := newProcess(processHandle, int(processInfo.ProcessId), computeSystem)
defer func() {
if err != nil {
process.Close()
}
}()
pipes, err := makeOpenFiles([]syscall.Handle{processInfo.StdInput, processInfo.StdOutput, processInfo.StdError})
if err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
process.stdin = pipes[0]
process.stdout = pipes[1]
process.stderr = pipes[2]
if err = process.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, "CreateProcess", "", err, nil)
}
go process.waitBackground()
return process, nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"CreateProcess",
"(",
"c",
"interface",
"{",
"}",
")",
"(",
"_",
"*",
"Process",
",",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"var",
"(",
"processInfo",
"hcsProcessInformation",
"\n",
"processHandle",
"hcsProcess",
"\n",
"resultp",
"*",
"uint16",
"\n",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"configurationb",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"configuration",
":=",
"string",
"(",
"configurationb",
")",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"computeSystem",
".",
"logctx",
")",
".",
"WithField",
"(",
"logfields",
".",
"JSON",
",",
"configuration",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsCreateProcess",
"(",
"computeSystem",
".",
"handle",
",",
"configuration",
",",
"&",
"processInfo",
",",
"&",
"processHandle",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"configuration",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"computeSystem",
".",
"logctx",
")",
".",
"WithField",
"(",
"logfields",
".",
"ProcessID",
",",
"processInfo",
".",
"ProcessId",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"process",
":=",
"newProcess",
"(",
"processHandle",
",",
"int",
"(",
"processInfo",
".",
"ProcessId",
")",
",",
"computeSystem",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"process",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"pipes",
",",
"err",
":=",
"makeOpenFiles",
"(",
"[",
"]",
"syscall",
".",
"Handle",
"{",
"processInfo",
".",
"StdInput",
",",
"processInfo",
".",
"StdOutput",
",",
"processInfo",
".",
"StdError",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n",
"process",
".",
"stdin",
"=",
"pipes",
"[",
"0",
"]",
"\n",
"process",
".",
"stdout",
"=",
"pipes",
"[",
"1",
"]",
"\n",
"process",
".",
"stderr",
"=",
"pipes",
"[",
"2",
"]",
"\n",
"if",
"err",
"=",
"process",
".",
"registerCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n",
"go",
"process",
".",
"waitBackground",
"(",
")",
"\n\n",
"return",
"process",
",",
"nil",
"\n",
"}"
] | // CreateProcess launches a new process within the computeSystem. | [
"CreateProcess",
"launches",
"a",
"new",
"process",
"within",
"the",
"computeSystem",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L469-L529 | train |
Microsoft/hcsshim | internal/hcs/system.go | OpenProcess | func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
// Add PID for the context of this operation
computeSystem.logctx[logfields.ProcessID] = pid
defer delete(computeSystem.logctx, logfields.ProcessID)
operation := "hcsshim::ComputeSystem::OpenProcess"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
var (
processHandle hcsProcess
resultp *uint16
)
if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, "OpenProcess", "", ErrAlreadyClosed, nil)
}
syscallWatcher(computeSystem.logctx, func() {
err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, "OpenProcess", "", err, events)
}
process := newProcess(processHandle, pid, computeSystem)
if err = process.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, "OpenProcess", "", err, nil)
}
go process.waitBackground()
return process, nil
} | go | func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
// Add PID for the context of this operation
computeSystem.logctx[logfields.ProcessID] = pid
defer delete(computeSystem.logctx, logfields.ProcessID)
operation := "hcsshim::ComputeSystem::OpenProcess"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
var (
processHandle hcsProcess
resultp *uint16
)
if computeSystem.handle == 0 {
return nil, makeSystemError(computeSystem, "OpenProcess", "", ErrAlreadyClosed, nil)
}
syscallWatcher(computeSystem.logctx, func() {
err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return nil, makeSystemError(computeSystem, "OpenProcess", "", err, events)
}
process := newProcess(processHandle, pid, computeSystem)
if err = process.registerCallback(); err != nil {
return nil, makeSystemError(computeSystem, "OpenProcess", "", err, nil)
}
go process.waitBackground()
return process, nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"OpenProcess",
"(",
"pid",
"int",
")",
"(",
"_",
"*",
"Process",
",",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Add PID for the context of this operation",
"computeSystem",
".",
"logctx",
"[",
"logfields",
".",
"ProcessID",
"]",
"=",
"pid",
"\n",
"defer",
"delete",
"(",
"computeSystem",
".",
"logctx",
",",
"logfields",
".",
"ProcessID",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"var",
"(",
"processHandle",
"hcsProcess",
"\n",
"resultp",
"*",
"uint16",
"\n",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsOpenProcess",
"(",
"computeSystem",
".",
"handle",
",",
"uint32",
"(",
"pid",
")",
",",
"&",
"processHandle",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"process",
":=",
"newProcess",
"(",
"processHandle",
",",
"pid",
",",
"computeSystem",
")",
"\n",
"if",
"err",
"=",
"process",
".",
"registerCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n",
"go",
"process",
".",
"waitBackground",
"(",
")",
"\n\n",
"return",
"process",
",",
"nil",
"\n",
"}"
] | // OpenProcess gets an interface to an existing process within the computeSystem. | [
"OpenProcess",
"gets",
"an",
"interface",
"to",
"an",
"existing",
"process",
"within",
"the",
"computeSystem",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L532-L568 | train |
Microsoft/hcsshim | internal/hcs/system.go | Close | func (computeSystem *System) Close() (err error) {
computeSystem.handleLock.Lock()
defer computeSystem.handleLock.Unlock()
operation := "hcsshim::ComputeSystem::Close"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
// Don't double free this
if computeSystem.handle == 0 {
return nil
}
if err = computeSystem.unregisterCallback(); err != nil {
return makeSystemError(computeSystem, "Close", "", err, nil)
}
syscallWatcher(computeSystem.logctx, func() {
err = hcsCloseComputeSystem(computeSystem.handle)
})
if err != nil {
return makeSystemError(computeSystem, "Close", "", err, nil)
}
computeSystem.handle = 0
computeSystem.closedWaitOnce.Do(func() {
computeSystem.waitError = ErrAlreadyClosed
close(computeSystem.waitBlock)
})
return nil
} | go | func (computeSystem *System) Close() (err error) {
computeSystem.handleLock.Lock()
defer computeSystem.handleLock.Unlock()
operation := "hcsshim::ComputeSystem::Close"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
// Don't double free this
if computeSystem.handle == 0 {
return nil
}
if err = computeSystem.unregisterCallback(); err != nil {
return makeSystemError(computeSystem, "Close", "", err, nil)
}
syscallWatcher(computeSystem.logctx, func() {
err = hcsCloseComputeSystem(computeSystem.handle)
})
if err != nil {
return makeSystemError(computeSystem, "Close", "", err, nil)
}
computeSystem.handle = 0
computeSystem.closedWaitOnce.Do(func() {
computeSystem.waitError = ErrAlreadyClosed
close(computeSystem.waitBlock)
})
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"Unlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"// Don't double free this",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"computeSystem",
".",
"unregisterCallback",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsCloseComputeSystem",
"(",
"computeSystem",
".",
"handle",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"computeSystem",
".",
"handle",
"=",
"0",
"\n",
"computeSystem",
".",
"closedWaitOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"computeSystem",
".",
"waitError",
"=",
"ErrAlreadyClosed",
"\n",
"close",
"(",
"computeSystem",
".",
"waitBlock",
")",
"\n",
"}",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close cleans up any state associated with the compute system but does not terminate or wait for it. | [
"Close",
"cleans",
"up",
"any",
"state",
"associated",
"with",
"the",
"compute",
"system",
"but",
"does",
"not",
"terminate",
"or",
"wait",
"for",
"it",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L571-L602 | train |
Microsoft/hcsshim | internal/hcs/system.go | Modify | func (computeSystem *System) Modify(config interface{}) (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Modify"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Modify", "", ErrAlreadyClosed, nil)
}
requestJSON, err := json.Marshal(config)
if err != nil {
return err
}
requestString := string(requestJSON)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, requestString).
Debug("HCS ComputeSystem Modify Document")
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsModifyComputeSystem(computeSystem.handle, requestString, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return makeSystemError(computeSystem, "Modify", requestString, err, events)
}
return nil
} | go | func (computeSystem *System) Modify(config interface{}) (err error) {
computeSystem.handleLock.RLock()
defer computeSystem.handleLock.RUnlock()
operation := "hcsshim::ComputeSystem::Modify"
computeSystem.logOperationBegin(operation)
defer func() { computeSystem.logOperationEnd(operation, err) }()
if computeSystem.handle == 0 {
return makeSystemError(computeSystem, "Modify", "", ErrAlreadyClosed, nil)
}
requestJSON, err := json.Marshal(config)
if err != nil {
return err
}
requestString := string(requestJSON)
logrus.WithFields(computeSystem.logctx).
WithField(logfields.JSON, requestString).
Debug("HCS ComputeSystem Modify Document")
var resultp *uint16
syscallWatcher(computeSystem.logctx, func() {
err = hcsModifyComputeSystem(computeSystem.handle, requestString, &resultp)
})
events := processHcsResult(resultp)
if err != nil {
return makeSystemError(computeSystem, "Modify", requestString, err, events)
}
return nil
} | [
"func",
"(",
"computeSystem",
"*",
"System",
")",
"Modify",
"(",
"config",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"computeSystem",
".",
"handleLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"computeSystem",
".",
"handleLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"operation",
":=",
"\"",
"\"",
"\n",
"computeSystem",
".",
"logOperationBegin",
"(",
"operation",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"computeSystem",
".",
"logOperationEnd",
"(",
"operation",
",",
"err",
")",
"}",
"(",
")",
"\n\n",
"if",
"computeSystem",
".",
"handle",
"==",
"0",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrAlreadyClosed",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"requestJSON",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"requestString",
":=",
"string",
"(",
"requestJSON",
")",
"\n\n",
"logrus",
".",
"WithFields",
"(",
"computeSystem",
".",
"logctx",
")",
".",
"WithField",
"(",
"logfields",
".",
"JSON",
",",
"requestString",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"resultp",
"*",
"uint16",
"\n",
"syscallWatcher",
"(",
"computeSystem",
".",
"logctx",
",",
"func",
"(",
")",
"{",
"err",
"=",
"hcsModifyComputeSystem",
"(",
"computeSystem",
".",
"handle",
",",
"requestString",
",",
"&",
"resultp",
")",
"\n",
"}",
")",
"\n",
"events",
":=",
"processHcsResult",
"(",
"resultp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"makeSystemError",
"(",
"computeSystem",
",",
"\"",
"\"",
",",
"requestString",
",",
"err",
",",
"events",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Modify the System by sending a request to HCS | [
"Modify",
"the",
"System",
"by",
"sending",
"a",
"request",
"to",
"HCS"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/system.go#L663-L696 | train |
Microsoft/hcsshim | internal/wclayer/expandscratchsize.go | ExpandScratchSize | func ExpandScratchSize(path string, size uint64) (err error) {
title := "hcsshim::ExpandScratchSize"
fields := logrus.Fields{
"path": path,
"size": size,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = expandSandboxSize(&stdDriverInfo, path, size)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | go | func ExpandScratchSize(path string, size uint64) (err error) {
title := "hcsshim::ExpandScratchSize"
fields := logrus.Fields{
"path": path,
"size": size,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = expandSandboxSize(&stdDriverInfo, path, size)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | [
"func",
"ExpandScratchSize",
"(",
"path",
"string",
",",
"size",
"uint64",
")",
"(",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"path",
",",
"\"",
"\"",
":",
"size",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"expandSandboxSize",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"size",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ExpandScratchSize expands the size of a layer to at least size bytes. | [
"ExpandScratchSize",
"expands",
"the",
"size",
"of",
"a",
"layer",
"to",
"at",
"least",
"size",
"bytes",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/expandscratchsize.go#L9-L30 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | ListLoadBalancers | func ListLoadBalancers() ([]HostComputeLoadBalancer, error) {
hcnQuery := defaultQuery()
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
if err != nil {
return nil, err
}
return loadBalancers, nil
} | go | func ListLoadBalancers() ([]HostComputeLoadBalancer, error) {
hcnQuery := defaultQuery()
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
if err != nil {
return nil, err
}
return loadBalancers, nil
} | [
"func",
"ListLoadBalancers",
"(",
")",
"(",
"[",
"]",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"loadBalancers",
",",
"err",
":=",
"ListLoadBalancersQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"loadBalancers",
",",
"nil",
"\n",
"}"
] | // ListLoadBalancers makes a call to list all available loadBalancers. | [
"ListLoadBalancers",
"makes",
"a",
"call",
"to",
"list",
"all",
"available",
"loadBalancers",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L202-L209 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | ListLoadBalancersQuery | func ListLoadBalancersQuery(query HostComputeQuery) ([]HostComputeLoadBalancer, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
loadBalancers, err := enumerateLoadBalancers(string(queryJson))
if err != nil {
return nil, err
}
return loadBalancers, nil
} | go | func ListLoadBalancersQuery(query HostComputeQuery) ([]HostComputeLoadBalancer, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
loadBalancers, err := enumerateLoadBalancers(string(queryJson))
if err != nil {
return nil, err
}
return loadBalancers, nil
} | [
"func",
"ListLoadBalancersQuery",
"(",
"query",
"HostComputeQuery",
")",
"(",
"[",
"]",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"queryJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"loadBalancers",
",",
"err",
":=",
"enumerateLoadBalancers",
"(",
"string",
"(",
"queryJson",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"loadBalancers",
",",
"nil",
"\n",
"}"
] | // ListLoadBalancersQuery makes a call to query the list of available loadBalancers. | [
"ListLoadBalancersQuery",
"makes",
"a",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"loadBalancers",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L212-L223 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | GetLoadBalancerByID | func GetLoadBalancerByID(loadBalancerId string) (*HostComputeLoadBalancer, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": loadBalancerId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(loadBalancers) == 0 {
return nil, LoadBalancerNotFoundError{LoadBalancerId: loadBalancerId}
}
return &loadBalancers[0], err
} | go | func GetLoadBalancerByID(loadBalancerId string) (*HostComputeLoadBalancer, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": loadBalancerId}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
loadBalancers, err := ListLoadBalancersQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(loadBalancers) == 0 {
return nil, LoadBalancerNotFoundError{LoadBalancerId: loadBalancerId}
}
return &loadBalancers[0], err
} | [
"func",
"GetLoadBalancerByID",
"(",
"loadBalancerId",
"string",
")",
"(",
"*",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"loadBalancerId",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"loadBalancers",
",",
"err",
":=",
"ListLoadBalancersQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"loadBalancers",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"LoadBalancerNotFoundError",
"{",
"LoadBalancerId",
":",
"loadBalancerId",
"}",
"\n",
"}",
"\n",
"return",
"&",
"loadBalancers",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] | // GetLoadBalancerByID returns the LoadBalancer specified by Id. | [
"GetLoadBalancerByID",
"returns",
"the",
"LoadBalancer",
"specified",
"by",
"Id",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L226-L243 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | Create | func (loadBalancer *HostComputeLoadBalancer) Create() (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::Create id=%s", loadBalancer.Id)
jsonString, err := json.Marshal(loadBalancer)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeLoadBalancer::Create JSON: %s", jsonString)
loadBalancer, hcnErr := createLoadBalancer(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return loadBalancer, nil
} | go | func (loadBalancer *HostComputeLoadBalancer) Create() (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::Create id=%s", loadBalancer.Id)
jsonString, err := json.Marshal(loadBalancer)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeLoadBalancer::Create JSON: %s", jsonString)
loadBalancer, hcnErr := createLoadBalancer(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return loadBalancer, nil
} | [
"func",
"(",
"loadBalancer",
"*",
"HostComputeLoadBalancer",
")",
"Create",
"(",
")",
"(",
"*",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"loadBalancer",
".",
"Id",
")",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"loadBalancer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"jsonString",
")",
"\n",
"loadBalancer",
",",
"hcnErr",
":=",
"createLoadBalancer",
"(",
"string",
"(",
"jsonString",
")",
")",
"\n",
"if",
"hcnErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"hcnErr",
"\n",
"}",
"\n",
"return",
"loadBalancer",
",",
"nil",
"\n",
"}"
] | // Create LoadBalancer. | [
"Create",
"LoadBalancer",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L246-L260 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | Delete | func (loadBalancer *HostComputeLoadBalancer) Delete() error {
logrus.Debugf("hcn::HostComputeLoadBalancer::Delete id=%s", loadBalancer.Id)
if err := deleteLoadBalancer(loadBalancer.Id); err != nil {
return err
}
return nil
} | go | func (loadBalancer *HostComputeLoadBalancer) Delete() error {
logrus.Debugf("hcn::HostComputeLoadBalancer::Delete id=%s", loadBalancer.Id)
if err := deleteLoadBalancer(loadBalancer.Id); err != nil {
return err
}
return nil
} | [
"func",
"(",
"loadBalancer",
"*",
"HostComputeLoadBalancer",
")",
"Delete",
"(",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"loadBalancer",
".",
"Id",
")",
"\n\n",
"if",
"err",
":=",
"deleteLoadBalancer",
"(",
"loadBalancer",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete LoadBalancer. | [
"Delete",
"LoadBalancer",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L263-L270 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | AddEndpoint | func (loadBalancer *HostComputeLoadBalancer) AddEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::AddEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
err := loadBalancer.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
return loadBalancer.Create()
} | go | func (loadBalancer *HostComputeLoadBalancer) AddEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::AddEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
err := loadBalancer.Delete()
if err != nil {
return nil, err
}
// Add Endpoint to the Existing List
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
return loadBalancer.Create()
} | [
"func",
"(",
"loadBalancer",
"*",
"HostComputeLoadBalancer",
")",
"AddEndpoint",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"(",
"*",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"loadBalancer",
".",
"Id",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"err",
":=",
"loadBalancer",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add Endpoint to the Existing List",
"loadBalancer",
".",
"HostComputeEndpoints",
"=",
"append",
"(",
"loadBalancer",
".",
"HostComputeEndpoints",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"return",
"loadBalancer",
".",
"Create",
"(",
")",
"\n",
"}"
] | // AddEndpoint add an endpoint to a LoadBalancer | [
"AddEndpoint",
"add",
"an",
"endpoint",
"to",
"a",
"LoadBalancer"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L273-L285 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | RemoveEndpoint | func (loadBalancer *HostComputeLoadBalancer) RemoveEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::RemoveEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
err := loadBalancer.Delete()
if err != nil {
return nil, err
}
// Create a list of all the endpoints besides the one being removed
var endpoints []string
for _, endpointReference := range loadBalancer.HostComputeEndpoints {
if endpointReference == endpoint.Id {
continue
}
endpoints = append(endpoints, endpointReference)
}
loadBalancer.HostComputeEndpoints = endpoints
return loadBalancer.Create()
} | go | func (loadBalancer *HostComputeLoadBalancer) RemoveEndpoint(endpoint *HostComputeEndpoint) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::RemoveEndpoint loadBalancer=%s endpoint=%s", loadBalancer.Id, endpoint.Id)
err := loadBalancer.Delete()
if err != nil {
return nil, err
}
// Create a list of all the endpoints besides the one being removed
var endpoints []string
for _, endpointReference := range loadBalancer.HostComputeEndpoints {
if endpointReference == endpoint.Id {
continue
}
endpoints = append(endpoints, endpointReference)
}
loadBalancer.HostComputeEndpoints = endpoints
return loadBalancer.Create()
} | [
"func",
"(",
"loadBalancer",
"*",
"HostComputeLoadBalancer",
")",
"RemoveEndpoint",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"(",
"*",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"loadBalancer",
".",
"Id",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"err",
":=",
"loadBalancer",
".",
"Delete",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create a list of all the endpoints besides the one being removed",
"var",
"endpoints",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"endpointReference",
":=",
"range",
"loadBalancer",
".",
"HostComputeEndpoints",
"{",
"if",
"endpointReference",
"==",
"endpoint",
".",
"Id",
"{",
"continue",
"\n",
"}",
"\n",
"endpoints",
"=",
"append",
"(",
"endpoints",
",",
"endpointReference",
")",
"\n",
"}",
"\n",
"loadBalancer",
".",
"HostComputeEndpoints",
"=",
"endpoints",
"\n",
"return",
"loadBalancer",
".",
"Create",
"(",
")",
"\n",
"}"
] | // RemoveEndpoint removes an endpoint from a LoadBalancer | [
"RemoveEndpoint",
"removes",
"an",
"endpoint",
"from",
"a",
"LoadBalancer"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L288-L306 | train |
Microsoft/hcsshim | hcn/hcnloadbalancer.go | AddLoadBalancer | func AddLoadBalancer(endpoints []HostComputeEndpoint, flags LoadBalancerFlags, portMappingFlags LoadBalancerPortMappingFlags, sourceVIP string, frontendVIPs []string, protocol uint16, internalPort uint16, externalPort uint16) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::AddLoadBalancer endpointId=%v, LoadBalancerFlags=%v, LoadBalancerPortMappingFlags=%v, sourceVIP=%s, frontendVIPs=%v, protocol=%v, internalPort=%v, externalPort=%v", endpoints, flags, portMappingFlags, sourceVIP, frontendVIPs, protocol, internalPort, externalPort)
loadBalancer := &HostComputeLoadBalancer{
SourceVIP: sourceVIP,
PortMappings: []LoadBalancerPortMapping{
{
Protocol: uint32(protocol),
InternalPort: internalPort,
ExternalPort: externalPort,
Flags: portMappingFlags,
},
},
FrontendVIPs: frontendVIPs,
SchemaVersion: SchemaVersion{
Major: 2,
Minor: 0,
},
Flags: flags,
}
for _, endpoint := range endpoints {
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
}
return loadBalancer.Create()
} | go | func AddLoadBalancer(endpoints []HostComputeEndpoint, flags LoadBalancerFlags, portMappingFlags LoadBalancerPortMappingFlags, sourceVIP string, frontendVIPs []string, protocol uint16, internalPort uint16, externalPort uint16) (*HostComputeLoadBalancer, error) {
logrus.Debugf("hcn::HostComputeLoadBalancer::AddLoadBalancer endpointId=%v, LoadBalancerFlags=%v, LoadBalancerPortMappingFlags=%v, sourceVIP=%s, frontendVIPs=%v, protocol=%v, internalPort=%v, externalPort=%v", endpoints, flags, portMappingFlags, sourceVIP, frontendVIPs, protocol, internalPort, externalPort)
loadBalancer := &HostComputeLoadBalancer{
SourceVIP: sourceVIP,
PortMappings: []LoadBalancerPortMapping{
{
Protocol: uint32(protocol),
InternalPort: internalPort,
ExternalPort: externalPort,
Flags: portMappingFlags,
},
},
FrontendVIPs: frontendVIPs,
SchemaVersion: SchemaVersion{
Major: 2,
Minor: 0,
},
Flags: flags,
}
for _, endpoint := range endpoints {
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
}
return loadBalancer.Create()
} | [
"func",
"AddLoadBalancer",
"(",
"endpoints",
"[",
"]",
"HostComputeEndpoint",
",",
"flags",
"LoadBalancerFlags",
",",
"portMappingFlags",
"LoadBalancerPortMappingFlags",
",",
"sourceVIP",
"string",
",",
"frontendVIPs",
"[",
"]",
"string",
",",
"protocol",
"uint16",
",",
"internalPort",
"uint16",
",",
"externalPort",
"uint16",
")",
"(",
"*",
"HostComputeLoadBalancer",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoints",
",",
"flags",
",",
"portMappingFlags",
",",
"sourceVIP",
",",
"frontendVIPs",
",",
"protocol",
",",
"internalPort",
",",
"externalPort",
")",
"\n\n",
"loadBalancer",
":=",
"&",
"HostComputeLoadBalancer",
"{",
"SourceVIP",
":",
"sourceVIP",
",",
"PortMappings",
":",
"[",
"]",
"LoadBalancerPortMapping",
"{",
"{",
"Protocol",
":",
"uint32",
"(",
"protocol",
")",
",",
"InternalPort",
":",
"internalPort",
",",
"ExternalPort",
":",
"externalPort",
",",
"Flags",
":",
"portMappingFlags",
",",
"}",
",",
"}",
",",
"FrontendVIPs",
":",
"frontendVIPs",
",",
"SchemaVersion",
":",
"SchemaVersion",
"{",
"Major",
":",
"2",
",",
"Minor",
":",
"0",
",",
"}",
",",
"Flags",
":",
"flags",
",",
"}",
"\n\n",
"for",
"_",
",",
"endpoint",
":=",
"range",
"endpoints",
"{",
"loadBalancer",
".",
"HostComputeEndpoints",
"=",
"append",
"(",
"loadBalancer",
".",
"HostComputeEndpoints",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}",
"\n\n",
"return",
"loadBalancer",
".",
"Create",
"(",
")",
"\n",
"}"
] | // AddLoadBalancer for the specified endpoints | [
"AddLoadBalancer",
"for",
"the",
"specified",
"endpoints"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnloadbalancer.go#L309-L335 | train |
Microsoft/hcsshim | layer.go | CreateSandboxLayer | func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths)
} | go | func CreateSandboxLayer(info DriverInfo, layerId, parentId string, parentLayerPaths []string) error {
return wclayer.CreateScratchLayer(layerPath(&info, layerId), parentLayerPaths)
} | [
"func",
"CreateSandboxLayer",
"(",
"info",
"DriverInfo",
",",
"layerId",
",",
"parentId",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"wclayer",
".",
"CreateScratchLayer",
"(",
"layerPath",
"(",
"&",
"info",
",",
"layerId",
")",
",",
"parentLayerPaths",
")",
"\n",
"}"
] | // New clients should use CreateScratchLayer instead. Kept in to preserve API compatibility. | [
"New",
"clients",
"should",
"use",
"CreateScratchLayer",
"instead",
".",
"Kept",
"in",
"to",
"preserve",
"API",
"compatibility",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/layer.go#L23-L25 | train |
Microsoft/hcsshim | layer.go | ExpandSandboxSize | func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
return wclayer.ExpandScratchSize(layerPath(&info, layerId), size)
} | go | func ExpandSandboxSize(info DriverInfo, layerId string, size uint64) error {
return wclayer.ExpandScratchSize(layerPath(&info, layerId), size)
} | [
"func",
"ExpandSandboxSize",
"(",
"info",
"DriverInfo",
",",
"layerId",
"string",
",",
"size",
"uint64",
")",
"error",
"{",
"return",
"wclayer",
".",
"ExpandScratchSize",
"(",
"layerPath",
"(",
"&",
"info",
",",
"layerId",
")",
",",
"size",
")",
"\n",
"}"
] | // New clients should use ExpandScratchSize instead. Kept in to preserve API compatibility. | [
"New",
"clients",
"should",
"use",
"ExpandScratchSize",
"instead",
".",
"Kept",
"in",
"to",
"preserve",
"API",
"compatibility",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/layer.go#L37-L39 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | ListNamespaces | func ListNamespaces() ([]HostComputeNamespace, error) {
hcnQuery := defaultQuery()
namespaces, err := ListNamespacesQuery(hcnQuery)
if err != nil {
return nil, err
}
return namespaces, nil
} | go | func ListNamespaces() ([]HostComputeNamespace, error) {
hcnQuery := defaultQuery()
namespaces, err := ListNamespacesQuery(hcnQuery)
if err != nil {
return nil, err
}
return namespaces, nil
} | [
"func",
"ListNamespaces",
"(",
")",
"(",
"[",
"]",
"HostComputeNamespace",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"namespaces",
",",
"err",
":=",
"ListNamespacesQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"namespaces",
",",
"nil",
"\n",
"}"
] | // ListNamespaces makes a call to list all available namespaces. | [
"ListNamespaces",
"makes",
"a",
"call",
"to",
"list",
"all",
"available",
"namespaces",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L219-L226 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | ListNamespacesQuery | func ListNamespacesQuery(query HostComputeQuery) ([]HostComputeNamespace, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
namespaces, err := enumerateNamespaces(string(queryJson))
if err != nil {
return nil, err
}
return namespaces, nil
} | go | func ListNamespacesQuery(query HostComputeQuery) ([]HostComputeNamespace, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
namespaces, err := enumerateNamespaces(string(queryJson))
if err != nil {
return nil, err
}
return namespaces, nil
} | [
"func",
"ListNamespacesQuery",
"(",
"query",
"HostComputeQuery",
")",
"(",
"[",
"]",
"HostComputeNamespace",
",",
"error",
")",
"{",
"queryJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"namespaces",
",",
"err",
":=",
"enumerateNamespaces",
"(",
"string",
"(",
"queryJson",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"namespaces",
",",
"nil",
"\n",
"}"
] | // ListNamespacesQuery makes a call to query the list of available namespaces. | [
"ListNamespacesQuery",
"makes",
"a",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"namespaces",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L229-L240 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | GetNamespaceByID | func GetNamespaceByID(namespaceId string) (*HostComputeNamespace, error) {
return getNamespace(guid.FromString(namespaceId), defaultQueryJson())
} | go | func GetNamespaceByID(namespaceId string) (*HostComputeNamespace, error) {
return getNamespace(guid.FromString(namespaceId), defaultQueryJson())
} | [
"func",
"GetNamespaceByID",
"(",
"namespaceId",
"string",
")",
"(",
"*",
"HostComputeNamespace",
",",
"error",
")",
"{",
"return",
"getNamespace",
"(",
"guid",
".",
"FromString",
"(",
"namespaceId",
")",
",",
"defaultQueryJson",
"(",
")",
")",
"\n",
"}"
] | // GetNamespaceByID returns the Namespace specified by Id. | [
"GetNamespaceByID",
"returns",
"the",
"Namespace",
"specified",
"by",
"Id",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L243-L245 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | GetNamespaceEndpointIds | func GetNamespaceEndpointIds(namespaceId string) ([]string, error) {
namespace, err := GetNamespaceByID(namespaceId)
if err != nil {
return nil, err
}
var endpointsIds []string
for _, resource := range namespace.Resources {
if resource.Type == "Endpoint" {
var endpointResource NamespaceResourceEndpoint
if err := json.Unmarshal([]byte(resource.Data), &endpointResource); err != nil {
return nil, err
}
endpointsIds = append(endpointsIds, endpointResource.Id)
}
}
return endpointsIds, nil
} | go | func GetNamespaceEndpointIds(namespaceId string) ([]string, error) {
namespace, err := GetNamespaceByID(namespaceId)
if err != nil {
return nil, err
}
var endpointsIds []string
for _, resource := range namespace.Resources {
if resource.Type == "Endpoint" {
var endpointResource NamespaceResourceEndpoint
if err := json.Unmarshal([]byte(resource.Data), &endpointResource); err != nil {
return nil, err
}
endpointsIds = append(endpointsIds, endpointResource.Id)
}
}
return endpointsIds, nil
} | [
"func",
"GetNamespaceEndpointIds",
"(",
"namespaceId",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"namespace",
",",
"err",
":=",
"GetNamespaceByID",
"(",
"namespaceId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"endpointsIds",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"resource",
":=",
"range",
"namespace",
".",
"Resources",
"{",
"if",
"resource",
".",
"Type",
"==",
"\"",
"\"",
"{",
"var",
"endpointResource",
"NamespaceResourceEndpoint",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"resource",
".",
"Data",
")",
",",
"&",
"endpointResource",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"endpointsIds",
"=",
"append",
"(",
"endpointsIds",
",",
"endpointResource",
".",
"Id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"endpointsIds",
",",
"nil",
"\n",
"}"
] | // GetNamespaceEndpointIds returns the endpoints of the Namespace specified by Id. | [
"GetNamespaceEndpointIds",
"returns",
"the",
"endpoints",
"of",
"the",
"Namespace",
"specified",
"by",
"Id",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L248-L264 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | GetNamespaceContainerIds | func GetNamespaceContainerIds(namespaceId string) ([]string, error) {
namespace, err := GetNamespaceByID(namespaceId)
if err != nil {
return nil, err
}
var containerIds []string
for _, resource := range namespace.Resources {
if resource.Type == "Container" {
var contaienrResource NamespaceResourceContainer
if err := json.Unmarshal([]byte(resource.Data), &contaienrResource); err != nil {
return nil, err
}
containerIds = append(containerIds, contaienrResource.Id)
}
}
return containerIds, nil
} | go | func GetNamespaceContainerIds(namespaceId string) ([]string, error) {
namespace, err := GetNamespaceByID(namespaceId)
if err != nil {
return nil, err
}
var containerIds []string
for _, resource := range namespace.Resources {
if resource.Type == "Container" {
var contaienrResource NamespaceResourceContainer
if err := json.Unmarshal([]byte(resource.Data), &contaienrResource); err != nil {
return nil, err
}
containerIds = append(containerIds, contaienrResource.Id)
}
}
return containerIds, nil
} | [
"func",
"GetNamespaceContainerIds",
"(",
"namespaceId",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"namespace",
",",
"err",
":=",
"GetNamespaceByID",
"(",
"namespaceId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"containerIds",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"resource",
":=",
"range",
"namespace",
".",
"Resources",
"{",
"if",
"resource",
".",
"Type",
"==",
"\"",
"\"",
"{",
"var",
"contaienrResource",
"NamespaceResourceContainer",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"resource",
".",
"Data",
")",
",",
"&",
"contaienrResource",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"containerIds",
"=",
"append",
"(",
"containerIds",
",",
"contaienrResource",
".",
"Id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"containerIds",
",",
"nil",
"\n",
"}"
] | // GetNamespaceContainerIds returns the containers of the Namespace specified by Id. | [
"GetNamespaceContainerIds",
"returns",
"the",
"containers",
"of",
"the",
"Namespace",
"specified",
"by",
"Id",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L267-L283 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | Create | func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) {
logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id)
jsonString, err := json.Marshal(namespace)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeNamespace::Create JSON: %s", jsonString)
namespace, hcnErr := createNamespace(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return namespace, nil
} | go | func (namespace *HostComputeNamespace) Create() (*HostComputeNamespace, error) {
logrus.Debugf("hcn::HostComputeNamespace::Create id=%s", namespace.Id)
jsonString, err := json.Marshal(namespace)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeNamespace::Create JSON: %s", jsonString)
namespace, hcnErr := createNamespace(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return namespace, nil
} | [
"func",
"(",
"namespace",
"*",
"HostComputeNamespace",
")",
"Create",
"(",
")",
"(",
"*",
"HostComputeNamespace",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"namespace",
".",
"Id",
")",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"namespace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"jsonString",
")",
"\n",
"namespace",
",",
"hcnErr",
":=",
"createNamespace",
"(",
"string",
"(",
"jsonString",
")",
")",
"\n",
"if",
"hcnErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"hcnErr",
"\n",
"}",
"\n",
"return",
"namespace",
",",
"nil",
"\n",
"}"
] | // Create Namespace. | [
"Create",
"Namespace",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L294-L308 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | Delete | func (namespace *HostComputeNamespace) Delete() error {
logrus.Debugf("hcn::HostComputeNamespace::Delete id=%s", namespace.Id)
if err := deleteNamespace(namespace.Id); err != nil {
return err
}
return nil
} | go | func (namespace *HostComputeNamespace) Delete() error {
logrus.Debugf("hcn::HostComputeNamespace::Delete id=%s", namespace.Id)
if err := deleteNamespace(namespace.Id); err != nil {
return err
}
return nil
} | [
"func",
"(",
"namespace",
"*",
"HostComputeNamespace",
")",
"Delete",
"(",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"namespace",
".",
"Id",
")",
"\n\n",
"if",
"err",
":=",
"deleteNamespace",
"(",
"namespace",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete Namespace. | [
"Delete",
"Namespace",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L311-L318 | train |
Microsoft/hcsshim | hcn/hcnnamespace.go | AddNamespaceEndpoint | func AddNamespaceEndpoint(namespaceId string, endpointId string) error {
logrus.Debugf("hcn::HostComputeEndpoint::AddNamespaceEndpoint id=%s", endpointId)
mapA := map[string]string{"EndpointId": endpointId}
settingsJson, err := json.Marshal(mapA)
if err != nil {
return err
}
requestMessage := &ModifyNamespaceSettingRequest{
ResourceType: NamespaceResourceTypeEndpoint,
RequestType: RequestTypeAdd,
Settings: settingsJson,
}
return ModifyNamespaceSettings(namespaceId, requestMessage)
} | go | func AddNamespaceEndpoint(namespaceId string, endpointId string) error {
logrus.Debugf("hcn::HostComputeEndpoint::AddNamespaceEndpoint id=%s", endpointId)
mapA := map[string]string{"EndpointId": endpointId}
settingsJson, err := json.Marshal(mapA)
if err != nil {
return err
}
requestMessage := &ModifyNamespaceSettingRequest{
ResourceType: NamespaceResourceTypeEndpoint,
RequestType: RequestTypeAdd,
Settings: settingsJson,
}
return ModifyNamespaceSettings(namespaceId, requestMessage)
} | [
"func",
"AddNamespaceEndpoint",
"(",
"namespaceId",
"string",
",",
"endpointId",
"string",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpointId",
")",
"\n\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"endpointId",
"}",
"\n",
"settingsJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"requestMessage",
":=",
"&",
"ModifyNamespaceSettingRequest",
"{",
"ResourceType",
":",
"NamespaceResourceTypeEndpoint",
",",
"RequestType",
":",
"RequestTypeAdd",
",",
"Settings",
":",
"settingsJson",
",",
"}",
"\n\n",
"return",
"ModifyNamespaceSettings",
"(",
"namespaceId",
",",
"requestMessage",
")",
"\n",
"}"
] | // AddNamespaceEndpoint adds an endpoint to a Namespace. | [
"AddNamespaceEndpoint",
"adds",
"an",
"endpoint",
"to",
"a",
"Namespace",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnamespace.go#L391-L406 | train |
Microsoft/hcsshim | internal/oci/util.go | IsIsolated | func IsIsolated(s *specs.Spec) bool {
return IsLCOW(s) || (s.Windows != nil && s.Windows.HyperV != nil)
} | go | func IsIsolated(s *specs.Spec) bool {
return IsLCOW(s) || (s.Windows != nil && s.Windows.HyperV != nil)
} | [
"func",
"IsIsolated",
"(",
"s",
"*",
"specs",
".",
"Spec",
")",
"bool",
"{",
"return",
"IsLCOW",
"(",
"s",
")",
"||",
"(",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"HyperV",
"!=",
"nil",
")",
"\n",
"}"
] | // IsIsolated checks if `s` is hypervisor isolated. | [
"IsIsolated",
"checks",
"if",
"s",
"is",
"hypervisor",
"isolated",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/util.go#L16-L18 | train |
Microsoft/hcsshim | internal/ociwclayer/import.go | ImportLayer | func ImportLayer(r io.Reader, path string, parentLayerPaths []string) (int64, error) {
err := os.MkdirAll(path, 0)
if err != nil {
return 0, err
}
w, err := hcsshim.NewLayerWriter(hcsshim.DriverInfo{}, path, parentLayerPaths)
if err != nil {
return 0, err
}
n, err := writeLayerFromTar(r, w, path)
cerr := w.Close()
if err != nil {
return 0, err
}
if cerr != nil {
return 0, cerr
}
return n, nil
} | go | func ImportLayer(r io.Reader, path string, parentLayerPaths []string) (int64, error) {
err := os.MkdirAll(path, 0)
if err != nil {
return 0, err
}
w, err := hcsshim.NewLayerWriter(hcsshim.DriverInfo{}, path, parentLayerPaths)
if err != nil {
return 0, err
}
n, err := writeLayerFromTar(r, w, path)
cerr := w.Close()
if err != nil {
return 0, err
}
if cerr != nil {
return 0, cerr
}
return n, nil
} | [
"func",
"ImportLayer",
"(",
"r",
"io",
".",
"Reader",
",",
"path",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"path",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"w",
",",
"err",
":=",
"hcsshim",
".",
"NewLayerWriter",
"(",
"hcsshim",
".",
"DriverInfo",
"{",
"}",
",",
"path",
",",
"parentLayerPaths",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"writeLayerFromTar",
"(",
"r",
",",
"w",
",",
"path",
")",
"\n",
"cerr",
":=",
"w",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"cerr",
"!=",
"nil",
"{",
"return",
"0",
",",
"cerr",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // ImportLayer reads a layer from an OCI layer tar stream and extracts it to the
// specified path. The caller must specify the parent layers, if any, ordered
// from lowest to highest layer.
//
// The caller must ensure that the thread or process has acquired backup and
// restore privileges.
//
// This function returns the total size of the layer's files, in bytes. | [
"ImportLayer",
"reads",
"a",
"layer",
"from",
"an",
"OCI",
"layer",
"tar",
"stream",
"and",
"extracts",
"it",
"to",
"the",
"specified",
"path",
".",
"The",
"caller",
"must",
"specify",
"the",
"parent",
"layers",
"if",
"any",
"ordered",
"from",
"lowest",
"to",
"highest",
"layer",
".",
"The",
"caller",
"must",
"ensure",
"that",
"the",
"thread",
"or",
"process",
"has",
"acquired",
"backup",
"and",
"restore",
"privileges",
".",
"This",
"function",
"returns",
"the",
"total",
"size",
"of",
"the",
"layer",
"s",
"files",
"in",
"bytes",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/ociwclayer/import.go#L38-L56 | train |
Microsoft/hcsshim | internal/lcow/tar2vhd.go | TarToVhd | func TarToVhd(lcowUVM *uvm.UtilityVM, targetVHDFile string, reader io.Reader) (int64, error) {
logrus.Debugf("hcsshim: TarToVhd: %s", targetVHDFile)
if lcowUVM == nil {
return 0, fmt.Errorf("no utility VM passed")
}
//defer uvm.DebugLCOWGCS()
outFile, err := os.Create(targetVHDFile)
if err != nil {
return 0, fmt.Errorf("tar2vhd failed to create %s: %s", targetVHDFile, err)
}
defer outFile.Close()
// BUGBUG Delete the file on failure
tar2vhd, byteCounts, err := CreateProcess(&ProcessOptions{
HCSSystem: lcowUVM.ComputeSystem(),
Process: &specs.Process{Args: []string{"tar2vhd"}},
CreateInUtilityVm: true,
Stdin: reader,
Stdout: outFile,
CopyTimeout: 2 * time.Minute,
})
if err != nil {
return 0, fmt.Errorf("failed to start tar2vhd for %s: %s", targetVHDFile, err)
}
defer tar2vhd.Close()
logrus.Debugf("hcsshim: TarToVhd: %s created, %d bytes", targetVHDFile, byteCounts.Out)
return byteCounts.Out, err
} | go | func TarToVhd(lcowUVM *uvm.UtilityVM, targetVHDFile string, reader io.Reader) (int64, error) {
logrus.Debugf("hcsshim: TarToVhd: %s", targetVHDFile)
if lcowUVM == nil {
return 0, fmt.Errorf("no utility VM passed")
}
//defer uvm.DebugLCOWGCS()
outFile, err := os.Create(targetVHDFile)
if err != nil {
return 0, fmt.Errorf("tar2vhd failed to create %s: %s", targetVHDFile, err)
}
defer outFile.Close()
// BUGBUG Delete the file on failure
tar2vhd, byteCounts, err := CreateProcess(&ProcessOptions{
HCSSystem: lcowUVM.ComputeSystem(),
Process: &specs.Process{Args: []string{"tar2vhd"}},
CreateInUtilityVm: true,
Stdin: reader,
Stdout: outFile,
CopyTimeout: 2 * time.Minute,
})
if err != nil {
return 0, fmt.Errorf("failed to start tar2vhd for %s: %s", targetVHDFile, err)
}
defer tar2vhd.Close()
logrus.Debugf("hcsshim: TarToVhd: %s created, %d bytes", targetVHDFile, byteCounts.Out)
return byteCounts.Out, err
} | [
"func",
"TarToVhd",
"(",
"lcowUVM",
"*",
"uvm",
".",
"UtilityVM",
",",
"targetVHDFile",
"string",
",",
"reader",
"io",
".",
"Reader",
")",
"(",
"int64",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"targetVHDFile",
")",
"\n\n",
"if",
"lcowUVM",
"==",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"//defer uvm.DebugLCOWGCS()",
"outFile",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"targetVHDFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"targetVHDFile",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"outFile",
".",
"Close",
"(",
")",
"\n",
"// BUGBUG Delete the file on failure",
"tar2vhd",
",",
"byteCounts",
",",
"err",
":=",
"CreateProcess",
"(",
"&",
"ProcessOptions",
"{",
"HCSSystem",
":",
"lcowUVM",
".",
"ComputeSystem",
"(",
")",
",",
"Process",
":",
"&",
"specs",
".",
"Process",
"{",
"Args",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"}",
",",
"CreateInUtilityVm",
":",
"true",
",",
"Stdin",
":",
"reader",
",",
"Stdout",
":",
"outFile",
",",
"CopyTimeout",
":",
"2",
"*",
"time",
".",
"Minute",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"targetVHDFile",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"tar2vhd",
".",
"Close",
"(",
")",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"targetVHDFile",
",",
"byteCounts",
".",
"Out",
")",
"\n",
"return",
"byteCounts",
".",
"Out",
",",
"err",
"\n",
"}"
] | // TarToVhd streams a tarstream contained in an io.Reader to a fixed vhd file | [
"TarToVhd",
"streams",
"a",
"tarstream",
"contained",
"in",
"an",
"io",
".",
"Reader",
"to",
"a",
"fixed",
"vhd",
"file"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/lcow/tar2vhd.go#L15-L46 | train |
Microsoft/hcsshim | internal/uvm/network.go | AddNetNS | func (uvm *UtilityVM) AddNetNS(id string) (err error) {
op := "uvm::AddNetNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if _, ok := uvm.namespaces[id]; ok {
return ErrNetNSAlreadyAttached
}
if uvm.isNetworkNamespaceSupported() {
// Add a Guest Network namespace. On LCOW we add the adapters
// dynamically.
if uvm.operatingSystem == "windows" {
hcnNamespace, err := hcn.GetNamespaceByID(id)
if err != nil {
return err
}
guestNamespace := hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeNetworkNamespace,
RequestType: requesttype.Add,
Settings: hcnNamespace,
},
}
if err := uvm.Modify(&guestNamespace); err != nil {
return err
}
}
}
if uvm.namespaces == nil {
uvm.namespaces = make(map[string]*namespaceInfo)
}
uvm.namespaces[id] = &namespaceInfo{
nics: make(map[string]*nicInfo),
}
return nil
} | go | func (uvm *UtilityVM) AddNetNS(id string) (err error) {
op := "uvm::AddNetNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if _, ok := uvm.namespaces[id]; ok {
return ErrNetNSAlreadyAttached
}
if uvm.isNetworkNamespaceSupported() {
// Add a Guest Network namespace. On LCOW we add the adapters
// dynamically.
if uvm.operatingSystem == "windows" {
hcnNamespace, err := hcn.GetNamespaceByID(id)
if err != nil {
return err
}
guestNamespace := hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeNetworkNamespace,
RequestType: requesttype.Add,
Settings: hcnNamespace,
},
}
if err := uvm.Modify(&guestNamespace); err != nil {
return err
}
}
}
if uvm.namespaces == nil {
uvm.namespaces = make(map[string]*namespaceInfo)
}
uvm.namespaces[id] = &namespaceInfo{
nics: make(map[string]*nicInfo),
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"AddNetNS",
"(",
"id",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"uvm",
".",
"namespaces",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"ErrNetNSAlreadyAttached",
"\n",
"}",
"\n\n",
"if",
"uvm",
".",
"isNetworkNamespaceSupported",
"(",
")",
"{",
"// Add a Guest Network namespace. On LCOW we add the adapters",
"// dynamically.",
"if",
"uvm",
".",
"operatingSystem",
"==",
"\"",
"\"",
"{",
"hcnNamespace",
",",
"err",
":=",
"hcn",
".",
"GetNamespaceByID",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"guestNamespace",
":=",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"GuestRequest",
":",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeNetworkNamespace",
",",
"RequestType",
":",
"requesttype",
".",
"Add",
",",
"Settings",
":",
"hcnNamespace",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"&",
"guestNamespace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"uvm",
".",
"namespaces",
"==",
"nil",
"{",
"uvm",
".",
"namespaces",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"namespaceInfo",
")",
"\n",
"}",
"\n",
"uvm",
".",
"namespaces",
"[",
"id",
"]",
"=",
"&",
"namespaceInfo",
"{",
"nics",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"nicInfo",
")",
",",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // AddNetNS adds network namespace inside the guest.
//
// If a namespace with `id` already exists returns `ErrNetNSAlreadyAttached`. | [
"AddNetNS",
"adds",
"network",
"namespace",
"inside",
"the",
"guest",
".",
"If",
"a",
"namespace",
"with",
"id",
"already",
"exists",
"returns",
"ErrNetNSAlreadyAttached",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/network.go#L32-L82 | train |
Microsoft/hcsshim | internal/uvm/network.go | AddEndpointsToNS | func (uvm *UtilityVM) AddEndpointsToNS(id string, endpoints []*hns.HNSEndpoint) (err error) {
op := "uvm::AddEndpointsToNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
ns, ok := uvm.namespaces[id]
if !ok {
return ErrNetNSNotFound
}
for _, endpoint := range endpoints {
if _, ok := ns.nics[endpoint.Id]; !ok {
nicID := guid.New()
if err := uvm.addNIC(nicID, endpoint); err != nil {
return err
}
ns.nics[endpoint.Id] = &nicInfo{
ID: nicID,
Endpoint: endpoint,
}
}
}
return nil
} | go | func (uvm *UtilityVM) AddEndpointsToNS(id string, endpoints []*hns.HNSEndpoint) (err error) {
op := "uvm::AddEndpointsToNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
ns, ok := uvm.namespaces[id]
if !ok {
return ErrNetNSNotFound
}
for _, endpoint := range endpoints {
if _, ok := ns.nics[endpoint.Id]; !ok {
nicID := guid.New()
if err := uvm.addNIC(nicID, endpoint); err != nil {
return err
}
ns.nics[endpoint.Id] = &nicInfo{
ID: nicID,
Endpoint: endpoint,
}
}
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"AddEndpointsToNS",
"(",
"id",
"string",
",",
"endpoints",
"[",
"]",
"*",
"hns",
".",
"HNSEndpoint",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"ns",
",",
"ok",
":=",
"uvm",
".",
"namespaces",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ErrNetNSNotFound",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"endpoint",
":=",
"range",
"endpoints",
"{",
"if",
"_",
",",
"ok",
":=",
"ns",
".",
"nics",
"[",
"endpoint",
".",
"Id",
"]",
";",
"!",
"ok",
"{",
"nicID",
":=",
"guid",
".",
"New",
"(",
")",
"\n",
"if",
"err",
":=",
"uvm",
".",
"addNIC",
"(",
"nicID",
",",
"endpoint",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ns",
".",
"nics",
"[",
"endpoint",
".",
"Id",
"]",
"=",
"&",
"nicInfo",
"{",
"ID",
":",
"nicID",
",",
"Endpoint",
":",
"endpoint",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // AddEndpointsToNS adds all unique `endpoints` to the network namespace
// matching `id`. On failure does not roll back any previously successfully
// added endpoints.
//
// If no network namespace matches `id` returns `ErrNetNSNotFound`. | [
"AddEndpointsToNS",
"adds",
"all",
"unique",
"endpoints",
"to",
"the",
"network",
"namespace",
"matching",
"id",
".",
"On",
"failure",
"does",
"not",
"roll",
"back",
"any",
"previously",
"successfully",
"added",
"endpoints",
".",
"If",
"no",
"network",
"namespace",
"matches",
"id",
"returns",
"ErrNetNSNotFound",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/network.go#L89-L126 | train |
Microsoft/hcsshim | internal/uvm/network.go | RemoveNetNS | func (uvm *UtilityVM) RemoveNetNS(id string) (err error) {
op := "uvm::RemoveNetNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if ns, ok := uvm.namespaces[id]; ok {
for _, ninfo := range ns.nics {
if err := uvm.removeNIC(ninfo.ID, ninfo.Endpoint); err != nil {
return err
}
ns.nics[ninfo.Endpoint.Id] = nil
}
// Remove the Guest Network namespace
if uvm.isNetworkNamespaceSupported() {
if uvm.operatingSystem == "windows" {
hcnNamespace, err := hcn.GetNamespaceByID(id)
if err != nil {
return err
}
guestNamespace := hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeNetworkNamespace,
RequestType: requesttype.Remove,
Settings: hcnNamespace,
},
}
if err := uvm.Modify(&guestNamespace); err != nil {
return err
}
}
}
delete(uvm.namespaces, id)
}
return nil
} | go | func (uvm *UtilityVM) RemoveNetNS(id string) (err error) {
op := "uvm::RemoveNetNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
if ns, ok := uvm.namespaces[id]; ok {
for _, ninfo := range ns.nics {
if err := uvm.removeNIC(ninfo.ID, ninfo.Endpoint); err != nil {
return err
}
ns.nics[ninfo.Endpoint.Id] = nil
}
// Remove the Guest Network namespace
if uvm.isNetworkNamespaceSupported() {
if uvm.operatingSystem == "windows" {
hcnNamespace, err := hcn.GetNamespaceByID(id)
if err != nil {
return err
}
guestNamespace := hcsschema.ModifySettingRequest{
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeNetworkNamespace,
RequestType: requesttype.Remove,
Settings: hcnNamespace,
},
}
if err := uvm.Modify(&guestNamespace); err != nil {
return err
}
}
}
delete(uvm.namespaces, id)
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveNetNS",
"(",
"id",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"if",
"ns",
",",
"ok",
":=",
"uvm",
".",
"namespaces",
"[",
"id",
"]",
";",
"ok",
"{",
"for",
"_",
",",
"ninfo",
":=",
"range",
"ns",
".",
"nics",
"{",
"if",
"err",
":=",
"uvm",
".",
"removeNIC",
"(",
"ninfo",
".",
"ID",
",",
"ninfo",
".",
"Endpoint",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ns",
".",
"nics",
"[",
"ninfo",
".",
"Endpoint",
".",
"Id",
"]",
"=",
"nil",
"\n",
"}",
"\n",
"// Remove the Guest Network namespace",
"if",
"uvm",
".",
"isNetworkNamespaceSupported",
"(",
")",
"{",
"if",
"uvm",
".",
"operatingSystem",
"==",
"\"",
"\"",
"{",
"hcnNamespace",
",",
"err",
":=",
"hcn",
".",
"GetNamespaceByID",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"guestNamespace",
":=",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"GuestRequest",
":",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeNetworkNamespace",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"hcnNamespace",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"&",
"guestNamespace",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"delete",
"(",
"uvm",
".",
"namespaces",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemoveNetNS removes the namespace from the uvm and all remaining endpoints in
// the namespace.
//
// If a namespace matching `id` is not found this command silently succeeds. | [
"RemoveNetNS",
"removes",
"the",
"namespace",
"from",
"the",
"uvm",
"and",
"all",
"remaining",
"endpoints",
"in",
"the",
"namespace",
".",
"If",
"a",
"namespace",
"matching",
"id",
"is",
"not",
"found",
"this",
"command",
"silently",
"succeeds",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/network.go#L132-L179 | train |
Microsoft/hcsshim | internal/uvm/network.go | RemoveEndpointsFromNS | func (uvm *UtilityVM) RemoveEndpointsFromNS(id string, endpoints []*hns.HNSEndpoint) (err error) {
op := "uvm::RemoveEndpointsFromNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
ns, ok := uvm.namespaces[id]
if !ok {
return ErrNetNSNotFound
}
for _, endpoint := range endpoints {
if ninfo, ok := ns.nics[endpoint.Id]; ok && ninfo != nil {
if err := uvm.removeNIC(ninfo.ID, ninfo.Endpoint); err != nil {
return err
}
delete(ns.nics, endpoint.Id)
}
}
return nil
} | go | func (uvm *UtilityVM) RemoveEndpointsFromNS(id string, endpoints []*hns.HNSEndpoint) (err error) {
op := "uvm::RemoveEndpointsFromNS"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"netns-id": id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.m.Lock()
defer uvm.m.Unlock()
ns, ok := uvm.namespaces[id]
if !ok {
return ErrNetNSNotFound
}
for _, endpoint := range endpoints {
if ninfo, ok := ns.nics[endpoint.Id]; ok && ninfo != nil {
if err := uvm.removeNIC(ninfo.ID, ninfo.Endpoint); err != nil {
return err
}
delete(ns.nics, endpoint.Id)
}
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveEndpointsFromNS",
"(",
"id",
"string",
",",
"endpoints",
"[",
"]",
"*",
"hns",
".",
"HNSEndpoint",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"ns",
",",
"ok",
":=",
"uvm",
".",
"namespaces",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ErrNetNSNotFound",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"endpoint",
":=",
"range",
"endpoints",
"{",
"if",
"ninfo",
",",
"ok",
":=",
"ns",
".",
"nics",
"[",
"endpoint",
".",
"Id",
"]",
";",
"ok",
"&&",
"ninfo",
"!=",
"nil",
"{",
"if",
"err",
":=",
"uvm",
".",
"removeNIC",
"(",
"ninfo",
".",
"ID",
",",
"ninfo",
".",
"Endpoint",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"delete",
"(",
"ns",
".",
"nics",
",",
"endpoint",
".",
"Id",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemoveEndpointsFromNS removes all matching `endpoints` in the network
// namespace matching `id`. If no endpoint matching `endpoint.Id` is found in
// the network namespace this command silently succeeds.
//
// If no network namespace matches `id` returns `ErrNetNSNotFound`. | [
"RemoveEndpointsFromNS",
"removes",
"all",
"matching",
"endpoints",
"in",
"the",
"network",
"namespace",
"matching",
"id",
".",
"If",
"no",
"endpoint",
"matching",
"endpoint",
".",
"Id",
"is",
"found",
"in",
"the",
"network",
"namespace",
"this",
"command",
"silently",
"succeeds",
".",
"If",
"no",
"network",
"namespace",
"matches",
"id",
"returns",
"ErrNetNSNotFound",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/network.go#L186-L219 | train |
Microsoft/hcsshim | internal/uvm/network.go | isNetworkNamespaceSupported | func (uvm *UtilityVM) isNetworkNamespaceSupported() bool {
p, err := uvm.ComputeSystem().Properties(schema1.PropertyTypeGuestConnection)
if err == nil {
return p.GuestConnectionInfo.GuestDefinedCapabilities.NamespaceAddRequestSupported
}
return false
} | go | func (uvm *UtilityVM) isNetworkNamespaceSupported() bool {
p, err := uvm.ComputeSystem().Properties(schema1.PropertyTypeGuestConnection)
if err == nil {
return p.GuestConnectionInfo.GuestDefinedCapabilities.NamespaceAddRequestSupported
}
return false
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"isNetworkNamespaceSupported",
"(",
")",
"bool",
"{",
"p",
",",
"err",
":=",
"uvm",
".",
"ComputeSystem",
"(",
")",
".",
"Properties",
"(",
"schema1",
".",
"PropertyTypeGuestConnection",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"p",
".",
"GuestConnectionInfo",
".",
"GuestDefinedCapabilities",
".",
"NamespaceAddRequestSupported",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // IsNetworkNamespaceSupported returns bool value specifying if network namespace is supported inside the guest | [
"IsNetworkNamespaceSupported",
"returns",
"bool",
"value",
"specifying",
"if",
"network",
"namespace",
"is",
"supported",
"inside",
"the",
"guest"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/network.go#L222-L229 | train |
Microsoft/hcsshim | internal/hcs/utils.go | makeOpenFiles | func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
fs := make([]io.ReadWriteCloser, len(hs))
for i, h := range hs {
if h != syscall.Handle(0) {
if err == nil {
fs[i], err = winio.MakeOpenFile(h)
}
if err != nil {
syscall.Close(h)
}
}
}
if err != nil {
for _, f := range fs {
if f != nil {
f.Close()
}
}
return nil, err
}
return fs, nil
} | go | func makeOpenFiles(hs []syscall.Handle) (_ []io.ReadWriteCloser, err error) {
fs := make([]io.ReadWriteCloser, len(hs))
for i, h := range hs {
if h != syscall.Handle(0) {
if err == nil {
fs[i], err = winio.MakeOpenFile(h)
}
if err != nil {
syscall.Close(h)
}
}
}
if err != nil {
for _, f := range fs {
if f != nil {
f.Close()
}
}
return nil, err
}
return fs, nil
} | [
"func",
"makeOpenFiles",
"(",
"hs",
"[",
"]",
"syscall",
".",
"Handle",
")",
"(",
"_",
"[",
"]",
"io",
".",
"ReadWriteCloser",
",",
"err",
"error",
")",
"{",
"fs",
":=",
"make",
"(",
"[",
"]",
"io",
".",
"ReadWriteCloser",
",",
"len",
"(",
"hs",
")",
")",
"\n",
"for",
"i",
",",
"h",
":=",
"range",
"hs",
"{",
"if",
"h",
"!=",
"syscall",
".",
"Handle",
"(",
"0",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"fs",
"[",
"i",
"]",
",",
"err",
"=",
"winio",
".",
"MakeOpenFile",
"(",
"h",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"h",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"fs",
"{",
"if",
"f",
"!=",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"fs",
",",
"nil",
"\n",
"}"
] | // makeOpenFiles calls winio.MakeOpenFile for each handle in a slice but closes all the handles
// if there is an error. | [
"makeOpenFiles",
"calls",
"winio",
".",
"MakeOpenFile",
"for",
"each",
"handle",
"in",
"a",
"slice",
"but",
"closes",
"all",
"the",
"handles",
"if",
"there",
"is",
"an",
"error",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcs/utils.go#L12-L33 | train |
Microsoft/hcsshim | internal/uvm/plan9.go | AddPlan9 | func (uvm *UtilityVM) AddPlan9(hostPath string, uvmPath string, readOnly bool, restrict bool, allowedNames []string) (_ *Plan9Share, err error) {
op := "uvm::AddPlan9"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"readOnly": readOnly,
"restrict": restrict,
"allowedNames": allowedNames,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return nil, errNotSupported
}
if restrict && osversion.Get().Build < 18328 {
return nil, errors.New("single-file mappings are not supported on this build of Windows")
}
if uvmPath == "" {
return nil, fmt.Errorf("uvmPath must be passed to AddPlan9")
}
// TODO: JTERRY75 - These are marked private in the schema. For now use them
// but when there are public variants we need to switch to them.
const (
shareFlagsReadOnly int32 = 0x00000001
shareFlagsLinuxMetadata int32 = 0x00000004
shareFlagsCaseSensitive int32 = 0x00000008
shareFlagsRestrictFileAccess int32 = 0x00000080
)
// TODO: JTERRY75 - `shareFlagsCaseSensitive` only works if the Windows
// `hostPath` supports case sensitivity. We need to detect this case before
// forwarding this flag in all cases.
flags := shareFlagsLinuxMetadata // | shareFlagsCaseSensitive
if readOnly {
flags |= shareFlagsReadOnly
}
if restrict {
flags |= shareFlagsRestrictFileAccess
}
uvm.m.Lock()
index := uvm.plan9Counter
uvm.plan9Counter++
uvm.m.Unlock()
name := strconv.FormatUint(index, 10)
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Add,
Settings: hcsschema.Plan9Share{
Name: name,
AccessName: name,
Path: hostPath,
Port: plan9Port,
Flags: flags,
AllowedFiles: allowedNames,
},
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Plan9/Shares"),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedDirectory,
RequestType: requesttype.Add,
Settings: guestrequest.LCOWMappedDirectory{
MountPath: uvmPath,
ShareName: name,
Port: plan9Port,
ReadOnly: readOnly,
},
},
}
if err := uvm.Modify(modification); err != nil {
return nil, err
}
share := &Plan9Share{name: name, uvmPath: uvmPath}
return share, nil
} | go | func (uvm *UtilityVM) AddPlan9(hostPath string, uvmPath string, readOnly bool, restrict bool, allowedNames []string) (_ *Plan9Share, err error) {
op := "uvm::AddPlan9"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
"uvm-path": uvmPath,
"readOnly": readOnly,
"restrict": restrict,
"allowedNames": allowedNames,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return nil, errNotSupported
}
if restrict && osversion.Get().Build < 18328 {
return nil, errors.New("single-file mappings are not supported on this build of Windows")
}
if uvmPath == "" {
return nil, fmt.Errorf("uvmPath must be passed to AddPlan9")
}
// TODO: JTERRY75 - These are marked private in the schema. For now use them
// but when there are public variants we need to switch to them.
const (
shareFlagsReadOnly int32 = 0x00000001
shareFlagsLinuxMetadata int32 = 0x00000004
shareFlagsCaseSensitive int32 = 0x00000008
shareFlagsRestrictFileAccess int32 = 0x00000080
)
// TODO: JTERRY75 - `shareFlagsCaseSensitive` only works if the Windows
// `hostPath` supports case sensitivity. We need to detect this case before
// forwarding this flag in all cases.
flags := shareFlagsLinuxMetadata // | shareFlagsCaseSensitive
if readOnly {
flags |= shareFlagsReadOnly
}
if restrict {
flags |= shareFlagsRestrictFileAccess
}
uvm.m.Lock()
index := uvm.plan9Counter
uvm.plan9Counter++
uvm.m.Unlock()
name := strconv.FormatUint(index, 10)
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Add,
Settings: hcsschema.Plan9Share{
Name: name,
AccessName: name,
Path: hostPath,
Port: plan9Port,
Flags: flags,
AllowedFiles: allowedNames,
},
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Plan9/Shares"),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedDirectory,
RequestType: requesttype.Add,
Settings: guestrequest.LCOWMappedDirectory{
MountPath: uvmPath,
ShareName: name,
Port: plan9Port,
ReadOnly: readOnly,
},
},
}
if err := uvm.Modify(modification); err != nil {
return nil, err
}
share := &Plan9Share{name: name, uvmPath: uvmPath}
return share, nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"AddPlan9",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"readOnly",
"bool",
",",
"restrict",
"bool",
",",
"allowedNames",
"[",
"]",
"string",
")",
"(",
"_",
"*",
"Plan9Share",
",",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"\"",
"\"",
":",
"uvmPath",
",",
"\"",
"\"",
":",
"readOnly",
",",
"\"",
"\"",
":",
"restrict",
",",
"\"",
"\"",
":",
"allowedNames",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"operatingSystem",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errNotSupported",
"\n",
"}",
"\n",
"if",
"restrict",
"&&",
"osversion",
".",
"Get",
"(",
")",
".",
"Build",
"<",
"18328",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"uvmPath",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO: JTERRY75 - These are marked private in the schema. For now use them",
"// but when there are public variants we need to switch to them.",
"const",
"(",
"shareFlagsReadOnly",
"int32",
"=",
"0x00000001",
"\n",
"shareFlagsLinuxMetadata",
"int32",
"=",
"0x00000004",
"\n",
"shareFlagsCaseSensitive",
"int32",
"=",
"0x00000008",
"\n",
"shareFlagsRestrictFileAccess",
"int32",
"=",
"0x00000080",
"\n",
")",
"\n\n",
"// TODO: JTERRY75 - `shareFlagsCaseSensitive` only works if the Windows",
"// `hostPath` supports case sensitivity. We need to detect this case before",
"// forwarding this flag in all cases.",
"flags",
":=",
"shareFlagsLinuxMetadata",
"// | shareFlagsCaseSensitive",
"\n",
"if",
"readOnly",
"{",
"flags",
"|=",
"shareFlagsReadOnly",
"\n",
"}",
"\n",
"if",
"restrict",
"{",
"flags",
"|=",
"shareFlagsRestrictFileAccess",
"\n",
"}",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"index",
":=",
"uvm",
".",
"plan9Counter",
"\n",
"uvm",
".",
"plan9Counter",
"++",
"\n",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n",
"name",
":=",
"strconv",
".",
"FormatUint",
"(",
"index",
",",
"10",
")",
"\n\n",
"modification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Add",
",",
"Settings",
":",
"hcsschema",
".",
"Plan9Share",
"{",
"Name",
":",
"name",
",",
"AccessName",
":",
"name",
",",
"Path",
":",
"hostPath",
",",
"Port",
":",
"plan9Port",
",",
"Flags",
":",
"flags",
",",
"AllowedFiles",
":",
"allowedNames",
",",
"}",
",",
"ResourcePath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
",",
"GuestRequest",
":",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedDirectory",
",",
"RequestType",
":",
"requesttype",
".",
"Add",
",",
"Settings",
":",
"guestrequest",
".",
"LCOWMappedDirectory",
"{",
"MountPath",
":",
"uvmPath",
",",
"ShareName",
":",
"name",
",",
"Port",
":",
"plan9Port",
",",
"ReadOnly",
":",
"readOnly",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"modification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"share",
":=",
"&",
"Plan9Share",
"{",
"name",
":",
"name",
",",
"uvmPath",
":",
"uvmPath",
"}",
"\n",
"return",
"share",
",",
"nil",
"\n",
"}"
] | // AddPlan9 adds a Plan9 share to a utility VM. | [
"AddPlan9",
"adds",
"a",
"Plan9",
"share",
"to",
"a",
"utility",
"VM",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/plan9.go#L23-L108 | train |
Microsoft/hcsshim | internal/uvm/plan9.go | RemovePlan9 | func (uvm *UtilityVM) RemovePlan9(share *Plan9Share) (err error) {
op := "uvm::RemovePlan9"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"name": share.name,
"uvm-path": share.uvmPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return errNotSupported
}
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
Settings: hcsschema.Plan9Share{
Name: share.name,
AccessName: share.name,
Port: plan9Port,
},
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Plan9/Shares"),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedDirectory,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedDirectory{
MountPath: share.uvmPath,
ShareName: share.name,
Port: plan9Port,
},
},
}
if err := uvm.Modify(modification); err != nil {
return fmt.Errorf("failed to remove plan9 share %s from %s: %+v: %s", share.name, uvm.id, modification, err)
}
return nil
} | go | func (uvm *UtilityVM) RemovePlan9(share *Plan9Share) (err error) {
op := "uvm::RemovePlan9"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"name": share.name,
"uvm-path": share.uvmPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return errNotSupported
}
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
Settings: hcsschema.Plan9Share{
Name: share.name,
AccessName: share.name,
Port: plan9Port,
},
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/Plan9/Shares"),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeMappedDirectory,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedDirectory{
MountPath: share.uvmPath,
ShareName: share.name,
Port: plan9Port,
},
},
}
if err := uvm.Modify(modification); err != nil {
return fmt.Errorf("failed to remove plan9 share %s from %s: %+v: %s", share.name, uvm.id, modification, err)
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemovePlan9",
"(",
"share",
"*",
"Plan9Share",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"share",
".",
"name",
",",
"\"",
"\"",
":",
"share",
".",
"uvmPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"operatingSystem",
"!=",
"\"",
"\"",
"{",
"return",
"errNotSupported",
"\n",
"}",
"\n\n",
"modification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"hcsschema",
".",
"Plan9Share",
"{",
"Name",
":",
"share",
".",
"name",
",",
"AccessName",
":",
"share",
".",
"name",
",",
"Port",
":",
"plan9Port",
",",
"}",
",",
"ResourcePath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
",",
"GuestRequest",
":",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeMappedDirectory",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"LCOWMappedDirectory",
"{",
"MountPath",
":",
"share",
".",
"uvmPath",
",",
"ShareName",
":",
"share",
".",
"name",
",",
"Port",
":",
"plan9Port",
",",
"}",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"modification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"share",
".",
"name",
",",
"uvm",
".",
"id",
",",
"modification",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemovePlan9 removes a Plan9 share from a utility VM. Each Plan9 share is ref-counted
// and only actually removed when the ref-count drops to zero. | [
"RemovePlan9",
"removes",
"a",
"Plan9",
"share",
"from",
"a",
"utility",
"VM",
".",
"Each",
"Plan9",
"share",
"is",
"ref",
"-",
"counted",
"and",
"only",
"actually",
"removed",
"when",
"the",
"ref",
"-",
"count",
"drops",
"to",
"zero",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/plan9.go#L112-L155 | train |
Microsoft/hcsshim | internal/hns/hnsnetwork.go | GetHNSNetworkByName | func GetHNSNetworkByName(networkName string) (*HNSNetwork, error) {
hsnnetworks, err := HNSListNetworkRequest("GET", "", "")
if err != nil {
return nil, err
}
for _, hnsnetwork := range hsnnetworks {
if hnsnetwork.Name == networkName {
return &hnsnetwork, nil
}
}
return nil, NetworkNotFoundError{NetworkName: networkName}
} | go | func GetHNSNetworkByName(networkName string) (*HNSNetwork, error) {
hsnnetworks, err := HNSListNetworkRequest("GET", "", "")
if err != nil {
return nil, err
}
for _, hnsnetwork := range hsnnetworks {
if hnsnetwork.Name == networkName {
return &hnsnetwork, nil
}
}
return nil, NetworkNotFoundError{NetworkName: networkName}
} | [
"func",
"GetHNSNetworkByName",
"(",
"networkName",
"string",
")",
"(",
"*",
"HNSNetwork",
",",
"error",
")",
"{",
"hsnnetworks",
",",
"err",
":=",
"HNSListNetworkRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"hnsnetwork",
":=",
"range",
"hsnnetworks",
"{",
"if",
"hnsnetwork",
".",
"Name",
"==",
"networkName",
"{",
"return",
"&",
"hnsnetwork",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"NetworkNotFoundError",
"{",
"NetworkName",
":",
"networkName",
"}",
"\n",
"}"
] | // GetHNSNetworkName filtered by Name | [
"GetHNSNetworkName",
"filtered",
"by",
"Name"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsnetwork.go#L82-L93 | train |
Microsoft/hcsshim | internal/hns/hnsnetwork.go | Create | func (network *HNSNetwork) Create() (*HNSNetwork, error) {
operation := "Create"
title := "hcsshim::HNSNetwork::" + operation
logrus.Debugf(title+" id=%s", network.Id)
for _, subnet := range network.Subnets {
if (subnet.AddressPrefix != "") && (subnet.GatewayAddress == "") {
return nil, errors.New("network create error, subnet has address prefix but no gateway specified")
}
}
jsonString, err := json.Marshal(network)
if err != nil {
return nil, err
}
return HNSNetworkRequest("POST", "", string(jsonString))
} | go | func (network *HNSNetwork) Create() (*HNSNetwork, error) {
operation := "Create"
title := "hcsshim::HNSNetwork::" + operation
logrus.Debugf(title+" id=%s", network.Id)
for _, subnet := range network.Subnets {
if (subnet.AddressPrefix != "") && (subnet.GatewayAddress == "") {
return nil, errors.New("network create error, subnet has address prefix but no gateway specified")
}
}
jsonString, err := json.Marshal(network)
if err != nil {
return nil, err
}
return HNSNetworkRequest("POST", "", string(jsonString))
} | [
"func",
"(",
"network",
"*",
"HNSNetwork",
")",
"Create",
"(",
")",
"(",
"*",
"HNSNetwork",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"network",
".",
"Id",
")",
"\n\n",
"for",
"_",
",",
"subnet",
":=",
"range",
"network",
".",
"Subnets",
"{",
"if",
"(",
"subnet",
".",
"AddressPrefix",
"!=",
"\"",
"\"",
")",
"&&",
"(",
"subnet",
".",
"GatewayAddress",
"==",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"network",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"HNSNetworkRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"string",
"(",
"jsonString",
")",
")",
"\n",
"}"
] | // Create Network by sending NetworkRequest to HNS. | [
"Create",
"Network",
"by",
"sending",
"NetworkRequest",
"to",
"HNS",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsnetwork.go#L96-L112 | train |
Microsoft/hcsshim | internal/hns/hnsnetwork.go | Delete | func (network *HNSNetwork) Delete() (*HNSNetwork, error) {
operation := "Delete"
title := "hcsshim::HNSNetwork::" + operation
logrus.Debugf(title+" id=%s", network.Id)
return HNSNetworkRequest("DELETE", network.Id, "")
} | go | func (network *HNSNetwork) Delete() (*HNSNetwork, error) {
operation := "Delete"
title := "hcsshim::HNSNetwork::" + operation
logrus.Debugf(title+" id=%s", network.Id)
return HNSNetworkRequest("DELETE", network.Id, "")
} | [
"func",
"(",
"network",
"*",
"HNSNetwork",
")",
"Delete",
"(",
")",
"(",
"*",
"HNSNetwork",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"network",
".",
"Id",
")",
"\n\n",
"return",
"HNSNetworkRequest",
"(",
"\"",
"\"",
",",
"network",
".",
"Id",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Delete Network by sending NetworkRequest to HNS | [
"Delete",
"Network",
"by",
"sending",
"NetworkRequest",
"to",
"HNS"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsnetwork.go#L115-L121 | train |
Microsoft/hcsshim | internal/hns/hnsnetwork.go | NewEndpoint | func (network *HNSNetwork) NewEndpoint(ipAddress net.IP, macAddress net.HardwareAddr) *HNSEndpoint {
return &HNSEndpoint{
VirtualNetwork: network.Id,
IPAddress: ipAddress,
MacAddress: string(macAddress),
}
} | go | func (network *HNSNetwork) NewEndpoint(ipAddress net.IP, macAddress net.HardwareAddr) *HNSEndpoint {
return &HNSEndpoint{
VirtualNetwork: network.Id,
IPAddress: ipAddress,
MacAddress: string(macAddress),
}
} | [
"func",
"(",
"network",
"*",
"HNSNetwork",
")",
"NewEndpoint",
"(",
"ipAddress",
"net",
".",
"IP",
",",
"macAddress",
"net",
".",
"HardwareAddr",
")",
"*",
"HNSEndpoint",
"{",
"return",
"&",
"HNSEndpoint",
"{",
"VirtualNetwork",
":",
"network",
".",
"Id",
",",
"IPAddress",
":",
"ipAddress",
",",
"MacAddress",
":",
"string",
"(",
"macAddress",
")",
",",
"}",
"\n",
"}"
] | // Creates an endpoint on the Network. | [
"Creates",
"an",
"endpoint",
"on",
"the",
"Network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsnetwork.go#L124-L130 | train |
Microsoft/hcsshim | internal/runhcs/container.go | GetErrorFromPipe | func GetErrorFromPipe(pipe io.Reader, p *os.Process) error {
serr, err := ioutil.ReadAll(pipe)
if err != nil {
return err
}
if bytes.Equal(serr, ShimSuccess) {
return nil
}
extra := ""
if p != nil {
p.Kill()
state, err := p.Wait()
if err != nil {
panic(err)
}
extra = fmt.Sprintf(", exit code %d", state.Sys().(syscall.WaitStatus).ExitCode)
}
if len(serr) == 0 {
return fmt.Errorf("unknown shim failure%s", extra)
}
return errors.New(string(serr))
} | go | func GetErrorFromPipe(pipe io.Reader, p *os.Process) error {
serr, err := ioutil.ReadAll(pipe)
if err != nil {
return err
}
if bytes.Equal(serr, ShimSuccess) {
return nil
}
extra := ""
if p != nil {
p.Kill()
state, err := p.Wait()
if err != nil {
panic(err)
}
extra = fmt.Sprintf(", exit code %d", state.Sys().(syscall.WaitStatus).ExitCode)
}
if len(serr) == 0 {
return fmt.Errorf("unknown shim failure%s", extra)
}
return errors.New(string(serr))
} | [
"func",
"GetErrorFromPipe",
"(",
"pipe",
"io",
".",
"Reader",
",",
"p",
"*",
"os",
".",
"Process",
")",
"error",
"{",
"serr",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"pipe",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"bytes",
".",
"Equal",
"(",
"serr",
",",
"ShimSuccess",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"extra",
":=",
"\"",
"\"",
"\n",
"if",
"p",
"!=",
"nil",
"{",
"p",
".",
"Kill",
"(",
")",
"\n",
"state",
",",
"err",
":=",
"p",
".",
"Wait",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"extra",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"state",
".",
"Sys",
"(",
")",
".",
"(",
"syscall",
".",
"WaitStatus",
")",
".",
"ExitCode",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"serr",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"extra",
")",
"\n",
"}",
"\n\n",
"return",
"errors",
".",
"New",
"(",
"string",
"(",
"serr",
")",
")",
"\n",
"}"
] | // GetErrorFromPipe returns reads from `pipe` and verifies if the operation
// returned success or error. If error converts that to an error and returns. If
// `p` is not nill will issue a `Kill` and `Wait` for exit. | [
"GetErrorFromPipe",
"returns",
"reads",
"from",
"pipe",
"and",
"verifies",
"if",
"the",
"operation",
"returned",
"success",
"or",
"error",
".",
"If",
"error",
"converts",
"that",
"to",
"an",
"error",
"and",
"returns",
".",
"If",
"p",
"is",
"not",
"nill",
"will",
"issue",
"a",
"Kill",
"and",
"Wait",
"for",
"exit",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/runhcs/container.go#L42-L66 | train |
Microsoft/hcsshim | internal/hcsoci/network.go | GetNamespaceEndpoints | func GetNamespaceEndpoints(netNS string) ([]*hns.HNSEndpoint, error) {
op := "hcsoci::GetNamespaceEndpoints"
log := logrus.WithField("netns-id", netNS)
log.Debug(op + " - Begin")
defer func() {
log.Debug(op + " - End")
}()
ids, err := hns.GetNamespaceEndpoints(netNS)
if err != nil {
return nil, err
}
var endpoints []*hns.HNSEndpoint
for _, id := range ids {
endpoint, err := hns.GetHNSEndpointByID(id)
if err != nil {
return nil, err
}
endpoints = append(endpoints, endpoint)
}
return endpoints, nil
} | go | func GetNamespaceEndpoints(netNS string) ([]*hns.HNSEndpoint, error) {
op := "hcsoci::GetNamespaceEndpoints"
log := logrus.WithField("netns-id", netNS)
log.Debug(op + " - Begin")
defer func() {
log.Debug(op + " - End")
}()
ids, err := hns.GetNamespaceEndpoints(netNS)
if err != nil {
return nil, err
}
var endpoints []*hns.HNSEndpoint
for _, id := range ids {
endpoint, err := hns.GetHNSEndpointByID(id)
if err != nil {
return nil, err
}
endpoints = append(endpoints, endpoint)
}
return endpoints, nil
} | [
"func",
"GetNamespaceEndpoints",
"(",
"netNS",
"string",
")",
"(",
"[",
"]",
"*",
"hns",
".",
"HNSEndpoint",
",",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithField",
"(",
"\"",
"\"",
",",
"netNS",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"(",
")",
"\n\n",
"ids",
",",
"err",
":=",
"hns",
".",
"GetNamespaceEndpoints",
"(",
"netNS",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"endpoints",
"[",
"]",
"*",
"hns",
".",
"HNSEndpoint",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"endpoint",
",",
"err",
":=",
"hns",
".",
"GetHNSEndpointByID",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"endpoints",
"=",
"append",
"(",
"endpoints",
",",
"endpoint",
")",
"\n",
"}",
"\n",
"return",
"endpoints",
",",
"nil",
"\n",
"}"
] | // GetNamespaceEndpoints gets all endpoints in `netNS` | [
"GetNamespaceEndpoints",
"gets",
"all",
"endpoints",
"in",
"netNS"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hcsoci/network.go#L36-L57 | train |
Microsoft/hcsshim | hcn/hcnerrors.go | IsNotFoundError | func IsNotFoundError(err error) bool {
switch err.(type) {
case NetworkNotFoundError:
return true
case EndpointNotFoundError:
return true
case NamespaceNotFoundError:
return true
case LoadBalancerNotFoundError:
return true
}
return false
} | go | func IsNotFoundError(err error) bool {
switch err.(type) {
case NetworkNotFoundError:
return true
case EndpointNotFoundError:
return true
case NamespaceNotFoundError:
return true
case LoadBalancerNotFoundError:
return true
}
return false
} | [
"func",
"IsNotFoundError",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"NetworkNotFoundError",
":",
"return",
"true",
"\n",
"case",
"EndpointNotFoundError",
":",
"return",
"true",
"\n",
"case",
"NamespaceNotFoundError",
":",
"return",
"true",
"\n",
"case",
"LoadBalancerNotFoundError",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsNotFoundError returns a boolean indicating whether the error was caused by
// a resource not being found. | [
"IsNotFoundError",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"error",
"was",
"caused",
"by",
"a",
"resource",
"not",
"being",
"found",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnerrors.go#L83-L95 | train |
Microsoft/hcsshim | pkg/go-runhcs/runhcs_delete.go | Delete | func (r *Runhcs) Delete(context context.Context, id string, opts *DeleteOpts) error {
args := []string{"delete"}
if opts != nil {
oargs, err := opts.args()
if err != nil {
return err
}
args = append(args, oargs...)
}
return r.runOrError(r.command(context, append(args, id)...))
} | go | func (r *Runhcs) Delete(context context.Context, id string, opts *DeleteOpts) error {
args := []string{"delete"}
if opts != nil {
oargs, err := opts.args()
if err != nil {
return err
}
args = append(args, oargs...)
}
return r.runOrError(r.command(context, append(args, id)...))
} | [
"func",
"(",
"r",
"*",
"Runhcs",
")",
"Delete",
"(",
"context",
"context",
".",
"Context",
",",
"id",
"string",
",",
"opts",
"*",
"DeleteOpts",
")",
"error",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"oargs",
",",
"err",
":=",
"opts",
".",
"args",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"oargs",
"...",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"runOrError",
"(",
"r",
".",
"command",
"(",
"context",
",",
"append",
"(",
"args",
",",
"id",
")",
"...",
")",
")",
"\n",
"}"
] | // Delete any resources held by the container often used with detached
// containers. | [
"Delete",
"any",
"resources",
"held",
"by",
"the",
"container",
"often",
"used",
"with",
"detached",
"containers",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/pkg/go-runhcs/runhcs_delete.go#L23-L33 | train |
Microsoft/hcsshim | internal/wclayer/baselayer.go | reapplyDirectoryTimes | func reapplyDirectoryTimes(root *os.File, dis []dirInfo) error {
for i := range dis {
di := &dis[len(dis)-i-1] // reverse order: process child directories first
f, err := safefile.OpenRelative(di.path, root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, safefile.FILE_OPEN, safefile.FILE_DIRECTORY_FILE)
if err != nil {
return err
}
err = winio.SetFileBasicInfo(f, &di.fileInfo)
f.Close()
if err != nil {
return err
}
}
return nil
} | go | func reapplyDirectoryTimes(root *os.File, dis []dirInfo) error {
for i := range dis {
di := &dis[len(dis)-i-1] // reverse order: process child directories first
f, err := safefile.OpenRelative(di.path, root, syscall.GENERIC_READ|syscall.GENERIC_WRITE, syscall.FILE_SHARE_READ, safefile.FILE_OPEN, safefile.FILE_DIRECTORY_FILE)
if err != nil {
return err
}
err = winio.SetFileBasicInfo(f, &di.fileInfo)
f.Close()
if err != nil {
return err
}
}
return nil
} | [
"func",
"reapplyDirectoryTimes",
"(",
"root",
"*",
"os",
".",
"File",
",",
"dis",
"[",
"]",
"dirInfo",
")",
"error",
"{",
"for",
"i",
":=",
"range",
"dis",
"{",
"di",
":=",
"&",
"dis",
"[",
"len",
"(",
"dis",
")",
"-",
"i",
"-",
"1",
"]",
"// reverse order: process child directories first",
"\n",
"f",
",",
"err",
":=",
"safefile",
".",
"OpenRelative",
"(",
"di",
".",
"path",
",",
"root",
",",
"syscall",
".",
"GENERIC_READ",
"|",
"syscall",
".",
"GENERIC_WRITE",
",",
"syscall",
".",
"FILE_SHARE_READ",
",",
"safefile",
".",
"FILE_OPEN",
",",
"safefile",
".",
"FILE_DIRECTORY_FILE",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"winio",
".",
"SetFileBasicInfo",
"(",
"f",
",",
"&",
"di",
".",
"fileInfo",
")",
"\n",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // reapplyDirectoryTimes reapplies directory modification, creation, etc. times
// after processing of the directory tree has completed. The times are expected
// to be ordered such that parent directories come before child directories. | [
"reapplyDirectoryTimes",
"reapplies",
"directory",
"modification",
"creation",
"etc",
".",
"times",
"after",
"processing",
"of",
"the",
"directory",
"tree",
"has",
"completed",
".",
"The",
"times",
"are",
"expected",
"to",
"be",
"ordered",
"such",
"that",
"parent",
"directories",
"come",
"before",
"child",
"directories",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/baselayer.go#L31-L46 | train |
Microsoft/hcsshim | internal/uvm/create.go | newDefaultOptions | func newDefaultOptions(id, owner string) *Options {
opts := &Options{
ID: id,
Owner: owner,
MemorySizeInMB: 1024,
AllowOvercommit: true,
EnableDeferredCommit: false,
ProcessorCount: defaultProcessorCount(),
}
if opts.ID == "" {
opts.ID = guid.New().String()
}
if opts.Owner == "" {
opts.Owner = filepath.Base(os.Args[0])
}
return opts
} | go | func newDefaultOptions(id, owner string) *Options {
opts := &Options{
ID: id,
Owner: owner,
MemorySizeInMB: 1024,
AllowOvercommit: true,
EnableDeferredCommit: false,
ProcessorCount: defaultProcessorCount(),
}
if opts.ID == "" {
opts.ID = guid.New().String()
}
if opts.Owner == "" {
opts.Owner = filepath.Base(os.Args[0])
}
return opts
} | [
"func",
"newDefaultOptions",
"(",
"id",
",",
"owner",
"string",
")",
"*",
"Options",
"{",
"opts",
":=",
"&",
"Options",
"{",
"ID",
":",
"id",
",",
"Owner",
":",
"owner",
",",
"MemorySizeInMB",
":",
"1024",
",",
"AllowOvercommit",
":",
"true",
",",
"EnableDeferredCommit",
":",
"false",
",",
"ProcessorCount",
":",
"defaultProcessorCount",
"(",
")",
",",
"}",
"\n\n",
"if",
"opts",
".",
"ID",
"==",
"\"",
"\"",
"{",
"opts",
".",
"ID",
"=",
"guid",
".",
"New",
"(",
")",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Owner",
"==",
"\"",
"\"",
"{",
"opts",
".",
"Owner",
"=",
"filepath",
".",
"Base",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"opts",
"\n",
"}"
] | // newDefaultOptions returns the default base options for WCOW and LCOW.
//
// If `id` is empty it will be generated.
//
// If `owner` is empty it will be set to the calling executables name. | [
"newDefaultOptions",
"returns",
"the",
"default",
"base",
"options",
"for",
"WCOW",
"and",
"LCOW",
".",
"If",
"id",
"is",
"empty",
"it",
"will",
"be",
"generated",
".",
"If",
"owner",
"is",
"empty",
"it",
"will",
"be",
"set",
"to",
"the",
"calling",
"executables",
"name",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/create.go#L57-L75 | train |
Microsoft/hcsshim | internal/uvm/create.go | Close | func (uvm *UtilityVM) Close() (err error) {
op := "uvm::Close"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.hcsSystem.Terminate()
uvm.Wait()
// outputListener will only be nil for a Create -> Stop without a Start. In
// this case we have no goroutine processing output so its safe to close the
// channel here.
if uvm.outputListener != nil {
close(uvm.outputProcessingDone)
uvm.outputListener.Close()
uvm.outputListener = nil
}
return uvm.hcsSystem.Close()
} | go | func (uvm *UtilityVM) Close() (err error) {
op := "uvm::Close"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
uvm.hcsSystem.Terminate()
uvm.Wait()
// outputListener will only be nil for a Create -> Stop without a Start. In
// this case we have no goroutine processing output so its safe to close the
// channel here.
if uvm.outputListener != nil {
close(uvm.outputProcessingDone)
uvm.outputListener.Close()
uvm.outputListener = nil
}
return uvm.hcsSystem.Close()
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"uvm",
".",
"hcsSystem",
".",
"Terminate",
"(",
")",
"\n",
"uvm",
".",
"Wait",
"(",
")",
"\n\n",
"// outputListener will only be nil for a Create -> Stop without a Start. In",
"// this case we have no goroutine processing output so its safe to close the",
"// channel here.",
"if",
"uvm",
".",
"outputListener",
"!=",
"nil",
"{",
"close",
"(",
"uvm",
".",
"outputProcessingDone",
")",
"\n",
"uvm",
".",
"outputListener",
".",
"Close",
"(",
")",
"\n",
"uvm",
".",
"outputListener",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"uvm",
".",
"hcsSystem",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close terminates and releases resources associated with the utility VM. | [
"Close",
"terminates",
"and",
"releases",
"resources",
"associated",
"with",
"the",
"utility",
"VM",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/create.go#L88-L115 | train |
Microsoft/hcsshim | internal/longpath/longpath.go | LongAbs | func LongAbs(path string) (string, error) {
if strings.HasPrefix(path, `\\?\`) || strings.HasPrefix(path, `\\.\`) {
return path, nil
}
if !filepath.IsAbs(path) {
absPath, err := filepath.Abs(path)
if err != nil {
return "", err
}
path = absPath
}
if strings.HasPrefix(path, `\\`) {
return `\\?\UNC\` + path[2:], nil
}
return `\\?\` + path, nil
} | go | func LongAbs(path string) (string, error) {
if strings.HasPrefix(path, `\\?\`) || strings.HasPrefix(path, `\\.\`) {
return path, nil
}
if !filepath.IsAbs(path) {
absPath, err := filepath.Abs(path)
if err != nil {
return "", err
}
path = absPath
}
if strings.HasPrefix(path, `\\`) {
return `\\?\UNC\` + path[2:], nil
}
return `\\?\` + path, nil
} | [
"func",
"LongAbs",
"(",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"`\\\\?\\`",
")",
"||",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"`\\\\.\\`",
")",
"{",
"return",
"path",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"path",
")",
"{",
"absPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"path",
"=",
"absPath",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"`\\\\`",
")",
"{",
"return",
"`\\\\?\\UNC\\`",
"+",
"path",
"[",
"2",
":",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"`\\\\?\\`",
"+",
"path",
",",
"nil",
"\n",
"}"
] | // LongAbs makes a path absolute and returns it in NT long path form. | [
"LongAbs",
"makes",
"a",
"path",
"absolute",
"and",
"returns",
"it",
"in",
"NT",
"long",
"path",
"form",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/longpath/longpath.go#L9-L24 | train |
Microsoft/hcsshim | internal/wclayer/grantvmaccess.go | GrantVmAccess | func GrantVmAccess(vmid string, filepath string) (err error) {
title := "hcsshim::GrantVmAccess"
fields := logrus.Fields{
"vm-id": vmid,
"path": filepath,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = grantVmAccess(vmid, filepath)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | go | func GrantVmAccess(vmid string, filepath string) (err error) {
title := "hcsshim::GrantVmAccess"
fields := logrus.Fields{
"vm-id": vmid,
"path": filepath,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = grantVmAccess(vmid, filepath)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | [
"func",
"GrantVmAccess",
"(",
"vmid",
"string",
",",
"filepath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"vmid",
",",
"\"",
"\"",
":",
"filepath",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"grantVmAccess",
"(",
"vmid",
",",
"filepath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GrantVmAccess adds access to a file for a given VM | [
"GrantVmAccess",
"adds",
"access",
"to",
"a",
"file",
"for",
"a",
"given",
"VM"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/grantvmaccess.go#L9-L30 | train |
Microsoft/hcsshim | internal/uvm/start.go | Start | func (uvm *UtilityVM) Start() (err error) {
op := "uvm::Start"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.outputListener != nil {
ctx, cancel := context.WithCancel(context.Background())
go processOutput(ctx, uvm.outputListener, uvm.outputProcessingDone, uvm.outputHandler)
uvm.outputProcessingCancel = cancel
uvm.outputListener = nil
}
return uvm.hcsSystem.Start()
} | go | func (uvm *UtilityVM) Start() (err error) {
op := "uvm::Start"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.outputListener != nil {
ctx, cancel := context.WithCancel(context.Background())
go processOutput(ctx, uvm.outputListener, uvm.outputProcessingDone, uvm.outputHandler)
uvm.outputProcessingCancel = cancel
uvm.outputListener = nil
}
return uvm.hcsSystem.Start()
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"outputListener",
"!=",
"nil",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"go",
"processOutput",
"(",
"ctx",
",",
"uvm",
".",
"outputListener",
",",
"uvm",
".",
"outputProcessingDone",
",",
"uvm",
".",
"outputHandler",
")",
"\n",
"uvm",
".",
"outputProcessingCancel",
"=",
"cancel",
"\n",
"uvm",
".",
"outputListener",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"uvm",
".",
"hcsSystem",
".",
"Start",
"(",
")",
"\n",
"}"
] | // Start synchronously starts the utility VM. | [
"Start",
"synchronously",
"starts",
"the",
"utility",
"VM",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/start.go#L135-L157 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | ListNetworks | func ListNetworks() ([]HostComputeNetwork, error) {
hcnQuery := defaultQuery()
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
return networks, nil
} | go | func ListNetworks() ([]HostComputeNetwork, error) {
hcnQuery := defaultQuery()
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
return networks, nil
} | [
"func",
"ListNetworks",
"(",
")",
"(",
"[",
"]",
"HostComputeNetwork",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"networks",
",",
"err",
":=",
"ListNetworksQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"networks",
",",
"nil",
"\n",
"}"
] | // ListNetworks makes a call to list all available networks. | [
"ListNetworks",
"makes",
"a",
"call",
"to",
"list",
"all",
"available",
"networks",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L257-L264 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | ListNetworksQuery | func ListNetworksQuery(query HostComputeQuery) ([]HostComputeNetwork, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
networks, err := enumerateNetworks(string(queryJson))
if err != nil {
return nil, err
}
return networks, nil
} | go | func ListNetworksQuery(query HostComputeQuery) ([]HostComputeNetwork, error) {
queryJson, err := json.Marshal(query)
if err != nil {
return nil, err
}
networks, err := enumerateNetworks(string(queryJson))
if err != nil {
return nil, err
}
return networks, nil
} | [
"func",
"ListNetworksQuery",
"(",
"query",
"HostComputeQuery",
")",
"(",
"[",
"]",
"HostComputeNetwork",
",",
"error",
")",
"{",
"queryJson",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"query",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"networks",
",",
"err",
":=",
"enumerateNetworks",
"(",
"string",
"(",
"queryJson",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"networks",
",",
"nil",
"\n",
"}"
] | // ListNetworksQuery makes a call to query the list of available networks. | [
"ListNetworksQuery",
"makes",
"a",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"networks",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L267-L278 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | GetNetworkByID | func GetNetworkByID(networkID string) (*HostComputeNetwork, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": networkID}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(networks) == 0 {
return nil, NetworkNotFoundError{NetworkID: networkID}
}
return &networks[0], err
} | go | func GetNetworkByID(networkID string) (*HostComputeNetwork, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"ID": networkID}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(networks) == 0 {
return nil, NetworkNotFoundError{NetworkID: networkID}
}
return &networks[0], err
} | [
"func",
"GetNetworkByID",
"(",
"networkID",
"string",
")",
"(",
"*",
"HostComputeNetwork",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"networkID",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"networks",
",",
"err",
":=",
"ListNetworksQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"networks",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"NetworkNotFoundError",
"{",
"NetworkID",
":",
"networkID",
"}",
"\n",
"}",
"\n",
"return",
"&",
"networks",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] | // GetNetworkByID returns the network specified by Id. | [
"GetNetworkByID",
"returns",
"the",
"network",
"specified",
"by",
"Id",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L281-L298 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | GetNetworkByName | func GetNetworkByName(networkName string) (*HostComputeNetwork, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": networkName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(networks) == 0 {
return nil, NetworkNotFoundError{NetworkName: networkName}
}
return &networks[0], err
} | go | func GetNetworkByName(networkName string) (*HostComputeNetwork, error) {
hcnQuery := defaultQuery()
mapA := map[string]string{"Name": networkName}
filter, err := json.Marshal(mapA)
if err != nil {
return nil, err
}
hcnQuery.Filter = string(filter)
networks, err := ListNetworksQuery(hcnQuery)
if err != nil {
return nil, err
}
if len(networks) == 0 {
return nil, NetworkNotFoundError{NetworkName: networkName}
}
return &networks[0], err
} | [
"func",
"GetNetworkByName",
"(",
"networkName",
"string",
")",
"(",
"*",
"HostComputeNetwork",
",",
"error",
")",
"{",
"hcnQuery",
":=",
"defaultQuery",
"(",
")",
"\n",
"mapA",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"networkName",
"}",
"\n",
"filter",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"mapA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"hcnQuery",
".",
"Filter",
"=",
"string",
"(",
"filter",
")",
"\n\n",
"networks",
",",
"err",
":=",
"ListNetworksQuery",
"(",
"hcnQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"networks",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"NetworkNotFoundError",
"{",
"NetworkName",
":",
"networkName",
"}",
"\n",
"}",
"\n",
"return",
"&",
"networks",
"[",
"0",
"]",
",",
"err",
"\n",
"}"
] | // GetNetworkByName returns the network specified by Name. | [
"GetNetworkByName",
"returns",
"the",
"network",
"specified",
"by",
"Name",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L301-L318 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | Create | func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) {
logrus.Debugf("hcn::HostComputeNetwork::Create id=%s", network.Id)
for _, ipam := range network.Ipams {
for _, subnet := range ipam.Subnets {
if subnet.IpAddressPrefix != "" {
hasDefault := false
for _, route := range subnet.Routes {
if route.NextHop == "" {
return nil, errors.New("network create error, subnet has address prefix but no gateway specified")
}
if route.DestinationPrefix == "0.0.0.0/0" || route.DestinationPrefix == "::/0" {
hasDefault = true
}
}
if !hasDefault {
return nil, errors.New("network create error, no default gateway")
}
}
}
}
jsonString, err := json.Marshal(network)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeNetwork::Create JSON: %s", jsonString)
network, hcnErr := createNetwork(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return network, nil
} | go | func (network *HostComputeNetwork) Create() (*HostComputeNetwork, error) {
logrus.Debugf("hcn::HostComputeNetwork::Create id=%s", network.Id)
for _, ipam := range network.Ipams {
for _, subnet := range ipam.Subnets {
if subnet.IpAddressPrefix != "" {
hasDefault := false
for _, route := range subnet.Routes {
if route.NextHop == "" {
return nil, errors.New("network create error, subnet has address prefix but no gateway specified")
}
if route.DestinationPrefix == "0.0.0.0/0" || route.DestinationPrefix == "::/0" {
hasDefault = true
}
}
if !hasDefault {
return nil, errors.New("network create error, no default gateway")
}
}
}
}
jsonString, err := json.Marshal(network)
if err != nil {
return nil, err
}
logrus.Debugf("hcn::HostComputeNetwork::Create JSON: %s", jsonString)
network, hcnErr := createNetwork(string(jsonString))
if hcnErr != nil {
return nil, hcnErr
}
return network, nil
} | [
"func",
"(",
"network",
"*",
"HostComputeNetwork",
")",
"Create",
"(",
")",
"(",
"*",
"HostComputeNetwork",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"network",
".",
"Id",
")",
"\n",
"for",
"_",
",",
"ipam",
":=",
"range",
"network",
".",
"Ipams",
"{",
"for",
"_",
",",
"subnet",
":=",
"range",
"ipam",
".",
"Subnets",
"{",
"if",
"subnet",
".",
"IpAddressPrefix",
"!=",
"\"",
"\"",
"{",
"hasDefault",
":=",
"false",
"\n",
"for",
"_",
",",
"route",
":=",
"range",
"subnet",
".",
"Routes",
"{",
"if",
"route",
".",
"NextHop",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"route",
".",
"DestinationPrefix",
"==",
"\"",
"\"",
"||",
"route",
".",
"DestinationPrefix",
"==",
"\"",
"\"",
"{",
"hasDefault",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"hasDefault",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"network",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"jsonString",
")",
"\n",
"network",
",",
"hcnErr",
":=",
"createNetwork",
"(",
"string",
"(",
"jsonString",
")",
")",
"\n",
"if",
"hcnErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"hcnErr",
"\n",
"}",
"\n",
"return",
"network",
",",
"nil",
"\n",
"}"
] | // Create Network. | [
"Create",
"Network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L321-L353 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | Delete | func (network *HostComputeNetwork) Delete() error {
logrus.Debugf("hcn::HostComputeNetwork::Delete id=%s", network.Id)
if err := deleteNetwork(network.Id); err != nil {
return err
}
return nil
} | go | func (network *HostComputeNetwork) Delete() error {
logrus.Debugf("hcn::HostComputeNetwork::Delete id=%s", network.Id)
if err := deleteNetwork(network.Id); err != nil {
return err
}
return nil
} | [
"func",
"(",
"network",
"*",
"HostComputeNetwork",
")",
"Delete",
"(",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"network",
".",
"Id",
")",
"\n\n",
"if",
"err",
":=",
"deleteNetwork",
"(",
"network",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete Network. | [
"Delete",
"Network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L356-L363 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | ModifyNetworkSettings | func (network *HostComputeNetwork) ModifyNetworkSettings(request *ModifyNetworkSettingRequest) error {
logrus.Debugf("hcn::HostComputeNetwork::ModifyNetworkSettings id=%s", network.Id)
networkSettingsRequest, err := json.Marshal(request)
if err != nil {
return err
}
_, err = modifyNetwork(network.Id, string(networkSettingsRequest))
if err != nil {
return err
}
return nil
} | go | func (network *HostComputeNetwork) ModifyNetworkSettings(request *ModifyNetworkSettingRequest) error {
logrus.Debugf("hcn::HostComputeNetwork::ModifyNetworkSettings id=%s", network.Id)
networkSettingsRequest, err := json.Marshal(request)
if err != nil {
return err
}
_, err = modifyNetwork(network.Id, string(networkSettingsRequest))
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"network",
"*",
"HostComputeNetwork",
")",
"ModifyNetworkSettings",
"(",
"request",
"*",
"ModifyNetworkSettingRequest",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"network",
".",
"Id",
")",
"\n\n",
"networkSettingsRequest",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"request",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"modifyNetwork",
"(",
"network",
".",
"Id",
",",
"string",
"(",
"networkSettingsRequest",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ModifyNetworkSettings updates the Policy for a network. | [
"ModifyNetworkSettings",
"updates",
"the",
"Policy",
"for",
"a",
"network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L366-L379 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | CreateEndpoint | func (network *HostComputeNetwork) CreateEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
isRemote := endpoint.Flags&EndpointFlagsRemoteEndpoint != 0
logrus.Debugf("hcn::HostComputeNetwork::CreatEndpoint, networkId=%s remote=%t", network.Id, isRemote)
endpoint.HostComputeNetwork = network.Id
endpointSettings, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
newEndpoint, err := createEndpoint(network.Id, string(endpointSettings))
if err != nil {
return nil, err
}
return newEndpoint, nil
} | go | func (network *HostComputeNetwork) CreateEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
isRemote := endpoint.Flags&EndpointFlagsRemoteEndpoint != 0
logrus.Debugf("hcn::HostComputeNetwork::CreatEndpoint, networkId=%s remote=%t", network.Id, isRemote)
endpoint.HostComputeNetwork = network.Id
endpointSettings, err := json.Marshal(endpoint)
if err != nil {
return nil, err
}
newEndpoint, err := createEndpoint(network.Id, string(endpointSettings))
if err != nil {
return nil, err
}
return newEndpoint, nil
} | [
"func",
"(",
"network",
"*",
"HostComputeNetwork",
")",
"CreateEndpoint",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"isRemote",
":=",
"endpoint",
".",
"Flags",
"&",
"EndpointFlagsRemoteEndpoint",
"!=",
"0",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"network",
".",
"Id",
",",
"isRemote",
")",
"\n\n",
"endpoint",
".",
"HostComputeNetwork",
"=",
"network",
".",
"Id",
"\n",
"endpointSettings",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newEndpoint",
",",
"err",
":=",
"createEndpoint",
"(",
"network",
".",
"Id",
",",
"string",
"(",
"endpointSettings",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newEndpoint",
",",
"nil",
"\n",
"}"
] | // CreateEndpoint creates an endpoint on the Network. | [
"CreateEndpoint",
"creates",
"an",
"endpoint",
"on",
"the",
"Network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L416-L430 | train |
Microsoft/hcsshim | hcn/hcnnetwork.go | CreateRemoteEndpoint | func (network *HostComputeNetwork) CreateRemoteEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
endpoint.Flags = EndpointFlagsRemoteEndpoint | endpoint.Flags
return network.CreateEndpoint(endpoint)
} | go | func (network *HostComputeNetwork) CreateRemoteEndpoint(endpoint *HostComputeEndpoint) (*HostComputeEndpoint, error) {
endpoint.Flags = EndpointFlagsRemoteEndpoint | endpoint.Flags
return network.CreateEndpoint(endpoint)
} | [
"func",
"(",
"network",
"*",
"HostComputeNetwork",
")",
"CreateRemoteEndpoint",
"(",
"endpoint",
"*",
"HostComputeEndpoint",
")",
"(",
"*",
"HostComputeEndpoint",
",",
"error",
")",
"{",
"endpoint",
".",
"Flags",
"=",
"EndpointFlagsRemoteEndpoint",
"|",
"endpoint",
".",
"Flags",
"\n",
"return",
"network",
".",
"CreateEndpoint",
"(",
"endpoint",
")",
"\n",
"}"
] | // CreateRemoteEndpoint creates a remote endpoint on the Network. | [
"CreateRemoteEndpoint",
"creates",
"a",
"remote",
"endpoint",
"on",
"the",
"Network",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnnetwork.go#L433-L436 | train |
Microsoft/hcsshim | internal/uvm/vpmem.go | allocateVPMEM | func (uvm *UtilityVM) allocateVPMEM(hostPath string) (uint32, error) {
for index, vi := range uvm.vpmemDevices {
if vi.hostPath == "" {
vi.hostPath = hostPath
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": vi.hostPath,
"uvm-path": vi.uvmPath,
"refCount": vi.refCount,
"deviceNumber": uint32(index),
}).Debug("uvm::allocateVPMEM")
return uint32(index), nil
}
}
return 0, fmt.Errorf("no free VPMEM locations")
} | go | func (uvm *UtilityVM) allocateVPMEM(hostPath string) (uint32, error) {
for index, vi := range uvm.vpmemDevices {
if vi.hostPath == "" {
vi.hostPath = hostPath
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": vi.hostPath,
"uvm-path": vi.uvmPath,
"refCount": vi.refCount,
"deviceNumber": uint32(index),
}).Debug("uvm::allocateVPMEM")
return uint32(index), nil
}
}
return 0, fmt.Errorf("no free VPMEM locations")
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"allocateVPMEM",
"(",
"hostPath",
"string",
")",
"(",
"uint32",
",",
"error",
")",
"{",
"for",
"index",
",",
"vi",
":=",
"range",
"uvm",
".",
"vpmemDevices",
"{",
"if",
"vi",
".",
"hostPath",
"==",
"\"",
"\"",
"{",
"vi",
".",
"hostPath",
"=",
"hostPath",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"vi",
".",
"hostPath",
",",
"\"",
"\"",
":",
"vi",
".",
"uvmPath",
",",
"\"",
"\"",
":",
"vi",
".",
"refCount",
",",
"\"",
"\"",
":",
"uint32",
"(",
"index",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"uint32",
"(",
"index",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // allocateVPMEM finds the next available VPMem slot. The lock MUST be held
// when calling this function. | [
"allocateVPMEM",
"finds",
"the",
"next",
"available",
"VPMem",
"slot",
".",
"The",
"lock",
"MUST",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vpmem.go#L15-L30 | train |
Microsoft/hcsshim | internal/uvm/vpmem.go | findVPMEMDevice | func (uvm *UtilityVM) findVPMEMDevice(findThisHostPath string) (uint32, string, error) {
for deviceNumber, vi := range uvm.vpmemDevices {
if vi.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": vi.uvmPath,
"refCount": vi.refCount,
"deviceNumber": uint32(deviceNumber),
}).Debug("uvm::findVPMEMDevice")
return uint32(deviceNumber), vi.uvmPath, nil
}
}
return 0, "", fmt.Errorf("%s is not attached to VPMEM", findThisHostPath)
} | go | func (uvm *UtilityVM) findVPMEMDevice(findThisHostPath string) (uint32, string, error) {
for deviceNumber, vi := range uvm.vpmemDevices {
if vi.hostPath == findThisHostPath {
logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": findThisHostPath,
"uvm-path": vi.uvmPath,
"refCount": vi.refCount,
"deviceNumber": uint32(deviceNumber),
}).Debug("uvm::findVPMEMDevice")
return uint32(deviceNumber), vi.uvmPath, nil
}
}
return 0, "", fmt.Errorf("%s is not attached to VPMEM", findThisHostPath)
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"findVPMEMDevice",
"(",
"findThisHostPath",
"string",
")",
"(",
"uint32",
",",
"string",
",",
"error",
")",
"{",
"for",
"deviceNumber",
",",
"vi",
":=",
"range",
"uvm",
".",
"vpmemDevices",
"{",
"if",
"vi",
".",
"hostPath",
"==",
"findThisHostPath",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"findThisHostPath",
",",
"\"",
"\"",
":",
"vi",
".",
"uvmPath",
",",
"\"",
"\"",
":",
"vi",
".",
"refCount",
",",
"\"",
"\"",
":",
"uint32",
"(",
"deviceNumber",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"uint32",
"(",
"deviceNumber",
")",
",",
"vi",
".",
"uvmPath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"findThisHostPath",
")",
"\n",
"}"
] | // Lock must be held when calling this function | [
"Lock",
"must",
"be",
"held",
"when",
"calling",
"this",
"function"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vpmem.go#L51-L65 | train |
Microsoft/hcsshim | internal/uvm/vpmem.go | RemoveVPMEM | func (uvm *UtilityVM) RemoveVPMEM(hostPath string) (err error) {
op := "uvm::RemoveVPMEM"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
// Make sure is actually attached
deviceNumber, uvmPath, err := uvm.findVPMEMDevice(hostPath)
if err != nil {
return fmt.Errorf("cannot remove VPMEM %s as it is not attached to utility VM %s: %s", hostPath, uvm.id, err)
}
if err := uvm.removeVPMEM(hostPath, uvmPath, deviceNumber); err != nil {
return fmt.Errorf("failed to remove VPMEM %s from utility VM %s: %s", hostPath, uvm.id, err)
}
return nil
} | go | func (uvm *UtilityVM) RemoveVPMEM(hostPath string) (err error) {
op := "uvm::RemoveVPMEM"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
"host-path": hostPath,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
if uvm.operatingSystem != "linux" {
return errNotSupported
}
uvm.m.Lock()
defer uvm.m.Unlock()
// Make sure is actually attached
deviceNumber, uvmPath, err := uvm.findVPMEMDevice(hostPath)
if err != nil {
return fmt.Errorf("cannot remove VPMEM %s as it is not attached to utility VM %s: %s", hostPath, uvm.id, err)
}
if err := uvm.removeVPMEM(hostPath, uvmPath, deviceNumber); err != nil {
return fmt.Errorf("failed to remove VPMEM %s from utility VM %s: %s", hostPath, uvm.id, err)
}
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"RemoveVPMEM",
"(",
"hostPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"\"",
"\"",
":",
"hostPath",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"uvm",
".",
"operatingSystem",
"!=",
"\"",
"\"",
"{",
"return",
"errNotSupported",
"\n",
"}",
"\n\n",
"uvm",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"uvm",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"// Make sure is actually attached",
"deviceNumber",
",",
"uvmPath",
",",
"err",
":=",
"uvm",
".",
"findVPMEMDevice",
"(",
"hostPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"removeVPMEM",
"(",
"hostPath",
",",
"uvmPath",
",",
"deviceNumber",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"hostPath",
",",
"uvm",
".",
"id",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemoveVPMEM removes a VPMEM disk from a utility VM. As an external API, it
// is "safe". Internal use can call removeVPMEM. | [
"RemoveVPMEM",
"removes",
"a",
"VPMEM",
"disk",
"from",
"a",
"utility",
"VM",
".",
"As",
"an",
"external",
"API",
"it",
"is",
"safe",
".",
"Internal",
"use",
"can",
"call",
"removeVPMEM",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vpmem.go#L151-L184 | train |
Microsoft/hcsshim | internal/uvm/vpmem.go | removeVPMEM | func (uvm *UtilityVM) removeVPMEM(hostPath string, uvmPath string, deviceNumber uint32) error {
if uvm.vpmemDevices[deviceNumber].refCount == 1 {
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/VirtualPMem/Devices/%d", deviceNumber),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeVPMemDevice,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVPMemDevice{
DeviceNumber: deviceNumber,
MountPath: uvmPath,
},
},
}
if err := uvm.Modify(modification); err != nil {
return err
}
uvm.vpmemDevices[deviceNumber] = vpmemInfo{}
return nil
}
uvm.vpmemDevices[deviceNumber].refCount--
return nil
} | go | func (uvm *UtilityVM) removeVPMEM(hostPath string, uvmPath string, deviceNumber uint32) error {
if uvm.vpmemDevices[deviceNumber].refCount == 1 {
modification := &hcsschema.ModifySettingRequest{
RequestType: requesttype.Remove,
ResourcePath: fmt.Sprintf("VirtualMachine/Devices/VirtualPMem/Devices/%d", deviceNumber),
GuestRequest: guestrequest.GuestRequest{
ResourceType: guestrequest.ResourceTypeVPMemDevice,
RequestType: requesttype.Remove,
Settings: guestrequest.LCOWMappedVPMemDevice{
DeviceNumber: deviceNumber,
MountPath: uvmPath,
},
},
}
if err := uvm.Modify(modification); err != nil {
return err
}
uvm.vpmemDevices[deviceNumber] = vpmemInfo{}
return nil
}
uvm.vpmemDevices[deviceNumber].refCount--
return nil
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"removeVPMEM",
"(",
"hostPath",
"string",
",",
"uvmPath",
"string",
",",
"deviceNumber",
"uint32",
")",
"error",
"{",
"if",
"uvm",
".",
"vpmemDevices",
"[",
"deviceNumber",
"]",
".",
"refCount",
"==",
"1",
"{",
"modification",
":=",
"&",
"hcsschema",
".",
"ModifySettingRequest",
"{",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"ResourcePath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"deviceNumber",
")",
",",
"GuestRequest",
":",
"guestrequest",
".",
"GuestRequest",
"{",
"ResourceType",
":",
"guestrequest",
".",
"ResourceTypeVPMemDevice",
",",
"RequestType",
":",
"requesttype",
".",
"Remove",
",",
"Settings",
":",
"guestrequest",
".",
"LCOWMappedVPMemDevice",
"{",
"DeviceNumber",
":",
"deviceNumber",
",",
"MountPath",
":",
"uvmPath",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"if",
"err",
":=",
"uvm",
".",
"Modify",
"(",
"modification",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"uvm",
".",
"vpmemDevices",
"[",
"deviceNumber",
"]",
"=",
"vpmemInfo",
"{",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"uvm",
".",
"vpmemDevices",
"[",
"deviceNumber",
"]",
".",
"refCount",
"--",
"\n",
"return",
"nil",
"\n\n",
"}"
] | // removeVPMEM is the internally callable "unsafe" version of RemoveVPMEM. The mutex
// MUST be held when calling this function. | [
"removeVPMEM",
"is",
"the",
"internally",
"callable",
"unsafe",
"version",
"of",
"RemoveVPMEM",
".",
"The",
"mutex",
"MUST",
"be",
"held",
"when",
"calling",
"this",
"function",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/vpmem.go#L188-L212 | train |
Microsoft/hcsshim | internal/ociwclayer/export.go | ExportLayer | func ExportLayer(w io.Writer, path string, parentLayerPaths []string) error {
err := hcsshim.ActivateLayer(driverInfo, path)
if err != nil {
return err
}
defer hcsshim.DeactivateLayer(driverInfo, path)
// Prepare and unprepare the layer to ensure that it has been initialized.
err = hcsshim.PrepareLayer(driverInfo, path, parentLayerPaths)
if err != nil {
return err
}
err = hcsshim.UnprepareLayer(driverInfo, path)
if err != nil {
return err
}
r, err := hcsshim.NewLayerReader(driverInfo, path, parentLayerPaths)
if err != nil {
return err
}
err = writeTarFromLayer(r, w)
cerr := r.Close()
if err != nil {
return err
}
return cerr
} | go | func ExportLayer(w io.Writer, path string, parentLayerPaths []string) error {
err := hcsshim.ActivateLayer(driverInfo, path)
if err != nil {
return err
}
defer hcsshim.DeactivateLayer(driverInfo, path)
// Prepare and unprepare the layer to ensure that it has been initialized.
err = hcsshim.PrepareLayer(driverInfo, path, parentLayerPaths)
if err != nil {
return err
}
err = hcsshim.UnprepareLayer(driverInfo, path)
if err != nil {
return err
}
r, err := hcsshim.NewLayerReader(driverInfo, path, parentLayerPaths)
if err != nil {
return err
}
err = writeTarFromLayer(r, w)
cerr := r.Close()
if err != nil {
return err
}
return cerr
} | [
"func",
"ExportLayer",
"(",
"w",
"io",
".",
"Writer",
",",
"path",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"error",
"{",
"err",
":=",
"hcsshim",
".",
"ActivateLayer",
"(",
"driverInfo",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"hcsshim",
".",
"DeactivateLayer",
"(",
"driverInfo",
",",
"path",
")",
"\n\n",
"// Prepare and unprepare the layer to ensure that it has been initialized.",
"err",
"=",
"hcsshim",
".",
"PrepareLayer",
"(",
"driverInfo",
",",
"path",
",",
"parentLayerPaths",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"hcsshim",
".",
"UnprepareLayer",
"(",
"driverInfo",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"hcsshim",
".",
"NewLayerReader",
"(",
"driverInfo",
",",
"path",
",",
"parentLayerPaths",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"writeTarFromLayer",
"(",
"r",
",",
"w",
")",
"\n",
"cerr",
":=",
"r",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"cerr",
"\n",
"}"
] | // ExportLayer writes an OCI layer tar stream from the provided on-disk layer.
// The caller must specify the parent layers, if any, ordered from lowest to
// highest layer.
//
// The layer will be mounted for this process, so the caller should ensure that
// it is not currently mounted. | [
"ExportLayer",
"writes",
"an",
"OCI",
"layer",
"tar",
"stream",
"from",
"the",
"provided",
"on",
"-",
"disk",
"layer",
".",
"The",
"caller",
"must",
"specify",
"the",
"parent",
"layers",
"if",
"any",
"ordered",
"from",
"lowest",
"to",
"highest",
"layer",
".",
"The",
"layer",
"will",
"be",
"mounted",
"for",
"this",
"process",
"so",
"the",
"caller",
"should",
"ensure",
"that",
"it",
"is",
"not",
"currently",
"mounted",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/ociwclayer/export.go#L22-L50 | train |
Microsoft/hcsshim | internal/uvm/modify.go | Modify | func (uvm *UtilityVM) Modify(hcsModificationDocument interface{}) (err error) {
op := "uvm::Modify"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
return uvm.hcsSystem.Modify(hcsModificationDocument)
} | go | func (uvm *UtilityVM) Modify(hcsModificationDocument interface{}) (err error) {
op := "uvm::Modify"
log := logrus.WithFields(logrus.Fields{
logfields.UVMID: uvm.id,
})
log.Debug(op + " - Begin Operation")
defer func() {
if err != nil {
log.Data[logrus.ErrorKey] = err
log.Error(op + " - End Operation - Error")
} else {
log.Debug(op + " - End Operation - Success")
}
}()
return uvm.hcsSystem.Modify(hcsModificationDocument)
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"Modify",
"(",
"hcsModificationDocument",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"op",
":=",
"\"",
"\"",
"\n",
"log",
":=",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"UVMID",
":",
"uvm",
".",
"id",
",",
"}",
")",
"\n",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Data",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"log",
".",
"Error",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debug",
"(",
"op",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"uvm",
".",
"hcsSystem",
".",
"Modify",
"(",
"hcsModificationDocument",
")",
"\n",
"}"
] | // Modify modifies the compute system by sending a request to HCS. | [
"Modify",
"modifies",
"the",
"compute",
"system",
"by",
"sending",
"a",
"request",
"to",
"HCS",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/modify.go#L9-L25 | train |
Microsoft/hcsshim | internal/uvm/wait.go | Wait | func (uvm *UtilityVM) Wait() error {
err := uvm.hcsSystem.Wait()
// outputProcessingCancel will only cancel waiting for the vsockexec
// connection, it won't stop output processing once the connection is
// established.
if uvm.outputProcessingCancel != nil {
uvm.outputProcessingCancel()
}
uvm.waitForOutput()
return err
} | go | func (uvm *UtilityVM) Wait() error {
err := uvm.hcsSystem.Wait()
// outputProcessingCancel will only cancel waiting for the vsockexec
// connection, it won't stop output processing once the connection is
// established.
if uvm.outputProcessingCancel != nil {
uvm.outputProcessingCancel()
}
uvm.waitForOutput()
return err
} | [
"func",
"(",
"uvm",
"*",
"UtilityVM",
")",
"Wait",
"(",
")",
"error",
"{",
"err",
":=",
"uvm",
".",
"hcsSystem",
".",
"Wait",
"(",
")",
"\n\n",
"// outputProcessingCancel will only cancel waiting for the vsockexec",
"// connection, it won't stop output processing once the connection is",
"// established.",
"if",
"uvm",
".",
"outputProcessingCancel",
"!=",
"nil",
"{",
"uvm",
".",
"outputProcessingCancel",
"(",
")",
"\n",
"}",
"\n",
"uvm",
".",
"waitForOutput",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Wait waits synchronously for a utility VM to terminate. | [
"Wait",
"waits",
"synchronously",
"for",
"a",
"utility",
"VM",
"to",
"terminate",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/wait.go#L17-L29 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.