VMware Server 2.0.2 + Linux 2.6.31.5

VMware Server 2.0.2 を Linux 2.6.31.5 で動かすためのパッチ。

使い方は、

$ mkdir /tmp/hogehoge
$ cd /tmp/hogehoge
$ for x in /usr/lib/vmware/modules/source/*.tar; do tar xfv $x; done
$ patch < FILENAME_OF_PATCH
$ for x in *-only; do tar cf ${x/-only/}.tar $x; done
$ sudo cp *.tar /usr/lib/vmware/modules/source

として、/usr/lib/vmware/modules/source/vmmon.tar などにパッチを当てて、

$ sudo /usr/bin/vmware-config.pl

を実行するだけ。

diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmci-only/Makefile vmci-only/Makefile
--- orignal/vmci-only/Makefile	2009-10-21 09:31:34.000000000 +0900
+++ vmci-only/Makefile	2009-10-31 22:17:06.000000000 +0900
@@ -113,7 +113,7 @@
 
 vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
 	$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
-	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
+	$(EXTRA_CFLAGS)  -I$(HEADER_DIR) -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)
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmmon-only/Makefile vmmon-only/Makefile
--- orignal/vmmon-only/Makefile	2009-10-21 09:31:31.000000000 +0900
+++ vmmon-only/Makefile	2009-10-31 22:04:02.000000000 +0900
@@ -113,7 +113,7 @@
 
 vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
 	$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
-	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
+	$(EXTRA_CFLAGS) -I$(HEADER_DIR) -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)
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmmon-only/include/x86svm.h vmmon-only/include/x86svm.h
--- orignal/vmmon-only/include/x86svm.h	2009-10-21 09:31:31.000000000 +0900
+++ vmmon-only/include/x86svm.h	2009-10-31 22:08:02.000000000 +0900
@@ -47,10 +47,14 @@
 #endif
 
 /* SVM related MSRs */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30)
 #define MSR_VM_CR                  0xC0010114
+#endif
 #define MSR_IGNNE                  0xC0010115
 #define MSR_SMM_CTL                0xC0010116
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30)
 #define MSR_VM_HSAVE_PA            0xC0010117
+#endif
 
 #define MSR_VM_CR_SVM_LOCK         0x0000000000000008ULL
 #define MSR_VM_CR_SVME_DISABLE     0x0000000000000010ULL
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmmon-only/linux/driver.c vmmon-only/linux/driver.c
--- orignal/vmmon-only/linux/driver.c	2009-10-21 09:31:31.000000000 +0900
+++ vmmon-only/linux/driver.c	2009-10-31 22:02:04.000000000 +0900
@@ -1984,10 +1984,17 @@
    }
 
    case IOCTL_VMX86_ALLOW_CORE_DUMP:
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
       if (current->euid == current->uid &&
 	  current->fsuid == current->uid &&
           current->egid == current->gid &&
 	  current->fsgid == current->gid) {
+#else
+      if (current_euid() == current_uid() &&
+         current_fsuid() == current_uid() &&
+          current_egid() == current_gid() &&
+         current_fsgid() == current_gid()) {
+#endif
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 23) || defined(MMF_DUMPABLE)
          /* Dump core, readable by user. */
          set_bit(MMF_DUMPABLE, &current->mm->flags);
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmmon-only/linux/hostif.c vmmon-only/linux/hostif.c
--- orignal/vmmon-only/linux/hostif.c	2009-10-21 09:31:31.000000000 +0900
+++ vmmon-only/linux/hostif.c	2009-10-31 22:07:19.000000000 +0900
@@ -3423,6 +3423,86 @@
    return -ENOIOCTLCMD;
 }
 
