/* This upgrades the mode on an already open dm_dev, being careful to leave things as they were if we fail to reopen the device and not to touch the existing bdev field in case it is accessed concurrently inside dm_table_any_congested().  */
static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode, struct mapped_device *md)
/* This upgrades the mode on an already open dm_dev, being careful to leave things as they were if we fail to reopen the device and not to touch the existing bdev field in case it is accessed concurrently inside dm_table_any_congested().  */
static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode, struct mapped_device *md)
{
	int r;
	struct dm_dev_internal dd_new, dd_old;
	dd_new = dd_old = *dd;
	dd_new.dm_dev.mode |= new_mode;
	dd_new.dm_dev.bdev = NULL;
	r = open_dev(&dd_new, dd->dm_dev.bdev->bd_dev, md);
	if (r)
		return r;
	dd->dm_dev.mode |= new_mode;
	close_dev(&dd_old, md);
	return 0;
}