From 27c3a93d153e34ac0f094f0369fd8e84479274ed Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 4 Nov 2019 22:05:50 +1100 Subject: [PATCH] [porthole] added unmap logic and response --- VERSION | 2 +- porthole/src/linux/client.c | 41 ++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 269c01c4..b52ebae1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -B1-27-g1dfa0ed218+1 \ No newline at end of file +B1-28-gdf9798c819+1 \ No newline at end of file diff --git a/porthole/src/linux/client.c b/porthole/src/linux/client.c index 27ad5387..84a034d2 100644 --- a/porthole/src/linux/client.c +++ b/porthole/src/linux/client.c @@ -234,9 +234,48 @@ static void * porthole_socket_thread(void * opaque) break; case PH_MSG_UNMAP: - /* TODO: remove the object from intmaps and maps */ + { + // notify the application of the unmap handle->unmap_cb(msg.u.unmap.id); + + // remove the PortholeMap object + unsigned int count = objectlist_count(handle->maps); + for(unsigned int i = 0; i < count; ++i) + { + PortholeMap *m = (PortholeMap *)objectlist_at(handle->maps, i); + if (m->id == msg.u.unmap.id) + { + objectlist_remove(handle->maps, i); + break; + } + } + + // remove the internal mapping object + count = objectlist_count(handle->intmaps); + for(unsigned int i = 0; i < count; ++i) + { + Mapping *m = (Mapping *)objectlist_at(handle->intmaps, i); + if (m->id == msg.u.unmap.id) + { + objectlist_remove(handle->intmaps, i); + break; + } + } break; + + // reply to the guest to allow it to continue + uint32_t reply = PH_MSG_UNMAP; + msghdr.msg_controllen = 0; + io.iov_base = &reply; + io.iov_len = sizeof(reply); + if (sendmsg(handle->socket, &msghdr, 0) < 0) + { + DEBUG_ERROR("Failed to respond to the guest"); + if (handle->discon_cb) + handle->discon_cb(); + break; + } + } } }