~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to modules/linux/vmci/vmciDatagram.c

  • Committer: Bazaar Package Importer
  • Author(s): Nate Muench
  • Date: 2010-09-06 21:06:01 UTC
  • mfrom: (2.4.19 sid)
  • Revision ID: james.westby@ubuntu.com-20100906210601-gxxy30e5roil4srt
Tags: 2010.06.16-268169-3ubuntu1
* Merge from Debian testing (LP: #632101), remaining changes:
  - Recommend open-vm-toolbox in open-vm-tools.
  - Rediffing vsock.patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *
17
17
 *********************************************************/
18
18
 
19
 
/* 
 
19
/*
20
20
 * vmciDatagram.c --
21
21
 *
22
22
 *      Simple Datagram API for the guest driver.
49
49
#include "vmciUtil.h"
50
50
#include "vmciDatagram.h"
51
51
#include "vmciCommonInt.h"
 
52
#include "vmciKernelAPI.h"
52
53
 
53
54
typedef struct DatagramHashEntry {
54
55
   struct DatagramHashEntry  *next;
67
68
#define VMCI_HASHRESOURCE(handle, size)                              \
68
69
   VMCI_HashId(VMCI_HANDLE_TO_RESOURCE_ID(handle), (size))
69
70
 
70
 
/* 
71
 
 * Hash table containing all the datagram handles for this VM. It is 
 
71
/*
 
72
 * Hash table containing all the datagram handles for this VM. It is
72
73
 * synchronized using a single lock but we should consider making it more
73
74
 * fine grained, e.g. a per bucket lock or per set of buckets' lock.
74
75
 */
100
101
 *
101
102
 *  DatagramReleaseCB --
102
103
 *
103
 
 *     Callback to release the datagram entry reference. It is called by the 
 
104
 *     Callback to release the datagram entry reference. It is called by the
104
105
 *     VMCI_WaitOnEvent function before it blocks.
105
 
 * 
 
106
 *
106
107
 *  Result:
107
108
 *     None.
108
 
 *     
 
109
 *
109
110
 *------------------------------------------------------------------------------
110
111
 */
111
112
 
131
132
 *
132
133
 *  Result:
133
134
 *     VMCI_SUCCESS if added, error if not.
134
 
 *     
 
135
 *
135
136
 *-------------------------------------------------------------------------
136
137
 */
137
138
 
183
184
         return VMCI_ERROR_NO_HANDLE;
184
185
      }
185
186
   }
186
 
   
 
187
 
187
188
   ASSERT(!VMCI_HANDLE_INVALID(entry->handle));
188
189
   idx = VMCI_HASHRESOURCE(entry->handle, HASH_TABLE_SIZE);
189
190
 
204
205
 *
205
206
 *  Result:
206
207
 *     VMCI_SUCCESS if removed, VMCI_ERROR_NO_HANDLE if not found.
207
 
 *     
 
208
 *
208
209
 *-------------------------------------------------------------------------
209
210
 */
210
211
 
211
212
static int
212
213
DatagramHashRemoveEntry(VMCIHandle handle)
213
 
 
214
{
214
215
   int result = VMCI_ERROR_NOT_FOUND;
215
216
   VMCILockFlags flags;
216
217
   DatagramHashEntry *prev, *cur;
232
233
         }
233
234
 
234
235
         cur->refCount--;
235
 
         
236
 
         /* 
237
 
          * We know that DestroyHnd still has a reference so refCount must be 
 
236
 
 
237
         /*
 
238
          * We know that DestroyHnd still has a reference so refCount must be
238
239
          * at least 1.
239
 
          */      
 
240
          */
240
241
         ASSERT(cur->refCount > 0);
241
242
         result = VMCI_SUCCESS;
242
243
         break;
852
853
 *-----------------------------------------------------------------------------
853
854
 */
854
855
 
855
 
void 
 
