drbd_req.c 35 KB

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