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