Lines Matching refs:sc
62 #define SC_NODEF_ARGS(sc) sc->sc_node->nd_name, sc->sc_node->nd_num, \ argument
63 &sc->sc_node->nd_ipv4_address, \
64 ntohs(sc->sc_node->nd_ipv4_port)
81 #define sclog(sc, fmt, args...) do { \ argument
82 typeof(sc) __sc = (sc); \
128 static void o2net_sc_postpone_idle(struct o2net_sock_container *sc);
129 static void o2net_sc_reset_idle_timer(struct o2net_sock_container *sc);
158 struct o2net_sock_container *sc) in o2net_set_nst_sock_container() argument
160 nst->st_sc = sc; in o2net_set_nst_sock_container()
169 static inline void o2net_set_sock_timer(struct o2net_sock_container *sc) in o2net_set_sock_timer() argument
171 sc->sc_tv_timer = ktime_get(); in o2net_set_sock_timer()
174 static inline void o2net_set_data_ready_time(struct o2net_sock_container *sc) in o2net_set_data_ready_time() argument
176 sc->sc_tv_data_ready = ktime_get(); in o2net_set_data_ready_time()
179 static inline void o2net_set_advance_start_time(struct o2net_sock_container *sc) in o2net_set_advance_start_time() argument
181 sc->sc_tv_advance_start = ktime_get(); in o2net_set_advance_start_time()
184 static inline void o2net_set_advance_stop_time(struct o2net_sock_container *sc) in o2net_set_advance_stop_time() argument
186 sc->sc_tv_advance_stop = ktime_get(); in o2net_set_advance_stop_time()
189 static inline void o2net_set_func_start_time(struct o2net_sock_container *sc) in o2net_set_func_start_time() argument
191 sc->sc_tv_func_start = ktime_get(); in o2net_set_func_start_time()
194 static inline void o2net_set_func_stop_time(struct o2net_sock_container *sc) in o2net_set_func_stop_time() argument
196 sc->sc_tv_func_stop = ktime_get(); in o2net_set_func_stop_time()
215 static ktime_t o2net_get_func_run_time(struct o2net_sock_container *sc) in o2net_get_func_run_time() argument
217 return ktime_sub(sc->sc_tv_func_stop, sc->sc_tv_func_start); in o2net_get_func_run_time()
221 struct o2net_sock_container *sc) in o2net_update_send_stats() argument
223 sc->sc_tv_status_total = ktime_add(sc->sc_tv_status_total, in o2net_update_send_stats()
226 sc->sc_tv_send_total = ktime_add(sc->sc_tv_send_total, in o2net_update_send_stats()
229 sc->sc_tv_acquiry_total = ktime_add(sc->sc_tv_acquiry_total, in o2net_update_send_stats()
232 sc->sc_send_count++; in o2net_update_send_stats()
235 static void o2net_update_recv_stats(struct o2net_sock_container *sc) in o2net_update_recv_stats() argument
237 sc->sc_tv_process_total = ktime_add(sc->sc_tv_process_total, in o2net_update_recv_stats()
238 o2net_get_func_run_time(sc)); in o2net_update_recv_stats()
239 sc->sc_recv_count++; in o2net_update_recv_stats()
246 # define o2net_update_recv_stats(sc) argument
378 struct o2net_sock_container *sc = container_of(kref, in sc_kref_release() local
380 BUG_ON(timer_pending(&sc->sc_idle_timeout)); in sc_kref_release()
382 sclog(sc, "releasing\n"); in sc_kref_release()
384 if (sc->sc_sock) { in sc_kref_release()
385 sock_release(sc->sc_sock); in sc_kref_release()
386 sc->sc_sock = NULL; in sc_kref_release()
389 o2nm_undepend_item(&sc->sc_node->nd_item); in sc_kref_release()
390 o2nm_node_put(sc->sc_node); in sc_kref_release()
391 sc->sc_node = NULL; in sc_kref_release()
393 o2net_debug_del_sc(sc); in sc_kref_release()
395 if (sc->sc_page) in sc_kref_release()
396 __free_page(sc->sc_page); in sc_kref_release()
397 kfree(sc); in sc_kref_release()
400 static void sc_put(struct o2net_sock_container *sc) in sc_put() argument
402 sclog(sc, "put\n"); in sc_put()
403 kref_put(&sc->sc_kref, sc_kref_release); in sc_put()
405 static void sc_get(struct o2net_sock_container *sc) in sc_get() argument
407 sclog(sc, "get\n"); in sc_get()
408 kref_get(&sc->sc_kref); in sc_get()
412 struct o2net_sock_container *sc, *ret = NULL; in sc_alloc() local
417 sc = kzalloc(sizeof(*sc), GFP_NOFS); in sc_alloc()
418 if (sc == NULL || page == NULL) in sc_alloc()
421 kref_init(&sc->sc_kref); in sc_alloc()
423 sc->sc_node = node; in sc_alloc()
432 INIT_WORK(&sc->sc_connect_work, o2net_sc_connect_completed); in sc_alloc()
433 INIT_WORK(&sc->sc_rx_work, o2net_rx_until_empty); in sc_alloc()
434 INIT_WORK(&sc->sc_shutdown_work, o2net_shutdown_sc); in sc_alloc()
435 INIT_DELAYED_WORK(&sc->sc_keepalive_work, o2net_sc_send_keep_req); in sc_alloc()
437 timer_setup(&sc->sc_idle_timeout, o2net_idle_timer, 0); in sc_alloc()
439 sclog(sc, "alloced\n"); in sc_alloc()
441 ret = sc; in sc_alloc()
442 sc->sc_page = page; in sc_alloc()
443 o2net_debug_add_sc(sc); in sc_alloc()
444 sc = NULL; in sc_alloc()
450 kfree(sc); in sc_alloc()
457 static void o2net_sc_queue_work(struct o2net_sock_container *sc, in o2net_sc_queue_work() argument
460 sc_get(sc); in o2net_sc_queue_work()
462 sc_put(sc); in o2net_sc_queue_work()
464 static void o2net_sc_queue_delayed_work(struct o2net_sock_container *sc, in o2net_sc_queue_delayed_work() argument
468 sc_get(sc); in o2net_sc_queue_delayed_work()
470 sc_put(sc); in o2net_sc_queue_delayed_work()
472 static void o2net_sc_cancel_delayed_work(struct o2net_sock_container *sc, in o2net_sc_cancel_delayed_work() argument
476 sc_put(sc); in o2net_sc_cancel_delayed_work()
487 struct o2net_sock_container *sc, in o2net_set_nn_state() argument
496 if (old_sc && !sc) in o2net_set_nn_state()
498 else if (!old_sc && sc) in o2net_set_nn_state()
503 BUG_ON(sc && nn->nn_sc && nn->nn_sc != sc); in o2net_set_nn_state()
505 mlog_bug_on_msg(valid && !sc, "valid %u sc %p\n", valid, sc); in o2net_set_nn_state()
511 o2net_num_from_nn(nn), nn->nn_sc, sc, nn->nn_sc_valid, valid, in o2net_set_nn_state()
514 nn->nn_sc = sc; in o2net_set_nn_state()
539 o2nm_this_node() > sc->sc_node->nd_num ? in o2net_set_nn_state()
541 SC_NODEF_ARGS(sc)); in o2net_set_nn_state()
574 if ((old_sc == NULL) && sc) in o2net_set_nn_state()
575 sc_get(sc); in o2net_set_nn_state()
576 if (old_sc && (old_sc != sc)) { in o2net_set_nn_state()
586 struct o2net_sock_container *sc; in o2net_data_ready() local
589 sc = sk->sk_user_data; in o2net_data_ready()
590 if (sc) { in o2net_data_ready()
591 sclog(sc, "data_ready hit\n"); in o2net_data_ready()
592 o2net_set_data_ready_time(sc); in o2net_data_ready()
593 o2net_sc_queue_work(sc, &sc->sc_rx_work); in o2net_data_ready()
594 ready = sc->sc_data_ready; in o2net_data_ready()
607 struct o2net_sock_container *sc; in o2net_state_change() local
610 sc = sk->sk_user_data; in o2net_state_change()
611 if (sc == NULL) { in o2net_state_change()
616 sclog(sc, "state_change to %d\n", sk->sk_state); in o2net_state_change()
618 state_change = sc->sc_state_change; in o2net_state_change()
626 o2net_sc_queue_work(sc, &sc->sc_connect_work); in o2net_state_change()
631 SC_NODEF_ARGS(sc), sk->sk_state); in o2net_state_change()
632 o2net_sc_queue_work(sc, &sc->sc_shutdown_work); in o2net_state_change()
646 struct o2net_sock_container *sc) in o2net_register_callbacks() argument
657 sk->sk_user_data = sc; in o2net_register_callbacks()
658 sc_get(sc); in o2net_register_callbacks()
660 sc->sc_data_ready = sk->sk_data_ready; in o2net_register_callbacks()
661 sc->sc_state_change = sk->sk_state_change; in o2net_register_callbacks()
665 mutex_init(&sc->sc_send_lock); in o2net_register_callbacks()
671 struct o2net_sock_container *sc) in o2net_unregister_callbacks() argument
676 if (sk->sk_user_data == sc) { in o2net_unregister_callbacks()
679 sk->sk_data_ready = sc->sc_data_ready; in o2net_unregister_callbacks()
680 sk->sk_state_change = sc->sc_state_change; in o2net_unregister_callbacks()
694 struct o2net_sock_container *sc, in o2net_ensure_shutdown() argument
698 if (nn->nn_sc == sc) in o2net_ensure_shutdown()
713 struct o2net_sock_container *sc = in o2net_shutdown_sc() local
716 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_shutdown_sc()
718 sclog(sc, "shutting down\n"); in o2net_shutdown_sc()
721 if (o2net_unregister_callbacks(sc->sc_sock->sk, sc)) { in o2net_shutdown_sc()
724 del_timer_sync(&sc->sc_idle_timeout); in o2net_shutdown_sc()
725 o2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); in o2net_shutdown_sc()
726 sc_put(sc); in o2net_shutdown_sc()
727 kernel_sock_shutdown(sc->sc_sock, SHUT_RDWR); in o2net_shutdown_sc()
732 o2net_ensure_shutdown(nn, sc, 0); in o2net_shutdown_sc()
733 sc_put(sc); in o2net_shutdown_sc()
929 static void o2net_sendpage(struct o2net_sock_container *sc, in o2net_sendpage() argument
933 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_sendpage()
937 mutex_lock(&sc->sc_send_lock); in o2net_sendpage()
938 ret = sc->sc_sock->ops->sendpage(sc->sc_sock, in o2net_sendpage()
942 mutex_unlock(&sc->sc_send_lock); in o2net_sendpage()
947 " returned EAGAIN\n", size, SC_NODEF_ARGS(sc)); in o2net_sendpage()
952 " failed with %zd\n", size, SC_NODEF_ARGS(sc), ret); in o2net_sendpage()
953 o2net_ensure_shutdown(nn, sc, 0); in o2net_sendpage()
995 struct o2net_sock_container *sc; in o2net_fill_node_map() local
1002 if (!o2net_tx_can_proceed(o2net_nn_from_num(node), &sc, &ret)) in o2net_fill_node_map()
1006 sc_put(sc); in o2net_fill_node_map()
1019 struct o2net_sock_container *sc = NULL; in o2net_send_message_vec() local
1056 wait_event(nn->nn_sc_wq, o2net_tx_can_proceed(nn, &sc, &ret)); in o2net_send_message_vec()
1060 o2net_set_nst_sock_container(&nst, sc); in o2net_send_message_vec()
1094 mutex_lock(&sc->sc_send_lock); in o2net_send_message_vec()
1095 ret = o2net_send_tcp_msg(sc->sc_sock, vec, veclen, in o2net_send_message_vec()
1097 mutex_unlock(&sc->sc_send_lock); in o2net_send_message_vec()
1108 o2net_update_send_stats(&nst, sc); in o2net_send_message_vec()
1121 if (sc) in o2net_send_message_vec()
1122 sc_put(sc); in o2net_send_message_vec()
1166 static int o2net_process_message(struct o2net_sock_container *sc, in o2net_process_message() argument
1169 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_process_message()
1177 o2net_sc_postpone_idle(sc); in o2net_process_message()
1188 o2net_sendpage(sc, o2net_keep_resp, in o2net_process_message()
1220 o2net_set_func_start_time(sc); in o2net_process_message()
1221 sc->sc_msg_key = be32_to_cpu(hdr->key); in o2net_process_message()
1222 sc->sc_msg_type = be16_to_cpu(hdr->msg_type); in o2net_process_message()
1226 o2net_set_func_stop_time(sc); in o2net_process_message()
1228 o2net_update_recv_stats(sc); in o2net_process_message()
1232 mutex_lock(&sc->sc_send_lock); in o2net_process_message()
1233 ret = o2net_send_status_magic(sc->sc_sock, hdr, syserr, in o2net_process_message()
1235 mutex_unlock(&sc->sc_send_lock); in o2net_process_message()
1253 static int o2net_check_handshake(struct o2net_sock_container *sc) in o2net_check_handshake() argument
1255 struct o2net_handshake *hand = page_address(sc->sc_page); in o2net_check_handshake()
1256 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_check_handshake()
1261 "Disconnecting.\n", SC_NODEF_ARGS(sc), in o2net_check_handshake()
1266 o2net_ensure_shutdown(nn, sc, -ENOTCONN); in o2net_check_handshake()
1279 "Disconnecting.\n", SC_NODEF_ARGS(sc), in o2net_check_handshake()
1282 o2net_ensure_shutdown(nn, sc, -ENOTCONN); in o2net_check_handshake()
1290 "Disconnecting.\n", SC_NODEF_ARGS(sc), in o2net_check_handshake()
1293 o2net_ensure_shutdown(nn, sc, -ENOTCONN); in o2net_check_handshake()
1301 "Disconnecting.\n", SC_NODEF_ARGS(sc), in o2net_check_handshake()
1304 o2net_ensure_shutdown(nn, sc, -ENOTCONN); in o2net_check_handshake()
1308 sc->sc_handshake_ok = 1; in o2net_check_handshake()
1313 if (nn->nn_sc == sc) { in o2net_check_handshake()
1314 o2net_sc_reset_idle_timer(sc); in o2net_check_handshake()
1316 o2net_set_nn_state(nn, sc, 1, 0); in o2net_check_handshake()
1321 sc->sc_page_off -= sizeof(struct o2net_handshake); in o2net_check_handshake()
1322 if (sc->sc_page_off) in o2net_check_handshake()
1323 memmove(hand, hand + 1, sc->sc_page_off); in o2net_check_handshake()
1331 static int o2net_advance_rx(struct o2net_sock_container *sc) in o2net_advance_rx() argument
1338 sclog(sc, "receiving\n"); in o2net_advance_rx()
1339 o2net_set_advance_start_time(sc); in o2net_advance_rx()
1341 if (unlikely(sc->sc_handshake_ok == 0)) { in o2net_advance_rx()
1342 if(sc->sc_page_off < sizeof(struct o2net_handshake)) { in o2net_advance_rx()
1343 data = page_address(sc->sc_page) + sc->sc_page_off; in o2net_advance_rx()
1344 datalen = sizeof(struct o2net_handshake) - sc->sc_page_off; in o2net_advance_rx()
1345 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen); in o2net_advance_rx()
1347 sc->sc_page_off += ret; in o2net_advance_rx()
1350 if (sc->sc_page_off == sizeof(struct o2net_handshake)) { in o2net_advance_rx()
1351 o2net_check_handshake(sc); in o2net_advance_rx()
1352 if (unlikely(sc->sc_handshake_ok == 0)) in o2net_advance_rx()
1359 if (sc->sc_page_off < sizeof(struct o2net_msg)) { in o2net_advance_rx()
1360 data = page_address(sc->sc_page) + sc->sc_page_off; in o2net_advance_rx()
1361 datalen = sizeof(struct o2net_msg) - sc->sc_page_off; in o2net_advance_rx()
1362 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen); in o2net_advance_rx()
1364 sc->sc_page_off += ret; in o2net_advance_rx()
1368 if (sc->sc_page_off == sizeof(struct o2net_msg)) { in o2net_advance_rx()
1369 hdr = page_address(sc->sc_page); in o2net_advance_rx()
1379 if (sc->sc_page_off < sizeof(struct o2net_msg)) { in o2net_advance_rx()
1385 hdr = page_address(sc->sc_page); in o2net_advance_rx()
1387 msglog(hdr, "at page_off %zu\n", sc->sc_page_off); in o2net_advance_rx()
1390 if (sc->sc_page_off - sizeof(struct o2net_msg) < be16_to_cpu(hdr->data_len)) { in o2net_advance_rx()
1392 data = page_address(sc->sc_page) + sc->sc_page_off; in o2net_advance_rx()
1394 sc->sc_page_off; in o2net_advance_rx()
1395 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen); in o2net_advance_rx()
1397 sc->sc_page_off += ret; in o2net_advance_rx()
1402 if (sc->sc_page_off - sizeof(struct o2net_msg) == be16_to_cpu(hdr->data_len)) { in o2net_advance_rx()
1406 ret = o2net_process_message(sc, hdr); in o2net_advance_rx()
1409 sc->sc_page_off = 0; in o2net_advance_rx()
1413 sclog(sc, "ret = %d\n", ret); in o2net_advance_rx()
1414 o2net_set_advance_stop_time(sc); in o2net_advance_rx()
1423 struct o2net_sock_container *sc = in o2net_rx_until_empty() local
1428 ret = o2net_advance_rx(sc); in o2net_rx_until_empty()
1432 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_rx_until_empty()
1433 sclog(sc, "saw error %d, closing\n", ret); in o2net_rx_until_empty()
1435 o2net_ensure_shutdown(nn, sc, 0); in o2net_rx_until_empty()
1438 sc_put(sc); in o2net_rx_until_empty()
1458 struct o2net_sock_container *sc = in o2net_sc_connect_completed() local
1467 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); in o2net_sc_connect_completed()
1468 sc_put(sc); in o2net_sc_connect_completed()
1474 struct o2net_sock_container *sc = in o2net_sc_send_keep_req() local
1478 o2net_sendpage(sc, o2net_keep_req, sizeof(*o2net_keep_req)); in o2net_sc_send_keep_req()
1479 sc_put(sc); in o2net_sc_send_keep_req()
1487 struct o2net_sock_container *sc = from_timer(sc, t, sc_idle_timeout); in o2net_idle_timer() local
1488 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_idle_timer()
1491 ktime_to_ms(sc->sc_tv_timer); in o2net_idle_timer()
1498 SC_NODEF_ARGS(sc), msecs / 1000, msecs % 1000); in o2net_idle_timer()
1509 o2net_sc_reset_idle_timer(sc); in o2net_idle_timer()
1513 static void o2net_sc_reset_idle_timer(struct o2net_sock_container *sc) in o2net_sc_reset_idle_timer() argument
1515 o2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); in o2net_sc_reset_idle_timer()
1516 o2net_sc_queue_delayed_work(sc, &sc->sc_keepalive_work, in o2net_sc_reset_idle_timer()
1518 o2net_set_sock_timer(sc); in o2net_sc_reset_idle_timer()
1519 mod_timer(&sc->sc_idle_timeout, in o2net_sc_reset_idle_timer()
1523 static void o2net_sc_postpone_idle(struct o2net_sock_container *sc) in o2net_sc_postpone_idle() argument
1525 struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); in o2net_sc_postpone_idle()
1535 if (timer_pending(&sc->sc_idle_timeout)) in o2net_sc_postpone_idle()
1536 o2net_sc_reset_idle_timer(sc); in o2net_sc_postpone_idle()
1548 struct o2net_sock_container *sc = NULL; in o2net_start_connect() local
1592 sc = sc_alloc(node); in o2net_start_connect()
1593 if (sc == NULL) { in o2net_start_connect()
1604 sc->sc_sock = sock; /* freed by sc_kref_release */ in o2net_start_connect()
1620 tcp_sock_set_nodelay(sc->sc_sock->sk); in o2net_start_connect()
1623 o2net_register_callbacks(sc->sc_sock->sk, sc); in o2net_start_connect()
1627 o2net_set_nn_state(nn, sc, 0, 0); in o2net_start_connect()
1634 ret = sc->sc_sock->ops->connect(sc->sc_sock, in o2net_start_connect()
1642 if (ret && sc) { in o2net_start_connect()
1644 " failed with errno %d\n", SC_NODEF_ARGS(sc), ret); in o2net_start_connect()
1647 o2net_ensure_shutdown(nn, sc, 0); in o2net_start_connect()
1649 if (sc) in o2net_start_connect()
1650 sc_put(sc); in o2net_start_connect()
1781 struct o2net_sock_container *sc = NULL; in o2net_accept_one() local
1866 sc = sc_alloc(node); in o2net_accept_one()
1867 if (sc == NULL) { in o2net_accept_one()
1872 sc->sc_sock = new_sock; in o2net_accept_one()
1877 o2net_set_nn_state(nn, sc, 0, 0); in o2net_accept_one()
1880 o2net_register_callbacks(sc->sc_sock->sk, sc); in o2net_accept_one()
1881 o2net_sc_queue_work(sc, &sc->sc_rx_work); in o2net_accept_one()
1884 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); in o2net_accept_one()
1893 if (sc) in o2net_accept_one()
1894 sc_put(sc); in o2net_accept_one()