]> git.proxmox.com Git - ceph.git/blame - ceph/src/rbd_replay/BufferReader.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rbd_replay / BufferReader.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "rbd_replay/BufferReader.h"
11fdf7f2 5#include "include/ceph_assert.h"
7c673cae
FG
6#include "include/intarith.h"
7
8namespace rbd_replay {
9
10BufferReader::BufferReader(int fd, size_t min_bytes, size_t max_bytes)
11 : m_fd(fd), m_min_bytes(min_bytes), m_max_bytes(max_bytes),
12 m_bl_it(m_bl.begin()), m_eof_reached(false) {
11fdf7f2 13 ceph_assert(m_min_bytes <= m_max_bytes);
7c673cae
FG
14}
15
11fdf7f2 16int BufferReader::fetch(bufferlist::const_iterator **it) {
7c673cae 17 if (m_bl_it.get_remaining() < m_min_bytes) {
11fdf7f2 18 ssize_t bytes_to_read = round_up_to(m_max_bytes - m_bl_it.get_remaining(),
7c673cae
FG
19 CEPH_PAGE_SIZE);
20 while (!m_eof_reached && bytes_to_read > 0) {
21 int r = m_bl.read_fd(m_fd, CEPH_PAGE_SIZE);
22 if (r < 0) {
23 return r;
24 }
25 if (r == 0) {
26 m_eof_reached = true;
27 }
11fdf7f2 28 ceph_assert(r <= bytes_to_read);
7c673cae
FG
29 bytes_to_read -= r;
30 }
31 }
32
33 *it = &m_bl_it;
34 return 0;
35}
36
37} // namespace rbd_replay