-
Notifications
You must be signed in to change notification settings - Fork 118
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
Conversation
8efb0dd
to
4123e0d
Compare
@@ -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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the logging back.
impl<FS: Filesystem> AsFd for Session<FS> { | ||
fn as_fd(&self) -> BorrowedFd<'_> { | ||
self.ch.as_fd() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
4123e0d
to
e1615fa
Compare
This is important for container runtimes, which need to do a special namespace mount dance. Fixes cberner#300.
e1615fa
to
574a43a
Compare
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.