mirror of
https://github.com/ceph/ceph
synced 2025-02-21 01:47:25 +00:00
rbd-replay: handle EOF gracefully
Fixes: #14452 Signed-off-by: Mykola Golub <mgolub@mirantis.com>
This commit is contained in:
parent
e7420f1268
commit
c59b84c3e2
@ -9,7 +9,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -17,11 +17,14 @@ 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;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ private:
|
||||
size_t m_max_bytes;
|
||||
bufferlist m_bl;
|
||||
bufferlist::iterator m_bl_it;
|
||||
bool m_eof_reached;
|
||||
|
||||
};
|
||||
|
||||
|
@ -224,6 +224,9 @@ void Replayer::run(const std::string& replay_file) {
|
||||
<< std::endl;
|
||||
exit(-r);
|
||||
}
|
||||
if (it->get_remaining() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (versioned) {
|
||||
action_entry.decode(*it);
|
||||
@ -231,7 +234,7 @@ void Replayer::run(const std::string& replay_file) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user