-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/sys/unix: add name_to_handle_at and open_by_handle_at #30537
Comments
I don't see a reason to split up the C type FileHandle struct { unexported fields }
func NameToHandleAt(dirfd int, path string, flags int) (handle FileHandle, mountID int, err error)
func OpenByHandleAt(mountID int, handle FileHandle, flags int) (err error) It's odd that in C the two functions use a different order for |
You left out the part I am actually struggling with. How can we structure FileHandle so that it a) allows Go users access to handle_type as well as f_handle b) has the same memory layout as in C, so that it can be passed to other functions accepting handles. Are you suggesting that we do not maintain the memory layout and handle conversions between two representations transparently? |
Why do Go users need access to To preserve the same memory layout as C I suggest that the "unexported fields" be simply a []byte that is the C memory layout. Then we can add a For that matter we could have a Probably I am missing something. |
|
@ianlancetaylor, I need it for writing tests for a FUSE filesystem. |
Change https://golang.org/cl/172584 mentions this issue: |
…wrappers No usable change for users in this CL; just auto-generated syscall wrapper funcs & types. The next CL will have hand-written code adding the nice Go API around these unexported symbols. (as outlined in the comment at https://golang.org/issue/30537#issuecomment-470284573) Updates golang/go#30537 Change-Id: I5e34df517efcf509fff97f670425500cc6608d59 Reviewed-on: https://go-review.googlesource.com/c/sys/+/172584 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
Change https://golang.org/cl/173357 mentions this issue: |
Change https://golang.org/cl/174077 mentions this issue: |
Updates golang/go#30537 Change-Id: Ica526a4bc689af594b0e91c988631bf9987a6119 Reviewed-on: https://go-review.googlesource.com/c/sys/+/174077 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
I would like to add name_to_handle_at and open_by_handle_at to x/sys/unix for Linux, but I am not sure how to structure the functions and types.
Their canonical definitions are
My issue is with the open-ended nature of file_handle. The name_to_handle_at syscall expects the user to allocate a file_handle of sufficient size (usually in a loop to determine the correct size) and to put its size in handle_bytes. And while the value of f_handle is opaque, the user may want to access it, for example to transmit it over the network.
I can imagine two possible ways of designing the API, and I am hoping for a third one.
The first option is to stick 1:1 to the C definitions. This would require use of unsafe.Pointer on the caller's side to convert the backing array into the appropriate type, as well as to access the value of f_handle. And due to #14440, the existence of the f_handle field is obscured. Furthermore, I am not sure how this interacts with the GC. If we back a 16 byte struct with an N bytes byte slice, can we be sure GC will never collect part of the memory?
The second option is to split the file_handle argument in two, one for the part of the struct that Go actually generates, and a byte slice for the f_handle, giving us the following:
This, however, begs the question: who's responsibility is it to ensure that handle.Bytes and len(fHandle) match, and what do we do if they don't?
Is there a third option I'm missing?
/cc @ianlancetaylor @tklauser
The text was updated successfully, but these errors were encountered: