From patchwork Fri Oct 2 19:09:08 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: 525733 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 C04EC1402D5 for ; Sat, 3 Oct 2015 05:26:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=ZKXxGA+H; dkim-atps=neutral Received: from localhost ([::1]:34603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5y0-0002uV-LM for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 15:26:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5id-0007YO-AY for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi5iX-0006wL-BP for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:11 -0400 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:35510) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5iW-0006tS-Sm for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:10:05 -0400 Received: by wicge5 with SMTP id ge5so46216438wic.0 for ; Fri, 02 Oct 2015 12:10:04 -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=ZKXxGA+HU4acnyjbv3ZoRNZ+HI8nYP4t6LueIYrJ8mrrzrL2elFU0iSKSJmIwO85+q YFbxvAQjDTdQdfhxlIXBekHPir9uNBYMF9R3afjI0H8tlFeRlRD9fh5Au5TckEy3fDtP nY4+1QieVUJS2WgOleZpXlT13QUJYdaE5MMvjRk/FhnVfXCrmF6pGq4VLJAkjUwRNOG8 tK9n1zhn0LIcGVEWbTWfCD5x68SOX8L1NUBhy/bWyIUU4qSd+rhC0DH3qbKEWm6Z2pjS SA6L0VzrhxPc7mSc45TSJXr8xuloDQhaicWFoKB1SSXGz3seje6tKb0qygm7JS9ChY3g WMKw== X-Received: by 10.180.198.109 with SMTP id jb13mr458897wic.17.1443813004399; Fri, 02 Oct 2015 12:10:04 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id gl4sm12713714wjb.29.2015.10.02.12.10.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 12:10:03 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 21:09:08 +0200 Message-Id: <1443812991-17356-6-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> References: <1443812991-17356-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: 2a00:1450:400c:c05::231 Cc: 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] [PATCH v5 05/48] 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) {