From: Shaohua Li <shli@fusionio.com>
To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org
Cc: neilb@suse.de, axboe@kernel.dk, vgoyal@redhat.com,
martin.petersen@oracle.com, Shaohua Li <shli@fusionio.com>
Subject: [patch v2 6/6] md: raid 10 supports TRIM
Date: Fri, 16 Mar 2012 15:32:19 +0800 [thread overview]
Message-ID: <20120316073512.851513245@fusionio.com> (raw)
In-Reply-To: 20120316073213.656519005@fusionio.com
[-- Attachment #1: md-raid10-discard-support.patch --]
[-- Type: text/plain, Size: 3859 bytes --]
This makes md raid 10 support TRIM.
If one disk supports discard and another not, or one has discard_zero_data and
another not, there could be inconsistent between data from such disks. But this
should not matter, discarded data is useless. This will add extra copy in rebuild
though.
Signed-off-by: Shaohua Li <shli@fusionio.com>
---
drivers/md/raid10.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
Index: linux/drivers/md/raid10.c
===================================================================
--- linux.orig/drivers/md/raid10.c 2012-03-14 09:16:37.300435113 +0800
+++ linux/drivers/md/raid10.c 2012-03-14 09:33:44.017262275 +0800
@@ -800,7 +800,12 @@ static void flush_pending_writes(struct
while (bio) { /* submit pending writes */
struct bio *next = bio->bi_next;
bio->bi_next = NULL;
- generic_make_request(bio);
+ if (unlikely((bio->bi_rw & REQ_DISCARD) &&
+ !blk_queue_discard(bdev_get_queue(bio->bi_bdev))))
+ /* Just ignore it */
+ bio_endio(bio, 0);
+ else
+ generic_make_request(bio);
bio = next;
}
} else
@@ -926,6 +931,7 @@ static void make_request(struct mddev *m
const int rw = bio_data_dir(bio);
const unsigned long do_sync = (bio->bi_rw & REQ_SYNC);
const unsigned long do_fua = (bio->bi_rw & REQ_FUA);
+ const unsigned long do_discard = (bio->bi_rw & (REQ_DISCARD | REQ_SECURE));
unsigned long flags;
struct md_rdev *blocked_rdev;
int plugged;
@@ -945,7 +951,7 @@ static void make_request(struct mddev *m
conf->near_copies < conf->raid_disks)) {
struct bio_pair *bp;
/* Sanity check -- queue functions should prevent this happening */
- if (bio->bi_vcnt != 1 ||
+ if ((bio->bi_vcnt != 1 && bio->bi_vcnt !=0) ||
bio->bi_idx != 0)
goto bad_map;
/* This is a one page bio that upper layers
@@ -1241,7 +1247,7 @@ retry_write:
conf->mirrors[d].rdev->data_offset);
mbio->bi_bdev = conf->mirrors[d].rdev->bdev;
mbio->bi_end_io = raid10_end_write_request;
- mbio->bi_rw = WRITE | do_sync | do_fua;
+ mbio->bi_rw = WRITE | do_sync | do_fua | do_discard;
mbio->bi_private = r10_bio;
atomic_inc(&r10_bio->remaining);
@@ -1266,7 +1272,7 @@ retry_write:
conf->mirrors[d].replacement->data_offset);
mbio->bi_bdev = conf->mirrors[d].replacement->bdev;
mbio->bi_end_io = raid10_end_write_request;
- mbio->bi_rw = WRITE | do_sync | do_fua;
+ mbio->bi_rw = WRITE | do_sync | do_fua | do_discard;
mbio->bi_private = r10_bio;
atomic_inc(&r10_bio->remaining);
@@ -1543,6 +1549,9 @@ static int raid10_add_disk(struct mddev
}
md_integrity_add_rdev(rdev, mddev);
+ if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
+ queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
+
print_conf(conf);
return err;
}
@@ -3214,6 +3223,7 @@ static int run(struct mddev *mddev)
struct mirror_info *disk;
struct md_rdev *rdev;
sector_t size;
+ bool discard_supported = false;
/*
* copy the already verified devices into our private RAID10
@@ -3234,6 +3244,7 @@ static int run(struct mddev *mddev)
mddev->thread = conf->thread;
conf->thread = NULL;
+ blk_queue_max_discard_sectors(mddev->queue, mddev->chunk_sectors);
chunk_size = mddev->chunk_sectors << 9;
blk_queue_io_min(mddev->queue, chunk_size);
if (conf->raid_disks % conf->near_copies)
@@ -3273,7 +3284,16 @@ static int run(struct mddev *mddev)
}
disk->head_position = 0;
+
+ if (blk_queue_discard(bdev_get_queue(rdev->bdev)))
+ discard_supported = true;
}
+
+ if (discard_supported)
+ queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
+ else
+ queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, mddev->queue);
+
/* need to check that every block has at least one working mirror */
if (!enough(conf, -1)) {
printk(KERN_ERR "md/raid10:%s: not enough operational mirrors.\n",
next prev parent reply other threads:[~2012-03-16 7:32 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-16 7:32 [patch v2 0/6] Add TRIM support for raid linear/0/1/10 Shaohua Li
2012-03-16 7:32 ` [patch v2 1/6] block: makes bio_split support bio without data Shaohua Li
2012-03-16 7:32 ` [patch v2 2/6] blk: dont allow discard request merge temporarily Shaohua Li
2012-03-20 16:21 ` Vivek Goyal
2012-03-21 1:22 ` Shaohua Li
2012-03-21 12:14 ` [patch 1/2]block: handle merged discard request Shaohua Li
2012-03-22 2:32 ` Martin K. Petersen
2012-03-22 2:39 ` Shaohua Li
2012-03-22 2:53 ` Martin K. Petersen
2012-06-20 8:57 ` Christoph Hellwig
2012-06-22 3:46 ` Martin K. Petersen
2012-08-03 2:10 ` Shaohua Li
2012-08-18 3:06 ` Mike Snitzer
2012-08-18 3:47 ` Martin K. Petersen
2012-08-20 13:57 ` Mike Snitzer
2012-08-20 13:58 ` Christoph Hellwig
2012-08-20 14:12 ` Mike Snitzer
2012-08-20 14:15 ` Christoph Hellwig
2012-03-22 2:18 ` [patch v2 2/6] blk: dont allow discard request merge temporarily Martin K. Petersen
2012-03-22 2:33 ` Shaohua Li
2012-03-22 6:28 ` Christoph Hellwig
2012-03-16 7:32 ` [patch v2 3/6] md: linear supports TRIM Shaohua Li
2012-03-16 7:32 ` [patch v2 4/6] md: raid 0 " Shaohua Li
2012-03-16 7:32 ` [patch v2 5/6] md: raid 1 " Shaohua Li
2012-03-16 7:32 ` Shaohua Li [this message]
2012-03-19 19:38 ` [patch v2 0/6] Add TRIM support for raid linear/0/1/10 Holger Kiehl
2012-03-20 1:27 ` Shaohua Li
2012-03-20 9:50 ` Holger Kiehl
2012-03-20 12:09 ` Shaohua Li
2012-03-21 2:08 ` Shaohua Li
2012-03-21 2:08 ` Shaohua Li
2012-03-21 2:24 ` Roberto Spadim
2012-03-21 2:29 ` Mathias Burén
2012-03-21 2:29 ` Mathias Burén
2012-03-21 2:29 ` Mathias Burén
2012-05-08 9:59 ` Patelczyk, Maciej
2012-05-09 2:27 ` Shaohua Li
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=20120316073512.851513245@fusionio.com \
--to=shli@fusionio.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=neilb@suse.de \
--cc=vgoyal@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.