26 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/wait.h>
33 #include <linux/slab.h>
34 #include <linux/random.h>
35 #include <linux/string.h>
42 static int w_make_resync_request(
struct drbd_conf *mdev,
103 unsigned long flags = 0;
111 if (list_empty(&mdev->
read_ee))
115 spin_unlock_irqrestore(&mdev->
req_lock, flags);
117 drbd_queue_work(&mdev->
data.work, &
e->w);
125 unsigned long flags = 0;
130 int do_al_complete_io;
138 e_sector =
e->sector;
152 do_wake = is_syncer_req
158 spin_unlock_irqrestore(&mdev->
req_lock, flags);
166 if (do_al_complete_io)
180 int uptodate = bio_flagged(bio, BIO_UPTODATE);
181 int is_write = bio_data_dir(bio) ==
WRITE;
185 is_write ?
"write" :
"read", error,
186 (
unsigned long long)e->
sector);
187 if (!error && !uptodate) {
189 dev_warn(
DEV,
"%s: setting error to -EIO s=%llus\n",
190 is_write ?
"write" :
"read",
191 (
unsigned long long)e->
sector);
204 drbd_endio_write_sec_final(e);
219 int uptodate = bio_flagged(bio, BIO_UPTODATE);
221 if (!error && !uptodate) {
223 bio_data_dir(bio) ==
WRITE ?
"write" :
"read");
232 what = (bio_data_dir(bio) ==
WRITE)
234 : (bio_rw(bio) ==
READ)
246 spin_unlock_irqrestore(&mdev->
req_lock, flags);
284 crypto_hash_init(&desc);
286 while ((tmp = page_chain_next(page))) {
289 crypto_hash_update(&desc, &sg, sg.
length);
294 sg_set_page(&sg, page, len ?:
PAGE_SIZE, 0);
295 crypto_hash_update(&desc, &sg, sg.
length);
296 crypto_hash_final(&desc, digest);
303 struct bio_vec *bvec;
310 crypto_hash_init(&desc);
312 bio_for_each_segment(bvec, bio, i) {
313 sg_set_page(&sg, bvec->bv_page, bvec->bv_len, bvec->bv_offset);
314 crypto_hash_update(&desc, &sg, sg.
length);
316 crypto_hash_final(&desc, digest);
335 digest_size = crypto_hash_digestsize(mdev->
csums_tfm);
348 inc_rs_pending(mdev);
354 dev_err(
DEV,
"kmalloc() of digest failed.\n");
363 dev_err(
DEV,
"drbd_send_drequest(..., csum) failed\n");
367 #define GFP_TRY (__GFP_HIGHMEM | __GFP_NOWARN)
387 list_add(&e->
w.list, &mdev->
read_ee);
412 w_make_ov_request(mdev, w, cancel);
415 w_make_resync_request(mdev, w, cancel);
426 if (list_empty(&mdev->resync_work.list))
427 drbd_queue_work(&mdev->
data.work, &mdev->resync_work);
434 for (i = 0; i < fb->
size; i++)
438 static int fifo_push(
struct fifo_buffer *fb,
int value)
451 static void fifo_add_val(
struct fifo_buffer *fb,
int value)
455 for (i = 0; i < fb->
size; i++)
459 static int drbd_rs_controller(
struct drbd_conf *mdev)
461 unsigned int sect_in;
487 cps = correction /
steps;
492 curr_corr = fifo_push(&mdev->
rs_plan_s, 0);
496 req_sect = sect_in + curr_corr;
501 if (req_sect > max_sect)
513 static int drbd_rs_number_requests(
struct drbd_conf *mdev)
529 static int w_make_resync_request(
struct drbd_conf *mdev,
536 int number, rollback_i,
size;
554 dev_err(
DEV,
"Disk broke down during resync!\n");
558 max_bio_size = queue_max_hw_sectors(mdev->
rq_queue) << 9;
559 number = drbd_rs_number_requests(mdev);
563 for (i = 0; i < number; i++) {
566 if (mdev->
data.socket) {
567 queued = mdev->
data.socket->sk->sk_wmem_queued;
568 sndbuf = mdev->
data.socket->sk->sk_sndbuf;
574 if (queued > sndbuf / 2)
601 #if DRBD_MAX_BIO_SIZE > BM_BLOCK_SIZE
615 if (sector & ((1<<(align+3))-1))
641 if (sector + (size>>9) > capacity)
642 size = (capacity-
sector)<<9;
644 switch (read_for_csum(mdev, sector, size)) {
660 inc_rs_pending(mdev);
663 dev_err(
DEV,
"drbd_send_drequest() failed, aborting...\n");
698 number = drbd_rs_number_requests(mdev);
701 for (i = 0; i < number; i++) {
702 if (sector >= capacity) {
714 if (sector + (size>>9) > capacity)
715 size = (capacity-
sector)<<9;
717 inc_rs_pending(mdev);
772 static void ping_peer(
struct drbd_conf *mdev)
782 unsigned long db, dt, dbdt;
786 char *khelper_cmd =
NULL;
801 w->
cb = w_resync_finished;
802 drbd_queue_work(&mdev->
data.work, w);
805 dev_err(
DEV,
"Warn failed to drbd_rs_del_all() and to kmalloc(w).\n");
833 dev_info(
DEV,
"%s done (total %lu sec; paused %lu sec; %lu K/sec)\n",
834 verify_done ?
"Online verify " :
"Resync",
841 dev_alert(
DEV,
"Online verify found %lu %dk block out of sync!\n",
843 khelper_cmd =
"out-of-sync";
849 khelper_cmd =
"after-resync-target";
856 (t < 100000) ? ((s*100)/t) : (s/(t/100));
857 dev_info(
DEV,
"%u %% had equal checksums, eliminated: %luK; "
858 "transferred %luK total %luK\n",
902 mdev->
p_uuid[i] = mdev->ldev->md.uuid[i];
929 if (drbd_ee_has_active_page(e)) {
963 dev_err(
DEV,
"Sending NegDReply. sector=%llus.\n",
964 (
unsigned long long)e->
sector);
971 move_to_net_ee_or_free(mdev, e);
1004 inc_rs_pending(mdev);
1009 "partner DISKLESS!\n");
1014 dev_err(
DEV,
"Sending NegRSDReply. sector %llus.\n",
1015 (
unsigned long long)e->
sector);
1025 move_to_net_ee_or_free(mdev, e);
1058 digest_size = crypto_hash_digestsize(mdev->
csums_tfm);
1074 inc_rs_pending(mdev);
1083 dev_err(
DEV,
"Sending NegDReply. I guess it gets messy.\n");
1087 move_to_net_ee_or_free(mdev, e);
1090 dev_err(
DEV,
"drbd_send_block/ack() failed\n");
1099 unsigned int size = e->
size;
1107 digest_size = crypto_hash_digestsize(mdev->
verify_tfm);
1117 memset(digest, 0, digest_size);
1126 inc_rs_pending(mdev);
1128 digest, digest_size,
1158 unsigned int size = e->
size;
1178 digest_size = crypto_hash_digestsize(mdev->
verify_tfm);
1208 if ((mdev->
ov_left & 0x200) == 0x200)
1244 if (!drbd_get_data_sock(mdev))
1252 drbd_put_data_sock(mdev);
1319 (
unsigned long)req);
1343 drbd_req_make_private_bio(req, req->
master_bio);
1344 req->
private_bio->bi_bdev = mdev->ldev->backing_bdev;
1350 static int _drbd_may_sync_now(
struct drbd_conf *mdev)
1357 odev = minor_to_mdev(odev->
sync_conf.after);
1361 odev->
state.aftr_isp || odev->
state.peer_isp ||
1362 odev->
state.user_isp)
1379 odev = minor_to_mdev(i);
1384 if (!_drbd_may_sync_now(odev))
1398 static int _drbd_resume_next(
struct drbd_conf *mdev)
1404 odev = minor_to_mdev(i);
1410 if (_drbd_may_sync_now(odev))
1422 _drbd_resume_next(mdev);
1429 _drbd_pause_after(mdev);
1433 static int sync_after_error(
struct drbd_conf *mdev,
int o_minor)
1439 if (o_minor < -1 || minor_to_mdev(o_minor) ==
NULL)
1443 odev = minor_to_mdev(o_minor);
1453 odev = minor_to_mdev(odev->
sync_conf.after);
1463 retcode = sync_after_error(mdev, na);
1467 changes = _drbd_pause_after(mdev);
1468 changes |= _drbd_resume_next(mdev);
1509 r = (r >> 8) & 0xff;
1511 dev_info(
DEV,
"before-resync-target handler returned %d, "
1512 "dropping connection.\n", r);
1518 r = (r >> 8) & 0xff;
1521 dev_info(
DEV,
"before-resync-source handler returned %d, "
1522 "ignoring. Old userland tools?", r);
1524 dev_info(
DEV,
"before-resync-source handler returned %d, "
1525 "dropping connection.\n", r);
1532 drbd_state_lock(mdev);
1536 drbd_state_unlock(mdev);
1542 ns.
aftr_isp = !_drbd_may_sync_now(mdev);
1573 _drbd_pause_after(mdev);
1578 dev_info(
DEV,
"Began resync as %s (will sync %lu KB [%lu bits set]).\n",
1624 drbd_state_unlock(mdev);
1636 while (get_t_state(thi) ==
Running) {
1642 drbd_tcp_uncork(mdev->
data.socket);
1649 drbd_tcp_cork(mdev->
data.socket);
1661 if (get_t_state(thi) !=
Running)
1668 spin_lock_irq(&mdev->
data.work.q_lock);
1681 spin_unlock_irq(&mdev->
data.work.q_lock);
1685 list_del_init(&w->
list);
1686 spin_unlock_irq(&mdev->
data.work.q_lock);
1698 spin_lock_irq(&mdev->
data.work.q_lock);
1700 while (!list_empty(&mdev->
data.work.q)) {
1701 list_splice_init(&mdev->
data.work.q, &work_list);
1702 spin_unlock_irq(&mdev->
data.work.q_lock);
1704 while (!list_empty(&work_list)) {
1706 list_del_init(&w->
list);
1711 spin_lock_irq(&mdev->
data.work.q_lock);
1713 sema_init(&mdev->
data.work.s, 0);
1719 spin_unlock_irq(&mdev->
data.work.q_lock);