aboutsummaryrefslogtreecommitdiff
path: root/contrib/ivshmem-server/ivshmem-server.c
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2015-06-23 17:09:59 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2015-10-24 18:03:16 +0200
commit022cffe31360750b405d368e343f3ca5febc0d0a (patch)
tree7daea3d2b9296c673c57334a6b6a2bc1ac3a5d5a /contrib/ivshmem-server/ivshmem-server.c
parent95204aa951ceb28eb6d4ce43bce09a58cbad83d8 (diff)
ivshmem-server: use a uint16 for client ID
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 <marcandre.lureau@redhat.com> Reviewed-by: Claudio Fontana <claudio.fontana@huawei.com>
Diffstat (limited to 'contrib/ivshmem-server/ivshmem-server.c')
-rw-r--r--contrib/ivshmem-server/ivshmem-server.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/contrib/ivshmem-server/ivshmem-server.c b/contrib/ivshmem-server/ivshmem-server.c
index 56b5df8ab7..53a51735ee 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 */