/* This creates an orphan entry for the given inode in case something goes wrong in the middle of an unlink/truncate.  */
int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
/* This creates an orphan entry for the given inode in case something goes wrong in the middle of an unlink/truncate.  */
int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
{
	struct btrfs_root *root = BTRFS_I(inode)->root;
	int ret = 0;
	spin_lock(&root->list_lock);
	if (!list_empty(&BTRFS_I(inode)->i_orphan)) {
		spin_unlock(&root->list_lock);
		return 0;
	}
	list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list);
	spin_unlock(&root->list_lock);
	ret = btrfs_insert_orphan_item(trans, root, inode->i_ino);
	return ret;
}