Skip to content

Commit

Permalink
buffer: try to do zero copy in read_fd
Browse files Browse the repository at this point in the history
Leave the explicit read_fd_zero_copy around as well for testing.

Signed-off-by: Josh Durgin <[email protected]>
  • Loading branch information
jdurgin committed Nov 23, 2013
1 parent be29b34 commit 445fb18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,12 @@ int buffer::list::read_file(const char *fn, std::string *error)

ssize_t buffer::list::read_fd(int fd, size_t len)
{
// try zero copy first
if (read_fd_zero_copy(fd, len) == 0) {
// TODO fix callers to not require correct read size, which is not
// available for raw_pipe until we actually inspect the data
return 0;
}
int s = ROUND_UP_TO(len, CEPH_PAGE_SIZE);
bufferptr bp = buffer::create_page_aligned(s);
ssize_t ret = safe_read(fd, (void*)bp.c_str(), len);
Expand All @@ -1507,6 +1513,8 @@ int buffer::list::read_fd_zero_copy(int fd, size_t len)
append(bp);
} catch (buffer::error_code e) {
return e.code;
} catch (buffer::malformed_input) {
return -EIO;
}
return 0;
#else
Expand Down
7 changes: 6 additions & 1 deletion src/test/bufferlist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1763,9 +1763,14 @@ TEST(BufferList, read_fd) {
bufferlist bl;
EXPECT_EQ(-EBADF, bl.read_fd(fd, len));
fd = ::open("testfile", O_RDONLY);
#ifdef CEPH_HAVE_SPLICE
EXPECT_EQ(0, bl.read_fd(fd, len));
EXPECT_EQ(0u, bl.buffers().front().unused_tail_length());
#else
EXPECT_EQ(len, (unsigned)bl.read_fd(fd, len));
EXPECT_EQ(len, bl.length());
EXPECT_EQ(CEPH_PAGE_SIZE - len, bl.buffers().front().unused_tail_length());
#endif
EXPECT_EQ(len, bl.length());
::close(fd);
::unlink("testfile");
}
Expand Down

0 comments on commit 445fb18

Please sign in to comment.