2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
2008-04-24 20:43:52 +00:00
|
|
|
* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* This file is released under the LGPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_DEVICE_MAPPER_H
|
|
|
|
#define _LINUX_DEVICE_MAPPER_H
|
|
|
|
|
2008-04-24 20:43:35 +00:00
|
|
|
#include <linux/bio.h>
|
2008-07-21 11:00:37 +00:00
|
|
|
#include <linux/blkdev.h>
|
2008-04-24 20:43:35 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct dm_target;
|
|
|
|
struct dm_table;
|
2006-06-26 07:27:33 +00:00
|
|
|
struct mapped_device;
|
2008-07-21 11:00:37 +00:00
|
|
|
struct bio_vec;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
|
|
|
|
|
|
|
|
union map_info {
|
|
|
|
void *ptr;
|
|
|
|
unsigned long long ll;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In the constructor the target parameter will already have the
|
|
|
|
* table, type, begin and len fields filled in.
|
|
|
|
*/
|
|
|
|
typedef int (*dm_ctr_fn) (struct dm_target *target,
|
|
|
|
unsigned int argc, char **argv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The destructor doesn't need to free the dm_target, just
|
|
|
|
* anything hidden ti->private.
|
|
|
|
*/
|
|
|
|
typedef void (*dm_dtr_fn) (struct dm_target *ti);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The map function must return:
|
|
|
|
* < 0: error
|
|
|
|
* = 0: The target will handle the io by resubmitting it later
|
2006-12-08 10:41:05 +00:00
|
|
|
* = 1: simple remap complete
|
[PATCH] dm: suspend: add noflush pushback
In device-mapper I/O is sometimes queued within targets for later processing.
For example the multipath target can be configured to store I/O when no paths
are available instead of returning it -EIO.
This patch allows the device-mapper core to instruct a target to transfer the
contents of any such in-target queue back into the core. This frees up the
resources used by the target so the core can replace that target with an
alternative one and then resend the I/O to it. Without this patch the only
way to change the target in such circumstances involves returning the I/O with
an error back to the filesystem/application. In the multipath case, this
patch will let us add new paths for existing I/O to try after all the existing
paths have failed.
DMF_NOFLUSH_SUSPENDING
----------------------
If the DM_NOFLUSH_FLAG ioctl option is specified at suspend time, the
DMF_NOFLUSH_SUSPENDING flag is set in md->flags during dm_suspend(). It
is always cleared before dm_suspend() returns.
The flag must be visible while the target is flushing pending I/Os so it
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 calling dm_noflush_suspending().
DM_MAPIO_REQUEUE / DM_ENDIO_REQUEUE
-----------------------------------
A target's map() function can now return DM_MAPIO_REQUEUE to request the
device mapper core queue the bio.
Similarly, a target's end_io() function can return DM_ENDIO_REQUEUE to request
the same. This has been labelled 'pushback'.
The __map_bio() and clone_endio() functions in the core treat these return
values as errors and call dec_pending() to end the I/O.
dec_pending
-----------
dec_pending() saves the pushback request in struct dm_io->error. Once all
the split clones have ended, dec_pending() will put the original bio on
the md->pushback list. Note that this supercedes any I/O errors.
It is possible for the suspend with DM_NOFLUSH_FLAG to be aborted while
in progress (e.g. by user interrupt). dec_pending() checks for this and
returns -EIO if it happened.
pushdback list and pushback_lock
--------------------------------
The bio is queued on md->pushback temporarily in dec_pending(), and after
all pending I/Os return, md->pushback is merged into 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 would 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 via the target's presuspend function.
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 lockless
checkings, the bio isn't left in md->pushback but returned to applications
with -EIO.
Other notes on 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 the 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 generated by lock_fs() would be
pushed back and never return if there were no valid devices.
- If an error occurs in dm_suspend() after the DMF_NOFLUSH_SUSPENDING
flag is set, md->pushback must be flushed because I/Os may be queued to
the list already. (flush_and_out label in dm_suspend())
Test results
------------
I have tested using multipath target with the next patch.
The following tests are for regression/compatibility:
- I/Os succeed when valid paths exist;
- I/Os fail when there are no valid paths and queue_if_no_path is not
set;
- I/Os are queued in the multipath target when there are no valid paths and
queue_if_no_path is set;
- The queued I/Os above fail when suspend is issued without the
DM_NOFLUSH_FLAG ioctl option. I/Os spanning 2 multipath targets also
fail.
The following tests are for the 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 the 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 the DM_NOFLUSH_FLAG ioctl option after table load. I/Os
spanning 2 multipath targets also succeed.
The following tests are for the error paths of the new pushback feature:
- When the bdget_disk() fails in dm_suspend(), the
DMF_NOFLUSH_SUSPENDING flag is cleared and I/Os already queued to the
pushback list are flushed properly.
- When suspend with the 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.
Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:41:09 +00:00
|
|
|
* = 2: The target wants to push back the io
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
|
|
|
|
union map_info *map_context);
|
2009-01-06 03:05:07 +00:00
|
|
|
typedef int (*dm_map_request_fn) (struct dm_target *ti, struct request *clone,
|
|
|
|
union map_info *map_context);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns:
|
|
|
|
* < 0 : error (currently ignored)
|
|
|
|
* 0 : ended successfully
|
|
|
|
* 1 : for some reason the io has still not completed (eg,
|
|
|
|
* multipath target might want to requeue a failed io).
|
[PATCH] dm: suspend: add noflush pushback
In device-mapper I/O is sometimes queued within targets for later processing.
For example the multipath target can be configured to store I/O when no paths
are available instead of returning it -EIO.
This patch allows the device-mapper core to instruct a target to transfer the
contents of any such in-target queue back into the core. This frees up the
resources used by the target so the core can replace that target with an
alternative one and then resend the I/O to it. Without this patch the only
way to change the target in such circumstances involves returning the I/O with
an error back to the filesystem/application. In the multipath case, this
patch will let us add new paths for existing I/O to try after all the existing
paths have failed.
DMF_NOFLUSH_SUSPENDING
----------------------
If the DM_NOFLUSH_FLAG ioctl option is specified at suspend time, the
DMF_NOFLUSH_SUSPENDING flag is set in md->flags during dm_suspend(). It
is always cleared before dm_suspend() returns.
The flag must be visible while the target is flushing pending I/Os so it
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 calling dm_noflush_suspending().
DM_MAPIO_REQUEUE / DM_ENDIO_REQUEUE
-----------------------------------
A target's map() function can now return DM_MAPIO_REQUEUE to request the
device mapper core queue the bio.
Similarly, a target's end_io() function can return DM_ENDIO_REQUEUE to request
the same. This has been labelled 'pushback'.
The __map_bio() and clone_endio() functions in the core treat these return
values as errors and call dec_pending() to end the I/O.
dec_pending
-----------
dec_pending() saves the pushback request in struct dm_io->error. Once all
the split clones have ended, dec_pending() will put the original bio on
the md->pushback list. Note that this supercedes any I/O errors.
It is possible for the suspend with DM_NOFLUSH_FLAG to be aborted while
in progress (e.g. by user interrupt). dec_pending() checks for this and
returns -EIO if it happened.
pushdback list and pushback_lock
--------------------------------
The bio is queued on md->pushback temporarily in dec_pending(), and after
all pending I/Os return, md->pushback is merged into 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 would 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 via the target's presuspend function.
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 lockless
checkings, the bio isn't left in md->pushback but returned to applications
with -EIO.
Other notes on 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 the 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 generated by lock_fs() would be
pushed back and never return if there were no valid devices.
- If an error occurs in dm_suspend() after the DMF_NOFLUSH_SUSPENDING
flag is set, md->pushback must be flushed because I/Os may be queued to
the list already. (flush_and_out label in dm_suspend())
Test results
------------
I have tested using multipath target with the next patch.
The following tests are for regression/compatibility:
- I/Os succeed when valid paths exist;
- I/Os fail when there are no valid paths and queue_if_no_path is not
set;
- I/Os are queued in the multipath target when there are no valid paths and
queue_if_no_path is set;
- The queued I/Os above fail when suspend is issued without the
DM_NOFLUSH_FLAG ioctl option. I/Os spanning 2 multipath targets also
fail.
The following tests are for the 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 the 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 the DM_NOFLUSH_FLAG ioctl option after table load. I/Os
spanning 2 multipath targets also succeed.
The following tests are for the error paths of the new pushback feature:
- When the bdget_disk() fails in dm_suspend(), the
DMF_NOFLUSH_SUSPENDING flag is cleared and I/Os already queued to the
pushback list are flushed properly.
- When suspend with the 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.
Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:41:09 +00:00
|
|
|
* 2 : The target wants to push back the io
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
typedef int (*dm_endio_fn) (struct dm_target *ti,
|
|
|
|
struct bio *bio, int error,
|
|
|
|
union map_info *map_context);
|
2009-01-06 03:05:07 +00:00
|
|
|
typedef int (*dm_request_endio_fn) (struct dm_target *ti,
|
|
|
|
struct request *clone, int error,
|
|
|
|
union map_info *map_context);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-10-03 08:15:43 +00:00
|
|
|
typedef void (*dm_flush_fn) (struct dm_target *ti);
|
2005-04-16 22:20:36 +00:00
|
|
|
typedef void (*dm_presuspend_fn) (struct dm_target *ti);
|
|
|
|
typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
|
2006-10-03 08:15:36 +00:00
|
|
|
typedef int (*dm_preresume_fn) (struct dm_target *ti);
|
2005-04-16 22:20:36 +00:00
|
|
|
typedef void (*dm_resume_fn) (struct dm_target *ti);
|
|
|
|
|
|
|
|
typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
|
|
|
|
char *result, unsigned int maxlen);
|
|
|
|
|
|
|
|
typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
|
|
|
|
|
2007-08-29 02:15:59 +00:00
|
|
|
typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
|
2006-10-03 08:15:15 +00:00
|
|
|
unsigned long arg);
|
|
|
|
|
2008-07-21 11:00:37 +00:00
|
|
|
typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
|
|
|
|
struct bio_vec *biovec, int max_size);
|
|
|
|
|
2009-01-06 03:05:07 +00:00
|
|
|
/*
|
|
|
|
* Returns:
|
|
|
|
* 0: The target can handle the next I/O immediately.
|
|
|
|
* 1: The target can't handle the next I/O immediately.
|
|
|
|
*/
|
|
|
|
typedef int (*dm_busy_fn) (struct dm_target *ti);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void dm_error(const char *message);
|
|
|
|
|
2006-10-03 08:15:42 +00:00
|
|
|
/*
|
|
|
|
* Combine device limits.
|
|
|
|
*/
|
|
|
|
void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
|
|
|
|
|
2008-10-10 12:37:09 +00:00
|
|
|
struct dm_dev {
|
|
|
|
struct block_device *bdev;
|
2008-09-02 19:28:45 +00:00
|
|
|
fmode_t mode;
|
2008-10-10 12:37:09 +00:00
|
|
|
char name[16];
|
|
|
|
};
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Constructors should call these functions to ensure destination devices
|
|
|
|
* are opened/closed correctly.
|
|
|
|
* FIXME: too many arguments.
|
|
|
|
*/
|
|
|
|
int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
|
2008-09-02 19:28:45 +00:00
|
|
|
sector_t len, fmode_t mode, struct dm_dev **result);
|
2005-04-16 22:20:36 +00:00
|
|
|
void dm_put_device(struct dm_target *ti, struct dm_dev *d);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Information about a target type
|
|
|
|
*/
|
2009-01-06 03:05:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Target features
|
|
|
|
*/
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
struct target_type {
|
2009-01-06 03:05:09 +00:00
|
|
|
uint64_t features;
|
2005-04-16 22:20:36 +00:00
|
|
|
const char *name;
|
|
|
|
struct module *module;
|
2006-06-26 07:27:33 +00:00
|
|
|
unsigned version[3];
|
2005-04-16 22:20:36 +00:00
|
|
|
dm_ctr_fn ctr;
|
|
|
|
dm_dtr_fn dtr;
|
|
|
|
dm_map_fn map;
|
2009-01-06 03:05:07 +00:00
|
|
|
dm_map_request_fn map_rq;
|
2005-04-16 22:20:36 +00:00
|
|
|
dm_endio_fn end_io;
|
2009-01-06 03:05:07 +00:00
|
|
|
dm_request_endio_fn rq_end_io;
|
2006-10-03 08:15:43 +00:00
|
|
|
dm_flush_fn flush;
|
2005-04-16 22:20:36 +00:00
|
|
|
dm_presuspend_fn presuspend;
|
|
|
|
dm_postsuspend_fn postsuspend;
|
2006-10-03 08:15:36 +00:00
|
|
|
dm_preresume_fn preresume;
|
2005-04-16 22:20:36 +00:00
|
|
|
dm_resume_fn resume;
|
|
|
|
dm_status_fn status;
|
|
|
|
dm_message_fn message;
|
2006-10-03 08:15:15 +00:00
|
|
|
dm_ioctl_fn ioctl;
|
2008-07-21 11:00:37 +00:00
|
|
|
dm_merge_fn merge;
|
2009-01-06 03:05:07 +00:00
|
|
|
dm_busy_fn busy;
|
2009-04-02 18:55:28 +00:00
|
|
|
|
|
|
|
/* For internal device-mapper use. */
|
|
|
|
struct list_head list;
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct io_restrictions {
|
2008-02-08 02:10:01 +00:00
|
|
|
unsigned long bounce_pfn;
|
|
|
|
unsigned long seg_boundary_mask;
|
|
|
|
unsigned max_hw_sectors;
|
|
|
|
unsigned max_sectors;
|
|
|
|
unsigned max_segment_size;
|
|
|
|
unsigned short hardsect_size;
|
|
|
|
unsigned short max_hw_segments;
|
|
|
|
unsigned short max_phys_segments;
|
|
|
|
unsigned char no_cluster; /* inverted so that 0 is default */
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dm_target {
|
|
|
|
struct dm_table *table;
|
|
|
|
struct target_type *type;
|
|
|
|
|
|
|
|
/* target limits */
|
|
|
|
sector_t begin;
|
|
|
|
sector_t len;
|
|
|
|
|
|
|
|
/* FIXME: turn this into a mask, and merge with io_restrictions */
|
|
|
|
/* Always a power of 2 */
|
|
|
|
sector_t split_io;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are automatically filled in by
|
|
|
|
* dm_table_get_device.
|
|
|
|
*/
|
|
|
|
struct io_restrictions limits;
|
|
|
|
|
|
|
|
/* target specific data */
|
|
|
|
void *private;
|
|
|
|
|
|
|
|
/* Used to provide an error string from the ctr */
|
|
|
|
char *error;
|
|
|
|
};
|
|
|
|
|
|
|
|
int dm_register_target(struct target_type *t);
|
2009-01-06 03:04:58 +00:00
|
|
|
void dm_unregister_target(struct target_type *t);
|
2006-06-26 07:27:33 +00:00
|
|
|
|
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* Functions for creating and manipulating mapped devices.
|
|
|
|
* Drop the reference with dm_put when you finish with the object.
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DM_ANY_MINOR chooses the next available minor number.
|
|
|
|
*/
|
|
|
|
#define DM_ANY_MINOR (-1)
|
|
|
|
int dm_create(int minor, struct mapped_device **md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reference counting for md.
|
|
|
|
*/
|
|
|
|
struct mapped_device *dm_get_md(dev_t dev);
|
|
|
|
void dm_get(struct mapped_device *md);
|
|
|
|
void dm_put(struct mapped_device *md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An arbitrary pointer may be stored alongside a mapped device.
|
|
|
|
*/
|
|
|
|
void dm_set_mdptr(struct mapped_device *md, void *ptr);
|
|
|
|
void *dm_get_mdptr(struct mapped_device *md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A device can still be used while suspended, but I/O is deferred.
|
|
|
|
*/
|
2006-12-08 10:41:04 +00:00
|
|
|
int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
|
2006-06-26 07:27:33 +00:00
|
|
|
int dm_resume(struct mapped_device *md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Event functions.
|
|
|
|
*/
|
|
|
|
uint32_t dm_get_event_nr(struct mapped_device *md);
|
|
|
|
int dm_wait_event(struct mapped_device *md, int event_nr);
|
2007-10-19 21:48:01 +00:00
|
|
|
uint32_t dm_next_uevent_seq(struct mapped_device *md);
|
|
|
|
void dm_uevent_add(struct mapped_device *md, struct list_head *elist);
|
2006-06-26 07:27:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Info functions.
|
|
|
|
*/
|
2006-06-26 07:27:35 +00:00
|
|
|
const char *dm_device_name(struct mapped_device *md);
|
2007-10-19 21:47:59 +00:00
|
|
|
int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
|
2006-06-26 07:27:33 +00:00
|
|
|
struct gendisk *dm_disk(struct mapped_device *md);
|
|
|
|
int dm_suspended(struct mapped_device *md);
|
[PATCH] dm: suspend: add noflush pushback
In device-mapper I/O is sometimes queued within targets for later processing.
For example the multipath target can be configured to store I/O when no paths
are available instead of returning it -EIO.
This patch allows the device-mapper core to instruct a target to transfer the
contents of any such in-target queue back into the core. This frees up the
resources used by the target so the core can replace that target with an
alternative one and then resend the I/O to it. Without this patch the only
way to change the target in such circumstances involves returning the I/O with
an error back to the filesystem/application. In the multipath case, this
patch will let us add new paths for existing I/O to try after all the existing
paths have failed.
DMF_NOFLUSH_SUSPENDING
----------------------
If the DM_NOFLUSH_FLAG ioctl option is specified at suspend time, the
DMF_NOFLUSH_SUSPENDING flag is set in md->flags during dm_suspend(). It
is always cleared before dm_suspend() returns.
The flag must be visible while the target is flushing pending I/Os so it
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 calling dm_noflush_suspending().
DM_MAPIO_REQUEUE / DM_ENDIO_REQUEUE
-----------------------------------
A target's map() function can now return DM_MAPIO_REQUEUE to request the
device mapper core queue the bio.
Similarly, a target's end_io() function can return DM_ENDIO_REQUEUE to request
the same. This has been labelled 'pushback'.
The __map_bio() and clone_endio() functions in the core treat these return
values as errors and call dec_pending() to end the I/O.
dec_pending
-----------
dec_pending() saves the pushback request in struct dm_io->error. Once all
the split clones have ended, dec_pending() will put the original bio on
the md->pushback list. Note that this supercedes any I/O errors.
It is possible for the suspend with DM_NOFLUSH_FLAG to be aborted while
in progress (e.g. by user interrupt). dec_pending() checks for this and
returns -EIO if it happened.
pushdback list and pushback_lock
--------------------------------
The bio is queued on md->pushback temporarily in dec_pending(), and after
all pending I/Os return, md->pushback is merged into 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 would 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 via the target's presuspend function.
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 lockless
checkings, the bio isn't left in md->pushback but returned to applications
with -EIO.
Other notes on 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 the 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 generated by lock_fs() would be
pushed back and never return if there were no valid devices.
- If an error occurs in dm_suspend() after the DMF_NOFLUSH_SUSPENDING
flag is set, md->pushback must be flushed because I/Os may be queued to
the list already. (flush_and_out label in dm_suspend())
Test results
------------
I have tested using multipath target with the next patch.
The following tests are for regression/compatibility:
- I/Os succeed when valid paths exist;
- I/Os fail when there are no valid paths and queue_if_no_path is not
set;
- I/Os are queued in the multipath target when there are no valid paths and
queue_if_no_path is set;
- The queued I/Os above fail when suspend is issued without the
DM_NOFLUSH_FLAG ioctl option. I/Os spanning 2 multipath targets also
fail.
The following tests are for the 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 the 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 the DM_NOFLUSH_FLAG ioctl option after table load. I/Os
spanning 2 multipath targets also succeed.
The following tests are for the error paths of the new pushback feature:
- When the bdget_disk() fails in dm_suspend(), the
DMF_NOFLUSH_SUSPENDING flag is cleared and I/Os already queued to the
pushback list are flushed properly.
- When suspend with the 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.
Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-12-08 10:41:09 +00:00
|
|
|
int dm_noflush_suspending(struct dm_target *ti);
|
2008-10-10 12:37:10 +00:00
|
|
|
union map_info *dm_get_mapinfo(struct bio *bio);
|
2006-06-26 07:27:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Geometry functions.
|
|
|
|
*/
|
|
|
|
int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo);
|
|
|
|
int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* Functions for manipulating device-mapper tables.
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First create an empty table.
|
|
|
|
*/
|
2008-09-02 19:28:45 +00:00
|
|
|
int dm_table_create(struct dm_table **result, fmode_t mode,
|
2006-06-26 07:27:33 +00:00
|
|
|
unsigned num_targets, struct mapped_device *md);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Then call this once for each target.
|
|
|
|
*/
|
|
|
|
int dm_table_add_target(struct dm_table *t, const char *type,
|
|
|
|
sector_t start, sector_t len, char *params);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally call this to make the table ready for use.
|
|
|
|
*/
|
|
|
|
int dm_table_complete(struct dm_table *t);
|
|
|
|
|
2008-10-10 12:37:11 +00:00
|
|
|
/*
|
|
|
|
* Unplug all devices in a table.
|
|
|
|
*/
|
|
|
|
void dm_table_unplug_all(struct dm_table *t);
|
|
|
|
|
2006-06-26 07:27:33 +00:00
|
|
|
/*
|
|
|
|
* Table reference counting.
|
|
|
|
*/
|
|
|
|
struct dm_table *dm_get_table(struct mapped_device *md);
|
|
|
|
void dm_table_get(struct dm_table *t);
|
|
|
|
void dm_table_put(struct dm_table *t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queries
|
|
|
|
*/
|
|
|
|
sector_t dm_table_get_size(struct dm_table *t);
|
|
|
|
unsigned int dm_table_get_num_targets(struct dm_table *t);
|
2008-09-02 19:28:45 +00:00
|
|
|
fmode_t dm_table_get_mode(struct dm_table *t);
|
2006-06-26 07:27:33 +00:00
|
|
|
struct mapped_device *dm_table_get_md(struct dm_table *t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger an event.
|
|
|
|
*/
|
|
|
|
void dm_table_event(struct dm_table *t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The device must be suspended before calling this method.
|
|
|
|
*/
|
|
|
|
int dm_swap_table(struct mapped_device *md, struct dm_table *t);
|
|
|
|
|
2008-10-10 12:37:12 +00:00
|
|
|
/*
|
|
|
|
* A wrapper around vmalloc.
|
|
|
|
*/
|
|
|
|
void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
|
|
|
|
|
2008-04-24 20:43:52 +00:00
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* Macros.
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
#define DM_NAME "device-mapper"
|
|
|
|
|
2009-01-06 03:04:58 +00:00
|
|
|
#define DMCRIT(f, arg...) \
|
|
|
|
printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
|
2008-04-24 20:43:52 +00:00
|
|
|
#define DMERR(f, arg...) \
|
|
|
|
printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
#define DMERR_LIMIT(f, arg...) \
|
|
|
|
do { \
|
|
|
|
if (printk_ratelimit()) \
|
|
|
|
printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " \
|
|
|
|
f "\n", ## arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DMWARN(f, arg...) \
|
|
|
|
printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
#define DMWARN_LIMIT(f, arg...) \
|
|
|
|
do { \
|
|
|
|
if (printk_ratelimit()) \
|
|
|
|
printk(KERN_WARNING DM_NAME ": " DM_MSG_PREFIX ": " \
|
|
|
|
f "\n", ## arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DMINFO(f, arg...) \
|
|
|
|
printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
#define DMINFO_LIMIT(f, arg...) \
|
|
|
|
do { \
|
|
|
|
if (printk_ratelimit()) \
|
|
|
|
printk(KERN_INFO DM_NAME ": " DM_MSG_PREFIX ": " f \
|
|
|
|
"\n", ## arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_DEBUG
|
|
|
|
# define DMDEBUG(f, arg...) \
|
|
|
|
printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX " DEBUG: " f "\n", ## arg)
|
|
|
|
# define DMDEBUG_LIMIT(f, arg...) \
|
|
|
|
do { \
|
|
|
|
if (printk_ratelimit()) \
|
|
|
|
printk(KERN_DEBUG DM_NAME ": " DM_MSG_PREFIX ": " f \
|
|
|
|
"\n", ## arg); \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
# define DMDEBUG(f, arg...) do {} while (0)
|
|
|
|
# define DMDEBUG_LIMIT(f, arg...) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DMEMIT(x...) sz += ((sz >= maxlen) ? \
|
|
|
|
0 : scnprintf(result + sz, maxlen - sz, x))
|
|
|
|
|
|
|
|
#define SECTOR_SHIFT 9
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ceiling(n / sz)
|
|
|
|
*/
|
|
|
|
#define dm_div_up(n, sz) (((n) + (sz) - 1) / (sz))
|
|
|
|
|
|
|
|
#define dm_sector_div_up(n, sz) ( \
|
|
|
|
{ \
|
|
|
|
sector_t _r = ((n) + (sz) - 1); \
|
|
|
|
sector_div(_r, (sz)); \
|
|
|
|
_r; \
|
|
|
|
} \
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ceiling(n / size) * size
|
|
|
|
*/
|
|
|
|
#define dm_round_up(n, sz) (dm_div_up((n), (sz)) * (sz))
|
|
|
|
|
2008-10-21 16:44:57 +00:00
|
|
|
#define dm_array_too_big(fixed, obj, num) \
|
|
|
|
((num) > (UINT_MAX - (fixed)) / (obj))
|
|
|
|
|
2008-04-24 20:43:52 +00:00
|
|
|
static inline sector_t to_sector(unsigned long n)
|
|
|
|
{
|
|
|
|
return (n >> SECTOR_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long to_bytes(sector_t n)
|
|
|
|
{
|
|
|
|
return (n << SECTOR_SHIFT);
|
|
|
|
}
|
|
|
|
|
2006-06-26 07:27:33 +00:00
|
|
|
#endif /* _LINUX_DEVICE_MAPPER_H */
|