summaryrefslogtreecommitdiffstats
path: root/fs/fuse/file.c
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2019-01-16 04:27:59 -0500
committerMiklos Szeredi <mszeredi@redhat.com>2019-02-13 07:15:12 -0500
commit2fe93bd43264242e4568763d1b183b1cc58066ff (patch)
treed98b1b16e48a377cb9f3f4b60d13cde768dad8da /fs/fuse/file.c
parentd13937116f1e82bf508a6325111b322c30c85eb9 (diff)
fuse: extract fuse_find_writeback() helper
Call this from fuse_range_is_writeback() and fuse_writepage_in_flight(). Turn a BUG_ON() into a WARN_ON() in the process. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/fuse/file.c')
-rw-r--r--fs/fuse/file.c52
1 files changed, 25 insertions, 27 deletions
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index a59c16bd90ac..927d40dec376 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -329,6 +329,24 @@ u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id)
329 return (u64) v0 + ((u64) v1 << 32); 329 return (u64) v0 + ((u64) v1 << 32);
330} 330}
331 331
332static struct fuse_req *fuse_find_writeback(struct fuse_inode *fi,
333 pgoff_t idx_from, pgoff_t idx_to)
334{
335 struct fuse_req *req;
336
337 list_for_each_entry(req, &fi->writepages, writepages_entry) {
338 pgoff_t curr_index;
339
340 WARN_ON(get_fuse_inode(req->inode) != fi);
341 curr_index = req->misc.write.in.offset >> PAGE_SHIFT;
342 if (idx_from < curr_index + req->num_pages &&
343 curr_index <= idx_to) {
344 return req;
345 }
346 }
347 return NULL;
348}
349
332/* 350/*
333 * Check if any page in a range is under writeback 351 * Check if any page in a range is under writeback
334 * 352 *
@@ -340,21 +358,10 @@ static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from,
340{ 358{
341 struct fuse_conn *fc = get_fuse_conn(inode); 359 struct fuse_conn *fc = get_fuse_conn(inode);
342 struct fuse_inode *fi = get_fuse_inode(inode); 360 struct fuse_inode *fi = get_fuse_inode(inode);
343 struct fuse_req *req; 361 bool found;
344 bool found = false;
345 362
346 spin_lock(&fc->lock); 363 spin_lock(&fc->lock);
347 list_for_each_entry(req, &fi->writepages, writepages_entry) { 364 found = fuse_find_writeback(fi, idx_from, idx_to);
348 pgoff_t curr_index;
349
350 BUG_ON(req->inode != inode);
351 curr_index = req->misc.write.in.offset >> PAGE_SHIFT;
352 if (idx_from < curr_index + req->num_pages &&
353 curr_index <= idx_to) {
354 found = true;
355 break;
356 }
357 }
358 spin_unlock(&fc->lock); 365 spin_unlock(&fc->lock);
359 366
360 return found; 367 return found;
@@ -1744,25 +1751,17 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
1744 struct fuse_inode *fi = get_fuse_inode(new_req->inode); 1751 struct fuse_inode *fi = get_fuse_inode(new_req->inode);
1745 struct fuse_req *tmp; 1752 struct fuse_req *tmp;
1746 struct fuse_req *old_req; 1753 struct fuse_req *old_req;
1747 bool found = false;
1748 pgoff_t curr_index; 1754 pgoff_t curr_index;
1749 1755
1750 BUG_ON(new_req->num_pages != 0); 1756 BUG_ON(new_req->num_pages != 0);
1751 1757
1752 spin_lock(&fc->lock); 1758 spin_lock(&fc->lock);
1753 list_del(&new_req->writepages_entry); 1759 list_del(&new_req->writepages_entry);
1754 list_for_each_entry(old_req, &fi->writepages, writepages_entry) { 1760 old_req = fuse_find_writeback(fi, page->index, page->index);
1755 BUG_ON(old_req->inode != new_req->inode); 1761 if (!old_req) {
1756 curr_index = old_req->misc.write.in.offset >> PAGE_SHIFT;
1757 if (curr_index <= page->index &&
1758 page->index < curr_index + old_req->num_pages) {
1759 found = true;
1760 break;
1761 }
1762 }
1763 if (!found) {
1764 list_add(&new_req->writepages_entry, &fi->writepages); 1762 list_add(&new_req->writepages_entry, &fi->writepages);
1765 goto out_unlock; 1763 spin_unlock(&fc->lock);
1764 return false;
1766 } 1765 }
1767 1766
1768 new_req->num_pages = 1; 1767 new_req->num_pages = 1;
@@ -1791,10 +1790,9 @@ static bool fuse_writepage_in_flight(struct fuse_req *new_req,
1791 new_req->misc.write.next = old_req->misc.write.next; 1790 new_req->misc.write.next = old_req->misc.write.next;
1792 old_req->misc.write.next = new_req; 1791 old_req->misc.write.next = new_req;
1793 } 1792 }
1794out_unlock:
1795 spin_unlock(&fc->lock); 1793 spin_unlock(&fc->lock);
1796out: 1794out:
1797 return found; 1795 return true;
1798} 1796}
1799 1797
1800static int fuse_writepages_fill(struct page *page, 1798static int fuse_writepages_fill(struct page *page,