+/* krellan: Linux 2.6.29 compatibility functions for capabilities */
+/* Errors are logged but otherwise ignored */
+
+void compat_cap_raise(int cap)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+  cap_raise(current->cap_effective, cap);
+#else
+  struct cred *new_cred;
+  
+  new_cred = prepare_creds();
+  if (new_cred != NULL)
+  {
+    cap_raise(new_cred->cap_effective, cap);
+    commit_creds(new_cred);
+  }
+  else
+  {
+    Log("compat_cap_raise(%d) prepare_creds(): Out of memory\n", cap);
+  }
+#endif
+}
+
+void compat_cap_lower(int cap)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+  cap_lower(current->cap_effective, cap);
+#else
+  struct cred *new_cred;
+  
+  new_cred = prepare_creds();
+  if (new_cred != NULL)
+  {
+    cap_lower(new_cred->cap_effective, cap);
+    commit_creds(new_cred);
+  }
+  else
+  {
+    Log("compat_cap_lower(%d) prepare_creds(): Out of memory\n", cap);
+  }
+#endif
+}
+
+int compat_cap_raised(int cap)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+  return cap_raised(current->cap_effective, cap);
+#else
+  return cap_raised(current_cap(), cap);
+#endif
+}
+
+int compat_get_fsuid(void)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+  return current->fsuid;
+#else
+  return current_fsuid();
+#endif
+}
+
+void compat_set_fsuid(int fsuid)
+{
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+  current->fsuid = fsuid;
+#else
+  struct cred *new_cred;
+  
+  new_cred = prepare_creds();
+  if (new_cred != NULL)
+  {
+    new_cred->fsuid = fsuid;
+    commit_creds(new_cred);
+  }
+  else
+  {
+    Log("compat_set_fsuid(%d) prepare_creds(): Out of memory\n", fsuid);
+  }
+#endif
+}
 
 /*
  *----------------------------------------------------------------------
@@ -3456,7 +3536,7 @@
    oldFS = get_fs();
    set_fs(KERNEL_DS);
    compat_allow_signal(SIGKILL);
-   cap_raise(current->cap_effective, CAP_SYS_RESOURCE);
+   compat_cap_raise(CAP_SYS_RESOURCE);
    compat_set_user_nice(current, linuxState.fastClockPriority);
 
    while (linuxState.fastClockRate > HZ + HZ/16) {
@@ -3580,19 +3660,19 @@
          Bool cap;
          long pid;
 
-         fsuid = current->fsuid;
-         current->fsuid = 0;
+	 fsuid = compat_get_fsuid();
+	 compat_set_fsuid(0);
          filp = filp_open("/dev/rtc", O_RDONLY, 0);
-         current->fsuid = fsuid;
+	 compat_set_fsuid(fsuid);
          if (IS_ERR(filp)) {
             Warning("/dev/rtc open failed: %d\n", (int)(VA)filp);
             return -(int)(VA)filp;
          }
-         cap = cap_raised(current->cap_effective, CAP_SYS_RESOURCE);
-         cap_raise(current->cap_effective, CAP_SYS_RESOURCE);
+         cap = compat_cap_raised(CAP_SYS_RESOURCE);
+         compat_cap_raise(CAP_SYS_RESOURCE);
          res = HostIFDoIoctl(filp, RTC_PIE_ON, 0);
          if (!cap) {
-            cap_lower(current->cap_effective, CAP_SYS_RESOURCE);            
+	    compat_cap_lower(CAP_SYS_RESOURCE);
          }
          if (res < 0) {
             Warning("/dev/rtc enable interrupt failed: %d\n", res);
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmnet-only/Makefile vmnet-only/Makefile
--- orignal/vmnet-only/Makefile	2009-10-21 09:31:33.000000000 +0900
+++ vmnet-only/Makefile	2009-10-31 22:12:06.000000000 +0900
@@ -113,7 +113,7 @@
 
 vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
 	$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
-	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
+	$(EXTRA_CFLAGS) -I$(HEADER_DIR) -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)
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vmnet-only/netif.c vmnet-only/netif.c
--- orignal/vmnet-only/netif.c	2009-10-21 09:31:32.000000000 +0900
+++ vmnet-only/netif.c	2009-10-31 22:13:57.000000000 +0900
@@ -194,10 +194,25 @@
  *----------------------------------------------------------------------
  */
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
+static const struct net_device_ops vnet_netdev_ops = {
+   .ndo_init = VNetNetifProbe,
+   .ndo_open = VNetNetifOpen,
+   .ndo_start_xmit = VNetNetifStartXmit,
+   .ndo_stop = VNetNetifClose,
+   .ndo_get_stats = VNetNetifGetStats,
+   .ndo_set_mac_address = VNetNetifSetMAC,
+   .ndo_set_multicast_list = VNetNetifSetMulticast,
+};
+#endif
+
 static void
 VNetNetIfSetup(struct net_device *dev)  // IN:
 {
    ether_setup(dev); // turns on IFF_BROADCAST, IFF_MULTICAST
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30)
+   dev->netdev_ops = &vnet_netdev_ops;
+#else
    dev->init = VNetNetifProbe;
    dev->open = VNetNetifOpen;
    dev->hard_start_xmit = VNetNetifStartXmit;
