| 2405 | |
| 2406 | |
| 2407 | int SyntheticClient::read_random(string& fn, int size, int rdsize) // size is in MB, wrsize in bytes |
| 2408 | { |
| 2409 | UserPerm perms = client->pick_my_perms(); |
| 2410 | uint64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)rdsize; |
| 2411 | int fd = client->open(fn.c_str(), O_RDWR, perms); |
| 2412 | dout(5) << "reading from " << fn << " fd " << fd << dendl; |
| 2413 | |
| 2414 | if (fd < 0) return fd; |
| 2415 | int offset = 0; |
| 2416 | char * buf = NULL; |
| 2417 | |
| 2418 | for (unsigned i=0; i<2000; i++) { |
| 2419 | if (time_to_stop()) break; |
| 2420 | |
| 2421 | bool read=false; |
| 2422 | |
| 2423 | time_t seconds; |
| 2424 | time( &seconds); |
| 2425 | srand(seconds); |
| 2426 | |
| 2427 | // use rand instead ?? |
| 2428 | double x = drand48(); |
| 2429 | |
| 2430 | // cleanup before call 'new' |
| 2431 | if (buf != NULL) { |
| 2432 | delete[] buf; |
| 2433 | buf = NULL; |
| 2434 | } |
| 2435 | if (x < 0.5) { |
| 2436 | buf = new char[rdsize]; |
| 2437 | memset(buf, 1, rdsize); |
| 2438 | read=true; |
| 2439 | } else { |
| 2440 | buf = new char[rdsize+100]; // 1 MB |
| 2441 | memset(buf, 7, rdsize); |
| 2442 | } |
| 2443 | |
| 2444 | if (read) { |
| 2445 | offset=(rand())%(chunks+1); |
| 2446 | dout(2) << "reading block " << offset << "/" << chunks << dendl; |
| 2447 | |
| 2448 | int r = client->read(fd, buf, rdsize, offset*rdsize); |
| 2449 | if (r < rdsize) { |
| 2450 | dout(1) << "read_file got r = " << r << ", probably end of file" << dendl; |
| 2451 | } |
| 2452 | } else { |
| 2453 | dout(2) << "writing block " << offset << "/" << chunks << dendl; |
| 2454 | |
| 2455 | // fill buf with a 16 byte fingerprint |
| 2456 | // 64 bits : file offset |
| 2457 | // 64 bits : client id |
| 2458 | // = 128 bits (16 bytes) |
| 2459 | |
| 2460 | offset=(rand())%(chunks+1); |
| 2461 | uint64_t *p = (uint64_t*)buf; |
| 2462 | while ((char*)p < buf + rdsize) { |
| 2463 | *p = offset*rdsize + (char*)p - buf; |
| 2464 | p++; |
nothing calls this directly
no test coverage detected