]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
HGFS: clean up the transport channel callbacks from the HGFS server
authorVMware, Inc <>
Fri, 12 Apr 2013 19:58:20 +0000 (12:58 -0700)
committerDmitry Torokhov <dtor@vmware.com>
Wed, 17 Apr 2013 19:16:57 +0000 (12:16 -0700)
The transport channel callbacks for the HGFS packet request-reply to read,
write and release the memory use badly defined arguments. It uses character
pointer and calls it a token. The type is simply just wrong and should be
treated as an opaque type owned and manipulated only by the channel transport.
Secondly, it is really a context although it is a token, it could be anything
the channel chooses and could change in the future.

This change fixes these issues to be a void *context. This shows that the type
and meaning are not to be exposed beyond the owner of object which is the channel
in this case.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/hgfsServer/hgfsServerPacketUtil.c
open-vm-tools/lib/include/hgfsServer.h

index 925455b3118dce0f324536da787d54bb6664dbe1..1993b6912cbd4b6ef86131eb38e18be5083fb64c 100644 (file)
@@ -215,7 +215,8 @@ HSPU_GetBuf(HgfsPacket *packet,           // IN/OUT: Hgfs Packet
    uint32 iovMapped = 0;
    int32 size = bufSize;
    int i;
-   void* (*func)(uint64, uint32, char **);
+   HgfsChannelMapVirtAddrFunc getVa;
+
    ASSERT(buf);
 
    if (*buf) {
@@ -230,14 +231,14 @@ HSPU_GetBuf(HgfsPacket *packet,           // IN/OUT: Hgfs Packet
 
    if (mappingType == BUF_WRITEABLE ||
        mappingType == BUF_READWRITEABLE) {
-      func = transportSession->channelCbTable->getWriteVa;
+      getVa = transportSession->channelCbTable->getWriteVa;
    } else {
       ASSERT(mappingType == BUF_READABLE);
-      func = transportSession->channelCbTable->getReadVa;
+      getVa = transportSession->channelCbTable->getReadVa;
    }
 
    /* Looks like we are in the middle of poweroff. */
-   if (func == NULL) {
+   if (getVa == NULL) {
       return NULL;
    }
 
@@ -245,15 +246,15 @@ HSPU_GetBuf(HgfsPacket *packet,           // IN/OUT: Hgfs Packet
    for (iovCount = startIndex; iovCount < packet->iovCount && size > 0;
         iovCount++) {
 
-      packet->iov[iovCount].token = NULL;
+      packet->iov[iovCount].context = NULL;
 
       /* Debugging check: Iov in VMCI should never cross page boundary */
       ASSERT_DEVEL(packet->iov[iovCount].len <=
       (PAGE_SIZE - PAGE_OFFSET(packet->iov[iovCount].pa)));
 
-      packet->iov[iovCount].va = func(packet->iov[iovCount].pa,
-                                      packet->iov[iovCount].len,
-                                      &packet->iov[iovCount].token);
+      packet->iov[iovCount].va = getVa(packet->iov[iovCount].pa,
+                                       packet->iov[iovCount].len,
+                                       &packet->iov[iovCount].context);
       ASSERT_DEVEL(packet->iov[iovCount].va);
       if (packet->iov[iovCount].va == NULL) {
          /* Guest probably passed us bad physical address */
@@ -302,7 +303,7 @@ HSPU_GetBuf(HgfsPacket *packet,           // IN/OUT: Hgfs Packet
 
 freeMem:
    for (i = startIndex; i < iovCount; i++) {
-      transportSession->channelCbTable->putVa(&packet->iov[i].token);
+      transportSession->channelCbTable->putVa(&packet->iov[i].context);
       packet->iov[i].va = NULL;
    }
 
@@ -436,8 +437,8 @@ HSPU_PutBuf(HgfsPacket *packet,        // IN/OUT: Hgfs Packet
       for (iovCount = startIndex;
            iovCount < packet->iovCount && size > 0;
            iovCount++) {
-         ASSERT_DEVEL(packet->iov[iovCount].token);
-         transportSession->channelCbTable->putVa(&packet->iov[iovCount].token);
+         ASSERT_DEVEL(packet->iov[iovCount].context);
+         transportSession->channelCbTable->putVa(&packet->iov[iovCount].context);
          size -= packet->iov[iovCount].len;
       }
       LOG(10, ("%s: Hgfs bufSize = %d \n", __FUNCTION__, size));
@@ -542,19 +543,20 @@ HSPU_CopyBufToIovec(HgfsPacket *packet,       // IN/OUT: Hgfs Packet
       copyAmount = remainingSize < packet->iov[iovCount].len ?
                    remainingSize: packet->iov[iovCount].len;
 
-      packet->iov[iovCount].token = NULL;
+      packet->iov[iovCount].context = NULL;
 
       /* Debugging check: Iov in VMCI should never cross page boundary */
       ASSERT_DEVEL(packet->iov[iovCount].len <=
                   (PAGE_SIZE - PAGE_OFFSET(packet->iov[iovCount].pa)));
 
-      packet->iov[iovCount].va = transportSession->channelCbTable->getWriteVa(packet->iov[iovCount].pa,
-                                                     packet->iov[iovCount].len,
-                                                     &packet->iov[iovCount].token);
+      packet->iov[iovCount].va =
+         transportSession->channelCbTable->getWriteVa(packet->iov[iovCount].pa,
+                                                      packet->iov[iovCount].len,
+                                                      &packet->iov[iovCount].context);
       ASSERT_DEVEL(packet->iov[iovCount].va);
       if (packet->iov[iovCount].va != NULL) {
          memcpy(packet->iov[iovCount].va, (char *)buf + copiedAmount, copyAmount);
-         transportSession->channelCbTable->putVa(&packet->iov[iovCount].token);
+         transportSession->channelCbTable->putVa(&packet->iov[iovCount].context);
          remainingSize -= copyAmount;
          copiedAmount += copyAmount;
       } else {
index 3b221c0766d2ea77d7c0471ceab85b55d0ca4396..0786e133c6a616a9dd82bd720e05d1cf60ec25a0 100644 (file)
@@ -40,7 +40,7 @@ struct HgfsVmxIov {
    void *va;           /* Virtual addr */
    uint64 pa;          /* Physical address passed by the guest */
    uint32 len;         /* length of data; should be <= PAGE_SIZE for VMCI; arbitrary for backdoor */
-   char *token;        /* Token for physMem_ APIs */
+   void *context;      /* Mapping context */
 } HgfsVmxIov;
 
 typedef enum {
@@ -116,11 +116,6 @@ typedef struct HgfsServerChannelData {
    uint32 maxPacketSize;
 }HgfsServerChannelData;
 
-typedef Bool
-HgfsSessionSendFunc(void *opaqueSession,  // IN
-                    char *buffer,         // IN
-                    size_t bufferLen,     // IN
-                    HgfsSendFlags flags); // IN
 
 /* Default maximum number of open nodes. */
 #define HGFS_MAX_CACHED_FILENODES   30
@@ -137,12 +132,19 @@ typedef struct HgfsServerConfig {
    uint32 maxCachedOpenNodes;
 }HgfsServerConfig;
 
+typedef Bool (*HgfsChannelSendFunc)(void *opaqueSession,
+                                    HgfsPacket *packet,
+                                    char *buffer,
+                                    size_t bufferLen,
+                                    HgfsSendFlags flags);
+typedef void * (*HgfsChannelMapVirtAddrFunc)(uint64 pa, uint32 size, void **context);
+typedef void (*HgfsChannelUnmapVirtAddrFunc)(void **context);
+
 typedef struct HgfsServerChannelCallbacks {
-    void* (*getReadVa)(uint64 pa, uint32 size, char **token);
-    void* (*getWriteVa)(uint64 pa, uint32 size, char **token);
-    void (*putVa)(char **token);
-    Bool (*send)(void *opaqueSession, HgfsPacket *packet, char *buffer,
-                 size_t bufferLen, HgfsSendFlags flags);
+    HgfsChannelMapVirtAddrFunc getReadVa;
+    HgfsChannelMapVirtAddrFunc getWriteVa;
+    HgfsChannelUnmapVirtAddrFunc putVa;
+    HgfsChannelSendFunc send;
 }HgfsServerChannelCallbacks;
 
 typedef struct HgfsServerSessionCallbacks {