From eea18abbb891a70aae6f630c0f67092a25779fdc Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Fri, 3 Sep 2021 18:25:21 -0700 Subject: [PATCH] Add new internal cmd package request struct to remove shimdiag package import Signed-off-by: Kathryn Baldauf --- cmd/containerd-shim-runhcs-v1/task_hcs.go | 13 +++++++++++-- .../task_wcow_podsandbox.go | 10 +++++++++- go.sum | 1 - internal/cmd/cmd.go | 10 ++++++++++ internal/cmd/diag.go | 5 ++--- internal/devices/assigned_devices.go | 5 ++--- internal/devices/pnp.go | 5 ++--- test/vendor/github.com/Microsoft/hcsshim/go.sum | 1 - .../Microsoft/hcsshim/internal/cmd/cmd.go | 10 ++++++++++ .../Microsoft/hcsshim/internal/cmd/diag.go | 5 ++--- .../hcsshim/internal/devices/assigned_devices.go | 5 ++--- .../Microsoft/hcsshim/internal/devices/pnp.go | 5 ++--- 12 files changed, 52 insertions(+), 23 deletions(-) diff --git a/cmd/containerd-shim-runhcs-v1/task_hcs.go b/cmd/containerd-shim-runhcs-v1/task_hcs.go index 484b21cf1a..9f6f5a9a11 100644 --- a/cmd/containerd-shim-runhcs-v1/task_hcs.go +++ b/cmd/containerd-shim-runhcs-v1/task_hcs.go @@ -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 { diff --git a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go index e8a5174945..b637ea58e7 100644 --- a/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go +++ b/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go @@ -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 { diff --git a/go.sum b/go.sum index 5ac7ffb111..00b5d3b667 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 685e703c3d..e91cf83b32 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -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. diff --git a/internal/cmd/diag.go b/internal/cmd/diag.go index 4d338707c0..092fcc207f 100644 --- a/internal/cmd/diag.go +++ b/internal/cmd/diag.go @@ -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") } @@ -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") } diff --git a/internal/devices/assigned_devices.go b/internal/devices/assigned_devices.go index 8cdc3d9419..0e2d06be62 100644 --- a/internal/devices/assigned_devices.go +++ b/internal/devices/assigned_devices.go @@ -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" ) @@ -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) } diff --git a/internal/devices/pnp.go b/internal/devices/pnp.go index 1cb67326f4..1bad6ab685 100644 --- a/internal/devices/pnp.go +++ b/internal/devices/pnp.go @@ -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" @@ -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 { diff --git a/test/vendor/github.com/Microsoft/hcsshim/go.sum b/test/vendor/github.com/Microsoft/hcsshim/go.sum index 5ac7ffb111..00b5d3b667 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/go.sum +++ b/test/vendor/github.com/Microsoft/hcsshim/go.sum @@ -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= diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go index 685e703c3d..e91cf83b32 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/cmd.go @@ -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. diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/diag.go b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/diag.go index 4d338707c0..092fcc207f 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/diag.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/cmd/diag.go @@ -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") } @@ -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") } diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/devices/assigned_devices.go b/test/vendor/github.com/Microsoft/hcsshim/internal/devices/assigned_devices.go index 8cdc3d9419..0e2d06be62 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/devices/assigned_devices.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/devices/assigned_devices.go @@ -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" ) @@ -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) } diff --git a/test/vendor/github.com/Microsoft/hcsshim/internal/devices/pnp.go b/test/vendor/github.com/Microsoft/hcsshim/internal/devices/pnp.go index 1cb67326f4..1bad6ab685 100644 --- a/test/vendor/github.com/Microsoft/hcsshim/internal/devices/pnp.go +++ b/test/vendor/github.com/Microsoft/hcsshim/internal/devices/pnp.go @@ -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" @@ -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 {