From patchwork Wed Apr 21 05:57:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 93805 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3L62Lmc005310 for ; Wed, 21 Apr 2010 06:02:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752157Ab0DUGCG (ORCPT ); Wed, 21 Apr 2010 02:02:06 -0400 Received: from sh.osrg.net ([192.16.179.4]:58776 "EHLO sh.osrg.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751899Ab0DUGCB (ORCPT ); Wed, 21 Apr 2010 02:02:01 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o3L61Qv1004085; Wed, 21 Apr 2010 15:01:26 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id 297B53E02F4; Wed, 21 Apr 2010 15:01:25 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: avi@redhat.com, aliguori@us.ibm.com, mtosatti@redhat.com, ohmura.kei@lab.ntt.co.jp, yoshikawa.takuya@oss.ntt.co.jp, Yoshiaki Tamura Subject: [RFC PATCH 07/20] Introduce qemu_put_vector() and qemu_put_vector_prepare() to use put_vector() in QEMUFile. Date: Wed, 21 Apr 2010 14:57:12 +0900 Message-Id: <1271829445-5328-8-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1271829445-5328-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 97 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 21 Apr 2010 06:02:24 +0000 (UTC) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Wed, 21 Apr 2010 15:01:26 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/hw/hw.h b/hw/hw.h index 921cf90..10e6dda 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -77,6 +77,8 @@ void qemu_fflush(QEMUFile *f); int qemu_fclose(QEMUFile *f); void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size); void qemu_put_byte(QEMUFile *f, int v); +void qemu_put_vector(QEMUFile *f, QEMUIOVector *qiov); +void qemu_put_vector_prepare(QEMUFile *f); void *qemu_realloc_buffer(QEMUFile *f, int size); void qemu_clear_buffer(QEMUFile *f); diff --git a/savevm.c b/savevm.c index 944e788..22d928c 100644 --- a/savevm.c +++ b/savevm.c @@ -180,6 +180,7 @@ struct QEMUFile { uint8_t *buf; int has_error; + int prepares_vector; }; typedef struct QEMUFileStdio @@ -557,6 +558,58 @@ void qemu_put_byte(QEMUFile *f, int v) qemu_fflush(f); } +void qemu_put_vector(QEMUFile *f, QEMUIOVector *v) +{ + struct iovec *iov; + int cnt; + size_t bufsize; + uint8_t *buf; + + if (qemu_file_get_rate_limit(f) != 0) { + fprintf(stderr, + "Attempted to write vector while bandwidth limit is not zero.\n"); + abort(); + } + + /* checks prepares vector. + * For fool proof purpose, qemu_put_vector_parepare should be called + * before qemu_put_vector. Then, if qemu_put_* functions except this + * is called after qemu_put_vector_prepare, program will abort(). + */ + if (!f->prepares_vector) { + fprintf(stderr, + "You should prepare with qemu_put_vector_prepare.\n"); + abort(); + } else if (f->prepares_vector && f->buf_index != 0) { + fprintf(stderr, "Wrote data after qemu_put_vector_prepare.\n"); + abort(); + } + f->prepares_vector = 0; + + if (f->put_vector) { + qemu_iovec_to_vector(v, &iov, &cnt); + f->put_vector(f->opaque, iov, 0, cnt); + } else { + qemu_iovec_to_size(v, &bufsize); + buf = qemu_malloc(bufsize + 1 /* for '\0' */); + qemu_iovec_to_buffer(v, buf); + qemu_put_buffer(f, buf, bufsize); + qemu_free(buf); + } + +} + +void qemu_put_vector_prepare(QEMUFile *f) +{ + if (f->prepares_vector) { + /* prepare vector */ + fprintf(stderr, "Attempted to prepare vector twice\n"); + abort(); + } + f->prepares_vector = 1; + qemu_fflush(f); +} + int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size1) { int size, l;