aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/block/drbd/drbd_main.c')
-rw-r--r--drivers/block/drbd/drbd_main.c102
1 files changed, 21 insertions, 81 deletions
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index 7258c95e895e..fa650dd85b90 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -2184,43 +2184,6 @@ int drbd_send_ov_request(struct drbd_conf *mdev, sector_t sector, int size)
2184 return ok; 2184 return ok;
2185} 2185}
2186 2186
2187static int drbd_send_delay_probe(struct drbd_conf *mdev, struct drbd_socket *ds)
2188{
2189 struct p_delay_probe dp;
2190 int offset, ok = 0;
2191 struct timeval now;
2192
2193 mutex_lock(&ds->mutex);
2194 if (likely(ds->socket)) {
2195 do_gettimeofday(&now);
2196 offset = now.tv_usec - mdev->dps_time.tv_usec +
2197 (now.tv_sec - mdev->dps_time.tv_sec) * 1000000;
2198 dp.seq_num = cpu_to_be32(mdev->delay_seq);
2199 dp.offset = cpu_to_be32(offset);
2200
2201 ok = _drbd_send_cmd(mdev, ds->socket, P_DELAY_PROBE,
2202 (struct p_header *)&dp, sizeof(dp), 0);
2203 }
2204 mutex_unlock(&ds->mutex);
2205
2206 return ok;
2207}
2208
2209static int drbd_send_delay_probes(struct drbd_conf *mdev)
2210{
2211 int ok;
2212
2213 mdev->delay_seq++;
2214 do_gettimeofday(&mdev->dps_time);
2215 ok = drbd_send_delay_probe(mdev, &mdev->meta);
2216 ok = ok && drbd_send_delay_probe(mdev, &mdev->data);
2217
2218 mdev->dp_volume_last = mdev->send_cnt;
2219 mod_timer(&mdev->delay_probe_timer, jiffies + mdev->sync_conf.dp_interval * HZ / 10);
2220
2221 return ok;
2222}
2223
2224/* called on sndtimeo 2187/* called on sndtimeo
2225 * returns FALSE if we should retry, 2188 * returns FALSE if we should retry,
2226 * TRUE if we think connection is dead 2189 * TRUE if we think connection is dead
@@ -2369,31 +2332,6 @@ static int _drbd_send_zc_ee(struct drbd_conf *mdev, struct drbd_epoch_entry *e)
2369 return 1; 2332 return 1;
2370} 2333}
2371 2334
2372static void consider_delay_probes(struct drbd_conf *mdev)
2373{
2374 if (mdev->state.conn != C_SYNC_SOURCE || mdev->agreed_pro_version < 93)
2375 return;
2376
2377 if (mdev->dp_volume_last + mdev->sync_conf.dp_volume * 2 < mdev->send_cnt)
2378 drbd_send_delay_probes(mdev);
2379}
2380
2381static int w_delay_probes(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
2382{
2383 if (!cancel && mdev->state.conn == C_SYNC_SOURCE)
2384 drbd_send_delay_probes(mdev);
2385
2386 return 1;
2387}
2388
2389static void delay_probe_timer_fn(unsigned long data)
2390{
2391 struct drbd_conf *mdev = (struct drbd_conf *) data;
2392
2393 if (list_empty(&mdev->delay_probe_work.list))
2394 drbd_queue_work(&mdev->data.work, &mdev->delay_probe_work);
2395}
2396
2397/* Used to send write requests 2335/* Used to send write requests
2398 * R_PRIMARY -> Peer (P_DATA) 2336 * R_PRIMARY -> Peer (P_DATA)
2399 */ 2337 */
@@ -2425,15 +2363,15 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
2425 /* NOTE: no need to check if barriers supported here as we would 2363 /* NOTE: no need to check if barriers supported here as we would
2426 * not pass the test in make_request_common in that case 2364 * not pass the test in make_request_common in that case
2427 */ 2365 */
2428 if (bio_rw_flagged(req->master_bio, BIO_RW_BARRIER)) { 2366 if (req->master_bio->bi_rw & REQ_HARDBARRIER) {
2429 dev_err(DEV, "ASSERT FAILED would have set DP_HARDBARRIER\n"); 2367 dev_err(DEV, "ASSERT FAILED would have set DP_HARDBARRIER\n");
2430 /* dp_flags |= DP_HARDBARRIER; */ 2368 /* dp_flags |= DP_HARDBARRIER; */
2431 } 2369 }
2432 if (bio_rw_flagged(req->master_bio, BIO_RW_SYNCIO)) 2370 if (req->master_bio->bi_rw & REQ_SYNC)
2433 dp_flags |= DP_RW_SYNC; 2371 dp_flags |= DP_RW_SYNC;
2434 /* for now handle SYNCIO and UNPLUG 2372 /* for now handle SYNCIO and UNPLUG
2435 * as if they still were one and the same flag */ 2373 * as if they still were one and the same flag */
2436 if (bio_rw_flagged(req->master_bio, BIO_RW_UNPLUG)) 2374 if (req->master_bio->bi_rw & REQ_UNPLUG)
2437 dp_flags |= DP_RW_SYNC; 2375 dp_flags |= DP_RW_SYNC;
2438 if (mdev->state.conn >= C_SYNC_SOURCE && 2376 if (mdev->state.conn >= C_SYNC_SOURCE &&
2439 mdev->state.conn <= C_PAUSED_SYNC_T) 2377 mdev->state.conn <= C_PAUSED_SYNC_T)
@@ -2457,9 +2395,6 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
2457 2395
2458 drbd_put_data_sock(mdev); 2396 drbd_put_data_sock(mdev);
2459 2397
2460 if (ok)
2461 consider_delay_probes(mdev);
2462
2463 return ok; 2398 return ok;
2464} 2399}
2465 2400
@@ -2506,9 +2441,6 @@ int drbd_send_block(struct drbd_conf *mdev, enum drbd_packets cmd,
2506 2441
2507 drbd_put_data_sock(mdev); 2442 drbd_put_data_sock(mdev);
2508 2443
2509 if (ok)
2510 consider_delay_probes(mdev);
2511
2512 return ok; 2444 return ok;
2513} 2445}
2514 2446
@@ -2604,6 +2536,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2604 unsigned long flags; 2536 unsigned long flags;
2605 int rv = 0; 2537 int rv = 0;
2606 2538
2539 lock_kernel();
2607 spin_lock_irqsave(&mdev->req_lock, flags); 2540 spin_lock_irqsave(&mdev->req_lock, flags);
2608 /* to have a stable mdev->state.role 2541 /* to have a stable mdev->state.role
2609 * and no race with updating open_cnt */ 2542 * and no race with updating open_cnt */
@@ -2618,6 +2551,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2618 if (!rv) 2551 if (!rv)
2619 mdev->open_cnt++; 2552 mdev->open_cnt++;
2620 spin_unlock_irqrestore(&mdev->req_lock, flags); 2553 spin_unlock_irqrestore(&mdev->req_lock, flags);
2554 unlock_kernel();
2621 2555
2622 return rv; 2556 return rv;
2623} 2557}
@@ -2625,7 +2559,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2625static int drbd_release(struct gendisk *gd, fmode_t mode) 2559static int drbd_release(struct gendisk *gd, fmode_t mode)
2626{ 2560{
2627 struct drbd_conf *mdev = gd->private_data; 2561 struct drbd_conf *mdev = gd->private_data;
2562 lock_kernel();
2628 mdev->open_cnt--; 2563 mdev->open_cnt--;
2564 unlock_kernel();
2629 return 0; 2565 return 0;
2630} 2566}
2631 2567
@@ -2660,9 +2596,20 @@ static void drbd_unplug_fn(struct request_queue *q)
2660 2596
2661static void drbd_set_defaults(struct drbd_conf *mdev) 2597static void drbd_set_defaults(struct drbd_conf *mdev)
2662{ 2598{
2663 mdev->sync_conf.after = DRBD_AFTER_DEF; 2599 /* This way we get a compile error when sync_conf grows,
2664 mdev->sync_conf.rate = DRBD_RATE_DEF; 2600 and we forgot to initialize it here */
2665 mdev->sync_conf.al_extents = DRBD_AL_EXTENTS_DEF; 2601 mdev->sync_conf = (struct syncer_conf) {
2602 /* .rate = */ DRBD_RATE_DEF,
2603 /* .after = */ DRBD_AFTER_DEF,
2604 /* .al_extents = */ DRBD_AL_EXTENTS_DEF,
2605 /* .verify_alg = */ {}, 0,
2606 /* .cpu_mask = */ {}, 0,
2607 /* .csums_alg = */ {}, 0,
2608 /* .use_rle = */ 0
2609 };
2610
2611 /* Have to use that way, because the layout differs between
2612 big endian and little endian */
2666 mdev->state = (union drbd_state) { 2613 mdev->state = (union drbd_state) {
2667 { .role = R_SECONDARY, 2614 { .role = R_SECONDARY,
2668 .peer = R_UNKNOWN, 2615 .peer = R_UNKNOWN,
@@ -2721,24 +2668,17 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
2721 INIT_LIST_HEAD(&mdev->unplug_work.list); 2668 INIT_LIST_HEAD(&mdev->unplug_work.list);
2722 INIT_LIST_HEAD(&mdev->md_sync_work.list); 2669 INIT_LIST_HEAD(&mdev->md_sync_work.list);
2723 INIT_LIST_HEAD(&mdev->bm_io_work.w.list); 2670 INIT_LIST_HEAD(&mdev->bm_io_work.w.list);
2724 INIT_LIST_HEAD(&mdev->delay_probes);
2725 INIT_LIST_HEAD(&mdev->delay_probe_work.list);
2726 2671
2727 mdev->resync_work.cb = w_resync_inactive; 2672 mdev->resync_work.cb = w_resync_inactive;
2728 mdev->unplug_work.cb = w_send_write_hint; 2673 mdev->unplug_work.cb = w_send_write_hint;
2729 mdev->md_sync_work.cb = w_md_sync; 2674 mdev->md_sync_work.cb = w_md_sync;
2730 mdev->bm_io_work.w.cb = w_bitmap_io; 2675 mdev->bm_io_work.w.cb = w_bitmap_io;
2731 mdev->delay_probe_work.cb = w_delay_probes;
2732 init_timer(&mdev->resync_timer); 2676 init_timer(&mdev->resync_timer);
2733 init_timer(&mdev->md_sync_timer); 2677 init_timer(&mdev->md_sync_timer);
2734 init_timer(&mdev->delay_probe_timer);
2735 mdev->resync_timer.function = resync_timer_fn; 2678 mdev->resync_timer.function = resync_timer_fn;
2736 mdev->resync_timer.data = (unsigned long) mdev; 2679 mdev->resync_timer.data = (unsigned long) mdev;
2737 mdev->md_sync_timer.function = md_sync_timer_fn; 2680 mdev->md_sync_timer.function = md_sync_timer_fn;
2738 mdev->md_sync_timer.data = (unsigned long) mdev; 2681 mdev->md_sync_timer.data = (unsigned long) mdev;
2739 mdev->delay_probe_timer.function = delay_probe_timer_fn;
2740 mdev->delay_probe_timer.data = (unsigned long) mdev;
2741
2742 2682
2743 init_waitqueue_head(&mdev->misc_wait); 2683 init_waitqueue_head(&mdev->misc_wait);
2744 init_waitqueue_head(&mdev->state_wait); 2684 init_waitqueue_head(&mdev->state_wait);