From: Jevon Qiao Date: Mon, 15 Jun 2015 15:59:12 +0000 (+0800) Subject: libcephfs: add ceph_p{read,write}v X-Git-Tag: v9.0.3~161^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F4954%2Fhead;p=ceph.git libcephfs: add ceph_p{read,write}v Fix comments raised by John Spray Signed-off-by: Jevon Qiao --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 02ea319bbfe8..17d191331d91 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7480,26 +7480,26 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t } if (write) { int w = _write(fh, offset, totallen, NULL, iov, iovcnt); - ldout(cct, 3) << "write(" << fd << ", \"...\", " << totallen << ", " << offset << ") = " << w << dendl; + ldout(cct, 3) << "pwritev(" << fd << ", \"...\", " << totallen << ", " << offset << ") = " << w << dendl; return w; } else { bufferlist bl; int r = _read(fh, offset, totallen, &bl); - ldout(cct, 3) << "read(" << fd << ", " << offset << ") = " << r << dendl; + ldout(cct, 3) << "preadv(" << fd << ", " << offset << ") = " << r << dendl; int bufoff = 0; uint32_t rlen = 0; - for (int j = 0, tmplen = r; j < iovcnt && tmplen > 0; j++) { + for (int j = 0, resid = r; j < iovcnt && resid > 0; j++) { /* - * This piece of code aims to handle the case that bufferlist does no have enough data + * This piece of code aims to handle the case that bufferlist does not have enough data * to fill in the iov */ - if (tmplen < iov[j].iov_len) { - bl.copy(bufoff, tmplen, (char *)iov[j].iov_base); + if (resid < iov[j].iov_len) { + bl.copy(bufoff, resid, (char *)iov[j].iov_base); break; } else { bl.copy(bufoff, iov[j].iov_len, (char *)iov[j].iov_base); } - tmplen -= iov[j].iov_len; + resid -= iov[j].iov_len; bufoff += iov[j].iov_len; } return r; @@ -7560,7 +7560,7 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf, // copy into fresh buffer (since our write may be resub, async) bufferlist bl; - bufferptr *bparr; + bufferptr *bparr = NULL; if (buf) { bufferptr bp; if (size > 0) bp = buffer::copy(buf, size); @@ -7569,7 +7569,9 @@ int Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf, //iov case bparr = new bufferptr[iovcnt]; for (int i = 0; i < iovcnt; i++) { - if (iov[i].iov_len > 0) bparr[i] = buffer::copy((char*)iov[i].iov_base, iov[i].iov_len); + if (iov[i].iov_len > 0) { + bparr[i] = buffer::copy((char*)iov[i].iov_base, iov[i].iov_len); + } bl.push_back( bparr[i] ); } } @@ -7720,9 +7722,7 @@ done: } put_cap_ref(in, CEPH_CAP_FILE_WR); - if (buf == NULL && iov != NULL) { - delete[] bparr; - } + delete[] bparr; return r; }