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

Allow wrapping an existing /dev/fuse file descriptor #304

Merged
merged 1 commit into from
Oct 19, 2024

Conversation

colinmarc
Copy link
Contributor

This is important for container runtimes, which need to do a special namespace mount dance.

Fixes #300. This is a less invasive version of #301, but I like that one better.

@@ -47,8 +53,6 @@ pub struct Session<FS: Filesystem> {
ch: Channel,
/// Handle to the mount. Dropping this unmounts.
mount: Arc<Mutex<Option<Mount>>>,
/// Mount point
mountpoint: PathBuf,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this optional instead of removing it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the utility of getting the mountpoint back out, after you just passed it in? Especially if it returns an Option<PathBuf>?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getter doesn't seem useful, but it seems nice to have the logging

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the logging back.

Comment on lines +71 to +76
impl<FS: Filesystem> AsFd for Session<FS> {
fn as_fd(&self) -> BorrowedFd<'_> {
self.ch.as_fd()
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to have a mount_to_fd() function similar to mount() that instead returns the FD. That better separates the concerns of creating the mountpoint, which won't even need to have a Filesystem implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for symmetry - I'm not using it, so I can remove it if you don't like it. Note that the stdlib equivalents all support this (File, various sockets, etc).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would someone use it though?

The reason it doesn't seem right to me is that a Session represents a mounted filesystem, borrowing its fd, and reading/writing it would interfere with the Filesystem that is mounted and feels like it breaks the encapsulation.

Copy link
Contributor Author

@colinmarc colinmarc Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would someone use it though?

By passing it into mount(2)/fsconfig(2) to mount the session somewhere.

In my use case, you need to mount first and then create the session. But it's not hard to imagine someone needing to do it the other way around.

EDIT: I just thought of another one. You could unset CLOEXEC or do some other fcntl stuff on the session if you needed to.

EDIT2: You could also use it to call fuse ioctls, perhaps ones that aren't supported by this library yet (eg file passthrough).

Copy link
Contributor Author

@colinmarc colinmarc Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zooming out a bit:

I would like to submit that FUSE is a very low-level concept, and it's often used as a hack-on-demand. So people using it probably know what they're doing, and may have complicated requirements. A fuse session is a /dev/fuse file descriptor - therefore it fulfills the requirements of AsFd.

I do see the concerns around breaking the encapsulation, but Channel is not actually stateful, right? So it's really very similar to UnixStream or whatever. If you call AsFd on a UnixStream and drop down to nix::io::write or whatever, you probably have a very specific use case that the stdlib authors didn't think of.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. Thanks for explaining the use case!

This is important for container runtimes, which need to do a special
namespace mount dance.

Fixes cberner#300.
@cberner cberner merged commit b97dae7 into cberner:master Oct 19, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extract Channel FD and self-mount
2 participants