Skip to contentSkip to conversation

Flush deferred queue when dm_suspend() is interrupted

PATCH In review Jun'ichi Nomura 2 participants 2 messages Mar 9, 2006 – Mar 12, 2006 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Flush deferred queue when dm_suspend() is interrupted

Hello,

I found in a code review that dm_suspend() doesn't flush deferred queue when it's interrupted and failed to suspend.

Attached patch theoretically fixes this problem. But I don't have a testcase to pick this point and would like to hear comment from others whether there is something to prevent this.

Also, modifying DMF_BLOCK_IO outside of io_lock may cause a race like this:
CPU0 (dm_suspend) CPU1 (dm_request)
-------------------------------------------------
set_bit(DMF_BLOCK_IO)
...
up_write(io_lock)
down_read(io_lock) test_bit(DMF_BLOCK_IO) up_read(io_lock) queue_io(deferred)
down_write(io_lock) test_bit(DMF_BLOCK_IO) up_write(io_lock)
clear_bit(DMF_BLOCK_IO)

The deferred I/O never be flushed until dm_resume().

For the failed dm_suspend() case, there is another problem that presuspend is not reverted.
It may require a new method like suspend_cancel() for any target which implements presuspend().

I would appreicate a comment for this as well.

Thanks,

Signature · 1 line
Jun'ichi Nomura, NEC Solutions (America), Inc.

When dm_suspend() is interrupted, it's possible that some bios are queued to deferred list.
DMF_BLOCK_IO modification must be protected by io->lock.

drivers/md/dm.c +2 -1
@@ -1152,9 +1152,10 @@ int dm_suspend(struct mapped_device *md,
 	/* were we interrupted ? */
 	r = -EINTR;
 	if (atomic_read(&md->pending)) {
+		clear_bit(DMF_BLOCK_IO, &md->flags);
+		__flush_deferred_io(md, bio_list_get(&md->deferred));
 		up_write(&md->io_lock);
 		unlock_fs(md);
-		clear_bit(DMF_BLOCK_IO, &md->flags);
 		goto out;
 	}
 	up_write(&md->io_lock);
#1 lore raw
Quoted 2 lines · Jun'ichi Nomura

I found in a code review that dm_suspend() doesn't flush deferred queue when it's interrupted and failed to suspend.

Yup - adding to tree.

Quoted 1 line

But I don't have a testcase to pick this point

Suspend the device below & issue I/O so the loop won't exit until you abort the suspend. That's the reason for that code.

Quoted 2 lines

For the failed dm_suspend() case, there is another problem that presuspend is not reverted.

Not a problem yet: no user of that should do anything that needs reverting should suspension fail, as per the comment (not a FIXME):

       /* This does not get reverted if there's an error later. */

If new targets or enhancements need new hooks then of course we can consider adding them when the need arises.

Alasdair

Signature · 1 line
[email protected]