/* If trans is not null, we'll do a friendly check for a transaction that is already flushing things and force the IO down ourselves.  */
int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct inode *inode)
/* If trans is not null, we'll do a friendly check for a transaction that is already flushing things and force the IO down ourselves.  */
int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct inode *inode)
{
	u64 last_mod;
	last_mod = max(BTRFS_I(inode)->generation, BTRFS_I(inode)->last_trans);
	if (last_mod < root->fs_info->last_trans_committed)
		return 0;
	if (trans && root->fs_info->running_transaction->blocked) {
		btrfs_wait_ordered_range(inode, 0, (u64)-1);
		return 0;
	}
	spin_lock(&root->fs_info->ordered_extent_lock);
	if (list_empty(&BTRFS_I(inode)->ordered_operations)) {
		list_add_tail(&BTRFS_I(inode)->ordered_operations,
			      &root->fs_info->ordered_operations);
	}
	spin_unlock(&root->fs_info->ordered_extent_lock);
	return 0;
}