8
8
//! sequentially. A FUSE session is a connection from a FUSE mountpoint to a FUSE server daemon.
9
9
//! A FUSE session can have multiple FUSE channels so that FUSE requests are handled in parallel.
10
10
11
- use mio:: { Events , Poll , Token , Waker } ;
12
11
use std:: fs:: { File , OpenOptions } ;
13
12
use std:: ops:: Deref ;
14
13
use std:: os:: unix:: fs:: PermissionsExt ;
@@ -17,6 +16,7 @@ use std::os::unix::net::UnixStream;
17
16
use std:: path:: { Path , PathBuf } ;
18
17
use std:: sync:: { Arc , Mutex } ;
19
18
19
+ use mio:: { Events , Poll , Token , Waker } ;
20
20
use nix:: errno:: Errno ;
21
21
use nix:: fcntl:: { fcntl, FcntlArg , FdFlag , OFlag } ;
22
22
use nix:: mount:: { mount, umount2, MntFlags , MsFlags } ;
@@ -27,7 +27,7 @@ use nix::unistd::{getgid, getuid, read};
27
27
use super :: {
28
28
super :: pagesize,
29
29
Error :: { IoError , SessionFailure } ,
30
- FuseBuf , FuseDevWriter , Reader , Result , FUSE_HEADER_SIZE , FUSE_KERN_BUF_SIZE ,
30
+ FuseBuf , FuseDevWriter , Reader , Result , FUSE_HEADER_SIZE , FUSE_KERN_BUF_PAGES ,
31
31
} ;
32
32
33
33
// These follows definition from libfuse.
@@ -90,7 +90,7 @@ impl FuseSession {
90
90
subtype : subtype. to_owned ( ) ,
91
91
file : None ,
92
92
keep_alive : None ,
93
- bufsize : FUSE_KERN_BUF_SIZE * pagesize ( ) + FUSE_HEADER_SIZE ,
93
+ bufsize : FUSE_KERN_BUF_PAGES * pagesize ( ) + FUSE_HEADER_SIZE ,
94
94
readonly,
95
95
wakers : Mutex :: new ( Vec :: new ( ) ) ,
96
96
auto_unmount,
@@ -123,6 +123,36 @@ impl FuseSession {
123
123
self . fusermount . as_str ( )
124
124
}
125
125
126
+ /// Expose the associated FUSE session file.
127
+ pub fn get_fuse_file ( & self ) -> Option < & File > {
128
+ self . file . as_ref ( )
129
+ }
130
+
131
+ /// Force setting the associated FUSE session file.
132
+ pub fn set_fuse_file ( & mut self , file : File ) {
133
+ self . file = Some ( file) ;
134
+ }
135
+
136
+ /// Get the mountpoint of the session.
137
+ pub fn mountpoint ( & self ) -> & Path {
138
+ & self . mountpoint
139
+ }
140
+
141
+ /// Get the file system name of the session.
142
+ pub fn fsname ( & self ) -> & str {
143
+ & self . fsname
144
+ }
145
+
146
+ /// Get the subtype of the session.
147
+ pub fn subtype ( & self ) -> & str {
148
+ & self . subtype
149
+ }
150
+
151
+ /// Get the default buffer size of the session.
152
+ pub fn bufsize ( & self ) -> usize {
153
+ self . bufsize
154
+ }
155
+
126
156
/// Mount the fuse mountpoint, building connection with the in kernel fuse driver.
127
157
pub fn mount ( & mut self ) -> Result < ( ) > {
128
158
let mut flags = MsFlags :: MS_NOSUID | MsFlags :: MS_NODEV | MsFlags :: MS_NOATIME ;
@@ -148,16 +178,6 @@ impl FuseSession {
148
178
Ok ( ( ) )
149
179
}
150
180
151
- /// Expose the associated FUSE session file.
152
- pub fn get_fuse_file ( & self ) -> Option < & File > {
153
- self . file . as_ref ( )
154
- }
155
-
156
- /// Force setting the associated FUSE session file.
157
- pub fn set_fuse_file ( & mut self , file : File ) {
158
- self . file = Some ( file) ;
159
- }
160
-
161
181
/// Destroy a fuse session.
162
182
pub fn umount ( & mut self ) -> Result < ( ) > {
163
183
// If we have a keep_alive socket, just drop it,
@@ -173,26 +193,6 @@ impl FuseSession {
173
193
}
174
194
}
175
195
176
- /// Get the mountpoint of the session.
177
- pub fn mountpoint ( & self ) -> & Path {
178
- & self . mountpoint
179
- }
180
-
181
- /// Get the file system name of the session.
182
- pub fn fsname ( & self ) -> & str {
183
- & self . fsname
184
- }
185
-
186
- /// Get the subtype of the session.
187
- pub fn subtype ( & self ) -> & str {
188
- & self . subtype
189
- }
190
-
191
- /// Get the default buffer size of the session.
192
- pub fn bufsize ( & self ) -> usize {
193
- self . bufsize
194
- }
195
-
196
196
/// Create a new fuse message channel.
197
197
pub fn new_channel ( & self ) -> Result < FuseChannel > {
198
198
if let Some ( file) = & self . file {
@@ -209,15 +209,6 @@ impl FuseSession {
209
209
}
210
210
}
211
211
212
- fn add_waker ( & self , waker : Arc < Waker > ) -> Result < ( ) > {
213
- let mut wakers = self
214
- . wakers
215
- . lock ( )
216
- . map_err ( |e| SessionFailure ( format ! ( "lock wakers: {e}" ) ) ) ?;
217
- wakers. push ( waker) ;
218
- Ok ( ( ) )
219
- }
220
-
221
212
/// Wake channel loop and exit
222
213
pub fn wake ( & self ) -> Result < ( ) > {
223
214
let wakers = self
@@ -231,6 +222,15 @@ impl FuseSession {
231
222
}
232
223
Ok ( ( ) )
233
224
}
225
+
226
+ fn add_waker ( & self , waker : Arc < Waker > ) -> Result < ( ) > {
227
+ let mut wakers = self
228
+ . wakers
229
+ . lock ( )
230
+ . map_err ( |e| SessionFailure ( format ! ( "lock wakers: {e}" ) ) ) ?;
231
+ wakers. push ( waker) ;
232
+ Ok ( ( ) )
233
+ }
234
234
}
235
235
236
236
impl Drop for FuseSession {
@@ -442,7 +442,7 @@ fn fuse_kern_mount(
442
442
Some ( opts. deref ( ) ) ,
443
443
) {
444
444
Ok ( ( ) ) => Ok ( ( file, None ) ) ,
445
- Err ( nix :: errno :: Errno :: EPERM ) => fuse_fusermount_mount (
445
+ Err ( Errno :: EPERM ) => fuse_fusermount_mount (
446
446
mountpoint,
447
447
fsname,
448
448
subtype,
@@ -507,7 +507,7 @@ fn fuse_fusermount_mount(
507
507
// When its partner recv closes, fusermount will unmount.
508
508
// Remove the close-on-exec flag from the socket, so we can pass it to
509
509
// fusermount.
510
- nix :: fcntl :: fcntl ( send. as_raw_fd ( ) , FcntlArg :: F_SETFD ( FdFlag :: empty ( ) ) )
510
+ fcntl ( send. as_raw_fd ( ) , FcntlArg :: F_SETFD ( FdFlag :: empty ( ) ) )
511
511
. map_err ( |e| SessionFailure ( format ! ( "Failed to remove close-on-exec flag: {e}" ) ) ) ?;
512
512
513
513
let mut cmd = match target_mntns {
@@ -581,14 +581,14 @@ fn fuse_kern_umount(mountpoint: &str, file: File, fusermount: &str) -> Result<()
581
581
drop ( file) ;
582
582
match umount2 ( mountpoint, MntFlags :: MNT_DETACH ) {
583
583
Ok ( ( ) ) => Ok ( ( ) ) ,
584
- Err ( nix :: errno :: Errno :: EPERM ) => fuse_fusermount_umount ( mountpoint, fusermount) ,
584
+ Err ( Errno :: EPERM ) => fuse_fusermount_umount ( mountpoint, fusermount) ,
585
585
Err ( e) => Err ( SessionFailure ( format ! (
586
586
"failed to umount {mountpoint}: {e}"
587
587
) ) ) ,
588
588
}
589
589
}
590
590
591
- /// Umount a fuse file system
591
+ /// Umount a fuse file system by fusermount helper
592
592
fn fuse_fusermount_umount ( mountpoint : & str , fusermount : & str ) -> Result < ( ) > {
593
593
match std:: process:: Command :: new ( fusermount)
594
594
. arg ( "--unmount" )
0 commit comments