Skip to content

Commit

Permalink
paths: Resolve paths earlier
Browse files Browse the repository at this point in the history
Paths need to be resolved as soon as possible to ensure that the
hypervisor is launched with fully-resolved paths.

Fixes clearcontainers#607.

Signed-off-by: James O. D. Hunt <[email protected]>
  • Loading branch information
jodh-intel committed Sep 25, 2017
1 parent fef6ba9 commit 2c1ce71
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 422 deletions.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,18 @@ var commit = "$(COMMIT)"
// version is the runtime version.
var version = "$(VERSION)"

const defaultHypervisorPath = "$(QEMUPATH)"
const defaultImagePath = "$(IMAGEPATH)"
const defaultKernelPath = "$(KERNELPATH)"
var defaultHypervisorPath = "$(QEMUPATH)"
var defaultImagePath = "$(IMAGEPATH)"
var defaultKernelPath = "$(KERNELPATH)"
var defaultPauseRootPath = "$(PAUSEROOTPATH)"
var defaultShimPath = "$(SHIMPATH)"

const defaultKernelParams = "$(KERNELPARAMS)"
const defaultMachineType = "$(MACHINETYPE)"
const defaultPauseRootPath = "$(PAUSEROOTPATH)"
const defaultProxyURL = "$(PROXYURL)"
const defaultRootDirectory = "$(PKGRUNDIR)"
const defaultRuntimeLib = "$(PKGLIBDIR)"
const defaultRuntimeRun = "$(PKGRUNDIR)"
const defaultShimPath = "$(SHIMPATH)"
const pauseBinRelativePath = "$(PAUSEBINRELPATH)"

const defaultVCPUCount uint32 = $(DEFVCPUS)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ but can be enabled with a simple change to the [configuration](#Configuration) f
First, to determine the configuration file path for your host run:

```bash
$ cc-runtime cc-env | grep -A 2 'Runtime.Config.Location'
$ cc-runtime cc-env | grep -A 1 Runtime.Config
```

To enable the global log:
Expand Down
94 changes: 31 additions & 63 deletions cc-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package main
import (
"errors"
"os"
"path/filepath"
"strings"

"github.com/BurntSushi/toml"
Expand All @@ -31,26 +30,25 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.3"
const formatVersion = "1.0.4"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
// output format version
Version string
}

// PathInfo stores a path in its original, and fully resolved forms
type PathInfo struct {
Path string
Resolved string
}

// KernelInfo stores kernel details
type KernelInfo struct {
Location PathInfo
Path string
Parameters string
}

// ImageInfo stores root filesystem image details
type ImageInfo struct {
Path string
}

// CPUInfo stores host CPU details
type CPUInfo struct {
Vendor string
Expand All @@ -59,8 +57,7 @@ type CPUInfo struct {

// RuntimeConfigInfo stores runtime config details.
type RuntimeConfigInfo struct {
Location PathInfo
// Note a PathInfo as it may not exist (validly)
Path string
GlobalLogPath string
}

Expand All @@ -81,7 +78,7 @@ type RuntimeVersionInfo struct {
type HypervisorInfo struct {
MachineType string
Version string
Location PathInfo
Path string
}

// ProxyInfo stores proxy details
Expand All @@ -93,16 +90,16 @@ type ProxyInfo struct {

// ShimInfo stores shim details
type ShimInfo struct {
Type string
Version string
Location PathInfo
Type string
Version string
Path string
}

// AgentInfo stores agent details
type AgentInfo struct {
Type string
Version string
PauseBin PathInfo
Type string
Version string
PauseBinPath string
}

// DistroInfo stores host operating system distribution details.
Expand All @@ -127,7 +124,7 @@ type EnvInfo struct {
Meta MetaInfo
Runtime RuntimeInfo
Hypervisor HypervisorInfo
Image PathInfo
Image ImageInfo
Kernel KernelInfo
Proxy ProxyInfo
Shim ShimInfo
Expand All @@ -150,12 +147,7 @@ func getRuntimeInfo(configFile, logFile string, config oci.RuntimeConfig) Runtim

runtimeConfig := RuntimeConfigInfo{
GlobalLogPath: logFile,
Location: PathInfo{
// This path is already resolved by
// loadConfiguration().
Path: configFile,
Resolved: configFile,
},
Path: configFile,
}

return RuntimeInfo{
Expand Down Expand Up @@ -240,23 +232,16 @@ func getShimInfo(config oci.RuntimeConfig) (ShimInfo, error) {
}

shimPath := shimConfig.Path
shimPathResolved, err := filepath.EvalSymlinks(shimPath)
if err != nil {
return ShimInfo{}, err
}

version, err := getCommandVersion(shimPathResolved)
version, err := getCommandVersion(shimPath)
if err != nil {
version = unknown
}

ccShim := ShimInfo{
Type: string(config.ShimType),
Version: version,
Location: PathInfo{
Path: shimPath,
Resolved: shimPathResolved,
},
Path: shimPath,
}

return ccShim, nil
Expand All @@ -269,36 +254,28 @@ func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
}

agentBinPath := agentConfig.PauseBinPath
agentBinPathResolved, err := filepath.EvalSymlinks(agentBinPath)
if err != nil {
return AgentInfo{}, err
}

ccAgent := AgentInfo{
Type: string(config.AgentType),
Version: unknown,
PauseBin: PathInfo{
Path: agentBinPath,
Resolved: agentBinPathResolved,
},
Type: string(config.AgentType),
Version: unknown,
PauseBinPath: agentBinPath,
}

return ccAgent, nil
}

func getHypervisorInfo(config oci.RuntimeConfig, hypervisorDetails hypervisorDetails) HypervisorInfo {
version, err := getCommandVersion(hypervisorDetails.HypervisorPath)
func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
hypervisorPath := config.HypervisorConfig.HypervisorPath

version, err := getCommandVersion(hypervisorPath)
if err != nil {
version = unknown
}

return HypervisorInfo{
MachineType: config.HypervisorConfig.HypervisorMachineType,
Version: version,
Location: PathInfo{
Path: config.HypervisorConfig.HypervisorPath,
Resolved: hypervisorDetails.HypervisorPath,
},
Path: hypervisorPath,
}
}

Expand All @@ -307,11 +284,6 @@ func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env E

ccRuntime := getRuntimeInfo(configFile, logfilePath, config)

resolvedHypervisor, err := getHypervisorDetails(config)
if err != nil {
return EnvInfo{}, err
}

ccHost, err := getHostInfo()
if err != nil {
return EnvInfo{}, err
Expand All @@ -332,18 +304,14 @@ func getEnvInfo(configFile, logfilePath string, config oci.RuntimeConfig) (env E
return EnvInfo{}, err
}

hypervisor := getHypervisorInfo(config, resolvedHypervisor)
hypervisor := getHypervisorInfo(config)

image := PathInfo{
Path: config.HypervisorConfig.ImagePath,
Resolved: resolvedHypervisor.ImagePath,
image := ImageInfo{
Path: config.HypervisorConfig.ImagePath,
}

kernel := KernelInfo{
Location: PathInfo{
Path: config.HypervisorConfig.KernelPath,
Resolved: resolvedHypervisor.KernelPath,
},
Path: config.HypervisorConfig.KernelPath,
Parameters: strings.Join(vc.SerializeParams(config.HypervisorConfig.KernelParams, "="), " "),
}

Expand Down
Loading

0 comments on commit 2c1ce71

Please sign in to comment.