librbd: track block_ofs instead of ofs in aio_sparse_read callback

This commit is contained in:
Yehuda Sadeh 2011-06-22 12:37:24 -07:00
parent e477e65b71
commit 44759452d4

View File

@ -1257,24 +1257,27 @@ void AioBlockCompletion::complete(ssize_t r)
map<uint64_t, uint64_t>::iterator iter;
uint64_t bl_ofs = 0, buf_bl_pos = 0;
dout(10) << "ofs=" << ofs << " len=" << len << dendl;
uint64_t block_ofs = ofs;
for (iter = m.begin(); iter != m.end(); ++iter) {
uint64_t extent_ofs = iter->first;
size_t extent_len = iter->second;
dout(10) << "extent_ofs=" << extent_ofs << " extent_len=" << extent_len << dendl;
dout(10) << "block_ofs=" << block_ofs << dendl;
/* a hole? */
if (extent_ofs - ofs) {
if (extent_ofs - block_ofs) {
dout(10) << "<1>zeroing " << buf_bl_pos << "~" << extent_ofs << dendl;
dout(10) << "buf=" << (void *)(buf + buf_bl_pos) << "~" << (void *)(buf + extent_ofs - ofs - 1) << dendl;
memset(buf + buf_bl_pos, 0, extent_ofs - ofs);
memset(buf + buf_bl_pos, 0, extent_ofs - block_ofs);
}
if (bl_ofs + extent_len > len) {
r = -EIO;
break;
}
buf_bl_pos += extent_ofs - ofs;
buf_bl_pos += extent_ofs - block_ofs;
block_ofs = extent_ofs;
/* data */
dout(10) << "<2>copying " << buf_bl_pos << "~" << extent_len << " from ofs=" << bl_ofs << dendl;
@ -1282,6 +1285,7 @@ void AioBlockCompletion::complete(ssize_t r)
memcpy(buf + buf_bl_pos, data_bl.c_str() + bl_ofs, extent_len);
bl_ofs += extent_len;
buf_bl_pos += extent_len;
block_ofs += extent_len;
}
/* last hole */