From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 10/21] libxl: datacopier: provide "prefix data" facility Date: Fri, 15 Jun 2012 12:53:55 +0100 Message-ID: <1339761246-27641-11-git-send-email-ian.jackson@eu.citrix.com> References: <1339761246-27641-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1339761246-27641-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Ian Jackson List-Id: xen-devel@lists.xenproject.org This will be used to write the qemu data banner to the save/migration stream. Signed-off-by: Ian Jackson Acked-by: Ian Campbell Changes in v3: * Clarified and added comments explaining the `immediately' constraint and the lack of a reentrancy/threading hazard. * Fixed subject line typo. --- tools/libxl/libxl_aoutils.c | 22 ++++++++++++++++++++++ tools/libxl/libxl_internal.h | 6 ++++++ 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c index ee0df57..7f8d6d3 100644 --- a/tools/libxl/libxl_aoutils.c +++ b/tools/libxl/libxl_aoutils.c @@ -74,6 +74,28 @@ static void datacopier_check_state(libxl__egc *egc, libxl__datacopier_state *dc) } } +void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, + const void *data, size_t len) +{ + libxl__datacopier_buf *buf; + /* + * It is safe for this to be called immediately after _start, as + * is documented in the public comment. _start's caller must have + * the ctx locked, so other threads don't get to mess with the + * contents, and the fd events cannot happen reentrantly. So we + * are guaranteed to beat the first data from the read fd. + */ + + assert(len < dc->maxsz - dc->used); + + buf = libxl__zalloc(0, sizeof(*buf) - sizeof(buf->buf) + len); + buf->used = len; + memcpy(buf->buf, data, len); + + dc->used += len; + LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry); +} + static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev, int fd, short events, short revents) { libxl__datacopier_state *dc = CONTAINER_OF(ev, *dc, toread); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 05bed01..8b582e4 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1811,6 +1811,12 @@ _hidden void libxl__datacopier_init(libxl__datacopier_state *dc); _hidden void libxl__datacopier_kill(libxl__datacopier_state *dc); _hidden int libxl__datacopier_start(libxl__datacopier_state *dc); +/* Inserts literal data into the output stream. The data is copied. + * May safely be used only immediately after libxl__datacopier_start + * (before the ctx is unlocked). But may be called multiple times. + * NB exceeding maxsz will fail an assertion! */ +_hidden void libxl__datacopier_prefixdata(libxl__egc*, libxl__datacopier_state*, + const void *data, size_t len); /*----- Save/restore helper (used by creation and suspend) -----*/ -- 1.7.2.5