History

raid5: separate header for log functions

Move raid5-cache declarations from raid5.h to raid5-log.h, add inline wrappers for functions which will be shared with ppl and use them in raid5 core instead of direct calls to raid5-cache. Remove unused parameter from r5c_cache_data(), move two duplicated pr_debug() calls to r5l_init_log().

Artur Paszkiewicz committed 9 years ago

Commit ff875731 parent ea0213e4 files · +107 −69Browse files

Unified · Split

4 files
  1. drivers/md/raid5-cache.c +13 −4
  2. drivers/md/raid5-log.h +81 −0
  3. drivers/md/raid5.c +13 −35
  4. drivers/md/raid5.h +0 −30
drivers/md/raid5-cache.c+13−4
@@ -344,6 +344,8 @@ void r5c_handle_cached_data_endio(struct r5conf *conf, · 343 unmodified lines
344344 }
345345 }
346346
347+void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
348+
347349 /* Check whether we should flush some stripes to free up stripe cache */
348350 void r5c_check_stripe_cache_usage(struct r5conf *conf)
349351 {
@@ -2749,9 +2751,7 @@ void r5c_finish_stripe_write_out(struct r5conf *conf, · 2399 unmodified lines
27492751 }
27502752 }
27512753
2752−int
2753−r5c_cache_data(struct r5l_log *log, struct stripe_head *sh,
2754− struct stripe_head_state *s)
2754+int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh)
27552755 {
27562756 struct r5conf *conf = sh->raid_conf;
27572757 int pages = 0;
@@ -2914,6 +2914,10 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev) · 156 unmodified lines
29142914 {
29152915 struct request_queue *q = bdev_get_queue(rdev->bdev);
29162916 struct r5l_log *log;
2917+ char b[BDEVNAME_SIZE];
2918+
2919+ pr_debug("md/raid:%s: using device %s as journal\n",
2920+ mdname(conf->mddev), bdevname(rdev->bdev, b));
29172921
29182922 if (PAGE_SIZE != 4096)
29192923 return -EINVAL;
@@ -3016,8 +3020,13 @@ io_kc: · 96 unmodified lines
30163020 return -EINVAL;
30173021 }
30183022
3019−void r5l_exit_log(struct r5l_log *log)
3023+void r5l_exit_log(struct r5conf *conf)
30203024 {
3025+ struct r5l_log *log = conf->log;
3026+
3027+ conf->log = NULL;
3028+ synchronize_rcu();
3029+
30213030 flush_work(&log->disable_writeback_work);
30223031 md_unregister_thread(&log->reclaim_thread);
30233032 mempool_destroy(log->meta_pool);
drivers/md/raid5-log.h+81−0
@@ -0,0 +1,81 @@
1+#ifndef _RAID5_LOG_H
2+#define _RAID5_LOG_H
3+
4+extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
5+extern void r5l_exit_log(struct r5conf *conf);
6+extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
7+extern void r5l_write_stripe_run(struct r5l_log *log);
8+extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
9+extern void r5l_stripe_write_finished(struct stripe_head *sh);
10+extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
11+extern void r5l_quiesce(struct r5l_log *log, int state);
12+extern bool r5l_log_disk_error(struct r5conf *conf);
13+extern bool r5c_is_writeback(struct r5l_log *log);
14+extern int
15+r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
16+ struct stripe_head_state *s, int disks);
17+extern void
18+r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh,
19+ struct stripe_head_state *s);
20+extern void r5c_release_extra_page(struct stripe_head *sh);
21+extern void r5c_use_extra_page(struct stripe_head *sh);
22+extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
23+extern void r5c_handle_cached_data_endio(struct r5conf *conf,
24+ struct stripe_head *sh, int disks, struct bio_list *return_bi);
25+extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh);
26+extern void r5c_make_stripe_write_out(struct stripe_head *sh);
27+extern void r5c_flush_cache(struct r5conf *conf, int num);
28+extern void r5c_check_stripe_cache_usage(struct r5conf *conf);
29+extern void r5c_check_cached_full_stripe(struct r5conf *conf);
30+extern struct md_sysfs_entry r5c_journal_mode;
31+extern void r5c_update_on_rdev_error(struct mddev *mddev);
32+extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect);
33+
34+static inline int log_stripe(struct stripe_head *sh, struct stripe_head_state *s)
35+{
36+ struct r5conf *conf = sh->raid_conf;
37+
38+ if (conf->log) {
39+ if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) {
40+ /* writing out phase */
41+ if (s->waiting_extra_page)
42+ return 0;
43+ return r5l_write_stripe(conf->log, sh);
44+ } else if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) {
45+ /* caching phase */
46+ return r5c_cache_data(conf->log, sh);
47+ }
48+ }
49+
50+ return -EAGAIN;
51+}
52+
53+static inline void log_stripe_write_finished(struct stripe_head *sh)
54+{
55+ struct r5conf *conf = sh->raid_conf;
56+
57+ if (conf->log)
58+ r5l_stripe_write_finished(sh);
59+}
60+
61+static inline void log_write_stripe_run(struct r5conf *conf)
62+{
63+ if (conf->log)
64+ r5l_write_stripe_run(conf->log);
65+}
66+
67+static inline void log_exit(struct r5conf *conf)
68+{
69+ if (conf->log)
70+ r5l_exit_log(conf);
71+}
72+
73+static inline int log_init(struct r5conf *conf, struct md_rdev *journal_dev)
74+{
75+ if (journal_dev)
76+ return r5l_init_log(conf, journal_dev);
77+
78+ return 0;
79+}
80+
81+#endif
drivers/md/raid5.c+13−35
@@ -64,6 +64,7 @@ · 63 unmodified lines
6464 #include "raid5.h"
6565 #include "raid0.h"
6666 #include "bitmap.h"
67+#include "raid5-log.h"
6768
6869 #define UNSUPPORTED_MDDEV_FLAGS (1L << MD_FAILFAST_SUPPORTED)
6970
@@ -997,18 +998,8 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) · 927 unmodified lines
997998
998999 might_sleep();
9991000
1000− if (!test_bit(STRIPE_R5C_CACHING, &sh->state)) {
1001− /* writing out phase */
1002− if (s->waiting_extra_page)
1003− return;
1004− if (r5l_write_stripe(conf->log, sh) == 0)
1005− return;
1006− } else { /* caching phase */
1007− if (test_bit(STRIPE_LOG_TRAPPED, &sh->state)) {
1008− r5c_cache_data(conf->log, sh, s);
1009− return;
1010− }
1011− }
1001+ if (log_stripe(sh, s) == 0)
1002+ return;
10121003
10131004 should_defer = conf->batch_bio_dispatch && conf->group_cnt;
10141005
@@ -3345,7 +3336,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh, · 2330 unmodified lines
33453336 if (bi)
33463337 bitmap_end = 1;
33473338
3348− r5l_stripe_write_finished(sh);
3339+ log_stripe_write_finished(sh);
33493340
33503341 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
33513342 wake_up(&conf->wait_for_overlap);
@@ -3764,7 +3755,7 @@ returnbi: · 412 unmodified lines
37643755 discard_pending = 1;
37653756 }
37663757
3767− r5l_stripe_write_finished(sh);
3758+ log_stripe_write_finished(sh);
37683759
37693760 if (!discard_pending &&
37703761 test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags)) {
@@ -4754,7 +4745,7 @@ static void handle_stripe(struct stripe_head *sh) · 983 unmodified lines
47544745
47554746 if (s.just_cached)
47564747 r5c_handle_cached_data_endio(conf, sh, disks, &s.return_bi);
4757− r5l_stripe_write_finished(sh);
4748+ log_stripe_write_finished(sh);
47584749
47594750 /* Now we might consider reading some blocks, either to check/generate
47604751 * parity, or to satisfy requests
@@ -6168,7 +6159,7 @@ static int handle_active_stripes(struct r5conf *conf, int group, · 1407 unmodified lines
61686159
61696160 for (i = 0; i < batch_size; i++)
61706161 handle_stripe(batch[i]);
6171− r5l_write_stripe_run(conf->log);
6162+ log_write_stripe_run(conf);
61726163
61736164 cond_resched();
61746165
@@ -6745,8 +6736,8 @@ static void free_conf(struct r5conf *conf) · 570 unmodified lines
67456736 {
67466737 int i;
67476738
6748− if (conf->log)
6749− r5l_exit_log(conf->log);
6739+ log_exit(conf);
6740+
67506741 if (conf->shrinker.nr_deferred)
67516742 unregister_shrinker(&conf->shrinker);
67526743
@@ -7436,14 +7427,8 @@ static int raid5_run(struct mddev *mddev) · 683 unmodified lines
74367427 blk_queue_max_hw_sectors(mddev->queue, UINT_MAX);
74377428 }
74387429
7439− if (journal_dev) {
7440− char b[BDEVNAME_SIZE];
7441−
7442− pr_debug("md/raid:%s: using device %s as journal\n",
7443− mdname(mddev), bdevname(journal_dev->bdev, b));
7444− if (r5l_init_log(conf, journal_dev))
7445− goto abort;
7446− }
7430+ if (log_init(conf, journal_dev))
7431+ goto abort;
74477432
74487433 return 0;
74497434 abort:
@@ -7557,17 +7542,13 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) · 107 unmodified lines
75577542
75587543 print_raid5_conf(conf);
75597544 if (test_bit(Journal, &rdev->flags) && conf->log) {
7560− struct r5l_log *log;
75617545 /*
75627546 * we can't wait pending write here, as this is called in
75637547 * raid5d, wait will deadlock.
75647548 */
75657549 if (atomic_read(&mddev->writes_pending))
75667550 return -EBUSY;
7567− log = conf->log;
7568− conf->log = NULL;
7569− synchronize_rcu();
7570− r5l_exit_log(log);
7551+ log_exit(conf);
75717552 return 0;
75727553 }
75737554 if (rdev == p->rdev)
@@ -7636,7 +7617,6 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) · 62 unmodified lines
76367617 int last = conf->raid_disks - 1;
76377618
76387619 if (test_bit(Journal, &rdev->flags)) {
7639− char b[BDEVNAME_SIZE];
76407620 if (conf->log)
76417621 return -EBUSY;
76427622
@@ -7645,9 +7625,7 @@ static int raid5_add_disk(struct mddev *mddev, struct md_rdev *rdev) · 2 unmodified lines
76457625 * The array is in readonly mode if journal is missing, so no
76467626 * write requests running. We should be safe
76477627 */
7648− r5l_init_log(conf, rdev);
7649− pr_debug("md/raid:%s: using device %s as journal\n",
7650− mdname(mddev), bdevname(rdev->bdev, b));
7628+ log_init(conf, rdev);
76517629 return 0;
76527630 }
76537631 if (mddev->recovery_disabled == conf->recovery_disabled)
drivers/md/raid5.h+0−30
@@ -779,34 +779,4 @@ extern struct stripe_head * · 778 unmodified lines
779779 raid5_get_active_stripe(struct r5conf *conf, sector_t sector,
780780 int previous, int noblock, int noquiesce);
781781 extern int raid5_calc_degraded(struct r5conf *conf);
782−extern int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev);
783−extern void r5l_exit_log(struct r5l_log *log);
784−extern int r5l_write_stripe(struct r5l_log *log, struct stripe_head *head_sh);
785−extern void r5l_write_stripe_run(struct r5l_log *log);
786−extern void r5l_flush_stripe_to_raid(struct r5l_log *log);
787−extern void r5l_stripe_write_finished(struct stripe_head *sh);
788−extern int r5l_handle_flush_request(struct r5l_log *log, struct bio *bio);
789−extern void r5l_quiesce(struct r5l_log *log, int state);
790−extern bool r5l_log_disk_error(struct r5conf *conf);
791−extern bool r5c_is_writeback(struct r5l_log *log);
792−extern int
793−r5c_try_caching_write(struct r5conf *conf, struct stripe_head *sh,
794− struct stripe_head_state *s, int disks);
795−extern void
796−r5c_finish_stripe_write_out(struct r5conf *conf, struct stripe_head *sh,
797− struct stripe_head_state *s);
798−extern void r5c_release_extra_page(struct stripe_head *sh);
799−extern void r5c_use_extra_page(struct stripe_head *sh);
800−extern void r5l_wake_reclaim(struct r5l_log *log, sector_t space);
801−extern void r5c_handle_cached_data_endio(struct r5conf *conf,
802− struct stripe_head *sh, int disks, struct bio_list *return_bi);
803−extern int r5c_cache_data(struct r5l_log *log, struct stripe_head *sh,
804− struct stripe_head_state *s);
805−extern void r5c_make_stripe_write_out(struct stripe_head *sh);
806−extern void r5c_flush_cache(struct r5conf *conf, int num);
807−extern void r5c_check_stripe_cache_usage(struct r5conf *conf);
808−extern void r5c_check_cached_full_stripe(struct r5conf *conf);
809−extern struct md_sysfs_entry r5c_journal_mode;
810−extern void r5c_update_on_rdev_error(struct mddev *mddev);
811−extern bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect);
812782 #endif

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t