dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: dm-devel@redhat.com
Subject: [PATCH v3 05/12] dm: factor max_io_len for code reuse
Date: Mon, 26 Jul 2010 17:36:54 -0400	[thread overview]
Message-ID: <20100726213654.GB20849@redhat.com> (raw)
In-Reply-To: <1279987768-13275-6-git-send-email-snitzer@redhat.com>

Split max_io_len_target_boundary out of max_io_len so that the discard
support can make use of it without duplicating max_io_len code.

Avoiding max_io_len's split_io logic enables DM's discard support to
submit the entire discard request to a target.  But discards must still
be split on target boundaries.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
 drivers/md/dm.c               |   22 ++++++++++++++--------
 include/linux/device-mapper.h |    2 ++
 2 files changed, 16 insertions(+), 8 deletions(-)

Index: linux-2.6-block/drivers/md/dm.c
===================================================================
--- linux-2.6-block.orig/drivers/md/dm.c
+++ linux-2.6-block/drivers/md/dm.c
@@ -1029,17 +1029,23 @@ static void end_clone_request(struct req
 	dm_complete_request(clone, error);
 }
 
-static sector_t max_io_len(struct mapped_device *md,
-			   sector_t sector, struct dm_target *ti)
+static sector_t max_io_len_target_boundary(sector_t sector, struct dm_target *ti)
 {
-	sector_t offset = sector - ti->begin;
-	sector_t len = ti->len - offset;
+	sector_t target_offset = dm_target_offset(ti, sector);
+
+	return ti->len - target_offset;
+}
+
+static sector_t max_io_len(sector_t sector, struct dm_target *ti)
+{
+	sector_t len = max_io_len_target_boundary(sector, ti);
 
 	/*
 	 * Does the target need to split even further ?
 	 */
 	if (ti->split_io) {
 		sector_t boundary;
+		sector_t offset = dm_target_offset(ti, sector);
 		boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
 			   - offset;
 		if (len > boundary)
@@ -1257,7 +1263,7 @@ static int __clone_and_map_discard(struc
 	if (!ti->num_discard_requests)
 		return -EOPNOTSUPP;
 
-	max = max_io_len(ci->md, ci->sector, ti);
+	max = max_io_len(ci->sector, ti);
 
 	if (ci->sector_count > max)
 		/*
@@ -1289,7 +1295,7 @@ static int __clone_and_map(struct clone_
 	if (!dm_target_is_valid(ti))
 		return -EIO;
 
-	max = max_io_len(ci->md, ci->sector, ti);
+	max = max_io_len(ci->sector, ti);
 
 	if (ci->sector_count <= max) {
 		/*
@@ -1340,7 +1346,7 @@ static int __clone_and_map(struct clone_
 				if (!dm_target_is_valid(ti))
 					return -EIO;
 
-				max = max_io_len(ci->md, ci->sector, ti);
+				max = max_io_len(ci->sector, ti);
 			}
 
 			len = min(remaining, max);
@@ -1427,7 +1433,7 @@ static int dm_merge_bvec(struct request_
 	/*
 	 * Find maximum amount of I/O that won't need splitting
 	 */
-	max_sectors = min(max_io_len(md, bvm->bi_sector, ti),
+	max_sectors = min(max_io_len(bvm->bi_sector, ti),
 			  (sector_t) BIO_MAX_SECTORS);
 	max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
 	if (max_size < 0)
Index: linux-2.6-block/include/linux/device-mapper.h
===================================================================
--- linux-2.6-block.orig/include/linux/device-mapper.h
+++ linux-2.6-block/include/linux/device-mapper.h
@@ -398,6 +398,8 @@ void *dm_vcalloc(unsigned long nmemb, un
 #define dm_array_too_big(fixed, obj, num) \
 	((num) > (UINT_MAX - (fixed)) / (obj))
 
+#define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
+
 static inline sector_t to_sector(unsigned long n)
 {
 	return (n >> SECTOR_SHIFT);

  reply	other threads:[~2010-07-26 21:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-24 16:09 [PATCH v2 00/12] dm: enable discard support for more targets Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 01/12] dm: rename map_info flush_request to target_request_nr Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 02/12] dm: introduce num_discard_requests in dm_target structure Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 03/12] dm: remove the DM_TARGET_SUPPORTS_DISCARDS feature flag Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 04/12] dm: use common __issue_target_request for flush and discard support Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 05/12] dm: factor max_io_len for code reuse Mike Snitzer
2010-07-26 21:36   ` Mike Snitzer [this message]
2010-07-24 16:09 ` [PATCH v2 06/12] dm: split discard requests on target boundaries Mike Snitzer
2010-07-26 21:41   ` [PATCH v3 " Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 07/12] dm zero: silently drop discards too Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 08/12] dm error: return error for " Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 09/12] dm delay: enable discard support Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 10/12] block: update request stacking methods to support discards Mike Snitzer
2010-07-27 14:54   ` Christoph Hellwig
2010-07-24 16:09 ` [PATCH v2 11/12] dm mpath: enable discard support Mike Snitzer
2010-07-26 20:41   ` [PATCH v3 " Mike Snitzer
2010-07-24 16:09 ` [PATCH v2 12/12] dm stripe: enable efficient " Mike Snitzer
2010-07-27 20:32   ` [PATCH v3 " Mike Snitzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100726213654.GB20849@redhat.com \
    --to=snitzer@redhat.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).