@@ -205,6 +220,7 @@
    dev->get_stats = VNetNetifGetStats;
    dev->set_mac_address = VNetNetifSetMAC;
    dev->set_multicast_list = VNetNetifSetMulticast;
+#endif
 #ifdef KERNEL_2_3_43
    /*
     * We cannot stuck... If someone will report problems under
@@ -324,7 +340,11 @@
       goto out;
    }
 
-   dev->priv = netIf;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+    dev->priv = netIf;
+#else
+   dev->ml_priv = netIf;
+#endif
    netIf->dev = dev;
    
    memcpy(dev->dev_addr, netIf->port.paddr, sizeof netIf->port.paddr);
@@ -566,7 +586,11 @@
 VNetNetifStartXmit(struct sk_buff    *skb, // IN:
                    struct net_device *dev) // IN:
 {
-   VNetNetIF *netIf = (VNetNetIF*)dev->priv;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+    VNetNetIF *netIf = (VNetNetIF*)dev->priv;
+#else
+   VNetNetIF *netIf = (VNetNetIF*)dev->ml_priv;
+#endif
 
    if(skb == NULL) {
       return 0;
@@ -618,7 +642,12 @@
 VNetNetifSetMAC(struct net_device *dev, // IN:
                 void *p)                // IN:
 {
-   VNetNetIF *netIf = (VNetNetIF*)dev->priv;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+    VNetNetIF *netIf = (VNetNetIF*)dev->priv;
+#else
+    VNetNetIF *netIf = (VNetNetIF*)dev->ml_priv;
+#endif
+
    struct sockaddr const *addr = p;
    if (!VMX86_IS_STATIC_MAC(addr->sa_data)) {
       return -EINVAL;
@@ -675,7 +704,12 @@
 struct net_device_stats *
 VNetNetifGetStats(struct net_device *dev) // IN:
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
    VNetNetIF *netIf = (VNetNetIF*)dev->priv;
+#else
+   VNetNetIF *netIf = (VNetNetIF*)dev->ml_priv;
+#endif
+
    return &(netIf->stats);
 }
 
diff -uNr --exclude='*~' --exclude=Module.markers orignal/vsock-only/Makefile vsock-only/Makefile
--- orignal/vsock-only/Makefile	2009-10-21 09:31:35.000000000 +0900
+++ vsock-only/Makefile	2009-10-31 22:15:01.000000000 +0900
@@ -113,7 +113,7 @@
 
 vm_check_build = $(shell if $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
 	$(CPPFLAGS) $(CFLAGS) $(CFLAGS_KERNEL) \
-	$(EXTRA_CFLAGS) -Iinclude2/asm/mach-default \
+	$(EXTRA_CFLAGS)  -I$(HEADER_DIR) -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)