drbd_req.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177
  1. /*
  2. drbd_req.c
  3. This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
  4. Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
  5. Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
  6. Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
  7. drbd is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. drbd is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with drbd; see the file COPYING. If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/drbd.h>
  22. #include "drbd_int.h"
  23. #include "drbd_req.h"
  24. /* Update disk stats at start of I/O request */
  25. static void _drbd_start_io_acct(struct drbd_conf *mdev, struct drbd_request *req, struct bio *bio)
  26. {
  27. const int rw = bio_data_dir(bio);
  28. int cpu;
  29. cpu = part_stat_lock();
  30. part_stat_inc(cpu, &mdev->vdisk->part0, ios[rw]);
  31. part_stat_add(cpu, &mdev->vdisk->part0, sectors[rw], bio_sectors(bio));
  32. part_inc_in_flight(&mdev->vdisk->part0, rw);
  33. part_stat_unlock();
  34. }
  35. /* Update disk stats when completing request upwards */
  36. static void _drbd_end_io_acct(struct drbd_conf *mdev, struct drbd_request *req)
  37. {
  38. int rw = bio_data_dir(req->master_bio);
  39. unsigned long duration = jiffies - req->start_time;
  40. int cpu;
  41. cpu = part_stat_lock();
  42. part_stat_add(cpu, &mdev->vdisk->part0, ticks[rw], duration);
  43. part_round_stats(cpu, &mdev->vdisk->part0);
  44. part_dec_in_flight(&mdev->vdisk->part0, rw);
  45. part_stat_unlock();
  46. }
  47. static struct drbd_request *drbd_req_new(struct drbd_conf *mdev,
  48. struct bio *bio_src)
  49. {
  50. struct drbd_request *req;
  51. req = mempool_alloc(drbd_request_mempool, GFP_NOIO);
  52. if (!req)
  53. return NULL;
  54. drbd_req_make_private_bio(req, bio_src);
  55. req->rq_state = bio_data_dir(bio_src) == WRITE ? RQ_WRITE : 0;
  56. req->w.mdev = mdev;
  57. req->master_bio = bio_src;
  58. req->epoch = 0;
  59. drbd_clear_interval(&req->i);
  60. req->i.sector = bio_src->bi_sector;
  61. req->i.size = bio_src->bi_size;
  62. req->i.local = true;
  63. req->i.waiting = false;
  64. INIT_LIST_HEAD(&req->tl_requests);
  65. INIT_LIST_HEAD(&req->w.list);
  66. return req;
  67. }
  68. static void drbd_req_free(struct drbd_request *req)
  69. {
  70. mempool_free(req, drbd_request_mempool);
  71. }
  72. /* rw is bio_data_dir(), only READ or WRITE */
  73. static void _req_is_done(struct drbd_conf *mdev, struct drbd_request *req, const int rw)
  74. {
  75. const unsigned long s = req->rq_state;
  76. /* remove it from the transfer log.
  77. * well, only if it had been there in the first
  78. * place... if it had not (local only or conflicting
  79. * and never sent), it should still be "empty" as
  80. * initialized in drbd_req_new(), so we can list_del() it
  81. * here unconditionally */
  82. list_del(&req->tl_requests);
  83. /* if it was a write, we may have to set the corresponding
  84. * bit(s) out-of-sync first. If it had a local part, we need to
  85. * release the reference to the activity log. */
  86. if (rw == WRITE) {
  87. /* Set out-of-sync unless both OK flags are set
  88. * (local only or remote failed).
  89. * Other places where we set out-of-sync:
  90. * READ with local io-error */
  91. if (!(s & RQ_NET_OK) || !(s & RQ_LOCAL_OK))
  92. drbd_set_out_of_sync(mdev, req->i.sector, req->i.size);
  93. if ((s & RQ_NET_OK) && (s & RQ_LOCAL_OK) && (s & RQ_NET_SIS))
  94. drbd_set_in_sync(mdev, req->i.sector, req->i.size);
  95. /* one might be tempted to move the drbd_al_complete_io
  96. * to the local io completion callback drbd_request_endio.
  97. * but, if this was a mirror write, we may only
  98. * drbd_al_complete_io after this is RQ_NET_DONE,
  99. * otherwise the extent could be dropped from the al
  100. * before it has actually been written on the peer.
  101. * if we crash before our peer knows about the request,
  102. * but after the extent has been dropped from the al,
  103. * we would forget to resync the corresponding extent.
  104. */
  105. if (s & RQ_LOCAL_MASK) {
  106. if (get_ldev_if_state(mdev, D_FAILED)) {
  107. if (s & RQ_IN_ACT_LOG)
  108. drbd_al_complete_io(mdev, req->i.sector);
  109. put_ldev(mdev);
  110. } else if (__ratelimit(&drbd_ratelimit_state)) {
  111. dev_warn(DEV, "Should have called drbd_al_complete_io(, %llu), "
  112. "but my Disk seems to have failed :(\n",
  113. (unsigned long long) req->i.sector);
  114. }
  115. }
  116. }
  117. drbd_req_free(req);
  118. }
  119. static void queue_barrier(struct drbd_conf *mdev)
  120. {
  121. struct drbd_tl_epoch *b;
  122. /* We are within the req_lock. Once we queued the barrier for sending,
  123. * we set the CREATE_BARRIER bit. It is cleared as soon as a new
  124. * barrier/epoch object is added. This is the only place this bit is
  125. * set. It indicates that the barrier for this epoch is already queued,
  126. * and no new epoch has been created yet. */
  127. if (test_bit(CREATE_BARRIER, &mdev->flags))
  128. return;
  129. b = mdev->tconn->newest_tle;
  130. b->w.cb = w_send_barrier;
  131. b->w.mdev = mdev;
  132. /* inc_ap_pending done here, so we won't
  133. * get imbalanced on connection loss.
  134. * dec_ap_pending will be done in got_BarrierAck
  135. * or (on connection loss) in tl_clear. */
  136. inc_ap_pending(mdev);
  137. drbd_queue_work(&mdev->tconn->data.work, &b->w);
  138. set_bit(CREATE_BARRIER, &mdev->flags);
  139. }
  140. static void _about_to_complete_local_write(struct drbd_conf *mdev,
  141. struct drbd_request *req)
  142. {
  143. const unsigned long s = req->rq_state;
  144. /* Before we can signal completion to the upper layers,
  145. * we may need to close the current epoch.
  146. * We can skip this, if this request has not even been sent, because we
  147. * did not have a fully established connection yet/anymore, during
  148. * bitmap exchange, or while we are C_AHEAD due to congestion policy.
  149. */
  150. if (mdev->state.conn >= C_CONNECTED &&
  151. (s & RQ_NET_SENT) != 0 &&
  152. req->epoch == mdev->tconn->newest_tle->br_number)
  153. queue_barrier(mdev);
  154. }
  155. void complete_master_bio(struct drbd_conf *mdev,
  156. struct bio_and_error *m)
  157. {
  158. bio_endio(m->bio, m->error);
  159. dec_ap_bio(mdev);
  160. }
  161. static void drbd_remove_request_interval(struct rb_root *root,
  162. struct drbd_request *req)
  163. {
  164. struct drbd_conf *mdev = req->w.mdev;
  165. struct drbd_interval *i = &req->i;
  166. drbd_remove_interval(root, i);
  167. /* Wake up any processes waiting for this request to complete. */
  168. if (i->waiting)
  169. wake_up(&mdev->misc_wait);
  170. }
  171. /* Helper for __req_mod().
  172. * Set m->bio to the master bio, if it is fit to be completed,
  173. * or leave it alone (it is initialized to NULL in __req_mod),
  174. * if it has already been completed, or cannot be completed yet.
  175. * If m->bio is set, the error status to be returned is placed in m->error.
  176. */
  177. void _req_may_be_done(struct drbd_request *req, struct bio_and_error *m)
  178. {
  179. const unsigned long s = req->rq_state;
  180. struct drbd_conf *mdev = req->w.mdev;
  181. /* only WRITES may end up here without a master bio (on barrier ack) */
  182. int rw = req->master_bio ? bio_data_dir(req->master_bio) : WRITE;
  183. /* we must not complete the master bio, while it is
  184. * still being processed by _drbd_send_zc_bio (drbd_send_dblock)
  185. * not yet acknowledged by the peer
  186. * not yet completed by the local io subsystem
  187. * these flags may get cleared in any order by
  188. * the worker,
  189. * the receiver,
  190. * the bio_endio completion callbacks.
  191. */
  192. if (s & RQ_LOCAL_PENDING)
  193. return;
  194. if (req->i.waiting) {
  195. /* Retry all conflicting peer requests. */
  196. wake_up(&mdev->misc_wait);
  197. }
  198. if (s & RQ_NET_QUEUED)
  199. return;
  200. if (s & RQ_NET_PENDING)
  201. return;
  202. if (req->master_bio) {
  203. /* this is DATA_RECEIVED (remote read)
  204. * or protocol C P_WRITE_ACK
  205. * or protocol B P_RECV_ACK
  206. * or protocol A "HANDED_OVER_TO_NETWORK" (SendAck)
  207. * or canceled or failed,
  208. * or killed from the transfer log due to connection loss.
  209. */
  210. /*
  211. * figure out whether to report success or failure.
  212. *
  213. * report success when at least one of the operations succeeded.
  214. * or, to put the other way,
  215. * only report failure, when both operations failed.
  216. *
  217. * what to do about the failures is handled elsewhere.
  218. * what we need to do here is just: complete the master_bio.
  219. *
  220. * local completion error, if any, has been stored as ERR_PTR
  221. * in private_bio within drbd_request_endio.
  222. */
  223. int ok = (s & RQ_LOCAL_OK) || (s & RQ_NET_OK);
  224. int error = PTR_ERR(req->private_bio);
  225. /* remove the request from the conflict detection
  226. * respective block_id verification hash */
  227. if (!drbd_interval_empty(&req->i)) {
  228. struct rb_root *root;
  229. if (rw == WRITE)
  230. root = &mdev->write_requests;
  231. else
  232. root = &mdev->read_requests;
  233. drbd_remove_request_interval(root, req);
  234. } else if (!(s & RQ_POSTPONED))
  235. D_ASSERT((s & (RQ_NET_MASK & ~RQ_NET_DONE)) == 0);
  236. /* for writes we need to do some extra housekeeping */
  237. if (rw == WRITE)
  238. _about_to_complete_local_write(mdev, req);
  239. /* Update disk stats */
  240. _drbd_end_io_acct(mdev, req);
  241. if (!(s & RQ_POSTPONED)) {
  242. m->error = ok ? 0 : (error ?: -EIO);
  243. m->bio = req->master_bio;
  244. }
  245. req->master_bio = NULL;
  246. }
  247. if ((s & RQ_NET_MASK) == 0 || (s & RQ_NET_DONE)) {
  248. /* this is disconnected (local only) operation,
  249. * or protocol C P_WRITE_ACK,
  250. * or protocol A or B P_BARRIER_ACK,
  251. * or killed from the transfer log due to connection loss. */
  252. _req_is_done(mdev, req, rw);
  253. }
  254. /* else: network part and not DONE yet. that is
  255. * protocol A or B, barrier ack still pending... */
  256. }
  257. static void _req_may_be_done_not_susp(struct drbd_request *req, struct bio_and_error *m)
  258. {
  259. struct drbd_conf *mdev = req->w.mdev;
  260. if (!is_susp(mdev->state))
  261. _req_may_be_done(req, m);
  262. }
  263. /* obviously this could be coded as many single functions
  264. * instead of one huge switch,
  265. * or by putting the code directly in the respective locations
  266. * (as it has been before).
  267. *
  268. * but having it this way
  269. * enforces that it is all in this one place, where it is easier to audit,
  270. * it makes it obvious that whatever "event" "happens" to a request should
  271. * happen "atomically" within the req_lock,
  272. * and it enforces that we have to think in a very structured manner
  273. * about the "events" that may happen to a request during its life time ...
  274. */
  275. int __req_mod(struct drbd_request *req, enum drbd_req_event what,
  276. struct bio_and_error *m)
  277. {
  278. struct drbd_conf *mdev = req->w.mdev;
  279. int rv = 0;
  280. if (m)
  281. m->bio = NULL;
  282. switch (what) {
  283. default:
  284. dev_err(DEV, "LOGIC BUG in %s:%u\n", __FILE__ , __LINE__);
  285. break;
  286. /* does not happen...
  287. * initialization done in drbd_req_new
  288. case CREATED:
  289. break;
  290. */
  291. case TO_BE_SENT: /* via network */
  292. /* reached via __drbd_make_request
  293. * and from w_read_retry_remote */
  294. D_ASSERT(!(req->rq_state & RQ_NET_MASK));
  295. req->rq_state |= RQ_NET_PENDING;
  296. inc_ap_pending(mdev);
  297. break;
  298. case TO_BE_SUBMITTED: /* locally */
  299. /* reached via __drbd_make_request */
  300. D_ASSERT(!(req->rq_state & RQ_LOCAL_MASK));
  301. req->rq_state |= RQ_LOCAL_PENDING;
  302. break;
  303. case COMPLETED_OK:
  304. if (bio_data_dir(req->master_bio) == WRITE)
  305. mdev->writ_cnt += req->i.size >> 9;
  306. else
  307. mdev->read_cnt += req->i.size >> 9;
  308. req->rq_state |= (RQ_LOCAL_COMPLETED|RQ_LOCAL_OK);
  309. req->rq_state &= ~RQ_LOCAL_PENDING;
  310. _req_may_be_done_not_susp(req, m);
  311. put_ldev(mdev);
  312. break;
  313. case WRITE_COMPLETED_WITH_ERROR:
  314. req->rq_state |= RQ_LOCAL_COMPLETED;
  315. req->rq_state &= ~RQ_LOCAL_PENDING;
  316. __drbd_chk_io_error(mdev, false);
  317. _req_may_be_done_not_susp(req, m);
  318. put_ldev(mdev);
  319. break;
  320. case READ_AHEAD_COMPLETED_WITH_ERROR:
  321. /* it is legal to fail READA */
  322. req->rq_state |= RQ_LOCAL_COMPLETED;
  323. req->rq_state &= ~RQ_LOCAL_PENDING;
  324. _req_may_be_done_not_susp(req, m);
  325. put_ldev(mdev);
  326. break;
  327. case READ_COMPLETED_WITH_ERROR:
  328. drbd_set_out_of_sync(mdev, req->i.sector, req->i.size);
  329. req->rq_state |= RQ_LOCAL_COMPLETED;
  330. req->rq_state &= ~RQ_LOCAL_PENDING;
  331. D_ASSERT(!(req->rq_state & RQ_NET_MASK));
  332. __drbd_chk_io_error(mdev, false);
  333. put_ldev(mdev);
  334. /* no point in retrying if there is no good remote data,
  335. * or we have no connection. */
  336. if (mdev->state.pdsk != D_UP_TO_DATE) {
  337. _req_may_be_done_not_susp(req, m);
  338. break;
  339. }
  340. /* _req_mod(req,TO_BE_SENT); oops, recursion... */
  341. req->rq_state |= RQ_NET_PENDING;
  342. inc_ap_pending(mdev);
  343. /* fall through: _req_mod(req,QUEUE_FOR_NET_READ); */
  344. case QUEUE_FOR_NET_READ:
  345. /* READ or READA, and
  346. * no local disk,
  347. * or target area marked as invalid,
  348. * or just got an io-error. */
  349. /* from __drbd_make_request
  350. * or from bio_endio during read io-error recovery */
  351. /* so we can verify the handle in the answer packet
  352. * corresponding hlist_del is in _req_may_be_done() */
  353. drbd_insert_interval(&mdev->read_requests, &req->i);
  354. set_bit(UNPLUG_REMOTE, &mdev->flags);
  355. D_ASSERT(req->rq_state & RQ_NET_PENDING);
  356. req->rq_state |= RQ_NET_QUEUED;
  357. req->w.cb = (req->rq_state & RQ_LOCAL_MASK)
  358. ? w_read_retry_remote
  359. : w_send_read_req;
  360. drbd_queue_work(&mdev->tconn->data.work, &req->w);
  361. break;
  362. case QUEUE_FOR_NET_WRITE:
  363. /* assert something? */
  364. /* from __drbd_make_request only */
  365. /* corresponding hlist_del is in _req_may_be_done() */
  366. drbd_insert_interval(&mdev->write_requests, &req->i);
  367. /* NOTE
  368. * In case the req ended up on the transfer log before being
  369. * queued on the worker, it could lead to this request being
  370. * missed during cleanup after connection loss.
  371. * So we have to do both operations here,
  372. * within the same lock that protects the transfer log.
  373. *
  374. * _req_add_to_epoch(req); this has to be after the
  375. * _maybe_start_new_epoch(req); which happened in
  376. * __drbd_make_request, because we now may set the bit
  377. * again ourselves to close the current epoch.
  378. *
  379. * Add req to the (now) current epoch (barrier). */
  380. /* otherwise we may lose an unplug, which may cause some remote
  381. * io-scheduler timeout to expire, increasing maximum latency,
  382. * hurting performance. */
  383. set_bit(UNPLUG_REMOTE, &mdev->flags);
  384. /* see __drbd_make_request,
  385. * just after it grabs the req_lock */
  386. D_ASSERT(test_bit(CREATE_BARRIER, &mdev->flags) == 0);
  387. req->epoch = mdev->tconn->newest_tle->br_number;
  388. /* increment size of current epoch */
  389. mdev->tconn->newest_tle->n_writes++;
  390. /* queue work item to send data */
  391. D_ASSERT(req->rq_state & RQ_NET_PENDING);
  392. req->rq_state |= RQ_NET_QUEUED;
  393. req->w.cb = w_send_dblock;
  394. drbd_queue_work(&mdev->tconn->data.work, &req->w);
  395. /* close the epoch, in case it outgrew the limit */
  396. if (mdev->tconn->newest_tle->n_writes >= mdev->tconn->net_conf->max_epoch_size)
  397. queue_barrier(mdev);
  398. break;
  399. case QUEUE_FOR_SEND_OOS:
  400. req->rq_state |= RQ_NET_QUEUED;
  401. req->w.cb = w_send_oos;
  402. drbd_queue_work(&mdev->tconn->data.work, &req->w);
  403. break;
  404. case OOS_HANDED_TO_NETWORK:
  405. /* actually the same */
  406. case SEND_CANCELED:
  407. /* treat it the same */
  408. case SEND_FAILED:
  409. /* real cleanup will be done from tl_clear. just update flags
  410. * so it is no longer marked as on the worker queue */
  411. req->rq_state &= ~RQ_NET_QUEUED;
  412. /* if we did it right, tl_clear should be scheduled only after
  413. * this, so this should not be necessary! */
  414. _req_may_be_done_not_susp(req, m);
  415. break;
  416. case HANDED_OVER_TO_NETWORK:
  417. /* assert something? */
  418. if (bio_data_dir(req->master_bio) == WRITE)
  419. atomic_add(req->i.size >> 9, &mdev->ap_in_flight);
  420. if (bio_data_dir(req->master_bio) == WRITE &&
  421. mdev->tconn->net_conf->wire_protocol == DRBD_PROT_A) {
  422. /* this is what is dangerous about protocol A:
  423. * pretend it was successfully written on the peer. */
  424. if (req->rq_state & RQ_NET_PENDING) {
  425. dec_ap_pending(mdev);
  426. req->rq_state &= ~RQ_NET_PENDING;
  427. req->rq_state |= RQ_NET_OK;
  428. } /* else: neg-ack was faster... */
  429. /* it is still not yet RQ_NET_DONE until the
  430. * corresponding epoch barrier got acked as well,
  431. * so we know what to dirty on connection loss */
  432. }
  433. req->rq_state &= ~RQ_NET_QUEUED;
  434. req->rq_state |= RQ_NET_SENT;
  435. /* because _drbd_send_zc_bio could sleep, and may want to
  436. * dereference the bio even after the "WRITE_ACKED_BY_PEER" and
  437. * "COMPLETED_OK" events came in, once we return from
  438. * _drbd_send_zc_bio (drbd_send_dblock), we have to check
  439. * whether it is done already, and end it. */
  440. _req_may_be_done_not_susp(req, m);
  441. break;
  442. case READ_RETRY_REMOTE_CANCELED:
  443. req->rq_state &= ~RQ_NET_QUEUED;
  444. /* fall through, in case we raced with drbd_disconnect */
  445. case CONNECTION_LOST_WHILE_PENDING:
  446. /* transfer log cleanup after connection loss */
  447. /* assert something? */
  448. if (req->rq_state & RQ_NET_PENDING)
  449. dec_ap_pending(mdev);
  450. req->rq_state &= ~(RQ_NET_OK|RQ_NET_PENDING);
  451. req->rq_state |= RQ_NET_DONE;
  452. if (req->rq_state & RQ_NET_SENT && req->rq_state & RQ_WRITE)
  453. atomic_sub(req->i.size >> 9, &mdev->ap_in_flight);
  454. /* if it is still queued, we may not complete it here.
  455. * it will be canceled soon. */
  456. if (!(req->rq_state & RQ_NET_QUEUED))
  457. _req_may_be_done(req, m); /* Allowed while state.susp */
  458. break;
  459. case WRITE_ACKED_BY_PEER_AND_SIS:
  460. req->rq_state |= RQ_NET_SIS;
  461. case DISCARD_WRITE:
  462. /* for discarded conflicting writes of multiple primaries,
  463. * there is no need to keep anything in the tl, potential
  464. * node crashes are covered by the activity log. */
  465. req->rq_state |= RQ_NET_DONE;
  466. /* fall through */
  467. case WRITE_ACKED_BY_PEER:
  468. /* protocol C; successfully written on peer.
  469. * Nothing to do here.
  470. * We want to keep the tl in place for all protocols, to cater
  471. * for volatile write-back caches on lower level devices.
  472. *
  473. * A barrier request is expected to have forced all prior
  474. * requests onto stable storage, so completion of a barrier
  475. * request could set NET_DONE right here, and not wait for the
  476. * P_BARRIER_ACK, but that is an unnecessary optimization. */
  477. /* this makes it effectively the same as for: */
  478. case RECV_ACKED_BY_PEER:
  479. /* protocol B; pretends to be successfully written on peer.
  480. * see also notes above in HANDED_OVER_TO_NETWORK about
  481. * protocol != C */
  482. req->rq_state |= RQ_NET_OK;
  483. D_ASSERT(req->rq_state & RQ_NET_PENDING);
  484. dec_ap_pending(mdev);
  485. atomic_sub(req->i.size >> 9, &mdev->ap_in_flight);
  486. req->rq_state &= ~RQ_NET_PENDING;
  487. _req_may_be_done_not_susp(req, m);
  488. break;
  489. case POSTPONE_WRITE:
  490. /*
  491. * If this node has already detected the write conflict, the
  492. * worker will be waiting on misc_wait. Wake it up once this
  493. * request has completed locally.
  494. */
  495. D_ASSERT(req->rq_state & RQ_NET_PENDING);
  496. req->rq_state |= RQ_POSTPONED;
  497. _req_may_be_done_not_susp(req, m);
  498. break;
  499. case NEG_ACKED:
  500. /* assert something? */
  501. if (req->rq_state & RQ_NET_PENDING) {
  502. dec_ap_pending(mdev);
  503. atomic_sub(req->i.size >> 9, &mdev->ap_in_flight);
  504. }
  505. req->rq_state &= ~(RQ_NET_OK|RQ_NET_PENDING);
  506. req->rq_state |= RQ_NET_DONE;
  507. _req_may_be_done_not_susp(req, m);
  508. /* else: done by HANDED_OVER_TO_NETWORK */
  509. break;
  510. case FAIL_FROZEN_DISK_IO:
  511. if (!(req->rq_state & RQ_LOCAL_COMPLETED))
  512. break;
  513. _req_may_be_done(req, m); /* Allowed while state.susp */
  514. break;
  515. case RESTART_FROZEN_DISK_IO:
  516. if (!(req->rq_state & RQ_LOCAL_COMPLETED))
  517. break;
  518. req->rq_state &= ~RQ_LOCAL_COMPLETED;
  519. rv = MR_READ;
  520. if (bio_data_dir(req->master_bio) == WRITE)
  521. rv = MR_WRITE;
  522. get_ldev(mdev);
  523. req->w.cb = w_restart_disk_io;
  524. drbd_queue_work(&mdev->tconn->data.work, &req->w);
  525. break;
  526. case RESEND:
  527. /* If RQ_NET_OK is already set, we got a P_WRITE_ACK or P_RECV_ACK
  528. before the connection loss (B&C only); only P_BARRIER_ACK was missing.
  529. Trowing them out of the TL here by pretending we got a BARRIER_ACK
  530. We ensure that the peer was not rebooted */
  531. if (!(req->rq_state & RQ_NET_OK)) {
  532. if (req->w.cb) {
  533. drbd_queue_work(&mdev->tconn->data.work, &req->w);
  534. rv = req->rq_state & RQ_WRITE ? MR_WRITE : MR_READ;
  535. }
  536. break;
  537. }
  538. /* else, fall through to BARRIER_ACKED */
  539. case BARRIER_ACKED:
  540. if (!(req->rq_state & RQ_WRITE))
  541. break;
  542. if (req->rq_state & RQ_NET_PENDING) {
  543. /* barrier came in before all requests have been acked.
  544. * this is bad, because if the connection is lost now,
  545. * we won't be able to clean them up... */
  546. dev_err(DEV, "FIXME (BARRIER_ACKED but pending)\n");
  547. list_move(&req->tl_requests, &mdev->tconn->out_of_sequence_requests);
  548. }
  549. if ((req->rq_state & RQ_NET_MASK) != 0) {
  550. req->rq_state |= RQ_NET_DONE;
  551. if (mdev->tconn->net_conf->wire_protocol == DRBD_PROT_A)
  552. atomic_sub(req->i.size>>9, &mdev->ap_in_flight);
  553. }
  554. _req_may_be_done(req, m); /* Allowed while state.susp */
  555. break;
  556. case DATA_RECEIVED:
  557. D_ASSERT(req->rq_state & RQ_NET_PENDING);
  558. dec_ap_pending(mdev);
  559. req->rq_state &= ~RQ_NET_PENDING;
  560. req->rq_state |= (RQ_NET_OK|RQ_NET_DONE);
  561. _req_may_be_done_not_susp(req, m);
  562. break;
  563. };
  564. return rv;
  565. }
  566. /* we may do a local read if:
  567. * - we are consistent (of course),
  568. * - or we are generally inconsistent,
  569. * BUT we are still/already IN SYNC for this area.
  570. * since size may be bigger than BM_BLOCK_SIZE,
  571. * we may need to check several bits.
  572. */
  573. static int drbd_may_do_local_read(struct drbd_conf *mdev, sector_t sector, int size)
  574. {
  575. unsigned long sbnr, ebnr;
  576. sector_t esector, nr_sectors;
  577. if (mdev->state.disk == D_UP_TO_DATE)
  578. return 1;
  579. if (mdev->state.disk != D_INCONSISTENT)
  580. return 0;
  581. esector = sector + (size >> 9) - 1;
  582. nr_sectors = drbd_get_capacity(mdev->this_bdev);
  583. D_ASSERT(sector < nr_sectors);
  584. D_ASSERT(esector < nr_sectors);
  585. sbnr = BM_SECT_TO_BIT(sector);
  586. ebnr = BM_SECT_TO_BIT(esector);
  587. return 0 == drbd_bm_count_bits(mdev, sbnr, ebnr);
  588. }
  589. /*
  590. * complete_conflicting_writes - wait for any conflicting write requests
  591. *
  592. * The write_requests tree contains all active write requests which we
  593. * currently know about. Wait for any requests to complete which conflict with
  594. * the new one.
  595. */
  596. static int complete_conflicting_writes(struct drbd_conf *mdev,
  597. sector_t sector, int size)
  598. {
  599. for(;;) {
  600. struct drbd_interval *i;
  601. int err;
  602. i = drbd_find_overlap(&mdev->write_requests, sector, size);
  603. if (!i)
  604. return 0;
  605. err = drbd_wait_misc(mdev, i);
  606. if (err)
  607. return err;
  608. }
  609. }
  610. int __drbd_make_request(struct drbd_conf *mdev, struct bio *bio, unsigned long start_time)
  611. {
  612. const int rw = bio_rw(bio);
  613. const int size = bio->bi_size;
  614. const sector_t sector = bio->bi_sector;
  615. struct drbd_tl_epoch *b = NULL;
  616. struct drbd_request *req;
  617. int local, remote, send_oos = 0;
  618. int err;
  619. int ret = 0;
  620. /* allocate outside of all locks; */
  621. req = drbd_req_new(mdev, bio);
  622. if (!req) {
  623. dec_ap_bio(mdev);
  624. /* only pass the error to the upper layers.
  625. * if user cannot handle io errors, that's not our business. */
  626. dev_err(DEV, "could not kmalloc() req\n");
  627. bio_endio(bio, -ENOMEM);
  628. return 0;
  629. }
  630. req->start_time = start_time;
  631. local = get_ldev(mdev);
  632. if (!local) {
  633. bio_put(req->private_bio); /* or we get a bio leak */
  634. req->private_bio = NULL;
  635. }
  636. if (rw == WRITE) {
  637. remote = 1;
  638. } else {
  639. /* READ || READA */
  640. if (local) {
  641. if (!drbd_may_do_local_read(mdev, sector, size)) {
  642. /* we could kick the syncer to
  643. * sync this extent asap, wait for
  644. * it, then continue locally.
  645. * Or just issue the request remotely.
  646. */
  647. local = 0;
  648. bio_put(req->private_bio);
  649. req->private_bio = NULL;
  650. put_ldev(mdev);
  651. }
  652. }
  653. remote = !local && mdev->state.pdsk >= D_UP_TO_DATE;
  654. }
  655. /* If we have a disk, but a READA request is mapped to remote,
  656. * we are R_PRIMARY, D_INCONSISTENT, SyncTarget.
  657. * Just fail that READA request right here.
  658. *
  659. * THINK: maybe fail all READA when not local?
  660. * or make this configurable...
  661. * if network is slow, READA won't do any good.
  662. */
  663. if (rw == READA && mdev->state.disk >= D_INCONSISTENT && !local) {
  664. err = -EWOULDBLOCK;
  665. goto fail_and_free_req;
  666. }
  667. /* For WRITES going to the local disk, grab a reference on the target
  668. * extent. This waits for any resync activity in the corresponding
  669. * resync extent to finish, and, if necessary, pulls in the target
  670. * extent into the activity log, which involves further disk io because
  671. * of transactional on-disk meta data updates. */
  672. if (rw == WRITE && local && !test_bit(AL_SUSPENDED, &mdev->flags)) {
  673. req->rq_state |= RQ_IN_ACT_LOG;
  674. drbd_al_begin_io(mdev, sector);
  675. }
  676. remote = remote && drbd_should_do_remote(mdev->state);
  677. send_oos = rw == WRITE && drbd_should_send_oos(mdev->state);
  678. D_ASSERT(!(remote && send_oos));
  679. if (!(local || remote) && !is_susp(mdev->state)) {
  680. if (__ratelimit(&drbd_ratelimit_state))
  681. dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
  682. err = -EIO;
  683. goto fail_free_complete;
  684. }
  685. /* For WRITE request, we have to make sure that we have an
  686. * unused_spare_tle, in case we need to start a new epoch.
  687. * I try to be smart and avoid to pre-allocate always "just in case",
  688. * but there is a race between testing the bit and pointer outside the
  689. * spinlock, and grabbing the spinlock.
  690. * if we lost that race, we retry. */
  691. if (rw == WRITE && (remote || send_oos) &&
  692. mdev->tconn->unused_spare_tle == NULL &&
  693. test_bit(CREATE_BARRIER, &mdev->flags)) {
  694. allocate_barrier:
  695. b = kmalloc(sizeof(struct drbd_tl_epoch), GFP_NOIO);
  696. if (!b) {
  697. dev_err(DEV, "Failed to alloc barrier.\n");
  698. err = -ENOMEM;
  699. goto fail_free_complete;
  700. }
  701. }
  702. /* GOOD, everything prepared, grab the spin_lock */
  703. spin_lock_irq(&mdev->tconn->req_lock);
  704. if (rw == WRITE) {
  705. err = complete_conflicting_writes(mdev, sector, size);
  706. if (err) {
  707. if (err != -ERESTARTSYS)
  708. _conn_request_state(mdev->tconn,
  709. NS(conn, C_TIMEOUT),
  710. CS_HARD);
  711. spin_unlock_irq(&mdev->tconn->req_lock);
  712. err = -EIO;
  713. goto fail_free_complete;
  714. }
  715. }
  716. if (is_susp(mdev->state)) {
  717. /* If we got suspended, use the retry mechanism of
  718. generic_make_request() to restart processing of this
  719. bio. In the next call to drbd_make_request
  720. we sleep in inc_ap_bio() */
  721. ret = 1;
  722. spin_unlock_irq(&mdev->tconn->req_lock);
  723. goto fail_free_complete;
  724. }
  725. if (remote || send_oos) {
  726. remote = drbd_should_do_remote(mdev->state);
  727. send_oos = rw == WRITE && drbd_should_send_oos(mdev->state);
  728. D_ASSERT(!(remote && send_oos));
  729. if (!(remote || send_oos))
  730. dev_warn(DEV, "lost connection while grabbing the req_lock!\n");
  731. if (!(local || remote)) {
  732. dev_err(DEV, "IO ERROR: neither local nor remote disk\n");
  733. spin_unlock_irq(&mdev->tconn->req_lock);
  734. err = -EIO;
  735. goto fail_free_complete;
  736. }
  737. }
  738. if (b && mdev->tconn->unused_spare_tle == NULL) {
  739. mdev->tconn->unused_spare_tle = b;
  740. b = NULL;
  741. }
  742. if (rw == WRITE && (remote || send_oos) &&
  743. mdev->tconn->unused_spare_tle == NULL &&
  744. test_bit(CREATE_BARRIER, &mdev->flags)) {
  745. /* someone closed the current epoch
  746. * while we were grabbing the spinlock */
  747. spin_unlock_irq(&mdev->tconn->req_lock);
  748. goto allocate_barrier;
  749. }
  750. /* Update disk stats */
  751. _drbd_start_io_acct(mdev, req, bio);
  752. /* _maybe_start_new_epoch(mdev);
  753. * If we need to generate a write barrier packet, we have to add the
  754. * new epoch (barrier) object, and queue the barrier packet for sending,
  755. * and queue the req's data after it _within the same lock_, otherwise
  756. * we have race conditions were the reorder domains could be mixed up.
  757. *
  758. * Even read requests may start a new epoch and queue the corresponding
  759. * barrier packet. To get the write ordering right, we only have to
  760. * make sure that, if this is a write request and it triggered a
  761. * barrier packet, this request is queued within the same spinlock. */
  762. if ((remote || send_oos) && mdev->tconn->unused_spare_tle &&
  763. test_and_clear_bit(CREATE_BARRIER, &mdev->flags)) {
  764. _tl_add_barrier(mdev, mdev->tconn->unused_spare_tle);
  765. mdev->tconn->unused_spare_tle = NULL;
  766. } else {
  767. D_ASSERT(!(remote && rw == WRITE &&
  768. test_bit(CREATE_BARRIER, &mdev->flags)));
  769. }
  770. /* NOTE
  771. * Actually, 'local' may be wrong here already, since we may have failed
  772. * to write to the meta data, and may become wrong anytime because of
  773. * local io-error for some other request, which would lead to us
  774. * "detaching" the local disk.
  775. *
  776. * 'remote' may become wrong any time because the network could fail.
  777. *
  778. * This is a harmless race condition, though, since it is handled
  779. * correctly at the appropriate places; so it just defers the failure
  780. * of the respective operation.
  781. */
  782. /* mark them early for readability.
  783. * this just sets some state flags. */
  784. if (remote)
  785. _req_mod(req, TO_BE_SENT);
  786. if (local)
  787. _req_mod(req, TO_BE_SUBMITTED);
  788. list_add_tail(&req->tl_requests, &mdev->tconn->newest_tle->requests);
  789. /* NOTE remote first: to get the concurrent write detection right,
  790. * we must register the request before start of local IO. */
  791. if (remote) {
  792. /* either WRITE and C_CONNECTED,
  793. * or READ, and no local disk,
  794. * or READ, but not in sync.
  795. */
  796. _req_mod(req, (rw == WRITE)
  797. ? QUEUE_FOR_NET_WRITE
  798. : QUEUE_FOR_NET_READ);
  799. }
  800. if (send_oos && drbd_set_out_of_sync(mdev, sector, size))
  801. _req_mod(req, QUEUE_FOR_SEND_OOS);
  802. if (remote &&
  803. mdev->tconn->net_conf->on_congestion != OC_BLOCK && mdev->tconn->agreed_pro_version >= 96) {
  804. int congested = 0;
  805. if (mdev->tconn->net_conf->cong_fill &&
  806. atomic_read(&mdev->ap_in_flight) >= mdev->tconn->net_conf->cong_fill) {
  807. dev_info(DEV, "Congestion-fill threshold reached\n");
  808. congested = 1;
  809. }
  810. if (mdev->act_log->used >= mdev->tconn->net_conf->cong_extents) {
  811. dev_info(DEV, "Congestion-extents threshold reached\n");
  812. congested = 1;
  813. }
  814. if (congested) {
  815. queue_barrier(mdev); /* last barrier, after mirrored writes */
  816. if (mdev->tconn->net_conf->on_congestion == OC_PULL_AHEAD)
  817. _drbd_set_state(_NS(mdev, conn, C_AHEAD), 0, NULL);
  818. else /*mdev->tconn->net_conf->on_congestion == OC_DISCONNECT */
  819. _drbd_set_state(_NS(mdev, conn, C_DISCONNECTING), 0, NULL);
  820. }
  821. }
  822. spin_unlock_irq(&mdev->tconn->req_lock);
  823. kfree(b); /* if someone else has beaten us to it... */
  824. if (local) {
  825. req->private_bio->bi_bdev = mdev->ldev->backing_bdev;
  826. /* State may have changed since we grabbed our reference on the
  827. * mdev->ldev member. Double check, and short-circuit to endio.
  828. * In case the last activity log transaction failed to get on
  829. * stable storage, and this is a WRITE, we may not even submit
  830. * this bio. */
  831. if (get_ldev(mdev)) {
  832. if (drbd_insert_fault(mdev, rw == WRITE ? DRBD_FAULT_DT_WR
  833. : rw == READ ? DRBD_FAULT_DT_RD
  834. : DRBD_FAULT_DT_RA))
  835. bio_endio(req->private_bio, -EIO);
  836. else
  837. generic_make_request(req->private_bio);
  838. put_ldev(mdev);
  839. } else
  840. bio_endio(req->private_bio, -EIO);
  841. }
  842. return 0;
  843. fail_free_complete:
  844. if (req->rq_state & RQ_IN_ACT_LOG)
  845. drbd_al_complete_io(mdev, sector);
  846. fail_and_free_req:
  847. if (local) {
  848. bio_put(req->private_bio);
  849. req->private_bio = NULL;
  850. put_ldev(mdev);
  851. }
  852. if (!ret)
  853. bio_endio(bio, err);
  854. drbd_req_free(req);
  855. dec_ap_bio(mdev);
  856. kfree(b);
  857. return ret;
  858. }
  859. /* helper function for drbd_make_request
  860. * if we can determine just by the mdev (state) that this request will fail,
  861. * return 1
  862. * otherwise return 0
  863. */
  864. static int drbd_fail_request_early(struct drbd_conf *mdev, int is_write)
  865. {
  866. if (mdev->state.role != R_PRIMARY &&
  867. (!allow_oos || is_write)) {
  868. if (__ratelimit(&drbd_ratelimit_state)) {
  869. dev_err(DEV, "Process %s[%u] tried to %s; "
  870. "since we are not in Primary state, "
  871. "we cannot allow this\n",
  872. current->comm, current->pid,
  873. is_write ? "WRITE" : "READ");
  874. }
  875. return 1;
  876. }
  877. return 0;
  878. }
  879. int drbd_make_request(struct request_queue *q, struct bio *bio)
  880. {
  881. unsigned int s_enr, e_enr;
  882. struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
  883. unsigned long start_time;
  884. if (drbd_fail_request_early(mdev, bio_data_dir(bio) & WRITE)) {
  885. bio_endio(bio, -EPERM);
  886. return 0;
  887. }
  888. start_time = jiffies;
  889. /*
  890. * what we "blindly" assume:
  891. */
  892. D_ASSERT(bio->bi_size > 0);
  893. D_ASSERT(IS_ALIGNED(bio->bi_size, 512));
  894. D_ASSERT(bio->bi_idx == 0);
  895. /* to make some things easier, force alignment of requests within the
  896. * granularity of our hash tables */
  897. s_enr = bio->bi_sector >> HT_SHIFT;
  898. e_enr = (bio->bi_sector+(bio->bi_size>>9)-1) >> HT_SHIFT;
  899. if (likely(s_enr == e_enr)) {
  900. inc_ap_bio(mdev, 1);
  901. return __drbd_make_request(mdev, bio, start_time);
  902. }
  903. /* can this bio be split generically?
  904. * Maybe add our own split-arbitrary-bios function. */
  905. if (bio->bi_vcnt != 1 || bio->bi_idx != 0 || bio->bi_size > DRBD_MAX_BIO_SIZE) {
  906. /* rather error out here than BUG in bio_split */
  907. dev_err(DEV, "bio would need to, but cannot, be split: "
  908. "(vcnt=%u,idx=%u,size=%u,sector=%llu)\n",
  909. bio->bi_vcnt, bio->bi_idx, bio->bi_size,
  910. (unsigned long long)bio->bi_sector);
  911. bio_endio(bio, -EINVAL);
  912. } else {
  913. /* This bio crosses some boundary, so we have to split it. */
  914. struct bio_pair *bp;
  915. /* works for the "do not cross hash slot boundaries" case
  916. * e.g. sector 262269, size 4096
  917. * s_enr = 262269 >> 6 = 4097
  918. * e_enr = (262269+8-1) >> 6 = 4098
  919. * HT_SHIFT = 6
  920. * sps = 64, mask = 63
  921. * first_sectors = 64 - (262269 & 63) = 3
  922. */
  923. const sector_t sect = bio->bi_sector;
  924. const int sps = 1 << HT_SHIFT; /* sectors per slot */
  925. const int mask = sps - 1;
  926. const sector_t first_sectors = sps - (sect & mask);
  927. bp = bio_split(bio, first_sectors);
  928. /* we need to get a "reference count" (ap_bio_cnt)
  929. * to avoid races with the disconnect/reconnect/suspend code.
  930. * In case we need to split the bio here, we need to get three references
  931. * atomically, otherwise we might deadlock when trying to submit the
  932. * second one! */
  933. inc_ap_bio(mdev, 3);
  934. D_ASSERT(e_enr == s_enr + 1);
  935. while (__drbd_make_request(mdev, &bp->bio1, start_time))
  936. inc_ap_bio(mdev, 1);
  937. while (__drbd_make_request(mdev, &bp->bio2, start_time))
  938. inc_ap_bio(mdev, 1);
  939. dec_ap_bio(mdev);
  940. bio_pair_release(bp);
  941. }
  942. return 0;
  943. }
  944. /* This is called by bio_add_page(). With this function we reduce
  945. * the number of BIOs that span over multiple DRBD_MAX_BIO_SIZEs
  946. * units (was AL_EXTENTs).
  947. *
  948. * we do the calculation within the lower 32bit of the byte offsets,
  949. * since we don't care for actual offset, but only check whether it
  950. * would cross "activity log extent" boundaries.
  951. *
  952. * As long as the BIO is empty we have to allow at least one bvec,
  953. * regardless of size and offset. so the resulting bio may still
  954. * cross extent boundaries. those are dealt with (bio_split) in
  955. * drbd_make_request.
  956. */
  957. int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec)
  958. {
  959. struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
  960. unsigned int bio_offset =
  961. (unsigned int)bvm->bi_sector << 9; /* 32 bit */
  962. unsigned int bio_size = bvm->bi_size;
  963. int limit, backing_limit;
  964. limit = DRBD_MAX_BIO_SIZE
  965. - ((bio_offset & (DRBD_MAX_BIO_SIZE-1)) + bio_size);
  966. if (limit < 0)
  967. limit = 0;
  968. if (bio_size == 0) {
  969. if (limit <= bvec->bv_len)
  970. limit = bvec->bv_len;
  971. } else if (limit && get_ldev(mdev)) {
  972. struct request_queue * const b =
  973. mdev->ldev->backing_bdev->bd_disk->queue;
  974. if (b->merge_bvec_fn) {
  975. backing_limit = b->merge_bvec_fn(b, bvm, bvec);
  976. limit = min(limit, backing_limit);
  977. }
  978. put_ldev(mdev);
  979. }
  980. return limit;
  981. }
  982. void request_timer_fn(unsigned long data)
  983. {
  984. struct drbd_conf *mdev = (struct drbd_conf *) data;
  985. struct drbd_request *req; /* oldest request */
  986. struct list_head *le;
  987. unsigned long et = 0; /* effective timeout = ko_count * timeout */
  988. if (get_net_conf(mdev->tconn)) {
  989. et = mdev->tconn->net_conf->timeout*HZ/10 * mdev->tconn->net_conf->ko_count;
  990. put_net_conf(mdev->tconn);
  991. }
  992. if (!et || mdev->state.conn < C_WF_REPORT_PARAMS)
  993. return; /* Recurring timer stopped */
  994. spin_lock_irq(&mdev->tconn->req_lock);
  995. le = &mdev->tconn->oldest_tle->requests;
  996. if (list_empty(le)) {
  997. spin_unlock_irq(&mdev->tconn->req_lock);
  998. mod_timer(&mdev->request_timer, jiffies + et);
  999. return;
  1000. }
  1001. le = le->prev;
  1002. req = list_entry(le, struct drbd_request, tl_requests);
  1003. if (time_is_before_eq_jiffies(req->start_time + et)) {
  1004. if (req->rq_state & RQ_NET_PENDING) {
  1005. dev_warn(DEV, "Remote failed to finish a request within ko-count * timeout\n");
  1006. _drbd_set_state(_NS(mdev, conn, C_TIMEOUT), CS_VERBOSE, NULL);
  1007. } else {
  1008. dev_warn(DEV, "Local backing block device frozen?\n");
  1009. mod_timer(&mdev->request_timer, jiffies + et);
  1010. }
  1011. } else {
  1012. mod_timer(&mdev->request_timer, req->start_time + et);
  1013. }
  1014. spin_unlock_irq(&mdev->tconn->req_lock);
  1015. }