--- /dev/null
+From b2acdddfad13c38a1e8b927d83c3cf321f63601a Mon Sep 17 00:00:00 2001
+From: Anand Jain <anand.jain@oracle.com>
+Date: Wed, 7 Oct 2015 17:23:23 +0800
+Subject: Btrfs: add missing brelse when superblock checksum fails
+
+From: Anand Jain <anand.jain@oracle.com>
+
+commit b2acdddfad13c38a1e8b927d83c3cf321f63601a upstream.
+
+Looks like oversight, call brelse() when checksum fails. Further down the
+code, in the non error path, we do call brelse() and so we don't see
+brelse() in the goto error paths.
+
+Signed-off-by: Anand Jain <anand.jain@oracle.com>
+Reviewed-by: David Sterba <dsterba@suse.com>
+Signed-off-by: David Sterba <dsterba@suse.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/btrfs/disk-io.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/fs/btrfs/disk-io.c
++++ b/fs/btrfs/disk-io.c
+@@ -2336,6 +2336,7 @@ int open_ctree(struct super_block *sb,
+ if (btrfs_check_super_csum(bh->b_data)) {
+ printk(KERN_ERR "BTRFS: superblock checksum mismatch\n");
+ err = -EINVAL;
++ brelse(bh);
+ goto fail_alloc;
+ }
+
--- /dev/null
+From 9269d12b2d57d9e3d13036bb750762d1110d425c Mon Sep 17 00:00:00 2001
+From: Filipe Manana <fdmanana@suse.com>
+Date: Thu, 31 Dec 2015 18:16:29 +0000
+Subject: Btrfs: fix number of transaction units required to create symlink
+
+From: Filipe Manana <fdmanana@suse.com>
+
+commit 9269d12b2d57d9e3d13036bb750762d1110d425c upstream.
+
+We weren't accounting for the insertion of an inline extent item for the
+symlink inode nor that we need to update the parent inode item (through
+the call to btrfs_add_nondir()). So fix this by including two more
+transaction units.
+
+Signed-off-by: Filipe Manana <fdmanana@suse.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/btrfs/inode.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+--- a/fs/btrfs/inode.c
++++ b/fs/btrfs/inode.c
+@@ -8625,9 +8625,11 @@ static int btrfs_symlink(struct inode *d
+ /*
+ * 2 items for inode item and ref
+ * 2 items for dir items
++ * 1 item for updating parent inode item
++ * 1 item for the inline extent item
+ * 1 item for xattr if selinux is on
+ */
+- trans = btrfs_start_transaction(root, 5);
++ trans = btrfs_start_transaction(root, 7);
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
+
--- /dev/null
+From be7bd730841e69fe8f70120098596f648cd1f3ff Mon Sep 17 00:00:00 2001
+From: Josef Bacik <jbacik@fb.com>
+Date: Thu, 22 Oct 2015 15:05:09 -0400
+Subject: Btrfs: igrab inode in writepage
+
+From: Josef Bacik <jbacik@fb.com>
+
+commit be7bd730841e69fe8f70120098596f648cd1f3ff upstream.
+
+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 <jbacik@fb.com>
+Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
+Signed-off-by: David Sterba <dsterba@suse.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/btrfs/inode.c | 17 +++++++++++++++--
+ 1 file changed, 15 insertions(+), 2 deletions(-)
+
+--- a/fs/btrfs/inode.c
++++ b/fs/btrfs/inode.c
+@@ -7511,15 +7511,28 @@ int btrfs_readpage(struct file *file, st
+ 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,
--- /dev/null
+From a879719b8c90e15c9e7fa7266d5e3c0ca962f9df Mon Sep 17 00:00:00 2001
+From: Filipe Manana <fdmanana@suse.com>
+Date: Thu, 31 Dec 2015 18:07:59 +0000
+Subject: Btrfs: send, don't BUG_ON() when an empty symlink is found
+
+From: Filipe Manana <fdmanana@suse.com>
+
+commit a879719b8c90e15c9e7fa7266d5e3c0ca962f9df upstream.
+
+When a symlink is successfully created it always has an inline extent
+containing the source path. However if an error happens when creating
+the symlink, we can leave in the subvolume's tree a symlink inode without
+any such inline extent item - this happens if after btrfs_symlink() calls
+btrfs_end_transaction() and before it calls the inode eviction handler
+(through the final iput() call), the transaction gets committed and a
+crash happens before the eviction handler gets called, or if a snapshot
+of the subvolume is made before the eviction handler gets called. Sadly
+we can't just avoid this by making btrfs_symlink() call
+btrfs_end_transaction() after it calls the eviction handler, because the
+later can commit the current transaction before it removes any items from
+the subvolume tree (if it encounters ENOSPC errors while reserving space
+for removing all the items).
+
+So make send fail more gracefully, with an -EIO error, and print a
+message to dmesg/syslog informing that there's an empty symlink inode,
+so that the user can delete the empty symlink or do something else
+about it.
+
+Reported-by: Stephen R. van den Berg <srb@cuci.nl>
+Signed-off-by: Filipe Manana <fdmanana@suse.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ fs/btrfs/send.c | 16 +++++++++++++++-
+ 1 file changed, 15 insertions(+), 1 deletion(-)
+
+--- a/fs/btrfs/send.c
++++ b/fs/btrfs/send.c
+@@ -1377,7 +1377,21 @@ static int read_symlink(struct btrfs_roo
+ ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
+ if (ret < 0)
+ goto out;
+- BUG_ON(ret);
++ if (ret) {
++ /*
++ * An empty symlink inode. Can happen in rare error paths when
++ * creating a symlink (transaction committed before the inode
++ * eviction handler removed the symlink inode items and a crash
++ * happened in between or the subvol was snapshoted in between).
++ * Print an informative message to dmesg/syslog so that the user
++ * can delete the symlink.
++ */
++ btrfs_err(root->fs_info,
++ "Found empty symlink inode %llu at root %llu",
++ ino, root->root_key.objectid);
++ ret = -EIO;
++ goto out;
++ }
+
+ ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
+ struct btrfs_file_extent_item);
ses-fix-additional-element-traversal-bug.patch
powercap-rapl-fix-bios-lock-check.patch
scripts-recordmcount-break-hardlinks.patch
+btrfs-add-missing-brelse-when-superblock-checksum-fails.patch
+btrfs-igrab-inode-in-writepage.patch
+btrfs-send-don-t-bug_on-when-an-empty-symlink-is-found.patch
+btrfs-fix-number-of-transaction-units-required-to-create-symlink.patch