* First we set the BLOCK_IO flag so no more ios will be * mapped. 
* First we set the BLOCK_IO flag so no more ios will be mapped. * * If the flag is already set we know another thread is trying to * suspend as well, so we leave the fs locked for this thread. 
int dm_suspend(struct mapped_device *md){	struct dm_table *map;	DECLARE_WAITQUEUE(wait, current);	/* Flush I/O to the device. */	down_read(&md->lock);	if (test_bit(DMF_BLOCK_IO, &md->flags)) {		up_read(&md->lock);		return -EINVAL;	}	map = dm_get_table(md);	if (map)		dm_table_presuspend_targets(map);	__lock_fs(md);	up_read(&md->lock);	/*	 * First we set the BLOCK_IO flag so no more ios will be	 * mapped.	 */	down_write(&md->lock);	if (test_bit(DMF_BLOCK_IO, &md->flags)) {		/*		 * If we get here we know another thread is		 * trying to suspend as well, so we leave the fs		 * locked for this thread.		 */		up_write(&md->lock);		return -EINVAL;	}	set_bit(DMF_BLOCK_IO, &md->flags);	add_wait_queue(&md->wait, &wait);	up_write(&md->lock);	/* unplug */	if (map) {		dm_table_unplug_all(map);		dm_table_put(map);	}	/*	 * Then we wait for the already mapped ios to	 * complete.	 */	while (1) {		set_current_state(TASK_INTERRUPTIBLE);		if (!atomic_read(&md->pending) || signal_pending(current))			break;		io_schedule();	}	set_current_state(TASK_RUNNING);	down_write(&md->lock);	remove_wait_queue(&md->wait, &wait);	/* were we interrupted ? */	if (atomic_read(&md->pending)) {		__unlock_fs(md);		clear_bit(DMF_BLOCK_IO, &md->flags);		up_write(&md->lock);		return -EINTR;	}	set_bit(DMF_SUSPENDED, &md->flags);	map = dm_get_table(md);	if (map)		dm_table_postsuspend_targets(map);	dm_table_put(map);	up_write(&md->lock);	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/354e007121de546e50b5592c2557575117435522/dm.c/buggy/drivers/md/dm.c