From: VMware, Inc <> Date: Fri, 12 Apr 2013 19:48:49 +0000 (-0700) Subject: VMCI: switch to upstreamed Linux VMCI API for internal users, pt 2 X-Git-Tag: 2013.04.16-1098359~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b1f02e907e9ab01c4a2db6ceeb132bf3a0c2a79d;p=thirdparty%2Fopen-vm-tools.git VMCI: switch to upstreamed Linux VMCI API for internal users, pt 2 Second part of the change to switch to the upstreamed API. This one tweaks the API for Linux only so that it matches exactly the one that is upstreamed. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/modules/linux/shared/vmciKernelAPI1.h b/open-vm-tools/modules/linux/shared/vmciKernelAPI1.h index bf8a00de3..992c642da 100644 --- a/open-vm-tools/modules/linux/shared/vmciKernelAPI1.h +++ b/open-vm-tools/modules/linux/shared/vmciKernelAPI1.h @@ -84,7 +84,14 @@ int vmci_datagram_send(VMCIDatagram *msg); /* VMCI Utility API. */ VMCIId vmci_get_context_id(void); + +#if defined(linux) && !defined(VMKERNEL) +/* Returned value is a bool, 0 for false, 1 for true. */ +int vmci_is_context_owner(VMCIId contextID, uid_t uid); +#else // !linux || VMKERNEL +/* Returned value is a VMCI error code. */ int vmci_is_context_owner(VMCIId contextID, void *hostUser); +#endif // !linux || VMKERNEL uint32 vmci_version(void); int vmci_cid_2_host_vm_id(VMCIId contextID, void *hostVmID, @@ -95,7 +102,10 @@ int vmci_cid_2_host_vm_id(VMCIId contextID, void *hostVmID, typedef void (*VMCI_EventCB)(VMCIId subID, VMCI_EventData *ed, void *clientData); -int vmci_event_subscribe(VMCI_Event event, uint32 flags, +int vmci_event_subscribe(VMCI_Event event, +#if !defined(linux) || defined(VMKERNEL) + uint32 flags, +#endif // !linux || VMKERNEL VMCI_EventCB callback, void *callbackData, VMCIId *subID); int vmci_event_unsubscribe(VMCIId subID); diff --git a/open-vm-tools/modules/linux/vmci/common/vmciContext.c b/open-vm-tools/modules/linux/vmci/common/vmciContext.c index 147098d44..5a698e34e 100644 --- a/open-vm-tools/modules/linux/vmci/common/vmciContext.c +++ b/open-vm-tools/modules/linux/vmci/common/vmciContext.c @@ -2195,7 +2195,8 @@ vmci_cid_2_host_vm_id(VMCIId contextID, // IN * user is the owner of the VM/VMX. * * Results: - * VMCI_SUCCESS if the hostUser is owner, error code otherwise. + * Linux: 1 (true) if hostUser is owner, 0 (false) otherwise. + * Other: VMCI_SUCCESS if the hostUser is owner, error code otherwise. * * Side effects: * None. @@ -2204,6 +2205,29 @@ vmci_cid_2_host_vm_id(VMCIId contextID, // IN */ VMCI_EXPORT_SYMBOL(vmci_is_context_owner) +#if defined(linux) && !defined(VMKERNEL) +int +vmci_is_context_owner(VMCIId contextID, // IN + uid_t uid) // IN +{ + int isOwner = 0; + + if (VMCI_HostPersonalityActive()) { + VMCIContext *context = VMCIContext_Get(contextID); + if (context) { + if (context->validUser) { + if (VMCIHost_CompareUser((VMCIHostUser *)&uid, + &context->user) == VMCI_SUCCESS) { + isOwner = 1; + } + } + VMCIContext_Release(context); + } + } + + return isOwner; +} +#else // !linux || VMKERNEL int vmci_is_context_owner(VMCIId contextID, // IN void *hostUser) // IN @@ -2237,6 +2261,7 @@ vmci_is_context_owner(VMCIId contextID, // IN } return VMCI_ERROR_UNAVAILABLE; } +#endif // !linux || VMKERNEL /* diff --git a/open-vm-tools/modules/linux/vmci/common/vmciDriver.c b/open-vm-tools/modules/linux/vmci/common/vmciDriver.c index 73af8260e..1933019c0 100644 --- a/open-vm-tools/modules/linux/vmci/common/vmciDriver.c +++ b/open-vm-tools/modules/linux/vmci/common/vmciDriver.c @@ -252,7 +252,10 @@ VMCIUtil_Init(void) * We subscribe to the VMCI_EVENT_CTX_ID_UPDATE here so we can update the * internal context id when needed. */ - if (vmci_event_subscribe(VMCI_EVENT_CTX_ID_UPDATE, VMCI_FLAG_EVENT_NONE, + if (vmci_event_subscribe(VMCI_EVENT_CTX_ID_UPDATE, +#if !defined(linux) || defined(VMKERNEL) + VMCI_FLAG_EVENT_NONE, +#endif // !linux || VMKERNEL VMCIUtilCidUpdate, NULL, &ctxUpdateSubID) < VMCI_SUCCESS) { VMCI_WARNING((LGPFX"Failed to subscribe to event (type=%d).\n", diff --git a/open-vm-tools/modules/linux/vmci/common/vmciEvent.c b/open-vm-tools/modules/linux/vmci/common/vmciEvent.c index 750440a3e..0d6a569c0 100644 --- a/open-vm-tools/modules/linux/vmci/common/vmciEvent.c +++ b/open-vm-tools/modules/linux/vmci/common/vmciEvent.c @@ -715,12 +715,17 @@ VMCIEventUnregisterSubscription(VMCIId subID) // IN VMCI_EXPORT_SYMBOL(vmci_event_subscribe) int vmci_event_subscribe(VMCI_Event event, // IN +#if !defined(linux) || defined(VMKERNEL) uint32 flags, // IN +#endif // !linux || VMKERNEL VMCI_EventCB callback, // IN void *callbackData, // IN VMCIId *subscriptionID) // OUT { int retval; +#if defined(linux) && !defined(VMKERNEL) + uint32 flags = VMCI_FLAG_EVENT_NONE; +#endif // linux && !VMKERNEL VMCISubscription *s = NULL; if (subscriptionID == NULL) { diff --git a/open-vm-tools/modules/linux/vmci/linux/vmci_version.h b/open-vm-tools/modules/linux/vmci/linux/vmci_version.h index 1d189b79c..441fb7494 100644 --- a/open-vm-tools/modules/linux/vmci/linux/vmci_version.h +++ b/open-vm-tools/modules/linux/vmci/linux/vmci_version.h @@ -25,8 +25,8 @@ #ifndef _VMCI_VERSION_H_ #define _VMCI_VERSION_H_ -#define VMCI_DRIVER_VERSION 9.5.15.0 -#define VMCI_DRIVER_VERSION_COMMAS 9,5,15,0 -#define VMCI_DRIVER_VERSION_STRING "9.5.15.0" +#define VMCI_DRIVER_VERSION 9.5.16.0 +#define VMCI_DRIVER_VERSION_COMMAS 9,5,16,0 +#define VMCI_DRIVER_VERSION_STRING "9.5.16.0" #endif /* _VMCI_VERSION_H_ */ 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 288be5507..c3a0e4dc5 100644 --- a/open-vm-tools/modules/linux/vsock/linux/af_vsock.c +++ b/open-vm-tools/modules/linux/vsock/linux/af_vsock.c @@ -541,15 +541,7 @@ Bool VSockVmciTrusted(VSockVmciSock *vsock, // IN: Local socket VMCIId peerCid) // IN: Context ID of peer { - int res; - - if (vsock->trusted) { - return TRUE; - } - - res = vmci_is_context_owner(peerCid, &vsock->owner); - - return res == VMCI_SUCCESS; + return vsock->trusted || vmci_is_context_owner(peerCid, vsock->owner); } @@ -1848,7 +1840,6 @@ VSockVmciRecvConnectingServer(struct sock *listener, // IN: the listening socket * specifying the ATTACH_ONLY flag below. */ err = vmci_event_subscribe(VMCI_EVENT_QP_PEER_DETACH, - VMCI_FLAG_EVENT_NONE, VSockVmciPeerDetachCB, pending, &detachSubId); @@ -2196,7 +2187,6 @@ VSockVmciRecvConnectingClientNegotiate(struct sock *sk, // IN: socket * once and add a way to lookup sockets by queue pair handle. */ err = vmci_event_subscribe(VMCI_EVENT_QP_PEER_ATTACH, - VMCI_FLAG_EVENT_NONE, VSockVmciPeerAttachCB, sk, &attachSubId); @@ -2206,7 +2196,6 @@ VSockVmciRecvConnectingClientNegotiate(struct sock *sk, // IN: socket } err = vmci_event_subscribe(VMCI_EVENT_QP_PEER_DETACH, - VMCI_FLAG_EVENT_NONE, VSockVmciPeerDetachCB, sk, &detachSubId); @@ -3284,7 +3273,6 @@ VSockVmciRegisterWithVmci(void) } err = vmci_event_subscribe(VMCI_EVENT_QP_RESUMED, - VMCI_FLAG_EVENT_NONE, VSockVmciQPResumedCB, NULL, &qpResumedSubId); diff --git a/open-vm-tools/modules/linux/vsock/linux/vsock_version.h b/open-vm-tools/modules/linux/vsock/linux/vsock_version.h index 7d2514c95..49b3ba2db 100644 --- a/open-vm-tools/modules/linux/vsock/linux/vsock_version.h +++ b/open-vm-tools/modules/linux/vsock/linux/vsock_version.h @@ -25,8 +25,8 @@ #ifndef _VSOCK_VERSION_H_ #define _VSOCK_VERSION_H_ -#define VSOCK_DRIVER_VERSION 9.5.8.0 -#define VSOCK_DRIVER_VERSION_COMMAS 9,5,8,0 -#define VSOCK_DRIVER_VERSION_STRING "9.5.8.0" +#define VSOCK_DRIVER_VERSION 9.5.9.0 +#define VSOCK_DRIVER_VERSION_COMMAS 9,5,9,0 +#define VSOCK_DRIVER_VERSION_STRING "9.5.9.0" #endif /* _VSOCK_VERSION_H_ */