drbd: merge_bvec_fn: properly remap bvm->bi_bdev
[pandora-kernel.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 /* Update disk stats at start of I/O request */
35 static void _drbd_start_io_acct(struct drbd_conf *mdev, struct drbd_request *req, struct bio *bio)
36 {
37         const int rw = bio_data_dir(bio);
38         int cpu;
39         cpu = part_stat_lock();
40         part_round_stats(cpu, &mdev->vdisk->part0);
41         part_stat_inc(cpu, &mdev->vdisk->part0, ios[rw]);
42         part_stat_add(cpu, &mdev->vdisk->part0, sectors[rw], bio_sectors(bio));
43         part_inc_in_flight(&mdev->vdisk->part0, rw);
44         part_stat_unlock();
45 }
46
47 /* Update disk stats when completing request upwards */
48 static void _drbd_end_io_acct(struct drbd_conf *mdev, struct drbd_request *req)
49 {
50         int rw = bio_data_dir(req->master_bio);
51         unsigned long duration = jiffies - req->start_time;
52         int cpu;
53         cpu = part_stat_lock();
54         part_stat_add(cpu, &mdev->vdisk->part0, ticks[rw], duration);
55         part_round_stats(cpu, &mdev->vdisk->part0);
56         part_dec_in_flight(&mdev->vdisk->part0, rw);
57         part_stat_unlock();
58 }
59
60 static void _req_is_done(struct drbd_conf *mdev, struct drbd_request *req, const int rw)
61 {
62         const unsigned long s = req->rq_state;
63
64         /* remove it from the transfer log.
65          * well, only if it had been there in the first
66          * place... if it had not (local only or conflicting
67          * and never sent), it should still be "empty" as
68          * initialized in drbd_req_new(), so we can list_del() it
69          * here unconditionally */
70         list_del(&req->tl_requests);
71
72         /* if it was a write, we may have to set the corresponding
73          * bit(s) out-of-sync first. If it had a local part, we need to
74          * release the reference to the activity log. */
75         if (rw == WRITE) {
76                 /* Set out-of-sync unless both OK flags are set
77                  * (local only or remote failed).
78                  * Other places where we set out-of-sync:
79                  * READ with local io-error */
80                 if (!(s & RQ_NET_OK) || !(s & RQ_LOCAL_OK))
81                         drbd_set_out_of_sync(mdev, req->sector, req->size);
82
83                 if ((s & RQ_NET_OK) && (s & RQ_LOCAL_OK) && (s & RQ_NET_SIS))
84                         drbd_set_in_sync(mdev, req->sector, req->size);
85
86                 /* one might be tempted to move the drbd_al_complete_io
87                  * to the local io completion callback drbd_endio_pri.
88                  * but, if this was a mirror write, we may only
89                  * drbd_al_complete_io after this is RQ_NET_DONE,
90                  * otherwise the extent could be dropped from the al
91                  * before it has actually been written on the peer.
92                  * if we crash before our peer knows about the request,
93                  * but after the extent has been dropped from the al,
94                  * we would forget to resync the corresponding extent.
95                  */
96                 if (s & RQ_LOCAL_MASK) {
97                         if (get_ldev_if_state(mdev, D_FAILED)) {
98                                 if (s & RQ_IN_ACT_LOG)
99                                         drbd_al_complete_io(mdev, req->sector);
100                                 put_ldev(mdev);
101                         } else if (__ratelimit(&drbd_ratelimit_state)) {
102                                 dev_warn(DEV, "Should have called drbd_al_complete_io(, %llu), "
103                                      "but my Disk seems to have failed :(\n",
104                                      (unsigned long long) req->sector);
105                         }
106                 }
107         }
108
109         drbd_req_free(req);
110 }
111
112 static void queue_barrier(struct drbd_conf *mdev)
113 {
114         struct drbd_tl_epoch *b;
115
116         /* We are within the req_lock. Once we queued the barrier for sending,
117          * we set the CREATE_BARRIER bit. It is cleared as soon as a new
118          * barrier/epoch object is added. This is the only place this bit is
119          * set. It indicates that the barrier for this epoch is already queued,
120          * and no new epoch has been created yet. */
121         if (test_bit(CREATE_BARRIER, &mdev->flags))
122                 return;
123
124         b = mdev->newest_tle;
125         b->w.cb = w_send_barrier;
126         /* inc_ap_pending done here, so we won't
127          * get imbalanced on connection loss.
128          * dec_ap_pending will be done in got_BarrierAck
129          * or (on connection loss) in tl_clear.  */
130         inc_ap_pending(mdev);
131         drbd_queue_work(&mdev->data.work, &b->w);
132         set_bit(CREATE_BARRIER, &mdev->flags);
133 }
134
135 static void _about_to_complete_local_write(struct drbd_conf *mdev,
136         struct drbd_request *req)
137 {
138         const unsigned long s = req->rq_state;
139         struct drbd_request *i;
140         struct drbd_epoch_entry *e;
141         struct hlist_node *n;
142         struct hlist_head *slot;
143
144         /* Before we can signal completion to the upper layers,
145          * we may need to close the current epoch.
146          * We can skip this, if this request has not even been sent, because we
147          * did not have a fully established connection yet/anymore, during
148          * bitmap exchange, or while we are C_AHEAD due to congestion policy.
149          */
150         if (mdev->state.conn >= C_CONNECTED &&
151             (s & RQ_NET_SENT) != 0 &&
152             req->epoch == mdev->newest_tle->br_number)
153                 queue_barrier(mdev);
154
155         /* we need to do the conflict detection stuff,
156          * if we have the ee_hash (two_primaries) and
157          * this has been on the network */
158         if ((s & RQ_NET_DONE) && mdev->ee_hash != NULL) {
159                 const sector_t sector = req->sector;
160                 const int size = req->size;
161
162                 /* ASSERT:
163                  * there must be no conflicting requests, since
164                  * they must have been failed on the spot */
165 #define OVERLAPS overlaps(sector, size, i->sector, i->size)
166                 slot = tl_hash_slot(mdev, sector);
167                 hlist_for_each_entry(i, n, slot, collision) {
168                         if (OVERLAPS) {
169                                 dev_alert(DEV, "LOGIC BUG: completed: %p %llus +%u; "
170                                       "other: %p %llus +%u\n",
171                                       req, (unsigned long long)sector, size,
172                                       i, (unsigned long long)i->sector, i->size);
173                         }
174                 }
175
176                 /* maybe "wake" those conflicting epoch entries
177                  * that wait for this request to finish.
178                  *
179                  * currently, there can be only _one_ such ee
180                  * (well, or some more, which would be pending
181                  * P_DISCARD_ACK not yet sent by the asender...),
182                  * since we block the receiver thread upon the
183                  * first conflict detection, which will wait on
184                  * misc_wait.  maybe we want to assert that?
185                  *
186                  * anyways, if we found one,
187                  * we just have to do a wake_up.  */
188 #undef OVERLAPS
189 #define OVERLAPS overlaps(sector, size, e->sector, e->size)
190                 slot = ee_hash_slot(mdev, req->sector);
191                 hlist_for_each_entry(e, n, slot, collision) {
192                         if (OVERLAPS) {
193                                 wake_up(&mdev->misc_wait);
194                                 break;
195                         }
196                 }
197         }
198 #undef OVERLAPS
199 }
200
201 void complete_master_bio(struct drbd_conf *mdev,
202                 struct bio_and_error *m)
203 {
204         bio_endio(m->bio, m->error);
205         dec_ap_bio(mdev);
206 }
207
208 /* Helper for __req_mod().
209  * Set m->bio to the master bio, if it is fit to be completed,
210  * or leave it alone (it is initialized to NULL in __req_mod),
211  * if it has already been completed, or cannot be completed yet.
212  * If m->bio is set, the error status to be returned is placed in m->error.
213  */
214 void _req_may_be_done(struct drbd_request *req, struct bio_and_error *m)
215 {
216         const unsigned long s = req->rq_state;
217         struct drbd_conf *mdev = req->mdev;
218         /* only WRITES may end up here without a master bio (on barrier ack) */
219         int rw = req->master_bio ? bio_data_dir(req->master_bio) : WRITE;
220
221         /* we must not complete the master bio, while it is
222          *      still being processed by _drbd_send_zc_bio (drbd_send_dblock)
223          *      not yet acknowledged by the peer
224          *      not yet completed by the local io subsystem
225          * these flags may get cleared in any order by
226          *      the worker,
227          *      the receiver,
228          *      the bio_endio completion callbacks.
229          */
230         if (s & RQ_NET_QUEUED)
231                 return;
232         if (s & RQ_NET_PENDING)
233                 return;
234         if (s & RQ_LOCAL_PENDING)
235                 return;
236
237         if (req->master_bio) {
238                 /* this is data_received (remote read)
239                  * or protocol C P_WRITE_ACK
240                  * or protocol B P_RECV_ACK
241                  * or protocol A "handed_over_to_network" (SendAck)
242                  * or canceled or failed,
243                  * or killed from the transfer log due to connection loss.
244                  */
245
246                 /*
247                  * figure out whether to report success or failure.
248                  *
249                  * report success when at least one of the operations succeeded.
250                  * or, to put the other way,
251                  * only report failure, when both operations failed.
252                  *
253                  * what to do about the failures is handled elsewhere.
254                  * what we need to do here is just: complete the master_bio.
255                  *
256                  * local completion error, if any, has been stored as ERR_PTR
257                  * in private_bio within drbd_endio_pri.
258                  */
259                 int ok = (s & RQ_LOCAL_OK) || (s & RQ_NET_OK);
260                 int error = PTR_ERR(req->private_bio);
261
262                 /* remove the request from the conflict detection
263                  * respective block_id verification hash */
264                 if (!hlist_unhashed(&req->collision))
265                         hlist_del(&req->collision);
266                 else
267                         D_ASSERT((s & (RQ_NET_MASK & ~RQ_NET_DONE)) == 0);
268
269                 /* for writes we need to do some extra housekeeping */
270                 if (rw == WRITE)
271                         _about_to_complete_local_write(mdev, req);
272
273                 /* Update disk stats */
274                 _drbd_end_io_acct(mdev, req);
275
276                 m->error = ok ? 0 : (error ?: -EIO);
277                 m->bio = req->master_bio;
278                 req->master_bio = NULL;
279         }
280
281         if ((s & RQ_NET_MASK) == 0 || (s & RQ_NET_DONE)) {
282                 /* this is disconnected (local only) operation,
283                  * or protocol C P_WRITE_ACK,
284                  * or protocol A or B P_BARRIER_ACK,
285                  * or killed from the transfer log due to connection loss. */
286                 _req_is_done(mdev, req, rw);
287         }
288         /* else: network part and not DONE yet. that is
289          * protocol A or B, barrier ack still pending... */
290 }
291
292 static void _req_may_be_done_not_susp(struct drbd_request *req, struct bio_and_error *m)
293 {
294         struct drbd_conf *mdev = req->mdev;
295
296         if (!is_susp(mdev->state))
297                 _req_may_be_done(req, m);
298 }
299
300 /*
301  * checks whether there was an overlapping request
302  * or ee already registered.
303  *
304  * if so, return 1, in which case this request is completed on the spot,
305  * without ever being submitted or send.
306  *
307  * return 0 if it is ok to submit this request.
308  *
309  * NOTE:
310  * paranoia: assume something above us is broken, and issues different write
311  * requests for the same block simultaneously...
312  *
313  * To ensure these won't be reordered differently on both nodes, resulting in
314  * diverging data sets, we discard the later one(s). Not that this is supposed
315  * to happen, but this is the rationale why we also have to check for
316  * conflicting requests with local origin, and why we have to do so regardless
317  * of whether we allowed multiple primaries.
318  *
319  * BTW, in case we only have one primary, the ee_hash is empty anyways, and the
320  * second hlist_for_each_entry becomes a noop. This is even simpler than to
321  * grab a reference on the net_conf, and check for the two_primaries flag...
322  */
323 static int _req_conflicts(struct drbd_request *req)
324 {
325         struct drbd_conf *mdev = req->mdev;
326         const sector_t sector = req->sector;
327         const int size = req->size;
328         struct drbd_request *i;
329         struct drbd_epoch_entry *e;
330         struct hlist_node *n;
331         struct hlist_head *slot;
332
333         D_ASSERT(hlist_unhashed(&req->collision));
334
335         if (!get_net_conf(mdev))
336                 return 0;
337
338         /* BUG_ON */
339         ERR_IF (mdev->tl_hash_s == 0)
340                 goto out_no_conflict;
341         BUG_ON(mdev->tl_hash == NULL);
342
343 #define OVERLAPS overlaps(i->sector, i->size, sector, size)
344         slot = tl_hash_slot(mdev, sector);
345         hlist_for_each_entry(i, n, slot, collision) {
346                 if (OVERLAPS) {
347                         dev_alert(DEV, "%s[%u] Concurrent local write detected! "
348                               "[DISCARD L] new: %llus +%u; "
349                               "pending: %llus +%u\n",
350                               current->comm, current->pid,
351                               (unsigned long long)sector, size,
352                               (unsigned long long)i->sector, i->size);
353                         goto out_conflict;
354                 }
355         }
356
357         if (mdev->ee_hash_s) {
358                 /* now, check for overlapping requests with remote origin */
359                 BUG_ON(mdev->ee_hash == NULL);
360 #undef OVERLAPS
361 #define OVERLAPS overlaps(e->sector, e->size, sector, size)
362                 slot = ee_hash_slot(mdev, sector);
363                 hlist_for_each_entry(e, n, slot, collision) {
364                         if (OVERLAPS) {
365                                 dev_alert(DEV, "%s[%u] Concurrent remote write detected!"
366                                       " [DISCARD L] new: %llus +%u; "
367                                       "pending: %llus +%u\n",
368                                       current->comm, current->pid,
369                                       (unsigned long long)sector, size,
370                                       (unsigned long long)e->sector, e->size);
371                                 goto out_conflict;
372                         }
373                 }
374         }
375 #undef OVERLAPS
376
377 out_no_conflict:
378         /* this is like it should be, and what we expected.
379          * our users do behave after all... */
380         put_net_conf(mdev);
381         return 0;
382
383 out_conflict:
384         put_net_conf(mdev);
385         return 1;
386 }
387
388 /* obviously this could be coded as many single functions
389  * instead of one huge switch,
390  * or by putting the code directly in the respective locations
391  * (as it has been before).
392  *
393  * but having it this way
394  *  enforces that it is all in this one place, where it is easier to audit,
395  *  it makes it obvious that whatever "event" "happens" to a request should
396  *  happen "atomically" within the req_lock,
397  *  and it enforces that we have to think in a very structured manner
398  *  about the "events" that may happen to a request during its life time ...
399  */
400 int __req_mod(struct drbd_request *req, enum drbd_req_event what,
401                 struct bio_and_error *m)
402 {
403         struct drbd_conf *mdev = req->mdev;
404         int rv = 0;
405         m->bio = NULL;
406
407         switch (what) {
408         default:
409                 dev_err(DEV, "LOGIC BUG in %s:%u\n", __FILE__ , __LINE__);
410                 break;
411
412         /* does not happen...
413          * initialization done in drbd_req_new
414         case created:
415                 break;
416                 */
417
418         case to_be_send: /* via network */
419                 /* reached via drbd_make_request_common
420                  * and from w_read_retry_remote */
421                 D_ASSERT(!(req->rq_state & RQ_NET_MASK));
422                 req->rq_state |= RQ_NET_PENDING;
423                 inc_ap_pending(mdev);
424                 break;
425
426         case to_be_submitted: /* locally */
427                 /* reached via drbd_make_request_common */
428                 D_ASSERT(!(req->rq_state & RQ_LOCAL_MASK));
429                 req->rq_state |= RQ_LOCAL_PENDING;
430                 break;
431
432         case completed_ok:
433                 if (bio_data_dir(req->master_bio) == WRITE)
434                         mdev->writ_cnt += req->size>>9;
435                 else
436                         mdev->read_cnt += req->size>>9;
437
438                 req->rq_state |= (RQ_LOCAL_COMPLETED|RQ_LOCAL_OK);
439                 req->rq_state &= ~RQ_LOCAL_PENDING;
440
441                 _req_may_be_done_not_susp(req, m);
442                 put_ldev(mdev);
443                 break;
444
445         case write_completed_with_error:
446                 req->rq_state |= RQ_LOCAL_COMPLETED;
447                 req->rq_state &= ~RQ_LOCAL_PENDING;
448
449                 __drbd_chk_io_error(mdev, false);
450                 _req_may_be_done_not_susp(req, m);
451                 put_ldev(mdev);
452                 break;
453
454         case read_ahead_completed_with_error:
455                 /* it is legal to fail READA */
456                 req->rq_state |= RQ_LOCAL_COMPLETED;
457                 req->rq_state &= ~RQ_LOCAL_PENDING;
458                 _req_may_be_done_not_susp(req, m);
459                 put_ldev(mdev);
460                 break;
461
462         case read_completed_with_error:
463                 drbd_set_out_of_sync(mdev, req->sector, req->size);
464
465                 req->rq_state |= RQ_LOCAL_COMPLETED;
466                 req->rq_state &= ~RQ_LOCAL_PENDING;
467
468                 D_ASSERT(!(req->rq_state & RQ_NET_MASK));
469
470                 __drbd_chk_io_error(mdev, false);
471                 put_ldev(mdev);
472
473                 /* no point in retrying if there is no good remote data,
474                  * or we have no connection. */
475                 if (mdev->state.pdsk != D_UP_TO_DATE) {
476                         _req_may_be_done_not_susp(req, m);
477                         break;
478                 }
479
480                 /* _req_mod(req,to_be_send); oops, recursion... */
481                 req->rq_state |= RQ_NET_PENDING;
482                 inc_ap_pending(mdev);
483                 /* fall through: _req_mod(req,queue_for_net_read); */
484
485         case queue_for_net_read:
486                 /* READ or READA, and
487                  * no local disk,
488                  * or target area marked as invalid,
489                  * or just got an io-error. */
490                 /* from drbd_make_request_common
491                  * or from bio_endio during read io-error recovery */
492
493                 /* so we can verify the handle in the answer packet
494                  * corresponding hlist_del is in _req_may_be_done() */
495                 hlist_add_head(&req->collision, ar_hash_slot(mdev, req->sector));
496
497                 set_bit(UNPLUG_REMOTE, &mdev->flags);
498
499                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
500                 req->rq_state |= RQ_NET_QUEUED;
501                 req->w.cb = (req->rq_state & RQ_LOCAL_MASK)
502                         ? w_read_retry_remote
503                         : w_send_read_req;
504                 drbd_queue_work(&mdev->data.work, &req->w);
505                 break;
506
507         case queue_for_net_write:
508                 /* assert something? */
509                 /* from drbd_make_request_common only */
510
511                 hlist_add_head(&req->collision, tl_hash_slot(mdev, req->sector));
512                 /* corresponding hlist_del is in _req_may_be_done() */
513
514                 /* NOTE
515                  * In case the req ended up on the transfer log before being
516                  * queued on the worker, it could lead to this request being
517                  * missed during cleanup after connection loss.
518                  * So we have to do both operations here,
519                  * within the same lock that protects the transfer log.
520                  *
521                  * _req_add_to_epoch(req); this has to be after the
522                  * _maybe_start_new_epoch(req); which happened in
523                  * drbd_make_request_common, because we now may set the bit
524                  * again ourselves to close the current epoch.
525                  *
526                  * Add req to the (now) current epoch (barrier). */
527
528                 /* otherwise we may lose an unplug, which may cause some remote
529                  * io-scheduler timeout to expire, increasing maximum latency,
530                  * hurting performance. */
531                 set_bit(UNPLUG_REMOTE, &mdev->flags);
532
533                 /* see drbd_make_request_common,
534                  * just after it grabs the req_lock */
535                 D_ASSERT(test_bit(CREATE_BARRIER, &mdev->flags) == 0);
536
537                 req->epoch = mdev->newest_tle->br_number;
538
539                 /* increment size of current epoch */
540                 mdev->newest_tle->n_writes++;
541
542                 /* queue work item to send data */
543                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
544                 req->rq_state |= RQ_NET_QUEUED;
545                 req->w.cb =  w_send_dblock;
546                 drbd_queue_work(&mdev->data.work, &req->w);
547
548                 /* close the epoch, in case it outgrew the limit */
549                 if (mdev->newest_tle->n_writes >= mdev->net_conf->max_epoch_size)
550                         queue_barrier(mdev);
551
552                 break;
553
554         case queue_for_send_oos:
555                 req->rq_state |= RQ_NET_QUEUED;
556                 req->w.cb =  w_send_oos;
557                 drbd_queue_work(&mdev->data.work, &req->w);
558                 break;
559
560         case oos_handed_to_network:
561                 /* actually the same */
562         case send_canceled:
563                 /* treat it the same */
564         case send_failed:
565                 /* real cleanup will be done from tl_clear.  just update flags
566                  * so it is no longer marked as on the worker queue */
567                 req->rq_state &= ~RQ_NET_QUEUED;
568                 /* if we did it right, tl_clear should be scheduled only after
569                  * this, so this should not be necessary! */
570                 _req_may_be_done_not_susp(req, m);
571                 break;
572
573         case handed_over_to_network:
574                 /* assert something? */
575                 if (bio_data_dir(req->master_bio) == WRITE)
576                         atomic_add(req->size>>9, &mdev->ap_in_flight);
577
578                 if (bio_data_dir(req->master_bio) == WRITE &&
579                     mdev->net_conf->wire_protocol == DRBD_PROT_A) {
580                         /* this is what is dangerous about protocol A:
581                          * pretend it was successfully written on the peer. */
582                         if (req->rq_state & RQ_NET_PENDING) {
583                                 dec_ap_pending(mdev);
584                                 req->rq_state &= ~RQ_NET_PENDING;
585                                 req->rq_state |= RQ_NET_OK;
586                         } /* else: neg-ack was faster... */
587                         /* it is still not yet RQ_NET_DONE until the
588                          * corresponding epoch barrier got acked as well,
589                          * so we know what to dirty on connection loss */
590                 }
591                 req->rq_state &= ~RQ_NET_QUEUED;
592                 req->rq_state |= RQ_NET_SENT;
593                 /* because _drbd_send_zc_bio could sleep, and may want to
594                  * dereference the bio even after the "write_acked_by_peer" and
595                  * "completed_ok" events came in, once we return from
596                  * _drbd_send_zc_bio (drbd_send_dblock), we have to check
597                  * whether it is done already, and end it.  */
598                 _req_may_be_done_not_susp(req, m);
599                 break;
600
601         case read_retry_remote_canceled:
602                 req->rq_state &= ~RQ_NET_QUEUED;
603                 /* fall through, in case we raced with drbd_disconnect */
604         case connection_lost_while_pending:
605                 /* transfer log cleanup after connection loss */
606                 /* assert something? */
607                 if (req->rq_state & RQ_NET_PENDING)
608                         dec_ap_pending(mdev);
609                 req->rq_state &= ~(RQ_NET_OK|RQ_NET_PENDING);
610                 req->rq_state |= RQ_NET_DONE;
611                 if (req->rq_state & RQ_NET_SENT && req->rq_state & RQ_WRITE)
612                         atomic_sub(req->size>>9, &mdev->ap_in_flight);
613
614                 /* if it is still queued, we may not complete it here.
615                  * it will be canceled soon. */
616                 if (!(req->rq_state & RQ_NET_QUEUED))
617                         _req_may_be_done(req, m); /* Allowed while state.susp */
618                 break;
619
620         case write_acked_by_peer_and_sis:
621                 req->rq_state |= RQ_NET_SIS;
622         case conflict_discarded_by_peer:
623                 /* for discarded conflicting writes of multiple primaries,
624                  * there is no need to keep anything in the tl, potential
625                  * node crashes are covered by the activity log. */
626                 if (what == conflict_discarded_by_peer)
627                         dev_alert(DEV, "Got DiscardAck packet %llus +%u!"
628                               " DRBD is not a random data generator!\n",
629                               (unsigned long long)req->sector, req->size);
630                 req->rq_state |= RQ_NET_DONE;
631                 /* fall through */
632         case write_acked_by_peer:
633                 /* protocol C; successfully written on peer.
634                  * Nothing to do here.
635                  * We want to keep the tl in place for all protocols, to cater
636                  * for volatile write-back caches on lower level devices.
637                  *
638                  * A barrier request is expected to have forced all prior
639                  * requests onto stable storage, so completion of a barrier
640                  * request could set NET_DONE right here, and not wait for the
641                  * P_BARRIER_ACK, but that is an unnecessary optimization. */
642
643                 /* this makes it effectively the same as for: */
644         case recv_acked_by_peer:
645                 /* protocol B; pretends to be successfully written on peer.
646                  * see also notes above in handed_over_to_network about
647                  * protocol != C */
648                 req->rq_state |= RQ_NET_OK;
649                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
650                 dec_ap_pending(mdev);
651                 atomic_sub(req->size>>9, &mdev->ap_in_flight);
652                 req->rq_state &= ~RQ_NET_PENDING;
653                 _req_may_be_done_not_susp(req, m);
654                 break;
655
656         case neg_acked:
657                 /* assert something? */
658                 if (req->rq_state & RQ_NET_PENDING) {
659                         dec_ap_pending(mdev);
660                         atomic_sub(req->size>>9, &mdev->ap_in_flight);
661                 }
662                 req->rq_state &= ~(RQ_NET_OK|RQ_NET_PENDING);
663
664                 req->rq_state |= RQ_NET_DONE;
665                 _req_may_be_done_not_susp(req, m);
666                 /* else: done by handed_over_to_network */
667                 break;
668
669         case fail_frozen_disk_io:
670                 if (!(req->rq_state & RQ_LOCAL_COMPLETED))
671                         break;
672
673                 _req_may_be_done(req, m); /* Allowed while state.susp */
674                 break;
675
676         case restart_frozen_disk_io:
677                 if (!(req->rq_state & RQ_LOCAL_COMPLETED))
678                         break;
679
680                 req->rq_state &= ~RQ_LOCAL_COMPLETED;
681
682                 rv = MR_READ;
683                 if (bio_data_dir(req->master_bio) == WRITE)
684                         rv = MR_WRITE;
685
686                 get_ldev(mdev);
687                 req->w.cb = w_restart_disk_io;
688                 drbd_queue_work(&mdev->data.work, &req->w);
689                 break;
690
691         case resend:
692                 /* If RQ_NET_OK is already set, we got a P_WRITE_ACK or P_RECV_ACK
693                    before the connection loss (B&C only); only P_BARRIER_ACK was missing.
694                    Trowing them out of the TL here by pretending we got a BARRIER_ACK
695                    We ensure that the peer was not rebooted */
696                 if (!(req->rq_state & RQ_NET_OK)) {
697                         if (req->w.cb) {
698                                 drbd_queue_work(&mdev->data.work, &req->w);
699                                 rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ;
700                         }
701                         break;
702                 }
703                 /* else, fall through to barrier_acked */
704
705         case barrier_acked:
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 have been 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                         list_move(&req->tl_requests, &mdev->out_of_sequence_requests);
715                 }
716                 if ((req->rq_state & RQ_NET_MASK) != 0) {
717                         req->rq_state |= RQ_NET_DONE;
718                         if (mdev->net_conf->wire_protocol == DRBD_PROT_A)
719                                 atomic_sub(req->size>>9, &mdev->ap_in_flight);
720                 }
721                 _req_may_be_done(req, m); /* Allowed while state.susp */
722                 break;
723
724         case data_received:
725                 D_ASSERT(req->rq_state & RQ_NET_PENDING);
726                 dec_ap_pending(mdev);
727                 req->rq_state &= ~RQ_NET_PENDING;
728                 req->rq_state |= (RQ_NET_OK|RQ_NET_DONE);
729                 _req_may_be_done_not_susp(req, m);
730                 break;
731         };
732
733         return rv;
734 }
735
736 /* we may do a local read if:
737  * - we are consistent (of course),
738  * - or we are generally inconsistent,
739  *   BUT we are still/already IN SYNC for this area.
740  *   since size may be bigger than BM_BLOCK_SIZE,
741  *   we may need to check several bits.
742  */
743 static int drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size)
744 {
745         unsigned long sbnr, ebnr;
746         sector_t esector, nr_sectors;
747
748         if (mdev->state.disk == D_UP_TO_DATE)
749                 return 1;
750         if (mdev->state.disk >= D_OUTDATED)
751                 return 0;
752         if (mdev->state.disk <  D_INCONSISTENT)
753                 return 0;
754         /* state.disk == D_INCONSISTENT   We will have a look at the BitMap */
755         nr_sectors = drbd_get_capacity(mdev->this_bdev);
756         esector = sector + (size >> 9) - 1;
757
758         D_ASSERT(sector  < nr_sectors);
759         D_ASSERT(esector < nr_sectors);
760
761         sbnr = BM_SECT_TO_BIT(sector);
762         ebnr = BM_SECT_TO_BIT(esector);
763
764         return 0 == drbd_bm_count_bits(mdev, sbnr, ebnr);
765 }
766
767 static int drbd_make_request_common(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time)
768 {
769         const int rw = bio_rw(bio);
770         const int size = bio->bi_size;
771         const sector_t sector = bio->bi_sector;
772         struct drbd_tl_epoch *b = NULL;
773         struct drbd_request *req;
774         int local, remote, send_oos = 0;
775         int err = -EIO;
776         int ret = 0;
777
778         /* allocate outside of all locks; */
779         req = drbd_req_new(mdev, bio);
780         if (!req) {
781                 dec_ap_bio(mdev);
782                 /* only pass the error to the upper layers.
783                  * if user cannot handle io errors, that's not our business. */
784                 dev_err(DEV, "could not kmalloc() req\n");
785                 bio_endio(bio, -ENOMEM);
786                 return 0;
787         }
788         req->start_time = start_time;
789
790         local = get_ldev(mdev);
791         if (!local) {
792                 bio_put(req->private_bio); /* or we get a bio leak */
793                 req->private_bio = NULL;
794         }
795         if (rw == WRITE) {
796                 remote = 1;
797         } else {
798                 /* READ || READA */
799                 if (local) {
800                         if (!drbd_may_do_local_read(mdev, sector, size)) {
801                                 /* we could kick the syncer to
802                                  * sync this extent asap, wait for
803                                  * it, then continue locally.
804                                  * Or just issue the request remotely.
805                                  */
806                                 local = 0;
807                                 bio_put(req->private_bio);
808                                 req->private_bio = NULL;
809                                 put_ldev(mdev);
810                         }
811                 }
812                 remote = !local && mdev->state.pdsk >= D_UP_TO_DATE;
813         }
814
815         /* If we have a disk, but a READA request is mapped to remote,
816          * we are R_PRIMARY, D_INCONSISTENT, SyncTarget.
817          * Just fail that READA request right here.
818          *
819          * THINK: maybe fail all READA when not local?
820          *        or make this configurable...
821          *        if network is slow, READA won't do any good.
822          */
823         if (rw == READA && mdev->state.disk >= D_INCONSISTENT && !local) {
824                 err = -EWOULDBLOCK;
825                 goto fail_and_free_req;
826         }
827
828         /* For WRITES going to the local disk, grab a reference on the target
829          * extent.  This waits for any resync activity in the corresponding
830          * resync extent to finish, and, if necessary, pulls in the target
831          * extent into the activity log, which involves further disk io because
832          * of transactional on-disk meta data updates. */
833         if (rw == WRITE && local && !test_bit(AL_SUSPENDED, &mdev->flags)) {
834                 req->rq_state |= RQ_IN_ACT_LOG;
835                 drbd_al_begin_io(mdev, sector);
836         }
837
838         remote = remote && drbd_should_do_remote(mdev->state);
839         send_oos = rw == WRITE && drbd_should_send_oos(mdev->state);
840         D_ASSERT(!(remote && send_oos));
841
842         if (!(local || remote) && !is_susp(mdev->state)) {
843                 if (__ratelimit(&drbd_ratelimit_state))
844                         dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
845                 goto fail_free_complete;
846         }
847
848         /* For WRITE request, we have to make sure that we have an
849          * unused_spare_tle, in case we need to start a new epoch.
850          * I try to be smart and avoid to pre-allocate always "just in case",
851          * but there is a race between testing the bit and pointer outside the
852          * spinlock, and grabbing the spinlock.
853          * if we lost that race, we retry.  */
854         if (rw == WRITE && (remote || send_oos) &&
855             mdev->unused_spare_tle == NULL &&
856             test_bit(CREATE_BARRIER, &mdev->flags)) {
857 allocate_barrier:
858                 b = kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO);
859                 if (!b) {
860                         dev_err(DEV, "Failed to alloc barrier.\n");
861                         err = -ENOMEM;
862                         goto fail_free_complete;
863                 }
864         }
865
866         /* GOOD, everything prepared, grab the spin_lock */
867         spin_lock_irq(&mdev->req_lock);
868
869         if (is_susp(mdev->state)) {
870                 /* If we got suspended, use the retry mechanism of
871                    generic_make_request() to restart processing of this
872                    bio. In the next call to drbd_make_request
873                    we sleep in inc_ap_bio() */
874                 ret = 1;
875                 spin_unlock_irq(&mdev->req_lock);
876                 goto fail_free_complete;
877         }
878
879         if (remote || send_oos) {
880                 remote = drbd_should_do_remote(mdev->state);
881                 send_oos = rw == WRITE && drbd_should_send_oos(mdev->state);
882                 D_ASSERT(!(remote && send_oos));
883
884                 if (!(remote || send_oos))
885                         dev_warn(DEV, "lost connection while grabbing the req_lock!\n");
886                 if (!(local || remote)) {
887                         dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
888                         spin_unlock_irq(&mdev->req_lock);
889                         goto fail_free_complete;
890                 }
891         }
892
893         if (b && mdev->unused_spare_tle == NULL) {
894                 mdev->unused_spare_tle = b;
895                 b = NULL;
896         }
897         if (rw == WRITE && (remote || send_oos) &&
898             mdev->unused_spare_tle == NULL &&
899             test_bit(CREATE_BARRIER, &mdev->flags)) {
900                 /* someone closed the current epoch
901                  * while we were grabbing the spinlock */
902                 spin_unlock_irq(&mdev->req_lock);
903                 goto allocate_barrier;
904         }
905
906
907         /* Update disk stats */
908         _drbd_start_io_acct(mdev, req, bio);
909
910         /* _maybe_start_new_epoch(mdev);
911          * If we need to generate a write barrier packet, we have to add the
912          * new epoch (barrier) object, and queue the barrier packet for sending,
913          * and queue the req's data after it _within the same lock_, otherwise
914          * we have race conditions were the reorder domains could be mixed up.
915          *
916          * Even read requests may start a new epoch and queue the corresponding
917          * barrier packet.  To get the write ordering right, we only have to
918          * make sure that, if this is a write request and it triggered a
919          * barrier packet, this request is queued within the same spinlock. */
920         if ((remote || send_oos) && mdev->unused_spare_tle &&
921             test_and_clear_bit(CREATE_BARRIER, &mdev->flags)) {
922                 _tl_add_barrier(mdev, mdev->unused_spare_tle);
923                 mdev->unused_spare_tle = NULL;
924         } else {
925                 D_ASSERT(!(remote && rw == WRITE &&
926                            test_bit(CREATE_BARRIER, &mdev->flags)));
927         }
928
929         /* NOTE
930          * Actually, 'local' may be wrong here already, since we may have failed
931          * to write to the meta data, and may become wrong anytime because of
932          * local io-error for some other request, which would lead to us
933          * "detaching" the local disk.
934          *
935          * 'remote' may become wrong any time because the network could fail.
936          *
937          * This is a harmless race condition, though, since it is handled
938          * correctly at the appropriate places; so it just defers the failure
939          * of the respective operation.
940          */
941
942         /* mark them early for readability.
943          * this just sets some state flags. */
944         if (remote)
945                 _req_mod(req, to_be_send);
946         if (local)
947                 _req_mod(req, to_be_submitted);
948
949         /* check this request on the collision detection hash tables.
950          * if we have a conflict, just complete it here.
951          * THINK do we want to check reads, too? (I don't think so...) */
952         if (rw == WRITE && _req_conflicts(req))
953                 goto fail_conflicting;
954
955         list_add_tail(&req->tl_requests, &mdev->newest_tle->requests);
956
957         /* NOTE remote first: to get the concurrent write detection right,
958          * we must register the request before start of local IO.  */
959         if (remote) {
960                 /* either WRITE and C_CONNECTED,
961                  * or READ, and no local disk,
962                  * or READ, but not in sync.
963                  */
964                 _req_mod(req, (rw == WRITE)
965                                 ? queue_for_net_write
966                                 : queue_for_net_read);
967         }
968         if (send_oos && drbd_set_out_of_sync(mdev, sector, size))
969                 _req_mod(req, queue_for_send_oos);
970
971         if (remote &&
972             mdev->net_conf->on_congestion != OC_BLOCK && mdev->agreed_pro_version >= 96) {
973                 int congested = 0;
974
975                 if (mdev->net_conf->cong_fill &&
976                     atomic_read(&mdev->ap_in_flight) >= mdev->net_conf->cong_fill) {
977                         dev_info(DEV, "Congestion-fill threshold reached\n");
978                         congested = 1;
979                 }
980
981                 if (mdev->act_log->used >= mdev->net_conf->cong_extents) {
982                         dev_info(DEV, "Congestion-extents threshold reached\n");
983                         congested = 1;
984                 }
985
986                 if (congested) {
987                         queue_barrier(mdev); /* last barrier, after mirrored writes */
988
989                         if (mdev->net_conf->on_congestion == OC_PULL_AHEAD)
990                                 _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL);
991                         else  /*mdev->net_conf->on_congestion == OC_DISCONNECT */
992                                 _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL);
993                 }
994         }
995
996         spin_unlock_irq(&mdev->req_lock);
997         kfree(b); /* if someone else has beaten us to it... */
998
999         if (local) {
1000                 req->private_bio->bi_bdev = mdev->ldev->backing_bdev;
1001
1002                 /* State may have changed since we grabbed our reference on the
1003                  * mdev->ldev member. Double check, and short-circuit to endio.
1004                  * In case the last activity log transaction failed to get on
1005                  * stable storage, and this is a WRITE, we may not even submit
1006                  * this bio. */
1007                 if (get_ldev(mdev)) {
1008                         if (drbd_insert_fault(mdev,   rw == WRITE ? DRBD_FAULT_DT_WR
1009                                                     : rw == READ  ? DRBD_FAULT_DT_RD
1010                                                     :               DRBD_FAULT_DT_RA))
1011                                 bio_endio(req->private_bio, -EIO);
1012                         else
1013                                 generic_make_request(req->private_bio);
1014                         put_ldev(mdev);
1015                 } else
1016                         bio_endio(req->private_bio, -EIO);
1017         }
1018
1019         return 0;
1020
1021 fail_conflicting:
1022         /* this is a conflicting request.
1023          * even though it may have been only _partially_
1024          * overlapping with one of the currently pending requests,
1025          * without even submitting or sending it, we will
1026          * pretend that it was successfully served right now.
1027          */
1028         _drbd_end_io_acct(mdev, req);
1029         spin_unlock_irq(&mdev->req_lock);
1030         if (remote)
1031                 dec_ap_pending(mdev);
1032         /* THINK: do we want to fail it (-EIO), or pretend success?
1033          * this pretends success. */
1034         err = 0;
1035
1036 fail_free_complete:
1037         if (req->rq_state & RQ_IN_ACT_LOG)
1038                 drbd_al_complete_io(mdev, sector);
1039 fail_and_free_req:
1040         if (local) {
1041                 bio_put(req->private_bio);
1042                 req->private_bio = NULL;
1043                 put_ldev(mdev);
1044         }
1045         if (!ret)
1046                 bio_endio(bio, err);
1047
1048         drbd_req_free(req);
1049         dec_ap_bio(mdev);
1050         kfree(b);
1051
1052         return ret;
1053 }
1054
1055 /* helper function for drbd_make_request
1056  * if we can determine just by the mdev (state) that this request will fail,
1057  * return 1
1058  * otherwise return 0
1059  */
1060 static int drbd_fail_request_early(struct drbd_conf *mdev, int is_write)
1061 {
1062         if (mdev->state.role != R_PRIMARY &&
1063                 (!allow_oos || is_write)) {
1064                 if (__ratelimit(&drbd_ratelimit_state)) {
1065                         dev_err(DEV, "Process %s[%u] tried to %s; "
1066                             "since we are not in Primary state, "
1067                             "we cannot allow this\n",
1068                             current->comm, current->pid,
1069                             is_write ? "WRITE" : "READ");
1070                 }
1071                 return 1;
1072         }
1073
1074         return 0;
1075 }
1076
1077 void drbd_make_request(struct request_queue *q, struct bio *bio)
1078 {
1079         unsigned int s_enr, e_enr;
1080         struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
1081         unsigned long start_time;
1082
1083         if (drbd_fail_request_early(mdev, bio_data_dir(bio) & WRITE)) {
1084                 bio_endio(bio, -EPERM);
1085                 return;
1086         }
1087
1088         start_time = jiffies;
1089
1090         /*
1091          * what we "blindly" assume:
1092          */
1093         D_ASSERT(bio->bi_size > 0);
1094         D_ASSERT((bio->bi_size & 0x1ff) == 0);
1095         D_ASSERT(bio->bi_idx == 0);
1096
1097         /* to make some things easier, force alignment of requests within the
1098          * granularity of our hash tables */
1099         s_enr = bio->bi_sector >> HT_SHIFT;
1100         e_enr = (bio->bi_sector+(bio->bi_size>>9)-1) >> HT_SHIFT;
1101
1102         if (likely(s_enr == e_enr)) {
1103                 inc_ap_bio(mdev, 1);
1104                 drbd_make_request_common(mdev, bio, start_time);
1105                 return;
1106         }
1107
1108         /* can this bio be split generically?
1109          * Maybe add our own split-arbitrary-bios function. */
1110         if (bio->bi_vcnt != 1 || bio->bi_idx != 0 || bio->bi_size > DRBD_MAX_BIO_SIZE) {
1111                 /* rather error out here than BUG in bio_split */
1112                 dev_err(DEV, "bio would need to, but cannot, be split: "
1113                     "(vcnt=%u,idx=%u,size=%u,sector=%llu)\n",
1114                     bio->bi_vcnt, bio->bi_idx, bio->bi_size,
1115                     (unsigned long long)bio->bi_sector);
1116                 bio_endio(bio, -EINVAL);
1117         } else {
1118                 /* This bio crosses some boundary, so we have to split it. */
1119                 struct bio_pair *bp;
1120                 /* works for the "do not cross hash slot boundaries" case
1121                  * e.g. sector 262269, size 4096
1122                  * s_enr = 262269 >> 6 = 4097
1123                  * e_enr = (262269+8-1) >> 6 = 4098
1124                  * HT_SHIFT = 6
1125                  * sps = 64, mask = 63
1126                  * first_sectors = 64 - (262269 & 63) = 3
1127                  */
1128                 const sector_t sect = bio->bi_sector;
1129                 const int sps = 1 << HT_SHIFT; /* sectors per slot */
1130                 const int mask = sps - 1;
1131                 const sector_t first_sectors = sps - (sect & mask);
1132                 bp = bio_split(bio, first_sectors);
1133
1134                 /* we need to get a "reference count" (ap_bio_cnt)
1135                  * to avoid races with the disconnect/reconnect/suspend code.
1136                  * In case we need to split the bio here, we need to get three references
1137                  * atomically, otherwise we might deadlock when trying to submit the
1138                  * second one! */
1139                 inc_ap_bio(mdev, 3);
1140
1141                 D_ASSERT(e_enr == s_enr + 1);
1142
1143                 while (drbd_make_request_common(mdev, &bp->bio1, start_time))
1144                         inc_ap_bio(mdev, 1);
1145
1146                 while (drbd_make_request_common(mdev, &bp->bio2, start_time))
1147                         inc_ap_bio(mdev, 1);
1148
1149                 dec_ap_bio(mdev);
1150
1151                 bio_pair_release(bp);
1152         }
1153 }
1154
1155 /* This is called by bio_add_page().  With this function we reduce
1156  * the number of BIOs that span over multiple DRBD_MAX_BIO_SIZEs
1157  * units (was AL_EXTENTs).
1158  *
1159  * we do the calculation within the lower 32bit of the byte offsets,
1160  * since we don't care for actual offset, but only check whether it
1161  * would cross "activity log extent" boundaries.
1162  *
1163  * As long as the BIO is empty we have to allow at least one bvec,
1164  * regardless of size and offset.  so the resulting bio may still
1165  * cross extent boundaries.  those are dealt with (bio_split) in
1166  * drbd_make_request.
1167  */
1168 int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec)
1169 {
1170         struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
1171         unsigned int bio_offset =
1172                 (unsigned int)bvm->bi_sector << 9; /* 32 bit */
1173         unsigned int bio_size = bvm->bi_size;
1174         int limit, backing_limit;
1175
1176         limit = DRBD_MAX_BIO_SIZE
1177               - ((bio_offset & (DRBD_MAX_BIO_SIZE-1)) + bio_size);
1178         if (limit < 0)
1179                 limit = 0;
1180         if (bio_size == 0) {
1181                 if (limit <= bvec->bv_len)
1182                         limit = bvec->bv_len;
1183         } else if (limit && get_ldev(mdev)) {
1184                 struct request_queue * const b =
1185                         mdev->ldev->backing_bdev->bd_disk->queue;
1186                 if (b->merge_bvec_fn) {
1187                         bvm->bi_bdev = mdev->ldev->backing_bdev;
1188                         backing_limit = b->merge_bvec_fn(b, bvm, bvec);
1189                         limit = min(limit, backing_limit);
1190                 }
1191                 put_ldev(mdev);
1192         }
1193         return limit;
1194 }
1195
1196 void request_timer_fn(unsigned long data)
1197 {
1198         struct drbd_conf *mdev = (struct drbd_conf *) data;
1199         struct drbd_request *req; /* oldest request */
1200         struct list_head *le;
1201         unsigned long et = 0; /* effective timeout = ko_count * timeout */
1202
1203         if (get_net_conf(mdev)) {
1204                 et = mdev->net_conf->timeout*HZ/10 * mdev->net_conf->ko_count;
1205                 put_net_conf(mdev);
1206         }
1207         if (!et || mdev->state.conn < C_WF_REPORT_PARAMS)
1208                 return; /* Recurring timer stopped */
1209
1210         spin_lock_irq(&mdev->req_lock);
1211         le = &mdev->oldest_tle->requests;
1212         if (list_empty(le)) {
1213                 spin_unlock_irq(&mdev->req_lock);
1214                 mod_timer(&mdev->request_timer, jiffies + et);
1215                 return;
1216         }
1217
1218         le = le->prev;
1219         req = list_entry(le, struct drbd_request, tl_requests);
1220         if (time_is_before_eq_jiffies(req->start_time + et)) {
1221                 if (req->rq_state & RQ_NET_PENDING) {
1222                         dev_warn(DEV, "Remote failed to finish a request within ko-count * timeout\n");
1223                         _drbd_set_state(_NS(mdev, conn, C_TIMEOUT), CS_VERBOSE, NULL);
1224                 } else {
1225                         dev_warn(DEV, "Local backing block device frozen?\n");
1226                         mod_timer(&mdev->request_timer, jiffies + et);
1227                 }
1228         } else {
1229                 mod_timer(&mdev->request_timer, req->start_time + et);
1230         }
1231
1232         spin_unlock_irq(&mdev->req_lock);
1233 }