Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/modules/linux/dkms.conf b/modules/linux/dkms.conf
index 3ed77f9..263921f 100644
--- a/modules/linux/dkms.conf
+++ b/modules/linux/dkms.conf
@@ -1,39 +1,35 @@
PACKAGE_NAME=open-vm-tools
PACKAGE_VERSION=2013.04.16
MAKE_CMD_TMPL="make VM_UNAME=\$kernelver \
- MODULEBUILDDIR=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build"
+ MODULEBUILDDIR=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build \
+ CC_WARNINGS=-Wno-unused-local-typedefs"
# The vsock module depends on symbols exported by the vmci module, so it
# needs to be built afterwards; the MODULEBUILDDIR variable tells the makefiles
# where to store / retrive those symbol files.
MAKE[0]="$MAKE_CMD_TMPL -C vmblock; \
- $MAKE_CMD_TMPL -C vmci; \
$MAKE_CMD_TMPL -C vmhgfs; \
$MAKE_CMD_TMPL -C vmsync; \
$MAKE_CMD_TMPL -C vmxnet; \
$MAKE_CMD_TMPL -C vsock"
CLEAN[0]="$MAKE_CMD_TMPL -C vmblock clean; \
- $MAKE_CMD_TMPL -C vmci clean; \
$MAKE_CMD_TMPL -C vmhgfs clean; \
- $MAKE_CMD_TMPL -C vmsync clean"; \
+ $MAKE_CMD_TMPL -C vmsync clean; \
$MAKE_CMD_TMPL -C vmxnet clean; \
- $MAKE_CMD_TMPL -C vsock clean
+ $MAKE_CMD_TMPL -C vsock clean"
BUILT_MODULE_NAME[0]="vmblock"
-BUILT_MODULE_NAME[1]="vmci"
-BUILT_MODULE_NAME[2]="vmhgfs"
-BUILT_MODULE_NAME[3]="vmsync"
-BUILT_MODULE_NAME[4]="vmxnet"
-BUILT_MODULE_NAME[5]="vsock"
+BUILT_MODULE_NAME[1]="vmhgfs"
+BUILT_MODULE_NAME[2]="vmsync"
+BUILT_MODULE_NAME[3]="vmxnet"
+BUILT_MODULE_NAME[4]="vsock"
BUILT_MODULE_LOCATION[0]="vmblock/"
-BUILT_MODULE_LOCATION[1]="vmci/"
-BUILT_MODULE_LOCATION[2]="vmhgfs/"
-BUILT_MODULE_LOCATION[3]="vmsync/"
-BUILT_MODULE_LOCATION[4]="vmxnet/"
-BUILT_MODULE_LOCATION[5]="vsock/"
+BUILT_MODULE_LOCATION[1]="vmhgfs/"
+BUILT_MODULE_LOCATION[2]="vmsync/"
+BUILT_MODULE_LOCATION[3]="vmxnet/"
+BUILT_MODULE_LOCATION[4]="vsock/"
DEST_MODULE_LOCATION[0]="/kernel/fs/vmblock"
-DEST_MODULE_LOCATION[1]="/kernel/drivers/misc"
-DEST_MODULE_LOCATION[2]="/kernel/fs/vmhgfs"
-DEST_MODULE_LOCATION[3]="/kernel/drivers/misc"
-DEST_MODULE_LOCATION[4]="/kernel/drivers/net"
-DEST_MODULE_LOCATION[5]="/kernel/net/vsock"
+DEST_MODULE_LOCATION[1]="/kernel/fs/vmhgfs"
+DEST_MODULE_LOCATION[2]="/kernel/drivers/misc"
+DEST_MODULE_LOCATION[3]="/kernel/drivers/net"
+DEST_MODULE_LOCATION[4]="/kernel/net/vsock"
AUTOINSTALL="YES"
diff --git a/modules/linux/vmblock/linux/control.c b/modules/linux/vmblock/linux/control.c
index 79716bd..ee64cdc 100644
--- a/modules/linux/vmblock/linux/control.c
+++ b/modules/linux/vmblock/linux/control.c
@@ -208,9 +208,10 @@ SetupProcDevice(void)
VMBlockSetProcEntryOwner(controlProcMountpoint);
/* Create /proc/fs/vmblock/dev */
- controlProcEntry = create_proc_entry(VMBLOCK_CONTROL_DEVNAME,
- VMBLOCK_CONTROL_MODE,
- controlProcDirEntry);
+ controlProcEntry = proc_create(VMBLOCK_CONTROL_DEVNAME,
+ VMBLOCK_CONTROL_MODE,
+ controlProcDirEntry,
+ &ControlFileOps);
if (!controlProcEntry) {
Warning("SetupProcDevice: could not create " VMBLOCK_DEVICE "\n");
remove_proc_entry(VMBLOCK_CONTROL_MOUNTPOINT, controlProcDirEntry);
@@ -218,7 +219,6 @@ SetupProcDevice(void)
return -EINVAL;
}
- controlProcEntry->proc_fops = &ControlFileOps;
return 0;
}
@@ -278,7 +278,7 @@ ExecuteBlockOp(const char __user *buf, // IN: buffer with name
int (*blockOp)(const char *filename, // IN: block operation
const os_blocker_id_t blocker))
{
- char *name;
+ struct filename *name;
int i;
int retval;
@@ -287,13 +287,13 @@ ExecuteBlockOp(const char __user *buf, // IN: buffer with name
return PTR_ERR(name);
}
- for (i = strlen(name) - 1; i >= 0 && name[i] == '/'; i--) {
- name[i] = '\0';
+ for (i = strlen(name->name) - 1; i >= 0 && name->name[i] == '/'; i--) {
+ ((char *)name->name)[i] = '\0';
}
- retval = i < 0 ? -EINVAL : blockOp(name, blocker);
+ retval = i < 0 ? -EINVAL : blockOp(name->name, blocker);
- putname(name);
+ __putname(name);
return retval;
}
diff --git a/modules/linux/vmblock/linux/dentry.c b/modules/linux/vmblock/linux/dentry.c
index 05ea95a..d93b2f0 100644
--- a/modules/linux/vmblock/linux/dentry.c
+++ b/modules/linux/vmblock/linux/dentry.c
@@ -31,8 +31,7 @@
#include "filesystem.h"
#include "block.h"
-
-static int DentryOpRevalidate(struct dentry *dentry, struct nameidata *nd);
+static int DentryOpRevalidate(struct dentry *dentry, unsigned int flags);
struct dentry_operations LinkDentryOps = {
.d_revalidate = DentryOpRevalidate,
@@ -60,7 +59,7 @@ struct dentry_operations LinkDentryOps = {
static int
DentryOpRevalidate(struct dentry *dentry, // IN: dentry revalidating
- struct nameidata *nd) // IN: lookup flags & intent
+ unsigned int flags) // IN: lookup flags
{
VMBlockInodeInfo *iinfo;
struct nameidata actualNd;
@@ -101,7 +100,7 @@ DentryOpRevalidate(struct dentry *dentry, // IN: dentry revalidating
if (actualDentry &&
actualDentry->d_op &&
actualDentry->d_op->d_revalidate) {
- return actualDentry->d_op->d_revalidate(actualDentry, nd);
+ return actualDentry->d_op->d_revalidate(actualDentry, flags);
}
if (compat_path_lookup(iinfo->name, 0, &actualNd)) {
diff --git a/modules/linux/vmblock/linux/inode.c b/modules/linux/vmblock/linux/inode.c
index 098c94c..ddd37f3 100644
--- a/modules/linux/vmblock/linux/inode.c
+++ b/modules/linux/vmblock/linux/inode.c
@@ -36,7 +36,7 @@
/* Inode operations */
static struct dentry *InodeOpLookup(struct inode *dir,
- struct dentry *dentry, struct nameidata *nd);
+ struct dentry *dentry, unsigned int flags);
static int InodeOpReadlink(struct dentry *dentry, char __user *buffer, int buflen);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
static void *InodeOpFollowlink(struct dentry *dentry, struct nameidata *nd);
@@ -75,7 +75,7 @@ static struct inode_operations LinkInodeOps = {
static struct dentry *
InodeOpLookup(struct inode *dir, // IN: parent directory's inode
struct dentry *dentry, // IN: dentry to lookup
- struct nameidata *nd) // IN: lookup intent and information
+ unsigned int flags) // IN: lookup flags
{
char *filename;
struct inode *inode;
diff --git a/modules/linux/vmci/COPYING b/modules/linux/vmci/COPYING
deleted file mode 100644
index d511905..0000000
--- a/modules/linux/vmci/COPYING
+++ /dev/null
@@ -1,339 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Lesser General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License.
diff --git a/modules/linux/vmci/Makefile b/modules/linux/vmci/Makefile
deleted file mode 100644
index a8cc0b7..0000000
--- a/modules/linux/vmci/Makefile
+++ /dev/null
@@ -1,171 +0,0 @@
-#!/usr/bin/make -f
-##########################################################
-# Copyright (C) 1998 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation version 2 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-##########################################################
-
-####
-#### VMware kernel module Makefile to be distributed externally
-####
-
-####
-#### SRCROOT _must_ be a relative path.
-####
-SRCROOT = .
-
-#
-# open-vm-tools doesn't replicate shared source files for different modules;
-# instead, files are kept in shared locations. So define a few useful macros
-# to be able to handle both cases cleanly.
-#
-INCLUDE :=
-ifdef OVT_SOURCE_DIR
-AUTOCONF_DIR := $(OVT_SOURCE_DIR)/modules/linux/shared/autoconf
-VMLIB_PATH = $(OVT_SOURCE_DIR)/lib/$(1)
-INCLUDE += -I$(OVT_SOURCE_DIR)/modules/linux/shared
-INCLUDE += -I$(OVT_SOURCE_DIR)/lib/include
-else
-AUTOCONF_DIR := $(SRCROOT)/shared/autoconf
-INCLUDE += -I$(SRCROOT)/shared
-endif
-
-
-VM_UNAME = $(shell uname -r)
-
-# Header directory for the running kernel
-ifdef LINUXINCLUDE
-HEADER_DIR = $(LINUXINCLUDE)
-else
-HEADER_DIR = /lib/modules/$(VM_UNAME)/build/include
-endif
-
-BUILD_DIR = $(HEADER_DIR)/..
-
-DRIVER := vmci
-PRODUCT := tools-source
-
-# Grep program
-GREP = /bin/grep
-
-vm_check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
- > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
-vm_check_file = $(shell if test -f $(1); then echo "yes"; else echo "no"; fi)
-
-ifndef VM_KBUILD
-VM_KBUILD := no
-ifeq ($(call vm_check_file,$(BUILD_DIR)/Makefile), yes)
-ifneq ($(call vm_check_file,$(BUILD_DIR)/Rules.make), yes)
-VM_KBUILD := 26
-endif
-endif
-export VM_KBUILD
-endif
-
-ifndef VM_KBUILD_SHOWN
-ifeq ($(VM_KBUILD), no)
-VM_DUMMY := $(shell echo >&2 "Using standalone build system.")
-else
-ifeq ($(VM_KBUILD), 24)
-VM_DUMMY := $(shell echo >&2 "Using 2.4.x kernel build system.")
-else
-VM_DUMMY := $(shell echo >&2 "Using 2.6.x kernel build system.")
-endif
-endif
-VM_KBUILD_SHOWN := yes
-export VM_KBUILD_SHOWN
-endif
-
-ifneq ($(VM_KBUILD), no)
-
-VMCCVER := $(shell $(CC) -dumpversion)
-
-# If there is no version defined, we are in toplevel pass, not yet in kernel makefiles...
-ifeq ($(VERSION),)
-
-ifeq ($(VM_KBUILD), 24)
-DRIVER_KO := $(DRIVER).o
-else
-DRIVER_KO := $(DRIVER).ko
-endif
-
-.PHONY: $(DRIVER_KO)
-
-auto-build: $(DRIVER_KO)
- cp -f $< $(SRCROOT)/../$(DRIVER).o
-
-# $(DRIVER_KO) is a phony target, so compare file times explicitly
-$(DRIVER): $(DRIVER_KO)
- if [ $< -nt $@ ] || [ ! -e $@ ] ; then cp -f $< $@; fi
-
-# Pass gcc version down the chain, so we can detect if kernel attempts to use unapproved compiler
-VM_CCVER := $(VMCCVER)
-export VM_CCVER
-VM_CC := $(CC)
-export VM_CC
-
-MAKEOVERRIDES := $(filter-out CC=%,$(MAKEOVERRIDES))
-
-#
-# Define a setup target that gets built before the actual driver.
-# This target may not be used at all, but if it is then it will be defined
-# in Makefile.kernel
-#
-prebuild:: ;
-postbuild:: ;
-
-$(DRIVER_KO): prebuild
- $(MAKE) -C $(BUILD_DIR) SUBDIRS=$$PWD SRCROOT=$$PWD/$(SRCROOT) \
- MODULEBUILDDIR=$(MODULEBUILDDIR) modules
- $(MAKE) -C $$PWD SRCROOT=$$PWD/$(SRCROOT) \
- MODULEBUILDDIR=$(MODULEBUILDDIR) postbuild
-endif
-
-vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
- $(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) $(LINUXINCLUDE) \
- $(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
- -DKBUILD_BASENAME=\"$(DRIVER)\" \
- -Werror -S -o /dev/null -xc $(1) \
- > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi)
-
-CC_WARNINGS := -Wall -Wstrict-prototypes
-CC_OPTS := $(GLOBAL_DEFS) $(CC_WARNINGS) -DVMW_USING_KBUILD
-ifdef VMX86_DEVEL
-CC_OPTS += -DVMX86_DEVEL
-endif
-ifdef VMX86_DEBUG
-CC_OPTS += -DVMX86_DEBUG
-endif
-
-include $(SRCROOT)/Makefile.kernel
-
-ifdef TOPDIR
-ifeq ($(VM_KBUILD), 24)
-
-O_TARGET := $(DRIVER).o
-
-obj-y := $($(DRIVER)-y)
-
-include $(TOPDIR)/Rules.make
-endif
-endif
-
-else
-
-include $(SRCROOT)/Makefile.normal
-
-endif
-
-#.SILENT:
diff --git a/modules/linux/vmci/Makefile.kernel b/modules/linux/vmci/Makefile.kernel
deleted file mode 100644
index ba343ee..0000000
--- a/modules/linux/vmci/Makefile.kernel
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/usr/bin/make -f
-##########################################################
-# Copyright (C) 2007 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation version 2 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-##########################################################
-
-CC_OPTS += -DVMCI
-
-INCLUDE += -I$(SRCROOT)/shared -I$(SRCROOT)/common -I$(SRCROOT)/linux
-
-EXTRA_CFLAGS := $(CC_OPTS) $(INCLUDE)
-
-obj-m += $(DRIVER).o
-
-$(DRIVER)-y := $(subst $(SRCROOT)/, , $(patsubst %.c, %.o, \
- $(wildcard $(SRCROOT)/linux/*.c $(SRCROOT)/common/*.c)))
-
-#
-# In open-vm-tools, need to compile the common sources from the shared directory.
-#
-DRIVERLOG := driverLog.o
-$(DRIVER)-y += $(DRIVERLOG)
-
-VMCI_PATH := $(shell cd $(SRCROOT) && pwd)
-ifdef OVT_SOURCE_DIR
-DRIVERLOG_PATH := $(OVT_SOURCE_DIR)/modules/linux/shared
-else
-DRIVERLOG_PATH := $(VMCI_PATH)/shared
-endif
-
-$(addprefix $(VMCI_PATH)/,$(DRIVERLOG)): $(VMCI_PATH)/%.o: $(DRIVERLOG_PATH)/%.c
- $(Q)$(rule_cc_o_c)
-
-clean:
- rm -rf $(wildcard $(DRIVER).mod.c $(DRIVER).ko .tmp_versions \
- Module.symvers Modules.symvers Module.markers modules.order \
- $(foreach dir,linux/ common/ \
- ./,$(addprefix $(dir),.*.cmd .*.o.flags *.o)))
-ifneq ($(MODULEBUILDDIR),)
- rm -f $(MODULEBUILDDIR)/VMwareVMCIModule.symvers
-endif
-
-#
-# If this build generated a Module.symvers, copy it to a public place where
-# the VMCI Sockets build will be able to find it.
-#
-postbuild::
-ifeq ($(call vm_check_file,$(SRCROOT)/Module.symvers), yes)
-ifneq ($(MODULEBUILDDIR),)
- cp -f $(SRCROOT)/Module.symvers $(MODULEBUILDDIR)/VMwareVMCIModule.symvers
-endif
-endif
diff --git a/modules/linux/vmci/Makefile.normal b/modules/linux/vmci/Makefile.normal
deleted file mode 100644
index dda1844..0000000
--- a/modules/linux/vmci/Makefile.normal
+++ /dev/null
@@ -1,146 +0,0 @@
-#!/usr/bin/make -f
-##########################################################
-# Copyright (C) 2007 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation version 2 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
-##########################################################
-
-vm_check_build = $(shell if $(CC) $(CC_OPTS) $(INCLUDE) -Werror -S -o /dev/null -xc $(1) \
- > /dev/null 2>&1; then echo "$(2)"; else echo "$(3)"; fi)
-
-####
-#### DESTDIR is where the module, object files, and dependencies are built
-####
-DESTDIR := driver-$(VM_UNAME)
-
-####
-#### DRIVERNAME should be untouched unless you have a good reason to change
-#### it. The form below is how the scripts expect it.
-####
-DRIVERNAME := $(DRIVER)-xxx-$(VM_UNAME)
-
-ifneq (,$(filter x86_64%, $(shell $(CC) -dumpmachine)))
-MACHINE := x86_64
-else
-MACHINE := x386
-endif
-
-ifdef QUIET
-ECHO := @true
-else
-ECHO := @echo
-endif
-
-####
-#### You must compile with at least -O level of optimization
-#### or the module won't load.
-#### If desparate, I think that bringing in <linux/bitops.h> might
-#### suffice.
-####
-CC_WARNINGS := -Wall -Wstrict-prototypes
-# Don't use -pipe or egcs-2.91.66 (shipped with RedHat) will die
-CC_KFLAGS := -D__KERNEL__ -fno-strength-reduce -fno-omit-frame-pointer \
- -fno-common -DKBUILD_MODNAME=\"$(DRIVER)\"
-CC_KFLAGS += $(call vm_check_gcc,-falign-loops=2 -falign-jumps=2 -falign-functions=2, \
- -malign-loops=2 -malign-jumps=2 -malign-functions=2)
-CC_KFLAGS += $(call vm_check_gcc,-fno-strict-aliasing,)
-ifeq ($(MACHINE),x86_64)
-CC_KFLAGS += -mno-red-zone -mcmodel=kernel
-else
-# Gcc 3.0 deprecates -m486 --hpreg
-CC_KFLAGS += -DCPU=586 $(call check_gcc,-march=i586,-m486)
-endif
-
-CC_OPTS := -O2 -DMODULE -DVMCI $(GLOBAL_DEFS) $(CC_KFLAGS) $(CC_WARNINGS)
-
-INCLUDE := -I$(SRCROOT)/shared -I$(SRCROOT)/common -I$(SRCROOT)/linux \
- -I$(HEADER_DIR)
-
-INCLUDE += $(shell $(CC) $(INCLUDE) -E $(SRCROOT)/shared/autoconf/geninclude.c \
- | sed -n -e 's!^APATH!-I$(HEADER_DIR)/asm!p')
-
-ifdef OVT_SOURCE_PATH
-DRIVERLOGPATH := $(OVT_SOURCE_DIR)/modules/linux/shared
-else
-DRIVERLOGPATH := $(SRCROOT)/shared
-endif
-
-C_TARGETS_LINUX := driver.o vmciKernelIf.o
-C_TARGETS_COMMON := vmciContext.o vmciDatagram.o vmciDriver.o \
- vmciHashtable.o vmciResource.o \
- vmciQueuePair.o vmciEvent.o vmciRoute.o
-
-C_TARGETS_LINUX_D := ${C_TARGETS_LINUX:.o=.d}
-C_TARGETS_COMMON_D := ${C_TARGETS_COMMON:.o=.d}
-C_TARGETS := $(C_TARGETS_LINUX) $(C_TARGETS_COMMON) driverLog.o
-
-####
-#### Make Targets are beneath here.
-####
-
-driver: setup deps
- $(MAKE) -C $(DESTDIR) -f ../Makefile SRCROOT=../$(SRCROOT) $(DRIVER).o \
- INCLUDE_DEPS=1
-
-setup:
- @if [ -d $(DESTDIR) ] ; then true ; else mkdir $(DESTDIR); chmod 755 $(DESTDIR) ; fi
-
-$(DRIVER) $(DRIVER).o: $(DRIVERNAME)
- cp -f $< $@
-
-$(DRIVERNAME): $(C_TARGETS)
- $(ECHO) "Building $(DRIVERNAME)"
- ld -r -o $(DRIVERNAME) $(C_TARGETS)
-
-auto-build:
- $(MAKE) driver QUIET=1
- cp -f $(DESTDIR)/$(DRIVERNAME) $(SRCROOT)/../$(DRIVER).o
-
-$(C_TARGETS_LINUX): %.o: $(SRCROOT)/linux/%.c
- $(ECHO) "Compiling linux/$(<F)"
- $(CC) $(CC_OPTS) $(INCLUDE) -c $<
-
-$(C_TARGETS_COMMON): %.o: $(SRCROOT)/common/%.c
- $(ECHO) "Compiling common/$(<F)"
- $(CC) $(CC_OPTS) $(INCLUDE) -c $<
-
-driverLog.o: $(DRIVERLOGPATH)/driverLog.c
- $(CC) $(CC_OPTS) $(INCLUDE) -c $<
-
-clean:
- rm -rf $(DESTDIR)/
-
-$(C_TARGETS_COMMON_D): %.d: $(SRCROOT)/common/%.c
- $(ECHO) "Dependencies for $(<F)"
- $(CC) -MM $(CC_OPTS) $(INCLUDE) $< > $@
-
-$(C_TARGETS_LINUX_D): %.d: $(SRCROOT)/linux/%.c
- $(ECHO) "Dependencies for $(<F)"
- $(CC) -MM $(CC_OPTS) $(INCLUDE) $< > $@
-
-driverLog.d: $(DRIVERLOGPATH)/driverLog.c
- $(ECHO) "Dependencies for $(<F)"
- $(CC) -MM $(CC_OPTS) $(INCLUDE) $< > $@
-
-deps: setup
- $(MAKE) -C $(DESTDIR) -f ../Makefile SRCROOT=../$(SRCROOT) driver_deps
-
-driver_deps: ${C_TARGETS:.o=.d}
-
-ifdef INCLUDE_DEPS
-include ${C_TARGETS:.o=.d}
-endif
-
-.SILENT:
diff --git a/modules/linux/vmci/common/vmciCommonInt.h b/modules/linux/vmci/common/vmciCommonInt.h
deleted file mode 100644
index 8af33b4..0000000
--- a/modules/linux/vmci/common/vmciCommonInt.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*********************************************************
- * Copyright (C) 2006-2012 VMware, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2 and no later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *********************************************************/
-
-/*
- * vmciCommonInt.h --
- *
- * Struct definitions for VMCI internal common code.
- */
-
-#ifndef _VMCI_COMMONINT_H_
-#define _VMCI_COMMONINT_H_
-
-#define INCLUDE_ALLOW_MODULE
-#define INCLUDE_ALLOW_VMCORE
-#define INCLUDE_ALLOW_VMKERNEL
-#include "includeCheck.h"
-
-#include "vm_atomic.h"
-#include "vmci_defs.h"
-#include "vmci_call_defs.h"
-#include "vmci_infrastructure.h"
-#include "vmci_handle_array.h"
-#include "vmci_kernel_if.h"
-
-/*
- * The DatagramQueueEntry is a queue header for the in-kernel VMCI
- * datagram queues. It is allocated in non-paged memory, as the
- * content is accessed while holding a spinlock. The pending datagram
- * itself may be allocated from paged memory. We shadow the size of
- * the datagram in the non-paged queue entry as this size is used
- * while holding the same spinlock as above.
- */
-
-typedef struct DatagramQueueEntry {
- VMCIListItem listItem; /* For queuing. */
- size_t dgSize; /* Size of datagram. */
- VMCIDatagram *dg; /* Pending datagram. */
-} DatagramQueueEntry;
-
-
-/*
- * The VMCIFilterState captures the state of all VMCI filters in one
- * direction. The ranges array contains all filter list in a single
- * memory chunk, and the filter list pointers in the VMCIProtoFilters
- * point into the ranges array.
- */
-
-typedef struct VMCIFilterState {
- VMCIProtoFilters filters;
- VMCIIdRange *ranges;
- size_t rangesSize;
-} VMCIFilterState;
-
-
-struct VMCIContext {
- VMCIListItem listItem; /* For global VMCI list. */
- VMCIId cid;
- Atomic_uint32 refCount;
- VMCIList datagramQueue; /* Head of per VM queue. */
- uint32 pendingDatagrams;
- size_t datagramQueueSize;/* Size of datagram queue in bytes. */
- int userVersion; /*
- * Version of the code that created
- * this context; e.g., VMX.
- */
- VMCILock lock; /*
- * Locks datagramQueue, inFilters,
- * doorbellArray, pendingDoorbellArray
- * and notifierArray.
- */
- VMCIHandleArray *queuePairArray; /*
- * QueuePairs attached to. The array of
- * handles for queue pairs is accessed
- * from the code for QP API, and there
- * it is protected by the QP lock. It
- * is also accessed from the context
- * clean up path, which does not
- * require a lock. VMCILock is not
- * used to protect the QP array.
- */
- VMCIHandleArray *doorbellArray; /* Doorbells created by context. */
- VMCIHandleArray *pendingDoorbellArray; /* Doorbells pending for context. */
- VMCIHandleArray *notifierArray; /* Contexts current context is subscribing to. */
- VMCIHost hostContext;
- VMCIPrivilegeFlags privFlags;
- VMCIHostUser user;
- Bool validUser;
-#ifdef VMKERNEL
- Bool isQuiesced; /* Whether current VM is quiesced */
- VMCIId migrateCid; /* The migrate cid if it is migrating */
- VMCIMutex guestMemMutex; /*
- * Coordinates guest memory
- * registration/release during FSR.
- */
- VMCIGuestMemID curGuestMemID; /* ID of current registered guest mem */
- VMCIFilterState *inFilters; /* Ingoing filters for VMCI traffic. */
-#endif
-#ifndef VMX86_SERVER
- Bool *notify; /* Notify flag pointer - hosted only. */
-# ifdef __linux__
- struct page *notifyPage; /* Page backing the notify UVA. */
-# endif
-#endif
-};
-
-
-/*
- *------------------------------------------------------------------------------
- *
- * VMCIDenyInteraction --
- *
- * Utilility function that checks whether two entities are allowed
- * to interact. If one of them is restricted, the other one must
- * be trusted.
- *
- * Result:
- * TRUE if the two entities are not allowed to interact. FALSE otherwise.
- *
- * Side effects:
- * None.
- *
- *------------------------------------------------------------------------------
- */
-
-static INLINE Bool
-VMCIDenyInteraction(VMCIPrivilegeFlags partOne, // IN
- VMCIPrivilegeFlags partTwo) // IN
-{
- return (((partOne & VMCI_PRIVILEGE_FLAG_RESTRICTED) &&
- !(partTwo & VMCI_PRIVILEGE_FLAG_TRUSTED)) ||
- ((partTwo & VMCI_PRIVILEGE_FLAG_RESTRICTED) &&
- !(partOne & VMCI_PRIVILEGE_FLAG_TRUSTED)));
-}
-
-#endif /* _VMCI_COMMONINT_H_ */
diff --git a/modules/linux/vmci/common/vmciContext.c b/modules/linux/vmci/common/vmciContext.c
deleted file mode 100644
index 5a698e3..0000000
--- a/modules/linux/vmci/common/vmciContext.c
+++ /dev/null
@@ -1,2716 +0,0 @@
-/*********************************************************
- * Copyright (C) 2006-2012 VMware, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2 and no later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- *********************************************************/
-
-/*
- * vmciContext.c --
- *
- * Platform independent routines for VMCI calls.
- */
-
-#include "vmci_kernel_if.h"
-#include "vm_assert.h"
-#include "vmci_defs.h"
-#include "vmci_infrastructure.h"
-#include "vmciCommonInt.h"
-#include "vmciContext.h"
-#include "vmciDatagram.h"
-#include "vmciDoorbell.h"
-#include "vmciDriver.h"
-#include "vmciEvent.h"
-#include "vmciKernelAPI.h"
-#include "vmciQueuePair.h"
-#if defined(VMKERNEL)
-# include "vmciVmkInt.h"
-# include "vm_libc.h"
-# include "helper_ext.h"
-#endif
-
-#define LGPFX "VMCIContext: "
-
-static void VMCIContextFreeContext(VMCIContext *context);
-static Bool VMCIContextExists(VMCIId cid);
-static int VMCIContextFireNotification(VMCIId contextID,
- VMCIPrivilegeFlags privFlags);
-#if defined(VMKERNEL)
-static void VMCIContextReleaseGuestMemLocked(VMCIContext *context,
- VMCIGuestMemID gid);
-static void VMCIContextInFilterCleanup(VMCIContext *context);
-#endif
-
-/*
- * List of current VMCI contexts.
- */
-
-static struct {
- VMCIList head;
- VMCILock lock;
- VMCILock firingLock;
-} contextList;
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContextSignalNotify --
- *
- * Sets the notify flag to TRUE. Assumes that the context lock is
- * held.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static INLINE void
-VMCIContextSignalNotify(VMCIContext *context) // IN:
-{
-#ifndef VMX86_SERVER
- if (context->notify) {
- *context->notify = TRUE;
- }
-#endif
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContextClearNotify --
- *
- * Sets the notify flag to FALSE. Assumes that the context lock is
- * held.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static INLINE void
-VMCIContextClearNotify(VMCIContext *context) // IN:
-{
-#ifndef VMX86_SERVER
- if (context->notify) {
- *context->notify = FALSE;
- }
-#endif
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContextClearNotifyAndCall --
- *
- * If nothing requires the attention of the guest, clears both
- * notify flag and call.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static INLINE void
-VMCIContextClearNotifyAndCall(VMCIContext *context) // IN:
-{
- if (context->pendingDatagrams == 0 &&
- VMCIHandleArray_GetSize(context->pendingDoorbellArray) == 0) {
- VMCIHost_ClearCall(&context->hostContext);
- VMCIContextClearNotify(context);
- }
-}
-
-
-#ifndef VMX86_SERVER
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_CheckAndSignalNotify --
- *
- * Sets the context's notify flag iff datagrams are pending for this
- * context. Called from VMCISetupNotify().
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_CheckAndSignalNotify(VMCIContext *context) // IN:
-{
- VMCILockFlags flags;
-
- ASSERT(context);
- VMCI_GrabLock(&context->lock, &flags);
- if (context->pendingDatagrams) {
- VMCIContextSignalNotify(context);
- }
- VMCI_ReleaseLock(&context->lock, flags);
-}
-#endif
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_Init --
- *
- * Initializes the VMCI context module.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_Init(void)
-{
- int err;
-
- VMCIList_Init(&contextList.head);
-
- err = VMCI_InitLock(&contextList.lock, "VMCIContextListLock",
- VMCI_LOCK_RANK_CONTEXTLIST);
- if (err < VMCI_SUCCESS) {
- return err;
- }
-
- err = VMCI_InitLock(&contextList.firingLock, "VMCIContextFiringLock",
- VMCI_LOCK_RANK_CONTEXTFIRE);
- if (err < VMCI_SUCCESS) {
- VMCI_CleanupLock(&contextList.lock);
- }
-
- return err;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_Exit --
- *
- * Cleans up the contexts module.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_Exit(void)
-{
- VMCI_CleanupLock(&contextList.firingLock);
- VMCI_CleanupLock(&contextList.lock);
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_InitContext --
- *
- * Allocates and initializes a VMCI context.
- *
- * Results:
- * Returns 0 on success, appropriate error code otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_InitContext(VMCIId cid, // IN
- VMCIPrivilegeFlags privFlags, // IN
- uintptr_t eventHnd, // IN
- int userVersion, // IN: User's vers no.
- VMCIHostUser *user, // IN
- VMCIContext **outContext) // OUT
-{
- VMCILockFlags flags;
- VMCIContext *context;
- int result;
-
- if (privFlags & ~VMCI_PRIVILEGE_ALL_FLAGS) {
- VMCI_DEBUG_LOG(4, (LGPFX"Invalid flag (flags=0x%x) for VMCI context.\n",
- privFlags));
- return VMCI_ERROR_INVALID_ARGS;
- }
-
- if (userVersion == 0) {
- return VMCI_ERROR_INVALID_ARGS;
- }
-
- context = VMCI_AllocKernelMem(sizeof *context, VMCI_MEMORY_NONPAGED);
- if (context == NULL) {
- VMCI_WARNING((LGPFX"Failed to allocate memory for VMCI context.\n"));
- return VMCI_ERROR_NO_MEM;
- }
- memset(context, 0, sizeof *context);
-
- VMCIList_InitEntry(&context->listItem);
- VMCIList_Init(&context->datagramQueue);
-
- context->userVersion = userVersion;
-
- context->queuePairArray = VMCIHandleArray_Create(0);
- if (!context->queuePairArray) {
- result = VMCI_ERROR_NO_MEM;
- goto error;
- }
-
- context->doorbellArray = VMCIHandleArray_Create(0);
- if (!context->doorbellArray) {
- result = VMCI_ERROR_NO_MEM;
- goto error;
- }
-
- context->pendingDoorbellArray = VMCIHandleArray_Create(0);
- if (!context->pendingDoorbellArray) {
- result = VMCI_ERROR_NO_MEM;
- goto error;
- }
-
- context->notifierArray = VMCIHandleArray_Create(0);
- if (context->notifierArray == NULL) {
- result = VMCI_ERROR_NO_MEM;
- goto error;
- }
-
- result = VMCI_InitLock(&context->lock, "VMCIContextLock",
- VMCI_LOCK_RANK_CONTEXT);
- if (result < VMCI_SUCCESS) {
- goto error;
- }
- Atomic_Write(&context->refCount, 1);
-
-#if defined(VMKERNEL)
- result = VMCIMutex_Init(&context->guestMemMutex, "VMCIGuestMem",
- VMCI_SEMA_RANK_GUESTMEM);
- if (result < VMCI_SUCCESS) {
- VMCI_CleanupLock(&context->lock);
- goto error;
- }
- context->curGuestMemID = INVALID_VMCI_GUEST_MEM_ID;
-
- context->inFilters = NULL;
-#endif
-
- /* Inititialize host-specific VMCI context. */
- VMCIHost_InitContext(&context->hostContext, eventHnd);
-
- context->privFlags = privFlags;
-
- /*
- * If we collide with an existing context we generate a new and use it
- * instead. The VMX will determine if regeneration is okay. Since there
- * isn't 4B - 16 VMs running on a given host, the below loop will terminate.
- */
- VMCI_GrabLock(&contextList.lock, &flags);
- ASSERT(cid != VMCI_INVALID_ID);
- while (VMCIContextExists(cid)) {
-
- /*
- * If the cid is below our limit and we collide we are creating duplicate
- * contexts internally so we want to assert fail in that case.
- */
- ASSERT(cid >= VMCI_RESERVED_CID_LIMIT);
-
- /* We reserve the lowest 16 ids for fixed contexts. */
- cid = MAX(cid, VMCI_RESERVED_CID_LIMIT-1) + 1;
- if (cid == VMCI_INVALID_ID) {
- cid = VMCI_RESERVED_CID_LIMIT;
- }
- }
- ASSERT(!VMCIContextExists(cid));
- context->cid = cid;
- context->validUser = user != NULL;
- if (context->validUser) {
- context->user = *user;
- }
- VMCIList_Insert(&context->listItem, &contextList.head);
- VMCI_ReleaseLock(&contextList.lock, flags);
-
-#ifdef VMKERNEL
- VMCIContext_SetFSRState(context, FALSE, VMCI_INVALID_ID, eventHnd, FALSE);
-#endif
-
-#ifndef VMX86_SERVER
- context->notify = NULL;
-# ifdef __linux__
- context->notifyPage = NULL;
-# endif
-#endif
-
- *outContext = context;
- return VMCI_SUCCESS;
-
-error:
- if (context->notifierArray) {
- VMCIHandleArray_Destroy(context->notifierArray);
- }
- if (context->queuePairArray) {
- VMCIHandleArray_Destroy(context->queuePairArray);
- }
- if (context->doorbellArray) {
- VMCIHandleArray_Destroy(context->doorbellArray);
- }
- if (context->pendingDoorbellArray) {
- VMCIHandleArray_Destroy(context->pendingDoorbellArray);
- }
- VMCI_FreeKernelMem(context, sizeof *context);
- return result;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_ReleaseContext --
- *
- * Cleans up a VMCI context.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_ReleaseContext(VMCIContext *context) // IN
-{
- VMCILockFlags flags;
-
- /* Dequeue VMCI context. */
-
- VMCI_GrabLock(&contextList.lock, &flags);
- VMCIList_Remove(&context->listItem);
- VMCI_ReleaseLock(&contextList.lock, flags);
-
- VMCIContext_Release(context);
-}
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * VMCIContextFreeContext --
- *
- * Deallocates all parts of a context datastructure. This
- * functions doesn't lock the context, because it assumes that
- * the caller is holding the last reference to context. As paged
- * memory may be freed as part of the call, the function must be
- * called without holding any spinlocks as this is not allowed on
- * Windows.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Paged memory is freed.
- *
- *-----------------------------------------------------------------------------
- */
-
-static void
-VMCIContextFreeContext(VMCIContext *context) // IN
-{
- VMCIListItem *curr;
- VMCIListItem *next;
- DatagramQueueEntry *dqEntry;
- VMCIHandle tempHandle;
-
- /* Fire event to all contexts interested in knowing this context is dying. */
- VMCIContextFireNotification(context->cid, context->privFlags);
-
- /*
- * Cleanup all queue pair resources attached to context. If the VM dies
- * without cleaning up, this code will make sure that no resources are
- * leaked.
- */
-
- tempHandle = VMCIHandleArray_GetEntry(context->queuePairArray, 0);
- while (!VMCI_HANDLE_EQUAL(tempHandle, VMCI_INVALID_HANDLE)) {
- if (VMCIQPBroker_Detach(tempHandle, context) < VMCI_SUCCESS) {
- /*
- * When VMCIQPBroker_Detach() succeeds it removes the handle from the
- * array. If detach fails, we must remove the handle ourselves.
- */
- VMCIHandleArray_RemoveEntry(context->queuePairArray, tempHandle);
- }
- tempHandle = VMCIHandleArray_GetEntry(context->queuePairArray, 0);
- }
-
- /*
- * It is fine to destroy this without locking the datagramQueue, as
- * this is the only thread having a reference to the context.
- */
-
- VMCIList_ScanSafe(curr, next, &context->datagramQueue) {
- dqEntry = VMCIList_Entry(curr, DatagramQueueEntry, listItem);
- VMCIList_Remove(curr);
- ASSERT(dqEntry && dqEntry->dg);
- ASSERT(dqEntry->dgSize == VMCI_DG_SIZE(dqEntry->dg));
- VMCI_FreeKernelMem(dqEntry->dg, dqEntry->dgSize);
- VMCI_FreeKernelMem(dqEntry, sizeof *dqEntry);
- }
-
- VMCIHandleArray_Destroy(context->notifierArray);
- VMCIHandleArray_Destroy(context->queuePairArray);
- VMCIHandleArray_Destroy(context->doorbellArray);
- VMCIHandleArray_Destroy(context->pendingDoorbellArray);
- VMCI_CleanupLock(&context->lock);
-#if defined(VMKERNEL)
- VMCIContextInFilterCleanup(context);
- VMCIMutex_Destroy(&context->guestMemMutex);
-#endif
- VMCIHost_ReleaseContext(&context->hostContext);
-#ifndef VMX86_SERVER
-# ifdef __linux__
- /* TODO Windows and Mac OS. */
- VMCIUnsetNotify(context);
-# endif
-#endif
- VMCI_FreeKernelMem(context, sizeof *context);
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_PendingDatagrams --
- *
- * Returns the current number of pending datagrams. The call may
- * also serve as a synchronization point for the datagram queue,
- * as no enqueue operations can occur concurrently.
- *
- * Results:
- * Length of datagram queue for the given context.
- *
- * Side effects:
- * Locks datagram queue.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_PendingDatagrams(VMCIId cid, // IN
- uint32 *pending) // OUT
-{
- VMCIContext *context;
- VMCILockFlags flags;
-
- context = VMCIContext_Get(cid);
- if (context == NULL) {
- return VMCI_ERROR_INVALID_ARGS;
- }
-
- VMCI_GrabLock(&context->lock, &flags);
- if (pending) {
- *pending = context->pendingDatagrams;
- }
- VMCI_ReleaseLock(&context->lock, flags);
- VMCIContext_Release(context);
-
- return VMCI_SUCCESS;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_EnqueueDatagram --
- *
- * Queues a VMCI datagram for the appropriate target VM
- * context.
- *
- * Results:
- * Size of enqueued data on success, appropriate error code otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_EnqueueDatagram(VMCIId cid, // IN: Target VM
- VMCIDatagram *dg) // IN:
-{
- DatagramQueueEntry *dqEntry;
- VMCIContext *context;
- VMCILockFlags flags;
- VMCIHandle dgSrc;
- size_t vmciDgSize;
-
- ASSERT(dg);
- vmciDgSize = VMCI_DG_SIZE(dg);
- ASSERT(vmciDgSize <= VMCI_MAX_DG_SIZE);
-
- /* Get the target VM's VMCI context. */
- context = VMCIContext_Get(cid);
- if (context == NULL) {
- VMCI_DEBUG_LOG(4, (LGPFX"Invalid context (ID=0x%x).\n", cid));
- return VMCI_ERROR_INVALID_ARGS;
- }
-
- /* Allocate guest call entry and add it to the target VM's queue. */
- dqEntry = VMCI_AllocKernelMem(sizeof *dqEntry, VMCI_MEMORY_NONPAGED);
- if (dqEntry == NULL) {
- VMCI_WARNING((LGPFX"Failed to allocate memory for datagram.\n"));
- VMCIContext_Release(context);
- return VMCI_ERROR_NO_MEM;
- }
- dqEntry->dg = dg;
- dqEntry->dgSize = vmciDgSize;
- dgSrc = dg->src;
- VMCIList_InitEntry(&dqEntry->listItem);
-
- VMCI_GrabLock(&context->lock, &flags);
-
-#if defined(VMKERNEL)
- if (context->inFilters != NULL) {
- if (VMCIFilterDenyDgIn(context->inFilters->filters, dg)) {
- VMCI_ReleaseLock(&context->lock, flags);
- VMCIContext_Release(context);
- VMCI_FreeKernelMem(dqEntry, sizeof *dqEntry);
- return VMCI_ERROR_NO_ACCESS;
- }
- }
-#endif
-
- /*
- * We put a higher limit on datagrams from the hypervisor. If the pending
- * datagram is not from hypervisor, then we check if enqueueing it would
- * exceed the VMCI_MAX_DATAGRAM_QUEUE_SIZE limit on the destination. If the
- * pending datagram is from hypervisor, we allow it to be queued at the
- * destination side provided we don't reach the
- * VMCI_MAX_DATAGRAM_AND_EVENT_QUEUE_SIZE limit.
- */
- if (context->datagramQueueSize + vmciDgSize >=
- VMCI_MAX_DATAGRAM_QUEUE_SIZE &&
- (!VMCI_HANDLE_EQUAL(dgSrc,
- VMCI_MAKE_HANDLE(VMCI_HYPERVISOR_CONTEXT_ID,
- VMCI_CONTEXT_RESOURCE_ID)) ||
- context->datagramQueueSize + vmciDgSize >=
- VMCI_MAX_DATAGRAM_AND_EVENT_QUEUE_SIZE)) {
- VMCI_ReleaseLock(&context->lock, flags);
- VMCIContext_Release(context);
- VMCI_FreeKernelMem(dqEntry, sizeof *dqEntry);
- VMCI_DEBUG_LOG(10, (LGPFX"Context (ID=0x%x) receive queue is full.\n",
- cid));
- return VMCI_ERROR_NO_RESOURCES;
- }
-
- VMCIList_Insert(&dqEntry->listItem, &context->datagramQueue);
- context->pendingDatagrams++;
- context->datagramQueueSize += vmciDgSize;
- VMCIContextSignalNotify(context);
- VMCIHost_SignalCall(&context->hostContext);
- VMCI_ReleaseLock(&context->lock, flags);
- VMCIContext_Release(context);
-
- return vmciDgSize;
-}
-
-#undef VMCI_MAX_DATAGRAM_AND_EVENT_QUEUE_SIZE
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContextExists --
- *
- * Internal helper to check if a context with the specified context
- * ID exists. Assumes the contextList.lock is held.
- *
- * Results:
- * TRUE if a context exists with the given cid.
- * FALSE otherwise
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static Bool
-VMCIContextExists(VMCIId cid) // IN
-{
- VMCIContext *context;
- VMCIListItem *next;
- Bool rv = FALSE;
-
- VMCIList_Scan(next, &contextList.head) {
- context = VMCIList_Entry(next, VMCIContext, listItem);
- if (context->cid == cid) {
- rv = TRUE;
- break;
- }
- }
- return rv;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_Exists --
- *
- * Verifies whether a context with the specified context ID exists.
- *
- * Results:
- * TRUE if a context exists with the given cid.
- * FALSE otherwise
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-Bool
-VMCIContext_Exists(VMCIId cid) // IN
-{
- VMCILockFlags flags;
- Bool rv;
-
- VMCI_GrabLock(&contextList.lock, &flags);
- rv = VMCIContextExists(cid);
- VMCI_ReleaseLock(&contextList.lock, flags);
- return rv;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_Get --
- *
- * Retrieves VMCI context corresponding to the given cid.
- *
- * Results:
- * VMCI context on success, NULL otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-VMCIContext *
-VMCIContext_Get(VMCIId cid) // IN
-{
- VMCIContext *context = NULL;
- VMCIListItem *next;
- VMCILockFlags flags;
-
- if (cid == VMCI_INVALID_ID) {
- return NULL;
- }
-
- VMCI_GrabLock(&contextList.lock, &flags);
- if (VMCIList_Empty(&contextList.head)) {
- goto out;
- }
-
- VMCIList_Scan(next, &contextList.head) {
- context = VMCIList_Entry(next, VMCIContext, listItem);
- if (context->cid == cid) {
- /*
- * At this point, we are sure that the reference count is
- * larger already than zero. When starting the destruction of
- * a context, we always remove it from the context list
- * before decreasing the reference count. As we found the
- * context here, it hasn't been destroyed yet. This means
- * that we are not about to increase the reference count of
- * something that is in the process of being destroyed.
- */
-
- Atomic_Inc(&context->refCount);
- break;
- }
- }
-
-out:
- VMCI_ReleaseLock(&contextList.lock, flags);
- return (context && context->cid == cid) ? context : NULL;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_Release --
- *
- * Releases the VMCI context. If this is the last reference to
- * the context it will be deallocated. A context is created with
- * a reference count of one, and on destroy, it is removed from
- * the context list before its reference count is
- * decremented. Thus, if we reach zero, we are sure that nobody
- * else are about to increment it (they need the entry in the
- * context list for that). This function musn't be called with a
- * lock held.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Paged memory may be deallocated.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_Release(VMCIContext *context) // IN
-{
- uint32 refCount;
- ASSERT(context);
- refCount = Atomic_FetchAndDec(&context->refCount);
- if (refCount == 1) {
- VMCIContextFreeContext(context);
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_DequeueDatagram --
- *
- * Dequeues the next datagram and returns it to caller.
- * The caller passes in a pointer to the max size datagram
- * it can handle and the datagram is only unqueued if the
- * size is less than maxSize. If larger maxSize is set to
- * the size of the datagram to give the caller a chance to
- * set up a larger buffer for the guestcall.
- *
- * Results:
- * On success: 0 if no more pending datagrams, otherwise the size of
- * the next pending datagram.
- * On failure: appropriate error code.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_DequeueDatagram(VMCIContext *context, // IN
- size_t *maxSize, // IN/OUT: max size of datagram caller can handle.
- VMCIDatagram **dg) // OUT:
-{
- DatagramQueueEntry *dqEntry;
- VMCIListItem *listItem;
- VMCILockFlags flags;
- int rv;
-
- ASSERT(context && dg);
-
- /* Dequeue the next datagram entry. */
- VMCI_GrabLock(&context->lock, &flags);
- if (context->pendingDatagrams == 0) {
- VMCIContextClearNotifyAndCall(context);
- VMCI_ReleaseLock(&context->lock, flags);
- VMCI_DEBUG_LOG(4, (LGPFX"No datagrams pending.\n"));
- return VMCI_ERROR_NO_MORE_DATAGRAMS;
- }
-
- listItem = VMCIList_First(&context->datagramQueue);
- ASSERT (listItem != NULL);
-
- dqEntry = VMCIList_Entry(listItem, DatagramQueueEntry, listItem);
- ASSERT(dqEntry->dg);
-
- /* Check size of caller's buffer. */
- if (*maxSize < dqEntry->dgSize) {
- *maxSize = dqEntry->dgSize;
- VMCI_ReleaseLock(&context->lock, flags);
- VMCI_DEBUG_LOG(4, (LGPFX"Caller's buffer should be at least "
- "(size=%u bytes).\n", (uint32)*maxSize));
- return VMCI_ERROR_NO_MEM;
- }
-
- VMCIList_Remove(listItem);
- context->pendingDatagrams--;
- context->datagramQueueSize -= dqEntry->dgSize;
- if (context->pendingDatagrams == 0) {
- VMCIContextClearNotifyAndCall(context);
- rv = VMCI_SUCCESS;
- } else {
- /*
- * Return the size of the next datagram.
- */
- DatagramQueueEntry *nextEntry;
-
- listItem = VMCIList_First(&context->datagramQueue);
- ASSERT(listItem);
- nextEntry = VMCIList_Entry(listItem, DatagramQueueEntry, listItem);
- ASSERT(nextEntry && nextEntry->dg);
- /*
- * The following size_t -> int truncation is fine as the maximum size of
- * a (routable) datagram is 68KB.
- */
- rv = (int)nextEntry->dgSize;
- }
- VMCI_ReleaseLock(&context->lock, flags);
-
- /* Caller must free datagram. */
- ASSERT(dqEntry->dgSize == VMCI_DG_SIZE(dqEntry->dg));
- *dg = dqEntry->dg;
- dqEntry->dg = NULL;
- VMCI_FreeKernelMem(dqEntry, sizeof *dqEntry);
-
- return rv;
-}
-
-
-#ifdef VMKERNEL
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_SetFSRState --
- *
- * Set the states related to FSR (quiesced state, migrateCid,
- * active event handle).
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_SetFSRState(VMCIContext *context, // IN
- Bool isQuiesced, // IN
- VMCIId migrateCid, // IN
- uintptr_t eventHnd, // IN
- Bool isLocked) // IN
-{
- VMCILockFlags flags;
- if (!context) {
- return;
- }
- if (!isLocked) {
- VMCI_GrabLock(&context->lock, &flags);
- }
- context->isQuiesced = isQuiesced;
- context->migrateCid = migrateCid;
- VMCIHost_SetActiveHnd(&context->hostContext, eventHnd);
- if (!isLocked) {
- VMCI_ReleaseLock(&context->lock, flags);
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_FindAndUpdateSrcFSR --
- *
- * Find the source context for fast-suspend-resume. If found, the
- * source context's FSR state is changed to reflect the new active
- * event handle.
- *
- * Results:
- * If found, source context for fast-suspend-resume, NULL otherwise.
- *
- * Side effects:
- * The source context reference count increased and the caller is
- * supposed to release the context once it is done using it.
- *
- *----------------------------------------------------------------------
- */
-
-VMCIContext *
-VMCIContext_FindAndUpdateSrcFSR(VMCIId migrateCid, // IN
- uintptr_t eventHnd, // IN
- uintptr_t *srcEventHnd) // IN/OUT
-{
- VMCIContext *contextSrc = VMCIContext_Get(migrateCid);
-
- if (contextSrc) {
- VMCILockFlags flags;
-
- VMCI_GrabLock(&contextSrc->lock, &flags);
- if (contextSrc->isQuiesced && contextSrc->migrateCid == migrateCid) {
- if (srcEventHnd) {
- *srcEventHnd = VMCIHost_GetActiveHnd(&contextSrc->hostContext);
- ASSERT(*srcEventHnd != VMCI_INVALID_ID);
- }
- VMCIContext_SetFSRState(contextSrc, FALSE, VMCI_INVALID_ID,
- eventHnd, TRUE);
- VMCI_ReleaseLock(&contextSrc->lock, flags);
- return contextSrc;
- }
- VMCI_ReleaseLock(&contextSrc->lock, flags);
- VMCIContext_Release(contextSrc);
- }
- return NULL;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_IsActiveHnd --
- *
- * Whether the curent event handle is the active handle.
- *
- * Results:
- * TRUE if the event handle is active, FALSE otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-Bool
-VMCIContext_IsActiveHnd(VMCIContext *context, // IN
- uintptr_t eventHnd) // IN
-{
- VMCILockFlags flags;
- Bool isActive;
-
- ASSERT(context);
- VMCI_GrabLock(&context->lock, &flags);
- isActive = VMCIHost_IsActiveHnd(&context->hostContext, eventHnd);
- VMCI_ReleaseLock(&context->lock, flags);
- return isActive;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_GetActiveHnd --
- *
- * Returns the curent event handle.
- *
- * Results:
- * The current active handle.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-uintptr_t
-VMCIContext_GetActiveHnd(VMCIContext *context) // IN
-{
- VMCILockFlags flags;
- uintptr_t activeHnd;
-
- ASSERT(context);
- VMCI_GrabLock(&context->lock, &flags);
- activeHnd = VMCIHost_GetActiveHnd(&context->hostContext);
- VMCI_ReleaseLock(&context->lock, flags);
- return activeHnd;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_SetInactiveHnd --
- *
- * Set the handle to be the inactive one.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_SetInactiveHnd(VMCIContext *context, // IN
- uintptr_t eventHnd) // IN
-{
- VMCILockFlags flags;
-
- ASSERT(context);
- VMCI_GrabLock(&context->lock, &flags);
- VMCIHost_SetInactiveHnd(&context->hostContext, eventHnd);
- VMCI_ReleaseLock(&context->lock, flags);
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_RemoveHnd --
- *
- * Remove the event handle from host context.
- *
- * Results:
- * Whether the handle exists and removed, also number of handles
- * before removal and number of handles after removal.
- *
- * Side effects:
- * If this is active handle, the inactive handle becomes active.
- *
- *----------------------------------------------------------------------
- */
-
-Bool
-VMCIContext_RemoveHnd(VMCIContext *context, // IN
- uintptr_t eventHnd, // IN
- uint32 *numOld, // OUT
- uint32 *numNew) // OUT
-{
- VMCILockFlags flags;
- uint32 numHandleOld, numHandleNew;
- Bool ret;
-
- ASSERT(context);
- VMCI_GrabLock(&context->lock, &flags);
- numHandleOld = VMCIHost_NumHnds(&context->hostContext);
- ret = VMCIHost_RemoveHnd(&context->hostContext, eventHnd);
- numHandleNew = VMCIHost_NumHnds(&context->hostContext);
- /*
- * This is needed to prevent FSR to share this
- * context while this context is being destroyed.
- */
- if (ret && numHandleOld == 1 && numHandleNew == 1) {
- context->migrateCid = VMCI_INVALID_ID;
- }
- VMCI_ReleaseLock(&context->lock, flags);
-
- if (numOld) {
- *numOld = numHandleOld;
- }
- if (numNew) {
- *numNew = numHandleNew;
- }
- return ret;
-}
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * VMCIContext_ClearDatagrams --
- *
- * Clear pending datagrams.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *-----------------------------------------------------------------------------
- */
-
-void
-VMCIContext_ClearDatagrams(VMCIContext *context) // IN
-{
- int retval;
- VMCIDatagram *dg = NULL;
- size_t size = VMCI_MAX_DG_SIZE;
- uint32 pending;
-
- /* Drop all datagrams that are currently pending for given context. */
- if (context == NULL) {
- return;
- }
- retval = VMCIContext_PendingDatagrams(context->cid, &pending);
- if (retval != VMCI_SUCCESS) {
- /*
- * This shouldn't happen as we already verified that the context
- * exists.
- */
-
- ASSERT(FALSE);
- return;
- }
-
- /*
- * We drain the queue for any datagrams pending at the beginning of
- * the loop. As datagrams may arrive at any point in time, we
- * cannot guarantee that the queue is empty after this point. Only
- * removing a fixed number of pending datagrams prevents us from
- * looping forever.
- */
-
- while (pending > 0 &&
- VMCIContext_DequeueDatagram(context, &size, &dg) >= 0) {
- ASSERT(dg);
- VMCI_FreeKernelMem(dg, VMCI_DG_SIZE(dg));
- --pending;
- }
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_SetId --
- *
- * Set the cid of given VMCI context.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-VMCIContext_SetId(VMCIContext *context, // IN
- VMCIId cid) // IN:
-{
- VMCILockFlags flags;
-
- if (!context) {
- return;
- }
- VMCI_GrabLock(&context->lock, &flags);
- context->cid = cid;
- VMCI_ReleaseLock(&context->lock, flags);
-}
-#endif
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_GetId --
- *
- * Retrieves cid of given VMCI context.
- *
- * Results:
- * VMCIId of context on success, VMCI_INVALID_ID otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-VMCIId
-VMCIContext_GetId(VMCIContext *context) // IN:
-{
- if (!context) {
- return VMCI_INVALID_ID;
- }
- ASSERT(context->cid != VMCI_INVALID_ID);
- return context->cid;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * vmci_context_get_priv_flags --
- *
- * Retrieves the privilege flags of the given VMCI context ID.
- *
- * Results:
- * Context's privilege flags.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-VMCI_EXPORT_SYMBOL(vmci_context_get_priv_flags)
-VMCIPrivilegeFlags
-vmci_context_get_priv_flags(VMCIId contextID) // IN
-{
- if (VMCI_HostPersonalityActive()) {
- VMCIPrivilegeFlags flags;
- VMCIContext *context;
-
- context = VMCIContext_Get(contextID);
- if (!context) {
- return VMCI_LEAST_PRIVILEGE_FLAGS;
- }
- flags = context->privFlags;
- VMCIContext_Release(context);
- return flags;
- }
- return VMCI_NO_PRIVILEGE_FLAGS;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_AddNotification --
- *
- * Add remoteCID to list of contexts current contexts wants
- * notifications from/about.
- *
- * Results:
- * VMCI_SUCCESS on success, error code otherwise.
- *
- * Side effects:
- * As in VMCIHandleArray_AppendEntry().
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_AddNotification(VMCIId contextID, // IN:
- VMCIId remoteCID) // IN:
-{
- int result = VMCI_ERROR_ALREADY_EXISTS;
- VMCILockFlags flags;
- VMCILockFlags firingFlags;
- VMCIHandle notifierHandle;
- VMCIContext *context = VMCIContext_Get(contextID);
- if (context == NULL) {
- return VMCI_ERROR_NOT_FOUND;
- }
-
- if (VMCI_CONTEXT_IS_VM(contextID) && VMCI_CONTEXT_IS_VM(remoteCID)) {
- VMCI_DEBUG_LOG(4, (LGPFX"Context removed notifications for other VMs not "
- "supported (src=0x%x, remote=0x%x).\n",
- contextID, remoteCID));
- result = VMCI_ERROR_DST_UNREACHABLE;
- goto out;
- }
-
- if (context->privFlags & VMCI_PRIVILEGE_FLAG_RESTRICTED) {
- result = VMCI_ERROR_NO_ACCESS;
- goto out;
- }
-
- notifierHandle = VMCI_MAKE_HANDLE(remoteCID, VMCI_EVENT_HANDLER);
- VMCI_GrabLock(&contextList.firingLock, &firingFlags);
- VMCI_GrabLock(&context->lock, &flags);
- if (!VMCIHandleArray_HasEntry(context->notifierArray, notifierHandle)) {
- VMCIHandleArray_AppendEntry(&context->notifierArray, notifierHandle);
- result = VMCI_SUCCESS;
- }
- VMCI_ReleaseLock(&context->lock, flags);
- VMCI_ReleaseLock(&contextList.firingLock, firingFlags);
-out:
- VMCIContext_Release(context);
- return result;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_RemoveNotification --
- *
- * Remove remoteCID from current context's list of contexts it is
- * interested in getting notifications from/about.
- *
- * Results:
- * VMCI_SUCCESS on success, error code otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-VMCIContext_RemoveNotification(VMCIId contextID, // IN:
- VMCIId remoteCID) // IN:
-{
- VMCILockFlags flags;
- VMCILockFlags firingFlags;
- VMCIContext *context = VMCIContext_Get(contextID);
- VMCIHandle tmpHandle;
- if (context == NULL) {
- return VMCI_ERROR_NOT_FOUND;
- }
- VMCI_GrabLock(&contextList.firingLock, &firingFlags);
- VMCI_GrabLock(&context->lock, &flags);
- tmpHandle =
- VMCIHandleArray_RemoveEntry(context->notifierArray,
- VMCI_MAKE_HANDLE(remoteCID,
- VMCI_EVENT_HANDLER));
- VMCI_ReleaseLock(&context->lock, flags);
- VMCI_ReleaseLock(&contextList.firingLock, firingFlags);
- VMCIContext_Release(context);
-
- if (VMCI_HANDLE_EQUAL(tmpHandle, VMCI_INVALID_HANDLE)) {
- return VMCI_ERROR_NOT_FOUND;
- }
- return VMCI_SUCCESS;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContextFireNotification --
- *
- * Fire notification for all contexts interested in given cid.
- *
- * Results:
- * VMCI_SUCCESS on success, error code otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-static int
-VMCIContextFireNotification(VMCIId contextID, // IN
- VMCIPrivilegeFlags privFlags) // IN
-{
- uint32 i, arraySize;
- VMCIListItem *next;
- VMCILockFlags flags;
- VMCILockFlags firingFlags;
- VMCIHandleArray *subscriberArray;
- VMCIHandle contextHandle = VMCI_MAKE_HANDLE(contextID, VMCI_EVENT_HANDLER);
-
- /*
- * We create an array to hold the subscribers we find when scanning through
- * all contexts.
- */
- subscriberArray = VMCIHandleArray_Create(0);
- if (subscriberArray == NULL) {
- return VMCI_ERROR_NO_MEM;
- }
-
- /*
- * Scan all contexts to find who is interested in being notified about
- * given contextID. We have a special firingLock that we use to synchronize
- * across all notification operations. This avoids us having to take the
- * context lock for each HasEntry call and it solves a lock ranking issue.
- */
- VMCI_GrabLock(&contextList.firingLock, &firingFlags);
- VMCI_GrabLock(&contextList.lock, &flags);
- VMCIList_Scan(next, &contextList.head) {
- VMCIContext *subCtx = VMCIList_Entry(next, VMCIContext, listItem);
-
- /*
- * We only deliver notifications of the removal of contexts, if
- * the two contexts are allowed to interact.
- */
-
- if (VMCIHandleArray_HasEntry(subCtx->notifierArray, contextHandle) &&
- !VMCIDenyInteraction(privFlags, subCtx->privFlags)) {
- VMCIHandleArray_AppendEntry(&subscriberArray,
- VMCI_MAKE_HANDLE(subCtx->cid,
- VMCI_EVENT_HANDLER));
- }
- }
- VMCI_ReleaseLock(&contextList.lock, flags);
- VMCI_ReleaseLock(&contextList.firingLock, firingFlags);
-
- /* Fire event to all subscribers. */
- arraySize = VMCIHandleArray_GetSize(subscriberArray);
- for (i = 0; i < arraySize; i++) {
- int result;
- VMCIEventMsg *eMsg;
- VMCIEventPayload_Context *evPayload;
- char buf[sizeof *eMsg + sizeof *evPayload];
-
- eMsg = (VMCIEventMsg *)buf;
-
- /* Clear out any garbage. */
- memset(eMsg, 0, sizeof *eMsg + sizeof *evPayload);
- eMsg->hdr.dst = VMCIHandleArray_GetEntry(subscriberArray, i);
- eMsg->hdr.src = VMCI_MAKE_HANDLE(VMCI_HYPERVISOR_CONTEXT_ID,
- VMCI_CONTEXT_RESOURCE_ID);
- eMsg->hdr.payloadSize = sizeof *eMsg + sizeof *evPayload -
- sizeof eMsg->hdr;
- eMsg->eventData.event = VMCI_EVENT_CTX_REMOVED;
- evPayload = VMCIEventMsgPayload(eMsg);
- evPayload->contextID = contextID;
-
- result = VMCIDatagram_Dispatch(VMCI_HYPERVISOR_CONTEXT_ID,
- (VMCIDatagram *)eMsg, FALSE);
- if (result < VMCI_SUCCESS) {
- VMCI_DEBUG_LOG(4, (LGPFX"Failed to enqueue event datagram "
- "(type=%d) for context (ID=0x%x).\n",
- eMsg->eventData.event, eMsg->hdr.dst.context));
- /* We continue to enqueue on next subscriber. */
- }
- }
- VMCIHandleArray_Destroy(subscriberArray);
-
- return VMCI_SUCCESS;
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * VMCIContext_GetCheckpointState --
- *
- * Get current context's checkpoint state of given type.
- *
- * Results:
- * VMCI_SUCCESS on success, error code otherwise.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */