-
Notifications
You must be signed in to change notification settings - Fork 5
/
pouch.h
164 lines (132 loc) · 3.74 KB
/
pouch.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Pouch.h
* - pouch container commands
*/
#ifndef POUCH_H
#define POUCH_H
typedef enum p_cmd {START, CONNECT, DISCONNECT, DESTROY, LIMIT, INFO, LIST} p_cmd;
#define CNTNAMESIZE 100
#define CNTARGSIZE 30
char *argv[] = { "sh", 0 };
/*
* Pouch cmd:
* - Pouch operation based on command type
* @input: container_name,p_cmd
* @output: none
* @return: 0 - OK, != 0 - FAILURE
*/
static int pouch_cmd(char* container_name, enum p_cmd);
/*
* Pouch fork:
* - Starting new container and execute shell inside, waiting for container to exit
* @input: container_name
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int pouch_fork(char* container_name);
/*
* Finding a tty:
* - Finds a free tty to be attached
* @input: none
* @output: tty_name
* @return: 0 - OK, <0 - FAILURE
*/
static int find_tty(char* tty_name);
/*
* Read from conf:
* - Reading container information from container's object
* @input: container_name
* @output: tty_name, pid
* @return: 0 - OK, <0 - FAILURE
*/
static int read_from_cconf(char* container_name, char* tty_name, int* pid);
/*
* Write to conf:
* - Writing container information to container's object
* @input: container_name, tty_name, pid
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int write_to_cconf(char* container_name, char* tty_name, int pid);
/*
* Init pouch cgroup:
* - Creates root cgroup dir if not exists and mounts cgroups fs
* @input: none
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int init_pouch_cgroup();
/*
* Create pouch cgroup:
* - Creates cgroup for a container inside root cgroup
* - Enables cpu.controller
* @input: cg_cname - cgroups fs path to a new cgroup
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int create_pouch_cgroup(char *cg_cname, char *cname);
/*
* Limit pouch cgroup:
* - Limits given state object for given container name and limit
* @input: container_name, cgroup_state_obj, limitation
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int pouch_limit_cgroup(char* container_name, char* cgroup_state_obj, char* limitation);
/*
* Prepate cgroup name:
* - Create a path in cgroup fs for corresponding cname
* @input: container_name
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int prepare_cgroup_cname(char* container_name, char* cgcname);
/*
* Write to pconf
* - pconf is a file that holds container name that is currently attached to a tty
* - pconf name is similar to tty name, having knows naming structure to open it
* - used for 'printing all containers list 'pouch list all' command
* @input: container_name, cgcname
* @return: 0 - OK, <0 - FAILURE
*/
static int write_to_pconf(char * ttyname, char * cname);
/*
* Remove from pconf
* - when container is deleted, tty is detatched, need to remove it's name from pconf
* @input: ttyname
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int remove_from_pconf(char * ttyname);
/*
* Read from pconf
* - get container name from provided tty name
* @input: ttyname
* @output: cname
* @return: 0 - OK, <0 - FAILURE
*/
static int read_from_pconf(char * ttyname, char * cname);
/*
* Print cotainers list
* - show all started containers and their state
* @input: none
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int print_clist();
/*
* Print given container information
* - show all started containers and their state
* @input: container_name,tty_name,pid
* @output: none
* @return: 0 - OK, <0 - FAILURE
*/
static int print_cinfo(char* container_name, char * tty_name, int pid);
/*
* Get connected container name
* @input: none
* @output: cname
* @return: 0 - OK, <0 - FAILURE
*/
static int get_connected_cname(char * cname);
#endif // POUCH_H