dm: add the pushback feature to the dm core
PATCH 6/7 dm: add the pushback feature to the dm core
This patch adds the pushback feature which can suspend and table swap without returning queued I/Os in targets to applications to the dm core.
Detail explanations are below.
======================================================================
Explanations of the patch
=-=-=-=-=-=-=-=-=-=-=-=-=-=
DMF_NOFLUSH_SUSPENDING
----------------------
If 'DM_NOFLUSH_FLAG' ioctl option is specified at suspend time, 'DMF_NOFLUSH_SUSPENDING' flag is set in md->flags at early stage of dm_suspend() and unset before returning from dm_suspend().
The flag must be visible during the target flushing pending I/Os, because the pushback feature is enabled only during the flag is set. So the flag is set before presuspend, where the flush starts, and unset after the wait for md->pending, where the flush ends.
Target drivers can check this flag by dm_noflush_suspending().
DM_MAPIO_REQUEUE / DM_ENDIO_REQUEUE
-----------------------------------
If DMF_NOFLUSH_SUSPENDING flag is set, target's map() function can return DM_MAPIO_REQUEUE to request the device mapper core to put the bio in queue.
Similarly, target's end_io() function can return DM_ENDIO_REQUEUE to request the same.
These requests are called 'pushback'.
The __map_bio() and clone_endio() in device mapper core treat these return values as error code and call dec_pending() to end the I/O.
dec_pending
-----------
The pushback request from target drivers are passed to dec_pending() as "error" argument.dec_pending() saves the pushback request in struct dm_io->error. Once the all splitted clones end, dec_pending() will check it and put the original bio to md->pushback list.
To avoid the dm_io->error is overwritten by other values, dec_pending() first checks if the dm_io->error is already set. So the pushback request supersede any I/O errors.
It is possible that the suspend with DM_NOFLUSH_FLAG is aborted after the flush started but before it ends (e.g. by user interrupt).dec_pending() checks it and returns EIO if it happens.
pushdback list and pushback_lock
--------------------------------
The bio which is requested to push back from target drivers is queued to md->pushback temporarily in dec_pending(), and after all pending I/Os return, md->pushback is merged to md->deferred in dm_suspend() for re-issuing at resume time.
md->pushback_lock protects md->pushback.
The lock should be held with irq disabled because dec_pending() can be called from interrupt context.
Queueing bios to md->pushback in dec_pending() must be done atomically with the check for 'DMF_NOFLUSH_SUSPENDING' flag. So md->pushback_lock is held when checking the flag. Otherwise, dec_pending() may queue a bio to md->pushback after the interrupted dm_suspend() flushes md->pushback. Then the bio will be left in md->pushback.
Flag setting in dm_suspend() can be done without md->pushback_lock, because the flag is checked only after presuspend and the set value is already made visible by the multipath presuspend.
The flag can be checked without md->pushback_lock (e.g. the first part of the dec_pending() or target drivers), because the flag is checked again with md->pushback_lock held when the bio is really queued to md->pushback as described above.
So even if the flag is cleared after the lock-less checkings, the bio isn't left in md->pushback. (It is returned to applications with EIO.)
Other notes in the current patch
--------------------------------
- md->pushback is added to the struct mapped_device instead of using md->deferred directly.
Because md->io_lock which protects md->deferred is rw_semaphore and can't be used in interrupt context like dec_pending(), and md->io_lock protects 'DMF_BLOCK_IO' flag of md->flags too.
- Don't issue lock_fs() in dm_suspend() if the 'DM_NOFLUSH_FLAG' ioctl option is specified, because I/Os for lock_fs() are pushed back and never return if no valid devices.
(See dm_suspend())
- If a error occurs in dm_suspend() after 'DMF_NOFLUSH_SUSPENDING' flag is set, md->pushback must be flushed because I/Os may be queued to the list already.
(See around 'flush_and_out:' label in dm_suspend())
======================================================================
Test results
=-=-=-=-=-=-=
I have tested by using multipath target with patch 7 (will be posted). Following tests are for regression/compatibility.
- I/Os succeed when valid paths are existing.
- I/Os fail when no valid paths and no queue_if_no_path setting.
- I/Os are queued in the multipath target when no valid paths and queue_if_no_path is set.
- The queued I/Os above fail when suspend is issued WITHOUT 'DM_NOFLUSH_FLAG' ioctl option.
I/Os spanning 2 multipath targets are as well.
Following tests are for normal code path of new pushback feature.
- Queued I/Os in the multipath target are flushed from the target but don't return when suspend is issued WITH 'DM_NOFLUSH_FLAG' ioctl option.
- The I/Os above are queued in the multipath target again when resume is issued WITHOUT path recovery.
The I/Os above succeed when resume is issued after path recovery or table load.
- Queued I/Os in the multipath target succeed when resume is issued WITH 'DM_NOFLUSH_FLAG' ioctl option after table load.
I/Os spanning 2 multipath targets are as well.
Following tests are for error code path of the new pushback feature.
- When the bdget_disk() fails in dm_suspned(), 'DMF_NOFLUSH_SUSPENDING' flag is cleared and already queued I/Os to the pushback list are flushed properly.
- When suspend with 'DM_NOFLUSH_FLAG' ioctl option is interrupted,
o I/Os which had already been queued to the pushback list at the time don't return, and are re-issued at resume time.
o I/Os which hadn't been returned at the time return with EIO.
======================================================================
Patch
=-=-=-=
The patch is for:
2.6.18-mm2 + patch 1-5
drivers/md/dm-bio-list.h +14 -0
@@ -44,6 +44,20 @@ static inline void bio_list_merge(struct bl->tail = bl2->tail; } +static inline void bio_list_merge_head (struct bio_list *bl, +struct bio_list *bl2) +{ +if (!bl2->head) +return ; + +if (bl->head) + bl2->tail->bi_next = bl->head; +else + bl->tail = bl2->tail; + + bl->head = bl2->head; +} +static inline struct bio *bio_list_pop (struct bio_list *bl) {struct bio *bio = bl->head;
drivers/md/dm.c +95 -10
207 lines not on this page · raw message
drivers/md/dm.h +2 -0
@@ -36,12 +36,14 @@* Definitions of return values from target end_io function. */ #define DM_ENDIO_INCOMPLETE 1 +#define DM_ENDIO_REQUEUE 2/* * Definitions of return values from target map function. */ #define DM_MAPIO_SUBMITTED 0#define DM_MAPIO_REMAPPED 1 +#define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE/* * Suspend feature flags
include/linux/device-mapper.h +3 -0
@@ -40,6 +40,7 @@ typedef void (*dm_dtr_fn) (struct dm_tar* < 0: error * = 0: The target will handle the io by resubmitting it later * = 1: simple remap complete +* = 2: The target wants to push back the io */ typedef int (*dm_map_fn ) (struct dm_target *ti,struct bio *bio,union map_info *map_context);
@@ -50,6 +51,7 @@ typedef int (*dm_map_fn) (struct dm_targ* 0 : ended successfully * 1 : for some reason the io has still not completed (eg, * multipath target might want to requeue a failed io). +* 2 : The target wants to push back the io */ typedef int (*dm_endio_fn) (struct dm_target *ti, struct bio *bio, int error,
@@ -188,6 +190,7 @@ int dm_wait_event(struct mapped_device *const char *dm_device_name (struct mapped_device *md);struct gendisk *dm_disk (struct mapped_device *md);int dm_suspended (struct mapped_device *md); +int dm_noflush_suspending (struct dm_target *ti);/* * Geometry functions.