rasa / vmware-tools-patches

Patch and build VMware tools automatically
https://github.com/rasa/vmware-tools-patches/wiki
MIT License
1.19k stars 198 forks source link

vmhgfs files created in guest are 0 byte on host #38

Closed rrva closed 9 years ago

rrva commented 9 years ago

With vmhgfs and linux-4.0rc6 and the patches in this repo, copying a file guest->host gives 0 byte files on host, but shown as >0 byte files when listing them from the guest. Creating files on host are properly recognized on the guest. echo 3 > /proc/sys/vm/drop_caches in the guest or calling sync did not help.

Host is vmware fusion / osx

rasa commented 9 years ago

What version of Linux? How are you installing the linux-4.0rc6 kernel? If you can provide the commands you used, I can try to duplicate the issue. Thanks

rrva commented 9 years ago

Try the following

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = "dreamscapes/archlinux"
    config.vm.box_check_update = false
    config.vm.define :docker do |t|
    end

    config.ssh.forward_agent = true
    config.vm.synced_folder ".", "/vagrant", disabled: true

    config.vm.provision :shell, :inline => <<-HEREDOC
        localectl set-locale LANG=en_US.UTF-8
        pacman -Syuu --noconfirm
        pacman -S --noconfirm linux linux-headers git net-tools wget unzip
    HEREDOC

    config.vm.provision :reload
    config.vm.provision :shell, :inline => <<-HEREDOC
        git clone https://github.com/rasa/vmware-tools-patches.git
        cd vmware-tools-patches
        wget -q https://softwareupdate.vmware.com/cds/vmw-desktop/fusion/7.1.1/2498930/packages/com.vmware.fusion.tools.linux.zip.tar
        tar xf com.vmware.fusion.tools.linux.zip.tar
        mkdir tmp
        cd tmp
        unzip ../com.vmware.fusion.tools.linux.zip 
        mkdir iso
        mount -o loop payload/linux.iso iso
        cp iso/VMwareTools* ..
        cd ..
        for x in {0..6}; do mkdir -p /etc/init.d/rc$x.d; done
        ./untar-and-patch-and-compile.sh
        vmware-config-tools.pl -d
        echo vmhgfs > /etc/modules-load.d/vmhgfs.conf
    HEREDOC

    config.vm.provision :shell, :inline => <<-HEREDOC
cat <<EOF > /etc/systemd/system/Users.mount
[Unit]
Description = Users vmhgfs
After = mnt-hgfs.mount

[Mount]
What=/mnt/hgfs/Users
Where=/Users
Type=none
Options=bind

[Install]
WantedBy = multi-user.target
EOF
systemctl enable Users.mount
HEREDOC

    config.vm.provision :shell, :inline => <<-HEREDOC
cat <<EOF > /etc/systemd/system/work.mount
[Unit]
Description = work vmhgfs
After = mnt-hgfs.mount

[Mount]
What=/mnt/hgfs/work
Where=/work
Type=none
Options=bind

[Install]
WantedBy = multi-user.target
EOF
systemctl enable work.mount
HEREDOC

    config.vm.provision :shell, :inline => <<-HEREDOC
cat <<EOF > /etc/systemd/system/mnt-hgfs.mount
[Unit]
Description=Load VMware shared folders
ConditionPathExists=.host:/
ConditionVirtualization=vmware

[Mount]
What=.host:/
Where=/mnt/hgfs
Type=vmhgfs
Options=defaults,noatime

[Install]
WantedBy=multi-user.target
EOF
systemctl enable mnt-hgfs.mount
HEREDOC
    config.vm.provision :shell, :inline => <<-HEREDOC
    echo "GRUB_HIDDEN_TIMEOUT=0" >> /etc/default/grub
    grub-mkconfig -o /boot/grub/grub.cfg
HEREDOC
end
rrva commented 9 years ago

After this has installed:

  1. Manually enable a shared folder in the VMware Fusion Settings for the machine created by vagrant
  2. Edit /etc/pacman.conf and remove the commented-out testing repo:

    [testing] Include = /etc/pacman.d/mirrorlist

  3. Install linux kernel with (at time of writing this is 4.0 in testing repo)

    sudo pacman -Syu --noconfirm testing/linux testing/linux-headers

  4. reboot vagrant box
  5. Rerun vmhgfs compilation

    sudo vmware-config-tools.pl (answered default to all)

  6. reboot vagrant box
  7. Copy any file from / to /mnt/hgfs/[shared-folder]
  8. On host:

ls -l /testfile

Expected: file copied Actual: 0 byte file

rrva commented 9 years ago

Don't forget to use vagrant up --provider=vmware_fusion

sl4ever commented 9 years ago

This due to removing mapping->backing_dev_info, we should create a bdi manually

--- vmhgfs-only/filesystem.c.orig
+++ vmhgfs-only/filesystem.c
@@ -386,8 +386,12 @@ HgfsReadSuper(struct super_block *sb, // OUT: Superblock object
       return PTR_ERR(si);
    }
    HGFS_SET_SB_TO_COMMON(sb, si);
+   result = bdi_setup_and_register(&si->bdi, "vmhgfs");
+   if (result)
+          goto exit1;
    sb->s_magic = HGFS_SUPER_MAGIC;
    sb->s_op = &HgfsSuperOperations;
+   sb->s_bdi = &si->bdi;

 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
    sb->s_d_op = &HgfsDentryOperations;
@@ -427,6 +431,8 @@ HgfsReadSuper(struct super_block *sb, // OUT: Superblock object
   exit:
    if (result) {
       dput(rootDentry);
+      bdi_destroy(&si->bdi);
+exit1:
       kfree(si->shareName);
       kfree(si);
    }
--- vmhgfs-only/module.h.orig
+++ vmhgfs-only/module.h
@@ -29,6 +29,7 @@
 #include "driver-config.h"

 #include <asm/atomic.h>
+#include <linux/backing-dev.h>
 #include "compat_fs.h"
 #include "compat_semaphore.h"
 #include "compat_slab.h"
@@ -130,6 +131,7 @@ typedef struct HgfsSuperInfo {
    uint32 ttl;                      /* Maximum dentry age (in ticks). */
    char *shareName;                 /* Mounted share name. */
    size_t shareNameLen;             /* To avoid repeated strlen() calls. */
+   struct backing_dev_info bdi;
 } HgfsSuperInfo;

 /*
--- vmhgfs-only/super.c.orig
+++ vmhgfs-only/super.c
@@ -152,6 +152,7 @@ HgfsPutSuper(struct super_block *sb) // IN: The superblock

    si = HGFS_SB_TO_COMMON(sb);

+   bdi_destroy(&si->bdi);
    kfree(si->shareName);
    kfree(si);
 }
rasa commented 9 years ago

Can you submit that as a PR?

sl4ever commented 9 years ago

I don't know how to upload a attachment on github. Here is the patch file.

On Fri, Apr 17, 2015 at 12:26 AM, Ross Smith II notifications@github.com wrote:

Can you submit that as a PR?

— Reply to this email directly or view it on GitHub https://github.com/rasa/vmware-tools-patches/issues/38#issuecomment-93777638 .

rrva commented 9 years ago

Use the fork button, upper right corner.

git clone [fork url] add file to patches/vmhgfs (prepend digit to indicate apply order)

add some #if LINUX_VERSION_CODE if needed so it compiles on linux < 4.0

git commit, git push and then go to your fork in github, and there is a create pull request button

rasa commented 9 years ago

@sl4ever: excellent work. Thanks! Closed by #39.