Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
virgo_mempool.h
1  /***************************************************************************************
2 VIRGO - a linux module extension with CPU and Memory pooling with cloud capabilities
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 --------------------------------------------------------------------------------------------------
18 Copyright(C):
19 Srinivasan Kannan (alias) Ka.Shrinivaasan (alias) Shrinivas Kannan
20 Independent Open Source Developer, Researcher and Consultant
21 Ph: 9003082186, 9791165980
22 Open Source Products Profile(Krishna iResearch): http://sourceforge.net/users/ka_shrinivaasan
23 Personal website(research): https://sites.google.com/site/kuja27/
24 emails: ka.shrinivaasan@gmail.com, shrinivas.kannan@gmail.com, kashrinivaasan@live.com
25 --------------------------------------------------------------------------------------------------
26 
27 *****************************************************************************************/
28 
29 /*
30  VIRGO Memory Pooling related datastructures and driver ops
31 */
32 
33 #ifndef _VIRGO_MEMPOOL_H_
34 #define _VIRGO_MEMPOOL_H_
35 
36 #include <linux/ioport.h>
37 #include <linux/kobject.h>
38 #include <linux/klist.h>
39 #include <linux/list.h>
40 #include <linux/lockdep.h>
41 #include <linux/compiler.h>
42 #include <linux/types.h>
43 #include <linux/mutex.h>
44 #include <linux/pm.h>
45 #include <linux/atomic.h>
46 #include <linux/ratelimit.h>
47 #include <asm/device.h>
48 #include <linux/time.h>
49 
50 #include <linux/kernel.h>
51 #include <linux/kthread.h>
52 #include <linux/sched.h>
53 #include <linux/module.h>
54 #include <linux/errno.h>
55 #include <linux/fcntl.h>
56 #include <linux/net.h>
57 #include <linux/in.h>
58 #include <linux/inet.h>
59 #include <linux/udp.h>
60 #include <linux/tcp.h>
61 #include <linux/string.h>
62 #include <linux/unistd.h>
63 #include <linux/slab.h>
64 #include <linux/netdevice.h>
65 #include <linux/skbuff.h>
66 #include <linux/file.h>
67 #include <linux/freezer.h>
68 #include <net/sock.h>
69 #include <net/checksum.h>
70 #include <net/ip.h>
71 #include <net/ipv6.h>
72 #include <net/tcp.h>
73 #include <net/tcp_states.h>
74 #include <asm/uaccess.h>
75 #include <asm/ioctls.h>
76 #include <trace/events/skb.h>
77 
78 #include <linux/module.h>
79 #include <linux/types.h>
80 #include <linux/uio.h>
81 #include <linux/unistd.h>
82 /*#include <linux/init.h>*/
83 
84 #include <linux/sunrpc/types.h>
85 #include <linux/sunrpc/clnt.h>
86 #include <linux/sunrpc/xdr.h>
87 #include <linux/sunrpc/msg_prot.h>
88 #include <linux/sunrpc/svcsock.h>
89 #include <linux/sunrpc/stats.h>
90 #include <linux/sunrpc/xprt.h>
91 /*#include "sunrpc.h"*/
92 #include <linux/sunrpc/xprt.h>
93 /*#include "netns.h"*/
94 
95 #define BUF_SIZE 500
96 
97 struct hostport
98 {
99  char* hostip;
100  int port;
101 };
102 
104 {
105  int node_id;
106  struct hostport* hstprt;
107  void* addr;
108  /*
109  allocation unique id to uniquely identify all chunks for that cloud allocation
110  */
111  int cloud_alloc_id;
112  /*
113  For future use - reference count for this address
114  */
115  int refcount;
116 };
117 
119 {
120 
121  /*
122  address table of size 3000 for maximum of 3000 cloud nodes
123  */
124  struct virgo_address vtable[3000];
125 
126 
127  /*
128  for future use - if some search algorithm is needed for tree representation of transtable
129  fragments distributed geographically. Each fragment is for maximum of 3000 cloud nodes.
130  */
131  struct virgo_addr_transtable* vtable_left;
132  struct virgo_addr_transtable* vtable_right;
133 
134  /*
135  for future use - Set to 1 if virgo_addr_transtable fragment is persisted in disk
136  */
137  int fragment_is_disk_persisted;
138 
139  /*
140  Mutex to synchronize access to this address table fragment
141  */
142  struct mutex vtable_fragment_mutex;
143 };
144 
145 struct virgo_mempool_args
146 {
147  char* mempool_cmd;
148  char* mempool_args[3];
149  char* mempoolFunction;
150  char* ptr;
151  char* data;
152 };
153 
154 
155 struct hostport* get_least_loaded_hostport_from_cloud_mempool();
156 char* get_host_from_cloud_Loadtrack_mempool();
157 char* get_host_from_cloud_PRG_mempool();
158 char* int_to_str(int);
159 char* addr_to_str(char*);
160 char* str_to_addr(char*);
161 char* str_to_addr2(char* straddr);
162 
163 unsigned long addr_to_virgo_unique_id(struct virgo_address* vaddr);
164 struct virgo_address* virgo_unique_id_to_addr(unsigned long virgo_unique_id);
165 
166 typedef void* (*FPTR)(struct virgo_mempool_args* args);
167 
168 void var_sscanf(char *str, const char* fmt, ...);
169 
170 struct mutex virgo_mempool_mutex;
171 
172 FPTR toFuncPtr(char*);
173 struct virgo_mempool_args* parse_virgomempool_command(char* mempoolFunction);
174 /*struct virgo_mempool_args* parse_virgomempool_command(void* args);*/
175 
176 int virgocloudexec_mempool_create(void);
177 void* virgocloudexec_mempool_recvfrom(struct socket*);
178 int virgocloudexec_mempool_sendto(struct socket*, void* virgo_mempool_ret);
179 
180 int virgo_cloudexec_mempool_service(void* args);
181 void do_virgocloudexec_init(void);
182 
183 extern void* virgo_cloud_malloc_kernelspace(struct virgo_mempool_args* args);
184 extern void* virgo_cloud_free_kernelspace(struct virgo_mempool_args* args);
185 extern void* virgo_cloud_get_kernelspace(struct virgo_mempool_args* args);
186 extern void* virgo_cloud_set_kernelspace(struct virgo_mempool_args* args);
187 extern char* toKernelAddress(const char* str);
188 
190  int (*virgo_mempool_create)(void);
191  void* (*virgo_mempool_recvfrom)(struct socket*);
192  int (*virgo_mempool_sendto)(struct socket*,void* virgo_mempool_ret);
193 };
194 
195 static struct virgo_mempool_ops_t virgo_mempool_ops = {
196  .virgo_mempool_create = virgocloudexec_mempool_create,
197  .virgo_mempool_recvfrom = virgocloudexec_mempool_recvfrom,
198  .virgo_mempool_sendto = virgocloudexec_mempool_sendto
199 };
200 
202  const char* m_virgo_name;
203  struct module* m_virgo_owner;
204  struct virgo_ops_t* m_virgo_ops;
205 };
206 
207 static struct virgo_mempool_class_t virgo_mempool_class = {
208  .m_virgo_name = "virgo_mempool",
209  .m_virgo_owner = THIS_MODULE,
210  .m_virgo_ops = &virgo_mempool_ops
211 };
212 
213 /*
214 struct task_struct *task;
215 char* mempoolFunction;
216 int error;
217 char buffer[BUF_SIZE];
218 */
219 
220 static struct socket *sock;
221 
222 /*
223 static struct sockaddr_in sin;
224 int len=0;
225 */
226 
227 /*
228 Multithreaded VIRGO Kernel Service - commented global declarations and moved to xxxsendto() and xxxrecvfrom() with in module
229 ----------------------------------------------------------------------------------------------------------------------------
230 static struct socket *clientsock;
231 static struct kvec iov;
232 static struct msghdr msg = { NULL, };
233 int buflen=BUF_SIZE;
234 int nr=1;
235 int args=0;
236 */
237 
238 int parameterIsExecutable=2;
239 struct file* file_stdout;
240 
241 void print_buffer(char*);
242 int tokenize_list_of_ip_addrs(char* buf);
243 void read_virgo_config();
244 int kernel_space_func(void* args);
245 char* strip_control_M(char*);
246 
247 int virgo_mempool_client_thread(void* args);
248 char* toAddressString(char* ptr);
249 
250 char* generate_logical_timestamp(void);
251 
252 struct virgo_addr_transtable vtranstable;
253 int alloc_id=1;
254 int next_vtable_entry=0;
255 
256 extern int virgo_cloud_test_kernelspace(void* args);
257 
258 extern void push_request(struct virgo_request* vrq);
259 
260 
261 /*
262 New boolean flag added for using VIRGO cloud mempool for KingCobra. If set to 1, VIRGO cloudexec service
263 in mempooling driver is invoked in kernelspace.
264 */
265 
266 int use_as_kingcobra_service=1;
267 
268 /*
269 Following boolean flags have been added for various logical timestamp generation schemes to be prepended to the request header so that
270 no two requests in the VIRGO-KingCobra cloud have the same timestamps:
271 
272 1) EventNet_timestamp is not implemented and for future use with EventNet implementation in AsFer depending on its feasibility.
273 2) machine_timestamp is the timestamp generated by kernel macros in the request recipient machine
274 3) other_timestamp_cloudservice is for any other cloud based timestamp services like NTP etc., and not implemented
275 */
276 
277 int EventNet_timestamp=0;
278 int machine_timestamp=1;
279 int other_timestamp_cloudservice=0;
280 
281 
282 #endif /* _VIRGO_MEMPOOL_H_ */
283