@@ -21,12 +21,13 @@ static inline bool fuse_is_io_cache_wait(struct fuse_inode *fi)
2121}
2222
2323/*
24- * Start cached io mode.
24+ * Called on cached file open() and on first mmap() of direct_io file.
25+ * Takes cached_io inode mode reference to be dropped on file release.
2526 *
2627 * Blocks new parallel dio writes and waits for the in-progress parallel dio
2728 * writes to complete.
2829 */
29- int fuse_file_cached_io_start (struct inode * inode , struct fuse_file * ff )
30+ int fuse_file_cached_io_open (struct inode * inode , struct fuse_file * ff )
3031{
3132 struct fuse_inode * fi = get_fuse_inode (inode );
3233
@@ -67,10 +68,9 @@ int fuse_file_cached_io_start(struct inode *inode, struct fuse_file *ff)
6768 return 0 ;
6869}
6970
70- static void fuse_file_cached_io_end (struct inode * inode , struct fuse_file * ff )
71+ static void fuse_file_cached_io_release (struct fuse_file * ff ,
72+ struct fuse_inode * fi )
7173{
72- struct fuse_inode * fi = get_fuse_inode (inode );
73-
7474 spin_lock (& fi -> lock );
7575 WARN_ON (fi -> iocachectr <= 0 );
7676 WARN_ON (ff -> iomode != IOM_CACHED );
@@ -82,29 +82,26 @@ static void fuse_file_cached_io_end(struct inode *inode, struct fuse_file *ff)
8282}
8383
8484/* Start strictly uncached io mode where cache access is not allowed */
85- int fuse_file_uncached_io_start (struct inode * inode , struct fuse_file * ff , struct fuse_backing * fb )
85+ int fuse_inode_uncached_io_start (struct fuse_inode * fi , struct fuse_backing * fb )
8686{
87- struct fuse_inode * fi = get_fuse_inode (inode );
8887 struct fuse_backing * oldfb ;
8988 int err = 0 ;
9089
9190 spin_lock (& fi -> lock );
9291 /* deny conflicting backing files on same fuse inode */
9392 oldfb = fuse_inode_backing (fi );
94- if (oldfb && oldfb != fb ) {
93+ if (fb && oldfb && oldfb != fb ) {
9594 err = - EBUSY ;
9695 goto unlock ;
9796 }
9897 if (fi -> iocachectr > 0 ) {
9998 err = - ETXTBSY ;
10099 goto unlock ;
101100 }
102- WARN_ON (ff -> iomode != IOM_NONE );
103101 fi -> iocachectr -- ;
104- ff -> iomode = IOM_UNCACHED ;
105102
106103 /* fuse inode holds a single refcount of backing file */
107- if (!oldfb ) {
104+ if (fb && !oldfb ) {
108105 oldfb = fuse_inode_backing_set (fi , fb );
109106 WARN_ON_ONCE (oldfb != NULL );
110107 } else {
@@ -115,15 +112,29 @@ int fuse_file_uncached_io_start(struct inode *inode, struct fuse_file *ff, struc
115112 return err ;
116113}
117114
118- void fuse_file_uncached_io_end (struct inode * inode , struct fuse_file * ff )
115+ /* Takes uncached_io inode mode reference to be dropped on file release */
116+ static int fuse_file_uncached_io_open (struct inode * inode ,
117+ struct fuse_file * ff ,
118+ struct fuse_backing * fb )
119119{
120120 struct fuse_inode * fi = get_fuse_inode (inode );
121+ int err ;
122+
123+ err = fuse_inode_uncached_io_start (fi , fb );
124+ if (err )
125+ return err ;
126+
127+ WARN_ON (ff -> iomode != IOM_NONE );
128+ ff -> iomode = IOM_UNCACHED ;
129+ return 0 ;
130+ }
131+
132+ void fuse_inode_uncached_io_end (struct fuse_inode * fi )
133+ {
121134 struct fuse_backing * oldfb = NULL ;
122135
123136 spin_lock (& fi -> lock );
124137 WARN_ON (fi -> iocachectr >= 0 );
125- WARN_ON (ff -> iomode != IOM_UNCACHED );
126- ff -> iomode = IOM_NONE ;
127138 fi -> iocachectr ++ ;
128139 if (!fi -> iocachectr ) {
129140 wake_up (& fi -> direct_io_waitq );
@@ -134,6 +145,15 @@ void fuse_file_uncached_io_end(struct inode *inode, struct fuse_file *ff)
134145 fuse_backing_put (oldfb );
135146}
136147
148+ /* Drop uncached_io reference from passthrough open */
149+ static void fuse_file_uncached_io_release (struct fuse_file * ff ,
150+ struct fuse_inode * fi )
151+ {
152+ WARN_ON (ff -> iomode != IOM_UNCACHED );
153+ ff -> iomode = IOM_NONE ;
154+ fuse_inode_uncached_io_end (fi );
155+ }
156+
137157/*
138158 * Open flags that are allowed in combination with FOPEN_PASSTHROUGH.
139159 * A combination of FOPEN_PASSTHROUGH and FOPEN_DIRECT_IO means that read/write
@@ -163,7 +183,7 @@ static int fuse_file_passthrough_open(struct inode *inode, struct file *file)
163183 return PTR_ERR (fb );
164184
165185 /* First passthrough file open denies caching inode io mode */
166- err = fuse_file_uncached_io_start (inode , ff , fb );
186+ err = fuse_file_uncached_io_open (inode , ff , fb );
167187 if (!err )
168188 return 0 ;
169189
@@ -216,7 +236,7 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
216236 if (ff -> open_flags & FOPEN_PASSTHROUGH )
217237 err = fuse_file_passthrough_open (inode , file );
218238 else
219- err = fuse_file_cached_io_start (inode , ff );
239+ err = fuse_file_cached_io_open (inode , ff );
220240 if (err )
221241 goto fail ;
222242
@@ -236,19 +256,21 @@ int fuse_file_io_open(struct file *file, struct inode *inode)
236256/* No more pending io and no new io possible to inode via open/mmapped file */
237257void fuse_file_io_release (struct fuse_file * ff , struct inode * inode )
238258{
259+ struct fuse_inode * fi = get_fuse_inode (inode );
260+
239261 /*
240- * Last parallel dio close allows caching inode io mode.
262+ * Last passthrough file close allows caching inode io mode.
241263 * Last caching file close exits caching inode io mode.
242264 */
243265 switch (ff -> iomode ) {
244266 case IOM_NONE :
245267 /* Nothing to do */
246268 break ;
247269 case IOM_UNCACHED :
248- fuse_file_uncached_io_end ( inode , ff );
270+ fuse_file_uncached_io_release ( ff , fi );
249271 break ;
250272 case IOM_CACHED :
251- fuse_file_cached_io_end ( inode , ff );
273+ fuse_file_cached_io_release ( ff , fi );
252274 break ;
253275 }
254276}
0 commit comments