Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
virgo_cloud_fs.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* fs_cmd;
41  char* fs_args[3];
42 };
43 
44 struct virgo_fs_args* parse_virgofs_command_userspace(char* fsFunction);
45 void* virgo_cloud_open(void*);
46 void* virgo_cloud_close(void*);
47 void* virgo_cloud_read(void*);
48 void* virgo_cloud_write(void*);
49 
50 void* virgo_cloud_open(void* args)
51 {
52  char buf[500];
53  printf("virgo_cloud_fs.c:Executing virgo_cloud_fs on cloud node, Invoking virgo_cloud_open(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
54  struct virgo_fs_args* vmargs=parse_virgofs_command_userspace((char*)args);
55  int fd=open(vmargs->fs_args[0],O_RDWR);
56  read(fd,buf,500);
57  printf("virgo_cloud_fs.c:virgo_cloud_open(): fd=%d,buf=%s\n",fd,buf);
58  fflush(stdout);
59  return &fd;
60 }
61 
62 void* virgo_cloud_read(void* args)
63 {
64  printf("virgo_cloud_fs.c:Executing virgo_cloud_fs on cloud node, Invoking virgo_cloud_read(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
65  struct virgo_fs_args* vmargs=parse_virgofs_command_userspace((char*)args);
66  char buf[256];
67  int fd=atoi(vmargs->fs_args[0]);
68  fd=open("/home/kashrinivaasan/linux-3.7.8/drivers/virgo/cloudfs/virgofstest.txt",O_RDWR);
69  read(fd,buf,256);
70  printf("virgo_cloud_fs.c: virgo_cloud_read(): fd=%d, buf=%s\n",fd,buf);
71  return NULL;
72 }
73 
74 void* virgo_cloud_write(void* args)
75 {
76  printf("virgo_cloud_fs.c:Executing virgo_cloud_fs on cloud node, Invoking virgo_cloud_write(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
77  struct virgo_fs_args* vmargs=parse_virgofs_command_userspace((char*)args);
78  int fd=atoi(vmargs->fs_args[0]);
79  printf("virgo_cloud_fs.c: virgo_cloud_write(): buf=%s\n",vmargs->fs_args[1]);
80  fd=open("/home/kashrinivaasan/linux-3.7.8/drivers/virgo/cloudfs/virgofstest.txt",O_RDWR);
81  write(fd,vmargs->fs_args[1],256);
82  fsync(fd);
83  return NULL;
84 }
85 
86 void* virgo_cloud_close(void* args)
87 {
88  printf("virgo_cloud_fs.c:Executing virgo_cloud_fs on cloud node, Invoking virgo_cloud_close(), Writing to file opened by Kernel, Kernel Space to User space communication works\n");
89  struct virgo_fs_args* vmargs=parse_virgofs_command_userspace((char*)args);
90  int fd=atoi(vmargs->fs_args[0]);
91  close(fd);
92  return NULL;
93 }
94 
95 struct virgo_fs_args* parse_virgofs_command_userspace(char* fsFunction)
96 {
97  struct virgo_fs_args* vmargs=(struct virgo_fs_args*)malloc(sizeof(struct virgo_fs_args));
98  printf("virgo_cloud_fs.c:fsFunction to parse = %s\n",fsFunction);
99  vmargs->fs_cmd=strdup(strsep(&fsFunction, "("));
100  printf("virgo_cloud_fs.c:vmargs->fs_cmd = %s\n",vmargs->fs_cmd);
101  if(strcmp(vmargs->fs_cmd,"virgo_cloud_open")==0 || strcmp(vmargs->fs_cmd,"virgo_cloud_close")==0)
102  {
103  vmargs->fs_args[0]=strdup(strsep(&fsFunction,")"));
104  printf("virgo_cloud_fs.c:vmargs->fs_args[0] = %s\n",vmargs->fs_args[0]);
105  vmargs->fs_args[1]=NULL;
106  }
107  else
108  {
109 
110  vmargs->fs_args[0]=strdup(strsep(&fsFunction,","));
111  vmargs->fs_args[1]=strdup(strsep(&fsFunction,","));
112  vmargs->fs_args[2]=strdup(strsep(&fsFunction,")"));
113  printf("virgo_cloud_fs.c:vmargs->fs_args[0] = %s\n",vmargs->fs_args[0]);
114  printf("virgo_cloud_fs.c:vmargs->fs_args[1] = %s\n",vmargs->fs_args[1]);
115  printf("virgo_cloud_fs.c:vmargs->fs_args[2] = %s\n",vmargs->fs_args[2]);
116  vmargs->fs_args[3]=NULL;
117  }
118  return vmargs;
119 }
120 
121 /*
122 This function parses the address within the string strAddress and returns as the address
123 Example: "0x0000ffff" to 0x0000ffff
124 */
125 
126 char* toAddress(char* strAddress)
127 {
128  char *ptr=NULL;
129  sscanf(strAddress,"%p",ptr);
130  return ptr;
131 }