856
void
856
857
VMCIDatagram_Init(void)
857
858
{
858
859
   int i;
859
 
   
 
860
 
860
861
   VMCI_InitLock(&hashTable.lock,
861
862
                 "VMCIDatagramHashtable",
862
863
                 VMCI_LOCK_RANK_MIDDLE_BH);
871
872
 *
872
873
 * VMCIDatagram_CheckHostCapabilities --
873
874
 *
874
 
 *      Verify that the host supports the resources we need. 
 
875
 *      Verify that the host supports the resources we need.
875
876
 *      None are required for datagrams since they are implicitly supported.
876
877
 *
877
878
 * Results:
916
917
   VMCIDatagram *dgm;
917
918
   DatagramQueueEntry *dqEntry;
918
919
   VMCILockFlags flags;
919
 
   
 
920
 
920
921
   ASSERT(dgmProc != NULL && msg != NULL);
921
922
   dgmSize = VMCI_DG_SIZE(msg);
922
923
   ASSERT(dgmSize <= VMCI_MAX_DG_SIZE);
931
932
   memcpy(dgm, msg, dgmSize);
932
933
 
933
934
   /* Allocate datagram queue entry and add it to the target fd's queue. */
934
 
   dqEntry = VMCI_AllocKernelMem(sizeof *dqEntry, 
 
935
   dqEntry = VMCI_AllocKernelMem(sizeof *dqEntry,
935
936
                                 VMCI_MEMORY_NONPAGED | VMCI_MEMORY_ATOMIC);
936
937
   if (dqEntry == NULL) {
937
938
      VMCI_FreeKernelMem(dgm, dgmSize);
953
954
   dgmProc->pendingDatagrams++;
954
955
   dgmProc->datagramQueueSize += dgmSize;
955
956
#ifdef SOLARIS
956
 
   /* 
957
 
    * Release the lock here for Solaris. Otherwise, a deadlock 
 
957
   /*
 
958
    * Release the lock here for Solaris. Otherwise, a deadlock
958
959
    * may occur since pollwakeup(9F) (invoked from VMCIHost_SignalCall)
959
960
    * and poll_common (invoked from poll(2)) try to grab a common lock.
960
961
    * The man pages of pollwakeup(9F) and chpoll(9E) talk about this.
1013
1014
   dgmProc->datagramQueue = NULL;
1014
1015
 
1015
1016
   /*
1016
 
    * We pass the result and corresponding handle to user level via the 
 
1017
    * We pass the result and corresponding handle to user level via the
1017
1018
    * createInfo.
1018
1019
    */
1019
1020
   createInfo->result = VMCIDatagram_CreateHnd(createInfo->resourceID,
1061
1062
 
1062
1063
   if (!VMCI_HANDLE_EQUAL(dgmProc->handle, VMCI_INVALID_HANDLE)) {
1063
1064
 
1064
 
      /* 
1065
 
       * We block in destroy so we know that there can be no more 
 
1065
      /*
 
1066
       * We block in destroy so we know that there can be no more
1066
1067
       * callbacks to DatagramProcessNotifyCB when we return from
1067
1068
       * this call.
1068
1069
       */
1105
1106
int
1106
1107
VMCIDatagramProcess_ReadCall(VMCIDatagramProcess *dgmProc, // IN:
1107
1108
                             size_t maxSize,               // IN: max size of dg
1108
 
                             VMCIDatagram **dg)            // OUT: 
 
1109
                             VMCIDatagram **dg)            // OUT:
1109
1110
{
1110
1111
   DatagramQueueEntry *dqEntry;
1111
1112
   ListItem *listItem;
1153
1154
      VMCI_LOG(("VMCI: Caller's buffer is too small.\n"));
1154
1155
      return VMCI_ERROR_NO_MEM;
1155
1156
   }
1156
 
   
 
1157
 
1157
1158
   LIST_DEL(listItem, &dgmProc->datagramQueue);
1158
1159
   dgmProc->pendingDatagrams--;
1159
1160
   dgmProc->datagramQueueSize -= VMCI_DG_SIZE(dqEntry->dg);