| 2534 | } |
| 2535 | |
| 2536 | int SyntheticClient::read_random_ex(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes |
| 2537 | { |
| 2538 | uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize; |
| 2539 | UserPerm perms = client->pick_my_perms(); |
| 2540 | int fd = client->open(fn.c_str(), O_RDWR, perms); |
| 2541 | dout(5) << "reading from " << fn << " fd " << fd << dendl; |
| 2542 | |
| 2543 | if (fd < 0) return fd; |
| 2544 | int offset = 0; |
| 2545 | char * buf = NULL; |
| 2546 | |
| 2547 | for (unsigned i=0; i<2000; i++) { |
| 2548 | if (time_to_stop()) break; |
| 2549 | |
| 2550 | bool read=false; |
| 2551 | |
| 2552 | time_t seconds; |
| 2553 | time( &seconds); |
| 2554 | srand(seconds); |
| 2555 | |
| 2556 | // use rand instead ?? |
| 2557 | double x = drand48(); |
| 2558 | |
| 2559 | // cleanup before call 'new' |
| 2560 | if (buf != NULL) { |
| 2561 | delete[] buf; |
| 2562 | buf = NULL; |
| 2563 | } |
| 2564 | if (x < 0.5) { |
| 2565 | buf = new char[rdsize]; |
| 2566 | memset(buf, 1, rdsize); |
| 2567 | read=true; |
| 2568 | } else { |
| 2569 | buf = new char[rdsize+100]; // 1 MB |
| 2570 | memset(buf, 7, rdsize); |
| 2571 | } |
| 2572 | |
| 2573 | if (read) { |
| 2574 | dout(2) << "reading block " << offset << "/" << chunks << dendl; |
| 2575 | |
| 2576 | int r = client->read(fd, buf, rdsize, |
| 2577 | offset*rdsize); |
| 2578 | if (r < rdsize) { |
| 2579 | dout(1) << "read_file got r = " << r << ", probably end of file" << dendl; |
| 2580 | } |
| 2581 | } else { |
| 2582 | dout(2) << "writing block " << offset << "/" << chunks << dendl; |
| 2583 | |
| 2584 | // fill buf with a 16 byte fingerprint |
| 2585 | // 64 bits : file offset |
| 2586 | // 64 bits : client id |
| 2587 | // = 128 bits (16 bytes) |
| 2588 | |
| 2589 | int count = rand()%10; |
| 2590 | |
| 2591 | for ( int j=0;j<count; j++ ) { |
| 2592 | offset=(rand())%(chunks+1); |
| 2593 | uint64_t *p = (uint64_t*)buf; |
nothing calls this directly
no test coverage detected