Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
virgo_queue.h
1 /***************************************************************************************
2 VIRGO - a linux module extension with CPU and Memory pooling with cloud capabilities
3 
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 --------------------------------------------------------------------------------------------------
19 Copyright (C):
20 Srinivasan Kannan (alias) Ka.Shrinivaasan (alias) Shrinivas Kannan
21 Independent Open Source Developer, Researcher and Consultant
22 Ph: 9789346927, 9003082186, 9791165980
23 Open Source Products Profile(Krishna iResearch): http://sourceforge.net/users/ka_shrinivaasan, https://www.ohloh.net/accounts/ka_shrinivaasan
24 Personal website(research): https://sites.google.com/site/kuja27/
25 emails: ka.shrinivaasan@gmail.com, shrinivas.kannan@gmail.com, kashrinivaasan@live.com
26 --------------------------------------------------------------------------------------------------
27 
28 *****************************************************************************************/
29 
30 /*
31  VIRGO queue related datastructures
32 */
33 
34 #ifndef _VIRGO_QUEUE_H_
35 #define _VIRGO_QUEUE_H_
36 
37 #define VIRGO_QUEUE_SZ 10000
38 
39 #include <linux/ioport.h>
40 #include <linux/kobject.h>
41 #include <linux/klist.h>
42 #include <linux/list.h>
43 #include <linux/lockdep.h>
44 #include <linux/compiler.h>
45 #include <linux/types.h>
46 #include <linux/mutex.h>
47 #include <linux/pm.h>
48 #include <linux/atomic.h>
49 #include <linux/ratelimit.h>
50 #include <asm/device.h>
51 
52 #include <linux/kernel.h>
53 #include <linux/kthread.h>
54 #include <linux/sched.h>
55 #include <linux/module.h>
56 #include <linux/errno.h>
57 #include <linux/fcntl.h>
58 #include <linux/net.h>
59 #include <linux/in.h>
60 #include <linux/inet.h>
61 #include <linux/udp.h>
62 #include <linux/tcp.h>
63 #include <linux/string.h>
64 #include <linux/unistd.h>
65 #include <linux/slab.h>
66 #include <linux/netdevice.h>
67 #include <linux/skbuff.h>
68 #include <linux/file.h>
69 #include <linux/freezer.h>
70 #include <net/sock.h>
71 #include <net/checksum.h>
72 #include <net/ip.h>
73 #include <net/ipv6.h>
74 #include <net/tcp.h>
75 #include <net/tcp_states.h>
76 #include <asm/uaccess.h>
77 #include <asm/ioctls.h>
78 #include <trace/events/skb.h>
79 
80 #include <linux/module.h>
81 #include <linux/types.h>
82 #include <linux/uio.h>
83 #include <linux/unistd.h>
84 #include <linux/workqueue.h>
85 /*#include <linux/init.h>*/
86 
87 #include <linux/sunrpc/types.h>
88 #include <linux/sunrpc/clnt.h>
89 #include <linux/sunrpc/xdr.h>
90 #include <linux/sunrpc/msg_prot.h>
91 #include <linux/sunrpc/svcsock.h>
92 #include <linux/sunrpc/stats.h>
93 #include <linux/sunrpc/xprt.h>
94 /*#include "sunrpc.h"*/
95 #include <linux/sunrpc/xprt.h>
96 /*#include "netns.h"*/
97 
98 #include <linux/kingcobra.h>
99 
101 {
102  char* data;
103  struct virgo_request* next;
104 };
105 
106 int queue_front=0;
107 int queue_end=0;
108 
110 {
111  char* data;
112  struct work_struct work;
113 };
114 
115 /*
116 This is a boolean flag that flips between a native local implementation of a queue and a
117 linux kernel implementation of workqueue.
118 */
119 int use_workqueue=1;
120 
121 /*
122 This is a boolean flag that enables use of VIRGO linux workqueue for KingCobra BFT messaging with queues and arbiters.
123 */
124 int use_for_kingcobra_messaging=1;
125 
126 /*
127 This is boolean flag that enables KingCobra in userspace through upcall from kernel using call_usermodehelper().
128 Obviously circuitous but might have necessity in some userspace applications. By default, KingCobra is in kernel space.
129 */
130 int kingcobra_in_userspace=0;
131 
132 /*
133 Persist KingCobra queue contents to disk - Guaranteed queue vs in-memory queue
134 with other declarations for file data segment and queue file offset.
135 */
136 int kingcobra_disk_persistence=1;
137 loff_t request_reply_queue_pos=0;
138 mm_segment_t fs;
139 
140 void* work_args;
141 
142 void virgo_workqueue_handler(struct work_struct* w);
143 static DECLARE_WORK(virgo_work, virgo_workqueue_handler);
144 static struct workqueue_struct *virgo_kernel_wq=NULL;
145 
146 struct file* file_stdout;
147 
148 void virgo_workqueue_handler(struct work_struct* w)
149 {
150  int ret;
151  char* argv[5];
152  char* envp[5];
153  mm_segment_t fs;
154  struct virgo_workqueue_request *vwqrq=container_of(w, struct virgo_workqueue_request, work);
155  printk(KERN_INFO "virgo_workqueue_handler(): invoked for work_struct w=%p, dequeueing enqueued vwqrq->data=%s",w,vwqrq->data);
156 
157  /*if(strncmp(vwqrq->data,"KingCobra:",10)==0)*/
158  if(use_for_kingcobra_messaging==1)
159  {
160  if(kingcobra_in_userspace==1)
161  {
162  fs=get_fs();
163  set_fs(get_ds());
164 
165  file_stdout=filp_open("/home/kashrinivaasan/linux-3.7.8/drivers/virgo/queuing/kingcobra_usermode_log.txt", O_RDWR|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR);
166  /*
167  fd_install(1,file_stdout);
168  fd_install(2,file_stdout);
169  */
170 
171  argv[1]=kstrdup("_Z24KingCobra_ServiceRequestPv",GFP_ATOMIC);
172  argv[2]=kstrdup(vwqrq->data,GFP_ATOMIC);
173  envp[0]="PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games::/home/kashrinivaasan/linux-3.7.8/drivers/virgo/queuing/";
174  envp[1]="HOME=/home/kashrinivaasan";
175  envp[2]=NULL;
176  printk(KERN_INFO "virgo_workqueue_handler(): kingcobra_in_userspace=1, before invoking call_usermodehelper() for KingCobra \n");
177  ret=call_usermodehelper("/home/kashrinivaasan/linux-3.7.8/drivers/virgo/queuing/kingcobra_main", argv, envp, UMH_WAIT_EXEC);
178  printk(KERN_INFO "virgo_workqueue_handler(): after invoking call_usermodehelper() for KingCobra \n");
179  filp_close(file_stdout,NULL);
180  }
181  else
182  {
183  printk(KERN_INFO "virgo_workqueue_handler(): kingcobra_in_userspace=0, before invoking kingcobra_servicerequest_kernelspace()\n");
184  kingcobra_servicerequest_kernelspace(vwqrq->data);
185  printk(KERN_INFO "virgo_workqueue_handler(): after invoking kingcobra_servicerequest_kernelspace()\n");
186  }
187  }
188 }
189 
190 
191 struct virgo_request* virgo_request_queue;
192 
193 static int __init virgo_queue_init();
194 void push_request(struct virgo_request* req);
195 struct virgo_request* pop_request();
196 static void __exit virgo_queue_exit();
197 
198 
199 
200 /*static struct virgo_workqueue_request vwqreq;*/
201 
202 #endif