* [PATCH V1] md/raid10: refactor some codes from raid10_write_request
@ 2017-03-17 9:45 Guoqing Jiang
2017-03-20 5:05 ` kbuild test robot
2017-03-20 9:46 ` [PATCH V2] " Guoqing Jiang
0 siblings, 2 replies; 5+ messages in thread
From: Guoqing Jiang @ 2017-03-17 9:45 UTC (permalink / raw)
To: linux-raid; +Cc: shli, neilb, Guoqing Jiang
Previously, we clone both bio and repl_bio in raid10_write_request,
then add the cloned bio to plug->pending or conf->pending_bio_list
based on plug or not, and most of the logics are same for the two
conditions.
So introduce raid10_write_one_disk for it, and use replacement parameter
to distinguish the difference. No functional changes in the patch.
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
---
Changes from RFC:
1. rename handle_clonebio to raid10_write_one_disk
2. s/i/n_copy/ and s/int replacement/bool replacement/
drivers/md/raid10.c | 172 ++++++++++++++++++++++------------------------------
1 file changed, 72 insertions(+), 100 deletions(-)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b1b1f982a722..a931e6e7b280 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1188,18 +1188,81 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
return;
}
-static void raid10_write_request(struct mddev *mddev, struct bio *bio,
- struct r10bio *r10_bio)
+static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
+ struct bio *bio, bool replacement,
+ int n_copy, int max_sectors)
{
- struct r10conf *conf = mddev->private;
- int i;
const int op = bio_op(bio);
const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
unsigned long flags;
- struct md_rdev *blocked_rdev;
struct blk_plug_cb *cb;
struct raid10_plug_cb *plug = NULL;
+ struct r10conf *conf = mddev->private;
+ struct md_rdev *rdev;
+ int devnum = r10_bio->devs[i].devnum;
+ struct bio *mbio;
+
+ if (replacement) {
+ rdev = conf->mirrors[devnum].replacement;
+ if (rdev == NULL) {
+ /* Replacement just got moved to main 'rdev' */
+ smp_mb();
+ rdev = conf->mirrors[devnum].rdev;
+ }
+ } else
+ rdev = conf->mirrors[devnum].rdev;
+
+ mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
+ bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector, max_sectors);
+ if (replacement)
+ r10_bio->devs[i].repl_bio = mbio;
+ else
+ r10_bio->devs[i].bio = mbio;
+
+ mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr +
+ choose_data_offset(r10_bio, rdev));
+ mbio->bi_bdev = rdev->bdev;
+ mbio->bi_end_io = raid10_end_write_request;
+ bio_set_op_attrs(mbio, op, do_sync | do_fua);
+ if (!replacement && test_bit(FailFast, &conf->mirrors[devnum].rdev->flags)
+ && enough(conf, devnum))
+ mbio->bi_opf |= MD_FAILFAST;
+ mbio->bi_private = r10_bio;
+
+ if (conf->mddev->gendisk)
+ trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
+ mbio, disk_devt(conf->mddev->gendisk),
+ r10_bio->sector);
+ /* flush_pending_writes() needs access to the rdev so...*/
+ mbio->bi_bdev = (void *)rdev;
+
+ atomic_inc(&r10_bio->remaining);
+
+ cb = blk_check_plugged(raid10_unplug, mddev, sizeof(*plug));
+ if (cb)
+ plug = container_of(cb, struct raid10_plug_cb, cb);
+ else
+ plug = NULL;
+ spin_lock_irqsave(&conf->device_lock, flags);
+ if (plug) {
+ bio_list_add(&plug->pending, mbio);
+ plug->pending_cnt++;
+ } else {
+ bio_list_add(&conf->pending_bio_list, mbio);
+ conf->pending_count++;
+ }
+ spin_unlock_irqrestore(&conf->device_lock, flags);
+ if (!plug)
+ md_wakeup_thread(mddev->thread);
+}
+
+static void raid10_write_request(struct mddev *mddev, struct bio *bio,
+ struct r10bio *r10_bio)
+{
+ struct r10conf *conf = mddev->private;
+ int i;
+ struct md_rdev *blocked_rdev;
sector_t sectors;
int sectors_handled;
int max_sectors;
@@ -1402,101 +1465,10 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0);
for (i = 0; i < conf->copies; i++) {
- struct bio *mbio;
- int d = r10_bio->devs[i].devnum;
- if (r10_bio->devs[i].bio) {
- struct md_rdev *rdev = conf->mirrors[d].rdev;
- mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
- bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
- max_sectors);
- r10_bio->devs[i].bio = mbio;
-
- mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr+
- choose_data_offset(r10_bio, rdev));
- mbio->bi_bdev = rdev->bdev;
- mbio->bi_end_io = raid10_end_write_request;
- bio_set_op_attrs(mbio, op, do_sync | do_fua);
- if (test_bit(FailFast, &conf->mirrors[d].rdev->flags) &&
- enough(conf, d))
- mbio->bi_opf |= MD_FAILFAST;
- mbio->bi_private = r10_bio;
-
- if (conf->mddev->gendisk)
- trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
- mbio, disk_devt(conf->mddev->gendisk),
- r10_bio->sector);
- /* flush_pending_writes() needs access to the rdev so...*/
- mbio->bi_bdev = (void*)rdev;
-
- atomic_inc(&r10_bio->remaining);
-
- cb = blk_check_plugged(raid10_unplug, mddev,
- sizeof(*plug));
- if (cb)
- plug = container_of(cb, struct raid10_plug_cb,
- cb);
- else
- plug = NULL;
- spin_lock_irqsave(&conf->device_lock, flags);
- if (plug) {
- bio_list_add(&plug->pending, mbio);
- plug->pending_cnt++;
- } else {
- bio_list_add(&conf->pending_bio_list, mbio);
- conf->pending_count++;
- }
- spin_unlock_irqrestore(&conf->device_lock, flags);
- if (!plug)
- md_wakeup_thread(mddev->thread);
- }
-
- if (r10_bio->devs[i].repl_bio) {
- struct md_rdev *rdev = conf->mirrors[d].replacement;
- if (rdev == NULL) {
- /* Replacement just got moved to main 'rdev' */
- smp_mb();
- rdev = conf->mirrors[d].rdev;
- }
- mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
- bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
- max_sectors);
- r10_bio->devs[i].repl_bio = mbio;
-
- mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr +
- choose_data_offset(r10_bio, rdev));
- mbio->bi_bdev = rdev->bdev;
- mbio->bi_end_io = raid10_end_write_request;
- bio_set_op_attrs(mbio, op, do_sync | do_fua);
- mbio->bi_private = r10_bio;
-
- if (conf->mddev->gendisk)
- trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
- mbio, disk_devt(conf->mddev->gendisk),
- r10_bio->sector);
- /* flush_pending_writes() needs access to the rdev so...*/
- mbio->bi_bdev = (void*)rdev;
-
- atomic_inc(&r10_bio->remaining);
-
- cb = blk_check_plugged(raid10_unplug, mddev,
- sizeof(*plug));
- if (cb)
- plug = container_of(cb, struct raid10_plug_cb,
- cb);
- else
- plug = NULL;
- spin_lock_irqsave(&conf->device_lock, flags);
- if (plug) {
- bio_list_add(&plug->pending, mbio);
- plug->pending_cnt++;
- } else {
- bio_list_add(&conf->pending_bio_list, mbio);
- conf->pending_count++;
- }
- spin_unlock_irqrestore(&conf->device_lock, flags);
- if (!plug)
- md_wakeup_thread(mddev->thread);
- }
+ if (r10_bio->devs[i].bio)
+ raid10_write_one_disk(mddev, r10_bio, bio, false, i, max_sectors);
+ if (r10_bio->devs[i].repl_bio)
+ raid10_write_one_disk(mddev, r10_bio, bio, true, i, max_sectors);
}
/* Don't remove the bias on 'remaining' (one_write_done) until
--
2.6.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V1] md/raid10: refactor some codes from raid10_write_request
2017-03-17 9:45 [PATCH V1] md/raid10: refactor some codes from raid10_write_request Guoqing Jiang
@ 2017-03-20 5:05 ` kbuild test robot
2017-03-20 8:28 ` Guoqing Jiang
2017-03-20 9:46 ` [PATCH V2] " Guoqing Jiang
1 sibling, 1 reply; 5+ messages in thread
From: kbuild test robot @ 2017-03-20 5:05 UTC (permalink / raw)
Cc: kbuild-all, linux-raid, shli, neilb, Guoqing Jiang
[-- Attachment #1: Type: text/plain, Size: 1512 bytes --]
Hi Guoqing,
[auto build test ERROR on next-20170310]
[also build test ERROR on v4.11-rc3]
[cannot apply to md/for-next v4.9-rc8 v4.9-rc7 v4.9-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Guoqing-Jiang/md-raid10-refactor-some-codes-from-raid10_write_request/20170320-124148
config: x86_64-randconfig-x004-201712 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/md/raid10.c: In function 'raid10_write_one_disk':
>> drivers/md/raid10.c:1203:29: error: 'i' undeclared (first use in this function)
int devnum = r10_bio->devs[i].devnum;
^
drivers/md/raid10.c:1203:29: note: each undeclared identifier is reported only once for each function it appears in
vim +/i +1203 drivers/md/raid10.c
1197 const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
1198 unsigned long flags;
1199 struct blk_plug_cb *cb;
1200 struct raid10_plug_cb *plug = NULL;
1201 struct r10conf *conf = mddev->private;
1202 struct md_rdev *rdev;
> 1203 int devnum = r10_bio->devs[i].devnum;
1204 struct bio *mbio;
1205
1206 if (replacement) {
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 26911 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V1] md/raid10: refactor some codes from raid10_write_request
2017-03-20 5:05 ` kbuild test robot
@ 2017-03-20 8:28 ` Guoqing Jiang
0 siblings, 0 replies; 5+ messages in thread
From: Guoqing Jiang @ 2017-03-20 8:28 UTC (permalink / raw)
To: kbuild test robot; +Cc: kbuild-all, linux-raid, shli, neilb
On 03/20/2017 01:05 PM, kbuild test robot wrote:
> Hi Guoqing,
>
> [auto build test ERROR on next-20170310]
> [also build test ERROR on v4.11-rc3]
> [cannot apply to md/for-next v4.9-rc8 v4.9-rc7 v4.9-rc6]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url: https://github.com/0day-ci/linux/commits/Guoqing-Jiang/md-raid10-refactor-some-codes-from-raid10_write_request/20170320-124148
> config: x86_64-randconfig-x004-201712 (attached as .config)
> compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
> reproduce:
> # save the attached .config to linux build tree
> make ARCH=x86_64
>
> All errors (new ones prefixed by >>):
>
> drivers/md/raid10.c: In function 'raid10_write_one_disk':
>>> drivers/md/raid10.c:1203:29: error: 'i' undeclared (first use in this function)
> int devnum = r10_bio->devs[i].devnum;
> ^
> drivers/md/raid10.c:1203:29: note: each undeclared identifier is reported only once for each function it appears in
>
> vim +/i +1203 drivers/md/raid10.c
>
> 1197 const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
> 1198 unsigned long flags;
> 1199 struct blk_plug_cb *cb;
> 1200 struct raid10_plug_cb *plug = NULL;
> 1201 struct r10conf *conf = mddev->private;
> 1202 struct md_rdev *rdev;
>> 1203 int devnum = r10_bio->devs[i].devnum;
Oops, I forgot to compile it, :-
Thanks,
Guoqing
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V2] md/raid10: refactor some codes from raid10_write_request
2017-03-17 9:45 [PATCH V1] md/raid10: refactor some codes from raid10_write_request Guoqing Jiang
2017-03-20 5:05 ` kbuild test robot
@ 2017-03-20 9:46 ` Guoqing Jiang
2017-03-24 5:47 ` Shaohua Li
1 sibling, 1 reply; 5+ messages in thread
From: Guoqing Jiang @ 2017-03-20 9:46 UTC (permalink / raw)
To: linux-raid; +Cc: shli, neilb, Guoqing Jiang
Previously, we clone both bio and repl_bio in raid10_write_request,
then add the cloned bio to plug->pending or conf->pending_bio_list
based on plug or not, and most of the logics are same for the two
conditions.
So introduce raid10_write_one_disk for it, and use replacement parameter
to distinguish the difference. No functional changes in the patch.
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
---
Changes from V1:
1. fix compile issues reported by kbuild test
2. also fix some warning infos about over 80 characters
Changes from RFC:
1. rename handle_clonebio to raid10_write_one_disk
2. s/i/n_copy/ and s/int replacement/bool replacement/
drivers/md/raid10.c | 175 ++++++++++++++++++++++------------------------------
1 file changed, 75 insertions(+), 100 deletions(-)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b1b1f982a722..69045b94a9ab 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1188,18 +1188,82 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
return;
}
-static void raid10_write_request(struct mddev *mddev, struct bio *bio,
- struct r10bio *r10_bio)
+static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
+ struct bio *bio, bool replacement,
+ int n_copy, int max_sectors)
{
- struct r10conf *conf = mddev->private;
- int i;
const int op = bio_op(bio);
const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
unsigned long flags;
- struct md_rdev *blocked_rdev;
struct blk_plug_cb *cb;
struct raid10_plug_cb *plug = NULL;
+ struct r10conf *conf = mddev->private;
+ struct md_rdev *rdev;
+ int devnum = r10_bio->devs[n_copy].devnum;
+ struct bio *mbio;
+
+ if (replacement) {
+ rdev = conf->mirrors[devnum].replacement;
+ if (rdev == NULL) {
+ /* Replacement just got moved to main 'rdev' */
+ smp_mb();
+ rdev = conf->mirrors[devnum].rdev;
+ }
+ } else
+ rdev = conf->mirrors[devnum].rdev;
+
+ mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
+ bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector, max_sectors);
+ if (replacement)
+ r10_bio->devs[n_copy].repl_bio = mbio;
+ else
+ r10_bio->devs[n_copy].bio = mbio;
+
+ mbio->bi_iter.bi_sector = (r10_bio->devs[n_copy].addr +
+ choose_data_offset(r10_bio, rdev));
+ mbio->bi_bdev = rdev->bdev;
+ mbio->bi_end_io = raid10_end_write_request;
+ bio_set_op_attrs(mbio, op, do_sync | do_fua);
+ if (!replacement && test_bit(FailFast,
+ &conf->mirrors[devnum].rdev->flags)
+ && enough(conf, devnum))
+ mbio->bi_opf |= MD_FAILFAST;
+ mbio->bi_private = r10_bio;
+
+ if (conf->mddev->gendisk)
+ trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
+ mbio, disk_devt(conf->mddev->gendisk),
+ r10_bio->sector);
+ /* flush_pending_writes() needs access to the rdev so...*/
+ mbio->bi_bdev = (void *)rdev;
+
+ atomic_inc(&r10_bio->remaining);
+
+ cb = blk_check_plugged(raid10_unplug, mddev, sizeof(*plug));
+ if (cb)
+ plug = container_of(cb, struct raid10_plug_cb, cb);
+ else
+ plug = NULL;
+ spin_lock_irqsave(&conf->device_lock, flags);
+ if (plug) {
+ bio_list_add(&plug->pending, mbio);
+ plug->pending_cnt++;
+ } else {
+ bio_list_add(&conf->pending_bio_list, mbio);
+ conf->pending_count++;
+ }
+ spin_unlock_irqrestore(&conf->device_lock, flags);
+ if (!plug)
+ md_wakeup_thread(mddev->thread);
+}
+
+static void raid10_write_request(struct mddev *mddev, struct bio *bio,
+ struct r10bio *r10_bio)
+{
+ struct r10conf *conf = mddev->private;
+ int i;
+ struct md_rdev *blocked_rdev;
sector_t sectors;
int sectors_handled;
int max_sectors;
@@ -1402,101 +1466,12 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0);
for (i = 0; i < conf->copies; i++) {
- struct bio *mbio;
- int d = r10_bio->devs[i].devnum;
- if (r10_bio->devs[i].bio) {
- struct md_rdev *rdev = conf->mirrors[d].rdev;
- mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
- bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
- max_sectors);
- r10_bio->devs[i].bio = mbio;
-
- mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr+
- choose_data_offset(r10_bio, rdev));
- mbio->bi_bdev = rdev->bdev;
- mbio->bi_end_io = raid10_end_write_request;
- bio_set_op_attrs(mbio, op, do_sync | do_fua);
- if (test_bit(FailFast, &conf->mirrors[d].rdev->flags) &&
- enough(conf, d))
- mbio->bi_opf |= MD_FAILFAST;
- mbio->bi_private = r10_bio;
-
- if (conf->mddev->gendisk)
- trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
- mbio, disk_devt(conf->mddev->gendisk),
- r10_bio->sector);
- /* flush_pending_writes() needs access to the rdev so...*/
- mbio->bi_bdev = (void*)rdev;
-
- atomic_inc(&r10_bio->remaining);
-
- cb = blk_check_plugged(raid10_unplug, mddev,
- sizeof(*plug));
- if (cb)
- plug = container_of(cb, struct raid10_plug_cb,
- cb);
- else
- plug = NULL;
- spin_lock_irqsave(&conf->device_lock, flags);
- if (plug) {
- bio_list_add(&plug->pending, mbio);
- plug->pending_cnt++;
- } else {
- bio_list_add(&conf->pending_bio_list, mbio);
- conf->pending_count++;
- }
- spin_unlock_irqrestore(&conf->device_lock, flags);
- if (!plug)
- md_wakeup_thread(mddev->thread);
- }
-
- if (r10_bio->devs[i].repl_bio) {
- struct md_rdev *rdev = conf->mirrors[d].replacement;
- if (rdev == NULL) {
- /* Replacement just got moved to main 'rdev' */
- smp_mb();
- rdev = conf->mirrors[d].rdev;
- }
- mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
- bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
- max_sectors);
- r10_bio->devs[i].repl_bio = mbio;
-
- mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr +
- choose_data_offset(r10_bio, rdev));
- mbio->bi_bdev = rdev->bdev;
- mbio->bi_end_io = raid10_end_write_request;
- bio_set_op_attrs(mbio, op, do_sync | do_fua);
- mbio->bi_private = r10_bio;
-
- if (conf->mddev->gendisk)
- trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
- mbio, disk_devt(conf->mddev->gendisk),
- r10_bio->sector);
- /* flush_pending_writes() needs access to the rdev so...*/
- mbio->bi_bdev = (void*)rdev;
-
- atomic_inc(&r10_bio->remaining);
-
- cb = blk_check_plugged(raid10_unplug, mddev,
- sizeof(*plug));
- if (cb)
- plug = container_of(cb, struct raid10_plug_cb,
- cb);
- else
- plug = NULL;
- spin_lock_irqsave(&conf->device_lock, flags);
- if (plug) {
- bio_list_add(&plug->pending, mbio);
- plug->pending_cnt++;
- } else {
- bio_list_add(&conf->pending_bio_list, mbio);
- conf->pending_count++;
- }
- spin_unlock_irqrestore(&conf->device_lock, flags);
- if (!plug)
- md_wakeup_thread(mddev->thread);
- }
+ if (r10_bio->devs[i].bio)
+ raid10_write_one_disk(mddev, r10_bio, bio, false,
+ i, max_sectors);
+ if (r10_bio->devs[i].repl_bio)
+ raid10_write_one_disk(mddev, r10_bio, bio, true,
+ i, max_sectors);
}
/* Don't remove the bias on 'remaining' (one_write_done) until
--
2.6.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] md/raid10: refactor some codes from raid10_write_request
2017-03-20 9:46 ` [PATCH V2] " Guoqing Jiang
@ 2017-03-24 5:47 ` Shaohua Li
0 siblings, 0 replies; 5+ messages in thread
From: Shaohua Li @ 2017-03-24 5:47 UTC (permalink / raw)
To: Guoqing Jiang; +Cc: linux-raid, shli, neilb
On Mon, Mar 20, 2017 at 05:46:04PM +0800, Guoqing Jiang wrote:
> Previously, we clone both bio and repl_bio in raid10_write_request,
> then add the cloned bio to plug->pending or conf->pending_bio_list
> based on plug or not, and most of the logics are same for the two
> conditions.
>
> So introduce raid10_write_one_disk for it, and use replacement parameter
> to distinguish the difference. No functional changes in the patch.
>
> Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
applied, thanks!
> ---
> Changes from V1:
> 1. fix compile issues reported by kbuild test
> 2. also fix some warning infos about over 80 characters
>
> Changes from RFC:
> 1. rename handle_clonebio to raid10_write_one_disk
> 2. s/i/n_copy/ and s/int replacement/bool replacement/
>
> drivers/md/raid10.c | 175 ++++++++++++++++++++++------------------------------
> 1 file changed, 75 insertions(+), 100 deletions(-)
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index b1b1f982a722..69045b94a9ab 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -1188,18 +1188,82 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
> return;
> }
>
> -static void raid10_write_request(struct mddev *mddev, struct bio *bio,
> - struct r10bio *r10_bio)
> +static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
> + struct bio *bio, bool replacement,
> + int n_copy, int max_sectors)
> {
> - struct r10conf *conf = mddev->private;
> - int i;
> const int op = bio_op(bio);
> const unsigned long do_sync = (bio->bi_opf & REQ_SYNC);
> const unsigned long do_fua = (bio->bi_opf & REQ_FUA);
> unsigned long flags;
> - struct md_rdev *blocked_rdev;
> struct blk_plug_cb *cb;
> struct raid10_plug_cb *plug = NULL;
> + struct r10conf *conf = mddev->private;
> + struct md_rdev *rdev;
> + int devnum = r10_bio->devs[n_copy].devnum;
> + struct bio *mbio;
> +
> + if (replacement) {
> + rdev = conf->mirrors[devnum].replacement;
> + if (rdev == NULL) {
> + /* Replacement just got moved to main 'rdev' */
> + smp_mb();
> + rdev = conf->mirrors[devnum].rdev;
> + }
> + } else
> + rdev = conf->mirrors[devnum].rdev;
> +
> + mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
> + bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector, max_sectors);
> + if (replacement)
> + r10_bio->devs[n_copy].repl_bio = mbio;
> + else
> + r10_bio->devs[n_copy].bio = mbio;
> +
> + mbio->bi_iter.bi_sector = (r10_bio->devs[n_copy].addr +
> + choose_data_offset(r10_bio, rdev));
> + mbio->bi_bdev = rdev->bdev;
> + mbio->bi_end_io = raid10_end_write_request;
> + bio_set_op_attrs(mbio, op, do_sync | do_fua);
> + if (!replacement && test_bit(FailFast,
> + &conf->mirrors[devnum].rdev->flags)
> + && enough(conf, devnum))
> + mbio->bi_opf |= MD_FAILFAST;
> + mbio->bi_private = r10_bio;
> +
> + if (conf->mddev->gendisk)
> + trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
> + mbio, disk_devt(conf->mddev->gendisk),
> + r10_bio->sector);
> + /* flush_pending_writes() needs access to the rdev so...*/
> + mbio->bi_bdev = (void *)rdev;
> +
> + atomic_inc(&r10_bio->remaining);
> +
> + cb = blk_check_plugged(raid10_unplug, mddev, sizeof(*plug));
> + if (cb)
> + plug = container_of(cb, struct raid10_plug_cb, cb);
> + else
> + plug = NULL;
> + spin_lock_irqsave(&conf->device_lock, flags);
> + if (plug) {
> + bio_list_add(&plug->pending, mbio);
> + plug->pending_cnt++;
> + } else {
> + bio_list_add(&conf->pending_bio_list, mbio);
> + conf->pending_count++;
> + }
> + spin_unlock_irqrestore(&conf->device_lock, flags);
> + if (!plug)
> + md_wakeup_thread(mddev->thread);
> +}
> +
> +static void raid10_write_request(struct mddev *mddev, struct bio *bio,
> + struct r10bio *r10_bio)
> +{
> + struct r10conf *conf = mddev->private;
> + int i;
> + struct md_rdev *blocked_rdev;
> sector_t sectors;
> int sectors_handled;
> int max_sectors;
> @@ -1402,101 +1466,12 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
> bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0);
>
> for (i = 0; i < conf->copies; i++) {
> - struct bio *mbio;
> - int d = r10_bio->devs[i].devnum;
> - if (r10_bio->devs[i].bio) {
> - struct md_rdev *rdev = conf->mirrors[d].rdev;
> - mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
> - bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
> - max_sectors);
> - r10_bio->devs[i].bio = mbio;
> -
> - mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr+
> - choose_data_offset(r10_bio, rdev));
> - mbio->bi_bdev = rdev->bdev;
> - mbio->bi_end_io = raid10_end_write_request;
> - bio_set_op_attrs(mbio, op, do_sync | do_fua);
> - if (test_bit(FailFast, &conf->mirrors[d].rdev->flags) &&
> - enough(conf, d))
> - mbio->bi_opf |= MD_FAILFAST;
> - mbio->bi_private = r10_bio;
> -
> - if (conf->mddev->gendisk)
> - trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
> - mbio, disk_devt(conf->mddev->gendisk),
> - r10_bio->sector);
> - /* flush_pending_writes() needs access to the rdev so...*/
> - mbio->bi_bdev = (void*)rdev;
> -
> - atomic_inc(&r10_bio->remaining);
> -
> - cb = blk_check_plugged(raid10_unplug, mddev,
> - sizeof(*plug));
> - if (cb)
> - plug = container_of(cb, struct raid10_plug_cb,
> - cb);
> - else
> - plug = NULL;
> - spin_lock_irqsave(&conf->device_lock, flags);
> - if (plug) {
> - bio_list_add(&plug->pending, mbio);
> - plug->pending_cnt++;
> - } else {
> - bio_list_add(&conf->pending_bio_list, mbio);
> - conf->pending_count++;
> - }
> - spin_unlock_irqrestore(&conf->device_lock, flags);
> - if (!plug)
> - md_wakeup_thread(mddev->thread);
> - }
> -
> - if (r10_bio->devs[i].repl_bio) {
> - struct md_rdev *rdev = conf->mirrors[d].replacement;
> - if (rdev == NULL) {
> - /* Replacement just got moved to main 'rdev' */
> - smp_mb();
> - rdev = conf->mirrors[d].rdev;
> - }
> - mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
> - bio_trim(mbio, r10_bio->sector - bio->bi_iter.bi_sector,
> - max_sectors);
> - r10_bio->devs[i].repl_bio = mbio;
> -
> - mbio->bi_iter.bi_sector = (r10_bio->devs[i].addr +
> - choose_data_offset(r10_bio, rdev));
> - mbio->bi_bdev = rdev->bdev;
> - mbio->bi_end_io = raid10_end_write_request;
> - bio_set_op_attrs(mbio, op, do_sync | do_fua);
> - mbio->bi_private = r10_bio;
> -
> - if (conf->mddev->gendisk)
> - trace_block_bio_remap(bdev_get_queue(mbio->bi_bdev),
> - mbio, disk_devt(conf->mddev->gendisk),
> - r10_bio->sector);
> - /* flush_pending_writes() needs access to the rdev so...*/
> - mbio->bi_bdev = (void*)rdev;
> -
> - atomic_inc(&r10_bio->remaining);
> -
> - cb = blk_check_plugged(raid10_unplug, mddev,
> - sizeof(*plug));
> - if (cb)
> - plug = container_of(cb, struct raid10_plug_cb,
> - cb);
> - else
> - plug = NULL;
> - spin_lock_irqsave(&conf->device_lock, flags);
> - if (plug) {
> - bio_list_add(&plug->pending, mbio);
> - plug->pending_cnt++;
> - } else {
> - bio_list_add(&conf->pending_bio_list, mbio);
> - conf->pending_count++;
> - }
> - spin_unlock_irqrestore(&conf->device_lock, flags);
> - if (!plug)
> - md_wakeup_thread(mddev->thread);
> - }
> + if (r10_bio->devs[i].bio)
> + raid10_write_one_disk(mddev, r10_bio, bio, false,
> + i, max_sectors);
> + if (r10_bio->devs[i].repl_bio)
> + raid10_write_one_disk(mddev, r10_bio, bio, true,
> + i, max_sectors);
> }
>
> /* Don't remove the bias on 'remaining' (one_write_done) until
> --
> 2.6.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-03-24 5:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-17 9:45 [PATCH V1] md/raid10: refactor some codes from raid10_write_request Guoqing Jiang
2017-03-20 5:05 ` kbuild test robot
2017-03-20 8:28 ` Guoqing Jiang
2017-03-20 9:46 ` [PATCH V2] " Guoqing Jiang
2017-03-24 5:47 ` Shaohua Li
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).