]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds shared_folders_sshfs config
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 7 Oct 2019 22:07:08 +0000 (19:07 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 7 Oct 2019 22:07:08 +0000 (19:07 -0300)
IDEAS.md
README.md
kvmx
kvmxfile

index bf9f47aa8b24efab78c8d0283d119be7296f3adf..0b7e3413d249203695c23bbe71e478c1841536f0 100644 (file)
--- a/IDEAS.md
+++ b/IDEAS.md
@@ -8,7 +8,6 @@
   * https://bbs.archlinux.org/viewtopic.php?id=177299
 * Alternative folder sharing support:
   * NFS, SMB.
-  * Using [sshfs like vagrant-libvirt](https://fedoramagazine.org/vagrant-sharing-folders-vagrant-sshfs/).
   * Or even [SSH to a server](https://superuser.com/questions/831659/mount-a-local-directory-to-a-remote-ssh-server)).
 * Remount 9p shared folders and reinitialize spice-vdagent upon resume from disk [see possible bug](https://bugzilla.redhat.com/show_bug.cgi?id=1333072).
 * [Nested virtualization](http://www.rdoxenham.com/?p=275) ([1](https://wiki.archlinux.org/index.php/KVM#Nested_virtualization), [2](https://ladipro.wordpress.com/2017/02/24/running-hyperv-in-kvm-guest/)).
index ecae6d568d9b5eb56db957556490b454e5ed3792..7e1c56cae8568dfa3c4f43575fa11eb80245e492 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ sources, you'll feel welcome here :)
 
 KVMX currently needs a Debian-based system and the following dependencies:
 
-    sudo apt install git qemu qemu-kvm virt-viewer spice-client spice-client-gtk socat screen
+    sudo apt install git qemu qemu-kvm virt-viewer spice-client spice-client-gtk socat screen sshfs
 
 If you plan to create guest images, you may also want the following packages:
 
diff --git a/kvmx b/kvmx
index 616631dbf32974faa53f791abc8ac0774c586597..ae857624261e51e05a6f0285df53274dce509805 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -632,6 +632,27 @@ function kvmx_up {
       IFS="$old_ifs"
     fi
 
+    # Shall we add an umount hook when powering off the guest?
+    if [ ! -z "$shared_folders_sshfs" ]; then
+      local old_ifs="$IFS"
+      local shared_item
+      IFS=","
+      for shared_item in $shared_folders_sshfs; do
+        local id="`echo $shared_item | cut -d ':' -f 1`"
+        local shared_folder="`echo $shared_item | cut -d ':' -f 2`"
+        local shared_folder_mountpoint="`echo $shared_item | cut -d ':' -f 3`"
+
+        # Temporaly reset IFS so kvmx_sshfs executes correctly
+        IFS="$old_ifs"
+        kvmx_sshfs $shared_folder $shared_folder_mountpoint
+        IFS=","
+
+        unset shared_folder
+        unset shared_folder_mountpoint
+      done
+      IFS="$old_ifs"
+    fi
+
     if [ "$xrandr" == "1" ] && [ "$run_spice_client" == "1" ]; then
       echo "Waiting for X11 to come up so we can set machine resolution..."
       sleep 8
@@ -799,7 +820,9 @@ function kvmx_sshfs {
   fi
 
   SSH="`cat $SSHFILE`"
-  sshfs $SSH_LOGIN@127.0.0.1:$folder $mountpoint $SSH_OPTS -o nonempty -p $SSH
+
+  # See https://github.com/libfuse/sshfs/issues/82 about "-o writeback_cache=no"
+  sshfs $SSH_LOGIN@127.0.0.1:$folder $mountpoint $SSH_OPTS -o nonempty -o sshfs_sync -o sync_readdir -o cache=no -o follow_symlinks -o sync_read -o workaround=rename -o noforget -p $SSH
 }
 
 # Get guest PID
index d9cc78797eb601f96d9c95d9fe408ecdd14032b3..860dfe3b33f06ab9d05fbcb5584b466ab2d58072 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -35,7 +35,7 @@ shared_folder_mountpoint="/home/$user/code/$VM"
 #shared_folder_mountpoint="/srv/kvmx"
 #shared_folder_mountpoint="/vagrant"
 
-# Set this is you want to be able to share multiple folders between host and guest.
+# Set this is you want to be able to share multiple folders between host and guest using 9p.
 # Needs ssh_support set to "y" and a workable SSH connection to the guest.
 # Format: <id1>:<host-folder1>:<guest-mountpoint1>,<id2>:<host-folder2>:<guest-mountpoint2>[,...]
 #shared_folders="shared1:.:/home/$user/code/$VM,shared2:$HOME/.local/share/app:/home/$user/.local/share/app"
@@ -49,6 +49,11 @@ shared_folder_mountpoint="/home/$user/code/$VM"
 # See https://www.kernel.org/doc/Documentation/filesystems/9p.txt
 #shared_folders_cache="none"
 
+# Set this is you want to be able to share multiple folders between host and guest using SSHFS.
+# Needs ssh_support set to "y" and a workable SSH connection to the guest.
+# Format: <id1>:<guest-folder1>:<host-mountpoint1>,<id2>:<guest-folder2>:<host-mountpoint2>[,...]
+#shared_folders_sshfs="shared1:/home/$user/code/$VM:.,shared2:/home/$user/.local/share/app:$HOME/.local/share/app"
+
 # Folder to sync during provisioning in the format "/host/folder1 /guest/folder1,/host/folder2 /guest/folder2[,...]".
 # Needs ssh_support set to "y" and a workable SSH connection to the guest.
 #provision_rsync="$KVMX_BASE/share/provision/ /usr/local/share/kvmx/provision/"