From b98ed828162ce00f334e6afc9e9a0801c0ab23d7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 6 Jan 2016 12:57:12 -0500 Subject: [PATCH] os/bluestore/BlockDevice: make pread() safe Signed-off-by: Sage Weil --- src/os/bluestore/BlockDevice.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index 13607ad2b84c4..33370bf495052 100644 --- a/src/os/bluestore/BlockDevice.cc +++ b/src/os/bluestore/BlockDevice.cc @@ -496,14 +496,21 @@ int BlockDevice::read_buffered(uint64_t off, uint64_t len, char *buf) assert(off < size); assert(off + len <= size); - int r = ::pread(fd_buffered, buf, len, off); - if (r < 0) { - r = -errno; - goto out; + int r = 0; + char *t = buf; + uint64_t left = len; + while (left > 0) { + r = ::pread(fd_buffered, t, left, off); + if (r < 0) { + r = -errno; + goto out; + } + off += r; + t += r; + left -= r; } - assert(r == len); - dout(40) << "data: "; + dout(40) << __func__ << " data: "; bufferlist bl; bl.append(buf, len); bl.hexdump(*_dout); -- 2.39.5