-
Notifications
You must be signed in to change notification settings - Fork 1
/
room.h
141 lines (123 loc) · 4.21 KB
/
room.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright (c) 2016 Mark Heily <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <memory>
#include "namespaceImport.h"
#include "Container.hpp"
#include "roomOptions.h"
extern FILE *logfile;
#include "logger.h"
struct RoomInstallParams {
string name;
string roomDir;
string installRoot;
string baseArchiveUri;
RoomOptions options;
};
enum e_RoomState {
ROOM_STATE_UNKNOWN,
ROOM_STATE_DEFINED,
ROOM_STATE_MOUNTED,
ROOM_STATE_RUNNING,
};
class Room {
public:
Room(const string& managerRoomDir, const string& name);
static void install(const struct RoomInstallParams& rip);
void createEmpty();
void editConfiguration();
void extractTarball(const string& baseTarball);
int forkAndExec(std::vector<std::string> execVec, const string& runAsUser);
void clone(const string& snapshot, const string& destRoom, const RoomOptions& roomOpt);
void killAllProcesses();
void snapshotCreate(const string& name);
void snapshotDestroy(const string& name);
void snapshotReceive(const string& name);
void start();
void stop();
void destroy();
static void destroy(const string& name);
void enter();
void send();
void mount();
void unmount();
void exec(std::vector<std::string> execVec, const string& runAsUser);
void exportArchive();
void printSnapshotList();
void transitionState(enum e_RoomState targetState);
// Remote push/pull functions
//void cloneFromOrigin(const string& uri);
//void pushToOrigin();
void setOriginUri(const string& uri);
// Cloned datasets need to use "zfs promote" in conjunction with "zfs receive"
void promoteClone(const string& cloneDataset);
static bool isValidName(const string& name)
{
try {
Room::validateName(name);
} catch (...) {
return false;
}
return true;
}
// The following methods can be used after create() but before install()
void setOsType(const string& osType);
RoomOptions& getRoomOptions() {
if (! areRoomOptionsLoaded ) {
throw std::logic_error("options not loaded");
}
return roomOptions;
}
void loadRoomOptions() {
roomOptions.load(roomOptionsPath);
areRoomOptionsLoaded = true;
}
void syncRoomOptions();
string getLatestSnapshot();
private:
//std::unique_ptr<Container> container = std::make_unique<Container>(Container::create());
Container* container;
bool areRoomOptionsLoaded = false;
RoomOptions roomOptions;
string roomDir; // copy of RoomManager::roomDir
string roomDataDir; // directory where this rooms data is stored
string chrootDir; // path to the root of the chroot environment
string roomName; // name of this room
string jailName; // name of the jail
uid_t ownerUid; // the uid of the jail owner
gid_t ownerGid; // the gid of the jail owner
string ownerLogin; // the login name from passwd(5) for the jail owner
string parentDataset; // the parent of roomDataset
string roomDataset; // the name of the ZFS dataset for the room
string zpoolName; // the ZFS pool the room lives in
string roomOptionsPath; // The path to the room options.json file
bool useZfs; // if true, create ZFS rooms
enum e_RoomState state = ROOM_STATE_UNKNOWN;
/* struct {
string tarballUri; // URI to the tarball for the root fs
} installOpts;*/
bool isClone() const {
return (roomOptions.templateSnapshot != "");
}
void determineInitialState();
void enterJail(const string& runAsUser);
bool jailExists();
void customizeWithoutRoot();
static void validateName(const string& name);
void pushResolvConf();
void getJailName();
static void parseRemoteUri(const string& uri, string& scheme, string& host, string& path);
string generateSnapshotName();
};