+int btrfs_wait_ordered_extents(struct btrfs_root *root)
+{
+ struct list_head splice;
+ struct list_head *cur;
+ struct btrfs_ordered_extent *ordered;
+ struct inode *inode;
+
+ INIT_LIST_HEAD(&splice);
+
+ spin_lock(&root->fs_info->ordered_extent_lock);
+ list_splice_init(&root->fs_info->ordered_extents, &splice);
+ while(!list_empty(&splice)) {
+ cur = splice.next;
+ ordered = list_entry(cur, struct btrfs_ordered_extent,
+ root_extent_list);
+ list_del_init(&ordered->root_extent_list);
+ atomic_inc(&ordered->refs);
+ inode = ordered->inode;
+
+ /*
+ * the inode can't go away until all the pages are gone
+ * and the pages won't go away while there is still
+ * an ordered extent and the ordered extent won't go
+ * away until it is off this list. So, we can safely
+ * increment i_count here and call iput later
+ */
+ atomic_inc(&inode->i_count);
+ spin_unlock(&root->fs_info->ordered_extent_lock);
+
+ btrfs_start_ordered_extent(inode, ordered, 1);
+ btrfs_put_ordered_extent(ordered);
+ iput(inode);
+
+ spin_lock(&root->fs_info->ordered_extent_lock);
+ }
+ spin_unlock(&root->fs_info->ordered_extent_lock);
+ return 0;
+}
+