Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
DobbyRootfs.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2016 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 /*
20  * File: DobbyRootfs.h
21  *
22  */
23 #ifndef DOBBYROOTFS_H
24 #define DOBBYROOTFS_H
25 
26 #include "IDobbyUtils.h"
27 #include "ContainerId.h"
28 
29 #if defined(LEGACY_COMPONENTS)
30 #include "DobbySpecConfig.h"
31 #endif // LEGACY_COMPONENTS
32 
33 #include "DobbyBundleConfig.h"
34 
35 #include <sys/types.h>
36 
37 #include <memory>
38 #include <string>
39 
40 
41 class DobbyBundle;
42 
43 // -----------------------------------------------------------------------------
57 {
58 public:
59 #if defined(LEGACY_COMPONENTS)
60  DobbyRootfs(const std::shared_ptr<IDobbyUtils>& utils,
61  const std::shared_ptr<const DobbyBundle>& bundle,
62  const std::shared_ptr<const DobbySpecConfig>& config);
63 #endif //defined(LEGACY_COMPONENTS)
64  DobbyRootfs(const std::shared_ptr<IDobbyUtils>& utils,
65  const std::shared_ptr<const DobbyBundle>& bundle,
66  const std::shared_ptr<const DobbyBundleConfig>& config);
67  ~DobbyRootfs();
68 
69 public:
70  bool isValid() const;
71 
72  const std::string& path() const;
73  int dirFd() const;
74 
75  void setPersistence(bool persist);
76 
77  void unmountAllAt(const std::string& pathPrefix);
78 
79 private:
80  void cleanUp();
81 
82 #if defined(LEGACY_COMPONENTS)
83  bool createMountPoint(int dirfd, const std::string &path, bool isDirectory) const;
84 
85  bool createStandardMountPoints(int dirfd) const;
86 
87  bool constructRootfs(int dirfd,
88  const std::shared_ptr<const DobbySpecConfig>& config);
89 
90  bool createAndWriteFileAt(int dirFd,
91  const std::string& filePath,
92  const std::string& fileContents,
93  mode_t mode = 0644) const;
94 
95 #endif //defined(LEGACY_COMPONENTS)
96 
97 private:
98  const std::shared_ptr<IDobbyUtils> mUtilities;
99  const std::shared_ptr<const DobbyBundle> mBundle;
100  std::string mPath;
101  int mDirFd;
102  bool mPersist;
103 };
104 
105 
106 #endif // !defined(DOBBYROOTFS_H)
Simple class that just creates a subdir in the bundles directory.
Definition: DobbyBundle.h:46
Creates a directory populated with rootfs based on the supplied container config.
Definition: DobbyRootfs.h:57
DobbyRootfs(const std::shared_ptr< IDobbyUtils > &utils, const std::shared_ptr< const DobbyBundle > &bundle, const std::shared_ptr< const DobbyBundleConfig > &config)
Constructor that populates the object's member variables required internally by Dobby.
Definition: DobbyRootfs.cpp:109
void unmountAllAt(const std::string &pathPrefix)
Unmounts anything mounted at the given path prefix.
Definition: DobbyRootfs.cpp:194
void cleanUp()
Removes the rootfs directory and all it's contents if set persistence set to false.
Definition: DobbyRootfs.cpp:270