-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_test.c
510 lines (467 loc) · 11 KB
/
fs_test.c
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
/*
* written by Yubo
*/
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <dirent.h>
#include <unistd.h>
#include "pacon.h"
#define TEST_TYPE 0 // 0 is mirco test, 1 is pressure test, 2 is cregion joint test
// 3 is eviction test, 4 is batch permission test
int test_init(struct pacon *pacon)
{
return init_pacon(pacon);
}
int test_free(struct pacon *pacon)
{
return free_pacon(pacon);
}
int test_mkdir(struct pacon *pacon, char *path, mode_t mode)
{
return pacon_mkdir(pacon, path, mode);
}
int test_create(struct pacon *pacon, char *path, mode_t mode)
{
return pacon_create(pacon, path, mode);
}
int test_stat(struct pacon *pacon, char *path, struct pacon_stat* st)
{
return pacon_getattr(pacon, path, st);
}
int test_rm(struct pacon *pacon, char *path)
{
return pacon_rm(pacon, path);
}
int test_open_wr(struct pacon *pacon, char *path, int flag, mode_t mode)
{
int ret;
struct pacon_file *p_file = new_pacon_file();
ret = pacon_open(pacon, path, flag, mode, p_file);
if (ret == -1)
{
printf("fail to open file\n");
return -1;
}
char *data = "hello, you are a pig";
int size = strlen(data);
ret = pacon_write(pacon, path, p_file, data, size, 0);
if (ret == -1)
{
printf("write file error\n");
return -1;
}
char out[128];
ret = pacon_read(pacon, path, p_file, out, size, 0);
if (ret <= 0)
{
printf("read file error\n");
return -1;
}
printf("file data: %s\n", out);
//pacon_close(pacon, p_file);
// test rewrite
char *update = "Opsss";
int update_size = strlen(update);
ret = pacon_write(pacon, path, p_file, update, update_size, 0);
if (ret == -1)
{
printf("rewrite error\n");
return -1;
}
char up_out[128];
ret = pacon_read(pacon, path, p_file, out, size, 0);
if (ret <= 0)
{
printf("read file error\n");
return -1;
}
printf("file data: %s\n", out);
return ret;
}
int test_create_write(struct pacon *pacon, char *path, int flag, mode_t mode)
{
int ret;
struct pacon_file *p_file = new_pacon_file();
char *data = "test write after create";
int size = strlen(data);
ret = pacon_create_write(pacon, path, mode, data, size, p_file);
if (ret == 0)
{
printf("write after create success\n");
} else {
printf("write after create error\n");
return -1;
}
// read it for test
//struct pacon_file *p_file = new_pacon_file();
ret = pacon_open(pacon, path, flag, mode, p_file);
if (ret == -1)
{
printf("fail to open file\n");
return -1;
}
char out[128];
ret = pacon_read(pacon, path, p_file, out, size, 0);
if (ret <= 0)
{
printf("read file error\n");
return -1;
}
printf("file data: %s\n", out);
return ret;
}
int test_fsync(struct pacon *pacon, char *path)
{
int ret;
struct pacon_file *p_file = new_pacon_file();
ret = pacon_open(pacon, path, 0, 0, p_file);
if (ret == -1)
{
printf("fail to open file\n");
return -1;
}
ret = pacon_fsync(pacon, path, p_file);
if (ret != 0)
{
printf("fsync error\n");
return -1;
}
return 0;
}
int test_readdir(struct pacon *pacon, char *path)
{
int ret;
DIR *dir;
struct dirent *entry;
dir = pacon_opendir(pacon, path);
entry = pacon_readdir(dir);
while (entry != NULL)
{
printf("entry name: %s\n", entry->d_name);
entry = pacon_readdir(dir);
}
pacon_closedir(pacon, dir);
return 0;
}
int test_rename(struct pacon *pacon, char *oldpath, char *newpath)
{
return pacon_rename(pacon, oldpath, newpath);
}
int test_rmdir(struct pacon *pacon, char *path)
{
return pacon_rmdir(pacon, path);
}
/*
int test_rm_dir()
{
return 0;
}
int test_chmod()
{
return 0;
}
int exc_test()
{
return 0;
}
*/
void batch_mkdir(struct pacon *pacon, char* p_dir, int num)
{
int i, ret, p_len = strlen(p_dir);
char dir[128];
memcpy(dir, p_dir, p_len);
dir[p_len] = '/';
char c[8];
for (i = 0; i < num; ++i)
{
sprintf(c, "%d", i);
int c_len = strlen(c);
memcpy(dir+p_len+1, c, c_len);
dir[p_len+c_len+1] = '\0';
ret = pacon_mkdir(pacon, dir, S_IFDIR | 0755);
if (ret != 0)
{
printf("batch mkdir error, path: %s\n", dir);
break;
}
}
}
int main(int argc, char const *argv[])
{
int ret;
struct pacon *pacon = (struct pacon *)malloc(sizeof(struct pacon));
/*pacon->mount_path[0] = '/';
pacon->mount_path[1] = '\0'; */
if (TEST_TYPE == 0 || TEST_TYPE == 1 || TEST_TYPE == 4)
{
ret = set_root_path(pacon, "/mnt/beegfs");
} else if (TEST_TYPE == 2) {
ret = set_root_path(pacon, "/mnt/beegfs/cr0");
} else if (TEST_TYPE == 3) {
ret = set_root_path(pacon, "/mnt/beegfs/pacon");
}
if (ret != 0)
{
printf("init pacon error\n");
return -1;
}
pacon->kv_type = 0;
ret = test_init(pacon);
if (ret != 0)
{
printf("init pacon error\n");
return -1;
}
printf("init pacon success\n");
sleep(1);
if (TEST_TYPE == 0)
{
printf("\n");
printf("/********** mkdir test **********/\n");
ret = test_mkdir(pacon, "/mnt/beegfs/test", S_IFDIR | 0755);
if (ret != 0)
{
printf("mkdir error\n");
return -1;
}
printf("mkdir test success, path: /mnt/beegfs/test\n");
ret = test_mkdir(pacon, "/mnt/beegfs/test/t1", S_IFDIR | 0755);
if (ret != 0)
{
printf("mkdir error\n");
return -1;
}
printf("mkdir test success, path: /mnt/beegfs/test/t1\n");
printf("\n");
printf("/********** create test **********/\n");
ret = test_create(pacon, "/mnt/beegfs/file", S_IFREG | 0644);
if (ret != 0)
{
printf("create error\n");
return -1;
}
printf("create file test succee, path: /mnt/beegfs/file\n");
ret = test_create(pacon, "/mnt/beegfs/test/f1", S_IFREG | 0644);
if (ret != 0)
{
printf("create error\n");
return -1;
}
printf("create file test succee, path: /mnt/beegfs/test/f1\n");
printf("\n");
printf("/********** open/rw test **********/\n");
ret = test_open_wr(pacon, "/mnt/beegfs/file", 0, 0);
if (ret <= 0)
{
printf("open/rw error\n");
return -1;
}
printf("open/rw success\n");
printf("\n");
printf("/********** create_write test **********/\n");
ret = test_create_write(pacon, "/mnt/beegfs/file_cw", 0, 0);
if (ret <= 0)
{
printf("create_write error\n");
return -1;
}
printf("create_write success\n");
printf("\n");
printf("/********** fsync test **********/\n");
ret = test_fsync(pacon, "/mnt/beegfs/file_cw");
if (ret != 0)
{
printf("fsync error\n");
return -1;
}
printf("fsync success\n");
printf("\n");
printf("/********** stat test **********/\n");
struct pacon_stat* st = (struct pacon_stat *)malloc(sizeof(struct pacon_stat));
ret = test_stat(pacon, "/mnt/beegfs/file", st);
if (ret != 0)
{
printf("stat error\n");
return -1;
} else {
printf("mode: %d\n", st->mode);
printf("size: %d\n", st->size);
}
printf("stat test succee\n");
printf("\n");
printf("/********** rm test **********/\n");
ret = test_rm(pacon, "/mnt/beegfs/file");
if (ret != 0)
{
printf("rm error\n");
return -1;
}
ret = test_stat(pacon, "/mnt/beegfs/file", st);
if (ret != 0)
printf("rm test succee\n");
else
printf("rm test error\n");
printf("\n");
printf("/********** readdir test **********/\n");
pacon_barrier(pacon, 1);
ret = test_readdir(pacon, "/mnt/beegfs/test");
if (ret == 0)
printf("readdir test succee\n");
else
printf("readdir test error\n");
//printf("\n");
//printf("/********** rename test **********/\n");
/*ret = test_rename(pacon, "/mnt/beegfs/test", "/mnt/beegfs/test1");
if (ret == 0)
printf("rename test succee\n");
else
printf("rename test error\n");*/
printf("\n");
printf("/********** rmdir test **********/\n");
pacon_barrier(pacon, 1);
ret = test_rmdir(pacon, "/mnt/beegfs/test");
if (ret != 0)
{
printf("rmdir error\n");
return -1;
}
ret = test_stat(pacon, "/mnt/beegfs/test", st);
if (ret != 0)
printf("rmdir test succee\n");
else
printf("rmdir test error\n");
printf("\n");
printf("/********** free pacon **********/\n");
ret = test_free(pacon);
if (ret != 0)
{
printf("free pacon error\n");
return -1;
}
printf("free pacon success\n");
}
if (TEST_TYPE == 1)
{
int test_num = 1000;
struct timespec start;
struct timespec end;
clock_gettime(CLOCK_REALTIME, &start);
batch_mkdir(pacon, "/mnt/beegfs/pacon", test_num);
clock_gettime(CLOCK_REALTIME, &end);
long timediff;
timediff = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000;
printf("batch mkdir %ld us\n", timediff);
//printf("throughput: %ld OPS\n", test_num/t);
}
if (TEST_TYPE == 2)
{
int cr_num = 1;
int num = 0;
// create dir and file
if (num == 0)
{
ret = test_mkdir(pacon, "/mnt/beegfs/cr0/d", S_IFDIR | 0755);
//ret = test_create(pacon, "/mnt/beegfs/cr0/f", S_IFREG | 0644);
if (ret != 0)
{
printf("mkdir in cr0 error\n");
return -1;
}
}
// joint to cregion 0 and stat dir/file in it
if (num == 1)
{
ret = cregion_joint(pacon, cr_num);
if (ret != 0)
{
printf("joint cregions error\n");
return -1;
}
struct pacon_stat* r_st = (struct pacon_stat *)malloc(sizeof(struct pacon_stat));
ret = test_stat(pacon, "/mnt/beegfs/cr0/d", r_st);
if (ret == 0)
{
printf("mode: %d\n", r_st->mode);
printf("size: %d\n", r_st->size);
printf("stat joint cregions success\n");
} else {
printf("stat joint cregions error\n");
return -1;
}
ret = cregion_split(pacon, cr_num);
if (ret == 0)
{
printf("split cregions success\n");
} else {
printf("split cregions error\n");
return -1;
}
}
ret = test_free(pacon);
if (ret != 0)
{
printf("free pacon error\n");
return -1;
}
printf("free pacon success\n");
}
if (TEST_TYPE == 3)
{
int ret1, ret2, ret3;
ret1 = test_mkdir(pacon, "/mnt/beegfs/pacon/test", S_IFDIR | 0755);
ret2 = test_mkdir(pacon, "/mnt/beegfs/pacon/test/d1", S_IFDIR | 0755);
ret3 = test_create(pacon, "/mnt/beegfs/pacon/test/f1", S_IFREG | 0644);
if (ret1 != 0 || ret2 != 0 || ret3 != 0)
{
printf("mkdir or create error\n");
return -1;
}
ret = evict_metadata(pacon);
if (ret != 0)
{
printf("evict error 1\n");
return -1;
}
/*struct pacon_stat* r_st = (struct pacon_stat *)malloc(sizeof(struct pacon_stat));
ret = test_stat(pacon, "/mnt/beegfs/pacon/test/d1", r_st);
if (ret != 0)
{
printf("evict error 2\n");
return -1;
} else {
printf("evict test success\n");
}*/
}
if (TEST_TYPE == 4)
{
struct permission_info *perm_info = (struct permission_info *)malloc(sizeof(struct permission_info));
pacon_init_perm_info(perm_info);
perm_info->nom_dir_mode = 755;
perm_info->nom_f_mode = 644;
perm_info->sp_num = 1;
char *sp = "/mnt/beegfs/sp";
sprintf(perm_info->sp_path[0], "%s", sp);
perm_info->sp_dir_modes[0] = 111;
ret = pacon_set_permission(pacon, perm_info);
if (ret != 0)
{
printf("batch set permission error\n");
return -1;
}
ret = test_mkdir(pacon, "/mnt/beegfs/sp", S_IFDIR | 0755);
if (ret != 0)
{
printf("sp path mkdir error\n");
return -1;
}
ret = test_mkdir(pacon, "/mnt/beegfs/sp/d1", S_IFDIR | 0755);
if (ret != 0)
{
printf("batch permission test success\n");
} else {
printf("batch permission test error\n");
}
}
return 0;
}