| 2013 | } |
| 2014 | |
| 2015 | int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size is in MB, wrsize in bytes |
| 2016 | { |
| 2017 | //uint64_t wrsize = 1024*256; |
| 2018 | char *buf = new char[wrsize+100]; // 1 MB |
| 2019 | memset(buf, 7, wrsize); |
| 2020 | int64_t chunks = (uint64_t)size * (uint64_t)(1024*1024) / (uint64_t)wrsize; |
| 2021 | UserPerm perms = client->pick_my_perms(); |
| 2022 | |
| 2023 | int fd = client->open(fn.c_str(), O_RDWR|O_CREAT, perms); |
| 2024 | dout(5) << "writing to " << fn << " fd " << fd << dendl; |
| 2025 | if (fd < 0) { |
| 2026 | delete[] buf; |
| 2027 | return fd; |
| 2028 | } |
| 2029 | |
| 2030 | utime_t from = ceph_clock_now(); |
| 2031 | utime_t start = from; |
| 2032 | uint64_t bytes = 0, total = 0; |
| 2033 | |
| 2034 | |
| 2035 | for (loff_t i=0; i<chunks; i++) { |
| 2036 | if (time_to_stop()) { |
| 2037 | dout(0) << "stopping" << dendl; |
| 2038 | break; |
| 2039 | } |
| 2040 | dout(2) << "writing block " << i << "/" << chunks << dendl; |
| 2041 | |
| 2042 | // fill buf with a 16 byte fingerprint |
| 2043 | // 64 bits : file offset |
| 2044 | // 64 bits : client id |
| 2045 | // = 128 bits (16 bytes) |
| 2046 | uint64_t *p = (uint64_t*)buf; |
| 2047 | while ((char*)p < buf + wrsize) { |
| 2048 | *p = (uint64_t)i*(uint64_t)wrsize + (uint64_t)((char*)p - buf); |
| 2049 | p++; |
| 2050 | *p = client->get_nodeid().v; |
| 2051 | p++; |
| 2052 | } |
| 2053 | |
| 2054 | client->write(fd, buf, wrsize, i*wrsize); |
| 2055 | bytes += wrsize; |
| 2056 | total += wrsize; |
| 2057 | |
| 2058 | utime_t now = ceph_clock_now(); |
| 2059 | if (now - from >= 1.0) { |
| 2060 | double el = now - from; |
| 2061 | dout(0) << "write " << (bytes / el / 1048576.0) << " MB/sec" << dendl; |
| 2062 | from = now; |
| 2063 | bytes = 0; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | client->fsync(fd, true); |
| 2068 | |
| 2069 | utime_t stop = ceph_clock_now(); |
| 2070 | double el = stop - start; |
| 2071 | dout(0) << "write total " << (total / el / 1048576.0) << " MB/sec (" |
| 2072 | << total << " bytes in " << el << " seconds)" << dendl; |
nothing calls this directly
no test coverage detected