microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.55k stars 823 forks source link

Support LockFileEx syscall in \\wsl$ directory #5762

Open kamijin-fanta opened 4 years ago

kamijin-fanta commented 4 years ago

Is your feature request related to a problem? Please describe.

Package management tools such as Go Modules and Rust Cargo use Write/Read Lock of File System. This is an important mechanism for removing conflicts.

The WSL2 shared directory \\wsl$ does not seem to support LockFileEx syscall. I confirmed that smb supports it. It returns an Incorrect function. error with the LOCKFILE_EXCLUSIVE_LOCK flag both set/unset.

To solve this problem, Rust Cargo has added code that ignores lock errors. https://github.com/rust-lang/cargo/pull/7602 Go Modules does not work with WSL and officially replied to Issue that WSL is not supported. https://github.com/golang/go/issues/37461

Describe the solution you'd like Add locking functionality to the shared file system for a better development experience.

Describe alternatives you've considered

Additional context

Below is an example of an error with go modules in latest version.

> go mod download # go version 1.14
go: RLock Z:\example\go.mod: Incorrect function.

simple test code to call LockFileEx

package main

import (
    "os"
    "fmt"
    "golang.org/x/sys/windows"
)

const (
    reserved = 0
    allBytes = ^uint32(0)
)

func main () {
    f, err := os.Open("tmp.txt")
    if err != nil {
        panic(err)
    }

    lockType := uint32(2) // 0: readlock 2: writelock
    ol := new(windows.Overlapped)
    err = windows.LockFileEx(windows.Handle(f.Fd()), lockType, reserved, allBytes, allBytes, ol)
    if err != nil {
        panic(err)
    }
    fmt.Printf("success lock")
}
WSLUser commented 4 years ago

Read this: https://devblogs.microsoft.com/commandline/a-deep-dive-into-how-wsl-allows-windows-to-access-linux-files/ and this https://devblogs.microsoft.com/commandline/whats-new-for-wsl-in-windows-10-version-1903/. Basically this means WSL2 will be unable to support without support being added to the 9P file server (unlikely).

therealkenc commented 4 years ago

Plausible. Other direction too ref #2395 (message).

nVitius commented 3 years ago

There's a comment in the golang/go repo that suggests that the 9P protocol does support file-locking, but the implementation used in WSL does not.

Can someone on the WSL team confirm this is the case? If so, can we have any insight into whether or not this will be fixed at some point? @craigloewen-msft @benhillis

nVitius commented 3 years ago

@benhillis @craigloewen-msft Can we get some feedback on this please?

I haven't seen any other MS employees active in these issues, so I'm pinging you two. If there's someone else that should be involved in this discussion, please let us know.

ghost commented 1 year ago

This also affects Gradle (a JVM build system).

michael-ts commented 1 year ago

This apparently also affects any programs on Windows which try to use SQLite to open a database on the WSL side (for instance, an ext4 partition mounted using wsl --mount). I can easily reproduce this by creating a simple test database in WSL, then running sqlite3.exe to open it, and execute the SQL statement SELECT * FROM SQLITE_MASTER - this produces this error:

Parse error: database is locked (5)
oldshensheep commented 7 months ago

\wsl$ also doesn't support watch. Why doesn't WSL use SMB? I set up samba in WSL, it supports both file locking and watch. I ended up dropping the shit \wsl$, replacing it with SMB

https://github.com/microsoft/WSL/issues/5103