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

Cherrypick #1097 into release-0.21 branch and bump tag to v0.21.1 #1098

Merged
merged 4 commits into from
Feb 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix fs stats handling for non-aufs storage drivers.
Signed-off-by: Vishnu kannan <vishnuk@google.com>
  • Loading branch information
vishh committed Feb 6, 2016
commit 47dfc46ee4b6927dc49bea59bf83d83e120f2360
2 changes: 1 addition & 1 deletion client/v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (self *Client) attributesUrl() string {
}

func (self *Client) statsUrl(name string) string {
return path.Join(self.baseUrl, "stats", name)
return self.baseUrl + path.Join("stats", name)
}

func (self *Client) httpGetResponse(postData interface{}, urlPath, infoName string) ([]byte, error) {
Expand Down
47 changes: 7 additions & 40 deletions container/docker/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package docker

import (
"encoding/json"
"flag"
"fmt"
"path"
Expand Down Expand Up @@ -106,8 +105,8 @@ const (
type dockerFactory struct {
machineInfoFactory info.MachineInfoFactory

storageDriver storageDriver
storageDriverDir string
storageDriver storageDriver
storageDir string

client *docker.Client

Expand Down Expand Up @@ -138,7 +137,7 @@ func (self *dockerFactory) NewContainerHandler(name string, inHostNamespace bool
self.machineInfoFactory,
self.fsInfo,
self.storageDriver,
self.storageDriverDir,
self.storageDir,
&self.cgroupSubsystems,
inHostNamespace,
metadataEnvs,
Expand Down Expand Up @@ -215,37 +214,6 @@ func parseDockerVersion(full_version_string string) ([]int, error) {
return version_array, nil
}

func getStorageDir(dockerInfo *docker.Env) (string, error) {
storageDriverInfo := dockerInfo.GetList("DriverStatus")
if len(storageDriverInfo) == 0 {
return "", fmt.Errorf("failed to find docker storage driver options")
}

var storageDir string
for _, data := range storageDriverInfo {
if data == "" {
continue
}
var parts [][]string
if err := json.Unmarshal([]byte(data), &parts); err != nil {
return "", fmt.Errorf("failed to parse docker storage driver options - %+v", data)
}
for _, part := range parts {
if len(part) != 2 {
return "", fmt.Errorf("failed to parse docker storage driver options - %+v", part)
}
if part[0] == dockerRootDirKey {
storageDir = part[1]
break
}
}
}
if storageDir == "" {
return "", fmt.Errorf("failed to find docker storage directory from docker info. Expected key %q in storage driver info %v", dockerRootDirKey, storageDriverInfo)
}
return storageDir, nil
}

// Register root container before running this function!
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
if UseSystemd() {
Expand Down Expand Up @@ -291,10 +259,9 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
return fmt.Errorf("failed to find docker storage driver")
}

storageDir, err := getStorageDir(information)
if err != nil {
glog.V(2).Infof("failed to detect storage directory from docker. Defaulting to using the value in --docker_root: %q", err, *dockerRootDir)
storageDir = path.Join(*dockerRootDir, sd)
storageDir := information.Get("DockerRootDir")
if storageDir == "" {
storageDir = *dockerRootDir
}
cgroupSubsystems, err := libcontainer.GetCgroupSubsystems()
if err != nil {
Expand All @@ -309,7 +276,7 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo) error {
fsInfo: fsInfo,
machineInfoFactory: factory,
storageDriver: storageDriver(sd),
storageDriverDir: storageDir,
storageDir: storageDir,
}
container.RegisterContainerHandlerFactory(f)
return nil
Expand Down
19 changes: 10 additions & 9 deletions container/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ type dockerContainerHandler struct {
fsHandler fsHandler
}

func getRwLayerID(containerID, storageDriverDir string, dockerVersion []int) (string, error) {
func getRwLayerID(containerID, storageDir string, sd storageDriver, dockerVersion []int) (string, error) {
const (
// Docker version >=1.10.0 have a randomized ID for the root fs of a container.
randomizedRWLayerMinorVersion = 10
// Directory where the file containinig the randomized ID of the root fs of a container is stored in versions >= 1.10.0
rwLayerIDDir = "../image/aufs/layerdb/mounts/"
rwLayerIDFile = "mount-id"
rwLayerIDDirTemplate = "image/%s/layerdb/mounts/"
rwLayerIDFile = "mount-id"
)
if (dockerVersion[0] <= 1) && (dockerVersion[1] < randomizedRWLayerMinorVersion) {
return containerID, nil
}
bytes, err := ioutil.ReadFile(path.Join(storageDriverDir, rwLayerIDDir, containerID, rwLayerIDFile))

bytes, err := ioutil.ReadFile(path.Join(storageDir, "image", string(sd), "layerdb", "mounts", containerID, rwLayerIDFile))
if err != nil {
return "", fmt.Errorf("failed to identify the read-write layer ID for container %q. - %v", containerID, err)
}
Expand All @@ -107,7 +108,7 @@ func newDockerContainerHandler(
machineInfoFactory info.MachineInfoFactory,
fsInfo fs.FsInfo,
storageDriver storageDriver,
storageDriverDir string,
storageDir string,
cgroupSubsystems *containerlibcontainer.CgroupSubsystems,
inHostNamespace bool,
metadataEnvs []string,
Expand Down Expand Up @@ -135,18 +136,18 @@ func newDockerContainerHandler(
id := ContainerNameToDockerId(name)

// Add the Containers dir where the log files are stored.
otherStorageDir := path.Join(path.Dir(storageDriverDir), pathToContainersDir, id)
otherStorageDir := path.Join(storageDir, pathToContainersDir, id)

rwLayerID, err := getRwLayerID(id, storageDriverDir, dockerVersion)
rwLayerID, err := getRwLayerID(id, storageDir, storageDriver, dockerVersion)
if err != nil {
return nil, err
}
var rootfsStorageDir string
switch storageDriver {
case aufsStorageDriver:
rootfsStorageDir = path.Join(storageDriverDir, aufsRWLayer, rwLayerID)
rootfsStorageDir = path.Join(storageDir, string(aufsStorageDriver), aufsRWLayer, rwLayerID)
case overlayStorageDriver:
rootfsStorageDir = path.Join(storageDriverDir, rwLayerID)
rootfsStorageDir = path.Join(storageDir, string(overlayStorageDriver), rwLayerID)
}

handler := &dockerContainerHandler{
Expand Down
6 changes: 3 additions & 3 deletions container/docker/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestStorageDirDetectionWithOldVersions(t *testing.T) {
as := assert.New(t)
rwLayer, err := getRwLayerID("abcd", "/", []int{1, 9, 0})
rwLayer, err := getRwLayerID("abcd", "/", aufsStorageDriver, []int{1, 9, 0})
as.Nil(err)
as.Equal(rwLayer, "abcd")
}
Expand All @@ -40,10 +40,10 @@ func TestStorageDirDetectionWithNewVersions(t *testing.T) {
randomIDPath := path.Join(testDir, "image/aufs/layerdb/mounts/", containerID)
as.Nil(os.MkdirAll(randomIDPath, os.ModePerm))
as.Nil(ioutil.WriteFile(path.Join(randomIDPath, "mount-id"), []byte(randomizedID), os.ModePerm))
rwLayer, err := getRwLayerID(containerID, path.Join(testDir, "aufs"), []int{1, 10, 0})
rwLayer, err := getRwLayerID(containerID, testDir, "aufs", []int{1, 10, 0})
as.Nil(err)
as.Equal(rwLayer, randomizedID)
rwLayer, err = getRwLayerID(containerID, path.Join(testDir, "aufs"), []int{1, 10, 0})
rwLayer, err = getRwLayerID(containerID, testDir, "aufs", []int{1, 10, 0})
as.Nil(err)
as.Equal(rwLayer, randomizedID)

Expand Down