send.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /*
  2. * Copyright (c) 2006 Oracle. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/gfp.h>
  36. #include <net/sock.h>
  37. #include <linux/in.h>
  38. #include <linux/list.h>
  39. #include <linux/ratelimit.h>
  40. #include <linux/export.h>
  41. #include <linux/sizes.h>
  42. #include "rds.h"
  43. /* When transmitting messages in rds_send_xmit, we need to emerge from
  44. * time to time and briefly release the CPU. Otherwise the softlock watchdog
  45. * will kick our shin.
  46. * Also, it seems fairer to not let one busy connection stall all the
  47. * others.
  48. *
  49. * send_batch_count is the number of times we'll loop in send_xmit. Setting
  50. * it to 0 will restore the old behavior (where we looped until we had
  51. * drained the queue).
  52. */
  53. static int send_batch_count = SZ_1K;
  54. module_param(send_batch_count, int, 0444);
  55. MODULE_PARM_DESC(send_batch_count, " batch factor when working the send queue");
  56. static void rds_send_remove_from_sock(struct list_head *messages, int status);
  57. /*
  58. * Reset the send state. Callers must ensure that this doesn't race with
  59. * rds_send_xmit().
  60. */
  61. void rds_send_path_reset(struct rds_conn_path *cp)
  62. {
  63. struct rds_message *rm, *tmp;
  64. unsigned long flags;
  65. if (cp->cp_xmit_rm) {
  66. rm = cp->cp_xmit_rm;
  67. cp->cp_xmit_rm = NULL;
  68. /* Tell the user the RDMA op is no longer mapped by the
  69. * transport. This isn't entirely true (it's flushed out
  70. * independently) but as the connection is down, there's
  71. * no ongoing RDMA to/from that memory */
  72. rds_message_unmapped(rm);
  73. rds_message_put(rm);
  74. }
  75. cp->cp_xmit_sg = 0;
  76. cp->cp_xmit_hdr_off = 0;
  77. cp->cp_xmit_data_off = 0;
  78. cp->cp_xmit_atomic_sent = 0;
  79. cp->cp_xmit_rdma_sent = 0;
  80. cp->cp_xmit_data_sent = 0;
  81. cp->cp_conn->c_map_queued = 0;
  82. cp->cp_unacked_packets = rds_sysctl_max_unacked_packets;
  83. cp->cp_unacked_bytes = rds_sysctl_max_unacked_bytes;
  84. /* Mark messages as retransmissions, and move them to the send q */
  85. spin_lock_irqsave(&cp->cp_lock, flags);
  86. list_for_each_entry_safe(rm, tmp, &cp->cp_retrans, m_conn_item) {
  87. set_bit(RDS_MSG_ACK_REQUIRED, &rm->m_flags);
  88. set_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags);
  89. }
  90. list_splice_init(&cp->cp_retrans, &cp->cp_send_queue);
  91. spin_unlock_irqrestore(&cp->cp_lock, flags);
  92. }
  93. EXPORT_SYMBOL_GPL(rds_send_path_reset);
  94. static int acquire_in_xmit(struct rds_conn_path *cp)
  95. {
  96. return test_and_set_bit(RDS_IN_XMIT, &cp->cp_flags) == 0;
  97. }
  98. static void release_in_xmit(struct rds_conn_path *cp)
  99. {
  100. clear_bit(RDS_IN_XMIT, &cp->cp_flags);
  101. smp_mb__after_atomic();
  102. /*
  103. * We don't use wait_on_bit()/wake_up_bit() because our waking is in a
  104. * hot path and finding waiters is very rare. We don't want to walk
  105. * the system-wide hashed waitqueue buckets in the fast path only to
  106. * almost never find waiters.
  107. */
  108. if (waitqueue_active(&cp->cp_waitq))
  109. wake_up_all(&cp->cp_waitq);
  110. }
  111. /*
  112. * We're making the conscious trade-off here to only send one message
  113. * down the connection at a time.
  114. * Pro:
  115. * - tx queueing is a simple fifo list
  116. * - reassembly is optional and easily done by transports per conn
  117. * - no per flow rx lookup at all, straight to the socket
  118. * - less per-frag memory and wire overhead
  119. * Con:
  120. * - queued acks can be delayed behind large messages
  121. * Depends:
  122. * - small message latency is higher behind queued large messages
  123. * - large message latency isn't starved by intervening small sends
  124. */
  125. int rds_send_xmit(struct rds_conn_path *cp)
  126. {
  127. struct rds_connection *conn = cp->cp_conn;
  128. struct rds_message *rm;
  129. unsigned long flags;
  130. unsigned int tmp;
  131. struct scatterlist *sg;
  132. int ret = 0;
  133. LIST_HEAD(to_be_dropped);
  134. int batch_count;
  135. unsigned long send_gen = 0;
  136. restart:
  137. batch_count = 0;
  138. /*
  139. * sendmsg calls here after having queued its message on the send
  140. * queue. We only have one task feeding the connection at a time. If
  141. * another thread is already feeding the queue then we back off. This
  142. * avoids blocking the caller and trading per-connection data between
  143. * caches per message.
  144. */
  145. if (!acquire_in_xmit(cp)) {
  146. rds_stats_inc(s_send_lock_contention);
  147. ret = -ENOMEM;
  148. goto out;
  149. }
  150. /*
  151. * we record the send generation after doing the xmit acquire.
  152. * if someone else manages to jump in and do some work, we'll use
  153. * this to avoid a goto restart farther down.
  154. *
  155. * The acquire_in_xmit() check above ensures that only one
  156. * caller can increment c_send_gen at any time.
  157. */
  158. cp->cp_send_gen++;
  159. send_gen = cp->cp_send_gen;
  160. /*
  161. * rds_conn_shutdown() sets the conn state and then tests RDS_IN_XMIT,
  162. * we do the opposite to avoid races.
  163. */
  164. if (!rds_conn_path_up(cp)) {
  165. release_in_xmit(cp);
  166. ret = 0;
  167. goto out;
  168. }
  169. if (conn->c_trans->xmit_path_prepare)
  170. conn->c_trans->xmit_path_prepare(cp);
  171. /*
  172. * spin trying to push headers and data down the connection until
  173. * the connection doesn't make forward progress.
  174. */
  175. while (1) {
  176. rm = cp->cp_xmit_rm;
  177. /*
  178. * If between sending messages, we can send a pending congestion
  179. * map update.
  180. */
  181. if (!rm && test_and_clear_bit(0, &conn->c_map_queued)) {
  182. rm = rds_cong_update_alloc(conn);
  183. if (IS_ERR(rm)) {
  184. ret = PTR_ERR(rm);
  185. break;
  186. }
  187. rm->data.op_active = 1;
  188. rm->m_inc.i_conn_path = cp;
  189. rm->m_inc.i_conn = cp->cp_conn;
  190. cp->cp_xmit_rm = rm;
  191. }
  192. /*
  193. * If not already working on one, grab the next message.
  194. *
  195. * cp_xmit_rm holds a ref while we're sending this message down
  196. * the connction. We can use this ref while holding the
  197. * send_sem.. rds_send_reset() is serialized with it.
  198. */
  199. if (!rm) {
  200. unsigned int len;
  201. batch_count++;
  202. /* we want to process as big a batch as we can, but
  203. * we also want to avoid softlockups. If we've been
  204. * through a lot of messages, lets back off and see
  205. * if anyone else jumps in
  206. */
  207. if (batch_count >= send_batch_count)
  208. goto over_batch;
  209. spin_lock_irqsave(&cp->cp_lock, flags);
  210. if (!list_empty(&cp->cp_send_queue)) {
  211. rm = list_entry(cp->cp_send_queue.next,
  212. struct rds_message,
  213. m_conn_item);
  214. rds_message_addref(rm);
  215. /*
  216. * Move the message from the send queue to the retransmit
  217. * list right away.
  218. */
  219. list_move_tail(&rm->m_conn_item,
  220. &cp->cp_retrans);
  221. }
  222. spin_unlock_irqrestore(&cp->cp_lock, flags);
  223. if (!rm)
  224. break;
  225. /* Unfortunately, the way Infiniband deals with
  226. * RDMA to a bad MR key is by moving the entire
  227. * queue pair to error state. We cold possibly
  228. * recover from that, but right now we drop the
  229. * connection.
  230. * Therefore, we never retransmit messages with RDMA ops.
  231. */
  232. if (test_bit(RDS_MSG_FLUSH, &rm->m_flags) ||
  233. (rm->rdma.op_active &&
  234. test_bit(RDS_MSG_RETRANSMITTED, &rm->m_flags))) {
  235. spin_lock_irqsave(&cp->cp_lock, flags);
  236. if (test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags))
  237. list_move(&rm->m_conn_item, &to_be_dropped);
  238. spin_unlock_irqrestore(&cp->cp_lock, flags);
  239. continue;
  240. }
  241. /* Require an ACK every once in a while */
  242. len = ntohl(rm->m_inc.i_hdr.h_len);
  243. if (cp->cp_unacked_packets == 0 ||
  244. cp->cp_unacked_bytes < len) {
  245. __set_bit(RDS_MSG_ACK_REQUIRED, &rm->m_flags);
  246. cp->cp_unacked_packets =
  247. rds_sysctl_max_unacked_packets;
  248. cp->cp_unacked_bytes =
  249. rds_sysctl_max_unacked_bytes;
  250. rds_stats_inc(s_send_ack_required);
  251. } else {
  252. cp->cp_unacked_bytes -= len;
  253. cp->cp_unacked_packets--;
  254. }
  255. cp->cp_xmit_rm = rm;
  256. }
  257. /* The transport either sends the whole rdma or none of it */
  258. if (rm->rdma.op_active && !cp->cp_xmit_rdma_sent) {
  259. rm->m_final_op = &rm->rdma;
  260. /* The transport owns the mapped memory for now.
  261. * You can't unmap it while it's on the send queue
  262. */
  263. set_bit(RDS_MSG_MAPPED, &rm->m_flags);
  264. ret = conn->c_trans->xmit_rdma(conn, &rm->rdma);
  265. if (ret) {
  266. clear_bit(RDS_MSG_MAPPED, &rm->m_flags);
  267. wake_up_interruptible(&rm->m_flush_wait);
  268. break;
  269. }
  270. cp->cp_xmit_rdma_sent = 1;
  271. }
  272. if (rm->atomic.op_active && !cp->cp_xmit_atomic_sent) {
  273. rm->m_final_op = &rm->atomic;
  274. /* The transport owns the mapped memory for now.
  275. * You can't unmap it while it's on the send queue
  276. */
  277. set_bit(RDS_MSG_MAPPED, &rm->m_flags);
  278. ret = conn->c_trans->xmit_atomic(conn, &rm->atomic);
  279. if (ret) {
  280. clear_bit(RDS_MSG_MAPPED, &rm->m_flags);
  281. wake_up_interruptible(&rm->m_flush_wait);
  282. break;
  283. }
  284. cp->cp_xmit_atomic_sent = 1;
  285. }
  286. /*
  287. * A number of cases require an RDS header to be sent
  288. * even if there is no data.
  289. * We permit 0-byte sends; rds-ping depends on this.
  290. * However, if there are exclusively attached silent ops,
  291. * we skip the hdr/data send, to enable silent operation.
  292. */
  293. if (rm->data.op_nents == 0) {
  294. int ops_present;
  295. int all_ops_are_silent = 1;
  296. ops_present = (rm->atomic.op_active || rm->rdma.op_active);
  297. if (rm->atomic.op_active && !rm->atomic.op_silent)
  298. all_ops_are_silent = 0;
  299. if (rm->rdma.op_active && !rm->rdma.op_silent)
  300. all_ops_are_silent = 0;
  301. if (ops_present && all_ops_are_silent
  302. && !rm->m_rdma_cookie)
  303. rm->data.op_active = 0;
  304. }
  305. if (rm->data.op_active && !cp->cp_xmit_data_sent) {
  306. rm->m_final_op = &rm->data;
  307. ret = conn->c_trans->xmit(conn, rm,
  308. cp->cp_xmit_hdr_off,
  309. cp->cp_xmit_sg,
  310. cp->cp_xmit_data_off);
  311. if (ret <= 0)
  312. break;
  313. if (cp->cp_xmit_hdr_off < sizeof(struct rds_header)) {
  314. tmp = min_t(int, ret,
  315. sizeof(struct rds_header) -
  316. cp->cp_xmit_hdr_off);
  317. cp->cp_xmit_hdr_off += tmp;
  318. ret -= tmp;
  319. }
  320. sg = &rm->data.op_sg[cp->cp_xmit_sg];
  321. while (ret) {
  322. tmp = min_t(int, ret, sg->length -
  323. cp->cp_xmit_data_off);
  324. cp->cp_xmit_data_off += tmp;
  325. ret -= tmp;
  326. if (cp->cp_xmit_data_off == sg->length) {
  327. cp->cp_xmit_data_off = 0;
  328. sg++;
  329. cp->cp_xmit_sg++;
  330. BUG_ON(ret != 0 && cp->cp_xmit_sg ==
  331. rm->data.op_nents);
  332. }
  333. }
  334. if (cp->cp_xmit_hdr_off == sizeof(struct rds_header) &&
  335. (cp->cp_xmit_sg == rm->data.op_nents))
  336. cp->cp_xmit_data_sent = 1;
  337. }
  338. /*
  339. * A rm will only take multiple times through this loop
  340. * if there is a data op. Thus, if the data is sent (or there was
  341. * none), then we're done with the rm.
  342. */
  343. if (!rm->data.op_active || cp->cp_xmit_data_sent) {
  344. cp->cp_xmit_rm = NULL;
  345. cp->cp_xmit_sg = 0;
  346. cp->cp_xmit_hdr_off = 0;
  347. cp->cp_xmit_data_off = 0;
  348. cp->cp_xmit_rdma_sent = 0;
  349. cp->cp_xmit_atomic_sent = 0;
  350. cp->cp_xmit_data_sent = 0;
  351. rds_message_put(rm);
  352. }
  353. }
  354. over_batch:
  355. if (conn->c_trans->xmit_path_complete)
  356. conn->c_trans->xmit_path_complete(cp);
  357. release_in_xmit(cp);
  358. /* Nuke any messages we decided not to retransmit. */
  359. if (!list_empty(&to_be_dropped)) {
  360. /* irqs on here, so we can put(), unlike above */
  361. list_for_each_entry(rm, &to_be_dropped, m_conn_item)
  362. rds_message_put(rm);
  363. rds_send_remove_from_sock(&to_be_dropped, RDS_RDMA_DROPPED);
  364. }
  365. /*
  366. * Other senders can queue a message after we last test the send queue
  367. * but before we clear RDS_IN_XMIT. In that case they'd back off and
  368. * not try and send their newly queued message. We need to check the
  369. * send queue after having cleared RDS_IN_XMIT so that their message
  370. * doesn't get stuck on the send queue.
  371. *
  372. * If the transport cannot continue (i.e ret != 0), then it must
  373. * call us when more room is available, such as from the tx
  374. * completion handler.
  375. *
  376. * We have an extra generation check here so that if someone manages
  377. * to jump in after our release_in_xmit, we'll see that they have done
  378. * some work and we will skip our goto
  379. */
  380. if (ret == 0) {
  381. smp_mb();
  382. if ((test_bit(0, &conn->c_map_queued) ||
  383. !list_empty(&cp->cp_send_queue)) &&
  384. send_gen == cp->cp_send_gen) {
  385. rds_stats_inc(s_send_lock_queue_raced);
  386. if (batch_count < send_batch_count)
  387. goto restart;
  388. queue_delayed_work(rds_wq, &cp->cp_send_w, 1);
  389. }
  390. }
  391. out:
  392. return ret;
  393. }
  394. EXPORT_SYMBOL_GPL(rds_send_xmit);
  395. static void rds_send_sndbuf_remove(struct rds_sock *rs, struct rds_message *rm)
  396. {
  397. u32 len = be32_to_cpu(rm->m_inc.i_hdr.h_len);
  398. assert_spin_locked(&rs->rs_lock);
  399. BUG_ON(rs->rs_snd_bytes < len);
  400. rs->rs_snd_bytes -= len;
  401. if (rs->rs_snd_bytes == 0)
  402. rds_stats_inc(s_send_queue_empty);
  403. }
  404. static inline int rds_send_is_acked(struct rds_message *rm, u64 ack,
  405. is_acked_func is_acked)
  406. {
  407. if (is_acked)
  408. return is_acked(rm, ack);
  409. return be64_to_cpu(rm->m_inc.i_hdr.h_sequence) <= ack;
  410. }
  411. /*
  412. * This is pretty similar to what happens below in the ACK
  413. * handling code - except that we call here as soon as we get
  414. * the IB send completion on the RDMA op and the accompanying
  415. * message.
  416. */
  417. void rds_rdma_send_complete(struct rds_message *rm, int status)
  418. {
  419. struct rds_sock *rs = NULL;
  420. struct rm_rdma_op *ro;
  421. struct rds_notifier *notifier;
  422. unsigned long flags;
  423. spin_lock_irqsave(&rm->m_rs_lock, flags);
  424. ro = &rm->rdma;
  425. if (test_bit(RDS_MSG_ON_SOCK, &rm->m_flags) &&
  426. ro->op_active && ro->op_notify && ro->op_notifier) {
  427. notifier = ro->op_notifier;
  428. rs = rm->m_rs;
  429. sock_hold(rds_rs_to_sk(rs));
  430. notifier->n_status = status;
  431. spin_lock(&rs->rs_lock);
  432. list_add_tail(&notifier->n_list, &rs->rs_notify_queue);
  433. spin_unlock(&rs->rs_lock);
  434. ro->op_notifier = NULL;
  435. }
  436. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  437. if (rs) {
  438. rds_wake_sk_sleep(rs);
  439. sock_put(rds_rs_to_sk(rs));
  440. }
  441. }
  442. EXPORT_SYMBOL_GPL(rds_rdma_send_complete);
  443. /*
  444. * Just like above, except looks at atomic op
  445. */
  446. void rds_atomic_send_complete(struct rds_message *rm, int status)
  447. {
  448. struct rds_sock *rs = NULL;
  449. struct rm_atomic_op *ao;
  450. struct rds_notifier *notifier;
  451. unsigned long flags;
  452. spin_lock_irqsave(&rm->m_rs_lock, flags);
  453. ao = &rm->atomic;
  454. if (test_bit(RDS_MSG_ON_SOCK, &rm->m_flags)
  455. && ao->op_active && ao->op_notify && ao->op_notifier) {
  456. notifier = ao->op_notifier;
  457. rs = rm->m_rs;
  458. sock_hold(rds_rs_to_sk(rs));
  459. notifier->n_status = status;
  460. spin_lock(&rs->rs_lock);
  461. list_add_tail(&notifier->n_list, &rs->rs_notify_queue);
  462. spin_unlock(&rs->rs_lock);
  463. ao->op_notifier = NULL;
  464. }
  465. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  466. if (rs) {
  467. rds_wake_sk_sleep(rs);
  468. sock_put(rds_rs_to_sk(rs));
  469. }
  470. }
  471. EXPORT_SYMBOL_GPL(rds_atomic_send_complete);
  472. /*
  473. * This is the same as rds_rdma_send_complete except we
  474. * don't do any locking - we have all the ingredients (message,
  475. * socket, socket lock) and can just move the notifier.
  476. */
  477. static inline void
  478. __rds_send_complete(struct rds_sock *rs, struct rds_message *rm, int status)
  479. {
  480. struct rm_rdma_op *ro;
  481. struct rm_atomic_op *ao;
  482. ro = &rm->rdma;
  483. if (ro->op_active && ro->op_notify && ro->op_notifier) {
  484. ro->op_notifier->n_status = status;
  485. list_add_tail(&ro->op_notifier->n_list, &rs->rs_notify_queue);
  486. ro->op_notifier = NULL;
  487. }
  488. ao = &rm->atomic;
  489. if (ao->op_active && ao->op_notify && ao->op_notifier) {
  490. ao->op_notifier->n_status = status;
  491. list_add_tail(&ao->op_notifier->n_list, &rs->rs_notify_queue);
  492. ao->op_notifier = NULL;
  493. }
  494. /* No need to wake the app - caller does this */
  495. }
  496. /*
  497. * This removes messages from the socket's list if they're on it. The list
  498. * argument must be private to the caller, we must be able to modify it
  499. * without locks. The messages must have a reference held for their
  500. * position on the list. This function will drop that reference after
  501. * removing the messages from the 'messages' list regardless of if it found
  502. * the messages on the socket list or not.
  503. */
  504. static void rds_send_remove_from_sock(struct list_head *messages, int status)
  505. {
  506. unsigned long flags;
  507. struct rds_sock *rs = NULL;
  508. struct rds_message *rm;
  509. while (!list_empty(messages)) {
  510. int was_on_sock = 0;
  511. rm = list_entry(messages->next, struct rds_message,
  512. m_conn_item);
  513. list_del_init(&rm->m_conn_item);
  514. /*
  515. * If we see this flag cleared then we're *sure* that someone
  516. * else beat us to removing it from the sock. If we race
  517. * with their flag update we'll get the lock and then really
  518. * see that the flag has been cleared.
  519. *
  520. * The message spinlock makes sure nobody clears rm->m_rs
  521. * while we're messing with it. It does not prevent the
  522. * message from being removed from the socket, though.
  523. */
  524. spin_lock_irqsave(&rm->m_rs_lock, flags);
  525. if (!test_bit(RDS_MSG_ON_SOCK, &rm->m_flags))
  526. goto unlock_and_drop;
  527. if (rs != rm->m_rs) {
  528. if (rs) {
  529. rds_wake_sk_sleep(rs);
  530. sock_put(rds_rs_to_sk(rs));
  531. }
  532. rs = rm->m_rs;
  533. if (rs)
  534. sock_hold(rds_rs_to_sk(rs));
  535. }
  536. if (!rs)
  537. goto unlock_and_drop;
  538. spin_lock(&rs->rs_lock);
  539. if (test_and_clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags)) {
  540. struct rm_rdma_op *ro = &rm->rdma;
  541. struct rds_notifier *notifier;
  542. list_del_init(&rm->m_sock_item);
  543. rds_send_sndbuf_remove(rs, rm);
  544. if (ro->op_active && ro->op_notifier &&
  545. (ro->op_notify || (ro->op_recverr && status))) {
  546. notifier = ro->op_notifier;
  547. list_add_tail(&notifier->n_list,
  548. &rs->rs_notify_queue);
  549. if (!notifier->n_status)
  550. notifier->n_status = status;
  551. rm->rdma.op_notifier = NULL;
  552. }
  553. was_on_sock = 1;
  554. rm->m_rs = NULL;
  555. }
  556. spin_unlock(&rs->rs_lock);
  557. unlock_and_drop:
  558. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  559. rds_message_put(rm);
  560. if (was_on_sock)
  561. rds_message_put(rm);
  562. }
  563. if (rs) {
  564. rds_wake_sk_sleep(rs);
  565. sock_put(rds_rs_to_sk(rs));
  566. }
  567. }
  568. /*
  569. * Transports call here when they've determined that the receiver queued
  570. * messages up to, and including, the given sequence number. Messages are
  571. * moved to the retrans queue when rds_send_xmit picks them off the send
  572. * queue. This means that in the TCP case, the message may not have been
  573. * assigned the m_ack_seq yet - but that's fine as long as tcp_is_acked
  574. * checks the RDS_MSG_HAS_ACK_SEQ bit.
  575. */
  576. void rds_send_path_drop_acked(struct rds_conn_path *cp, u64 ack,
  577. is_acked_func is_acked)
  578. {
  579. struct rds_message *rm, *tmp;
  580. unsigned long flags;
  581. LIST_HEAD(list);
  582. spin_lock_irqsave(&cp->cp_lock, flags);
  583. list_for_each_entry_safe(rm, tmp, &cp->cp_retrans, m_conn_item) {
  584. if (!rds_send_is_acked(rm, ack, is_acked))
  585. break;
  586. list_move(&rm->m_conn_item, &list);
  587. clear_bit(RDS_MSG_ON_CONN, &rm->m_flags);
  588. }
  589. /* order flag updates with spin locks */
  590. if (!list_empty(&list))
  591. smp_mb__after_atomic();
  592. spin_unlock_irqrestore(&cp->cp_lock, flags);
  593. /* now remove the messages from the sock list as needed */
  594. rds_send_remove_from_sock(&list, RDS_RDMA_SUCCESS);
  595. }
  596. EXPORT_SYMBOL_GPL(rds_send_path_drop_acked);
  597. void rds_send_drop_acked(struct rds_connection *conn, u64 ack,
  598. is_acked_func is_acked)
  599. {
  600. WARN_ON(conn->c_trans->t_mp_capable);
  601. rds_send_path_drop_acked(&conn->c_path[0], ack, is_acked);
  602. }
  603. EXPORT_SYMBOL_GPL(rds_send_drop_acked);
  604. void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
  605. {
  606. struct rds_message *rm, *tmp;
  607. struct rds_connection *conn;
  608. struct rds_conn_path *cp;
  609. unsigned long flags;
  610. LIST_HEAD(list);
  611. /* get all the messages we're dropping under the rs lock */
  612. spin_lock_irqsave(&rs->rs_lock, flags);
  613. list_for_each_entry_safe(rm, tmp, &rs->rs_send_queue, m_sock_item) {
  614. if (dest && (dest->sin_addr.s_addr != rm->m_daddr ||
  615. dest->sin_port != rm->m_inc.i_hdr.h_dport))
  616. continue;
  617. list_move(&rm->m_sock_item, &list);
  618. rds_send_sndbuf_remove(rs, rm);
  619. clear_bit(RDS_MSG_ON_SOCK, &rm->m_flags);
  620. }
  621. /* order flag updates with the rs lock */
  622. smp_mb__after_atomic();
  623. spin_unlock_irqrestore(&rs->rs_lock, flags);
  624. if (list_empty(&list))
  625. return;
  626. /* Remove the messages from the conn */
  627. list_for_each_entry(rm, &list, m_sock_item) {
  628. conn = rm->m_inc.i_conn;
  629. if (conn->c_trans->t_mp_capable)
  630. cp = rm->m_inc.i_conn_path;
  631. else
  632. cp = &conn->c_path[0];
  633. spin_lock_irqsave(&cp->cp_lock, flags);
  634. /*
  635. * Maybe someone else beat us to removing rm from the conn.
  636. * If we race with their flag update we'll get the lock and
  637. * then really see that the flag has been cleared.
  638. */
  639. if (!test_and_clear_bit(RDS_MSG_ON_CONN, &rm->m_flags)) {
  640. spin_unlock_irqrestore(&cp->cp_lock, flags);
  641. spin_lock_irqsave(&rm->m_rs_lock, flags);
  642. rm->m_rs = NULL;
  643. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  644. continue;
  645. }
  646. list_del_init(&rm->m_conn_item);
  647. spin_unlock_irqrestore(&cp->cp_lock, flags);
  648. /*
  649. * Couldn't grab m_rs_lock in top loop (lock ordering),
  650. * but we can now.
  651. */
  652. spin_lock_irqsave(&rm->m_rs_lock, flags);
  653. spin_lock(&rs->rs_lock);
  654. __rds_send_complete(rs, rm, RDS_RDMA_CANCELED);
  655. spin_unlock(&rs->rs_lock);
  656. rm->m_rs = NULL;
  657. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  658. rds_message_put(rm);
  659. }
  660. rds_wake_sk_sleep(rs);
  661. while (!list_empty(&list)) {
  662. rm = list_entry(list.next, struct rds_message, m_sock_item);
  663. list_del_init(&rm->m_sock_item);
  664. rds_message_wait(rm);
  665. /* just in case the code above skipped this message
  666. * because RDS_MSG_ON_CONN wasn't set, run it again here
  667. * taking m_rs_lock is the only thing that keeps us
  668. * from racing with ack processing.
  669. */
  670. spin_lock_irqsave(&rm->m_rs_lock, flags);
  671. spin_lock(&rs->rs_lock);
  672. __rds_send_complete(rs, rm, RDS_RDMA_CANCELED);
  673. spin_unlock(&rs->rs_lock);
  674. rm->m_rs = NULL;
  675. spin_unlock_irqrestore(&rm->m_rs_lock, flags);
  676. rds_message_put(rm);
  677. }
  678. }
  679. /*
  680. * we only want this to fire once so we use the callers 'queued'. It's
  681. * possible that another thread can race with us and remove the
  682. * message from the flow with RDS_CANCEL_SENT_TO.
  683. */
  684. static int rds_send_queue_rm(struct rds_sock *rs, struct rds_connection *conn,
  685. struct rds_conn_path *cp,
  686. struct rds_message *rm, __be16 sport,
  687. __be16 dport, int *queued)
  688. {
  689. unsigned long flags;
  690. u32 len;
  691. if (*queued)
  692. goto out;
  693. len = be32_to_cpu(rm->m_inc.i_hdr.h_len);
  694. /* this is the only place which holds both the socket's rs_lock
  695. * and the connection's c_lock */
  696. spin_lock_irqsave(&rs->rs_lock, flags);
  697. /*
  698. * If there is a little space in sndbuf, we don't queue anything,
  699. * and userspace gets -EAGAIN. But poll() indicates there's send
  700. * room. This can lead to bad behavior (spinning) if snd_bytes isn't
  701. * freed up by incoming acks. So we check the *old* value of
  702. * rs_snd_bytes here to allow the last msg to exceed the buffer,
  703. * and poll() now knows no more data can be sent.
  704. */
  705. if (rs->rs_snd_bytes < rds_sk_sndbuf(rs)) {
  706. rs->rs_snd_bytes += len;
  707. /* let recv side know we are close to send space exhaustion.
  708. * This is probably not the optimal way to do it, as this
  709. * means we set the flag on *all* messages as soon as our
  710. * throughput hits a certain threshold.
  711. */
  712. if (rs->rs_snd_bytes >= rds_sk_sndbuf(rs) / 2)
  713. __set_bit(RDS_MSG_ACK_REQUIRED, &rm->m_flags);
  714. list_add_tail(&rm->m_sock_item, &rs->rs_send_queue);
  715. set_bit(RDS_MSG_ON_SOCK, &rm->m_flags);
  716. rds_message_addref(rm);
  717. rm->m_rs = rs;
  718. /* The code ordering is a little weird, but we're
  719. trying to minimize the time we hold c_lock */
  720. rds_message_populate_header(&rm->m_inc.i_hdr, sport, dport, 0);
  721. rm->m_inc.i_conn = conn;
  722. rm->m_inc.i_conn_path = cp;
  723. rds_message_addref(rm);
  724. spin_lock(&cp->cp_lock);
  725. rm->m_inc.i_hdr.h_sequence = cpu_to_be64(cp->cp_next_tx_seq++);
  726. list_add_tail(&rm->m_conn_item, &cp->cp_send_queue);
  727. set_bit(RDS_MSG_ON_CONN, &rm->m_flags);
  728. spin_unlock(&cp->cp_lock);
  729. rdsdebug("queued msg %p len %d, rs %p bytes %d seq %llu\n",
  730. rm, len, rs, rs->rs_snd_bytes,
  731. (unsigned long long)be64_to_cpu(rm->m_inc.i_hdr.h_sequence));
  732. *queued = 1;
  733. }
  734. spin_unlock_irqrestore(&rs->rs_lock, flags);
  735. out:
  736. return *queued;
  737. }
  738. /*
  739. * rds_message is getting to be quite complicated, and we'd like to allocate
  740. * it all in one go. This figures out how big it needs to be up front.
  741. */
  742. static int rds_rm_size(struct msghdr *msg, int data_len)
  743. {
  744. struct cmsghdr *cmsg;
  745. int size = 0;
  746. int cmsg_groups = 0;
  747. int retval;
  748. for_each_cmsghdr(cmsg, msg) {
  749. if (!CMSG_OK(msg, cmsg))
  750. return -EINVAL;
  751. if (cmsg->cmsg_level != SOL_RDS)
  752. continue;
  753. switch (cmsg->cmsg_type) {
  754. case RDS_CMSG_RDMA_ARGS:
  755. cmsg_groups |= 1;
  756. retval = rds_rdma_extra_size(CMSG_DATA(cmsg));
  757. if (retval < 0)
  758. return retval;
  759. size += retval;
  760. break;
  761. case RDS_CMSG_RDMA_DEST:
  762. case RDS_CMSG_RDMA_MAP:
  763. cmsg_groups |= 2;
  764. /* these are valid but do no add any size */
  765. break;
  766. case RDS_CMSG_ATOMIC_CSWP:
  767. case RDS_CMSG_ATOMIC_FADD:
  768. case RDS_CMSG_MASKED_ATOMIC_CSWP:
  769. case RDS_CMSG_MASKED_ATOMIC_FADD:
  770. cmsg_groups |= 1;
  771. size += sizeof(struct scatterlist);
  772. break;
  773. default:
  774. return -EINVAL;
  775. }
  776. }
  777. size += ceil(data_len, PAGE_SIZE) * sizeof(struct scatterlist);
  778. /* Ensure (DEST, MAP) are never used with (ARGS, ATOMIC) */
  779. if (cmsg_groups == 3)
  780. return -EINVAL;
  781. return size;
  782. }
  783. static int rds_cmsg_send(struct rds_sock *rs, struct rds_message *rm,
  784. struct msghdr *msg, int *allocated_mr)
  785. {
  786. struct cmsghdr *cmsg;
  787. int ret = 0;
  788. for_each_cmsghdr(cmsg, msg) {
  789. if (!CMSG_OK(msg, cmsg))
  790. return -EINVAL;
  791. if (cmsg->cmsg_level != SOL_RDS)
  792. continue;
  793. /* As a side effect, RDMA_DEST and RDMA_MAP will set
  794. * rm->rdma.m_rdma_cookie and rm->rdma.m_rdma_mr.
  795. */
  796. switch (cmsg->cmsg_type) {
  797. case RDS_CMSG_RDMA_ARGS:
  798. ret = rds_cmsg_rdma_args(rs, rm, cmsg);
  799. break;
  800. case RDS_CMSG_RDMA_DEST:
  801. ret = rds_cmsg_rdma_dest(rs, rm, cmsg);
  802. break;
  803. case RDS_CMSG_RDMA_MAP:
  804. ret = rds_cmsg_rdma_map(rs, rm, cmsg);
  805. if (!ret)
  806. *allocated_mr = 1;
  807. break;
  808. case RDS_CMSG_ATOMIC_CSWP:
  809. case RDS_CMSG_ATOMIC_FADD:
  810. case RDS_CMSG_MASKED_ATOMIC_CSWP:
  811. case RDS_CMSG_MASKED_ATOMIC_FADD:
  812. ret = rds_cmsg_atomic(rs, rm, cmsg);
  813. break;
  814. default:
  815. return -EINVAL;
  816. }
  817. if (ret)
  818. break;
  819. }
  820. return ret;
  821. }
  822. static void rds_send_ping(struct rds_connection *conn);
  823. static int rds_send_mprds_hash(struct rds_sock *rs, struct rds_connection *conn)
  824. {
  825. int hash;
  826. if (conn->c_npaths == 0)
  827. hash = RDS_MPATH_HASH(rs, RDS_MPATH_WORKERS);
  828. else
  829. hash = RDS_MPATH_HASH(rs, conn->c_npaths);
  830. if (conn->c_npaths == 0 && hash != 0) {
  831. rds_send_ping(conn);
  832. if (conn->c_npaths == 0) {
  833. wait_event_interruptible(conn->c_hs_waitq,
  834. (conn->c_npaths != 0));
  835. }
  836. if (conn->c_npaths == 1)
  837. hash = 0;
  838. }
  839. return hash;
  840. }
  841. int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len)
  842. {
  843. struct sock *sk = sock->sk;
  844. struct rds_sock *rs = rds_sk_to_rs(sk);
  845. DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name);
  846. __be32 daddr;
  847. __be16 dport;
  848. struct rds_message *rm = NULL;
  849. struct rds_connection *conn;
  850. int ret = 0;
  851. int queued = 0, allocated_mr = 0;
  852. int nonblock = msg->msg_flags & MSG_DONTWAIT;
  853. long timeo = sock_sndtimeo(sk, nonblock);
  854. struct rds_conn_path *cpath;
  855. /* Mirror Linux UDP mirror of BSD error message compatibility */
  856. /* XXX: Perhaps MSG_MORE someday */
  857. if (msg->msg_flags & ~(MSG_DONTWAIT | MSG_CMSG_COMPAT)) {
  858. ret = -EOPNOTSUPP;
  859. goto out;
  860. }
  861. if (msg->msg_namelen) {
  862. /* XXX fail non-unicast destination IPs? */
  863. if (msg->msg_namelen < sizeof(*usin) || usin->sin_family != AF_INET) {
  864. ret = -EINVAL;
  865. goto out;
  866. }
  867. daddr = usin->sin_addr.s_addr;
  868. dport = usin->sin_port;
  869. } else {
  870. /* We only care about consistency with ->connect() */
  871. lock_sock(sk);
  872. daddr = rs->rs_conn_addr;
  873. dport = rs->rs_conn_port;
  874. release_sock(sk);
  875. }
  876. lock_sock(sk);
  877. if (daddr == 0 || rs->rs_bound_addr == 0) {
  878. release_sock(sk);
  879. ret = -ENOTCONN; /* XXX not a great errno */
  880. goto out;
  881. }
  882. release_sock(sk);
  883. if (payload_len > rds_sk_sndbuf(rs)) {
  884. ret = -EMSGSIZE;
  885. goto out;
  886. }
  887. /* size of rm including all sgs */
  888. ret = rds_rm_size(msg, payload_len);
  889. if (ret < 0)
  890. goto out;
  891. rm = rds_message_alloc(ret, GFP_KERNEL);
  892. if (!rm) {
  893. ret = -ENOMEM;
  894. goto out;
  895. }
  896. /* Attach data to the rm */
  897. if (payload_len) {
  898. rm->data.op_sg = rds_message_alloc_sgs(rm, ceil(payload_len, PAGE_SIZE));
  899. if (!rm->data.op_sg) {
  900. ret = -ENOMEM;
  901. goto out;
  902. }
  903. ret = rds_message_copy_from_user(rm, &msg->msg_iter);
  904. if (ret)
  905. goto out;
  906. }
  907. rm->data.op_active = 1;
  908. rm->m_daddr = daddr;
  909. /* rds_conn_create has a spinlock that runs with IRQ off.
  910. * Caching the conn in the socket helps a lot. */
  911. if (rs->rs_conn && rs->rs_conn->c_faddr == daddr)
  912. conn = rs->rs_conn;
  913. else {
  914. conn = rds_conn_create_outgoing(sock_net(sock->sk),
  915. rs->rs_bound_addr, daddr,
  916. rs->rs_transport,
  917. sock->sk->sk_allocation);
  918. if (IS_ERR(conn)) {
  919. ret = PTR_ERR(conn);
  920. goto out;
  921. }
  922. rs->rs_conn = conn;
  923. }
  924. /* Parse any control messages the user may have included. */
  925. ret = rds_cmsg_send(rs, rm, msg, &allocated_mr);
  926. if (ret)
  927. goto out;
  928. if (rm->rdma.op_active && !conn->c_trans->xmit_rdma) {
  929. printk_ratelimited(KERN_NOTICE "rdma_op %p conn xmit_rdma %p\n",
  930. &rm->rdma, conn->c_trans->xmit_rdma);
  931. ret = -EOPNOTSUPP;
  932. goto out;
  933. }
  934. if (rm->atomic.op_active && !conn->c_trans->xmit_atomic) {
  935. printk_ratelimited(KERN_NOTICE "atomic_op %p conn xmit_atomic %p\n",
  936. &rm->atomic, conn->c_trans->xmit_atomic);
  937. ret = -EOPNOTSUPP;
  938. goto out;
  939. }
  940. if (conn->c_trans->t_mp_capable)
  941. cpath = &conn->c_path[rds_send_mprds_hash(rs, conn)];
  942. else
  943. cpath = &conn->c_path[0];
  944. rds_conn_path_connect_if_down(cpath);
  945. ret = rds_cong_wait(conn->c_fcong, dport, nonblock, rs);
  946. if (ret) {
  947. rs->rs_seen_congestion = 1;
  948. goto out;
  949. }
  950. while (!rds_send_queue_rm(rs, conn, cpath, rm, rs->rs_bound_port,
  951. dport, &queued)) {
  952. rds_stats_inc(s_send_queue_full);
  953. if (nonblock) {
  954. ret = -EAGAIN;
  955. goto out;
  956. }
  957. timeo = wait_event_interruptible_timeout(*sk_sleep(sk),
  958. rds_send_queue_rm(rs, conn, cpath, rm,
  959. rs->rs_bound_port,
  960. dport,
  961. &queued),
  962. timeo);
  963. rdsdebug("sendmsg woke queued %d timeo %ld\n", queued, timeo);
  964. if (timeo > 0 || timeo == MAX_SCHEDULE_TIMEOUT)
  965. continue;
  966. ret = timeo;
  967. if (ret == 0)
  968. ret = -ETIMEDOUT;
  969. goto out;
  970. }
  971. /*
  972. * By now we've committed to the send. We reuse rds_send_worker()
  973. * to retry sends in the rds thread if the transport asks us to.
  974. */
  975. rds_stats_inc(s_send_queued);
  976. ret = rds_send_xmit(cpath);
  977. if (ret == -ENOMEM || ret == -EAGAIN)
  978. queue_delayed_work(rds_wq, &cpath->cp_send_w, 1);
  979. rds_message_put(rm);
  980. return payload_len;
  981. out:
  982. /* If the user included a RDMA_MAP cmsg, we allocated a MR on the fly.
  983. * If the sendmsg goes through, we keep the MR. If it fails with EAGAIN
  984. * or in any other way, we need to destroy the MR again */
  985. if (allocated_mr)
  986. rds_rdma_unuse(rs, rds_rdma_cookie_key(rm->m_rdma_cookie), 1);
  987. if (rm)
  988. rds_message_put(rm);
  989. return ret;
  990. }
  991. /*
  992. * send out a probe. Can be shared by rds_send_ping,
  993. * rds_send_pong, rds_send_hb.
  994. * rds_send_hb should use h_flags
  995. * RDS_FLAG_HB_PING|RDS_FLAG_ACK_REQUIRED
  996. * or
  997. * RDS_FLAG_HB_PONG|RDS_FLAG_ACK_REQUIRED
  998. */
  999. int
  1000. rds_send_probe(struct rds_conn_path *cp, __be16 sport,
  1001. __be16 dport, u8 h_flags)
  1002. {
  1003. struct rds_message *rm;
  1004. unsigned long flags;
  1005. int ret = 0;
  1006. rm = rds_message_alloc(0, GFP_ATOMIC);
  1007. if (!rm) {
  1008. ret = -ENOMEM;
  1009. goto out;
  1010. }
  1011. rm->m_daddr = cp->cp_conn->c_faddr;
  1012. rm->data.op_active = 1;
  1013. rds_conn_path_connect_if_down(cp);
  1014. ret = rds_cong_wait(cp->cp_conn->c_fcong, dport, 1, NULL);
  1015. if (ret)
  1016. goto out;
  1017. spin_lock_irqsave(&cp->cp_lock, flags);
  1018. list_add_tail(&rm->m_conn_item, &cp->cp_send_queue);
  1019. set_bit(RDS_MSG_ON_CONN, &rm->m_flags);
  1020. rds_message_addref(rm);
  1021. rm->m_inc.i_conn = cp->cp_conn;
  1022. rm->m_inc.i_conn_path = cp;
  1023. rds_message_populate_header(&rm->m_inc.i_hdr, sport, dport,
  1024. cp->cp_next_tx_seq);
  1025. rm->m_inc.i_hdr.h_flags |= h_flags;
  1026. cp->cp_next_tx_seq++;
  1027. if (RDS_HS_PROBE(sport, dport) && cp->cp_conn->c_trans->t_mp_capable) {
  1028. u16 npaths = RDS_MPATH_WORKERS;
  1029. rds_message_add_extension(&rm->m_inc.i_hdr,
  1030. RDS_EXTHDR_NPATHS, &npaths,
  1031. sizeof(npaths));
  1032. rds_message_add_extension(&rm->m_inc.i_hdr,
  1033. RDS_EXTHDR_GEN_NUM,
  1034. &cp->cp_conn->c_my_gen_num,
  1035. sizeof(u32));
  1036. }
  1037. spin_unlock_irqrestore(&cp->cp_lock, flags);
  1038. rds_stats_inc(s_send_queued);
  1039. rds_stats_inc(s_send_pong);
  1040. /* schedule the send work on rds_wq */
  1041. queue_delayed_work(rds_wq, &cp->cp_send_w, 1);
  1042. rds_message_put(rm);
  1043. return 0;
  1044. out:
  1045. if (rm)
  1046. rds_message_put(rm);
  1047. return ret;
  1048. }
  1049. int
  1050. rds_send_pong(struct rds_conn_path *cp, __be16 dport)
  1051. {
  1052. return rds_send_probe(cp, 0, dport, 0);
  1053. }
  1054. void
  1055. rds_send_ping(struct rds_connection *conn)
  1056. {
  1057. unsigned long flags;
  1058. struct rds_conn_path *cp = &conn->c_path[0];
  1059. spin_lock_irqsave(&cp->cp_lock, flags);
  1060. if (conn->c_ping_triggered) {
  1061. spin_unlock_irqrestore(&cp->cp_lock, flags);
  1062. return;
  1063. }
  1064. conn->c_ping_triggered = 1;
  1065. spin_unlock_irqrestore(&cp->cp_lock, flags);
  1066. rds_send_probe(&conn->c_path[0], RDS_FLAG_PROBE_PORT, 0, 0);
  1067. }