From patchwork Mon Oct 12 16:41:28 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: 529237 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 B775E1400CB for ; Tue, 13 Oct 2015 04:03:12 +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=Ww2gC01k; dkim-atps=neutral Received: from localhost ([::1]:56794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgVC-00051Q-Es for incoming@patchwork.ozlabs.org; Mon, 12 Oct 2015 13:03:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgIG-0000wU-MT for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:49:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZlgIE-0003i7-KP for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:49:47 -0400 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:35432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZlgIE-0003i1-EV for qemu-devel@nongnu.org; Mon, 12 Oct 2015 12:49:46 -0400 Received: by pabve7 with SMTP id ve7so100585685pab.2 for ; Mon, 12 Oct 2015 09:49:45 -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=+pArPxHD1cPPbsHZGx7nWI9Wmg5hO+gTFsteSyyu+oY=; b=Ww2gC01k7Ig6a+e+DZZ9BuFCzF1V9DhwbFuUPqTKxD7sOPOT3SNhiU8Me85VxHpMMA fk0GEnkgmhg0LLA/y4Xr6DI/XEBM8tu/aio30C/wlWBDj+STfriqCctggKVqqXqaKP2M cq/jWBLxcdzlyyqVOm2XP6pThhuTiiKRbiJhBYiC5+g60nQ00qkTpEA6Lyf9Hr7T9vp7 CCygX0MsRT6zn4RPpBpL8w7moPqmVu9GT2q3QR+gVfa8G2i4ccyK9Ql34WaoDrkNNrVz nUImsZJRmDZN0HbdukQH2zXoNGIu1HZF32aC1UHHuL+z8beAKPhKtAZZiL9rHPu/szAH YvqQ== X-Received: by 10.68.222.163 with SMTP id qn3mr35898828pbc.54.1444668585910; Mon, 12 Oct 2015 09:49:45 -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 xd10sm19420054pab.25.2015.10.12.09.49.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:49:45 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Mon, 12 Oct 2015 18:41:28 +0200 Message-Id: <1444668104-22955-35-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::22c 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 34/50] ivshmem-server: use a uint16 for client ID 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 In practice, the number of VM is limited to MAXUINT16 in ivshmem, so use the same limit on the server (removes a theorical infinite loop) Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- contrib/ivshmem-server/ivshmem-server.c | 11 ++++++++++- contrib/ivshmem-server/ivshmem-server.h | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c index 16ee583..972fda2 100644 --- a/contrib/ivshmem-server/ivshmem-server.c +++ b/contrib/ivshmem-server/ivshmem-server.c @@ -145,9 +145,18 @@ ivshmem_server_handle_new_conn(IvshmemServer *server) peer->sock_fd = newfd; /* get an unused peer id */ - while (ivshmem_server_search_peer(server, server->cur_id) != NULL) { + /* XXX: this could use id allocation such as Linux IDA, or simply + * a free-list */ + for (i = 0; i < G_MAXUINT16; i++) { + if (ivshmem_server_search_peer(server, server->cur_id) == NULL) { + break; + } server->cur_id++; } + if (i == G_MAXUINT16) { + IVSHMEM_SERVER_DEBUG(server, "cannot allocate new client id\n"); + goto fail; + } peer->id = server->cur_id++; /* create eventfd, one per vector */ diff --git a/contrib/ivshmem-server/ivshmem-server.h b/contrib/ivshmem-server/ivshmem-server.h index cd584fc..2176d5e 100644 --- a/contrib/ivshmem-server/ivshmem-server.h +++ b/contrib/ivshmem-server/ivshmem-server.h @@ -70,7 +70,7 @@ typedef struct IvshmemServer { size_t shm_size; /**< size of shm */ int shm_fd; /**< shm file descriptor */ unsigned n_vectors; /**< number of vectors */ - long cur_id; /**< id to be given to next client */ + uint16_t cur_id; /**< id to be given to next client */ bool verbose; /**< true in verbose mode */ IvshmemServerPeerList peer_list; /**< list of peers */ } IvshmemServer;