func startThinPoolWatcher(dockerInfo *dockertypes.Info) (*devicemapper.ThinPoolWatcher, error) { _, err := devicemapper.ThinLsBinaryPresent() if err != nil { return nil, err } if err := ensureThinLsKernelVersion(machine.KernelVersion()); err != nil { return nil, err } dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo) if err != nil { return nil, err } dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo) if err != nil { return nil, err } thinPoolWatcher, err := devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice) if err != nil { return nil, err } go thinPoolWatcher.Start() return thinPoolWatcher, nil }
// Register root container before running this function! func Register(factory info.MachineInfoFactory, fsInfo fs.FsInfo, ignoreMetrics container.MetricSet) error { client, err := Client() if err != nil { return fmt.Errorf("unable to communicate with docker daemon: %v", err) } dockerInfo, err := ValidateInfo() if err != nil { return fmt.Errorf("failed to validate Docker info: %v", err) } // Version already validated above, assume no error here. dockerVersion, _ := parseDockerVersion(dockerInfo.ServerVersion) cgroupSubsystems, err := libcontainer.GetCgroupSubsystems() if err != nil { return fmt.Errorf("failed to get cgroup subsystems: %v", err) } var ( dockerStorageDriver = storageDriver(dockerInfo.Driver) thinPoolWatcher *devicemapper.ThinPoolWatcher = nil ) if dockerStorageDriver == devicemapperStorageDriver { // If the storage drive is devicemapper, create and start a // ThinPoolWatcher to monitor the size of container CoW layers with // thin_ls. dockerThinPoolName, err := dockerutil.DockerThinPoolName(*dockerInfo) if err != nil { return fmt.Errorf("couldn't find device mapper thin pool name: %v", err) } dockerMetadataDevice, err := dockerutil.DockerMetadataDevice(*dockerInfo) if err != nil { return fmt.Errorf("couldn't determine devicemapper metadata device") } thinPoolWatcher = devicemapper.NewThinPoolWatcher(dockerThinPoolName, dockerMetadataDevice) go thinPoolWatcher.Start() } glog.Infof("registering Docker factory") f := &dockerFactory{ cgroupSubsystems: cgroupSubsystems, client: client, dockerVersion: dockerVersion, fsInfo: fsInfo, machineInfoFactory: factory, storageDriver: storageDriver(dockerInfo.Driver), storageDir: RootDir(), ignoreMetrics: ignoreMetrics, thinPoolWatcher: thinPoolWatcher, } container.RegisterContainerHandlerFactory(f, []watcher.ContainerWatchSource{watcher.Raw}) return nil }