1414#include <linux/sched.h>
1515#include <linux/module.h>
1616#include <linux/compat.h>
17+ #include <linux/swap.h>
1718
1819static const struct file_operations fuse_direct_io_file_operations ;
1920
@@ -245,6 +246,12 @@ void fuse_release_common(struct file *file, int opcode)
245246 req = ff -> reserved_req ;
246247 fuse_prepare_release (ff , file -> f_flags , opcode );
247248
249+ if (ff -> flock ) {
250+ struct fuse_release_in * inarg = & req -> misc .release .in ;
251+ inarg -> release_flags |= FUSE_RELEASE_FLOCK_UNLOCK ;
252+ inarg -> lock_owner = fuse_lock_owner_id (ff -> fc ,
253+ (fl_owner_t ) file );
254+ }
248255 /* Hold vfsmount and dentry until release is finished */
249256 path_get (& file -> f_path );
250257 req -> misc .release .path = file -> f_path ;
@@ -755,18 +762,6 @@ static size_t fuse_send_write(struct fuse_req *req, struct file *file,
755762 return req -> misc .write .out .size ;
756763}
757764
758- static int fuse_write_begin (struct file * file , struct address_space * mapping ,
759- loff_t pos , unsigned len , unsigned flags ,
760- struct page * * pagep , void * * fsdata )
761- {
762- pgoff_t index = pos >> PAGE_CACHE_SHIFT ;
763-
764- * pagep = grab_cache_page_write_begin (mapping , index , flags );
765- if (!* pagep )
766- return - ENOMEM ;
767- return 0 ;
768- }
769-
770765void fuse_write_update_size (struct inode * inode , loff_t pos )
771766{
772767 struct fuse_conn * fc = get_fuse_conn (inode );
@@ -779,62 +774,6 @@ void fuse_write_update_size(struct inode *inode, loff_t pos)
779774 spin_unlock (& fc -> lock );
780775}
781776
782- static int fuse_buffered_write (struct file * file , struct inode * inode ,
783- loff_t pos , unsigned count , struct page * page )
784- {
785- int err ;
786- size_t nres ;
787- struct fuse_conn * fc = get_fuse_conn (inode );
788- unsigned offset = pos & (PAGE_CACHE_SIZE - 1 );
789- struct fuse_req * req ;
790-
791- if (is_bad_inode (inode ))
792- return - EIO ;
793-
794- /*
795- * Make sure writepages on the same page are not mixed up with
796- * plain writes.
797- */
798- fuse_wait_on_page_writeback (inode , page -> index );
799-
800- req = fuse_get_req (fc );
801- if (IS_ERR (req ))
802- return PTR_ERR (req );
803-
804- req -> in .argpages = 1 ;
805- req -> num_pages = 1 ;
806- req -> pages [0 ] = page ;
807- req -> page_offset = offset ;
808- nres = fuse_send_write (req , file , pos , count , NULL );
809- err = req -> out .h .error ;
810- fuse_put_request (fc , req );
811- if (!err && !nres )
812- err = - EIO ;
813- if (!err ) {
814- pos += nres ;
815- fuse_write_update_size (inode , pos );
816- if (count == PAGE_CACHE_SIZE )
817- SetPageUptodate (page );
818- }
819- fuse_invalidate_attr (inode );
820- return err ? err : nres ;
821- }
822-
823- static int fuse_write_end (struct file * file , struct address_space * mapping ,
824- loff_t pos , unsigned len , unsigned copied ,
825- struct page * page , void * fsdata )
826- {
827- struct inode * inode = mapping -> host ;
828- int res = 0 ;
829-
830- if (copied )
831- res = fuse_buffered_write (file , inode , pos , copied , page );
832-
833- unlock_page (page );
834- page_cache_release (page );
835- return res ;
836- }
837-
838777static size_t fuse_send_write_pages (struct fuse_req * req , struct file * file ,
839778 struct inode * inode , loff_t pos ,
840779 size_t count )
@@ -908,6 +847,8 @@ static ssize_t fuse_fill_write_pages(struct fuse_req *req,
908847 pagefault_enable ();
909848 flush_dcache_page (page );
910849
850+ mark_page_accessed (page );
851+
911852 if (!tmp ) {
912853 unlock_page (page );
913854 page_cache_release (page );
@@ -1559,11 +1500,14 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
15591500 struct fuse_conn * fc = get_fuse_conn (inode );
15601501 int err ;
15611502
1562- if (fc -> no_lock ) {
1503+ if (fc -> no_flock ) {
15631504 err = flock_lock_file_wait (file , fl );
15641505 } else {
1506+ struct fuse_file * ff = file -> private_data ;
1507+
15651508 /* emulate flock with POSIX locks */
15661509 fl -> fl_owner = (fl_owner_t ) file ;
1510+ ff -> flock = true;
15671511 err = fuse_setlk (file , fl , 1 );
15681512 }
15691513
@@ -2201,8 +2145,6 @@ static const struct address_space_operations fuse_file_aops = {
22012145 .readpage = fuse_readpage ,
22022146 .writepage = fuse_writepage ,
22032147 .launder_page = fuse_launder_page ,
2204- .write_begin = fuse_write_begin ,
2205- .write_end = fuse_write_end ,
22062148 .readpages = fuse_readpages ,
22072149 .set_page_dirty = __set_page_dirty_nobuffers ,
22082150 .bmap = fuse_bmap ,
0 commit comments