From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:24:08 +0000 (-0700) Subject: HGFS: Server packet abstraction part IX X-Git-Tag: 2013.09.16-1328054~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bc8730194cd723c32010053a93a580eb336e54c;p=thirdparty%2Fopen-vm-tools.git HGFS: Server packet abstraction part IX Adding in the new fields to indicate the size of the valid data, not the size of the buffer. Previously, the two were combined which meant that the buffer size was ultimately used instead making the data copies very inefficient. Another transitional change to get this stuff moved over to handle the total pack size and valid data sizes separately. Currently, VMCI has to use the total packet sizes only and so maps in 16 pages and copies all the data back and forth because it can't tell how much is actually valid. When I switch the VMCI transport header to support V2 it will have the correct data size and packet ID - asynchronous will then work too. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServer.c b/open-vm-tools/lib/hgfsServer/hgfsServer.c index b8bb1539c..fa0fdb5ad 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServer.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServer.c @@ -8399,6 +8399,7 @@ HgfsServerDirWatchEvent(HgfsSharedFolderHandle sharedFolder, // IN: shared folde packet = Util_SafeCalloc(1, sizeof *packet); packet->state &= ~HGFS_STATE_CLIENT_REQUEST; packet->metaPacketSize = sizeNeeded; + packet->metaPacketDataSize = packet->metaPacketSize; packet->metaPacket = packetHeader; packet->dataPacketIsAllocated = TRUE; notifyFlags = 0; diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c b/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c index 7a3ad2e19..73b015f74 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c @@ -107,12 +107,21 @@ HSPU_GetReplyPacket(HgfsPacket *packet, // IN/OUT: Hgfs Packet /* Can we write directly into guest memory? */ ASSERT_DEVEL(packet->metaPacket != NULL); if (packet->metaPacket != NULL) { - /* Use the pre-allocated metapacket buffer for the reply. */ + /* + * Use the mapped metapacket buffer for the reply. + * This currently makes assumptions about the mapping - + * - It is mapped read -write + * - It is always large enough for any reply + * This will change as it is grossly inefficient as the maximum size + * is always mapped and copied no matter how much data it really contains. + */ LOG(10, ("%s Using meta packet for reply packet\n", __FUNCTION__)); + ASSERT_DEVEL(*replyPacketSize <= packet->metaPacketDataSize); + ASSERT_DEVEL(BUF_READWRITEABLE == packet->metaMappingType); ASSERT_DEVEL(*replyPacketSize <= packet->metaPacketSize); packet->replyPacket = packet->metaPacket; - packet->replyPacketSize = packet->metaPacketSize; + packet->replyPacketSize = packet->metaPacketDataSize; packet->replyPacketIsAllocated = FALSE; } } else { @@ -183,7 +192,7 @@ HSPU_GetMetaPacket(HgfsPacket *packet, // IN/OUT: Hgfs Packet size_t *metaPacketSize, // OUT: Size of metaPacket HgfsServerChannelCallbacks *chanCb) // IN: Channel callbacks { - *metaPacketSize = packet->metaPacketSize; + *metaPacketSize = packet->metaPacketDataSize; if (packet->metaPacket != NULL) { return packet->metaPacket; } @@ -199,7 +208,7 @@ HSPU_GetMetaPacket(HgfsPacket *packet, // IN/OUT: Hgfs Packet packet->iov, packet->iovCount, 0, - packet->metaPacketSize, + packet->metaPacketDataSize, &packet->metaPacket, &packet->metaPacketIsAllocated, &packet->metaPacketMappedIov); @@ -373,7 +382,7 @@ HSPU_PutMetaPacket(HgfsPacket *packet, // IN/OUT: Hgfs Packet packet->iov, packet->iovCount, 0, - packet->metaPacketSize, + packet->metaPacketDataSize, &packet->metaPacket, &packet->metaPacketIsAllocated, &packet->metaPacketMappedIov); diff --git a/open-vm-tools/lib/hgfsServerManagerGuest/hgfsChannelGuestBd.c b/open-vm-tools/lib/hgfsServerManagerGuest/hgfsChannelGuestBd.c index fd3d0445e..d7ff8cd45 100644 --- a/open-vm-tools/lib/hgfsServerManagerGuest/hgfsChannelGuestBd.c +++ b/open-vm-tools/lib/hgfsServerManagerGuest/hgfsChannelGuestBd.c @@ -485,6 +485,7 @@ HgfsChannelGuestReceiveInternal(HgfsGuestConn *connData, // IN: connection packet.iov[0].len = packetInSize; packet.iovCount = 1; packet.metaPacket = (void *)packetIn; + packet.metaPacketDataSize = packetInSize; packet.metaPacketSize = packetInSize; packet.replyPacket = packetOut; packet.replyPacketSize = *packetOutSize; diff --git a/open-vm-tools/lib/include/hgfsServer.h b/open-vm-tools/lib/include/hgfsServer.h index 180f6e051..818623bdd 100644 --- a/open-vm-tools/lib/include/hgfsServer.h +++ b/open-vm-tools/lib/include/hgfsServer.h @@ -60,12 +60,14 @@ typedef struct HgfsPacket { void *metaPacket; size_t metaPacketSize; uint32 metaPacketMappedIov; + size_t metaPacketDataSize; Bool metaPacketIsAllocated; MappingType metaMappingType; void *dataPacket; size_t dataPacketSize; uint32 dataPacketMappedIov; + size_t dataPacketDataSize; uint32 dataPacketIovIndex; Bool dataPacketIsAllocated; /* What type of mapping was established - readable/ writeable ? */