My favorites
▼
|
Sign in
fscops
OHSM - Online Hierarchical Storage Manager
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
37
attachment: getopt.c
(10.1 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#define _GNU_SOURCE
#include <getopt.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "ohsm_user.h"
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#define SET 1
#define UNSET 0
#define MAX_ARG_LENGTH 20
int ohsm_relocate(unsigned long rule_bitmap)
{
int ohsm_device_fd = 0, retval =0;
ohsm_device_fd = open("/dev/ohsm", O_RDONLY);
if (ohsm_device_fd <= 0) {
printf("\n\nError opening device /dev/ohsm");
return -1;
}
printf("\n\nTrigger Relocation ");
getchar();
retval = ioctl(ohsm_device_fd, OHSM_TRIGGER_RELOCATION, &rule_bitmap);
close(ohsm_device_fd);
return retval;
}
int ohsm_start(char *alloc_file, char *reloc_file, char *tier_file, char *mountpoint)
{
int ohsm_dm_fd = 0 , ohsm_device_fd = 0,ret; // set to 1 for testing
char p ='1';
struct ohsm_tier_device_count *xml_dev_file = NULL;
struct ohsm_struct_rules *xml_relocate_file = NULL;
struct ohsm_allocation_policy *xml_alloc_file = NULL;
struct ohsm_struct_for_ioctl input_to_kernel;
ohsm_dm_fd = open("/dev/vg/lvol0", O_RDONLY);
ohsm_device_fd = open("/dev/ohsm", O_RDONLY);
if (ohsm_device_fd <= 0) {
printf("\n\nError opening device /dev/ohsm");
return -1;
}
if (ohsm_dm_fd <= 0) {
printf("\n\nError in opering device name /dev/vg/lvol0");
return -1;
}
printf("\n\nCalling First Ioctl");
ret = ioctl(ohsm_dm_fd, OHSM_GET_DM_INFO, &p); //41 will be changed
if (ret) {
printf("\n\n DM ioctl returned %d", ret);
}
if (ret) {
printf("\n\nDEVICE ioctl returned %d", ret);
}
xml_alloc_file = (struct ohsm_allocation_policy *)
ohsm_get_allocation_policy(alloc_file);
if (xml_alloc_file == NULL) {
printf
("\n\nError in parsing the allocation policy file in user.c ");
return -1;
}
xml_dev_file =
(struct ohsm_tier_device_count *)ohsm_get_tier_device_info(tier_file);
if (xml_dev_file == NULL) {
printf("\n\nError in parsing the device tier file");
return -1;
}
xml_relocate_file = (struct ohsm_struct_rules *) ohsm_get_relocation_policy(reloc_file);
if( xml_relocate_file == NULL){
printf("\n\nError in parsing the relocation file");
return -1;
}
input_to_kernel.ptr_reloc_policy = xml_relocate_file;
input_to_kernel.ptr_alloc_policy = xml_alloc_file;
input_to_kernel.ptr_dev_file = xml_dev_file;
strcpy(input_to_kernel.mountpoint, mountpoint);
printf("\n\nCalling Second Ioctl");
ret = ioctl(ohsm_device_fd, OHSM_SET_POLICY, &input_to_kernel);
return ret;
}
int main(int argc,char *argv[])
{
int i,opt,count;
char argn[60];
char cmd[60]="";
char lname[40];
// unsigned char FLAG_CR = UNSET;
unsigned char FLAG_LVU = UNSET; /*SHOW THE EXISTING LOGICAL VOLUME AND UNDERLYING DEVICES*/
unsigned char FLAG_LVC = UNSET; /*CREATE LOGICAL VOLUME WITH DEVICES NAMES AS PARAMETER*/
unsigned char FLAG_TI = UNSET; /*GIVES TIER INFORMATION*/
unsigned char FLAG_TD = UNSET; /*SETS TIER DEVICE INFORMATION*/
unsigned char FLAG_AP = UNSET; /*SETS ALLOCATION POLICY*/
unsigned char FLAG_RP = UNSET; /*SETS RELOCATION POLICY*/
unsigned char FLAG_E = UNSET; /*OHSM ENABLED*/
unsigned char FLAG_D = UNSET; /*OHSM DISABLED*/
unsigned char FLAG_CP = UNSET; /*SHOW CURRENT POLICY BOTH ALLOC & RELLOC*/
unsigned char FLAG_RT = UNSET; /*REASSIGN ALLOC POLICY*/
unsigned char FLAG_RR = UNSET; /*REASSIGN RELOC POLICY*/
unsigned char FLAG_RD = UNSET; /*REASSIGN TIER DEVICE INFORMATION*/
unsigned char FLAG_MNT = UNSET;
unsigned char FLAG_REL = UNSET;
struct option longopts[] = {
// {"create",1,NULL,'b'},
{"existnglvm",1,NULL, 'u'},
{"createlvm",1,NULL, 'l'},
{"tierinfo", 10,NULL , 't'},
{"tierdeviceinfo", 1, NULL, 'i'},
{"currpoly", 1, NULL, 'c'},
{"allocpoly", 1, NULL, 'a'},
{"relocpoly", 1, NULL, 'r'},
{"enabled", 0, NULL, 'e'},
{"disabled", 1, NULL, 'd'},
{"reassgnpoly", 1, NULL, 'x'},
{"reassgnreloc", 1, NULL, 'y'},
{"retierdevinfo",1,NULL,'z'},
{"relocate",1,NULL,'o'},
{0,0,0,0}
};
char reloc_file[MAX_ARG_LENGTH] = "";
char alloc_file[MAX_ARG_LENGTH] = "";
char mountpoint[MAX_ARG_LENGTH] = "";
char tier_file[MAX_ARG_LENGTH] = "";
while((opt=getopt_long(argc, argv, ":u:l:t:i:c:a:r:d:x:y:z:m:o e", longopts, NULL)) != -1)
{
switch(opt) {
case 'u':
printf("option %c\n",opt);
printf("\nThis ioctl gives the information about the logical volume and devices beneath");
printf("\nArguments are %s \n",optarg);
FLAG_LVU = SET;
break;
case 'l':
printf("option %c\n",opt);
printf("\nThis ioctl gives the information about the logical volume and devices beneath");
printf("\nArguments are %s \n",optarg);
FLAG_LVC = SET;
break;
case 'o':
printf("\n\nStarting Relocation");
printf ("\nArguments are %s \n", optarg);
FLAG_REL = SET;
break;
case 'm':
printf("\n\nThe Mountpoint entered is %s",optarg);
FLAG_MNT = SET;
strcpy(mountpoint,optarg);
break;
case 't':
printf("option %c\n", opt);
FLAG_TI = SET;
printf ("This gives tier information");
printf ("\nArguments are %s \n", optarg);
break;
case 'i':
printf ("option %c\n", opt);
FLAG_TD = SET;
printf ("This sets tier device information");
printf ("\nArgument are %s\n", optarg);
strcpy(tier_file,optarg);
break;
case ':':
printf ("Arguement Missing");
break;
case 'c':
printf ("option %c\n", opt);
FLAG_CP = SET;
printf ("Argument are %s\n", optarg);
printf ("\nThis gives the current policy enforced");
break;
case 'a':
printf ("option %c\n", opt);
FLAG_AP = SET;
printf ("Argument are %s\n", optarg);
printf ("\nThis sets the allocation policy");
strcpy(alloc_file, optarg);
break;
case 'r':
printf ("option %c\n", opt);
FLAG_RP = SET;
printf ("Argument is %s\n", optarg);
printf ("\nThis sets the relocation policy");
strcpy(reloc_file, optarg);
break;
case 'e':
printf ("\n\noption %c\n", opt);
FLAG_E = SET;
printf ("This will enable the OHSM");
printf ("\nArgument is %s\n", optarg);
break;
case 'd':
printf ("option %c\n", opt);
FLAG_D = SET;
printf ("This gives disable the OHSM");
printf ("\nArgument is %s\n", optarg);
break;
case '?':
printf ("No such options declared %c", optopt);
break;
case 'x':
printf ("option %c\n", opt);
FLAG_RT = SET;
printf ("This will reassign the allocation policy");
printf ("\nArgument is %s\n", optarg);
break;
case 'y':
printf ("option %c\n", opt);
FLAG_RR = SET;
printf ("Argument is %s\n", optarg);
printf ("\nThis will reassign the realloc policy");
break;
case 'z':
printf ("option %c\n", opt);
FLAG_RD = SET;
printf ("Argument is %s\n", optarg);
printf ("\nThis will reassign tier device information");
break;
}
}
if( FLAG_E && FLAG_TD && FLAG_AP && FLAG_RP && FLAG_MNT)
{
printf("\n\nOHSM START");
ohsm_start(alloc_file, reloc_file, tier_file, mountpoint);
return 0;
}
if( FLAG_REL )
{
printf("\n\nOHSM RELOCATE");
int i;
unsigned long rule_bitmap = 0, temp =1,temp2;
for( i = 0; i < argc - 2; i++)
{
temp = 1;
temp2 = strtoul(argv[i+2], NULL, 10);
if( temp2 > 30)
{
printf("\n\nError : maximum number of rules supported are 30\n");
return -1;
}
temp = temp<<(temp2 -1);
printf("\n\n temp is %lu temp2 is %lu", temp, temp2);
rule_bitmap = rule_bitmap | temp;
printf("\nThe rule Bitmap = %lu",rule_bitmap);
}
printf("\n\nThe rule Bitmap = %lu",rule_bitmap);
if(ohsm_relocate(rule_bitmap))
{
printf("\n\nError could not relocate");
return -1;
}
return 0;
}
if(FLAG_LVU == SET){
system("./info");/*its a script which gives details of existing lvm and devices on the system*/
printf("Enter the full path of the logical volume you wish to have");
scanf("%s",lname); /*lname is a variable /dev/vg/lvol0*/
/* needs to be filled*/
}
if(FLAG_LVC == SET){
count=argc - 2;
sprintf(cmd,"./fs_lvm %s",argv[2]);
printf("%s",cmd);
printf("The command ran well");
if(count == 1){
system(cmd);
}
else{
printf("M in else");
for(i=2;i<=argc;i++){
strcat(argn," ");
printf("%s",argn);
strcat(argn,argv[i]);
}
printf("%s",argn);
system("./fs_lvm argn");
}
/*call the function ohsm_start*/
}
// *
if(FLAG_D == SET){
//call the ioctl
}
/*
if(FLAG_TD == SET){
//Call the ioctl
xml_dev_file= (struct ohsm_tier_device_count*) ohsm_get_tier_device_info(argv[2]);
if(xml_dev_file==NULL)
{
printf("\nError in parsing the device file");
return -1;
}
retval=ioctl(); //fill your ioctl over here??
if(retval < 0){
printf("\n ioctl failed %d",retval);
return retval;
}
//remember to unset
}
if(FLAG_AP == SET){
//Call the ioctl
xml_alloc_file= (struct ohsm_allocation_policy*) ohsm_get_allocation_policy(argv[2]);
if(xml_alloc_file==NULL)
{
printf("\nError in parsing the allocation file");
return -1;
}
retval=ioctl(); //fill your ioctl over here??
if(retval < 0){
printf("\n ioctl failed %d",retval);
return -1;
}
//remember to unset
}
if(FLAG_RP == SET){
//Call the ioctl
xml_reloc_file= (struct ohsm_relocation_policy *) ohsm_get_relocation_policy(argv[2]);
if(xml_reloc_file==NULL)
{
printf("\nError in parsing the xml alloc file");
return -1;
}
retval=ioctl(); //fill your ioctl over here??
if (retval < 0){
printf("\nioctl failed %d",retval);
return -1;
}
//remember to unset
}
if(FLAG_CP == SET){
//call the ioctl
}
if(FLAG_RT == SET){
//call the ioctl
//remember to unset
}
if(FLAG_RR == SET){
//call the ioctl
//remember to unset
}
if(FLAG_RD == SET){
} */
exit (0);
}
Powered by
Google Project Hosting