Merge git://git.infradead.org/users/eparis/selinux
[cascardo/linux.git] / fs / bfs / file.c
index f20e8a7..ad3ea14 100644 (file)
@@ -161,6 +161,14 @@ static int bfs_readpage(struct file *file, struct page *page)
        return block_read_full_page(page, bfs_get_block);
 }
 
+static void bfs_write_failed(struct address_space *mapping, loff_t to)
+{
+       struct inode *inode = mapping->host;
+
+       if (to > inode->i_size)
+               truncate_pagecache(inode, to, inode->i_size);
+}
+
 static int bfs_write_begin(struct file *file, struct address_space *mapping,
                        loff_t pos, unsigned len, unsigned flags,
                        struct page **pagep, void **fsdata)
@@ -169,11 +177,8 @@ static int bfs_write_begin(struct file *file, struct address_space *mapping,
 
        ret = block_write_begin(mapping, pos, len, flags, pagep,
                                bfs_get_block);
-       if (unlikely(ret)) {
-               loff_t isize = mapping->host->i_size;
-               if (pos + len > isize)
-                       vmtruncate(mapping->host, isize);
-       }
+       if (unlikely(ret))
+               bfs_write_failed(mapping, pos + len);
 
        return ret;
 }