Btrfs: Fix super block updates during transaction commit

The super block written during commit was not consistent with the state of
the trees.  This change adds an in-memory copy of the super so that we can
make sure to write out consistent data during a commit.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index a5a63d4..3b2face 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -380,6 +380,12 @@
 		else
 			prev_trans->use_count++;
 	}
+	btrfs_set_super_generation(&root->fs_info->super_copy,
+				   cur_trans->transid);
+	btrfs_set_super_root(&root->fs_info->super_copy,
+			     bh_blocknr(root->fs_info->tree_root->node));
+	memcpy(root->fs_info->disk_super, &root->fs_info->super_copy,
+	       sizeof(root->fs_info->super_copy));
 	mutex_unlock(&root->fs_info->trans_mutex);
 	mutex_unlock(&root->fs_info->fs_mutex);
 	ret = btrfs_write_and_wait_transaction(trans, root);
@@ -389,8 +395,6 @@
 		put_transaction(prev_trans);
 		mutex_unlock(&root->fs_info->trans_mutex);
 	}
-	btrfs_set_super_generation(root->fs_info->disk_super,
-				   cur_trans->transid);
 	BUG_ON(ret);
 	write_ctree_super(trans, root);