| 1 | |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <stdarg.h> |
|---|
| 6 | #include <time.h> |
|---|
| 7 | #include <unistd.h> |
|---|
| 8 | #include "pvfs2-request.h" |
|---|
| 9 | #include "pvfs2-sysint.h" |
|---|
| 10 | #include "pvfs2-util.h" |
|---|
| 11 | #include "pvfs2-dist-simple-stripe.h" |
|---|
| 12 | |
|---|
| 13 | char buff[1000]; |
|---|
| 14 | char check_buff[1000]; |
|---|
| 15 | char * dashes = "--------------------------------------------------------"; |
|---|
| 16 | char * spaces = " "; |
|---|
| 17 | char * as = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; |
|---|
| 18 | char * bs = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; |
|---|
| 19 | char * cs = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"; |
|---|
| 20 | char * xs = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; |
|---|
| 21 | |
|---|
| 22 | int verbose = 0; |
|---|
| 23 | |
|---|
| 24 | void reset_buff(void); |
|---|
| 25 | void print_buff(int padding, int len); |
|---|
| 26 | |
|---|
| 27 | int do_smallmem_noncontig_read( |
|---|
| 28 | PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 29 | int memsize, |
|---|
| 30 | int chunks, |
|---|
| 31 | ...); |
|---|
| 32 | |
|---|
| 33 | int do_noncontig_read( |
|---|
| 34 | PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 35 | int chunks, |
|---|
| 36 | ...); |
|---|
| 37 | |
|---|
| 38 | int do_contig_read( |
|---|
| 39 | PVFS_object_ref ref, |
|---|
| 40 | PVFS_credentials * creds, |
|---|
| 41 | PVFS_offset offset, |
|---|
| 42 | int length, |
|---|
| 43 | PVFS_Request freq); |
|---|
| 44 | |
|---|
| 45 | int do_write(PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 46 | PVFS_offset offset, PVFS_size size, char * buff); |
|---|
| 47 | |
|---|
| 48 | int check_results( |
|---|
| 49 | PVFS_offset offset, |
|---|
| 50 | int total_read, |
|---|
| 51 | PVFS_offset * offsets, |
|---|
| 52 | int32_t * sizes, |
|---|
| 53 | int count); |
|---|
| 54 | |
|---|
| 55 | int check_smallmem_results( |
|---|
| 56 | PVFS_offset offset, |
|---|
| 57 | int total_read, |
|---|
| 58 | int memsize, |
|---|
| 59 | PVFS_offset * offsets, |
|---|
| 60 | int32_t * sizes, |
|---|
| 61 | int count); |
|---|
| 62 | |
|---|
| 63 | void reset_buff(void) |
|---|
| 64 | { |
|---|
| 65 | memset(buff, 'X', 1000); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | void print_buff(int padding, int len) |
|---|
| 69 | { |
|---|
| 70 | int i = 0; |
|---|
| 71 | |
|---|
| 72 | fprintf(stdout, "RESULT: \t"); |
|---|
| 73 | fprintf(stdout, "%.*s", padding, spaces); |
|---|
| 74 | |
|---|
| 75 | for(; i < 50; ++i) |
|---|
| 76 | { |
|---|
| 77 | fprintf(stdout, "%c", (buff[i] == 0 ? '-' : buff[i])); |
|---|
| 78 | } |
|---|
| 79 | fprintf(stdout, "\t (%d bytes)\n\n", len); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | int check_smallmem_results( |
|---|
| 83 | PVFS_offset offset, |
|---|
| 84 | int total_read, |
|---|
| 85 | int memsize, |
|---|
| 86 | PVFS_offset * offsets, |
|---|
| 87 | int32_t * sizes, |
|---|
| 88 | int count) |
|---|
| 89 | { |
|---|
| 90 | int stop_size; |
|---|
| 91 | int total_size = 0; |
|---|
| 92 | int i = 0; |
|---|
| 93 | int res = 0; |
|---|
| 94 | |
|---|
| 95 | stop_size = (memsize > total_read) ? total_read : memsize; |
|---|
| 96 | |
|---|
| 97 | for(; i < count; ++i) |
|---|
| 98 | { |
|---|
| 99 | if(total_size + sizes[i] > stop_size) |
|---|
| 100 | { |
|---|
| 101 | sizes[i] = stop_size - total_size; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | res = memcmp(check_buff + offset + offsets[i], |
|---|
| 105 | buff + total_size, sizes[i]); |
|---|
| 106 | if(res != 0) |
|---|
| 107 | { |
|---|
| 108 | if(verbose) |
|---|
| 109 | { |
|---|
| 110 | printf("Invalid result: offset: %d, size: %d\n", |
|---|
| 111 | (int32_t)offsets[i], (int32_t)sizes[i]); |
|---|
| 112 | } |
|---|
| 113 | return res; |
|---|
| 114 | } |
|---|
| 115 | total_size += sizes[i]; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | return 0; |
|---|
| 119 | |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | int check_results( |
|---|
| 123 | PVFS_offset offset, |
|---|
| 124 | int total_read, |
|---|
| 125 | PVFS_offset * offsets, |
|---|
| 126 | int32_t * sizes, |
|---|
| 127 | int count) |
|---|
| 128 | { |
|---|
| 129 | int total_size = 0; |
|---|
| 130 | int i = 0; |
|---|
| 131 | int res; |
|---|
| 132 | |
|---|
| 133 | for(; i < count; ++i) |
|---|
| 134 | { |
|---|
| 135 | if(total_read < (total_size + sizes[i])) |
|---|
| 136 | { |
|---|
| 137 | sizes[i] = (total_read - total_size); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | res = memcmp( |
|---|
| 141 | check_buff + offset + offsets[i], buff + total_size, sizes[i]); |
|---|
| 142 | if(res != 0) |
|---|
| 143 | { |
|---|
| 144 | if(verbose) |
|---|
| 145 | { |
|---|
| 146 | printf("Invalid result: offset: %u, size: %d\n", |
|---|
| 147 | (int32_t)offsets[i], (int32_t)sizes[i]); |
|---|
| 148 | } |
|---|
| 149 | return res; |
|---|
| 150 | } |
|---|
| 151 | total_size += sizes[i]; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | return 0; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | int do_smallmem_noncontig_read( |
|---|
| 159 | PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 160 | int memsize, |
|---|
| 161 | int chunks, |
|---|
| 162 | ...) |
|---|
| 163 | { |
|---|
| 164 | int i; |
|---|
| 165 | int res; |
|---|
| 166 | PVFS_Request memreq, readreq; |
|---|
| 167 | PVFS_sysresp_io io_resp; |
|---|
| 168 | PVFS_size * offsets; |
|---|
| 169 | int32_t * sizes; |
|---|
| 170 | va_list args_list; |
|---|
| 171 | int total = 0; |
|---|
| 172 | |
|---|
| 173 | if(verbose) |
|---|
| 174 | { |
|---|
| 175 | fprintf(stdout, |
|---|
| 176 | "READING:\t"); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | sizes = malloc(sizeof(int32_t) * chunks); |
|---|
| 180 | offsets = malloc(sizeof(PVFS_size) * chunks); |
|---|
| 181 | |
|---|
| 182 | va_start(args_list, chunks); |
|---|
| 183 | |
|---|
| 184 | for(i = 0; i < chunks; ++i) |
|---|
| 185 | { |
|---|
| 186 | offsets[i] = (PVFS_size)va_arg(args_list, int); |
|---|
| 187 | sizes[i] = (int32_t)va_arg(args_list, int); |
|---|
| 188 | |
|---|
| 189 | if(verbose) |
|---|
| 190 | { |
|---|
| 191 | total += fprintf(stdout, |
|---|
| 192 | "%.*s<%.*s>", |
|---|
| 193 | (int) (offsets[i] - total), spaces, |
|---|
| 194 | (int) (sizes[i] - 2), spaces); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | va_end(args_list); |
|---|
| 200 | |
|---|
| 201 | if(verbose) |
|---|
| 202 | { |
|---|
| 203 | fprintf(stdout, " (memsize = %d)\n", memsize); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | PVFS_Request_indexed(chunks, sizes, offsets, PVFS_BYTE, &readreq); |
|---|
| 207 | PVFS_Request_contiguous(memsize, PVFS_BYTE, &memreq); |
|---|
| 208 | |
|---|
| 209 | reset_buff(); |
|---|
| 210 | |
|---|
| 211 | res = PVFS_sys_read( |
|---|
| 212 | ref, readreq, 0, buff, memreq, creds, &io_resp, NULL); |
|---|
| 213 | if(res < 0) |
|---|
| 214 | { |
|---|
| 215 | PVFS_perror("read failed with errcode", res); |
|---|
| 216 | return res; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | if(verbose) |
|---|
| 220 | { |
|---|
| 221 | print_buff(0, io_resp.total_completed); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | res = check_smallmem_results( |
|---|
| 225 | 0, io_resp.total_completed, memsize, offsets, sizes, chunks); |
|---|
| 226 | |
|---|
| 227 | free(offsets); |
|---|
| 228 | free(sizes); |
|---|
| 229 | |
|---|
| 230 | return res; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | int do_noncontig_read( |
|---|
| 234 | PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 235 | int chunks, |
|---|
| 236 | ...) |
|---|
| 237 | { |
|---|
| 238 | int i; |
|---|
| 239 | int res; |
|---|
| 240 | PVFS_Request memreq, readreq; |
|---|
| 241 | PVFS_sysresp_io io_resp; |
|---|
| 242 | PVFS_size * offsets; |
|---|
| 243 | int32_t * sizes; |
|---|
| 244 | PVFS_size readreq_size; |
|---|
| 245 | va_list args_list; |
|---|
| 246 | int total = 0; |
|---|
| 247 | |
|---|
| 248 | if(verbose) |
|---|
| 249 | { |
|---|
| 250 | fprintf(stdout, |
|---|
| 251 | "READING:\t"); |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | sizes = malloc(sizeof(int32_t) * chunks); |
|---|
| 255 | offsets = malloc(sizeof(PVFS_size) * chunks); |
|---|
| 256 | |
|---|
| 257 | va_start(args_list, chunks); |
|---|
| 258 | |
|---|
| 259 | for(i = 0; i < chunks; ++i) |
|---|
| 260 | { |
|---|
| 261 | offsets[i] = (PVFS_size)va_arg(args_list, int); |
|---|
| 262 | sizes[i] = (int32_t)va_arg(args_list, int); |
|---|
| 263 | |
|---|
| 264 | if(verbose) |
|---|
| 265 | { |
|---|
| 266 | total += fprintf(stdout, |
|---|
| 267 | "%.*s<%.*s>", |
|---|
| 268 | (int) (offsets[i] - total), spaces, |
|---|
| 269 | (int) (sizes[i] - 2), spaces); |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | va_end(args_list); |
|---|
| 274 | |
|---|
| 275 | if(verbose) |
|---|
| 276 | { |
|---|
| 277 | fprintf(stdout, "\n"); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | PVFS_Request_indexed(chunks, sizes, offsets, PVFS_BYTE, &readreq); |
|---|
| 281 | PVFS_Request_size(readreq, &readreq_size); |
|---|
| 282 | PVFS_Request_contiguous(readreq_size, PVFS_BYTE, &memreq); |
|---|
| 283 | |
|---|
| 284 | reset_buff(); |
|---|
| 285 | |
|---|
| 286 | res = PVFS_sys_read( |
|---|
| 287 | ref, readreq, 0, buff, memreq, creds, &io_resp, NULL); |
|---|
| 288 | if(res < 0) |
|---|
| 289 | { |
|---|
| 290 | PVFS_perror("read failed with errcode", res); |
|---|
| 291 | return res; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | if(verbose) |
|---|
| 295 | { |
|---|
| 296 | print_buff(0, io_resp.total_completed); |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | res = check_results(0, io_resp.total_completed, offsets, sizes, chunks); |
|---|
| 300 | |
|---|
| 301 | free(offsets); |
|---|
| 302 | free(sizes); |
|---|
| 303 | |
|---|
| 304 | return res; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | int do_contig_read( |
|---|
| 308 | PVFS_object_ref ref, |
|---|
| 309 | PVFS_credentials * creds, |
|---|
| 310 | PVFS_offset offset, |
|---|
| 311 | int length, |
|---|
| 312 | PVFS_Request freq) |
|---|
| 313 | { |
|---|
| 314 | int res; |
|---|
| 315 | PVFS_sysresp_io io_resp; |
|---|
| 316 | PVFS_Request memreq, readreq; |
|---|
| 317 | |
|---|
| 318 | if(verbose) |
|---|
| 319 | { |
|---|
| 320 | fprintf(stdout, |
|---|
| 321 | "READING:\t" |
|---|
| 322 | "%.*s<%.*s>\n", |
|---|
| 323 | (int)offset, spaces, |
|---|
| 324 | length - 2, spaces); |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | res = PVFS_Request_contiguous(length, PVFS_BYTE, &memreq); |
|---|
| 328 | if(res < 0) |
|---|
| 329 | { |
|---|
| 330 | PVFS_perror("request contig for memory failed with errcode", res); |
|---|
| 331 | return res; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | if(freq) |
|---|
| 335 | { |
|---|
| 336 | readreq = freq; |
|---|
| 337 | } |
|---|
| 338 | else |
|---|
| 339 | { |
|---|
| 340 | res = PVFS_Request_contiguous(length, PVFS_BYTE, &readreq); |
|---|
| 341 | if(res < 0) |
|---|
| 342 | { |
|---|
| 343 | PVFS_perror("request contig for file failed with errcode", res); |
|---|
| 344 | return res; |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | reset_buff(); |
|---|
| 349 | |
|---|
| 350 | res = PVFS_sys_read( |
|---|
| 351 | ref, readreq, offset, buff, memreq, creds, &io_resp, NULL); |
|---|
| 352 | if(res < 0) |
|---|
| 353 | { |
|---|
| 354 | PVFS_perror("read failed with errcode", res); |
|---|
| 355 | return res; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | if(verbose) |
|---|
| 359 | { |
|---|
| 360 | print_buff(offset, io_resp.total_completed); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | res = check_results(0, io_resp.total_completed, |
|---|
| 364 | (PVFS_offset *)&offset, &length, 1); |
|---|
| 365 | |
|---|
| 366 | return res; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | int do_write(PVFS_object_ref ref, PVFS_credentials * creds, |
|---|
| 370 | PVFS_offset offset, PVFS_size size, char * buff) |
|---|
| 371 | { |
|---|
| 372 | PVFS_Request filereq; |
|---|
| 373 | PVFS_Request memreq; |
|---|
| 374 | PVFS_sysresp_io io_resp; |
|---|
| 375 | int res; |
|---|
| 376 | |
|---|
| 377 | /* setup check_buff */ |
|---|
| 378 | memcpy(check_buff + offset, buff, size); |
|---|
| 379 | |
|---|
| 380 | if(verbose) |
|---|
| 381 | { |
|---|
| 382 | fprintf(stdout, |
|---|
| 383 | "WRITING:\t" |
|---|
| 384 | "%.*s%.*s\n\n", |
|---|
| 385 | (int32_t)offset, spaces, |
|---|
| 386 | (int32_t)size, buff); |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | res = PVFS_Request_contiguous(size, PVFS_BYTE, &filereq); |
|---|
| 390 | if(res < 0) |
|---|
| 391 | { |
|---|
| 392 | PVFS_perror("request contig for memory failed with errcode", res); |
|---|
| 393 | return -1; |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | res = PVFS_Request_contiguous(size, PVFS_BYTE, &memreq); |
|---|
| 397 | if(res < 0) |
|---|
| 398 | { |
|---|
| 399 | PVFS_perror("request contig for memory failed with errcode", res); |
|---|
| 400 | return -1; |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | res = PVFS_sys_write( |
|---|
| 404 | ref, filereq, |
|---|
| 405 | offset, buff, memreq, creds, &io_resp, NULL); |
|---|
| 406 | if(res < 0) |
|---|
| 407 | { |
|---|
| 408 | PVFS_perror("write failed with errcode", res); |
|---|
| 409 | return -1; |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | return 0; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | static void usage(void) |
|---|
| 416 | { |
|---|
| 417 | printf("usage: test-zero-fill [<OPTIONS>...]\n"); |
|---|
| 418 | printf("\n<OPTIONS> is one of\n"); |
|---|
| 419 | printf("-v\t\tverbose mode. prints out read results\n"); |
|---|
| 420 | printf("-s <strip size>\tstrip size to use when creating the file\n"); |
|---|
| 421 | printf("-h\t\tprint this help\n"); |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | #define ZEROFILL_FILENAME "test-zerofill" |
|---|
| 425 | |
|---|
| 426 | extern char *optarg; |
|---|
| 427 | extern int optind, opterr, optopt; |
|---|
| 428 | |
|---|
| 429 | int main(int argc, char * argv[]) |
|---|
| 430 | { |
|---|
| 431 | PVFS_sysresp_create create_resp; |
|---|
| 432 | PVFS_sysresp_lookup lookup_resp; |
|---|
| 433 | PVFS_fs_id curfs; |
|---|
| 434 | PVFS_sys_attr attr; |
|---|
| 435 | PVFS_credentials creds; |
|---|
| 436 | PVFS_sys_dist * dist; |
|---|
| 437 | int strip_size = 9; |
|---|
| 438 | int half_strip; |
|---|
| 439 | int before_len, after_len; |
|---|
| 440 | char zerofill_fname[100]; |
|---|
| 441 | PVFS_simple_stripe_params params; |
|---|
| 442 | int32_t res, realres; |
|---|
| 443 | char c; |
|---|
| 444 | |
|---|
| 445 | memset(check_buff, 0, 1000); |
|---|
| 446 | |
|---|
| 447 | while((c = getopt(argc, argv, "vs:")) != EOF) |
|---|
| 448 | { |
|---|
| 449 | switch(c) |
|---|
| 450 | { |
|---|
| 451 | case 'v': |
|---|
| 452 | verbose = 1; |
|---|
| 453 | break; |
|---|
| 454 | case 's': |
|---|
| 455 | strip_size = atoi(optarg); |
|---|
| 456 | break; |
|---|
| 457 | case 'h': |
|---|
| 458 | usage(); |
|---|
| 459 | exit(0); |
|---|
| 460 | case '?': |
|---|
| 461 | usage(); |
|---|
| 462 | exit(1); |
|---|
| 463 | default: |
|---|
| 464 | break; |
|---|
| 465 | } |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | half_strip = (int) strip_size / 2; |
|---|
| 469 | |
|---|
| 470 | res = PVFS_util_init_defaults(); |
|---|
| 471 | if(res < 0) |
|---|
| 472 | { |
|---|
| 473 | PVFS_perror("PVFS_util_init_defaults", res); |
|---|
| 474 | return (-1); |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | res = PVFS_util_get_default_fsid(&curfs); |
|---|
| 478 | if(res < 0) |
|---|
| 479 | { |
|---|
| 480 | PVFS_perror("PVFS_util_get_default_fsid", res); |
|---|
| 481 | return (-1); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | before_len = half_strip - 1; |
|---|
| 485 | after_len = half_strip + (strip_size % 2 == 0 ? 0 : 1) - 2; |
|---|
| 486 | |
|---|
| 487 | if(verbose) |
|---|
| 488 | { |
|---|
| 489 | |
|---|
| 490 | fprintf(stdout, |
|---|
| 491 | "unset = XXXXX\n" |
|---|
| 492 | "zeroed = -----\n\n" |
|---|
| 493 | "DISTRIBUTION (strip size == %d):\n" |
|---|
| 494 | " \t|%.*s0%.*s||%.*s1%.*s||%.*s2%.*s|" |
|---|
| 495 | "|%.*s0%.*s||%.*s1%.*s||%.*s2%.*s|\n", |
|---|
| 496 | strip_size, |
|---|
| 497 | before_len, dashes, after_len, dashes, |
|---|
| 498 | before_len, dashes, after_len, dashes, |
|---|
| 499 | before_len, dashes, after_len, dashes, |
|---|
| 500 | before_len, dashes, after_len, dashes, |
|---|
| 501 | before_len, dashes, after_len, dashes, |
|---|
| 502 | before_len, dashes, after_len, dashes); |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | res = PVFS_sys_lookup(curfs, "/", &creds, &lookup_resp, 0, NULL); |
|---|
| 506 | if(res < 0) |
|---|
| 507 | { |
|---|
| 508 | PVFS_perror("lookup failed with errcode", res); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | dist = PVFS_sys_dist_lookup("simple_stripe"); |
|---|
| 512 | params.strip_size = strip_size; |
|---|
| 513 | |
|---|
| 514 | res = PVFS_sys_dist_setparam(dist, "strip_size", (void *)¶ms); |
|---|
| 515 | if(res < 0) |
|---|
| 516 | { |
|---|
| 517 | PVFS_perror("dist setparam failed with errcode", res); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | PVFS_util_gen_credentials(&creds); |
|---|
| 521 | |
|---|
| 522 | attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; |
|---|
| 523 | attr.owner = creds.uid; |
|---|
| 524 | attr.group = creds.gid; |
|---|
| 525 | attr.perms = 1877; |
|---|
| 526 | attr.atime = attr.ctime = attr.mtime = time(NULL); |
|---|
| 527 | |
|---|
| 528 | sprintf(zerofill_fname, "%s-%d", ZEROFILL_FILENAME, rand()); |
|---|
| 529 | |
|---|
| 530 | if(verbose) |
|---|
| 531 | { |
|---|
| 532 | fprintf(stdout, "filename: %s\n", zerofill_fname); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | res = PVFS_sys_create( |
|---|
| 536 | zerofill_fname, lookup_resp.ref, attr, &creds, dist, &create_resp, NULL, NULL); |
|---|
| 537 | if(res < 0) |
|---|
| 538 | { |
|---|
| 539 | PVFS_perror("create failed with errcode", res); |
|---|
| 540 | return -1; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | half_strip = strip_size / 2; |
|---|
| 544 | |
|---|
| 545 | do_write(create_resp.ref, &creds, 0, half_strip, as); |
|---|
| 546 | |
|---|
| 547 | do_write(create_resp.ref, &creds, strip_size * 2, half_strip, bs); |
|---|
| 548 | |
|---|
| 549 | res = do_contig_read( |
|---|
| 550 | create_resp.ref, &creds, 0, strip_size + half_strip, NULL); |
|---|
| 551 | if(res < 0) |
|---|
| 552 | { |
|---|
| 553 | goto exit; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | res = do_contig_read( |
|---|
| 557 | create_resp.ref, &creds, 0, strip_size + half_strip, PVFS_BYTE); |
|---|
| 558 | if(res < 0) |
|---|
| 559 | { |
|---|
| 560 | goto exit; |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | res = do_contig_read( |
|---|
| 564 | create_resp.ref, &creds, |
|---|
| 565 | (strip_size + half_strip), (strip_size + half_strip), NULL); |
|---|
| 566 | if(res < 0) |
|---|
| 567 | { |
|---|
| 568 | goto exit; |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | res = do_contig_read( |
|---|
| 572 | create_resp.ref, &creds, |
|---|
| 573 | (strip_size + half_strip), (strip_size + half_strip), PVFS_BYTE); |
|---|
| 574 | if(res < 0) |
|---|
| 575 | { |
|---|
| 576 | goto exit; |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | res = do_contig_read( |
|---|
| 580 | create_resp.ref, &creds, 0, (strip_size * 3), NULL); |
|---|
| 581 | if(res < 0) |
|---|
| 582 | { |
|---|
| 583 | goto exit; |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | res = do_contig_read( |
|---|
| 587 | create_resp.ref, &creds, 0, (strip_size * 3), PVFS_BYTE); |
|---|
| 588 | if(res < 0) |
|---|
| 589 | { |
|---|
| 590 | goto exit; |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | res = do_contig_read( |
|---|
| 594 | create_resp.ref, &creds, 0, half_strip + 2, NULL); |
|---|
| 595 | if(res < 0) |
|---|
| 596 | { |
|---|
| 597 | goto exit; |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | res = do_contig_read( |
|---|
| 601 | create_resp.ref, &creds, 0, half_strip + 2, PVFS_BYTE); |
|---|
| 602 | if(res < 0) |
|---|
| 603 | { |
|---|
| 604 | goto exit; |
|---|
| 605 | } |
|---|
| 606 | |
|---|
| 607 | res = do_contig_read( |
|---|
| 608 | create_resp.ref, &creds, half_strip + 2, strip_size, NULL); |
|---|
| 609 | if(res < 0) |
|---|
| 610 | { |
|---|
| 611 | goto exit; |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | res = do_contig_read( |
|---|
| 615 | create_resp.ref, &creds, half_strip + 2, strip_size, PVFS_BYTE); |
|---|
| 616 | if(res < 0) |
|---|
| 617 | { |
|---|
| 618 | goto exit; |
|---|
| 619 | } |
|---|
| 620 | |
|---|
| 621 | res = do_contig_read( |
|---|
| 622 | create_resp.ref, &creds, strip_size + 1, 3, NULL); |
|---|
| 623 | if(res < 0) |
|---|
| 624 | { |
|---|
| 625 | goto exit; |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | res = do_contig_read( |
|---|
| 629 | create_resp.ref, &creds, strip_size + 1, 3, PVFS_BYTE); |
|---|
| 630 | if(res < 0) |
|---|
| 631 | { |
|---|
| 632 | goto exit; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | res = do_contig_read( |
|---|
| 636 | create_resp.ref, &creds, 0, 2, NULL); |
|---|
| 637 | if(res < 0) |
|---|
| 638 | { |
|---|
| 639 | goto exit; |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | res = do_contig_read( |
|---|
| 643 | create_resp.ref, &creds, 0, 2, PVFS_BYTE); |
|---|
| 644 | if(res < 0) |
|---|
| 645 | { |
|---|
| 646 | goto exit; |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | do_write(create_resp.ref, &creds, strip_size * 4, half_strip, cs); |
|---|
| 650 | |
|---|
| 651 | res = do_contig_read( |
|---|
| 652 | create_resp.ref, &creds, |
|---|
| 653 | (strip_size * 3 + half_strip), (strip_size + half_strip), NULL); |
|---|
| 654 | if(res < 0) |
|---|
| 655 | { |
|---|
| 656 | goto exit; |
|---|
| 657 | } |
|---|
| 658 | |
|---|
| 659 | res = do_contig_read( |
|---|
| 660 | create_resp.ref, &creds, |
|---|
| 661 | (strip_size * 3 + half_strip), (strip_size + half_strip), PVFS_BYTE); |
|---|
| 662 | if(res < 0) |
|---|
| 663 | { |
|---|
| 664 | goto exit; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | res = do_contig_read( |
|---|
| 668 | create_resp.ref, &creds, |
|---|
| 669 | 0, (strip_size * 5), NULL); |
|---|
| 670 | if(res < 0) |
|---|
| 671 | { |
|---|
| 672 | goto exit; |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | res = do_contig_read( |
|---|
| 676 | create_resp.ref, &creds, |
|---|
| 677 | 0, (strip_size * 5), PVFS_BYTE); |
|---|
| 678 | if(res < 0) |
|---|
| 679 | { |
|---|
| 680 | goto exit; |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | res = do_contig_read( |
|---|
| 684 | create_resp.ref, &creds, |
|---|
| 685 | (strip_size + half_strip), (strip_size + half_strip), NULL); |
|---|
| 686 | if(res < 0) |
|---|
| 687 | { |
|---|
| 688 | goto exit; |
|---|
| 689 | } |
|---|
| 690 | |
|---|
| 691 | res = do_contig_read( |
|---|
| 692 | create_resp.ref, &creds, |
|---|
| 693 | (strip_size + half_strip), (strip_size + half_strip), PVFS_BYTE); |
|---|
| 694 | if(res < 0) |
|---|
| 695 | { |
|---|
| 696 | goto exit; |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | res = do_contig_read( |
|---|
| 700 | create_resp.ref, &creds, |
|---|
| 701 | 0, (strip_size * 3), NULL); |
|---|
| 702 | if(res < 0) |
|---|
| 703 | { |
|---|
| 704 | goto exit; |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | res = do_contig_read( |
|---|
| 708 | create_resp.ref, &creds, |
|---|
| 709 | 0, (strip_size * 3), PVFS_BYTE); |
|---|
| 710 | if(res < 0) |
|---|
| 711 | { |
|---|
| 712 | goto exit; |
|---|
| 713 | } |
|---|
| 714 | |
|---|
| 715 | res = do_noncontig_read( |
|---|
| 716 | create_resp.ref, &creds, |
|---|
| 717 | 2, |
|---|
| 718 | 0, strip_size + half_strip, |
|---|
| 719 | strip_size * 4, half_strip); |
|---|
| 720 | if(res < 0) |
|---|
| 721 | { |
|---|
| 722 | goto exit; |
|---|
| 723 | } |
|---|
| 724 | |
|---|
| 725 | res = do_noncontig_read( |
|---|
| 726 | create_resp.ref, &creds, |
|---|
| 727 | 2, |
|---|
| 728 | 0, strip_size, |
|---|
| 729 | strip_size * 5, half_strip); |
|---|
| 730 | if(res < 0) |
|---|
| 731 | { |
|---|
| 732 | goto exit; |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | res = do_noncontig_read( |
|---|
| 736 | create_resp.ref, &creds, |
|---|
| 737 | 2, |
|---|
| 738 | 0, strip_size, |
|---|
| 739 | strip_size * 3, half_strip); |
|---|
| 740 | if(res < 0) |
|---|
| 741 | { |
|---|
| 742 | goto exit; |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | res = do_noncontig_read( |
|---|
| 746 | create_resp.ref, &creds, |
|---|
| 747 | 2, |
|---|
| 748 | strip_size, strip_size, |
|---|
| 749 | strip_size * 4 + 2, strip_size); |
|---|
| 750 | if(res < 0) |
|---|
| 751 | { |
|---|
| 752 | goto exit; |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | res = do_noncontig_read( |
|---|
| 756 | create_resp.ref, &creds, |
|---|
| 757 | 9, |
|---|
| 758 | 2, 2, |
|---|
| 759 | 8, 2, |
|---|
| 760 | 14, 2, |
|---|
| 761 | 20, 2, |
|---|
| 762 | 26, 2, |
|---|
| 763 | 32, 2, |
|---|
| 764 | 38, 2, |
|---|
| 765 | 44, 2, |
|---|
| 766 | 50, 2); |
|---|
| 767 | if(res < 0) |
|---|
| 768 | { |
|---|
| 769 | goto exit; |
|---|
| 770 | } |
|---|
| 771 | |
|---|
| 772 | res = do_smallmem_noncontig_read( |
|---|
| 773 | create_resp.ref, &creds, |
|---|
| 774 | strip_size, |
|---|
| 775 | 4, |
|---|
| 776 | strip_size, half_strip, |
|---|
| 777 | strip_size * 2, half_strip, |
|---|
| 778 | strip_size * 3, half_strip, |
|---|
| 779 | strip_size * 4, half_strip); |
|---|
| 780 | if(res < 0) |
|---|
| 781 | { |
|---|
| 782 | goto exit; |
|---|
| 783 | } |
|---|
| 784 | |
|---|
| 785 | res = do_smallmem_noncontig_read( |
|---|
| 786 | create_resp.ref, &creds, |
|---|
| 787 | strip_size, |
|---|
| 788 | 2, |
|---|
| 789 | strip_size, 2, |
|---|
| 790 | strip_size * 4, strip_size); |
|---|
| 791 | if(res < 0) |
|---|
| 792 | { |
|---|
| 793 | goto exit; |
|---|
| 794 | } |
|---|
| 795 | |
|---|
| 796 | PVFS_sys_remove( |
|---|
| 797 | zerofill_fname, |
|---|
| 798 | lookup_resp.ref, |
|---|
| 799 | &creds, |
|---|
| 800 | NULL); |
|---|
| 801 | |
|---|
| 802 | exit: |
|---|
| 803 | |
|---|
| 804 | realres = res; |
|---|
| 805 | |
|---|
| 806 | res = PVFS_sys_finalize(); |
|---|
| 807 | if(res < 0) |
|---|
| 808 | { |
|---|
| 809 | printf("finalizing sysint failed with errcode = %d\n", res); |
|---|
| 810 | realres = res; |
|---|
| 811 | } |
|---|
| 812 | |
|---|
| 813 | return realres; |
|---|
| 814 | } |
|---|
| 815 | |
|---|