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
102
attachment: admin.c
(34.7 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
/*
Copyright (C) <2009>
<Rishi B Agrawal> <Vineet Agarwal> <Rohit Sharma>
<rishi.b.agrawal@gmail.com> <checkout.vineet@gmail.com> <imreckless@gmail.com>
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version->
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE-> See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <linux/kernel.h>
#include <linux/buffer_head.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/namei.h>
#include <linux/mount.h>
#include <linux/ext2_fs.h>
#include <linux/ext2_fs_sb.h>
#include <linux/path.h>
#include <linux/dcache.h>
#include <../fs/ext2/ext2.h>
#include <linux/time.h>
#include <linux/writeback.h>
#include "../include/ohsm.h"
#include "ohsm_k.h"
#include <linux/quotaops.h>
#include <linux/sched.h>
#include <linux/capability.h>
#define DEVICE_NAME "OHSM_KERNEL_DRIVER"
static int device_ioctl (struct inode *, struct file *,
unsigned int, unsigned long);
/****************************************************************
* *
* reset_sam() is used to reset the sam table *
* which is declared in ext2/balloc.c *
* *
***************************************************************/
void
reset_sam(void) {
int i = 0;
int j;
ohsm_printk ("\nOHSM: Resetting SAM table.");
for (i = 0; i < MAX_TIER_ALLOWED; i++) {
for (j = 0; j < (MAX_DISK_ALLOWED * 2 + 1); j++) {
sam[i][j] = 0;
}
ohsm_printk ("\n");
}
ohsm_printk ("\nOHSM: Resetting SAM table done.");
}
/****************************************************************
* *
* ohsm_disable () disables OHSM and free all data *
* structures allocated *
* *
***************************************************************/
int
ohsm_disable(void) {
if (ohsm_relocating) {
return OHSM_ERR_RELOC_ON;
}
if (!ohsm_enabled) {
return OHSM_ERR_ALREADY_DISABLED;
}
ohsm_enabled = UNSET;
ohsm_sb = NULL;
ohsm_sbi = NULL;
ohsm_printk ("\nOHSM: Freeing the Allocation policy.");
reset_sam();
ohsm_printk ("\nOHSM: Allocation policy freed.");
return OHSM_SUCCESS;
}
/****************************************************************
* *
* verify_mntpt () verify whether the mountpoint entered *
* is valid and whether it contain a valid ext2 partition *
* *
***************************************************************/
int
verify_mntpt (char *mountpoint) {
int retval = 0;
struct nameidata nd;
strcpy(ohsm_mountpoint, mountpoint);
retval = path_lookup (mountpoint, LOOKUP_OPEN, &nd);
ohsm_printk ("\nOHSM: Verifying mount point = %s.",mountpoint);
ohsm_printk ("\nOHSM: Path lookup returned = %d.",retval);
ohsm_printk ("\nOHSM: Fetched Mountpoint = %s.", nd.path.mnt->mnt_mountpoint->d_name.name);
if (!strcmp (nd.path.mnt->mnt_mountpoint->d_name.name, mountpoint + 1)) {
ohsm_sb = nd.path.mnt->mnt_sb;
}
else {
printk("\nOHSM: Invalid mountpoint.");
return OHSM_ERR_MNTPNT;
}
if (ohsm_sb == NULL) {
printk ("\nOHSM: OHSM Super block not found.");
return OHSM_ERR_NULL_PTR;
}
ohsm_sbi = (struct ext2_sb_info *) (ohsm_sb->s_fs_info);
if (ohsm_sbi == NULL) {
printk ("\nOHSM: Incore OHSM superblock is NULL.");
return OHSM_ERR_NULL_PTR;
}
path_put (&(nd.path));
return OHSM_SUCCESS;
}
/****************************************************************
* *
* ohsm_check_age () checks the access age for the inode *
* time - inode access time *
* check_val - policy value *
* rel_op - relational operator *
* *
***************************************************************/
int
ohsm_check_age (struct timespec time, long long check_val,
unsigned int rel_op) {
unsigned int days;
struct timespec now = current_fs_time (ohsm_sb);
unsigned long diff_sec = now.tv_sec - time.tv_sec;
days = diff_sec / (24 * 60 * 60);
ohsm_printk ("\nOHSM: Days = %u < Policy value (check_val) = %lld.", days, check_val);
switch (rel_op)
{
case LT:
ohsm_printk ("\nOHSM: IN CHECK AGE LT.");
return (days < check_val);
case GT:
ohsm_printk ("\nOHSM: IN CHECK AGE GT.");
return (days > check_val);
case EQ:
ohsm_printk ("\nOHSM: IN CHECK AGE EQ.");
return (days == check_val);
case NEQ:
ohsm_printk ("\nOHSM: IN CHECK AGE NEQ.");
return (days != check_val);
case LE:
ohsm_printk ("\nOHSM: IN CHECK AGE LE.");
return (days <= check_val);
case GE:
ohsm_printk ("\nOHSM: IN CHECK AGE GE.");
return (days >= check_val);
}
return FALSE;
}
/****************************************************************
* *
* ohsm_check_param () checks the access age for the inode *
* input - inode size in KB *
* check_val - policy value *
* rel_op - relational operator *
* *
***************************************************************/
int
ohsm_check_param (long long input, long long check_val,
unsigned char rel_op) {
ohsm_printk ("\nOHSM: Operator = %u.", rel_op);
ohsm_printk ("\nOHSM: Input Values : %lld.", input);
ohsm_printk ("\nOHSM: Value To Be checked %lld.", check_val);
switch (rel_op)
{
case LT:
ohsm_printk ("\nOHSM: Inside LT.");
return (input < check_val);
case GT:
ohsm_printk ("\nOHSM: Inside GT.");
return (input > check_val);
case EQ:
ohsm_printk ("\nOHSM: Inside EQ.");
return (input == check_val);
case NEQ:
ohsm_printk ("\nOHSM: Inside NEQ.");
return (input != check_val);
case LE:
ohsm_printk ("\nOHSM: Inside LE.");
return (input <= check_val);
case GE:
ohsm_printk ("\nOHSM: Inside GE.");
return (input >= check_val);
}
return FALSE;
}
/****************************************************************
* *
* ohsm_check_fiot () For Future Implementation *
* *
***************************************************************/
int
ohsm_check_fiot (struct inode *temp_inode, long long check_val,
unsigned int rel_op) {
long long temp_fiot = 0;
temp_fiot++;
return OHSM_SUCCESS;
}
/****************************************************************
* *
* ohsm_check_fat () For Future Implementation *
* *
***************************************************************/
int
ohsm_check_fat (struct inode *temp_inode, long long check_val,
unsigned int rel_op) {
long long temp_fat = 0;
temp_fat++;
return OHSM_SUCCESS;
}
/****************************************************************
* *
* ohsm_check_qualifying_policy () sets destination *
* tier id for the qualified inode *
* *
***************************************************************/
int
ohsm_check_qualifying_policy (struct inode *temp_inode,
struct ohsm_relocation_policy *policy) {
unsigned int val = 1;
struct ext2_inode_info *ei = NULL;
ei = EXT2_I (temp_inode);
if (ei == NULL ) {
ohsm_printk ("\nOHSM: Incore inode is NULL.");
}
ohsm_printk ("\nOHSM: Src tier of policy = %u.", policy->src_tier);
ohsm_printk ("\nOHSM: Dest tier of policy = %u.", policy->dest_tier);
ohsm_printk ("\nOHSM: Home tier of inode = %u.", ei->ohsm_home_tid);
if (ei->ohsm_home_tid == policy->src_tier) {
ohsm_printk ("\nOHSM: Source tier matched.");
if (policy->reloc_criteria_bitmap == 0) {
ohsm_printk ("\nOHSM: Unconditional policy found.");
ei->ohsm_dest_tid = policy->dest_tier;
return TRUE;
}
if (policy->reloc_criteria_bitmap & FSIZE) {
ohsm_printk ("\nOHSM: Policy based on size being tested.");
val = ohsm_check_param ((temp_inode->i_size/1024), policy->values[0], policy->rel_ops[0]);
if (!val) {
ohsm_printk ("\nOHSM: Policy based on size didn't match.");
return FALSE;
}
ohsm_printk ("\nOHSM: Policy based on size passed.");
}
if (policy->reloc_criteria_bitmap & FAA) {
ohsm_printk ("\nOHSM: Policy based on FAA being tested.");
val = val & ohsm_check_age (temp_inode->i_atime, policy->values[1], policy->rel_ops[1]);
if (!val) {
ohsm_printk ("\nOHSM: Policy based on FAA didn't match.");
return FALSE;
}
ohsm_printk ("\nOHSM: Policy based on FAA passed.");
}
if (policy->reloc_criteria_bitmap & FMA) {
ohsm_printk ("\nOHSM: Policy based on FMA being tested.");
val = val & ohsm_check_age (temp_inode->i_mtime, policy->values[2], policy->rel_ops[2]);
if (!val) {
ohsm_printk ("\nOHSM: Policy based on FMA didn't match.");
return FALSE;
}
ohsm_printk ("\nOHSM: Policy based on FMA passed.");
}
if (policy->reloc_criteria_bitmap & FIOT) {
val = val & ohsm_check_fiot (temp_inode, policy->values[3], policy->rel_ops[3]);
if (!val) {
return FALSE;
}
}
if (policy->reloc_criteria_bitmap & FAT) {
val = val & ohsm_check_fat (temp_inode, policy->values[4], policy->rel_ops[4]);
if (!val) {
return FALSE;
}
}
} else {
ohsm_printk ("\nOHSM: None of the rules matched.");
return FALSE;
}
ei->ohsm_dest_tid = policy->dest_tier;
mark_inode_dirty (temp_inode);
ohsm_sync_inode(temp_inode);
return TRUE;
}
/****************************************************************
* *
* ohsm_find_dest_for_rule () find the destination *
* tier for relocation *
* *
***************************************************************/
int
ohsm_find_dest_for_rule (struct inode *temp_inode, int rule_no) {
int policy_no = 0;
int ret = 0;
ohsm_printk ("\nOHSM: Finding destination for relocation.");
for (policy_no = 0; policy_no < relocpol->cnt_policies; policy_no++) {
ohsm_printk ("\nChecking against policy number = %d.", policy_no);
ret = ohsm_check_qualifying_policy (temp_inode, &relocpol->policy[rule_no]);
if (ret == TRUE) {
ohsm_printk ("\nOHSM: Policy number %d qualified.", policy_no);
return TRUE;
}
}
return FALSE;
}
/****************************************************************
* *
* ohsm_realloc_mcp () actual relocation code performing *
* relocation. *
* Relocation is done using Tricky Copy And Swap Algorithm *
* inum - inode no. of the inode that is to be relocated *
* *
***************************************************************/
int
ohsm_realloc_mcp (unsigned long inum) {
int err = 0;
int done;
int blk_index = 0;
int retval = 0;
unsigned int swap;
loff_t i_size;
blkcnt_t nblocks;
struct inode *src_ind, *dest_ind;
struct buffer_head *src_bhptr = NULL, *dst_bhptr = NULL;
struct buffer_head dest_bh, src_bh;
struct nameidata nd;
retval = path_lookup (ohsm_mountpoint, LOOKUP_OPEN, &nd);
if(retval) {
printk(KERN_DEBUG "\nOHSM: Error in pathlookup");
goto out_err;
}
/* Get the source inode */
src_ind = ext2_iget (ohsm_sb, inum);
if (!src_ind) {
printk ("\nOHSM: Source Inode Not Found ");
goto out_err;
}
/* Getting the ghost inode */
dest_ind = ext2_new_inode (nd.path.dentry->d_inode, src_ind->i_mode);
if (IS_ERR(dest_ind)) {
err = OHSM_ERR_FS;
printk ("\nOHSM: destination inode unable to allocate. OHSM_ERR = %ld.", PTR_ERR(dest_ind));
iput(src_ind);
goto out_err;
}
EXT2_I(dest_ind)->ohsm_home_tid = EXT2_I(src_ind)->ohsm_dest_tid;
/* Locking the source inode using mutex */
mutex_lock (&src_ind->i_mutex);
/* Get the source inode size and number of blocks */
i_size = i_size_read(src_ind);
/* Calculating number of block to allocate for ghost inode */
nblocks = (i_size >> EXT2_BLOCK_SIZE_BITS(ohsm_sb)) +
((i_size & (ohsm_sb->s_blocksize - 1)) ? 1 : 0);
/* Starting Tricky Copy
*
* Allocate a data block for ghost
* Read the block into buffer head 1
* Read the source block into buffer head 2
* assign b_data of buffer 2 to b_data of buffer 1
* Mark buffer dirty
* For indirect blocks read the chain of indirect
* pointers leading to data
* Now ghost inode has exact data from source
* Swap source i_data with ghost i_data
* Finally source inode has new data blocks
*
* so mark it dirty and delete the ghost inode.
*/
for (done = 0; done < nblocks; done++) {
memset(&dest_bh, 0, sizeof(struct buffer_head));
memset(&src_bh, 0, sizeof(struct buffer_head));
err = ext2_get_block (src_ind, done, &src_bh, 0);
if (err < 0) {
err = OHSM_ERR_FS;
printk ("\nOHSM: OHSM_ERRor getting blocks ret_val = %d.", err);
goto unlock;
}
if (!buffer_mapped(&src_bh)) {
ohsm_printk ("\nOHSM: HOLE found.");
continue;
}
dest_bh.b_state = 0;
err = ext2_get_block (dest_ind, done, &dest_bh, 1);
if (err < 0) {
err = OHSM_ERR_FS;
printk ("\nOHSM: OHSM_ERRor getting blocks. ret_val = %d.", err);
goto unlock;
}
src_bhptr = sb_bread(ohsm_sb, src_bh.b_blocknr);
if (!src_bhptr) {
err = OHSM_ERR_FS;
printk("\nOHSM: Source buffer NULL.");
goto unlock;
}
dst_bhptr = sb_bread(ohsm_sb, dest_bh.b_blocknr);
if (!dst_bhptr) {
err = OHSM_ERR_FS;
printk("\nOHSM: Destination buffer NULL.");
goto unlock;
}
lock_buffer(dst_bhptr);
memcpy(dst_bhptr->b_data,src_bhptr->b_data,src_bhptr->b_size);
unlock_buffer(dst_bhptr);
mark_buffer_dirty(dst_bhptr);
brelse(src_bhptr);
brelse(dst_bhptr);
}
for (blk_index = 0; blk_index < 15; blk_index++) {
if (EXT2_I (dest_ind)->i_data[blk_index]) {
swap = EXT2_I (src_ind)->i_data[blk_index];
EXT2_I (src_ind)->i_data[blk_index] =
EXT2_I (dest_ind)->i_data[blk_index];
EXT2_I (dest_ind)->i_data[blk_index] = swap;
}
}
EXT2_I(src_ind)->ohsm_home_tid = EXT2_I(src_ind)->ohsm_dest_tid;
EXT2_I(src_ind)->ohsm_dest_tid = 0;
dest_ind->i_blocks = src_ind->i_blocks ;
mark_inode_dirty (src_ind);
sync_mapping_buffers(src_ind->i_mapping);
ohsm_sync_inode(src_ind);
err = OHSM_SUCCESS;
unlock:
iput(src_ind);
dest_ind->i_state &= ~I_NEW;
dest_ind->i_nlink = 0;
iput(dest_ind);
mutex_unlock (&src_ind->i_mutex);
out_err:
return err;
}
/****************************************************************
* *
* ohsm_get_inodes_for_relocation () scans the complete *
* inode of the file system to get an qualifying inode *
* and send the qualified for relocation *
* *
***************************************************************/
int
ohsm_get_inodes_for_relocation (unsigned long arg)
{
unsigned char r_bitmap;
unsigned char start_ino = 0;
int rule_no = 0, ret;
int retval = 0;
unsigned long nr_groups;
unsigned long rel_inode;
unsigned long i = 0;
unsigned long inode_no = 0;
unsigned long nr_inodes_per_group;
unsigned long *t = NULL;
unsigned long count = 0;
unsigned long rule_bitmap_arg = 0;
struct buffer_head *bh = NULL;
struct inode *temp_inode = NULL;
struct ext2_inode_info *ei = NULL;
t = (unsigned long *)arg;
rule_bitmap_arg = *t;
if (!ohsm_enabled) {
printk ("\nOHSM: OHSM is not enabled. Hence, no relocation.");
return OHSM_ERR_RELOC_INACTIVE;
}
if (rule_bitmap_arg > ((1 << (relocpol->cnt_policies )) - 1)) {
printk ("\nOHSM: Invalid relocation rule number passed. Rule = %lu.", rule_bitmap_arg);
return OHSM_ERR_RULE_BITMAP;
}
ohsm_printk ("\nOHSM: In RELOCATION CODE.");
ohsm_printk ("\nOHSM: The rule bitmap = %lu.", rule_bitmap_arg);
ohsm_printk ("\nOHSM: The Number of Rules = %d.",relocpol->cnt_policies);
nr_groups = ohsm_sbi->s_groups_count;
nr_inodes_per_group = ohsm_sbi->s_inodes_per_group; //group
ohsm_printk ("\nOHSM: Number of groups in file system: %lu.", nr_groups);
ohsm_printk ("\nOHSM: Number of inodes per groups : %lu.", nr_inodes_per_group);
for (i = 0; i < nr_groups; i++) {
bh = (struct buffer_head *) read_inode_bitmap (ohsm_sb, i);
if (!bh) {
printk ("\nOHSM: BH is null ");
return OHSM_ERR_FS;
}
if (i == 0) {
start_ino = 11;
} else {
start_ino = 0;
}
for (inode_no = start_ino; inode_no < nr_inodes_per_group - 1; inode_no++) {
ret = ext2_test_bit (inode_no, (unsigned long *) (bh->b_data));
if (ret) {
ohsm_printk ("\nOHSM: Matching found. Inode Number = %lu.",inode_no);
temp_inode = ext2_iget (ohsm_sb, (inode_no + 1) + i * nr_inodes_per_group);
if (!temp_inode) {
printk ("\nOHSM : ext2_iget returned NULL.");
brelse(bh);
return OHSM_ERR_FS;
}
ei = EXT2_I (temp_inode);
if (!ei) {
printk ("\nOHSM: Incore inode is NULL.");
iput(temp_inode);
brelse(bh);
return OHSM_ERR_FS;
}
if (ei->ohsm_home_tid == 0) {
printk ("\nOHSM: Not relocating as home tid is 0. Inode Number = %ld.", temp_inode->i_ino);
iput(temp_inode);
continue;
} else {
r_bitmap = rule_bitmap_arg;
for (rule_no = 0; rule_no < relocpol->cnt_policies && r_bitmap; rule_no++) {
ohsm_printk ("\nOHSM: Checking for rule Number = %d.", rule_no);
if (r_bitmap & 1) {
ohsm_printk ("\nOHSM: Checking inode number = %ld.", temp_inode->i_ino);
retval = ohsm_find_dest_for_rule (temp_inode, rule_no);
if (retval) {
ohsm_printk ("\nOHSM: Qualified Rule = %d.", rule_no);
ohsm_printk ("\nOHSM: The Destination TID should have changed now.");
ohsm_printk ("\nOHSM: inode number = %lu.", temp_inode->i_ino);
ohsm_printk ("\nOHSM: inode home tier id = %u.", ei->ohsm_home_tid);
ohsm_printk ("\nOHSM: inode dest tier id = %u.", ei->ohsm_dest_tid);
ohsm_printk ("\nOHSM: Relocate inode num = %lu from tier = %u to tier = %u.", temp_inode->i_ino, ei->ohsm_home_tid, ei->ohsm_dest_tid);
rel_inode = temp_inode->i_ino;
iput (temp_inode);
ohsm_realloc_mcp(rel_inode);
count++;
ohsm_printk ("\nOHSM: Total files relocated till now = %lu",count);
break;
} else {
iput(temp_inode);
}
}
ohsm_printk ("\nOHSM: R Bitmap before SHIFT is = %x ", r_bitmap);
r_bitmap = r_bitmap >> 1;
}
}
}
}
brelse(bh);
}
ohsm_printk ("\nOHSM: Relocation performed successfully.");
return OHSM_SUCCESS;
}
/****************************************************************
* *
* debug_print_and_test_type () is used in debugging *
* It prints File type and dest tier specified by the *
* user *
* *
***************************************************************/
void
debug_print_and_test_type (struct ohsm_type_tier *ptr,
unsigned int number) {
int i = 0;
ohsm_printk ("\n\nOHSM: File type and their destinations.");
for (i = 0; i < number; i++) {
ohsm_printk ("\nOHSM: File Type = %s Dest Tier = %u.",ptr[i].type, ptr[i].tier);
}
}
/****************************************************************
* *
* debug_print_and_test_user () is used in debugging *
* It prints UID and dest tier specified by the *
* user *
* *
***************************************************************/
void
debug_print_and_test_user (struct ohsm_uid_tier *ptr, unsigned int number) {
int i = 0;
ohsm_printk ("\n\nOHSM: UID and their destinations.");
for (i = 0; i < number; i++) {
ohsm_printk ("\nOHSM: UID = %u Dest Tier = %u", ptr[i].uid, ptr[i].tier);
}
}
/****************************************************************
* *
* debug_print_and_test_group () is used in debugging *
* It prints GID and dest tier specified by the *
* user *
* *
***************************************************************/
void
debug_print_and_test_group (struct ohsm_gid_tier *ptr,
unsigned int number) {
int i = 0;
ohsm_printk ("\n\nOHSM: GID and their destinations.");
for (i = 0; i < number; i++) {
ohsm_printk ("\nOHSM: Gid = %u Dest Tier = %u", ptr[i].gid, ptr[i].tier);
}
}
/****************************************************************
* *
* turn_the_tables () is used to create the sam table *
* *
***************************************************************/
void
turn_the_tables (void) {
int i = 0, j = 0;
unsigned int cur_tier;
unsigned int col;
unsigned int disks;
unsigned long nr_groups;
ohsm_printk ("\nOHSM: Initializing the SAM table.");
for (i = 0; i < MAX_TIER_ALLOWED; i++) {
for (j = 0; j < MAX_DISK_ALLOWED * 2 + 1; j++) {
sam[i][j] = 0;
}
}
ohsm_printk("\nOHSM: Printing the Dev info");
ohsm_printk("\nOHSM: Number of tiers = %u ", dev_info->nr_tiers);
ohsm_printk("\nOHSM: Number of devices = %u ", dev_info->nr_devices);
for(i=0 ; i < dev_info->dinfo_count; ++i) {
ohsm_printk("\nOHSM: Number = %u ", i);
ohsm_printk("\nOHSM: Tier = %u ", dev_info->device[i].tier);
ohsm_printk("\nOHSM: Device = %u ", dev_info->device[i].dev_num);
ohsm_printk("\nOHSM Length = %lu ", dev_info->device[i].len);
ohsm_printk("\nOHSM Start = %lu ", dev_info->device[i].begin);
}
for (i = 0; i < dev_info->dinfo_count; i++) {
ohsm_printk ("\n\n\n\n");
cur_tier = dev_info->device[i].tier;
sam[cur_tier][0] = sam[cur_tier][0] + 1;
disks = sam[cur_tier][0];
col = disks * 2 - 1;
sam[cur_tier][col] = dev_info->device[i].blkgrp_start;
sam[cur_tier][col + 1] = dev_info->device[i].blkgrp_end;
}
#ifdef DEBUG
ohsm_printk ("\nOHSM: Printing SAM before adding the start and end.");
debug_print_sam ();
#endif
nr_groups = ohsm_sbi->s_groups_count;
ohsm_printk ("\nOHSM: Number of Groups in the File System = %lu.",nr_groups);
sam[0][0] = 1;
sam[0][1] = 0;
sam[0][2] = nr_groups;
for (i = 1; i <= dev_info->dinfo_count; i++) {
if (sam[i][0] == 0) {
ohsm_printk ("\nOHSM: SAM table filled.");
break;
}
sam[i][0]++;
disks = sam[i][0];
col = disks * 2 - 1;
ohsm_printk ("\nOHSM: sam[joined[i].tier][0] = %lu.", sam[dev_info->device[i].tier][0]);
ohsm_printk ("\nOHSM: Number of disks on tier = %u is %u.", dev_info->device[i].tier, disks);
ohsm_printk ("\nOHSM: Printing the columns = %u.", col);
sam[i][col] = 0;
sam[i][col + 1] = nr_groups;
}
#ifdef DEBUG
ohsm_printk ("\nOHSM: Printing SAM after adding start and end.");
debug_print_sam ();
#endif
}
/****************************************************************
* *
* ohsm_set_bg_dm_info is used to calculate the blockgroup *
* start and block group end per device *
* *
***************************************************************/
void
ohsm_set_bg_dm_info (void) {
unsigned int i;
unsigned int block_size, blk_per_grp;
int retval = 0;
struct nameidata nd;
struct ext2_sb_info *sbi = NULL;
struct super_block *sb;
struct vfsmount *vfs = NULL;
retval = path_lookup (ohsm_mountpoint, LOOKUP_OPEN, &nd);
vfs = nd.path.mnt;
sb = (struct super_block *) vfs->mnt_sb;
sbi = (struct ext2_sb_info *) sb->s_fs_info;
block_size = 1 << sbi->s_es->s_log_block_size;
blk_per_grp = sbi->s_es->s_blocks_per_group;
for (i = 0; i < dev_info->dinfo_count; i++) {
dev_info->device[i].blkgrp_start = (unsigned int) (dev_info->device[i].begin /(2 * block_size * blk_per_grp));
if (dev_info->device[i].begin) {
dev_info->device[i].blkgrp_start++;
}
dev_info->device[i].blkgrp_end =
(unsigned int) ((dev_info->device[i].begin + dev_info->device[i].len) / (2 * block_size * blk_per_grp) - 1);
if (dev_info->device[i].len < (block_size * blk_per_grp)) {
dev_info->device[i].blkgrp_end++;
}
}
path_put (&(nd.path));
}
/****************************************************************
* *
* ohsm_get_inode_for_debug () is used for debugging *
* it scans all inodes in the file system and prints *
* them along with their size and tier-id *
* *
***************************************************************/
int
ohsm_get_inodes_for_debug (void) {
unsigned char start_ino = 0;
int ret;
unsigned long nr_groups;
unsigned long i = 0;
unsigned long nr_inodes_per_group;
unsigned long inode_no = 0;
struct buffer_head *bh = NULL;
struct inode *temp_inode = NULL;
struct ext2_inode_info *ei = NULL;
nr_groups = ohsm_sbi->s_groups_count;
nr_inodes_per_group = ohsm_sbi->s_inodes_per_group;
printk ("\n\nOHSM: Inode No.\tFile Size\tHome TID\n");
for (i = 0, start_ino = 11; i < nr_groups; i++, start_ino = 0) {
bh = (struct buffer_head *) read_inode_bitmap (ohsm_sb, i);
if (!bh) {
printk ("\nOHSM: BH is null.");
return OHSM_ERR_FS;
}
for (inode_no = start_ino; inode_no < nr_inodes_per_group - 1; inode_no++) {
ret = ext2_test_bit (inode_no, (unsigned long *) (bh->b_data));
if (ret) {
temp_inode = ext2_iget (ohsm_sb, (inode_no + 1) + i * nr_inodes_per_group);
if (!temp_inode) {
printk ("\nOHSM: ext2_iget returned NULL.");
brelse(bh);
return OHSM_ERR_FS;
}
ei = EXT2_I (temp_inode);
if (!ei) {
printk ("\nOHSM: EXT2_I returned NULL.");
iput(temp_inode);
brelse(bh);
return OHSM_ERR_FS;
}
if(temp_inode->i_size < 1024)
printk ("\n%lu\t\t%lub\t\t%u",(unsigned long) temp_inode->i_ino, (unsigned long) temp_inode->i_size, (unsigned int)ei->ohsm_home_tid);
else
printk ("\n%lu\t\t%luk\t\t%u",(unsigned long) temp_inode->i_ino, (unsigned long) temp_inode->i_size >> 10, (unsigned int)ei->ohsm_home_tid);
iput(temp_inode);
}
}
brelse(bh);
}
return OHSM_SUCCESS;
}
/****************************************************************
* *
* debug_print_sam () print the sam table conatining the *
* block group range per tier *
* *
***************************************************************/
void
debug_print_sam (void) {
int i = 0;
int j;
printk ("\nOHSM: Printing SAM Table.\n");
for (i = 0; i < MAX_TIER_ALLOWED; i++) {
ohsm_printk ("\n");
if(sam[i][0]==0)
continue;
else
for (j = 0; j < (MAX_DISK_ALLOWED * 2 + 1); j++) {
printk (" - %lu - ", sam[i][j]);
if(sam[i][j] == sam[0][2])
break;
}
printk ("\n");
}
}
/****************************************************************
* *
* demo_reloc () is defined for demo. It relocates the *
* inode submitted by the user. *
* *
***************************************************************/
int
demo_reloc(struct ohsm_debug_reloc *reloc_demo) {
int ret;
struct inode *src_ind ;
/* Get the source inode */
src_ind = ext2_iget (ohsm_sb, reloc_demo->inum);
if (!src_ind) {
printk (KERN_DEBUG "\nOHSM: Source Inode Not Found, ext2_iget returned NULL.");
return OHSM_ERR_INO_NOEXIST;
}
EXT2_I(src_ind)->ohsm_dest_tid = reloc_demo->dest;
iput(src_ind);
ret = ohsm_realloc_mcp(reloc_demo->inum);
return ret;
}
/****************************************************************
* *
* device_driver related functions *
* *
***************************************************************/
struct file_operations fops = {
.ioctl = device_ioctl,
.read = NULL,
.write = NULL,
};
/****************************************************************
* *
* ohsm_disable () disables OHSM and free all data *
* structures allocated *
* *
***************************************************************/
int
ohsm_init (void) {
Major = register_chrdev (0, DEVICE_NAME, &fops);
if (Major < 0) {
printk ("\nOHSM: Unable to initialize driver.");
return Major;
}
ohsm_printk ("\nOHSM: Module Initialized.");
ohsm_enabled = UNSET;
ohsm_relocating = UNSET;
ohsm_get_tier_fptr = &ohsm_get_tier;
return OHSM_SUCCESS;
}
/****************************************************************
* *
* ohsm_disable () disables OHSM and free all data *
* structures allocated *
* bug *
***************************************************************/
void
ohsm_cleanup (void) {
int ret;
ret = ohsm_disable();
unregister_chrdev (Major, DEVICE_NAME);
ohsm_get_tier_fptr = NULL;
ohsm_printk ("\nOSHM: Module unloaded.");
}
/****************************************************************
* *
* ohsm_sanity_check () checks whether the ohsm is currently *
* enabled and the superblock of the mounted file system *
* exist. *
* *
***************************************************************/
int
ohsm_sanity_check (void) {
if (!ohsm_enabled) {
ohsm_printk ("\nOHSM: OHSM is currently Disabled " );
return OHSM_ERR_OHSM_INACTIVE;
}
else if (!ohsm_sb) {
printk ("\nOHSM: oshm_sb is null.");
return OHSM_ERR_NULL_PTR;
}
else if (!ohsm_sbi) {
printk ("\nOHSM: oshm_sbi is null.");
return OHSM_ERR_NULL_PTR;
}
return OHSM_SUCCESS;
}
/****************************************************************
* *
* ohsm_disable () disables OHSM and free all data *
* structures allocated *
* *
***************************************************************/
static int
device_ioctl (struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg) {
int ret = 0;
unsigned long rules = 0;
struct ohsm_debug_reloc *reloc_demo;
switch (cmd) {
case IOC_OHSM_ENABLE:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
if (ohsm_enabled) {
printk ("\nOHSM: OHSM already enabled.");
return OHSM_ERR_ALREADY_EN;
}
ohsm_admin_info = (struct ohsm_struct_for_ioctl *) arg;
if (!ohsm_admin_info) {
printk ("\nOHSM: NULL passed from userspace.");
return OHSM_ERR_NULL_PTR;
}
ohsm_printk ("\nOHSM: Request to enable OHSM.");
ohsm_printk ("\nOHSM: The Mount Point = %s.", ohsm_admin_info->mountpoint);
if (verify_mntpt (ohsm_admin_info->mountpoint)) {
return OHSM_ERR_MNTPNT;
}
if (ohsm_admin_info->ptr_dev_file == NULL) {
printk ("\nOHSM: Device topology is NULL");
return OHSM_ERR_NULL_PTR;
}
if (ohsm_admin_info->ptr_alloc_policy == NULL) {
printk ("\nOHSM: Allocation policy is NULL");
return OHSM_ERR_ALLOC_PTR;
}
if (ohsm_admin_info->ptr_reloc_policy == NULL) {
printk ("\nOHSM: Relocation policy is NULL.");
return OHSM_ERR_RELOC_PTR;
}
dev_info = (struct ohsm_tier_dev_info *)kmalloc(sizeof(struct ohsm_tier_dev_info), GFP_KERNEL);
allocpol = (struct ohsm_allocation_policy *)kmalloc(sizeof(struct ohsm_allocation_policy), GFP_KERNEL);
relocpol = (struct ohsm_reloc_policy *)kmalloc(sizeof(struct ohsm_reloc_policy), GFP_KERNEL);
if(copy_from_user((void *)dev_info,(void*)ohsm_admin_info->ptr_dev_file,sizeof(struct ohsm_tier_dev_info))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying dev_info");
return OHSM_ERROR;
}
if(copy_from_user((void *)allocpol,(void*)ohsm_admin_info->ptr_alloc_policy,sizeof(struct ohsm_allocation_policy))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying allocation policy");
return OHSM_ERROR;
}
if(copy_from_user((void *)relocpol,(void*)ohsm_admin_info->ptr_reloc_policy,sizeof(struct ohsm_reloc_policy))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying relocation policy");
return OHSM_ERROR;
}
ohsm_set_bg_dm_info ();
turn_the_tables();
ohsm_enabled = 1;
return OHSM_SUCCESS;
case OHSM_SELECT_RELOCATION:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if(ret)
return ret;
ohsm_relocating = SET;
ret = ohsm_get_inodes_for_relocation (arg);
ohsm_relocating = UNSET;
ohsm_printk ("\nOHSM: Relocation process done, returning with ret = %d.",ret);
return ret;
case OHSM_RELOCATION:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if(ret)
return ret;
BUG_ON (relocpol == NULL);
ohsm_relocating = SET;
rules = (1 << (relocpol->cnt_policies )) - 1;
ret = ohsm_get_inodes_for_relocation ((unsigned long) &rules);
ohsm_relocating = UNSET;
ohsm_printk ("\nOHSM: Relocation process done, returning with ret = %d.",ret);
return ret;
case DISABLE_OHSM:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
if (ohsm_relocating) {
return OHSM_ERR_RELOC_ON;
}
ret = ohsm_sanity_check();
if (ret)
return ret;
return ohsm_disable();
case DISPLAY_SAM:
ret = ohsm_sanity_check();
if (ret)
return ret;
debug_print_sam();
return OHSM_SUCCESS;
case DISPLAY_INODES:
ret = ohsm_sanity_check();
if (ret)
return ret;
ret = ohsm_get_inodes_for_debug ();
return ret;
case DEMO_RELOC:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if (ret)
return ret;
reloc_demo = (struct ohsm_debug_reloc *) arg;
ret = demo_reloc(reloc_demo);
return ret;
case OHSM_STATUS :
if (ohsm_enabled)
ohsm_printk ("\nOHSM: OHSM is currently Enabled." );
else
ohsm_printk ("\nOHSM: OHSM is currently Disabled " );
return !ohsm_enabled ;
case OHSM_GET_TIER_INFO:
ret = ohsm_sanity_check();
if (ret)
return ret;
BUG_ON(dev_info == NULL);
if (copy_to_user ((void*)arg, (void*)dev_info, sizeof (struct ohsm_tier_dev_info)))
return OHSM_ERR_DISP_DEVICE;
return OHSM_SUCCESS;
case OHSM_GET_ALLOC_POL:
ret = ohsm_sanity_check();
if (ret)
return ret;
BUG_ON (allocpol == NULL);
if (copy_to_user ((void*)arg, (void*)allocpol, sizeof (struct ohsm_allocation_policy)))
return OHSM_ERR_DISP_ALLOC;
return OHSM_SUCCESS;
case OHSM_GET_RELOC_POL:
ret = ohsm_sanity_check();
if (ret)
return ret;
BUG_ON (relocpol == NULL);
if (copy_to_user ((void*)arg, (void*)relocpol, sizeof (struct ohsm_reloc_policy)))
return OHSM_ERR_DISP_RELOC;
return OHSM_SUCCESS;
case OHSM_SET_ALLOC_POL:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if (ret)
return ret;
memset (allocpol, 0, sizeof (struct ohsm_allocation_policy));
if (copy_from_user ((void *)allocpol, (void*)arg, sizeof (struct ohsm_allocation_policy))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying allocation policy");
return OHSM_ERROR;
}
return OHSM_SUCCESS;
case OHSM_SET_RELOC_POL:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if (ret)
return ret;
memset (relocpol, 0, sizeof (struct ohsm_reloc_policy));
if(copy_from_user ((void *)relocpol,(void*)arg,sizeof(struct ohsm_reloc_policy))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying relocation policy");
return OHSM_ERROR;
}
return OHSM_SUCCESS;
case OHSM_SET_TIER_INFO:
if (!capable (CAP_SYS_ADMIN))
return -EPERM;
ret = ohsm_sanity_check();
if (ret)
return ret;
memset (dev_info, 0, sizeof(struct ohsm_tier_dev_info));
if (copy_from_user ((void *)dev_info, (void*)arg, sizeof (struct ohsm_tier_dev_info))) {
printk(KERN_ALERT "OHSM: OHSM_ERRor copying tier device information");
return OHSM_ERROR;
}
ohsm_set_bg_dm_info ();
turn_the_tables();
return OHSM_SUCCESS;
}
return OHSM_SUCCESS;
}
module_init(ohsm_init);
module_exit(ohsm_cleanup);
MODULE_LICENSE ("GPL v2");
MODULE_AUTHOR ("Rishi Bhushan Agrawal, Vineet Agarwal, Rohit Sharma");
Powered by
Google Project Hosting