From: VMware, Inc <> Date: Thu, 17 Dec 2009 22:52:21 +0000 (-0800) Subject: Make vmci, vsock, vmsync and vmnet use compat_mutex X-Git-Tag: 2009.12.16-217847~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46af6067caaa980e84055011154c38e2bbed7010;p=thirdparty%2Fopen-vm-tools.git Make vmci, vsock, vmsync and vmnet use compat_mutex 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 --- diff --git a/open-vm-tools/modules/linux/shared/compat_mutex.h b/open-vm-tools/modules/linux/shared/compat_mutex.h index becdf8bd5..95e59a9bf 100644 --- a/open-vm-tools/modules/linux/shared/compat_mutex.h +++ b/open-vm-tools/modules/linux/shared/compat_mutex.h @@ -28,10 +28,11 @@ 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 diff --git a/open-vm-tools/modules/linux/vmci/vmci_drv.c b/open-vm-tools/modules/linux/vmci/vmci_drv.c index e487ecbd2..791f12119 100644 --- a/open-vm-tools/modules/linux/vmci/vmci_drv.c +++ b/open-vm-tools/modules/linux/vmci/vmci_drv.c @@ -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; } diff --git a/open-vm-tools/modules/linux/vmsync/sync.c b/open-vm-tools/modules/linux/vmsync/sync.c index c43ff6b49..06d796bbc 100644 --- a/open-vm-tools/modules/linux/vmsync/sync.c +++ b/open-vm-tools/modules/linux/vmsync/sync.c @@ -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", diff --git a/open-vm-tools/modules/linux/vsock/linux/af_vsock.c b/open-vm-tools/modules/linux/vsock/linux/af_vsock.c index 90e4fe385..b620adf64 100644 --- a/open-vm-tools/modules/linux/vsock/linux/af_vsock.c +++ b/open-vm-tools/modules/linux/vsock/linux/af_vsock.c @@ -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(®istrationMutex); + compat_mutex_lock(®istrationMutex); /* * Kernel clients are required to explicitly register themselves before they @@ -530,7 +528,7 @@ VMCISock_GetAFValue(void) afvalue = VSockVmciGetAFValue(); exit: - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); return afvalue; } EXPORT_SYMBOL(VMCISock_GetAFValue); @@ -560,7 +558,7 @@ VMCISock_GetLocalCID(void) { int cid; - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); /* * Kernel clients are required to explicitly register themselves before they @@ -574,7 +572,7 @@ VMCISock_GetLocalCID(void) cid = VMCI_GetContextID(); exit: - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); return cid; } EXPORT_SYMBOL(VMCISock_GetLocalCID); @@ -602,9 +600,9 @@ EXPORT_SYMBOL(VMCISock_GetLocalCID); void VMCISock_KernelRegister(void) { - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); vsockVmciKernClientCount++; - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); } EXPORT_SYMBOL(VMCISock_KernelRegister); @@ -630,10 +628,10 @@ EXPORT_SYMBOL(VMCISock_KernelRegister); void VMCISock_KernelDeregister(void) { - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); vsockVmciKernClientCount--; VSockVmciTestUnregister(); - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); } EXPORT_SYMBOL(VMCISock_KernelDeregister); @@ -689,9 +687,9 @@ VSockVmci_GetAFValue(void) { int afvalue; - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); afvalue = VSockVmciGetAFValue(); - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); return afvalue; } @@ -1297,7 +1295,7 @@ VSockVmciCidChangedCB(VMCIId subId, // IN void *clientData) // IN { int err; - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); 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(®istrationMutex); + compat_mutex_unlock(®istrationMutex); } @@ -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(®istrationMutex); + compat_mutex_lock(®istrationMutex); vsockVmciSocketCount++; - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); sock_init_data(sock, sk); @@ -2910,10 +2908,10 @@ VSockVmciSkDestruct(struct sock *sk) // IN NOTIFYCALL(vsk, socketDestruct, sk); - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); vsockVmciSocketCount--; VSockVmciTestUnregister(); - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); VSOCK_STATS_CTLPKT_DUMP_ALL(); @@ -4944,9 +4942,9 @@ int VSockVmciDevOpen(struct inode *inode, // IN struct file *file) // IN { - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); devOpenCount++; - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); return 0; } @@ -4972,10 +4970,10 @@ int VSockVmciDevRelease(struct inode *inode, // IN struct file *file) // IN { - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); devOpenCount--; VSockVmciTestUnregister(); - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); return 0; } @@ -5142,9 +5140,9 @@ VSockVmciExit(void) { unregister_ioctl32_handlers(); misc_deregister(&vsockVmciDevice); - down(®istrationMutex); + compat_mutex_lock(®istrationMutex); VSockVmciUnregisterAddressFamily(); - up(®istrationMutex); + compat_mutex_unlock(®istrationMutex); VSockVmciUnregisterProto(); }