]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Reference count the VMCI device.
authorVMware, Inc <>
Thu, 24 Feb 2011 21:59:47 +0000 (13:59 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 24 Feb 2011 21:59:47 +0000 (13:59 -0800)
We must reference the device when we have clients
attached, for example HGFS or vsock.  Changed
VMCI_DeviceGet() and VMCI_DeviceRelease() so that
they reference count, and added new function
VMCI_DeviceInUse() so that we can tell when the
device is referenced during a query-for-stop IRP
and fail if necessary.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/modules/linux/vmci/vmciUtil.c
open-vm-tools/modules/linux/vmci/vmciUtil.h

index 6b7add5b9fbd10f745d46bb1fc5124c71f3ed631..e0ad2025c169a606fe3b1a55554fd659ffbc86fa 100644 (file)
@@ -65,6 +65,7 @@ static void VMCIUtilCidUpdate(VMCIId subID, VMCI_EventData *eventData,
 
 static VMCIId ctxUpdateSubID = VMCI_INVALID_ID;
 static Atomic_uint32 vmContextID = { VMCI_INVALID_ID };
+static Atomic_uint32 vmciClientCount;
 
 
 /*
@@ -363,11 +364,26 @@ VMCI_EXPORT_SYMBOL(VMCI_DeviceGet)
 Bool
 VMCI_DeviceGet(uint32 *apiVersion)
 {
+   Atomic_Inc32(&vmciClientCount);
+
    if (*apiVersion > VMCI_KERNEL_API_VERSION) {
       *apiVersion = VMCI_KERNEL_API_VERSION;
-      return FALSE;
+      goto release;
+   }
+
+   if (!VMCI_DeviceEnabled()) {
+      goto release;
    }
-   return VMCI_DeviceEnabled();
+
+   if (VMCI_DeviceShutdown()) {
+      goto release;
+   }
+
+   return TRUE;
+
+release:
+   Atomic_Dec32(&vmciClientCount);
+   return FALSE;
 }
 
 
@@ -391,6 +407,31 @@ VMCI_EXPORT_SYMBOL(VMCI_DeviceRelease)
 void
 VMCI_DeviceRelease(void)
 {
+   Atomic_Dec32(&vmciClientCount);
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * VMCI_DeviceInUse --
+ *
+ *      Report whether the device is in-use by a client.
+ *
+ * Results:
+ *      TRUE if the device is in-use (reference count greater than zero),
+ *      FALSE otherwise.
+ *
+ * Side effects:
+ *      None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Bool
+VMCI_DeviceInUse(void)
+{
+   return Atomic_Read32(&vmciClientCount) > 0 ? TRUE : FALSE;
 }
 
 
index 13eefda0adeed8c1cf5bce46a9da8334d60b2cc3..62dccbfeb7d6ec1267ab40b78e04dc64615c58c5 100644 (file)
@@ -47,6 +47,7 @@ Bool VMCIUtil_CheckHostCapabilities(void);
 Bool VMCI_CheckHostCapabilities(void);
 Bool VMCI_InInterrupt(void);
 void VMCI_ReadDatagramsFromPort(VMCIIoHandle ioHandle, VMCIIoPort dgInPort,
-                               uint8 *dgInBuffer, size_t dgInBufferSize);
+                                uint8 *dgInBuffer, size_t dgInBufferSize);
+Bool VMCI_DeviceInUse(void);
 
 #endif //__VMCI_UTIL_H__