hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/md/raid5-cache.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2015 Shaohua Li <shli@fb.com>
34 * Copyright (C) 2016 Song Liu <songliubraving@fb.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms and conditions of the GNU General Public License,
7
- * version 2, as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
- *
145 */
156 #include <linux/kernel.h>
167 #include <linux/wait.h>
....@@ -204,9 +195,7 @@
204195 static inline sector_t r5c_tree_index(struct r5conf *conf,
205196 sector_t sect)
206197 {
207
- sector_t offset;
208
-
209
- offset = sector_div(sect, conf->chunk_sectors);
198
+ sector_div(sect, conf->chunk_sectors);
210199 return sect;
211200 }
212201
....@@ -307,8 +296,8 @@
307296 wbi = dev->written;
308297 dev->written = NULL;
309298 while (wbi && wbi->bi_iter.bi_sector <
310
- dev->sector + STRIPE_SECTORS) {
311
- wbi2 = r5_next_bio(wbi, dev->sector);
299
+ dev->sector + RAID5_STRIPE_SECTORS(conf)) {
300
+ wbi2 = r5_next_bio(conf, wbi, dev->sector);
312301 md_write_end(conf->mddev);
313302 bio_endio(wbi);
314303 wbi = wbi2;
....@@ -325,7 +314,7 @@
325314 set_bit(R5_UPTODATE, &sh->dev[i].flags);
326315 r5c_return_dev_pending_writes(conf, &sh->dev[i]);
327316 md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
328
- STRIPE_SECTORS,
317
+ RAID5_STRIPE_SECTORS(conf),
329318 !test_bit(STRIPE_DEGRADED, &sh->state),
330319 0);
331320 }
....@@ -373,7 +362,7 @@
373362 */
374363 if (atomic_read(&conf->r5c_cached_full_stripes) >=
375364 min(R5C_FULL_STRIPE_FLUSH_BATCH(conf),
376
- conf->chunk_sectors >> STRIPE_SHIFT))
365
+ conf->chunk_sectors >> RAID5_STRIPE_SHIFT(conf)))
377366 r5l_wake_reclaim(conf->log, 0);
378367 }
379368
....@@ -2439,10 +2428,15 @@
24392428 struct mddev *mddev = log->rdev->mddev;
24402429 struct r5conf *conf = mddev->private;
24412430 struct stripe_head *sh, *next;
2431
+ bool cleared_pending = false;
24422432
24432433 if (ctx->data_only_stripes == 0)
24442434 return;
24452435
2436
+ if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) {
2437
+ cleared_pending = true;
2438
+ clear_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags);
2439
+ }
24462440 log->r5c_journal_mode = R5C_JOURNAL_MODE_WRITE_BACK;
24472441
24482442 list_for_each_entry_safe(sh, next, &ctx->cached_list, lru) {
....@@ -2457,6 +2451,8 @@
24572451 atomic_read(&conf->active_stripes) == 0);
24582452
24592453 log->r5c_journal_mode = R5C_JOURNAL_MODE_WRITE_THROUGH;
2454
+ if (cleared_pending)
2455
+ set_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags);
24602456 }
24612457
24622458 static int r5l_recovery_log(struct r5l_log *log)
....@@ -2541,13 +2537,10 @@
25412537 struct r5conf *conf;
25422538 int ret;
25432539
2544
- ret = mddev_lock(mddev);
2545
- if (ret)
2546
- return ret;
2547
-
2540
+ spin_lock(&mddev->lock);
25482541 conf = mddev->private;
25492542 if (!conf || !conf->log) {
2550
- mddev_unlock(mddev);
2543
+ spin_unlock(&mddev->lock);
25512544 return 0;
25522545 }
25532546
....@@ -2567,7 +2560,7 @@
25672560 default:
25682561 ret = 0;
25692562 }
2570
- mddev_unlock(mddev);
2563
+ spin_unlock(&mddev->lock);
25712564 return ret;
25722565 }
25732566
....@@ -3162,8 +3155,6 @@
31623155 set_bit(MD_HAS_JOURNAL, &conf->mddev->flags);
31633156 return 0;
31643157
3165
- rcu_assign_pointer(conf->log, NULL);
3166
- md_unregister_thread(&log->reclaim_thread);
31673158 reclaim_thread:
31683159 mempool_exit(&log->meta_pool);
31693160 out_mempool: