Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling ext4 as supported for synced folders within WSL #12948

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/vagrant/util/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,20 @@ def wsl_windows_access_bypass?(path)
# Mount pattern for extracting local mount information
MOUNT_PATTERN = /^(?<device>.+?) on (?<mount>.+?) type (?<type>.+?) \((?<options>.+)\)/.freeze

# List of supported file systems for WSL
WSL_MOUNT_TYPES = ['drvfs', '9p', 'ext4']

# Get list of local mount paths that are DrvFs file systems
#
# @return [Array<String>]
# @todo(chrisroberts): Constantize types for check
def wsl_drvfs_mounts
if !defined?(@_wsl_drvfs_mounts)
@_wsl_drvfs_mounts = []
if wsl?
result = Util::Subprocess.execute("mount")
result.stdout.each_line do |line|
info = line.match(MOUNT_PATTERN)
if info && (info[:type] == "drvfs" || info[:type] == "9p")
if info && WSL_MOUNT_TYPES.include?(info[:type])
@_wsl_drvfs_mounts << info[:mount]
end
end
Expand Down
14 changes: 10 additions & 4 deletions test/unit/plugins/kernel_v2/config/vm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

let(:provider) { double("provider") }
let(:machine) { double("machine", provider: provider, provider_name: "provider", name: "default") }
let(:fs_config){ double("fs_config", vm: double("fs_vm", allowed_synced_folder_types: nil)) }
let(:synced_folder_impl) { double("synced_folder_impl", new: double("synced_folder_inst", usable?: true, _initialize: true)) }
let(:synced_folders ) { {sf_impl: [synced_folder_impl, 1] } }

def assert_invalid
errors = subject.validate(machine)
Expand Down Expand Up @@ -37,12 +40,16 @@ def find_network(name)
allow(machine).to receive(:env).and_return(env)
allow(machine).to receive(:provider_config).and_return(nil)
allow(machine).to receive(:provider_options).and_return({})
allow(machine).to receive(:config).and_return(fs_config)
allow(machine).to receive_message_chain(:synced_folders, :types).and_return( {} )
allow(provider).to receive(:capability?).with(:validate_disk_ext).and_return(true)
allow(provider).to receive(:capability).with(:validate_disk_ext, "vdi").and_return(true)
allow(provider).to receive(:capability?).with(:set_default_disk_ext).and_return(true)
allow(provider).to receive(:capability).with(:set_default_disk_ext).and_return("vdi")

allow(synced_folder_impl).to receive(:respond_to?).with(:wsl_allow_non_drvfs?).and_return(true)
allow(synced_folder_impl).to receive(:wsl_allow_non_drvfs?).and_return(true)
allow(Vagrant.plugin("2").manager).to receive(:synced_folders).and_return(synced_folders)
subject.box = "foo"
end

Expand Down Expand Up @@ -759,10 +766,8 @@ def find_network(name)
context "WSL host paths" do
let(:valid_path){ "/mnt/c/path" }
let(:invalid_path){ "/home/vagrant/path" }
let(:synced_folder_impl){ double("synced_folder_impl", new: double("synced_folder_inst", usable?: true, _initialize: true)) }
let(:fs_config){ double("fs_config", vm: double("fs_vm", allowed_synced_folder_types: nil)) }
let(:plugin){ double("plugin", manager: manager) }
let(:manager){ double("manager", synced_folders: {sf_impl: [synced_folder_impl, 1]}) }
let(:manager){ double("manager", synced_folders: synced_folders) }

let(:stub_pathname){ double("stub_pathname", directory?: true, relative?: false) }

Expand All @@ -772,8 +777,9 @@ def find_network(name)
allow(Vagrant::Util::Platform).to receive(:wsl?).and_return(true)
allow(Vagrant::Util::Platform).to receive(:wsl_drvfs_path?).with(valid_path).and_return(true)
allow(Vagrant::Util::Platform).to receive(:wsl_drvfs_path?).with(invalid_path).and_return(false)
allow(machine).to receive(:config).and_return(fs_config)
allow(Vagrant).to receive(:plugin).with("2").and_return(plugin)
allow(synced_folder_impl).to receive(:respond_to?).with(:wsl_allow_non_drvfs?).and_return(true)
allow(synced_folder_impl).to receive(:wsl_allow_non_drvfs?).and_return(false)
subject.synced_folder(".", "/vagrant", disabled: true)
end

Expand Down
4 changes: 3 additions & 1 deletion test/unit/vagrant/util/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noatime)
C: on /mnt/c type drvfs (rw,noatime)
drvfs on /mnt/d type 9p (rw,noatime,dirsync,anme=drvfs;path=D:\\)
/dev/sdc on /mnt/e type ext4 (rw,relatime,data=ordered)
EOF
}

Expand All @@ -509,7 +511,7 @@
end

it "should locate DrvFs mount path" do
expect(subject.wsl_drvfs_mounts).to eq(["/mnt/c"])
expect(subject.wsl_drvfs_mounts).to eq(["/mnt/c", "/mnt/d", "/mnt/e"])
end

context "when no DrvFs mounts exist" do
Expand Down