Apache Mesos
volume.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __NVIDIA_VOLUME_HPP__
18 #define __NVIDIA_VOLUME_HPP__
19 
20 #include <string>
21 
22 #include <mesos/mesos.hpp>
23 
24 #include <mesos/docker/spec.hpp>
25 
26 #include <stout/try.hpp>
27 
28 namespace mesos {
29 namespace internal {
30 namespace slave {
31 
32 // Provides a consolidated volume of binaries and libraries
33 // from the user-space portion of the Nvidia GPU drivers.
34 // We follow the approach taken by Nvidia's docker plugin:
35 // https://github.com/NVIDIA/nvidia-docker/
37 {
38 public:
39  // Returns the Nvidia volume. Once we create the volume it is
40  // never deleted until reboot. This means that if an agent
41  // crashes and tries to recreate the volume it will only ever
42  // *add* new libraries to it (nothing will be deleted from it).
43  // This prevents already-running containers from having
44  // whatever libraries they depend on ripped out from under them.
45  static Try<NvidiaVolume> create();
46 
47  const std::string& HOST_PATH() const;
48  const std::string& CONTAINER_PATH() const;
49 
50  // Returns whether the container based on a docker image
51  // should have the volume injected. We follow nvidia-docker's
52  // label conventions:
53  // https://github.com/NVIDIA/nvidia-docker/wiki/Image-inspection
54  bool shouldInject(const ::docker::spec::v1::ImageManifest& manifest) const;
55 
56 private:
57  NvidiaVolume() = delete;
58 
59  NvidiaVolume(const std::string& _hostPath,
60  const std::string& _containerPath)
61  : hostPath(_hostPath),
62  containerPath(_containerPath) {}
63 
64  std::string hostPath;
65  std::string containerPath;
66 };
67 
68 } // namespace slave {
69 } // namespace internal {
70 } // namespace mesos {
71 
72 #endif // __NVIDIA_GPU_VOLUME_HPP__
Definition: check.hpp:33
URI manifest(const std::string &repository, const std::string &reference, const std::string &registry, const Option< std::string > &scheme=None(), const Option< int > &port=None())
Definition: docker.hpp:47
static Try< NvidiaVolume > create()
bool shouldInject(const ::docker::spec::v1::ImageManifest &manifest) const
const std::string & HOST_PATH() const
Definition: spec.hpp:30
const std::string & CONTAINER_PATH() const
Definition: attributes.hpp:24
Definition: volume.hpp:36