]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/f2fs/data.c
Merge remote-tracking branch 'pfdo/drm-fixes' into drm-next
[karo-tx-linux.git] / fs / f2fs / data.c
index eba7e84d1ffdfc0c32611eda7da2f31f29bde899..91ff93b0b0f403300f951f0d26fa2698ac535c9a 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/f2fs_fs.h>
 #include <linux/buffer_head.h>
 #include <linux/mpage.h>
+#include <linux/aio.h>
 #include <linux/writeback.h>
 #include <linux/backing-dev.h>
 #include <linux/blkdev.h>
@@ -240,7 +241,7 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
 
        if (dn.data_blkaddr == NULL_ADDR)
                return ERR_PTR(-ENOENT);
-
+repeat:
        page = grab_cache_page(mapping, index);
        if (!page)
                return ERR_PTR(-ENOMEM);
@@ -260,6 +261,10 @@ struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
                f2fs_put_page(page, 1);
                return ERR_PTR(-EIO);
        }
+       if (page->mapping != mapping) {
+               f2fs_put_page(page, 1);
+               goto repeat;
+       }
        return page;
 }
 
@@ -291,7 +296,7 @@ struct page *get_new_data_page(struct inode *inode, pgoff_t index,
                }
        }
        f2fs_put_dnode(&dn);
-
+repeat:
        page = grab_cache_page(mapping, index);
        if (!page)
                return ERR_PTR(-ENOMEM);
@@ -311,6 +316,10 @@ struct page *get_new_data_page(struct inode *inode, pgoff_t index,
                        f2fs_put_page(page, 1);
                        return ERR_PTR(-EIO);
                }
+               if (page->mapping != mapping) {
+                       f2fs_put_page(page, 1);
+                       goto repeat;
+               }
        }
 
        if (new_i_size &&
@@ -569,6 +578,7 @@ static int f2fs_write_data_pages(struct address_space *mapping,
 {
        struct inode *inode = mapping->host;
        struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
+       bool locked = false;
        int ret;
        long excess_nrtw = 0, desired_nrtw;
 
@@ -582,10 +592,12 @@ static int f2fs_write_data_pages(struct address_space *mapping,
                wbc->nr_to_write = desired_nrtw;
        }
 
-       if (!S_ISDIR(inode->i_mode))
+       if (!S_ISDIR(inode->i_mode)) {
                mutex_lock(&sbi->writepages);
+               locked = true;
+       }
        ret = write_cache_pages(mapping, wbc, __f2fs_writepage, mapping);
-       if (!S_ISDIR(inode->i_mode))
+       if (locked)
                mutex_unlock(&sbi->writepages);
        f2fs_submit_bio(sbi, DATA, (wbc->sync_mode == WB_SYNC_ALL));
 
@@ -611,7 +623,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
        *fsdata = NULL;
 
        f2fs_balance_fs(sbi);
-
+repeat:
        page = grab_cache_page_write_begin(mapping, index, flags);
        if (!page)
                return -ENOMEM;
@@ -656,6 +668,10 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
                        f2fs_put_page(page, 1);
                        return -EIO;
                }
+               if (page->mapping != mapping) {
+                       f2fs_put_page(page, 1);
+                       goto repeat;
+               }
        }
 out:
        SetPageUptodate(page);