Skip to content

Commit 3ecedda

Browse files
authored
Merge pull request google#1345 from sjenning/cherry-pick-dm-fix
v0.23: cherry pick dm fixes
2 parents 7d22cf6 + c4173e8 commit 3ecedda

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

container/docker/factory.go

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"sync"
2424

25+
dockertypes "github.com/docker/engine-api/types"
2526
"github.com/google/cadvisor/container"
2627
"github.com/google/cadvisor/container/libcontainer"
2728
"github.com/google/cadvisor/devicemapper"
@@ -171,6 +172,31 @@ var (
171172
version_re = regexp.MustCompile(version_regexp_string)
172173
)
173174

175+
func startThinPoolWatcher(dockerInfo *dockertypes.Info) (*devicemapper.ThinPoolWatcher, error) {
176+
_, err := devicemapper.ThinLsBinaryPresent()
177+
if err != nil {
178+
return nil, err
179+
}
180+
181+
dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo)
182+
if err != nil {
183+
return nil, err
184+
}
185+
186+
dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo)
187+
if err != nil {
188+
return nil, err
189+
}
190+
191+
thinPoolWatcher, err := devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice)
192+
if err != nil {
193+
return nil, err
194+
}
195+
196+
go thinPoolWatcher.Start()
197+
return thinPoolWatcher, nil
198+
}
199+
174200
// Register root container before running this function!
175201
func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error {
176202
client, err := Client()
@@ -191,40 +217,11 @@ func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics c
191217
return fmt.Errorf("failed to get cgroup subsystems: %v", err)
192218
}
193219

194-
var (
195-
dockerStorageDriver = storageDriver(dockerInfo.Driver)
196-
thinPoolWatcher *devicemapper.ThinPoolWatcher = nil
197-
)
198-
199-
if dockerStorageDriver == devicemapperStorageDriver {
200-
_, err := devicemapper.ThinLsBinaryPresent()
201-
if err == nil {
202-
// If the storage driver is devicemapper, create and start a
203-
// ThinPoolWatcher to monitor the size of container CoW layers
204-
// with thin_ls.
205-
dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo)
206-
if err != nil {
207-
return fmt.Errorf("couldn't find device mapper thin pool name: %v", err)
208-
}
209-
210-
dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo)
211-
if err != nil {
212-
return fmt.Errorf("couldn't determine devicemapper metadata device: %v", err)
213-
}
214-
215-
thinPoolWatcher, err = devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice)
216-
if err != nil {
217-
return fmt.Errorf("couldn't create thin pool watcher: %v", err)
218-
}
219-
220-
go thinPoolWatcher.Start()
221-
} else {
222-
msg := []string{
223-
"Couldn't locate thin_ls binary; not starting thin pool watcher.",
224-
"Containers backed by thin pools will not show accurate usage.",
225-
"err: %v",
226-
}
227-
glog.Errorf(strings.Join(msg, " "), err)
220+
var thinPoolWatcher *devicemapper.ThinPoolWatcher
221+
if storageDriver(dockerInfo.Driver) == devicemapperStorageDriver {
222+
thinPoolWatcher, err = startThinPoolWatcher(dockerInfo)
223+
if err != nil {
224+
glog.Errorf("devicemapper filesystem stats will not be reported: %v", err)
228225
}
229226
}
230227

utils/docker/docker.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package docker
1616

1717
import (
1818
"fmt"
19+
"os"
1920
"strings"
2021

2122
dockertypes "github.com/docker/engine-api/types"
@@ -50,8 +51,19 @@ func DockerThinPoolName(info dockertypes.Info) (string, error) {
5051

5152
func DockerMetadataDevice(info dockertypes.Info) (string, error) {
5253
metadataDevice := DriverStatusValue(info.DriverStatus, DriverStatusMetadataFile)
53-
if len(metadataDevice) == 0 {
54-
return "", fmt.Errorf("Could not get the devicemapper metadata device")
54+
if len(metadataDevice) != 0 {
55+
return metadataDevice, nil
56+
}
57+
58+
poolName, err := DockerThinPoolName(info)
59+
if err != nil {
60+
return "", err
61+
}
62+
63+
metadataDevice = fmt.Sprintf("/dev/mapper/%s_tmeta", poolName)
64+
65+
if _, err := os.Stat(metadataDevice); err != nil {
66+
return "", err
5567
}
5668

5769
return metadataDevice, nil

0 commit comments

Comments
 (0)