From: Ian Campbell Subject: Re: [PATCH 09/15] libxl: datacopier: provide "prefix data" facilit Date: Thu, 31 May 2012 08:52:40 +0100 Message-ID: <1338450760.17466.5.camel@zakaz.uk.xensource.com> References: <1338394606-22693-1-git-send-email-ian.jackson@eu.citrix.com> <1338394606-22693-10-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: <1338394606-22693-10-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: Ian Jackson Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org In the subject: "facility" On Wed, 2012-05-30 at 17:16 +0100, Ian Jackson wrote: > This will be used to write the qemu data banner to the save/migration > stream. > > Signed-off-by: Ian Jackson > --- > tools/libxl/libxl_aoutils.c | 15 +++++++++++++++ > tools/libxl/libxl_internal.h | 6 ++++++ > 2 files changed, 21 insertions(+), 0 deletions(-) > > diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c > index ee0df57..208b34b 100644 > --- a/tools/libxl/libxl_aoutils.c > +++ b/tools/libxl/libxl_aoutils.c > @@ -74,6 +74,21 @@ 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; > + > + 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 8f4f45d..b41e72f 100644 > --- a/tools/libxl/libxl_internal.h > +++ b/tools/libxl/libxl_internal.h > @@ -1812,6 +1812,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. > + * May safely be used only immediately after libxl__datacopier_start. After datacopier_start the fds are registered, is there not a race between those events firing (perhaps in another thread which has called into libxl) and this thread? Is the safe place not between datacopier_init and the rest of datacopier_start? > + * (But may be called multiple times.) The data is copied. > + * 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) -----*/ >