From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuDJz-0003Dy-Ay for qemu-devel@nongnu.org; Mon, 18 May 2015 01:10:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuDJv-0003j7-9X for qemu-devel@nongnu.org; Mon, 18 May 2015 01:10:35 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:55246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuDJu-0003j2-Fs for qemu-devel@nongnu.org; Mon, 18 May 2015 01:10:31 -0400 Message-ID: <5559742C.3090005@huawei.com> Date: Mon, 18 May 2015 13:10:04 +0800 From: zhanghailiang MIME-Version: 1.0 References: <1427347774-8960-1-git-send-email-zhang.zhanghailiang@huawei.com> <1427347774-8960-9-git-send-email-zhang.zhanghailiang@huawei.com> <20150515115633.GE2194@work-vm> In-Reply-To: <20150515115633.GE2194@work-vm> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH v4 08/28] QEMUSizedBuffer: Introduce two help functions for qsb List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert" Cc: lizhijian@cn.fujitsu.com, quintela@redhat.com, yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, qemu-devel@nongnu.org, arei.gonglei@huawei.com, amit.shah@redhat.com, Yang Hongyang , david@gibson.dropbear.id.au On 2015/5/15 19:56, Dr. David Alan Gilbert wrote: > * zhanghailiang (zhang.zhanghailiang@huawei.com) wrote: >> Introduce two new QEMUSizedBuffer APIs which will be used by COLO to buffer >> VM state: >> One is qsb_put_buffer(), which put the content of a given QEMUSizedBuffer >> into QEMUFile, this is used to send buffered VM state to secondary. >> Another is qsb_fill_buffer(), read 'size' bytes of data from the file into >> qsb, this is used to get VM state from socket into a buffer. >> >> Signed-off-by: Yang Hongyang >> Signed-off-by: zhanghailiang > > Reviewed-by: Dr. David Alan Gilbert > > (I could use these in my postcopy world) Please feel free to do that, maybe this patch can be merged in advance as prerequisite patch ;) > >> --- >> include/migration/qemu-file.h | 3 ++- >> migration/qemu-file-buf.c | 58 +++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 60 insertions(+), 1 deletion(-) >> >> diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h >> index 745a850..09a0e2a 100644 >> --- a/include/migration/qemu-file.h >> +++ b/include/migration/qemu-file.h >> @@ -140,7 +140,8 @@ ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count, >> uint8_t *buf); >> ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *buf, >> off_t pos, size_t count); >> - >> +void qsb_put_buffer(QEMUFile *f, QEMUSizedBuffer *qsb, int size); >> +int qsb_fill_buffer(QEMUSizedBuffer *qsb, QEMUFile *f, int size); >> >> /* >> * For use on files opened with qemu_bufopen >> diff --git a/migration/qemu-file-buf.c b/migration/qemu-file-buf.c >> index 16a51a1..686f417 100644 >> --- a/migration/qemu-file-buf.c >> +++ b/migration/qemu-file-buf.c >> @@ -365,6 +365,64 @@ ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *source, >> return count; >> } >> >> + >> +/** >> + * Put the content of a given QEMUSizedBuffer into QEMUFile. >> + * >> + * @f: A QEMUFile >> + * @qsb: A QEMUSizedBuffer >> + * @size: size of content to write >> + */ >> +void qsb_put_buffer(QEMUFile *f, QEMUSizedBuffer *qsb, int size) >> +{ >> + int i, l; >> + >> + for (i = 0; i < qsb->n_iov && size > 0; i++) { >> + l = MIN(qsb->iov[i].iov_len, size); >> + qemu_put_buffer(f, qsb->iov[i].iov_base, l); >> + size -= l; >> + } >> +} >> + >> +/* >> + * Read 'size' bytes of data from the file into qsb. >> + * always fill from pos 0 and used after qsb_create(). >> + * >> + * It will return size bytes unless there was an error, in which case it will >> + * return as many as it managed to read (assuming blocking fd's which >> + * all current QEMUFile are) >> + */ >> +int qsb_fill_buffer(QEMUSizedBuffer *qsb, QEMUFile *f, int size) >> +{ >> + ssize_t rc = qsb_grow(qsb, size); >> + int pending = size, i; >> + qsb->used = 0; >> + uint8_t *buf = NULL; >> + >> + if (rc < 0) { >> + return rc; >> + } >> + >> + for (i = 0; i < qsb->n_iov && pending > 0; i++) { >> + int doneone = 0; >> + /* read until iov full */ >> + while (doneone < qsb->iov[i].iov_len && pending > 0) { >> + int readone = 0; >> + buf = qsb->iov[i].iov_base; >> + readone = qemu_get_buffer(f, buf, >> + MIN(qsb->iov[i].iov_len - doneone, pending)); >> + if (readone == 0) { >> + return qsb->used; >> + } >> + buf += readone; >> + doneone += readone; >> + pending -= readone; >> + qsb->used += readone; >> + } >> + } >> + return qsb->used; >> +} >> + >> typedef struct QEMUBuffer { >> QEMUSizedBuffer *qsb; >> QEMUFile *file; >> -- >> 1.7.12.4 >> >> > -- > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK > > . >