newContainerHandler returns a new container.ContainerHandler
( client *dclient.Client, containerdClient containerd.ContainerdClient, name string, machineInfoFactory info.MachineInfoFactory, fsInfo fs.FsInfo, storageDriver StorageDriver, storageDir string, cgroupSubsystems map[string]string, inHostNamespace bool, metadataEnvAllowList []string, dockerVersion []int, metrics container.MetricSet, thinPoolName string, thinPoolWatcher *devicemapper.ThinPoolWatcher, zfsWatcher *zfs.ZfsWatcher, )
| 125 | |
| 126 | // newContainerHandler returns a new container.ContainerHandler |
| 127 | func newContainerHandler( |
| 128 | client *dclient.Client, |
| 129 | containerdClient containerd.ContainerdClient, |
| 130 | name string, |
| 131 | machineInfoFactory info.MachineInfoFactory, |
| 132 | fsInfo fs.FsInfo, |
| 133 | storageDriver StorageDriver, |
| 134 | storageDir string, |
| 135 | cgroupSubsystems map[string]string, |
| 136 | inHostNamespace bool, |
| 137 | metadataEnvAllowList []string, |
| 138 | dockerVersion []int, |
| 139 | metrics container.MetricSet, |
| 140 | thinPoolName string, |
| 141 | thinPoolWatcher *devicemapper.ThinPoolWatcher, |
| 142 | zfsWatcher *zfs.ZfsWatcher, |
| 143 | ) (container.ContainerHandler, error) { |
| 144 | // Create the cgroup paths. |
| 145 | cgroupPaths := common.MakeCgroupPaths(cgroupSubsystems, name) |
| 146 | |
| 147 | // Generate the equivalent cgroup manager for this container. |
| 148 | cgroupManager, err := containerlibcontainer.NewCgroupManager(name, cgroupPaths) |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | |
| 153 | rootFs := "/" |
| 154 | if !inHostNamespace { |
| 155 | rootFs = "/rootfs" |
| 156 | storageDir = path.Join(rootFs, storageDir) |
| 157 | } |
| 158 | |
| 159 | id := dockerutil.ContainerNameToId(name) |
| 160 | |
| 161 | // Add the Containers dir where the log files are stored. |
| 162 | // FIXME: Give `otherStorageDir` a more descriptive name. |
| 163 | otherStorageDir := path.Join(storageDir, pathToContainersDir, id) |
| 164 | |
| 165 | var rootfsStorageDir, zfsFilesystem, zfsParent string |
| 166 | if storageDriver == ContainerdSnapshotterStorageDriver { |
| 167 | ctx := namespaces.WithNamespace(context.Background(), "moby") |
| 168 | cntr, err := containerdClient.LoadContainer(ctx, id) |
| 169 | if err != nil { |
| 170 | return nil, err |
| 171 | } |
| 172 | |
| 173 | var spec specs.Spec |
| 174 | if err := json.Unmarshal(cntr.Spec.Value, &spec); err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | rootfsStorageDir = spec.Root.Path |
| 178 | } else { |
| 179 | rwLayerID, err := getRwLayerID(id, storageDir, storageDriver, dockerVersion) |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | |
| 184 | // Determine the rootfs storage dir OR the pool name to determine the device. |
no test coverage detected
searching dependent graphs…