From: Josef Bacik Date: Thu, 22 Oct 2015 19:05:09 +0000 (-0400) Subject: Btrfs: igrab inode in writepage X-Git-Tag: v4.1.12-92~150^2~115 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=33455813642800b3ea3298e774d1dd340cc6c678;p=users%2Fjedix%2Flinux-maple.git Btrfs: igrab inode in writepage Orabug: 23331024 [ Upstream commit be7bd730841e69fe8f70120098596f648cd1f3ff ] We hit this panic on a few of our boxes this week where we have an ordered_extent with an NULL inode. We do an igrab() of the inode in writepages, but weren't doing it in writepage which can be called directly from the VM on dirty pages. If the inode has been unlinked then we could have I_FREEING set which means igrab() would return NULL and we get this panic. Fix this by trying to igrab in btrfs_writepage, and if it returns NULL then just redirty the page and return AOP_WRITEPAGE_ACTIVATE; so the VM knows it wasn't successful. Thanks, Signed-off-by: Josef Bacik Reviewed-by: Liu Bo Signed-off-by: David Sterba Signed-off-by: Sasha Levin (cherry picked from commit bb055e837f904fdc80d4d82819b0a9aaf35dce4a) Signed-off-by: Dan Duval --- diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index f4bb01dd852f..1cfa27b3e6f1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8415,15 +8415,28 @@ int btrfs_readpage(struct file *file, struct page *page) static int btrfs_writepage(struct page *page, struct writeback_control *wbc) { struct extent_io_tree *tree; - + struct inode *inode = page->mapping->host; + int ret; if (current->flags & PF_MEMALLOC) { redirty_page_for_writepage(wbc, page); unlock_page(page); return 0; } + + /* + * If we are under memory pressure we will call this directly from the + * VM, we need to make sure we have the inode referenced for the ordered + * extent. If not just return like we didn't do anything. + */ + if (!igrab(inode)) { + redirty_page_for_writepage(wbc, page); + return AOP_WRITEPAGE_ACTIVATE; + } tree = &BTRFS_I(page->mapping->host)->io_tree; - return extent_write_full_page(tree, page, btrfs_get_extent, wbc); + ret = extent_write_full_page(tree, page, btrfs_get_extent, wbc); + btrfs_add_delayed_iput(inode); + return ret; } static int btrfs_writepages(struct address_space *mapping,