Skip to content

Commit

Permalink
rbd-replay: handle EOF gracefully
Browse files Browse the repository at this point in the history
Fixes: #14452
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
(cherry picked from commit c59b84c)
  • Loading branch information
Mykola Golub authored and Abhishek Varshney committed Jan 29, 2016
1 parent bb2ecea commit 2c5b90a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/rbd_replay/BufferReader.cc
Expand Up @@ -9,19 +9,22 @@ namespace rbd_replay {

BufferReader::BufferReader(int fd, size_t min_bytes, size_t max_bytes)
: m_fd(fd), m_min_bytes(min_bytes), m_max_bytes(max_bytes),
m_bl_it(m_bl.begin()) {
m_bl_it(m_bl.begin()), m_eof_reached(false) {
assert(m_min_bytes <= m_max_bytes);
}

int BufferReader::fetch(bufferlist::iterator **it) {
if (m_bl_it.get_remaining() < m_min_bytes) {
ssize_t bytes_to_read = ROUND_UP_TO(m_max_bytes - m_bl_it.get_remaining(),
CEPH_BUFFER_APPEND_SIZE);
while (bytes_to_read > 0) {
while (!m_eof_reached && bytes_to_read > 0) {
int r = m_bl.read_fd(m_fd, CEPH_BUFFER_APPEND_SIZE);
if (r < 0) {
return r;
}
if (r == 0) {
m_eof_reached = true;
}
assert(r <= bytes_to_read);
bytes_to_read -= r;
}
Expand Down
1 change: 1 addition & 0 deletions src/rbd_replay/BufferReader.h
Expand Up @@ -25,6 +25,7 @@ class BufferReader {
size_t m_max_bytes;
bufferlist m_bl;
bufferlist::iterator m_bl_it;
bool m_eof_reached;

};

Expand Down
5 changes: 4 additions & 1 deletion src/rbd_replay/Replayer.cc
Expand Up @@ -224,14 +224,17 @@ void Replayer::run(const std::string& replay_file) {
<< std::endl;
exit(-r);
}
if (it->get_remaining() == 0) {
break;
}

if (versioned) {
action_entry.decode(*it);
} else {
action_entry.decode_unversioned(*it);
}
} catch (const buffer::error &err) {
std::cerr << "Failed to decode trace action" << std::endl;
std::cerr << "Failed to decode trace action: " << err.what() << std::endl;
exit(1);
}

Expand Down

0 comments on commit 2c5b90a

Please sign in to comment.