2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
2008-04-25 03:43:52 +07:00
|
|
|
* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* This file is released under the LGPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_DEVICE_MAPPER_H
|
|
|
|
#define _LINUX_DEVICE_MAPPER_H
|
|
|
|
|
2008-04-25 03:43:35 +07:00
|
|
|
#include <linux/bio.h>
|
2008-07-21 18:00:37 +07:00
|
|
|
#include <linux/blkdev.h>
|
2013-08-16 21:54:23 +07:00
|
|
|
#include <linux/math64.h>
|
2011-11-01 03:18:54 +07:00
|
|
|
#include <linux/ratelimit.h>
|
2008-04-25 03:43:35 +07:00
|
|
|
|
2009-06-22 16:12:33 +07:00
|
|
|
struct dm_dev;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct dm_target;
|
|
|
|
struct dm_table;
|
2006-06-26 14:27:33 +07:00
|
|
|
struct mapped_device;
|
2008-07-21 18:00:37 +07:00
|
|
|
struct bio_vec;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2016-05-25 08:16:51 +07:00
|
|
|
/*
|
|
|
|
* Type of table, mapped_device's mempool and request_queue
|
|
|
|
*/
|
|
|
|
#define DM_TYPE_NONE 0
|
|
|
|
#define DM_TYPE_BIO_BASED 1
|
|
|
|
#define DM_TYPE_REQUEST_BASED 2
|
|
|
|
#define DM_TYPE_MQ_REQUEST_BASED 3
|
2016-06-23 06:54:53 +07:00
|
|
|
#define DM_TYPE_DAX_BIO_BASED 4
|
2016-05-25 08:16:51 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
typedef enum { STATUSTYPE_INFO, STATUSTYPE_TABLE } status_type_t;
|
|
|
|
|
|
|
|
union map_info {
|
|
|
|
void *ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 17:41:05 +07: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 17:41:09 +07:00
|
|
|
* = 2: The target wants to push back the io
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2012-12-22 03:23:41 +07:00
|
|
|
typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio);
|
2009-01-06 10:05:07 +07:00
|
|
|
typedef int (*dm_map_request_fn) (struct dm_target *ti, struct request *clone,
|
|
|
|
union map_info *map_context);
|
2014-12-18 09:08:12 +07:00
|
|
|
typedef int (*dm_clone_and_map_request_fn) (struct dm_target *ti,
|
|
|
|
struct request *rq,
|
|
|
|
union map_info *map_context,
|
|
|
|
struct request **clone);
|
|
|
|
typedef void (*dm_release_clone_request_fn) (struct request *clone);
|
2005-04-17 05:20:36 +07: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 17:41:09 +07:00
|
|
|
* 2 : The target wants to push back the io
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
typedef int (*dm_endio_fn) (struct dm_target *ti,
|
2012-12-22 03:23:41 +07:00
|
|
|
struct bio *bio, int error);
|
2009-01-06 10:05:07 +07:00
|
|
|
typedef int (*dm_request_endio_fn) (struct dm_target *ti,
|
|
|
|
struct request *clone, int error,
|
|
|
|
union map_info *map_context);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
typedef void (*dm_presuspend_fn) (struct dm_target *ti);
|
2014-10-29 07:13:31 +07:00
|
|
|
typedef void (*dm_presuspend_undo_fn) (struct dm_target *ti);
|
2005-04-17 05:20:36 +07:00
|
|
|
typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
|
2006-10-03 15:15:36 +07:00
|
|
|
typedef int (*dm_preresume_fn) (struct dm_target *ti);
|
2005-04-17 05:20:36 +07:00
|
|
|
typedef void (*dm_resume_fn) (struct dm_target *ti);
|
|
|
|
|
2013-03-02 05:45:44 +07:00
|
|
|
typedef void (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
|
|
|
|
unsigned status_flags, char *result, unsigned maxlen);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
|
|
|
|
|
2015-10-15 19:10:50 +07:00
|
|
|
typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti,
|
|
|
|
struct block_device **bdev, fmode_t *mode);
|
2006-10-03 15:15:15 +07:00
|
|
|
|
2013-05-10 20:37:17 +07:00
|
|
|
/*
|
|
|
|
* These iteration functions are typically used to check (and combine)
|
|
|
|
* properties of underlying devices.
|
|
|
|
* E.g. Does at least one underlying device support flush?
|
|
|
|
* Does any underlying device not support WRITE_SAME?
|
|
|
|
*
|
|
|
|
* The callout function is called once for each contiguous section of
|
|
|
|
* an underlying device. State can be maintained in *data.
|
|
|
|
* Return non-zero to stop iterating through any further devices.
|
|
|
|
*/
|
2009-06-22 16:12:33 +07:00
|
|
|
typedef int (*iterate_devices_callout_fn) (struct dm_target *ti,
|
|
|
|
struct dm_dev *dev,
|
2009-07-24 02:30:42 +07:00
|
|
|
sector_t start, sector_t len,
|
2009-06-22 16:12:33 +07:00
|
|
|
void *data);
|
|
|
|
|
2013-05-10 20:37:17 +07:00
|
|
|
/*
|
|
|
|
* This function must iterate through each section of device used by the
|
|
|
|
* target until it encounters a non-zero return code, which it then returns.
|
|
|
|
* Returns zero if no callout returned non-zero.
|
|
|
|
*/
|
2009-06-22 16:12:33 +07:00
|
|
|
typedef int (*dm_iterate_devices_fn) (struct dm_target *ti,
|
|
|
|
iterate_devices_callout_fn fn,
|
|
|
|
void *data);
|
|
|
|
|
2009-09-05 02:40:25 +07:00
|
|
|
typedef void (*dm_io_hints_fn) (struct dm_target *ti,
|
|
|
|
struct queue_limits *limits);
|
|
|
|
|
2009-01-06 10:05:07 +07: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);
|
|
|
|
|
2016-06-23 06:54:53 +07:00
|
|
|
/*
|
|
|
|
* Returns:
|
|
|
|
* < 0 : error
|
|
|
|
* >= 0 : the number of bytes accessible at the address
|
|
|
|
*/
|
|
|
|
typedef long (*dm_direct_access_fn) (struct dm_target *ti, sector_t sector,
|
libnvdimm for 4.8
1/ Replace pcommit with ADR / directed-flushing:
The pcommit instruction, which has not shipped on any product, is
deprecated. Instead, the requirement is that platforms implement either
ADR, or provide one or more flush addresses per nvdimm. ADR
(Asynchronous DRAM Refresh) flushes data in posted write buffers to the
memory controller on a power-fail event. Flush addresses are defined in
ACPI 6.x as an NVDIMM Firmware Interface Table (NFIT) sub-structure:
"Flush Hint Address Structure". A flush hint is an mmio address that
when written and fenced assures that all previous posted writes
targeting a given dimm have been flushed to media.
2/ On-demand ARS (address range scrub):
Linux uses the results of the ACPI ARS commands to track bad blocks
in pmem devices. When latent errors are detected we re-scrub the media
to refresh the bad block list, userspace can also request a re-scrub at
any time.
3/ Support for the Microsoft DSM (device specific method) command format.
4/ Support for EDK2/OVMF virtual disk device memory ranges.
5/ Various fixes and cleanups across the subsystem.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAABAgAGBQJXmXBsAAoJEB7SkWpmfYgCEwwP/1IOt9ocP+iHLMDH9KE7VaTZ
NmUDR+Zy6g5cRQM7SgcuU5BXUcx+OsSrSrUTVF1cW994o9Gbz1mFotkv0ZAsPcYY
ZVRQxo2oqHrssyOcg+PsgKWiXn68rJOCgmpEyzaJywl5qTMst7pzsT1s1f7rSh6h
trCf4VaJJwxZR8fARGtlHUnnhPe2Orp99EZRKEWprAsIv2kPuWpPHSjRjuEgN1JG
KW8AYwWqFTtiLRUk86I4KBB0wcDrfctsjgN9Ogd6+aHyQBRnVSr2U+vDCFkC8KLu
qiDCpYp+yyxBjclnljz7tRRT3GtzfCUWd4v2KVWqgg2IaobUc0Lbukp/rmikUXQP
WLikT2OCQ994eFK5OX3Q3cIU/4j459TQnof8q14yVSpjAKrNUXVSR5puN7Hxa+V7
41wKrAsnsyY1oq+Yd/rMR8VfH7PHx3bFkrmRCGZCufLX1UQm4aYj+sWagDKiV3yA
DiudghbOnhfurfGsnXUVw7y7GKs+gNWNBmB6ndAD6ZEHmKoGUhAEbJDLCc3DnANl
b/2mv1MIdIcC1DlCmnbbcn6fv6bICe/r8poK3VrCK3UgOq/EOvKIWl7giP+k1JuC
6DdVYhlNYIVFXUNSLFAwz8OkLu8byx7WDm36iEqrKHtPw+8qa/2bWVgOU6OBgpjV
cN3edFVIdxvZeMgM5Ubq
=xCBG
-----END PGP SIGNATURE-----
Merge tag 'libnvdimm-for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Dan Williams:
- Replace pcommit with ADR / directed-flushing.
The pcommit instruction, which has not shipped on any product, is
deprecated. Instead, the requirement is that platforms implement
either ADR, or provide one or more flush addresses per nvdimm.
ADR (Asynchronous DRAM Refresh) flushes data in posted write buffers
to the memory controller on a power-fail event.
Flush addresses are defined in ACPI 6.x as an NVDIMM Firmware
Interface Table (NFIT) sub-structure: "Flush Hint Address Structure".
A flush hint is an mmio address that when written and fenced assures
that all previous posted writes targeting a given dimm have been
flushed to media.
- On-demand ARS (address range scrub).
Linux uses the results of the ACPI ARS commands to track bad blocks
in pmem devices. When latent errors are detected we re-scrub the
media to refresh the bad block list, userspace can also request a
re-scrub at any time.
- Support for the Microsoft DSM (device specific method) command
format.
- Support for EDK2/OVMF virtual disk device memory ranges.
- Various fixes and cleanups across the subsystem.
* tag 'libnvdimm-for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: (41 commits)
libnvdimm-btt: Delete an unnecessary check before the function call "__nd_device_register"
nfit: do an ARS scrub on hitting a latent media error
nfit: move to nfit/ sub-directory
nfit, libnvdimm: allow an ARS scrub to be triggered on demand
libnvdimm: register nvdimm_bus devices with an nd_bus driver
pmem: clarify a debug print in pmem_clear_poison
x86/insn: remove pcommit
Revert "KVM: x86: add pcommit support"
nfit, tools/testing/nvdimm/: unify shutdown paths
libnvdimm: move ->module to struct nvdimm_bus_descriptor
nfit: cleanup acpi_nfit_init calling convention
nfit: fix _FIT evaluation memory leak + use after free
tools/testing/nvdimm: add manufacturing_{date|location} dimm properties
tools/testing/nvdimm: add virtual ramdisk range
acpi, nfit: treat virtual ramdisk SPA as pmem region
pmem: kill __pmem address space
pmem: kill wmb_pmem()
libnvdimm, pmem: use nvdimm_flush() for namespace I/O writes
fs/dax: remove wmb_pmem()
libnvdimm, pmem: flush posted-write queues on shutdown
...
2016-07-29 07:22:07 +07:00
|
|
|
void **kaddr, pfn_t *pfn, long size);
|
2016-06-23 06:54:53 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
void dm_error(const char *message);
|
|
|
|
|
2008-10-10 19:37:09 +07:00
|
|
|
struct dm_dev {
|
|
|
|
struct block_device *bdev;
|
2008-09-03 02:28:45 +07:00
|
|
|
fmode_t mode;
|
2008-10-10 19:37:09 +07:00
|
|
|
char name[16];
|
|
|
|
};
|
|
|
|
|
2016-02-02 11:29:18 +07:00
|
|
|
dev_t dm_get_dev_t(const char *path);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Constructors should call these functions to ensure destination devices
|
|
|
|
* are opened/closed correctly.
|
|
|
|
*/
|
2010-03-06 09:32:27 +07:00
|
|
|
int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
|
2014-06-03 21:30:28 +07:00
|
|
|
struct dm_dev **result);
|
2005-04-17 05:20:36 +07:00
|
|
|
void dm_put_device(struct dm_target *ti, struct dm_dev *d);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Information about a target type
|
|
|
|
*/
|
2009-01-06 10:05:09 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct target_type {
|
2009-01-06 10:05:09 +07:00
|
|
|
uint64_t features;
|
2005-04-17 05:20:36 +07:00
|
|
|
const char *name;
|
|
|
|
struct module *module;
|
2006-06-26 14:27:33 +07:00
|
|
|
unsigned version[3];
|
2005-04-17 05:20:36 +07:00
|
|
|
dm_ctr_fn ctr;
|
|
|
|
dm_dtr_fn dtr;
|
|
|
|
dm_map_fn map;
|
2009-01-06 10:05:07 +07:00
|
|
|
dm_map_request_fn map_rq;
|
2014-12-18 09:08:12 +07:00
|
|
|
dm_clone_and_map_request_fn clone_and_map_rq;
|
|
|
|
dm_release_clone_request_fn release_clone_rq;
|
2005-04-17 05:20:36 +07:00
|
|
|
dm_endio_fn end_io;
|
2009-01-06 10:05:07 +07:00
|
|
|
dm_request_endio_fn rq_end_io;
|
2005-04-17 05:20:36 +07:00
|
|
|
dm_presuspend_fn presuspend;
|
2014-10-29 07:13:31 +07:00
|
|
|
dm_presuspend_undo_fn presuspend_undo;
|
2005-04-17 05:20:36 +07:00
|
|
|
dm_postsuspend_fn postsuspend;
|
2006-10-03 15:15:36 +07:00
|
|
|
dm_preresume_fn preresume;
|
2005-04-17 05:20:36 +07:00
|
|
|
dm_resume_fn resume;
|
|
|
|
dm_status_fn status;
|
|
|
|
dm_message_fn message;
|
2015-10-15 19:10:50 +07:00
|
|
|
dm_prepare_ioctl_fn prepare_ioctl;
|
2009-01-06 10:05:07 +07:00
|
|
|
dm_busy_fn busy;
|
2009-06-22 16:12:33 +07:00
|
|
|
dm_iterate_devices_fn iterate_devices;
|
2009-09-05 02:40:25 +07:00
|
|
|
dm_io_hints_fn io_hints;
|
2016-06-23 06:54:53 +07:00
|
|
|
dm_direct_access_fn direct_access;
|
2009-04-03 01:55:28 +07:00
|
|
|
|
|
|
|
/* For internal device-mapper use. */
|
|
|
|
struct list_head list;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2011-11-01 03:19:00 +07:00
|
|
|
/*
|
|
|
|
* Target features
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Any table that contains an instance of this target must have only one.
|
|
|
|
*/
|
|
|
|
#define DM_TARGET_SINGLETON 0x00000001
|
|
|
|
#define dm_target_needs_singleton(type) ((type)->features & DM_TARGET_SINGLETON)
|
|
|
|
|
2011-11-01 03:19:02 +07:00
|
|
|
/*
|
|
|
|
* Indicates that a target does not support read-only devices.
|
|
|
|
*/
|
|
|
|
#define DM_TARGET_ALWAYS_WRITEABLE 0x00000002
|
|
|
|
#define dm_target_always_writeable(type) \
|
|
|
|
((type)->features & DM_TARGET_ALWAYS_WRITEABLE)
|
|
|
|
|
2011-11-01 03:19:04 +07:00
|
|
|
/*
|
|
|
|
* Any device that contains a table with an instance of this target may never
|
|
|
|
* have tables containing any different target type.
|
|
|
|
*/
|
|
|
|
#define DM_TARGET_IMMUTABLE 0x00000004
|
|
|
|
#define dm_target_is_immutable(type) ((type)->features & DM_TARGET_IMMUTABLE)
|
|
|
|
|
2016-02-07 06:38:46 +07:00
|
|
|
/*
|
|
|
|
* Indicates that a target may replace any target; even immutable targets.
|
|
|
|
* .map, .map_rq, .clone_and_map_rq and .release_clone_rq are all defined.
|
|
|
|
*/
|
|
|
|
#define DM_TARGET_WILDCARD 0x00000008
|
|
|
|
#define dm_target_is_wildcard(type) ((type)->features & DM_TARGET_WILDCARD)
|
|
|
|
|
2013-03-02 05:45:49 +07:00
|
|
|
/*
|
|
|
|
* Some targets need to be sent the same WRITE bio severals times so
|
|
|
|
* that they can send copies of it to different devices. This function
|
|
|
|
* examines any supplied bio and returns the number of copies of it the
|
|
|
|
* target requires.
|
|
|
|
*/
|
|
|
|
typedef unsigned (*dm_num_write_bios_fn) (struct dm_target *ti, struct bio *bio);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
struct dm_target {
|
|
|
|
struct dm_table *table;
|
|
|
|
struct target_type *type;
|
|
|
|
|
|
|
|
/* target limits */
|
|
|
|
sector_t begin;
|
|
|
|
sector_t len;
|
|
|
|
|
2012-07-27 21:08:00 +07:00
|
|
|
/* If non-zero, maximum size of I/O submitted to a target. */
|
|
|
|
uint32_t max_io_len;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-06-22 16:12:20 +07:00
|
|
|
/*
|
2013-03-02 05:45:47 +07:00
|
|
|
* A number of zero-length barrier bios that will be submitted
|
2009-06-22 16:12:20 +07:00
|
|
|
* to the target for the purpose of flushing cache.
|
|
|
|
*
|
2013-03-02 05:45:47 +07:00
|
|
|
* The bio number can be accessed with dm_bio_get_target_bio_nr.
|
|
|
|
* It is a responsibility of the target driver to remap these bios
|
2009-06-22 16:12:20 +07:00
|
|
|
* to the real underlying devices.
|
|
|
|
*/
|
2013-03-02 05:45:47 +07:00
|
|
|
unsigned num_flush_bios;
|
2009-06-22 16:12:20 +07:00
|
|
|
|
2010-08-12 10:14:08 +07:00
|
|
|
/*
|
2013-03-02 05:45:47 +07:00
|
|
|
* The number of discard bios that will be submitted to the target.
|
|
|
|
* The bio number can be accessed with dm_bio_get_target_bio_nr.
|
2010-08-12 10:14:08 +07:00
|
|
|
*/
|
2013-03-02 05:45:47 +07:00
|
|
|
unsigned num_discard_bios;
|
2010-08-12 10:14:08 +07:00
|
|
|
|
2012-12-22 03:23:36 +07:00
|
|
|
/*
|
2013-03-02 05:45:47 +07:00
|
|
|
* The number of WRITE SAME bios that will be submitted to the target.
|
|
|
|
* The bio number can be accessed with dm_bio_get_target_bio_nr.
|
2012-12-22 03:23:36 +07:00
|
|
|
*/
|
2013-03-02 05:45:47 +07:00
|
|
|
unsigned num_write_same_bios;
|
2012-12-22 03:23:36 +07:00
|
|
|
|
2012-12-22 03:23:38 +07:00
|
|
|
/*
|
2016-02-01 01:28:26 +07:00
|
|
|
* The minimum number of extra bytes allocated in each io for the
|
|
|
|
* target to use.
|
2012-12-22 03:23:38 +07:00
|
|
|
*/
|
2016-02-01 01:28:26 +07:00
|
|
|
unsigned per_io_data_size;
|
2012-12-22 03:23:38 +07:00
|
|
|
|
2013-03-02 05:45:49 +07:00
|
|
|
/*
|
|
|
|
* If defined, this function is called to find out how many
|
|
|
|
* duplicate bios should be sent to the target when writing
|
|
|
|
* data.
|
|
|
|
*/
|
|
|
|
dm_num_write_bios_fn num_write_bios;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* target specific data */
|
|
|
|
void *private;
|
|
|
|
|
|
|
|
/* Used to provide an error string from the ctr */
|
|
|
|
char *error;
|
2011-05-29 18:52:55 +07:00
|
|
|
|
2012-07-27 21:08:07 +07:00
|
|
|
/*
|
|
|
|
* Set if this target needs to receive flushes regardless of
|
|
|
|
* whether or not its underlying devices have support.
|
|
|
|
*/
|
|
|
|
bool flush_supported:1;
|
|
|
|
|
2011-05-29 18:52:55 +07:00
|
|
|
/*
|
|
|
|
* Set if this target needs to receive discards regardless of
|
|
|
|
* whether or not its underlying devices have support.
|
|
|
|
*/
|
2012-07-27 21:08:08 +07:00
|
|
|
bool discards_supported:1;
|
2011-09-26 05:26:21 +07:00
|
|
|
|
2012-07-27 21:08:03 +07:00
|
|
|
/*
|
2013-03-02 05:45:47 +07:00
|
|
|
* Set if the target required discard bios to be split
|
2012-07-27 21:08:03 +07:00
|
|
|
* on max_io_len boundary.
|
|
|
|
*/
|
2013-03-02 05:45:47 +07:00
|
|
|
bool split_discard_bios:1;
|
2012-07-27 21:08:03 +07:00
|
|
|
|
2011-09-26 05:26:21 +07:00
|
|
|
/*
|
|
|
|
* Set if this target does not return zeroes on discarded blocks.
|
|
|
|
*/
|
2012-07-27 21:08:08 +07:00
|
|
|
bool discard_zeroes_data_unsupported:1;
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2011-01-14 03:00:01 +07:00
|
|
|
/* Each target can link one of these into the table */
|
|
|
|
struct dm_target_callbacks {
|
|
|
|
struct list_head list;
|
|
|
|
int (*congested_fn) (struct dm_target_callbacks *, int);
|
|
|
|
};
|
|
|
|
|
2012-12-22 03:23:38 +07:00
|
|
|
/*
|
|
|
|
* For bio-based dm.
|
|
|
|
* One of these is allocated for each bio.
|
|
|
|
* This structure shouldn't be touched directly by target drivers.
|
|
|
|
* It is here so that we can inline dm_per_bio_data and
|
|
|
|
* dm_bio_from_per_bio_data
|
|
|
|
*/
|
|
|
|
struct dm_target_io {
|
|
|
|
struct dm_io *io;
|
|
|
|
struct dm_target *ti;
|
2013-03-02 05:45:47 +07:00
|
|
|
unsigned target_bio_nr;
|
2014-03-15 05:41:24 +07:00
|
|
|
unsigned *len_ptr;
|
2012-12-22 03:23:38 +07:00
|
|
|
struct bio clone;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void *dm_per_bio_data(struct bio *bio, size_t data_size)
|
|
|
|
{
|
|
|
|
return (char *)bio - offsetof(struct dm_target_io, clone) - data_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct bio *dm_bio_from_per_bio_data(void *data, size_t data_size)
|
|
|
|
{
|
|
|
|
return (struct bio *)((char *)data + data_size + offsetof(struct dm_target_io, clone));
|
|
|
|
}
|
|
|
|
|
2013-03-02 05:45:47 +07:00
|
|
|
static inline unsigned dm_bio_get_target_bio_nr(const struct bio *bio)
|
2012-12-22 03:23:39 +07:00
|
|
|
{
|
2013-03-02 05:45:47 +07:00
|
|
|
return container_of(bio, struct dm_target_io, clone)->target_bio_nr;
|
2012-12-22 03:23:39 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
int dm_register_target(struct target_type *t);
|
2009-01-06 10:04:58 +07:00
|
|
|
void dm_unregister_target(struct target_type *t);
|
2006-06-26 14:27:33 +07:00
|
|
|
|
2011-08-02 18:32:04 +07:00
|
|
|
/*
|
|
|
|
* Target argument parsing.
|
|
|
|
*/
|
|
|
|
struct dm_arg_set {
|
|
|
|
unsigned argc;
|
|
|
|
char **argv;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The minimum and maximum value of a numeric argument, together with
|
|
|
|
* the error message to use if the number is found to be outside that range.
|
|
|
|
*/
|
|
|
|
struct dm_arg {
|
|
|
|
unsigned min;
|
|
|
|
unsigned max;
|
|
|
|
char *error;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate the next argument, either returning it as *value or, if invalid,
|
|
|
|
* returning -EINVAL and setting *error.
|
|
|
|
*/
|
|
|
|
int dm_read_arg(struct dm_arg *arg, struct dm_arg_set *arg_set,
|
|
|
|
unsigned *value, char **error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the next argument as the start of a group containing between
|
|
|
|
* arg->min and arg->max further arguments. Either return the size as
|
|
|
|
* *num_args or, if invalid, return -EINVAL and set *error.
|
|
|
|
*/
|
|
|
|
int dm_read_arg_group(struct dm_arg *arg, struct dm_arg_set *arg_set,
|
|
|
|
unsigned *num_args, char **error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the current argument and shift to the next.
|
|
|
|
*/
|
|
|
|
const char *dm_shift_arg(struct dm_arg_set *as);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move through num_args arguments.
|
|
|
|
*/
|
|
|
|
void dm_consume_args(struct dm_arg_set *as, unsigned num_args);
|
|
|
|
|
2006-06-26 14:27:33 +07: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);
|
dm snapshot: suspend merging snapshot when doing exception handover
The "dm snapshot: suspend origin when doing exception handover" commit
fixed a exception store handover bug associated with pending exceptions
to the "snapshot-origin" target.
However, a similar problem exists in snapshot merging. When snapshot
merging is in progress, we use the target "snapshot-merge" instead of
"snapshot-origin". Consequently, during exception store handover, we
must find the snapshot-merge target and suspend its associated
mapped_device.
To avoid lockdep warnings, the target must be suspended and resumed
without holding _origins_lock.
Introduce a dm_hold() function that grabs a reference on a
mapped_device, but unlike dm_get(), it doesn't crash if the device has
the DMF_FREEING flag set, it returns an error in this case.
In snapshot_resume() we grab the reference to the origin device using
dm_hold() while holding _origins_lock (_origins_lock guarantees that the
device won't disappear). Then we release _origins_lock, suspend the
device and grab _origins_lock again.
NOTE to stable@ people:
When backporting to kernels 3.18 and older, use dm_internal_suspend and
dm_internal_resume instead of dm_internal_suspend_fast and
dm_internal_resume_fast.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
2015-02-26 23:41:28 +07:00
|
|
|
int dm_hold(struct mapped_device *md);
|
2006-06-26 14:27:33 +07:00
|
|
|
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 17:41:04 +07:00
|
|
|
int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
|
2006-06-26 14:27:33 +07: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-20 04:48:01 +07: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 14:27:33 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Info functions.
|
|
|
|
*/
|
2006-06-26 14:27:35 +07:00
|
|
|
const char *dm_device_name(struct mapped_device *md);
|
2007-10-20 04:47:59 +07:00
|
|
|
int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid);
|
2006-06-26 14:27:33 +07:00
|
|
|
struct gendisk *dm_disk(struct mapped_device *md);
|
2009-12-11 06:52:27 +07:00
|
|
|
int dm_suspended(struct dm_target *ti);
|
[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 17:41:09 +07:00
|
|
|
int dm_noflush_suspending(struct dm_target *ti);
|
2014-03-15 05:41:24 +07:00
|
|
|
void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors);
|
dm: prepare for request based option
This patch adds core functions for request-based dm.
When struct mapped device (md) is initialized, md->queue has
an I/O scheduler and the following functions are used for
request-based dm as the queue functions:
make_request_fn: dm_make_request()
pref_fn: dm_prep_fn()
request_fn: dm_request_fn()
softirq_done_fn: dm_softirq_done()
lld_busy_fn: dm_lld_busy()
Actual initializations are done in another patch (PATCH 2).
Below is a brief summary of how request-based dm behaves, including:
- making request from bio
- cloning, mapping and dispatching request
- completing request and bio
- suspending md
- resuming md
bio to request
==============
md->queue->make_request_fn() (dm_make_request()) calls __make_request()
for a bio submitted to the md.
Then, the bio is kept in the queue as a new request or merged into
another request in the queue if possible.
Cloning and Mapping
===================
Cloning and mapping are done in md->queue->request_fn() (dm_request_fn()),
when requests are dispatched after they are sorted by the I/O scheduler.
dm_request_fn() checks busy state of underlying devices using
target's busy() function and stops dispatching requests to keep them
on the dm device's queue if busy.
It helps better I/O merging, since no merge is done for a request
once it is dispatched to underlying devices.
Actual cloning and mapping are done in dm_prep_fn() and map_request()
called from dm_request_fn().
dm_prep_fn() clones not only request but also bios of the request
so that dm can hold bio completion in error cases and prevent
the bio submitter from noticing the error.
(See the "Completion" section below for details.)
After the cloning, the clone is mapped by target's map_rq() function
and inserted to underlying device's queue using
blk_insert_cloned_request().
Completion
==========
Request completion can be hooked by rq->end_io(), but then, all bios
in the request will have been completed even error cases, and the bio
submitter will have noticed the error.
To prevent the bio completion in error cases, request-based dm clones
both bio and request and hooks both bio->bi_end_io() and rq->end_io():
bio->bi_end_io(): end_clone_bio()
rq->end_io(): end_clone_request()
Summary of the request completion flow is below:
blk_end_request() for a clone request
=> blk_update_request()
=> bio->bi_end_io() == end_clone_bio() for each clone bio
=> Free the clone bio
=> Success: Complete the original bio (blk_update_request())
Error: Don't complete the original bio
=> blk_finish_request()
=> rq->end_io() == end_clone_request()
=> blk_complete_request()
=> dm_softirq_done()
=> Free the clone request
=> Success: Complete the original request (blk_end_request())
Error: Requeue the original request
end_clone_bio() completes the original request on the size of
the original bio in successful cases.
Even if all bios in the original request are completed by that
completion, the original request must not be completed yet to keep
the ordering of request completion for the stacking.
So end_clone_bio() uses blk_update_request() instead of
blk_end_request().
In error cases, end_clone_bio() doesn't complete the original bio.
It just frees the cloned bio and gives over the error handling to
end_clone_request().
end_clone_request(), which is called with queue lock held, completes
the clone request and the original request in a softirq context
(dm_softirq_done()), which has no queue lock, to avoid a deadlock
issue on submission of another request during the completion:
- The submitted request may be mapped to the same device
- Request submission requires queue lock, but the queue lock
has been held by itself and it doesn't know that
The clone request has no clone bio when dm_softirq_done() is called.
So target drivers can't resubmit it again even error cases.
Instead, they can ask dm core for requeueing and remapping
the original request in that cases.
suspend
=======
Request-based dm uses stopping md->queue as suspend of the md.
For noflush suspend, just stops md->queue.
For flush suspend, inserts a marker request to the tail of md->queue.
And dispatches all requests in md->queue until the marker comes to
the front of md->queue. Then, stops dispatching request and waits
for the all dispatched requests to complete.
After that, completes the marker request, stops md->queue and
wake up the waiter on the suspend queue, md->wait.
resume
======
Starts md->queue.
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>
2009-06-22 16:12:35 +07:00
|
|
|
union map_info *dm_get_rq_mapinfo(struct request *rq);
|
2006-06-26 14:27:33 +07:00
|
|
|
|
dm mpath: disable WRITE SAME if it fails
Workaround the SCSI layer's problematic WRITE SAME heuristics by
disabling WRITE SAME in the DM multipath device's queue_limits if an
underlying device disabled it.
The WRITE SAME heuristics, with both the original commit 5db44863b6eb
("[SCSI] sd: Implement support for WRITE SAME") and the updated commit
66c28f971 ("[SCSI] sd: Update WRITE SAME heuristics"), default to enabling
WRITE SAME(10) even without successfully determining it is supported.
After the first failed WRITE SAME the SCSI layer will disable WRITE SAME
for the device (by setting sdkp->device->no_write_same which results in
'max_write_same_sectors' in device's queue_limits to be set to 0).
When a device is stacked ontop of such a SCSI device any changes to that
SCSI device's queue_limits do not automatically propagate up the stack.
As such, a DM multipath device will not have its WRITE SAME support
disabled. This causes the block layer to continue to issue WRITE SAME
requests to the mpath device which causes paths to fail and (if mpath IO
isn't configured to queue when no paths are available) it will result in
actual IO errors to the upper layers.
This fix doesn't help configurations that have additional devices
stacked ontop of the mpath device (e.g. LVM created linear DM devices
ontop). A proper fix that restacks all the queue_limits from the bottom
of the device stack up will need to be explored if SCSI will continue to
use this model of optimistically allowing op codes and then disabling
them after they fail for the first time.
Before this patch:
EXT4-fs (dm-6): mounted filesystem with ordered data mode. Opts: (null)
device-mapper: multipath: XXX snitm debugging: got -EREMOTEIO (-121)
device-mapper: multipath: XXX snitm debugging: failing WRITE SAME IO with error=-121
end_request: critical target error, dev dm-6, sector 528
dm-6: WRITE SAME failed. Manually zeroing.
device-mapper: multipath: Failing path 8:112.
end_request: I/O error, dev dm-6, sector 4616
dm-6: WRITE SAME failed. Manually zeroing.
end_request: I/O error, dev dm-6, sector 4616
end_request: I/O error, dev dm-6, sector 5640
end_request: I/O error, dev dm-6, sector 6664
end_request: I/O error, dev dm-6, sector 7688
end_request: I/O error, dev dm-6, sector 524288
Buffer I/O error on device dm-6, logical block 65536
lost page write due to I/O error on dm-6
JBD2: Error -5 detected when updating journal superblock for dm-6-8.
end_request: I/O error, dev dm-6, sector 524296
Aborting journal on device dm-6-8.
end_request: I/O error, dev dm-6, sector 524288
Buffer I/O error on device dm-6, logical block 65536
lost page write due to I/O error on dm-6
JBD2: Error -5 detected when updating journal superblock for dm-6-8.
# cat /sys/block/sdh/queue/write_same_max_bytes
0
# cat /sys/block/dm-6/queue/write_same_max_bytes
33553920
After this patch:
EXT4-fs (dm-6): mounted filesystem with ordered data mode. Opts: (null)
device-mapper: multipath: XXX snitm debugging: got -EREMOTEIO (-121)
device-mapper: multipath: XXX snitm debugging: WRITE SAME I/O failed with error=-121
end_request: critical target error, dev dm-6, sector 528
dm-6: WRITE SAME failed. Manually zeroing.
# cat /sys/block/sdh/queue/write_same_max_bytes
0
# cat /sys/block/dm-6/queue/write_same_max_bytes
0
It should be noted that WRITE SAME support wasn't enabled in DM
multipath until v3.10.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: stable@vger.kernel.org # 3.10+
2013-09-19 23:13:58 +07:00
|
|
|
struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
|
|
|
|
|
2006-06-26 14:27:33 +07: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-03 02:28:45 +07:00
|
|
|
int dm_table_create(struct dm_table **result, fmode_t mode,
|
2006-06-26 14:27:33 +07: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);
|
|
|
|
|
2011-01-14 03:00:01 +07:00
|
|
|
/*
|
|
|
|
* Target_ctr should call this if it needs to add any callbacks.
|
|
|
|
*/
|
|
|
|
void dm_table_add_target_callbacks(struct dm_table *t, struct dm_target_callbacks *cb);
|
2016-05-25 08:16:51 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Target can use this to set the table's type.
|
|
|
|
* Can only ever be called from a target's ctr.
|
|
|
|
* Useful for "hybrid" target (supports both bio-based
|
|
|
|
* and request-based).
|
|
|
|
*/
|
|
|
|
void dm_table_set_type(struct dm_table *t, unsigned type);
|
2011-01-14 03:00:01 +07:00
|
|
|
|
2006-06-26 14:27:33 +07:00
|
|
|
/*
|
|
|
|
* Finally call this to make the table ready for use.
|
|
|
|
*/
|
|
|
|
int dm_table_complete(struct dm_table *t);
|
|
|
|
|
2012-07-27 21:08:00 +07:00
|
|
|
/*
|
|
|
|
* Target may require that it is never sent I/O larger than len.
|
|
|
|
*/
|
|
|
|
int __must_check dm_set_target_max_io_len(struct dm_target *ti, sector_t len);
|
|
|
|
|
2006-06-26 14:27:33 +07:00
|
|
|
/*
|
|
|
|
* Table reference counting.
|
|
|
|
*/
|
2013-07-11 05:41:18 +07:00
|
|
|
struct dm_table *dm_get_live_table(struct mapped_device *md, int *srcu_idx);
|
|
|
|
void dm_put_live_table(struct mapped_device *md, int srcu_idx);
|
|
|
|
void dm_sync_table(struct mapped_device *md);
|
2006-06-26 14:27:33 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queries
|
|
|
|
*/
|
|
|
|
sector_t dm_table_get_size(struct dm_table *t);
|
|
|
|
unsigned int dm_table_get_num_targets(struct dm_table *t);
|
2008-09-03 02:28:45 +07:00
|
|
|
fmode_t dm_table_get_mode(struct dm_table *t);
|
2006-06-26 14:27:33 +07:00
|
|
|
struct mapped_device *dm_table_get_md(struct dm_table *t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trigger an event.
|
|
|
|
*/
|
|
|
|
void dm_table_event(struct dm_table *t);
|
|
|
|
|
2014-02-28 21:33:43 +07:00
|
|
|
/*
|
|
|
|
* Run the queue for request-based targets.
|
|
|
|
*/
|
|
|
|
void dm_table_run_md_queue_async(struct dm_table *t);
|
|
|
|
|
2006-06-26 14:27:33 +07:00
|
|
|
/*
|
|
|
|
* The device must be suspended before calling this method.
|
2009-12-11 06:52:24 +07:00
|
|
|
* Returns the previous table, which the caller must destroy.
|
2006-06-26 14:27:33 +07:00
|
|
|
*/
|
2009-12-11 06:52:24 +07:00
|
|
|
struct dm_table *dm_swap_table(struct mapped_device *md,
|
|
|
|
struct dm_table *t);
|
2006-06-26 14:27:33 +07:00
|
|
|
|
2008-10-10 19:37:12 +07:00
|
|
|
/*
|
|
|
|
* A wrapper around vmalloc.
|
|
|
|
*/
|
|
|
|
void *dm_vcalloc(unsigned long nmemb, unsigned long elem_size);
|
|
|
|
|
2008-04-25 03:43:52 +07:00
|
|
|
/*-----------------------------------------------------------------
|
|
|
|
* Macros.
|
|
|
|
*---------------------------------------------------------------*/
|
|
|
|
#define DM_NAME "device-mapper"
|
|
|
|
|
2011-11-01 03:18:54 +07:00
|
|
|
#ifdef CONFIG_PRINTK
|
|
|
|
extern struct ratelimit_state dm_ratelimit_state;
|
|
|
|
|
|
|
|
#define dm_ratelimit() __ratelimit(&dm_ratelimit_state)
|
|
|
|
#else
|
|
|
|
#define dm_ratelimit() 0
|
|
|
|
#endif
|
|
|
|
|
2009-01-06 10:04:58 +07:00
|
|
|
#define DMCRIT(f, arg...) \
|
|
|
|
printk(KERN_CRIT DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
|
2008-04-25 03:43:52 +07:00
|
|
|
#define DMERR(f, arg...) \
|
|
|
|
printk(KERN_ERR DM_NAME ": " DM_MSG_PREFIX ": " f "\n", ## arg)
|
|
|
|
#define DMERR_LIMIT(f, arg...) \
|
|
|
|
do { \
|
2011-11-01 03:18:54 +07:00
|
|
|
if (dm_ratelimit()) \
|
2008-04-25 03:43:52 +07:00
|
|
|
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 { \
|
2011-11-01 03:18:54 +07:00
|
|
|
if (dm_ratelimit()) \
|
2008-04-25 03:43:52 +07:00
|
|
|
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 { \
|
2011-11-01 03:18:54 +07:00
|
|
|
if (dm_ratelimit()) \
|
2008-04-25 03:43:52 +07:00
|
|
|
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 { \
|
2011-11-01 03:18:54 +07:00
|
|
|
if (dm_ratelimit()) \
|
2008-04-25 03:43:52 +07:00
|
|
|
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
|
|
|
|
|
2013-08-16 21:54:23 +07:00
|
|
|
#define dm_sector_div64(x, y)( \
|
|
|
|
{ \
|
|
|
|
u64 _res; \
|
|
|
|
(x) = div64_u64_rem(x, y, &_res); \
|
|
|
|
_res; \
|
|
|
|
} \
|
|
|
|
)
|
|
|
|
|
2008-04-25 03:43:52 +07:00
|
|
|
/*
|
|
|
|
* 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 23:44:57 +07:00
|
|
|
#define dm_array_too_big(fixed, obj, num) \
|
|
|
|
((num) > (UINT_MAX - (fixed)) / (obj))
|
|
|
|
|
2010-08-12 10:14:10 +07:00
|
|
|
/*
|
|
|
|
* Sector offset taken relative to the start of the target instead of
|
|
|
|
* relative to the start of the device.
|
|
|
|
*/
|
|
|
|
#define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
|
|
|
|
|
2008-04-25 03:43:52 +07: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 14:27:33 +07:00
|
|
|
#endif /* _LINUX_DEVICE_MAPPER_H */
|