| 3337 | } |
| 3338 | |
| 3339 | int SyntheticClient::chunk_file(string &filename) |
| 3340 | { |
| 3341 | UserPerm perms = client->pick_my_perms(); |
| 3342 | int fd = client->open(filename.c_str(), O_RDONLY, perms); |
| 3343 | if (fd < 0) |
| 3344 | return fd; |
| 3345 | |
| 3346 | struct stat st; |
| 3347 | int ret = client->fstat(fd, &st, perms); |
| 3348 | if (ret < 0) { |
| 3349 | client->close(fd); |
| 3350 | return ret; |
| 3351 | } |
| 3352 | uint64_t size = st.st_size; |
| 3353 | dout(0) << "file " << filename << " size is " << size << dendl; |
| 3354 | |
| 3355 | inode_t inode{}; |
| 3356 | inode.ino = st.st_ino; |
| 3357 | ret = client->fdescribe_layout(fd, &inode.layout); |
| 3358 | ceph_assert(ret == 0); // otherwise fstat did a bad thing |
| 3359 | |
| 3360 | uint64_t pos = 0; |
| 3361 | bufferlist from_before; |
| 3362 | while (pos < size) { |
| 3363 | int get = std::min<int>(size - pos, 1048576); |
| 3364 | |
| 3365 | ceph::mutex flock = ceph::make_mutex("synclient chunk_file lock"); |
| 3366 | ceph::condition_variable cond; |
| 3367 | bool done; |
| 3368 | bufferlist bl; |
| 3369 | { |
| 3370 | std::unique_lock locker{flock}; |
| 3371 | Context *onfinish = new C_SafeCond(flock, cond, &done); |
| 3372 | client->filer->read(inode.ino, &inode.layout, CEPH_NOSNAP, pos, get, &bl, 0, |
| 3373 | onfinish); |
| 3374 | cond.wait(locker, [&done] { return done; }); |
| 3375 | } |
| 3376 | dout(0) << "got " << bl.length() << " bytes at " << pos << dendl; |
| 3377 | |
| 3378 | if (from_before.length()) { |
| 3379 | dout(0) << " including bit from previous block" << dendl; |
| 3380 | pos -= from_before.length(); |
| 3381 | from_before.claim_append(bl); |
| 3382 | bl.swap(from_before); |
| 3383 | } |
| 3384 | |
| 3385 | // .... |
| 3386 | |
| 3387 | // keep last 32 bytes around |
| 3388 | from_before.clear(); |
| 3389 | from_before.substr_of(bl, bl.length()-32, 32); |
| 3390 | |
| 3391 | pos += bl.length(); |
| 3392 | } |
| 3393 | |
| 3394 | client->close(fd); |
| 3395 | return 0; |
| 3396 | } |
nothing calls this directly
no test coverage detected