Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
Storage.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 2020 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: Storage.h
21 *
22 */
23#ifndef STORAGE_H
24#define STORAGE_H
25
26#include "LoopMountDetails.h"
27#include "DynamicMountDetails.h"
28#include "MountOwnerDetails.h"
29
30#include <RdkPluginBase.h>
31
32#include <sys/types.h>
33#include <netinet/in.h>
34#include <unistd.h>
35#include <string>
36
37//#define ENABLE_TESTS 1
38
44class Storage : public RdkPluginBase
45{
46public:
47 Storage(std::shared_ptr<rt_dobby_schema>& containerConfig,
48 const std::shared_ptr<DobbyRdkPluginUtils> &utils,
49 const std::string &rootfsPath);
50
51public:
52 inline std::string name() const override
53 {
54 return mName;
55 };
56
57 // Override to return the appropriate hints for what we implement
58 unsigned hookHints() const override;
59
60
61public:
62 // This hook attaches img file to loop device and mount it inside
63 // temp mount point (within container rootfs)
64 bool preCreation() override;
65
66 // This hook changes privileges of the mounted directories
67 bool createRuntime() override;
68
69 // This hook mounts temp directory to the proper one
70 bool createContainer() override;
71
72#ifdef ENABLE_TESTS
73 // Used only for testing purpose
74 bool startContainer() override;
75#endif // ENABLE_TESTS
76
77 // Cleaning up temp mount
78 bool postStart() override;
79
80 // In this hook there should be deletion of img file when non-
81 // persistent option is selected
82 bool postStop() override;
83
84public:
85 std::vector<std::string> getDependencies() const override;
86
87private:
88 std::vector<LoopMountProperties> getLoopMounts() const;
89 std::vector<std::unique_ptr<LoopMountDetails>> getLoopMountDetails() const;
90
91 std::vector<DynamicMountProperties> getDynamicMounts() const;
92 std::vector<std::unique_ptr<DynamicMountDetails>> getDynamicMountDetails() const;
93
94 std::vector<MountOwnerProperties> getMountOwners() const;
95 std::vector<std::unique_ptr<MountOwnerDetails>> getMountOwnerDetails() const;
96
97 void setupOwnerIds(uid_t& uid, gid_t& gid) const;
98
99private:
100 const std::string mName;
101 std::shared_ptr<rt_dobby_schema> mContainerConfig;
102 const std::string mRootfsPath;
103 const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
104#ifndef USE_OPEN_TREE_FOR_DYNAMIC_MOUNTS
105 std::string mMountPointInsideContainer;
106 std::string mTempMountPointOutsideContainer;
107#endif
108 uint32_t getMappedId(uint32_t id, rt_defs_id_mapping **mapping, size_t mapping_len) const;
109};
110
111#endif // !defined(STORAGE_H)
Basic object that provides the default overrides for a plugin.
Definition RdkPluginBase.h:34
Dobby RDK Storage Plugin.
Definition Storage.h:45
bool postStop() override
OCI Hook - Run in host namespace. Confusing name - is run when a container is DELETED.
Definition Storage.cpp:269
std::string name() const override
Should return the name of the plugin.
Definition Storage.h:52
unsigned hookHints() const override
Set the bit flags for which hooks we're going to use.
Definition Storage.cpp:63
std::vector< std::unique_ptr< LoopMountDetails > > getLoopMountDetails() const
Create loop mount details vector from all loopback mounts in config.
Definition Storage.cpp:353
bool postStart() override
OCI Hook - Run in container namespace.
Definition Storage.cpp:245
bool createContainer() override
OCI Hook - Run in container namespace. Paths resolve to host namespace.
Definition Storage.cpp:174
void setupOwnerIds(uid_t &uid, gid_t &gid) const
Gets userId and groupId.
Definition Storage.cpp:656
std::vector< MountOwnerProperties > getMountOwners() const
Reads container config to obtain source path on host, userId, groupId and recursive options....
Definition Storage.cpp:608
bool preCreation() override
OCI Hook - Run in host namespace.
Definition Storage.cpp:81
std::vector< LoopMountProperties > getLoopMounts() const
Reads container config and creates all loop mounts in LoopMountProperties type objects.
Definition Storage.cpp:394
std::vector< std::string > getDependencies() const override
Should return the names of the plugins this plugin depends on.
Definition Storage.cpp:331
bool createRuntime() override
OCI Hook - Run in host namespace.
Definition Storage.cpp:126
std::vector< std::unique_ptr< DynamicMountDetails > > getDynamicMountDetails() const
Create dynamic mount details vector from all dynamic mounts in config.
Definition Storage.cpp:487
uint32_t getMappedId(uint32_t id, rt_defs_id_mapping **mapping, size_t mapping_len) const
Gets userId or groupId based on mappings.
Definition Storage.cpp:695
std::vector< std::unique_ptr< MountOwnerDetails > > getMountOwnerDetails() const
Create mount owner details vector from all mount owners in config.
Definition Storage.cpp:566
std::vector< DynamicMountProperties > getDynamicMounts() const
Reads container config and creates all dynamic mounts in DynamicMountProperties type objects.
Definition Storage.cpp:522