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