From patchwork Mon Oct 12 16:41:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 529206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 585731402B0 for ; Tue, 13 Oct 2015 03:46:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=f/rsB8IL; dkim-atps=neutral Received: from localhost ([::1]:56631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgEa-0003XF-NS for incoming@patchwork.ozlabs.org; Mon, 12 Oct 2015 12:46:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgC6-0007Ry-Iq for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:43:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlgC3-0001E0-CY for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:43:26 -0400 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]:34847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgC3-0001Ds-6m for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:43:23 -0400 Received: by pabve7 with SMTP id ve7so100461515pab.2 for ; Mon, 12 Oct 2015 09:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=GIbv3QHJq1hrgQn8UODyJ1pH65BMsfd7FHTldXZABvQ=; b=f/rsB8ILXfu/TcHlABrA+6wlRqRIqVGEqpKBLnsTHaFjTncE2RIppPszUb5pvMD9eX K6BZD6hRGf++OgsGICN1IhxH3vQ6jxkLlmJ40MIVtz1lxui5otvdUBabWpzROqvHA9OE XXSd5aL44PIO35uJ14JQC3nL/CiuZvCX2Lmg5HgPVwAHfEOLC6W0EO4DO45FmtAX4XaA UPLtIzCRcuOX2QJWp1fWdH1YaKVQuACCT3aQcifhBXmPFIfw1x2NObj/2YIVti9x/5ND noQ3MCKOrhRCMS+jS1Pu0FIDz8tQ5d85ip5oKQWnHdFxIfymz7j69XH30ogpGTfp9Sfy TCjw== X-Received: by 10.68.165.34 with SMTP id yv2mr12227587pbb.112.1444668202803; Mon, 12 Oct 2015 09:43:22 -0700 (PDT) Received: from localhost (APoitiers-257-1-35-234.w90-38.abo.wanadoo.fr. [90.38.210.234]) by smtp.gmail.com with ESMTPSA id dt1sm19207763pbc.96.2015.10.12.09.43.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:43:22 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Mon, 12 Oct 2015 18:41:00 +0200 Message-Id: <1444668104-22955-7-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1444668104-22955-1-git-send-email-marcandre.lureau@redhat.com> References: <1444668104-22955-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::231 Cc: peter.maydell@linaro.org, drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca Subject: [Qemu-devel] [PULL v2 06/50] ivshmem: factor out the incoming fifo handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Make a new function fifo_update_and_get() that can be reused by other functions (in next commits). Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- hw/misc/ivshmem.c | 59 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 2162d02..dd15f0e 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -441,6 +441,42 @@ static int increase_dynamic_storage(IVShmemState *s, int new_min_size) return 0; } +static bool fifo_update_and_get(IVShmemState *s, const uint8_t *buf, int size, + void *data, size_t len) +{ + const uint8_t *p; + uint32_t num; + + assert(len <= sizeof(long)); /* limitation of the fifo */ + if (fifo8_is_empty(&s->incoming_fifo) && size == len) { + memcpy(data, buf, size); + return true; + } + + IVSHMEM_DPRINTF("short read of %d bytes\n", size); + + num = MIN(size, sizeof(long) - fifo8_num_used(&s->incoming_fifo)); + fifo8_push_all(&s->incoming_fifo, buf, num); + + if (fifo8_num_used(&s->incoming_fifo) < len) { + assert(num == 0); + return false; + } + + size -= num; + buf += num; + p = fifo8_pop_buf(&s->incoming_fifo, len, &num); + assert(num == len); + + memcpy(data, p, len); + + if (size > 0) { + fifo8_push_all(&s->incoming_fifo, buf, size); + } + + return true; +} + static void ivshmem_read(void *opaque, const uint8_t *buf, int size) { IVShmemState *s = opaque; @@ -448,26 +484,9 @@ static void ivshmem_read(void *opaque, const uint8_t *buf, int size) int guest_max_eventfd; long incoming_posn; - if (fifo8_is_empty(&s->incoming_fifo) && size == sizeof(incoming_posn)) { - memcpy(&incoming_posn, buf, size); - } else { - const uint8_t *p; - uint32_t num; - - IVSHMEM_DPRINTF("short read of %d bytes\n", size); - num = MIN(size, sizeof(long) - fifo8_num_used(&s->incoming_fifo)); - fifo8_push_all(&s->incoming_fifo, buf, num); - if (fifo8_num_used(&s->incoming_fifo) < sizeof(incoming_posn)) { - return; - } - size -= num; - buf += num; - p = fifo8_pop_buf(&s->incoming_fifo, sizeof(incoming_posn), &num); - g_assert(num == sizeof(incoming_posn)); - memcpy(&incoming_posn, p, sizeof(incoming_posn)); - if (size > 0) { - fifo8_push_all(&s->incoming_fifo, buf, size); - } + if (!fifo_update_and_get(s, buf, size, + &incoming_posn, sizeof(incoming_posn))) { + return; } if (incoming_posn < -1) {