| 12443 | } |
| 12444 | |
| 12445 | int Client::WriteEncMgr::read_modify_write(Context *_iofinish) |
| 12446 | { |
| 12447 | get(); |
| 12448 | iofinish = new LambdaContext([this, _iofinish](int r) { |
| 12449 | this->put(); |
| 12450 | if(_iofinish) { |
| 12451 | _iofinish->complete(r); |
| 12452 | } |
| 12453 | }); |
| 12454 | |
| 12455 | #if defined(__linux__) |
| 12456 | if (!denc) |
| 12457 | return do_write(); |
| 12458 | #else |
| 12459 | return do_write(); |
| 12460 | #endif |
| 12461 | |
| 12462 | #if defined(__linux__) |
| 12463 | ceph_assert(ceph_mutex_is_locked_by_me(clnt->client_lock)); |
| 12464 | |
| 12465 | int r = 0; |
| 12466 | |
| 12467 | start_block = fscrypt_block_from_ofs(offset); |
| 12468 | start_block_ofs = fscrypt_block_start(offset); |
| 12469 | ofs_in_start_block = fscrypt_ofs_in_block(offset); |
| 12470 | end_block = fscrypt_block_from_ofs(endoff - 1); |
| 12471 | end_block_ofs = fscrypt_block_start(endoff - 1); |
| 12472 | ofs_in_end_block = fscrypt_ofs_in_block(endoff - 1); |
| 12473 | |
| 12474 | need_read_start = ofs_in_start_block > 0 || (ofs_in_start_block == 0 && ((endoff - offset) < FSCRYPT_BLOCK_SIZE)); |
| 12475 | need_read_end = (endoff <= in->effective_size() && ofs_in_end_block < FSCRYPT_BLOCK_SIZE && start_block != end_block); |
| 12476 | read_start_size = FSCRYPT_BLOCK_SIZE; |
| 12477 | |
| 12478 | bool need_read = need_read_start | need_read_end; |
| 12479 | |
| 12480 | |
| 12481 | if (need_read_start) { |
| 12482 | finish_read_start_ctx.reset(new iofinish_method_ctx<WriteEncMgr>(*this, &WriteEncMgr::finish_read_start_cb, &aioc)); |
| 12483 | |
| 12484 | r = read(start_block_ofs, read_start_size, &startbl, finish_read_start_ctx.get()); |
| 12485 | if (r < 0) { |
| 12486 | finish_read_start_ctx.reset(); |
| 12487 | |
| 12488 | ldout(cct, 0) << "failed to read first block: r=" << r << dendl; |
| 12489 | goto done; |
| 12490 | } |
| 12491 | } |
| 12492 | |
| 12493 | if (need_read_end) { |
| 12494 | finish_read_end_ctx.reset(new iofinish_method_ctx<WriteEncMgr>(*this, &WriteEncMgr::finish_read_end_cb, &aioc)); |
| 12495 | |
| 12496 | r = read(end_block_ofs, FSCRYPT_BLOCK_SIZE, &endbl, finish_read_end_ctx.get()); |
| 12497 | if (r < 0) { |
| 12498 | finish_read_end_ctx.reset(); |
| 12499 | |
| 12500 | ldout(cct, 0) << "failed to read end block: r=" << r << dendl; |
| 12501 | goto done; |
| 12502 | } |
no test coverage detected