]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Make vmci, vsock, vmsync and vmnet use compat_mutex
authorVMware, Inc <>
Thu, 17 Dec 2009 22:52:21 +0000 (14:52 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 17 Dec 2009 22:52:21 +0000 (14:52 -0800)
In recent rt kernels (bug 490581 reports this for
2.6.31.4-rt14), old style mutex operations are no longer
supported (DECLARE_MUTEX, init_MUTEX are gone). Since we
already have a compat_mutex.h, convert vmci, vsock, vmsync and
vmmnet to use that instead. Since vmnet used an interruptible
version of down, compat_mutex_lock_interruptible has been
added to compat_mutex.h.

Another option would be to extend the current compat_semaphore
header, but since the new Linux mutex operations are there and
are specific for mutexes, we might as well move to these.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/modules/linux/shared/compat_mutex.h
open-vm-tools/modules/linux/vmci/vmci_drv.c
open-vm-tools/modules/linux/vmsync/sync.c
open-vm-tools/modules/linux/vsock/linux/af_vsock.c

index becdf8bd545a73c975193eecd4dbcaba392e3658..95e59a9bfc5f58ff8656823da5261eff03cbf3f7 100644 (file)
 
 typedef struct semaphore compat_mutex_t;
 
-# define compat_define_mutex(_mx)       DECLARE_MUTEX(_mx)
-# define compat_mutex_init(_mx)         init_MUTEX(_mx)
-# define compat_mutex_lock(_mx)         down(_mx)
-# define compat_mutex_unlock(_mx)       up(_mx)
+# define compat_define_mutex(_mx)               DECLARE_MUTEX(_mx)
+# define compat_mutex_init(_mx)                 init_MUTEX(_mx)
+# define compat_mutex_lock(_mx)                 down(_mx)
+# define compat_mutex_lock_interruptible(_mx)   down_interruptible(_mx)
+# define compat_mutex_unlock(_mx)               up(_mx)
 
 #else
 
@@ -39,10 +40,11 @@ typedef struct semaphore compat_mutex_t;
 
 typedef struct mutex compat_mutex_t;
 
-# define compat_define_mutex(_mx)       DEFINE_MUTEX(_mx)
-# define compat_mutex_init(_mx)         mutex_init(_mx)
-# define compat_mutex_lock(_mx)         mutex_lock(_mx)
-# define compat_mutex_unlock(_mx)       mutex_unlock(_mx)
+# define compat_define_mutex(_mx)               DEFINE_MUTEX(_mx)
+# define compat_mutex_init(_mx)                 mutex_init(_mx)
+# define compat_mutex_lock(_mx)                 mutex_lock(_mx)
+# define compat_mutex_lock_interruptible(_mx)   mutex_lock_interruptible(_mx)
+# define compat_mutex_unlock(_mx)               mutex_unlock(_mx)
 
 #endif
 
index e487ecbd28c3500f88f8297877111d1f08b81cdd..791f12119e1ba6e6840ee1c88d49c1a278e30f23 100644 (file)
@@ -34,6 +34,7 @@
 #include "compat_ioport.h"
 #include "compat_interrupt.h"
 #include "compat_page.h"
+#include "compat_mutex.h"
 #include "vm_basic_types.h"
 #include "vm_device_version.h"
 #include "kernelStubs.h"
@@ -53,7 +54,7 @@
 #define VMCI_DEVICE_MINOR_NUM 0
 
 typedef struct vmci_device {
-   struct semaphore lock;
+   compat_mutex_t lock;
 
    unsigned int ioaddr;
    unsigned int ioaddr_size;
@@ -148,7 +149,7 @@ vmci_init(void)
    printk("VMCI: Major device number is: %d\n", device_major_nr);
 
    /* Initialize device data. */
-   init_MUTEX(&vmci_dev.lock);
+   compat_mutex_init(&vmci_dev.lock);
    spin_lock_init(&vmci_dev.dev_spinlock);
    vmci_dev.enabled = FALSE;
 
@@ -269,7 +270,7 @@ vmci_probe_device(struct pci_dev *pdev,           // IN: vmci PCI device
    outl(VMCI_CAPS_DATAGRAM, ioaddr + VMCI_CAPS_ADDR);
 
    /* Device struct initialization. */
-   down(&vmci_dev.lock);
+   compat_mutex_lock(&vmci_dev.lock);
    if (vmci_dev.enabled) {
       printk(KERN_ERR "VMCI device already enabled.\n");
       goto unlock;
@@ -312,7 +313,7 @@ vmci_probe_device(struct pci_dev *pdev,           // IN: vmci PCI device
 
    printk(KERN_INFO "Registered vmci device.\n");
 
-   up(&vmci_dev.lock);
+   compat_mutex_unlock(&vmci_dev.lock);
 
    /* Enable specific interrupt bits. */
    outl(VMCI_IMR_DATAGRAM, vmci_dev.ioaddr + VMCI_IMR_ADDR);
@@ -328,7 +329,7 @@ vmci_probe_device(struct pci_dev *pdev,           // IN: vmci PCI device
    VMCIEvent_Exit();
    VMCIProcess_Exit();
  unlock:
-   up(&vmci_dev.lock);
+   compat_mutex_unlock(&vmci_dev.lock);
  release:
    release_region(ioaddr, ioaddr_size);
  pci_disable:
@@ -368,7 +369,7 @@ vmci_remove_device(struct pci_dev* pdev)
    //VMCIDatagram_Exit();
    VMCIProcess_Exit();
 
-   down(&dev->lock);
+   compat_mutex_lock(&dev->lock);
    printk(KERN_INFO "Resetting vmci device\n");
    outl(VMCI_CONTROL_RESET, vmci_dev.ioaddr + VMCI_CONTROL_ADDR);
    free_irq(dev->irq, dev);
@@ -376,7 +377,7 @@ vmci_remove_device(struct pci_dev* pdev)
    dev->enabled = FALSE;
 
    printk(KERN_INFO "Unregistered vmci device.\n");
-   up(&dev->lock);
+   compat_mutex_unlock(&dev->lock);
 
    compat_pci_disable_device(pdev);
 }
@@ -411,7 +412,7 @@ vmci_open(struct inode *inode,  // IN
       return -ENODEV;
    }
 
-   down(&vmci_dev.lock);
+   compat_mutex_lock(&vmci_dev.lock);
    if (!vmci_dev.enabled) {
       printk(KERN_INFO "Received open on uninitialized vmci device.\n");
       errcode = -ENODEV;
@@ -429,12 +430,12 @@ vmci_open(struct inode *inode,  // IN
    devHndl->objType = VMCIOBJ_NOT_SET;
    file->private_data = devHndl;
 
-   up(&vmci_dev.lock);
+   compat_mutex_unlock(&vmci_dev.lock);
 
    return 0;
 
  unlock:
-   up(&vmci_dev.lock);
+   compat_mutex_unlock(&vmci_dev.lock);
    return errcode;
 }
 
@@ -795,9 +796,9 @@ VMCI_DeviceEnabled(void)
 {
    Bool retval;
 
-   down(&vmci_dev.lock);
+   compat_mutex_lock(&vmci_dev.lock);
    retval = vmci_dev.enabled;
-   up(&vmci_dev.lock);
+   compat_mutex_unlock(&vmci_dev.lock);
 
    return retval;
 }
index c43ff6b491b504a834970fc755f86adf4cc707d5..06d796bbcdcac005d4554d5532da5b756b0c078c 100644 (file)
@@ -47,7 +47,7 @@
 #include "compat_fs.h"
 #include "compat_module.h"
 #include "compat_namei.h"
-#include "compat_semaphore.h"
+#include "compat_mutex.h"
 #include "compat_slab.h"
 #include "compat_workqueue.h"
 
@@ -112,7 +112,7 @@ typedef struct VmSyncBlockDevice {
 
 typedef struct VmSyncState {
    struct list_head     devices;
-   struct semaphore     lock;
+   compat_mutex_t       lock;
    compat_delayed_work  thawTask;
 } VmSyncState;
 
@@ -121,7 +121,7 @@ typedef struct VmSyncState {
  * Serializes freeze operations. Used to make sure that two different
  * fds aren't allowed to freeze the same device.
  */
-static struct semaphore gFreezeLock;
+static compat_mutex_t gFreezeLock;
 
 /* A global count of how many devices are currently frozen by the driver. */
 static atomic_t gFreezeCount;
@@ -158,7 +158,7 @@ VmSyncThawDevices(void  *_state)  // IN
 
    state = (VmSyncState *) _state;
 
-   down(&state->lock);
+   compat_mutex_lock(&state->lock);
    cancel_delayed_work(&state->thawTask);
    list_for_each_safe(cur, tmp, &state->devices) {
       dev = list_entry(cur, VmSyncBlockDevice, list);
@@ -169,7 +169,7 @@ VmSyncThawDevices(void  *_state)  // IN
       list_del_init(&dev->list);
       kmem_cache_free(gBlockDeviceCache, dev);
    }
-   up(&state->lock);
+   compat_mutex_unlock(&state->lock);
 }
 
 
@@ -322,8 +322,8 @@ VmSyncFreezeDevices(VmSyncState *state,            // IN
       return PTR_ERR(paths);
    }
 
-   down(&gFreezeLock);
-   down(&state->lock);
+   compat_mutex_lock(&gFreezeLock);
+   compat_mutex_lock(&state->lock);
 
    /*
     * First, try to add all paths to the list of paths to be frozen.
@@ -368,8 +368,8 @@ VmSyncFreezeDevices(VmSyncState *state,            // IN
       }
    }
 
-   up(&state->lock);
-   up(&gFreezeLock);
+   compat_mutex_unlock(&state->lock);
+   compat_mutex_unlock(&gFreezeLock);
 
    if (result == 0) {
       compat_schedule_delayed_work(&state->thawTask, VMSYNC_THAW_TASK_DELAY);
@@ -618,7 +618,7 @@ VmSyncStateCtor(COMPAT_KMEM_CACHE_CTOR_ARGS(slabelem))  // IN
    INIT_LIST_HEAD(&state->devices);
    COMPAT_INIT_DELAYED_WORK(&state->thawTask,
                             VmSyncThawDevicesCallback, state);
-   init_MUTEX(&state->lock);
+   compat_mutex_init(&state->lock);
 }
 
 
@@ -645,7 +645,7 @@ init_module(void)
    struct proc_dir_entry *controlProcEntry;
 
    atomic_set(&gFreezeCount, 0);
-   init_MUTEX(&gFreezeLock);
+   compat_mutex_init(&gFreezeLock);
 
    /* Create the slab allocators for the module. */
    gBlockDeviceCache = compat_kmem_cache_create("VmSyncBlockDeviceCache",
index 90e4fe385ae20241b700bf6db19214b6b81ba4c0..b620adf64c3e253a1bfa8425f31bb7f3d3487a85 100644 (file)
@@ -120,9 +120,7 @@ sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
 #include "compat_version.h"
 #include "compat_workqueue.h"
 #include "compat_list.h"
-#if defined(HAVE_COMPAT_IOCTL) || defined(HAVE_UNLOCKED_IOCTL)
-#   include "compat_semaphore.h"
-#endif
+#include "compat_mutex.h"
 
 #include "vmware.h"
 
@@ -344,7 +342,7 @@ typedef struct VSockRecvPktInfo {
    VSockPacket pkt;
 } VSockRecvPktInfo;
 
-static DECLARE_MUTEX(registrationMutex);
+static compat_define_mutex(registrationMutex);
 static int devOpenCount = 0;
 static int vsockVmciSocketCount = 0;
 static int vsockVmciKernClientCount = 0;
@@ -516,7 +514,7 @@ VMCISock_GetAFValue(void)
 {
    int afvalue;
 
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
 
    /*
     * Kernel clients are required to explicitly register themselves before they
@@ -530,7 +528,7 @@ VMCISock_GetAFValue(void)
    afvalue = VSockVmciGetAFValue();
 
 exit:
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
    return afvalue;
 }
 EXPORT_SYMBOL(VMCISock_GetAFValue);
@@ -560,7 +558,7 @@ VMCISock_GetLocalCID(void)
 {
    int cid;
 
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
 
    /*
     * Kernel clients are required to explicitly register themselves before they
@@ -574,7 +572,7 @@ VMCISock_GetLocalCID(void)
    cid = VMCI_GetContextID();
 
 exit:
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
    return cid;
 }
 EXPORT_SYMBOL(VMCISock_GetLocalCID);
@@ -602,9 +600,9 @@ EXPORT_SYMBOL(VMCISock_GetLocalCID);
 void
 VMCISock_KernelRegister(void)
 {
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    vsockVmciKernClientCount++;
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 }
 EXPORT_SYMBOL(VMCISock_KernelRegister);
 
@@ -630,10 +628,10 @@ EXPORT_SYMBOL(VMCISock_KernelRegister);
 void
 VMCISock_KernelDeregister(void)
 {
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    vsockVmciKernClientCount--;
    VSockVmciTestUnregister();
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 }
 EXPORT_SYMBOL(VMCISock_KernelDeregister);
 
@@ -689,9 +687,9 @@ VSockVmci_GetAFValue(void)
 {
    int afvalue;
 
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    afvalue = VSockVmciGetAFValue();
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 
    return afvalue;
 }
@@ -1297,7 +1295,7 @@ VSockVmciCidChangedCB(VMCIId subId,             // IN
                       void *clientData)         // IN
 {
    int err;
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
 
    if (!VMCI_HANDLE_INVALID(vmciStreamHandle)) {
       VMCIDatagram_DestroyHnd(vmciStreamHandle);
@@ -1312,7 +1310,7 @@ VSockVmciCidChangedCB(VMCIId subId,             // IN
       Warning("Unable to create datagram handle. (%d)\n", err);
    }
 
-  up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 }
 
 
@@ -2727,9 +2725,9 @@ __VSockVmciCreate(struct net *net,       // IN: Network namespace
     * If we go this far, we know the socket family is registered, so there's no
     * need to register it now.
     */
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    vsockVmciSocketCount++;
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 
    sock_init_data(sock, sk);
 
@@ -2910,10 +2908,10 @@ VSockVmciSkDestruct(struct sock *sk) // IN
 
    NOTIFYCALL(vsk, socketDestruct, sk);
 
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    vsockVmciSocketCount--;
    VSockVmciTestUnregister();
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 
 
    VSOCK_STATS_CTLPKT_DUMP_ALL();
@@ -4944,9 +4942,9 @@ int
 VSockVmciDevOpen(struct inode *inode,  // IN
                  struct file *file)    // IN
 {
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    devOpenCount++;
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
    return 0;
 }
 
@@ -4972,10 +4970,10 @@ int
 VSockVmciDevRelease(struct inode *inode,  // IN
                     struct file *file)    // IN
 {
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    devOpenCount--;
    VSockVmciTestUnregister();
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
    return 0;
 }
 
@@ -5142,9 +5140,9 @@ VSockVmciExit(void)
 {
    unregister_ioctl32_handlers();
    misc_deregister(&vsockVmciDevice);
-   down(&registrationMutex);
+   compat_mutex_lock(&registrationMutex);
    VSockVmciUnregisterAddressFamily();
-   up(&registrationMutex);
+   compat_mutex_unlock(&registrationMutex);
 
    VSockVmciUnregisterProto();
 }