Lines 32-38
Link Here
|
32 |
#include <linux/poll.h> |
32 |
#include <linux/poll.h> |
33 |
|
33 |
|
34 |
#include <linux/smp.h> |
34 |
#include <linux/smp.h> |
35 |
#include <linux/smp_lock.h> |
|
|
36 |
|
35 |
|
37 |
#include <linux/netdevice.h> |
36 |
#include <linux/netdevice.h> |
38 |
#include <linux/etherdevice.h> |
37 |
#include <linux/etherdevice.h> |
Lines 57-63
Link Here
|
57 |
#include "compat_uaccess.h" |
56 |
#include "compat_uaccess.h" |
58 |
#include "compat_kdev_t.h" |
57 |
#include "compat_kdev_t.h" |
59 |
#include "compat_sched.h" |
58 |
#include "compat_sched.h" |
60 |
#include "compat_semaphore.h" |
59 |
#include "compat_mutex.h" |
61 |
#include "vmnetInt.h" |
60 |
#include "vmnetInt.h" |
62 |
|
61 |
|
63 |
/* |
62 |
/* |
Lines 105-123
Link Here
|
105 |
* use write_lock_irqsave() to gain write access. |
104 |
* use write_lock_irqsave() to gain write access. |
106 |
* |
105 |
* |
107 |
* If you are acquiring this lock for write, and you do |
106 |
* If you are acquiring this lock for write, and you do |
108 |
* not have vnetStructureSemaphore already acquired, |
107 |
* not have vnetStructureMutex already acquired, |
109 |
* it is most certainly a bug. |
108 |
* it is most certainly a bug. |
110 |
*/ |
109 |
*/ |
111 |
static rwlock_t vnetPeerLock = RW_LOCK_UNLOCKED; |
110 |
static DEFINE_RWLOCK(vnetPeerLock); |
112 |
|
111 |
|
113 |
/* |
112 |
/* |
114 |
* All concurrent changes to the network structure are |
113 |
* All concurrent changes to the network structure are |
115 |
* guarded by this semaphore. |
114 |
* guarded by this semaphore. |
116 |
* |
115 |
* |
117 |
* For change to peer field you must own both |
116 |
* For change to peer field you must own both |
118 |
* vnetStructureSemaphore and vnetPeerLock for write. |
117 |
* vnetStructureMutex and vnetPeerLock for write. |
119 |
*/ |
118 |
*/ |
120 |
DECLARE_MUTEX(vnetStructureSemaphore); |
119 |
compat_define_mutex(vnetStructureMutex); |
|
|
120 |
compat_define_mutex(driver_mutex); |
121 |
|
121 |
|
122 |
#if defined(VM_X86_64) && !defined(HAVE_COMPAT_IOCTL) |
122 |
#if defined(VM_X86_64) && !defined(HAVE_COMPAT_IOCTL) |
123 |
/* |
123 |
/* |
Lines 134-140
Link Here
|
134 |
#endif |
134 |
#endif |
135 |
|
135 |
|
136 |
/* |
136 |
/* |
137 |
* List of known ports. Use vnetStructureSemaphore for locking. |
137 |
* List of known ports. Use vnetStructureMutex for locking. |
138 |
*/ |
138 |
*/ |
139 |
|
139 |
|
140 |
static VNetPort *vnetAllPorts = NULL; |
140 |
static VNetPort *vnetAllPorts = NULL; |
Lines 267-277
Link Here
|
267 |
struct file * filp) // IN: |
267 |
struct file * filp) // IN: |
268 |
{ |
268 |
{ |
269 |
int ret = -ENOTTY; |
269 |
int ret = -ENOTTY; |
270 |
lock_kernel(); |
270 |
compat_mutex_lock(&driver_mutex); |
271 |
if (filp && filp->f_op && filp->f_op->ioctl == VNetFileOpIoctl) { |
271 |
if (filp && filp->f_op && filp->f_op->ioctl == VNetFileOpIoctl) { |
272 |
ret = VNetFileOpIoctl(filp->f_dentry->d_inode, filp, iocmd, ioarg); |
272 |
ret = VNetFileOpIoctl(filp->f_dentry->d_inode, filp, iocmd, ioarg); |
273 |
} |
273 |
} |
274 |
unlock_kernel(); |
274 |
compat_mutex_unlock(&driver_mutex); |
275 |
return ret; |
275 |
return ret; |
276 |
} |
276 |
} |
277 |
|
277 |
|
Lines 386-392
Link Here
|
386 |
* VNetAddPortToList -- |
386 |
* VNetAddPortToList -- |
387 |
* |
387 |
* |
388 |
* Add port to list of known ports. |
388 |
* Add port to list of known ports. |
389 |
* Caller must own vnetStructureSemaphore. |
389 |
* Caller must own vnetStructureMutex. |
390 |
* |
390 |
* |
391 |
* Results: |
391 |
* Results: |
392 |
* |
392 |
* |
Lines 412-418
Link Here
|
412 |
* VNetRemovePortFromList -- |
412 |
* VNetRemovePortFromList -- |
413 |
* |
413 |
* |
414 |
* Remove port from list of known ports. |
414 |
* Remove port from list of known ports. |
415 |
* Caller must own vnetStructureSemaphore. |
415 |
* Caller must own vnetStructureMutex. |
416 |
* |
416 |
* |
417 |
* Results: |
417 |
* Results: |
418 |
* |
418 |
* |
Lines 643-659
Link Here
|
643 |
return -EBUSY; |
643 |
return -EBUSY; |
644 |
} |
644 |
} |
645 |
|
645 |
|
646 |
down(&vnetStructureSemaphore); |
646 |
compat_mutex_lock(&vnetStructureMutex); |
647 |
retval = VNetConnect(&port->jack, hubJack); |
647 |
retval = VNetConnect(&port->jack, hubJack); |
648 |
if (retval) { |
648 |
if (retval) { |
649 |
up(&vnetStructureSemaphore); |
649 |
compat_mutex_unlock(&vnetStructureMutex); |
650 |
VNetFree(&port->jack); |
650 |
VNetFree(&port->jack); |
651 |
VNetFree(hubJack); |
651 |
VNetFree(hubJack); |
652 |
return retval; |
652 |
return retval; |
653 |
} |
653 |
} |
654 |
|
654 |
|
655 |
VNetAddPortToList(port); |
655 |
VNetAddPortToList(port); |
656 |
up(&vnetStructureSemaphore); |
656 |
compat_mutex_unlock(&vnetStructureMutex); |
657 |
|
657 |
|
658 |
/* |
658 |
/* |
659 |
* Store away jack in file pointer private field for later use. |
659 |
* Store away jack in file pointer private field for later use. |
Lines 698-707
Link Here
|
698 |
return -EBADF; |
698 |
return -EBADF; |
699 |
} |
699 |
} |
700 |
|
700 |
|
701 |
down(&vnetStructureSemaphore); |
701 |
compat_mutex_lock(&vnetStructureMutex); |
702 |
peer = VNetDisconnect(&port->jack); |
702 |
peer = VNetDisconnect(&port->jack); |
703 |
VNetRemovePortFromList(port); |
703 |
VNetRemovePortFromList(port); |
704 |
up(&vnetStructureSemaphore); |
704 |
compat_mutex_unlock(&vnetStructureMutex); |
705 |
|
705 |
|
706 |
VNetFree(&port->jack); |
706 |
VNetFree(&port->jack); |
707 |
VNetFree(peer); |
707 |
VNetFree(peer); |
Lines 1186-1194
Link Here
|
1186 |
if (filp && filp->f_dentry) { |
1186 |
if (filp && filp->f_dentry) { |
1187 |
inode = filp->f_dentry->d_inode; |
1187 |
inode = filp->f_dentry->d_inode; |
1188 |
} |
1188 |
} |
1189 |
lock_kernel(); |
1189 |
compat_mutex_lock(&driver_mutex); |
1190 |
err = VNetFileOpIoctl(inode, filp, iocmd, ioarg); |
1190 |
err = VNetFileOpIoctl(inode, filp, iocmd, ioarg); |
1191 |
unlock_kernel(); |
1191 |
compat_mutex_unlock(&driver_mutex); |
1192 |
return err; |
1192 |
return err; |
1193 |
} |
1193 |
} |
1194 |
#endif |
1194 |
#endif |
Lines 1248-1254
Link Here
|
1248 |
* old peer if a cycle is detected. |
1248 |
* old peer if a cycle is detected. |
1249 |
*/ |
1249 |
*/ |
1250 |
|
1250 |
|
1251 |
down(&vnetStructureSemaphore); |
1251 |
compat_mutex_lock(&vnetStructureMutex); |
1252 |
|
1252 |
|
1253 |
/* Disconnect from the old peer */ |
1253 |
/* Disconnect from the old peer */ |
1254 |
oldPeer = VNetDisconnect(jack); |
1254 |
oldPeer = VNetDisconnect(jack); |
Lines 1263-1269
Link Here
|
1263 |
|
1263 |
|
1264 |
/* Connect failed, so reconnect back to old peer */ |
1264 |
/* Connect failed, so reconnect back to old peer */ |
1265 |
int retval2 = VNetConnect(jack, oldPeer); |
1265 |
int retval2 = VNetConnect(jack, oldPeer); |
1266 |
up(&vnetStructureSemaphore); |
1266 |
compat_mutex_unlock(&vnetStructureMutex); |
1267 |
|
1267 |
|
1268 |
/* Free the new peer */ |
1268 |
/* Free the new peer */ |
1269 |
VNetFree(newPeer); |
1269 |
VNetFree(newPeer); |
Lines 1285-1291
Link Here
|
1285 |
VNetRemovePortFromList(jackPort); |
1285 |
VNetRemovePortFromList(jackPort); |
1286 |
} |
1286 |
} |
1287 |
|
1287 |
|
1288 |
up(&vnetStructureSemaphore); |
1288 |
compat_mutex_unlock(&vnetStructureMutex); |
1289 |
|
1289 |
|
1290 |
/* Connected to new peer, so dealloc the old peer */ |
1290 |
/* Connected to new peer, so dealloc the old peer */ |
1291 |
if (connectNewToPeerOfJack) { |
1291 |
if (connectNewToPeerOfJack) { |
Lines 1447-1453
Link Here
|
1447 |
* VNetConnect -- |
1447 |
* VNetConnect -- |
1448 |
* |
1448 |
* |
1449 |
* Connect 2 jacks. |
1449 |
* Connect 2 jacks. |
1450 |
* vnetStructureSemaphore must be held. |
1450 |
* vnetStructureMutex must be held. |
1451 |
* |
1451 |
* |
1452 |
* Results: |
1452 |
* Results: |
1453 |
* errno. |
1453 |
* errno. |
Lines 1508-1514
Link Here
|
1508 |
* VNetDisconnect -- |
1508 |
* VNetDisconnect -- |
1509 |
* |
1509 |
* |
1510 |
* Disconnect 2 jacks. |
1510 |
* Disconnect 2 jacks. |
1511 |
* vnetStructureSemaphore must be held. |
1511 |
* vnetStructureMutex must be held. |
1512 |
* |
1512 |
* |
1513 |
* Results: |
1513 |
* Results: |
1514 |
* Return the peer jack (returns NULL on error, or if no peer) |
1514 |
* Return the peer jack (returns NULL on error, or if no peer) |
Lines 1555-1561
Link Here
|
1555 |
* Perform the cycle detect alogorithm for this generation on a |
1555 |
* Perform the cycle detect alogorithm for this generation on a |
1556 |
* specific interface. This could be a bridged interface, host |
1556 |
* specific interface. This could be a bridged interface, host |
1557 |
* interface or both. |
1557 |
* interface or both. |
1558 |
* vnetStructureSemaphore must be held. |
1558 |
* vnetStructureMutex must be held. |
1559 |
* |
1559 |
* |
1560 |
* Results: |
1560 |
* Results: |
1561 |
* TRUE if a cycle was detected, FALSE otherwise. |
1561 |
* TRUE if a cycle was detected, FALSE otherwise. |
Lines 1606-1612
Link Here
|
1606 |
* |
1606 |
* |
1607 |
* Free's the linked list that may have been constructed |
1607 |
* Free's the linked list that may have been constructed |
1608 |
* during a recent run on the cycle detect alogorithm. |
1608 |
* during a recent run on the cycle detect alogorithm. |
1609 |
* vnetStructureSemaphore must be held. |
1609 |
* vnetStructureMutex must be held. |
1610 |
* |
1610 |
* |
1611 |
* Results: |
1611 |
* Results: |
1612 |
* None. |
1612 |
* None. |
Lines 1685-1699
Link Here
|
1685 |
{ |
1685 |
{ |
1686 |
VNetPort *p; |
1686 |
VNetPort *p; |
1687 |
|
1687 |
|
1688 |
down(&vnetStructureSemaphore); |
1688 |
compat_mutex_lock(&vnetStructureMutex); |
1689 |
for (p = vnetAllPorts; p != NULL; p = p->next) { |
1689 |
for (p = vnetAllPorts; p != NULL; p = p->next) { |
1690 |
if (p != port && MAC_EQ(p->paddr, mac)) { |
1690 |
if (p != port && MAC_EQ(p->paddr, mac)) { |
1691 |
up(&vnetStructureSemaphore); |
1691 |
compat_mutex_unlock(&vnetStructureMutex); |
1692 |
return -EBUSY; |
1692 |
return -EBUSY; |
1693 |
} |
1693 |
} |
1694 |
} |
1694 |
} |
1695 |
memcpy(port->paddr, mac, ETH_ALEN); |
1695 |
memcpy(port->paddr, mac, ETH_ALEN); |
1696 |
up(&vnetStructureSemaphore); |
1696 |
compat_mutex_unlock(&vnetStructureMutex); |
1697 |
return 0; |
1697 |
return 0; |
1698 |
} |
1698 |
} |
1699 |
|
1699 |
|