a9111b68fe2de6f423638da54a7a3e1f8a5d980e
[firefly-linux-kernel-4.4.55.git] / drivers / block / drbd / drbd_req.c
1 /*
2    drbd_req.c
3
4    This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5
6    Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
7    Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
8    Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
9
10    drbd is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2, or (at your option)
13    any later version.
14
15    drbd is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with drbd; see the file COPYING.  If not, write to
22    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24  */
25
26 #include <linux/module.h>
27
28 #include <linux/slab.h>
29 #include <linux/drbd.h>
30 #include "drbd_int.h"
31 #include "drbd_req.h"
32
33
34 static bool drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size);
35
36 /* Update disk stats at start of I/O request */
37 static void _drbd_start_io_acct(struct drbd_conf *mdev, struct drbd_request *req, struct bio *bio)
38 {
39         const int rw = bio_data_dir(bio);
40         int cpu;
41         cpu = part_stat_lock();
42         part_round_stats(cpu, &mdev->vdisk->part0);
43         part_stat_inc(cpu, &mdev->vdisk->part0, ios[rw]);
44         part_stat_add(cpu, &mdev->vdisk->part0, sectors[rw], bio_sectors(bio));
45         (void) cpu; /* The macro invocations above want the cpu argument, I do not like
46                        the compiler warning about cpu only assigned but never used... */
47         part_inc_in_flight(&mdev->vdisk->part0, rw);
48         part_stat_unlock();
49 }
50
51 /* Update disk stats when completing request upwards */
52 static void _drbd_end_io_acct(struct drbd_conf *mdev, struct drbd_request *req)
53 {
54         int rw = bio_data_dir(req->master_bio);
55         unsigned long duration = jiffies - req->start_time;
56         int cpu;
57         cpu = part_stat_lock();
58         part_stat_add(cpu, &mdev->vdisk->part0, ticks[rw], duration);
59         part_round_stats(cpu, &mdev->vdisk->part0);
60         part_dec_in_flight(&mdev->vdisk->part0, rw);
61         part_stat_unlock();
62 }
63
64 static struct drbd_request *drbd_req_new(struct drbd_conf *mdev,
65                                                struct bio *bio_src)
66 {
67         struct drbd_request *req;
68
69         req = mempool_alloc(drbd_request_mempool, GFP_NOIO);
70         if (!req)
71                 return NULL;
72
73         drbd_req_make_private_bio(req, bio_src);
74         req->rq_state    = bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0;
75         req->w.mdev      = mdev;
76         req->master_bio  = bio_src;
77         req->epoch       = 0;
78
79         drbd_clear_interval(&req->i);
80         req->i.sector     = bio_src->bi_sector;
81         req->i.size      = bio_src->bi_size;
82         req->i.local = true;
83         req->i.waiting = false;
84
85         INIT_LIST_HEAD(&req->tl_requests);
86         INIT_LIST_HEAD(&req->w.list);
87
88         /* one reference to be put by __drbd_make_request */
89         atomic_set(&req->completion_ref, 1);
90         /* one kref as long as completion_ref > 0 */
91         kref_init(&req->kref);
92         return req;
93 }
94
95 void drbd_req_destroy(struct kref *kref)
96 {
97         struct drbd_request *req = container_of(kref, struct drbd_request, kref);
98         struct drbd_conf *mdev = req->w.mdev;
99         const unsigned s = req->rq_state;
100
101         if ((req->master_bio && !(s & RQ_POSTPONED)) ||
102                 atomic_read(&req->completion_ref) ||
103                 (s & RQ_LOCAL_PENDING) ||
104                 ((s & RQ_NET_MASK) && !(s & RQ_NET_DONE))) {
105                 dev_err(DEV, "drbd_req_destroy: Logic BUG rq_state = 0x%x, completion_ref = %d\n",
106                                 s, atomic_read(&req->completion_ref));
107                 return;
108         }
109
110         /* remove it from the transfer log.
111          * well, only if it had been there in the first
112          * place... if it had not (local only or conflicting
113          * and never sent), it should still be "empty" as
114          * initialized in drbd_req_new(), so we can list_del() it
115          * here unconditionally */
116         list_del_init(&req->tl_requests);
117
118         /* if it was a write, we may have to set the corresponding
119          * bit(s) out-of-sync first. If it had a local part, we need to
120          * release the reference to the activity log. */
121         if (s & RQ_WRITE) {
122                 /* Set out-of-sync unless both OK flags are set
123                  * (local only or remote failed).
124                  * Other places where we set out-of-sync:
125                  * READ with local io-error */
126                 if (!(s & RQ_NET_OK) || !(s & RQ_LOCAL_OK))
127                         drbd_set_out_of_sync(mdev, req->i.sector, req->i.size);
128
129                 if ((s & RQ_NET_OK) && (s & RQ_LOCAL_OK) && (s & RQ_NET_SIS))
130                         drbd_set_in_sync(mdev, req->i.sector, req->i.size);
131
132                 /* one might be tempted to move the drbd_al_complete_io
133                  * to the local io completion callback drbd_request_endio.
134                  * but, if this was a mirror write, we may only
135                  * drbd_al_complete_io after this is RQ_NET_DONE,
136                  * otherwise the extent could be dropped from the al
137                  * before it has actually been written on the peer.
138                  * if we crash before our peer knows about the request,
139                  * but after the extent has been dropped from the al,
140                  * we would forget to resync the corresponding extent.
141                  */
142                 if (s & RQ_LOCAL_MASK) {
143                         if (get_ldev_if_state(mdev, D_FAILED)) {
144                                 if (s & RQ_IN_ACT_LOG)
145                                         drbd_al_complete_io(mdev, &req->i);
146                                 put_ldev(mdev);
147                         } else if (__ratelimit(&drbd_ratelimit_state)) {
148                                 dev_warn(DEV, "Should have called drbd_al_complete_io(, %llu, %u), "
149                                          "but my Disk seems to have failed :(\n",
150                                          (unsigned long long) req->i.sector, req->i.size);
151                         }
152                 }
153         }
154
155         mempool_free(req, drbd_request_mempool);
156 }
157
158 static void wake_all_senders(struct drbd_tconn *tconn) {
159         wake_up(&tconn->sender_work.q_wait);
160 }
161
162 /* must hold resource->req_lock */
163 static void start_new_tl_epoch(struct drbd_tconn *tconn)
164 {
165         tconn->current_tle_writes = 0;
166         atomic_inc(&tconn->current_tle_nr);
167         wake_all_senders(tconn);
168 }
169
170 void complete_master_bio(struct drbd_conf *mdev,
171                 struct bio_and_error *m)
172 {
173         bio_endio(m->bio, m->error);
174         dec_ap_bio(mdev);
175 }
176
177
178 static void drbd_remove_request_interval(struct rb_root *root,
179                                          struct drbd_request *req)
180 {
181         struct drbd_conf *mdev = req->w.mdev;
182         struct drbd_interval *i = &req->i;
183
184         drbd_remove_interval(root, i);
185
186         /* Wake up any processes waiting for this request to complete.  */
187         if (i->waiting)
188                 wake_up(&mdev->misc_wait);
189 }
190
191 /* Helper for __req_mod().
192  * Set m->bio to the master bio, if it is fit to be completed,
193  * or leave it alone (it is initialized to NULL in __req_mod),
194  * if it has already been completed, or cannot be completed yet.
195  * If m->bio is set, the error status to be returned is placed in m->error.
196  */
197 static
198 void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
199 {
200         const unsigned s = req->rq_state;
201         struct drbd_conf *mdev = req->w.mdev;
202         int rw;
203         int error, ok;
204
205         /* we must not complete the master bio, while it is
206          *      still being processed by _drbd_send_zc_bio (drbd_send_dblock)
207          *      not yet acknowledged by the peer
208          *      not yet completed by the local io subsystem
209          * these flags may get cleared in any order by
210          *      the worker,
211          *      the receiver,
212          *      the bio_endio completion callbacks.
213          */
214         if ((s & RQ_LOCAL_PENDING && !(s & RQ_LOCAL_ABORTED)) ||
215             (s & RQ_NET_QUEUED) || (s & RQ_NET_PENDING) ||
216             (s & RQ_COMPLETION_SUSP)) {
217                 dev_err(DEV, "drbd_req_complete: Logic BUG rq_state = 0x%x\n", s);
218                 return;
219         }
220
221         if (!req->master_bio) {
222                 dev_err(DEV, "drbd_req_complete: Logic BUG, master_bio == NULL!\n");
223                 return;
224         }
225
226         rw = bio_rw(req->master_bio);
227
228         /*
229          * figure out whether to report success or failure.
230          *
231          * report success when at least one of the operations succeeded.
232          * or, to put the other way,
233          * only report failure, when both operations failed.
234          *
235          * what to do about the failures is handled elsewhere.
236          * what we need to do here is just: complete the master_bio.
237          *
238          * local completion error, if any, has been stored as ERR_PTR
239          * in private_bio within drbd_request_endio.
240          */
241         ok = (s & RQ_LOCAL_OK) || (s & RQ_NET_OK);
242         error = PTR_ERR(req->private_bio);
243
244         /* remove the request from the conflict detection
245          * respective block_id verification hash */
246         if (!drbd_interval_empty(&req->i)) {
247                 struct rb_root *root;
248
249                 if (rw == WRITE)
250                         root = &mdev->write_requests;
251                 else
252                         root = &mdev->read_requests;
253                 drbd_remove_request_interval(root, req);
254         } else if (!(s & RQ_POSTPONED))
255                 D_ASSERT((s & (RQ_NET_MASK & ~RQ_NET_DONE)) == 0);
256
257         /* Before we can signal completion to the upper layers,
258          * we may need to close the current transfer log epoch.
259          * We are within the request lock, so we can simply compare
260          * the request epoch number with the current transfer log
261          * epoch number.  If they match, increase the current_tle_nr,
262          * and reset the transfer log epoch write_cnt.
263          */
264         if (rw == WRITE &&
265             req->epoch == atomic_read(&mdev->tconn->current_tle_nr))
266                 start_new_tl_epoch(mdev->tconn);
267
268         /* Update disk stats */
269         _drbd_end_io_acct(mdev, req);
270
271         /* If READ failed,
272          * have it be pushed back to the retry work queue,
273          * so it will re-enter __drbd_make_request(),
274          * and be re-assigned to a suitable local or remote path,
275          * or failed if we do not have access to good data anymore.
276          *
277          * Unless it was failed early by __drbd_make_request(),
278          * because no path was available, in which case
279          * it was not even added to the transfer_log.
280          *
281          * READA may fail, and will not be retried.
282          *
283          * WRITE should have used all available paths already.
284          */
285         if (!ok && rw == READ && !list_empty(&req->tl_requests))
286                 req->rq_state |= RQ_POSTPONED;
287
288         if (!(req->rq_state & RQ_POSTPONED)) {
289                 m->error = ok ? 0 : (error ?: -EIO);
290                 m->bio = req->master_bio;
291                 req->master_bio = NULL;
292         }
293 }
294
295 static int drbd_req_put_completion_ref(struct drbd_request *req, struct bio_and_error *m, int put)
296 {
297         struct drbd_conf *mdev = req->w.mdev;
298         D_ASSERT(m || (req->rq_state & RQ_POSTPONED));
299
300         if (!atomic_sub_and_test(put, &req->completion_ref))
301                 return 0;
302
303         if (drbd_suspended(mdev)) {
304                 /* We do not allow completion while suspended.  Re-get a
305                  * reference, so whatever happens when this is resumed
306                  * may put and complete. */
307
308                 D_ASSERT(!(req->rq_state & RQ_COMPLETION_SUSP));
309                 req->rq_state |= RQ_COMPLETION_SUSP;
310                 atomic_inc(&req->completion_ref);
311                 return 0;
312         }
313
314         /* else */
315         drbd_req_complete(req, m);
316
317         if (req->rq_state & RQ_POSTPONED) {
318                 /* don't destroy the req object just yet,
319                  * but queue it for retry */
320                 drbd_restart_request(req);
321                 return 0;
322         }
323
324         return 1;
325 }
326
327 /* I'd like this to be the only place that manipulates
328  * req->completion_ref and req->kref. */
329 static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
330                 int clear, int set)
331 {
332         struct drbd_conf *mdev = req->w.mdev;
333         unsigned s = req->rq_state;
334         int c_put = 0;
335         int k_put = 0;
336
337         /* apply */
338
339         req->rq_state &= ~clear;
340         req->rq_state |= set;
341
342         /* no change? */
343         if (req->rq_state == s)
344                 return;
345
346         /* intent: get references */
347
348         if (!(s & RQ_LOCAL_PENDING) && (set & RQ_LOCAL_PENDING))
349                 atomic_inc(&req->completion_ref);
350
351         if (!(s & RQ_NET_PENDING) && (set & RQ_NET_PENDING)) {
352                 inc_ap_pending(mdev);
353                 atomic_inc(&req->completion_ref);
354         }
355
356         if (!(s & RQ_NET_QUEUED) && (set & RQ_NET_QUEUED))
357                 atomic_inc(&req->completion_ref);
358
359         if (!(s & RQ_EXP_BARR_ACK) && (set & RQ_EXP_BARR_ACK))
360                 kref_get(&req->kref); /* wait for the DONE */
361
362         if (!(s & RQ_NET_SENT) && (set & RQ_NET_SENT))
363                 atomic_add(req->i.size >> 9, &mdev->ap_in_flight);
364
365         /* progress: put references */
366
367         if ((s & RQ_COMPLETION_SUSP) && (clear & RQ_COMPLETION_SUSP))
368                 ++c_put;
369
370         if (!(s & RQ_LOCAL_ABORTED) && (set & RQ_LOCAL_ABORTED)) {
371                 D_ASSERT(req->rq_state & RQ_LOCAL_PENDING);
372                 /* local completion may still come in later,
373                  * we need to keep the req object around. */
374                 kref_get(&req->kref);
375                 ++c_put;
376         }
377
378         if ((s & RQ_LOCAL_PENDING) && (clear & RQ_LOCAL_PENDING)) {
379                 if (req->rq_state & RQ_LOCAL_ABORTED)
380                         ++k_put;
381                 else
382                         ++c_put;
383         }
384
385         if ((s & RQ_NET_PENDING) && (clear & RQ_NET_PENDING)) {
386                 dec_ap_pending(mdev);
387                 ++c_put;
388         }
389
390         if ((s & RQ_NET_QUEUED) && (clear & RQ_NET_QUEUED))
391                 ++c_put;
392
393         if ((s & RQ_EXP_BARR_ACK) && !(s & RQ_NET_DONE) && (set & RQ_NET_DONE)) {
394                 if (req->rq_state & RQ_NET_SENT)
395                         atomic_sub(req->i.size >> 9, &mdev->ap_in_flight);
396                 ++k_put;
397         }
398
399         /* potentially complete and destroy */
400
401         if (k_put || c_put) {
402                 /* Completion does it's own kref_put.  If we are going to
403                  * kref_sub below, we need req to be still around then. */
404                 int at_least = k_put + !!c_put;
405                 int refcount = atomic_read(&req->kref.refcount);
406                 if (refcount < at_least)
407                         dev_err(DEV,
408                                 "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n",
409                                 s, req->rq_state, refcount, at_least);
410         }
411
412         /* If we made progress, retry conflicting peer requests, if any. */
413         if (req->i.waiting)
414                 wake_up(&mdev->misc_wait);
415
416         if (c_put)
417                 k_put += drbd_req_put_completion_ref(req, m, c_put);
418         if (k_put)
419                 kref_sub(&req->kref, k_put, drbd_req_destroy);
420 }
421
422 /* obviously this could be coded as many single functions
423  * instead of one huge switch,
424  * or by putting the code directly in the respective locations
425  * (as it has been before).
426  *
427  * but having it this way
428  *  enforces that it is all in this one place, where it is easier to audit,
429  *  it makes it obvious that whatever "event" "happens" to a request should
430  *  happen "atomically" within the req_lock,
431  *  and it enforces that we have to think in a very structured manner
432  *  about the "events" that may happen to a request during its life time ...
433  */
434 int __req_mod(struct drbd_request *req, enum drbd_req_event what,
435                 struct bio_and_error *m)
436 {
437         struct drbd_conf *mdev = req->w.mdev;
438         struct net_conf *nc;
439         int p, rv = 0;
440
441         if (m)
442                 m->bio = NULL;
443
444         switch (what) {
445         default:
446                 dev_err(DEV, "LOGIC BUG in %s:%u\n", __FILE__ , __LINE__);
447                 break;
448
449         /* does not happen...
450          * initialization done in drbd_req_new
451         case CREATED:
452                 break;
453                 */
454
455         case TO_BE_SENT: /* via network */
456                 /* reached via __drbd_make_request
457                  * and from w_read_retry_remote */
458                 D_ASSERT(!(req->rq_state & RQ_NET_MASK));
459                 rcu_read_lock();
460                 nc = rcu_dereference(mdev->tconn->net_conf);
461                 p = nc->wire_protocol;
462                 rcu_read_unlock();
463                 req->rq_state |=
464                         p == DRBD_PROT_C ? RQ_EXP_WRITE_ACK :
465                         p == DRBD_PROT_B ? RQ_EXP_RECEIVE_ACK : 0;
466                 mod_rq_state(req, m, 0, RQ_NET_PENDING);
467                 break;
468
469         case TO_BE_SUBMITTED: /* locally */
470                 /* reached via __drbd_make_request */
471                 D_ASSERT(!(req->rq_state & RQ_LOCAL_MASK));
472                 mod_rq_state(req, m, 0, RQ_LOCAL_PENDING);
473                 break;
474
475         case COMPLETED_OK:
476                 if (req->rq_state & RQ_WRITE)
477                         mdev->writ_cnt += req->i.size >> 9;
478                 else
479                         mdev->read_cnt += req->i.size >> 9;
480
481                 mod_rq_state(req, m, RQ_LOCAL_PENDING,
482                                 RQ_LOCAL_COMPLETED|RQ_LOCAL_OK);
483                 break;
484
485         case ABORT_DISK_IO:
486                 mod_rq_state(req, m, 0, RQ_LOCAL_ABORTED);
487                 break;
488
489         case READ_COMPLETED_WITH_ERROR:
490                 drbd_set_out_of_sync(mdev, req->i.sector, req->i.size);
491                 /* fall through. */
492         case WRITE_COMPLETED_WITH_ERROR:
493                 __drbd_chk_io_error(mdev, DRBD_IO_ERROR);
494                 /* fall through. */
495         case READ_AHEAD_COMPLETED_WITH_ERROR:
496                 /* it is legal to fail READA, no __drbd_chk_io_error in that case. */
497                 mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED);
498                 break;
499
500         case QUEUE_FOR_NET_READ:
501                 /* READ or READA, and
502                  * no local disk,
503                  * or target area marked as invalid,
504                  * or just got an io-error. */
505                 /* from __drbd_make_request
506                  * or from bio_endio during read io-error recovery */
507
508                 /* So we can verify the handle in the answer packet.
509                  * Corresponding drbd_remove_request_interval is in
510                  * drbd_req_complete() */
511                 D_ASSERT(drbd_interval_empty(&req->i));
512                 drbd_insert_interval(&mdev->read_requests, &req->i);
513
514                 set_bit(UNPLUG_REMOTE, &mdev->flags);
515
516                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
517                 D_ASSERT((req->rq_state & RQ_LOCAL_MASK) == 0);
518                 mod_rq_state(req, m, 0, RQ_NET_QUEUED);
519                 req->w.cb = w_send_read_req;
520                 drbd_queue_work(&mdev->tconn->sender_work, &req->w);
521                 break;
522
523         case QUEUE_FOR_NET_WRITE:
524                 /* assert something? */
525                 /* from __drbd_make_request only */
526
527                 /* Corresponding drbd_remove_request_interval is in
528                  * drbd_req_complete() */
529                 D_ASSERT(drbd_interval_empty(&req->i));
530                 drbd_insert_interval(&mdev->write_requests, &req->i);
531
532                 /* NOTE
533                  * In case the req ended up on the transfer log before being
534                  * queued on the worker, it could lead to this request being
535                  * missed during cleanup after connection loss.
536                  * So we have to do both operations here,
537                  * within the same lock that protects the transfer log.
538                  *
539                  * _req_add_to_epoch(req); this has to be after the
540                  * _maybe_start_new_epoch(req); which happened in
541                  * __drbd_make_request, because we now may set the bit
542                  * again ourselves to close the current epoch.
543                  *
544                  * Add req to the (now) current epoch (barrier). */
545
546                 /* otherwise we may lose an unplug, which may cause some remote
547                  * io-scheduler timeout to expire, increasing maximum latency,
548                  * hurting performance. */
549                 set_bit(UNPLUG_REMOTE, &mdev->flags);
550
551                 /* queue work item to send data */
552                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
553                 mod_rq_state(req, m, 0, RQ_NET_QUEUED|RQ_EXP_BARR_ACK);
554                 req->w.cb =  w_send_dblock;
555                 drbd_queue_work(&mdev->tconn->sender_work, &req->w);
556
557                 /* close the epoch, in case it outgrew the limit */
558                 rcu_read_lock();
559                 nc = rcu_dereference(mdev->tconn->net_conf);
560                 p = nc->max_epoch_size;
561                 rcu_read_unlock();
562                 if (mdev->tconn->current_tle_writes >= p)
563                         start_new_tl_epoch(mdev->tconn);
564
565                 break;
566
567         case QUEUE_FOR_SEND_OOS:
568                 mod_rq_state(req, m, 0, RQ_NET_QUEUED);
569                 req->w.cb =  w_send_out_of_sync;
570                 drbd_queue_work(&mdev->tconn->sender_work, &req->w);
571                 break;
572
573         case READ_RETRY_REMOTE_CANCELED:
574         case SEND_CANCELED:
575         case SEND_FAILED:
576                 /* real cleanup will be done from tl_clear.  just update flags
577                  * so it is no longer marked as on the worker queue */
578                 mod_rq_state(req, m, RQ_NET_QUEUED, 0);
579                 break;
580
581         case HANDED_OVER_TO_NETWORK:
582                 /* assert something? */
583                 if (bio_data_dir(req->master_bio) == WRITE &&
584                     !(req->rq_state & (RQ_EXP_RECEIVE_ACK | RQ_EXP_WRITE_ACK))) {
585                         /* this is what is dangerous about protocol A:
586                          * pretend it was successfully written on the peer. */
587                         if (req->rq_state & RQ_NET_PENDING)
588                                 mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK);
589                         /* else: neg-ack was faster... */
590                         /* it is still not yet RQ_NET_DONE until the
591                          * corresponding epoch barrier got acked as well,
592                          * so we know what to dirty on connection loss */
593                 }
594                 mod_rq_state(req, m, RQ_NET_QUEUED, RQ_NET_SENT);
595                 break;
596
597         case OOS_HANDED_TO_NETWORK:
598                 /* Was not set PENDING, no longer QUEUED, so is now DONE
599                  * as far as this connection is concerned. */
600                 mod_rq_state(req, m, RQ_NET_QUEUED, RQ_NET_DONE);
601                 break;
602
603         case CONNECTION_LOST_WHILE_PENDING:
604                 /* transfer log cleanup after connection loss */
605                 mod_rq_state(req, m,
606                                 RQ_NET_OK|RQ_NET_PENDING|RQ_COMPLETION_SUSP,
607                                 RQ_NET_DONE);
608                 break;
609
610         case DISCARD_WRITE:
611                 /* for discarded conflicting writes of multiple primaries,
612                  * there is no need to keep anything in the tl, potential
613                  * node crashes are covered by the activity log.
614                  *
615                  * If this request had been marked as RQ_POSTPONED before,
616                  * it will actually not be discarded, but "restarted",
617                  * resubmitted from the retry worker context. */
618                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
619                 D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK);
620                 mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_DONE|RQ_NET_OK);
621                 break;
622
623         case WRITE_ACKED_BY_PEER_AND_SIS:
624                 req->rq_state |= RQ_NET_SIS;
625         case WRITE_ACKED_BY_PEER:
626                 D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK);
627                 /* protocol C; successfully written on peer.
628                  * Nothing more to do here.
629                  * We want to keep the tl in place for all protocols, to cater
630                  * for volatile write-back caches on lower level devices. */
631
632                 goto ack_common;
633         case RECV_ACKED_BY_PEER:
634                 D_ASSERT(req->rq_state & RQ_EXP_RECEIVE_ACK);
635                 /* protocol B; pretends to be successfully written on peer.
636                  * see also notes above in HANDED_OVER_TO_NETWORK about
637                  * protocol != C */
638         ack_common:
639                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
640                 mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK);
641                 break;
642
643         case POSTPONE_WRITE:
644                 D_ASSERT(req->rq_state & RQ_EXP_WRITE_ACK);
645                 /* If this node has already detected the write conflict, the
646                  * worker will be waiting on misc_wait.  Wake it up once this
647                  * request has completed locally.
648                  */
649                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
650                 req->rq_state |= RQ_POSTPONED;
651                 if (req->i.waiting)
652                         wake_up(&mdev->misc_wait);
653                 /* Do not clear RQ_NET_PENDING. This request will make further
654                  * progress via restart_conflicting_writes() or
655                  * fail_postponed_requests(). Hopefully. */
656                 break;
657
658         case NEG_ACKED:
659                 mod_rq_state(req, m, RQ_NET_OK|RQ_NET_PENDING, RQ_NET_DONE);
660                 break;
661
662         case FAIL_FROZEN_DISK_IO:
663                 if (!(req->rq_state & RQ_LOCAL_COMPLETED))
664                         break;
665                 mod_rq_state(req, m, RQ_COMPLETION_SUSP, 0);
666                 break;
667
668         case RESTART_FROZEN_DISK_IO:
669                 if (!(req->rq_state & RQ_LOCAL_COMPLETED))
670                         break;
671
672                 mod_rq_state(req, m,
673                                 RQ_COMPLETION_SUSP|RQ_LOCAL_COMPLETED,
674                                 RQ_LOCAL_PENDING);
675
676                 rv = MR_READ;
677                 if (bio_data_dir(req->master_bio) == WRITE)
678                         rv = MR_WRITE;
679
680                 get_ldev(mdev); /* always succeeds in this call path */
681                 req->w.cb = w_restart_disk_io;
682                 drbd_queue_work(&mdev->tconn->sender_work, &req->w);
683                 break;
684
685         case RESEND:
686                 /* If RQ_NET_OK is already set, we got a P_WRITE_ACK or P_RECV_ACK
687                    before the connection loss (B&C only); only P_BARRIER_ACK
688                    (or the local completion?) was missing when we suspended.
689                    Throwing them out of the TL here by pretending we got a BARRIER_ACK.
690                    During connection handshake, we ensure that the peer was not rebooted. */
691                 if (!(req->rq_state & RQ_NET_OK)) {
692                         /* FIXME could this possibly be a req->w.cb == w_send_out_of_sync?
693                          * in that case we must not set RQ_NET_PENDING. */
694
695                         mod_rq_state(req, m, RQ_COMPLETION_SUSP, RQ_NET_QUEUED|RQ_NET_PENDING);
696                         if (req->w.cb) {
697                                 drbd_queue_work(&mdev->tconn->sender_work, &req->w);
698                                 rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ;
699                         } /* else: FIXME can this happen? */
700                         break;
701                 }
702                 /* else, fall through to BARRIER_ACKED */
703
704         case BARRIER_ACKED:
705                 /* barrier ack for READ requests does not make sense */
706                 if (!(req->rq_state & RQ_WRITE))
707                         break;
708
709                 if (req->rq_state & RQ_NET_PENDING) {
710                         /* barrier came in before all requests were acked.
711                          * this is bad, because if the connection is lost now,
712                          * we won't be able to clean them up... */
713                         dev_err(DEV, "FIXME (BARRIER_ACKED but pending)\n");
714                 }
715                 /* Allowed to complete requests, even while suspended.
716                  * As this is called for all requests within a matching epoch,
717                  * we need to filter, and only set RQ_NET_DONE for those that
718                  * have actually been on the wire. */
719                 mod_rq_state(req, m, RQ_COMPLETION_SUSP,
720                                 (req->rq_state & RQ_NET_MASK) ? RQ_NET_DONE : 0);
721                 break;
722
723         case DATA_RECEIVED:
724                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
725                 mod_rq_state(req, m, RQ_NET_PENDING, RQ_NET_OK|RQ_NET_DONE);
726                 break;
727         };
728
729         return rv;
730 }
731
732 /* we may do a local read if:
733  * - we are consistent (of course),
734  * - or we are generally inconsistent,
735  *   BUT we are still/already IN SYNC for this area.
736  *   since size may be bigger than BM_BLOCK_SIZE,
737  *   we may need to check several bits.
738  */
739 static bool drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size)
740 {
741         unsigned long sbnr, ebnr;
742         sector_t esector, nr_sectors;
743
744         if (mdev->state.disk == D_UP_TO_DATE)
745                 return true;
746         if (mdev->state.disk != D_INCONSISTENT)
747                 return false;
748         esector = sector + (size >> 9) - 1;
749         nr_sectors = drbd_get_capacity(mdev->this_bdev);
750         D_ASSERT(sector  < nr_sectors);
751         D_ASSERT(esector < nr_sectors);
752
753         sbnr = BM_SECT_TO_BIT(sector);
754         ebnr = BM_SECT_TO_BIT(esector);
755
756         return drbd_bm_count_bits(mdev, sbnr, ebnr) == 0;
757 }
758
759 static bool remote_due_to_read_balancing(struct drbd_conf *mdev, sector_t sector,
760                 enum drbd_read_balancing rbm)
761 {
762         struct backing_dev_info *bdi;
763         int stripe_shift;
764
765         switch (rbm) {
766         case RB_CONGESTED_REMOTE:
767                 bdi = &mdev->ldev->backing_bdev->bd_disk->queue->backing_dev_info;
768                 return bdi_read_congested(bdi);
769         case RB_LEAST_PENDING:
770                 return atomic_read(&mdev->local_cnt) >
771                         atomic_read(&mdev->ap_pending_cnt) + atomic_read(&mdev->rs_pending_cnt);
772         case RB_32K_STRIPING:  /* stripe_shift = 15 */
773         case RB_64K_STRIPING:
774         case RB_128K_STRIPING:
775         case RB_256K_STRIPING:
776         case RB_512K_STRIPING:
777         case RB_1M_STRIPING:   /* stripe_shift = 20 */
778                 stripe_shift = (rbm - RB_32K_STRIPING + 15);
779                 return (sector >> (stripe_shift - 9)) & 1;
780         case RB_ROUND_ROBIN:
781                 return test_and_change_bit(READ_BALANCE_RR, &mdev->flags);
782         case RB_PREFER_REMOTE:
783                 return true;
784         case RB_PREFER_LOCAL:
785         default:
786                 return false;
787         }
788 }
789
790 /*
791  * complete_conflicting_writes  -  wait for any conflicting write requests
792  *
793  * The write_requests tree contains all active write requests which we
794  * currently know about.  Wait for any requests to complete which conflict with
795  * the new one.
796  *
797  * Only way out: remove the conflicting intervals from the tree.
798  */
799 static void complete_conflicting_writes(struct drbd_request *req)
800 {
801         DEFINE_WAIT(wait);
802         struct drbd_conf *mdev = req->w.mdev;
803         struct drbd_interval *i;
804         sector_t sector = req->i.sector;
805         int size = req->i.size;
806
807         i = drbd_find_overlap(&mdev->write_requests, sector, size);
808         if (!i)
809                 return;
810
811         for (;;) {
812                 prepare_to_wait(&mdev->misc_wait, &wait, TASK_UNINTERRUPTIBLE);
813                 i = drbd_find_overlap(&mdev->write_requests, sector, size);
814                 if (!i)
815                         break;
816                 /* Indicate to wake up device->misc_wait on progress.  */
817                 i->waiting = true;
818                 spin_unlock_irq(&mdev->tconn->req_lock);
819                 schedule();
820                 spin_lock_irq(&mdev->tconn->req_lock);
821         }
822         finish_wait(&mdev->misc_wait, &wait);
823 }
824
825 /* called within req_lock and rcu_read_lock() */
826 static void maybe_pull_ahead(struct drbd_conf *mdev)
827 {
828         struct drbd_tconn *tconn = mdev->tconn;
829         struct net_conf *nc;
830         bool congested = false;
831         enum drbd_on_congestion on_congestion;
832
833         nc = rcu_dereference(tconn->net_conf);
834         on_congestion = nc ? nc->on_congestion : OC_BLOCK;
835         if (on_congestion == OC_BLOCK ||
836             tconn->agreed_pro_version < 96)
837                 return;
838
839         /* If I don't even have good local storage, we can not reasonably try
840          * to pull ahead of the peer. We also need the local reference to make
841          * sure mdev->act_log is there.
842          */
843         if (!get_ldev_if_state(mdev, D_UP_TO_DATE))
844                 return;
845
846         if (nc->cong_fill &&
847             atomic_read(&mdev->ap_in_flight) >= nc->cong_fill) {
848                 dev_info(DEV, "Congestion-fill threshold reached\n");
849                 congested = true;
850         }
851
852         if (mdev->act_log->used >= nc->cong_extents) {
853                 dev_info(DEV, "Congestion-extents threshold reached\n");
854                 congested = true;
855         }
856
857         if (congested) {
858                 if (mdev->tconn->current_tle_writes)
859                         /* start a new epoch for non-mirrored writes */
860                         start_new_tl_epoch(mdev->tconn);
861
862                 if (on_congestion == OC_PULL_AHEAD)
863                         _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL);
864                 else  /*nc->on_congestion == OC_DISCONNECT */
865                         _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL);
866         }
867         put_ldev(mdev);
868 }
869
870 /* If this returns false, and req->private_bio is still set,
871  * this should be submitted locally.
872  *
873  * If it returns false, but req->private_bio is not set,
874  * we do not have access to good data :(
875  *
876  * Otherwise, this destroys req->private_bio, if any,
877  * and returns true.
878  */
879 static bool do_remote_read(struct drbd_request *req)
880 {
881         struct drbd_conf *mdev = req->w.mdev;
882         enum drbd_read_balancing rbm;
883
884         if (req->private_bio) {
885                 if (!drbd_may_do_local_read(mdev,
886                                         req->i.sector, req->i.size)) {
887                         bio_put(req->private_bio);
888                         req->private_bio = NULL;
889                         put_ldev(mdev);
890                 }
891         }
892
893         if (mdev->state.pdsk != D_UP_TO_DATE)
894                 return false;
895
896         if (req->private_bio == NULL)
897                 return true;
898
899         /* TODO: improve read balancing decisions, take into account drbd
900          * protocol, pending requests etc. */
901
902         rcu_read_lock();
903         rbm = rcu_dereference(mdev->ldev->disk_conf)->read_balancing;
904         rcu_read_unlock();
905
906         if (rbm == RB_PREFER_LOCAL && req->private_bio)
907                 return false; /* submit locally */
908
909         if (remote_due_to_read_balancing(mdev, req->i.sector, rbm)) {
910                 if (req->private_bio) {
911                         bio_put(req->private_bio);
912                         req->private_bio = NULL;
913                         put_ldev(mdev);
914                 }
915                 return true;
916         }
917
918         return false;
919 }
920
921 /* returns number of connections (== 1, for drbd 8.4)
922  * expected to actually write this data,
923  * which does NOT include those that we are L_AHEAD for. */
924 static int drbd_process_write_request(struct drbd_request *req)
925 {
926         struct drbd_conf *mdev = req->w.mdev;
927         int remote, send_oos;
928
929         rcu_read_lock();
930         remote = drbd_should_do_remote(mdev->state);
931         if (remote) {
932                 maybe_pull_ahead(mdev);
933                 remote = drbd_should_do_remote(mdev->state);
934         }
935         send_oos = drbd_should_send_out_of_sync(mdev->state);
936         rcu_read_unlock();
937
938         /* Need to replicate writes.  Unless it is an empty flush,
939          * which is better mapped to a DRBD P_BARRIER packet,
940          * also for drbd wire protocol compatibility reasons.
941          * If this was a flush, just start a new epoch.
942          * Unless the current epoch was empty anyways, or we are not currently
943          * replicating, in which case there is no point. */
944         if (unlikely(req->i.size == 0)) {
945                 /* The only size==0 bios we expect are empty flushes. */
946                 D_ASSERT(req->master_bio->bi_rw & REQ_FLUSH);
947                 if (remote && mdev->tconn->current_tle_writes)
948                         start_new_tl_epoch(mdev->tconn);
949                 return 0;
950         }
951
952         if (!remote && !send_oos)
953                 return 0;
954
955         D_ASSERT(!(remote && send_oos));
956
957         if (remote) {
958                 _req_mod(req, TO_BE_SENT);
959                 _req_mod(req, QUEUE_FOR_NET_WRITE);
960         } else if (drbd_set_out_of_sync(mdev, req->i.sector, req->i.size))
961                 _req_mod(req, QUEUE_FOR_SEND_OOS);
962
963         return remote;
964 }
965
966 static void
967 drbd_submit_req_private_bio(struct drbd_request *req)
968 {
969         struct drbd_conf *mdev = req->w.mdev;
970         struct bio *bio = req->private_bio;
971         const int rw = bio_rw(bio);
972
973         bio->bi_bdev = mdev->ldev->backing_bdev;
974
975         /* State may have changed since we grabbed our reference on the
976          * ->ldev member. Double check, and short-circuit to endio.
977          * In case the last activity log transaction failed to get on
978          * stable storage, and this is a WRITE, we may not even submit
979          * this bio. */
980         if (get_ldev(mdev)) {
981                 if (drbd_insert_fault(mdev,
982                                       rw == WRITE ? DRBD_FAULT_DT_WR
983                                     : rw == READ  ? DRBD_FAULT_DT_RD
984                                     :               DRBD_FAULT_DT_RA))
985                         bio_endio(bio, -EIO);
986                 else
987                         generic_make_request(bio);
988                 put_ldev(mdev);
989         } else
990                 bio_endio(bio, -EIO);
991 }
992
993 void __drbd_make_request(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time)
994 {
995         const int rw = bio_rw(bio);
996         struct bio_and_error m = { NULL, };
997         struct drbd_request *req;
998         bool no_remote = false;
999
1000         /* allocate outside of all locks; */
1001         req = drbd_req_new(mdev, bio);
1002         if (!req) {
1003                 dec_ap_bio(mdev);
1004                 /* only pass the error to the upper layers.
1005                  * if user cannot handle io errors, that's not our business. */
1006                 dev_err(DEV, "could not kmalloc() req\n");
1007                 bio_endio(bio, -ENOMEM);
1008                 return;
1009         }
1010         req->start_time = start_time;
1011
1012         if (!get_ldev(mdev)) {
1013                 bio_put(req->private_bio);
1014                 req->private_bio = NULL;
1015         }
1016
1017         /* For WRITES going to the local disk, grab a reference on the target
1018          * extent.  This waits for any resync activity in the corresponding
1019          * resync extent to finish, and, if necessary, pulls in the target
1020          * extent into the activity log, which involves further disk io because
1021          * of transactional on-disk meta data updates.
1022          * Empty flushes don't need to go into the activity log, they can only
1023          * flush data for pending writes which are already in there. */
1024         if (rw == WRITE && req->private_bio && req->i.size
1025         && !test_bit(AL_SUSPENDED, &mdev->flags)) {
1026                 req->rq_state |= RQ_IN_ACT_LOG;
1027                 drbd_al_begin_io(mdev, &req->i);
1028         }
1029
1030         spin_lock_irq(&mdev->tconn->req_lock);
1031         if (rw == WRITE) {
1032                 /* This may temporarily give up the req_lock,
1033                  * but will re-aquire it before it returns here.
1034                  * Needs to be before the check on drbd_suspended() */
1035                 complete_conflicting_writes(req);
1036         }
1037
1038         /* no more giving up req_lock from now on! */
1039
1040         if (drbd_suspended(mdev)) {
1041                 /* push back and retry: */
1042                 req->rq_state |= RQ_POSTPONED;
1043                 if (req->private_bio) {
1044                         bio_put(req->private_bio);
1045                         req->private_bio = NULL;
1046                 }
1047                 goto out;
1048         }
1049
1050         /* Update disk stats */
1051         _drbd_start_io_acct(mdev, req, bio);
1052
1053         /* We fail READ/READA early, if we can not serve it.
1054          * We must do this before req is registered on any lists.
1055          * Otherwise, drbd_req_complete() will queue failed READ for retry. */
1056         if (rw != WRITE) {
1057                 if (!do_remote_read(req) && !req->private_bio)
1058                         goto nodata;
1059         }
1060
1061         /* which transfer log epoch does this belong to? */
1062         req->epoch = atomic_read(&mdev->tconn->current_tle_nr);
1063         if (rw == WRITE)
1064                 mdev->tconn->current_tle_writes++;
1065
1066         /* no point in adding empty flushes to the transfer log,
1067          * they are mapped to drbd barriers already. */
1068         if (likely(req->i.size!=0))
1069                 list_add_tail(&req->tl_requests, &mdev->tconn->transfer_log);
1070
1071         if (rw == WRITE) {
1072                 if (!drbd_process_write_request(req))
1073                         no_remote = true;
1074         } else {
1075                 /* We either have a private_bio, or we can read from remote.
1076                  * Otherwise we had done the goto nodata above. */
1077                 if (req->private_bio == NULL) {
1078                         _req_mod(req, TO_BE_SENT);
1079                         _req_mod(req, QUEUE_FOR_NET_READ);
1080                 } else
1081                         no_remote = true;
1082         }
1083
1084         if (req->private_bio) {
1085                 /* needs to be marked within the same spinlock */
1086                 _req_mod(req, TO_BE_SUBMITTED);
1087                 /* but we need to give up the spinlock to submit */
1088                 spin_unlock_irq(&mdev->tconn->req_lock);
1089                 drbd_submit_req_private_bio(req);
1090                 spin_lock_irq(&mdev->tconn->req_lock);
1091         } else if (no_remote) {
1092 nodata:
1093                 if (__ratelimit(&drbd_ratelimit_state))
1094                         dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
1095                 /* A write may have been queued for send_oos, however.
1096                  * So we can not simply free it, we must go through drbd_req_put_completion_ref() */
1097         }
1098
1099 out:
1100         if (drbd_req_put_completion_ref(req, &m, 1))
1101                 kref_put(&req->kref, drbd_req_destroy);
1102         spin_unlock_irq(&mdev->tconn->req_lock);
1103
1104         if (m.bio)
1105                 complete_master_bio(mdev, &m);
1106         return;
1107 }
1108
1109 int drbd_make_request(struct request_queue *q, struct bio *bio)
1110 {
1111         struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
1112         unsigned long start_time;
1113
1114         start_time = jiffies;
1115
1116         /*
1117          * what we "blindly" assume:
1118          */
1119         D_ASSERT(IS_ALIGNED(bio->bi_size, 512));
1120
1121         inc_ap_bio(mdev);
1122         __drbd_make_request(mdev, bio, start_time);
1123
1124         return 0;
1125 }
1126
1127 /* This is called by bio_add_page().
1128  *
1129  * q->max_hw_sectors and other global limits are already enforced there.
1130  *
1131  * We need to call down to our lower level device,
1132  * in case it has special restrictions.
1133  *
1134  * We also may need to enforce configured max-bio-bvecs limits.
1135  *
1136  * As long as the BIO is empty we have to allow at least one bvec,
1137  * regardless of size and offset, so no need to ask lower levels.
1138  */
1139 int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec)
1140 {
1141         struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
1142         unsigned int bio_size = bvm->bi_size;
1143         int limit = DRBD_MAX_BIO_SIZE;
1144         int backing_limit;
1145
1146         if (bio_size && get_ldev(mdev)) {
1147                 struct request_queue * const b =
1148                         mdev->ldev->backing_bdev->bd_disk->queue;
1149                 if (b->merge_bvec_fn) {
1150                         backing_limit = b->merge_bvec_fn(b, bvm, bvec);
1151                         limit = min(limit, backing_limit);
1152                 }
1153                 put_ldev(mdev);
1154         }
1155         return limit;
1156 }
1157
1158 struct drbd_request *find_oldest_request(struct drbd_tconn *tconn)
1159 {
1160         /* Walk the transfer log,
1161          * and find the oldest not yet completed request */
1162         struct drbd_request *r;
1163         list_for_each_entry(r, &tconn->transfer_log, tl_requests) {
1164                 if (atomic_read(&r->completion_ref))
1165                         return r;
1166         }
1167         return NULL;
1168 }
1169
1170 void request_timer_fn(unsigned long data)
1171 {
1172         struct drbd_conf *mdev = (struct drbd_conf *) data;
1173         struct drbd_tconn *tconn = mdev->tconn;
1174         struct drbd_request *req; /* oldest request */
1175         struct net_conf *nc;
1176         unsigned long ent = 0, dt = 0, et, nt; /* effective timeout = ko_count * timeout */
1177         unsigned long now;
1178
1179         rcu_read_lock();
1180         nc = rcu_dereference(tconn->net_conf);
1181         if (nc && mdev->state.conn >= C_WF_REPORT_PARAMS)
1182                 ent = nc->timeout * HZ/10 * nc->ko_count;
1183
1184         if (get_ldev(mdev)) { /* implicit state.disk >= D_INCONSISTENT */
1185                 dt = rcu_dereference(mdev->ldev->disk_conf)->disk_timeout * HZ / 10;
1186                 put_ldev(mdev);
1187         }
1188         rcu_read_unlock();
1189
1190         et = min_not_zero(dt, ent);
1191
1192         if (!et)
1193                 return; /* Recurring timer stopped */
1194
1195         now = jiffies;
1196
1197         spin_lock_irq(&tconn->req_lock);
1198         req = find_oldest_request(tconn);
1199         if (!req) {
1200                 spin_unlock_irq(&tconn->req_lock);
1201                 mod_timer(&mdev->request_timer, now + et);
1202                 return;
1203         }
1204
1205         /* The request is considered timed out, if
1206          * - we have some effective timeout from the configuration,
1207          *   with above state restrictions applied,
1208          * - the oldest request is waiting for a response from the network
1209          *   resp. the local disk,
1210          * - the oldest request is in fact older than the effective timeout,
1211          * - the connection was established (resp. disk was attached)
1212          *   for longer than the timeout already.
1213          * Note that for 32bit jiffies and very stable connections/disks,
1214          * we may have a wrap around, which is catched by
1215          *   !time_in_range(now, last_..._jif, last_..._jif + timeout).
1216          *
1217          * Side effect: once per 32bit wrap-around interval, which means every
1218          * ~198 days with 250 HZ, we have a window where the timeout would need
1219          * to expire twice (worst case) to become effective. Good enough.
1220          */
1221         if (ent && req->rq_state & RQ_NET_PENDING &&
1222                  time_after(now, req->start_time + ent) &&
1223                 !time_in_range(now, tconn->last_reconnect_jif, tconn->last_reconnect_jif + ent)) {
1224                 dev_warn(DEV, "Remote failed to finish a request within ko-count * timeout\n");
1225                 _drbd_set_state(_NS(mdev, conn, C_TIMEOUT), CS_VERBOSE | CS_HARD, NULL);
1226         }
1227         if (dt && req->rq_state & RQ_LOCAL_PENDING && req->w.mdev == mdev &&
1228                  time_after(now, req->start_time + dt) &&
1229                 !time_in_range(now, mdev->last_reattach_jif, mdev->last_reattach_jif + dt)) {
1230                 dev_warn(DEV, "Local backing device failed to meet the disk-timeout\n");
1231                 __drbd_chk_io_error(mdev, DRBD_FORCE_DETACH);
1232         }
1233         nt = (time_after(now, req->start_time + et) ? now : req->start_time) + et;
1234         spin_unlock_irq(&tconn->req_lock);
1235         mod_timer(&mdev->request_timer, nt);
1236 }