Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
virgo_cloud_mempool.c
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: 9003082186, 9791165980
23 Open Source Products Profile(Krishna iResearch): http://sourceforge.net/users/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 #include <sys/types.h>
31 #include <stdlib.h>
32 #include <sys/stat.h>
33 #include <stdio.h>
34 #include <fcntl.h>
35 #include <unistd.h>
36 #include <string.h>
37 
39 {
40  char* mempool_cmd;
41  char* mempool_args[3];
42 };
43 
44 char* toAddress(char*);
45 void* virgo_cloud_malloc(void*);
46 void* virgo_cloud_free(void*);
47 void* virgo_cloud_get(void*);
48 void* virgo_cloud_set(void*);
49 struct virgo_mempool_args* parse_virgomempool_command_userspace(char* mempoolFunction);
50 
51 void* virgo_cloud_malloc(void* args)
52 {
53  printf("virgo_cloud_mempool.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_malloc(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
54  struct virgo_mempool_args* vmargs=parse_virgomempool_command_userspace((char*)args);
55  int size=atoi(vmargs->mempool_args[0]);
56  void* ptr=malloc(size);
57  printf("virgo_cloud_mempool.c:virgo_cloud_malloc(): ptr=%p\n",ptr);
58  fflush(stdout);
59  return ptr;
60 }
61 
62 void* virgo_cloud_get(void* args)
63 {
64  printf("virgo_cloud_mempool.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_get(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
65  struct virgo_mempool_args* vmargs=parse_virgomempool_command_userspace((char*)args);
66  char* ptr=toAddress((char*)vmargs->mempool_args[0]);
67  printf("virgo_cloud_mempool.c: virgo_cloud_get(): address=%p, data=%s\n",ptr,ptr);
68  return ptr;
69 }
70 
71 void* virgo_cloud_set(void* args)
72 {
73  printf("virgo_cloud_mempool.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_set(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
74  struct virgo_mempool_args* vmargs=parse_virgomempool_command_userspace((char*)args);
75  char* ptr=toAddress(vmargs->mempool_args[0]);
76  strcpy(ptr,strdup(vmargs->mempool_args[1]));
77  printf("virgo_cloud_mempool.c: virgo_cloud_set(): address=%p, data=%s\n",ptr,vmargs->mempool_args[1]);
78  return 0;
79 }
80 
81 void* virgo_cloud_free(void* args)
82 {
83  printf("virgo_cloud_mempool.c:Executing virgo_cloud_mempool on cloud node, Invoking virgo_cloud_free(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
84  struct virgo_mempool_args* vmargs=parse_virgomempool_command_userspace((char*)args);
85  char* ptr=toAddress(vmargs->mempool_args[0]);
86  printf("virgo_cloud_mempool.c: virgo_cloud_free(): address=%p\n",ptr);
87  free(ptr);
88  return 0;
89 }
90 
91 struct virgo_mempool_args* parse_virgomempool_command_userspace(char* mempoolFunction)
92 {
93  struct virgo_mempool_args* vmargs=(struct virgo_mempool_args*)malloc(sizeof(struct virgo_mempool_args));
94  vmargs->mempool_cmd=strdup(strsep(&mempoolFunction, "("));
95  if(strcmp(vmargs->mempool_cmd,"virgo_cloud_malloc")==0 || strcmp(vmargs->mempool_cmd,"virgo_cloud_free")==0)
96  {
97  vmargs->mempool_args[0]=strdup(strsep(&mempoolFunction,")"));
98  vmargs->mempool_args[1]=NULL;
99  }
100  else
101  {
102 
103  vmargs->mempool_args[0]=strdup(strsep(&mempoolFunction,","));
104  vmargs->mempool_args[1]=strdup(strsep(&mempoolFunction,")"));
105  vmargs->mempool_args[2]=NULL;
106  }
107  return vmargs;
108 }
109 
110 /*
111 This function parses the address within the string strAddress and returns as the address
112 Example: "0x0000ffff" to 0x0000ffff
113 */
114 
115 char* toAddress(char* strAddress)
116 {
117  char *ptr=NULL;
118  sscanf(strAddress,"%p",ptr);
119  return ptr;
120 }