22 #include <linux/kernel.h>
23 #include <linux/kthread.h>
24 #include <linux/sched.h>
25 #include <linux/module.h>
26 #include <linux/errno.h>
27 #include <linux/fcntl.h>
28 #include <linux/net.h>
30 #include <linux/inet.h>
31 #include <linux/udp.h>
32 #include <linux/tcp.h>
33 #include <linux/string.h>
34 #include <linux/unistd.h>
35 #include <linux/slab.h>
36 #include <linux/netdevice.h>
37 #include <linux/skbuff.h>
38 #include <linux/file.h>
39 #include <linux/freezer.h>
41 #include <net/checksum.h>
45 #include <net/tcp_states.h>
46 #include <asm/uaccess.h>
47 #include <asm/ioctls.h>
48 #include <trace/events/skb.h>
50 #include <linux/module.h>
51 #include <linux/types.h>
52 #include <linux/uio.h>
53 #include <linux/unistd.h>
54 #include <linux/init.h>
56 #include <linux/random.h>
58 #include <linux/virgo_config.h>
78 char* get_host_from_cloud_Loadtrack();
79 char* get_host_from_cloud_PRG();
81 struct hostport* get_least_loaded_hostport_from_cloud()
89 char *LBAlgorithm =
"PRG";
91 if(strcmp(LBAlgorithm,
"Loadtrack")==0)
93 char* cloud_host = get_host_from_cloud_Loadtrack();
94 hopo->hostip=kstrdup(cloud_host, GFP_KERNEL);
95 printk(KERN_INFO
"get_least_loaded_hostport_from_cloud(): get_host_from_cloud_Loadtrack() returns host ip: %s \n",hopo->hostip);
98 else if(strcmp(LBAlgorithm,
"PRG")==0)
100 char* cloud_host = get_host_from_cloud_PRG();
101 printk(KERN_INFO
"get_least_loaded_hostport_from_cloud(): get_host_from_cloud_PRG() - cloud_host(before kstrdup): %s \n",cloud_host);
102 hopo->hostip=kstrdup(cloud_host, GFP_KERNEL);
103 printk(KERN_INFO
"get_least_loaded_hostport_from_cloud(): get_host_from_cloud_PRG() returns host ip: %s \n",hopo->hostip);
113 char* get_host_from_cloud_Loadtrack()
122 char* get_host_from_cloud_PRG()
124 unsigned int rand_int = get_random_int();
136 unsigned int rand_host_id = rand_int % num_cloud_nodes;
138 printk(KERN_INFO
"get_host_from_cloud_PRG() - get_random_int() returned %u \n",rand_int);
139 printk(KERN_INFO
"get_host_from_cloud_PRG() range mapping for %d cloud nodes(num_cloud_nodes) returns random integer %d, host ip(nodes_ip_addrs_in_cloud): %s \n",num_cloud_nodes,rand_host_id, node_ip_addrs_in_cloud[rand_host_id]);
140 return node_ip_addrs_in_cloud[rand_host_id];
145 asmlinkage
long sys_virgo_clone(
char* func_signature,
void *child_stack,
int flags,
void *arg)
183 struct sockaddr_in sin;
206 struct hostport* leastloadedhostport = get_least_loaded_hostport_from_cloud();
207 sin.sin_family=AF_INET;
208 in4_pton(leastloadedhostport->hostip, strlen(leastloadedhostport->hostip), &sin.sin_addr.s_addr,
'\0',NULL);
209 sin.sin_port=htons(leastloadedhostport->port);
212 iov.iov_len=
sizeof(buf);
213 msg.msg_name = (
struct sockaddr *) &sin;
214 msg.msg_namelen =
sizeof(
struct sockaddr);
215 msg.msg_iov = (
struct iovec *) &iov;
217 msg.msg_control = NULL;
218 msg.msg_controllen = 0;
223 strcpy(iov.iov_base, func_signature);
224 error = sock_create_kern(AF_INET, SOCK_STREAM, IPPROTO_TCP, &sock);
225 printk(KERN_INFO
"virgo_clone() syscall: created client kernel socket\n");
226 kernel_connect(sock, (
struct sockaddr*)&sin,
sizeof(sin) , 0);
227 printk(KERN_INFO
"virgo_clone() syscall: connected kernel client to virgo cloudexec kernel service\n ");
228 kernel_sendmsg(sock, &msg, &iov, nr, BUF_SIZE);
229 printk(KERN_INFO
"virgo_clone() syscall: sent message: %s \n", buf);
230 len = kernel_recvmsg(sock, &msg, &iov, nr, BUF_SIZE, msg.msg_flags);
231 printk(KERN_INFO
"virgo_clone() syscall: received message: %s \n", buf);
233 printk(KERN_INFO
"virgo_clone() syscall: le32_to_cpus(buf): %s \n", buf);
235 printk(KERN_INFO
"virgo_clone() syscall: virgo_clone() client socket_release() invoked\n");