/* Swap in a new table, returning the old one for the caller to destroy.  */
struct dm_table* dm_swap_table(struct mapped_device *md, struct dm_table *table)
/* Swap in a new table, returning the old one for the caller to destroy.  */
struct dm_table* dm_swap_table(struct mapped_device *md, struct dm_table *table)
{
	struct dm_table *map = ERR_PTR(-EINVAL);
	struct queue_limits limits;
	int r;
	mutex_lock(&md->suspend_lock);
	if (!dm_suspended_md(md))
		goto out;
	r = dm_calculate_queue_limits(table, &limits);
	if (r) {
		map = ERR_PTR(r);
		goto out;
	}
	if (md->map &&
	    (dm_table_get_type(md->map) != dm_table_get_type(table))) {
		DMWARN("can't change the device type after a table is bound");
		goto out;
	}
	map = __bind(md, table, &limits);
out:
	mutex_unlock(&md->suspend_lock);
	return map;
}