Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new internal cmd package request struct to remove shimdiag package import #1153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,19 @@ func (ht *hcsTask) closeHost(ctx context.Context) {
}

func (ht *hcsTask) ExecInHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int, error) {
cmdReq := &cmd.CmdProcessRequest{
Args: req.Args,
Workdir: req.Workdir,
Terminal: req.Terminal,
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
}

if ht.host == nil {
return cmd.ExecInShimHost(ctx, req)
return cmd.ExecInShimHost(ctx, cmdReq)
}
return cmd.ExecInUvm(ctx, ht.host, req)
return cmd.ExecInUvm(ctx, ht.host, cmdReq)
}

func (ht *hcsTask) DumpGuestStacks(ctx context.Context) string {
Expand Down
10 changes: 9 additions & 1 deletion cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,18 @@ func (wpst *wcowPodSandboxTask) waitParentExit() {
}

func (wpst *wcowPodSandboxTask) ExecInHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int, error) {
cmdReq := &cmd.CmdProcessRequest{
Args: req.Args,
Workdir: req.Workdir,
Terminal: req.Terminal,
Stdin: req.Stdin,
Stdout: req.Stdout,
Stderr: req.Stderr,
}
if wpst.host == nil {
return 0, errTaskNotIsolated
}
return cmd.ExecInUvm(ctx, wpst.host, req)
return cmd.ExecInUvm(ctx, wpst.host, cmdReq)
}

func (wpst *wcowPodSandboxTask) DumpGuestStacks(ctx context.Context) string {
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down
10 changes: 10 additions & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ import (
"golang.org/x/sys/windows"
)

// CmdProcessRequest stores information on command requests made through this package.
type CmdProcessRequest struct {
Args []string
Workdir string
Terminal bool
Stdin string
Stdout string
Stderr string
}

// Cmd represents a command being prepared or run in a process host.
type Cmd struct {
// Host is the process host in which to launch the process.
Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (

"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/logfields"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/internal/uvm"
)

// ExecInUvm is a helper function used to execute commands specified in `req` inside the given UVM.
func ExecInUvm(ctx context.Context, vm *uvm.UtilityVM, req *shimdiag.ExecProcessRequest) (int, error) {
func ExecInUvm(ctx context.Context, vm *uvm.UtilityVM, req *CmdProcessRequest) (int, error) {
if len(req.Args) == 0 {
return 0, errors.New("missing command")
}
Expand All @@ -39,7 +38,7 @@ func ExecInUvm(ctx context.Context, vm *uvm.UtilityVM, req *shimdiag.ExecProcess

// ExecInShimHost is a helper function used to execute commands specified in `req` in the shim's
// hosting system.
func ExecInShimHost(ctx context.Context, req *shimdiag.ExecProcessRequest) (int, error) {
func ExecInShimHost(ctx context.Context, req *CmdProcessRequest) (int, error) {
if len(req.Args) == 0 {
return 0, errors.New("missing command")
}
Expand Down
5 changes: 2 additions & 3 deletions internal/devices/assigned_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/internal/uvm"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -72,11 +71,11 @@ func getChildrenDeviceLocationPaths(ctx context.Context, vm *uvm.UtilityVM, vmBu
go readCsPipeOutput(l, errChan, &pipeResults)

args := createDeviceUtilChildrenCommand(deviceUtilPath, vmBusInstanceID)
req := &shimdiag.ExecProcessRequest{
cmdReq := &cmd.CmdProcessRequest{
Args: args,
Stdout: p,
}
exitCode, err := cmd.ExecInUvm(ctx, vm, req)
exitCode, err := cmd.ExecInUvm(ctx, vm, cmdReq)
if err != nil {
return nil, errors.Wrapf(err, "failed to find devices with exit code %d", exitCode)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/devices/pnp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/log"
"github.com/Microsoft/hcsshim/internal/logfields"
"github.com/Microsoft/hcsshim/internal/shimdiag"
"github.com/Microsoft/hcsshim/internal/uvm"
"github.com/Microsoft/hcsshim/internal/winapi"
"github.com/pkg/errors"
Expand Down Expand Up @@ -43,10 +42,10 @@ func createPnPInstallDriverCommand(driverUVMPath string) []string {
// that installs a driver previously mounted into the uvm.
func execPnPInstallDriver(ctx context.Context, vm *uvm.UtilityVM, driverDir string) error {
args := createPnPInstallDriverCommand(driverDir)
req := &shimdiag.ExecProcessRequest{
cmdReq := &cmd.CmdProcessRequest{
Args: args,
}
exitCode, err := cmd.ExecInUvm(ctx, vm, req)
exitCode, err := cmd.ExecInUvm(ctx, vm, cmdReq)
if err != nil && exitCode != winapi.ERROR_NO_MORE_ITEMS {
return errors.Wrapf(err, "failed to install driver %s in uvm with exit code %d", driverDir, exitCode)
} else if exitCode == winapi.ERROR_NO_MORE_ITEMS {
Expand Down
1 change: 0 additions & 1 deletion test/vendor/github.com/Microsoft/hcsshim/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.