History

Merge tag 'dlm-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm

Pull dlm updates from David Teigland: "This set mainly includes a change to the way the dlm uses the SCTP API in the kernel, removing the direct dependency on the sctp module. Other odd SCTP-related fixes are also included. The other notable fix is for a long standing regression in the behavior of lock value blocks for user space locks" * tag 'dlm-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm: dlm: print error from kernel_sendpage dlm: fix lvb copy for user locks dlm: sctp_accept_from_sock() can be static dlm: fix reconnecting but not sending data dlm: replace BUG_ON with a less severe handling dlm: use sctp 1-to-1 API dlm: fix not reconnecting on connecting error handling dlm: fix race while closing connections dlm: fix connection stealing if using SCTP

Linus Torvalds committed 11 years ago

Commit 9cbf22b2 parents ea814ab b3a5bbf3 files · +305 −447Browse files

Unified · Split

3 files
  1. fs/dlm/lowcomms.c +300 −443
  2. fs/dlm/user.c +4 −3
  3. include/uapi/linux/dlm_device.h +1 −1
fs/dlm/lowcomms.c+300−443
@@ -120,12 +120,11 @@ struct connection { · 119 unmodified lines
120120 struct cbuf cb;
121121 int retries;
122122 #define MAX_CONNECT_RETRIES 3
123− int sctp_assoc;
124123 struct hlist_node list;
125124 struct connection *othercon;
126125 struct work_struct rwork; /* Receive workqueue */
127126 struct work_struct swork; /* Send workqueue */
128− bool try_new_addr;
127+ void (*orig_error_report)(struct sock *sk);
129128 };
130129 #define sock2con(x) ((struct connection *)(x)->sk_user_data)
131130
@@ -252,26 +251,6 @@ static struct connection *nodeid2con(int nodeid, gfp_t allocation) · 120 unmodified lines
252251 return con;
253252 }
254253
255−/* This is a bit drastic, but only called when things go wrong */
256−static struct connection *assoc2con(int assoc_id)
257−{
258− int i;
259− struct connection *con;
260−
261− mutex_lock(&connections_lock);
262−
263− for (i = 0 ; i < CONN_HASH_SIZE; i++) {
264− hlist_for_each_entry(con, &connection_hash[i], list) {
265− if (con->sctp_assoc == assoc_id) {
266− mutex_unlock(&connections_lock);
267− return con;
268− }
269− }
270− }
271− mutex_unlock(&connections_lock);
272− return NULL;
273−}
274−
275254 static struct dlm_node_addr *find_node_addr(int nodeid)
276255 {
277256 struct dlm_node_addr *na;
@@ -322,14 +301,14 @@ static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out, · 44 unmodified lines
322301 spin_lock(&dlm_node_addrs_spin);
323302 na = find_node_addr(nodeid);
324303 if (na && na->addr_count) {
304+ memcpy(&sas, na->addr[na->curr_addr_index],
305+ sizeof(struct sockaddr_storage));
306+
325307 if (try_new_addr) {
326308 na->curr_addr_index++;
327309 if (na->curr_addr_index == na->addr_count)
328310 na->curr_addr_index = 0;
329311 }
330−
331− memcpy(&sas, na->addr[na->curr_addr_index ],
332− sizeof(struct sockaddr_storage));
333312 }
334313 spin_unlock(&dlm_node_addrs_spin);
335314
@@ -459,18 +438,23 @@ static inline void lowcomms_connect_sock(struct connection *con) · 123 unmodified lines
459438
460439 static void lowcomms_state_change(struct sock *sk)
461440 {
462− if (sk->sk_state == TCP_ESTABLISHED)
441+ /* SCTP layer is not calling sk_data_ready when the connection
442+ * is done, so we catch the signal through here. Also, it
443+ * doesn't switch socket state when entering shutdown, so we
444+ * skip the write in that case.
445+ */
446+ if (sk->sk_shutdown) {
447+ if (sk->sk_shutdown == RCV_SHUTDOWN)
448+ lowcomms_data_ready(sk);
449+ } else if (sk->sk_state == TCP_ESTABLISHED) {
463450 lowcomms_write_space(sk);
451+ }
464452 }
465453
466454 int dlm_lowcomms_connect_node(int nodeid)
467455 {
468456 struct connection *con;
469457
470− /* with sctp there's no connecting without sending */
471− if (dlm_config.ci_protocol != 0)
472− return 0;
473−
474458 if (nodeid == dlm_our_nodeid())
475459 return 0;
476460
@@ -481,6 +465,43 @@ int dlm_lowcomms_connect_node(int nodeid) · 4 unmodified lines
481465 return 0;
482466 }
483467
468+static void lowcomms_error_report(struct sock *sk)
469+{
470+ struct connection *con = sock2con(sk);
471+ struct sockaddr_storage saddr;
472+
473+ if (nodeid_to_addr(con->nodeid, &saddr, NULL, false)) {
474+ printk_ratelimited(KERN_ERR "dlm: node %d: socket error "
475+ "sending to node %d, port %d, "
476+ "sk_err=%d/%d\n", dlm_our_nodeid(),
477+ con->nodeid, dlm_config.ci_tcp_port,
478+ sk->sk_err, sk->sk_err_soft);
479+ return;
480+ } else if (saddr.ss_family == AF_INET) {
481+ struct sockaddr_in *sin4 = (struct sockaddr_in *)&saddr;
482+
483+ printk_ratelimited(KERN_ERR "dlm: node %d: socket error "
484+ "sending to node %d at %pI4, port %d, "
485+ "sk_err=%d/%d\n", dlm_our_nodeid(),
486+ con->nodeid, &sin4->sin_addr.s_addr,
487+ dlm_config.ci_tcp_port, sk->sk_err,
488+ sk->sk_err_soft);
489+ } else {
490+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&saddr;
491+
492+ printk_ratelimited(KERN_ERR "dlm: node %d: socket error "
493+ "sending to node %d at %u.%u.%u.%u, "
494+ "port %d, sk_err=%d/%d\n", dlm_our_nodeid(),
495+ con->nodeid, sin6->sin6_addr.s6_addr32[0],
496+ sin6->sin6_addr.s6_addr32[1],
497+ sin6->sin6_addr.s6_addr32[2],
498+ sin6->sin6_addr.s6_addr32[3],
499+ dlm_config.ci_tcp_port, sk->sk_err,
500+ sk->sk_err_soft);
501+ }
502+ con->orig_error_report(sk);
503+}
504+
484505 /* Make a socket active */
485506 static void add_sock(struct socket *sock, struct connection *con)
486507 {
@@ -492,6 +513,8 @@ static void add_sock(struct socket *sock, struct connection *con) · 5 unmodified lines
492513 con->sock->sk->sk_state_change = lowcomms_state_change;
493514 con->sock->sk->sk_user_data = con;
494515 con->sock->sk->sk_allocation = GFP_NOFS;
516+ con->orig_error_report = con->sock->sk->sk_error_report;
517+ con->sock->sk->sk_error_report = lowcomms_error_report;
495518 }
496519
497520 /* Add the port number to an IPv6 or 4 sockaddr and return the address
@@ -514,17 +537,24 @@ static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port, · 16 unmodified lines
514537 }
515538
516539 /* Close a remote connection and tidy up */
517−static void close_connection(struct connection *con, bool and_other)
540+static void close_connection(struct connection *con, bool and_other,
541+ bool tx, bool rx)
518542 {
519− mutex_lock(&con->sock_mutex);
543+ clear_bit(CF_CONNECT_PENDING, &con->flags);
544+ clear_bit(CF_WRITE_PENDING, &con->flags);
545+ if (tx && cancel_work_sync(&con->swork))
546+ log_print("canceled swork for node %d", con->nodeid);
547+ if (rx && cancel_work_sync(&con->rwork))
548+ log_print("canceled rwork for node %d", con->nodeid);
520549
550+ mutex_lock(&con->sock_mutex);
521551 if (con->sock) {
522552 sock_release(con->sock);
523553 con->sock = NULL;
524554 }
525555 if (con->othercon && and_other) {
526556 /* Will only re-enter once. */
527− close_connection(con->othercon, false);
557+ close_connection(con->othercon, false, true, true);
528558 }
529559 if (con->rx_page) {
530560 __free_page(con->rx_page);
@@ -535,254 +565,6 @@ static void close_connection(struct connection *con, bool and_other) · 4 unmodified lines
535565 mutex_unlock(&con->sock_mutex);
536566 }
537567
538−/* We only send shutdown messages to nodes that are not part of the cluster */
539−static void sctp_send_shutdown(sctp_assoc_t associd)
540−{
541− static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
542− struct msghdr outmessage;
543− struct cmsghdr *cmsg;
544− struct sctp_sndrcvinfo *sinfo;
545− int ret;
546− struct connection *con;
547−
548− con = nodeid2con(0,0);
549− BUG_ON(con == NULL);
550−
551− outmessage.msg_name = NULL;
552− outmessage.msg_namelen = 0;
553− outmessage.msg_control = outcmsg;
554− outmessage.msg_controllen = sizeof(outcmsg);
555− outmessage.msg_flags = MSG_EOR;
556−
557− cmsg = CMSG_FIRSTHDR(&outmessage);
558− cmsg->cmsg_level = IPPROTO_SCTP;
559− cmsg->cmsg_type = SCTP_SNDRCV;
560− cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
561− outmessage.msg_controllen = cmsg->cmsg_len;
562− sinfo = CMSG_DATA(cmsg);
563− memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
564−
565− sinfo->sinfo_flags |= MSG_EOF;
566− sinfo->sinfo_assoc_id = associd;
567−
568− ret = kernel_sendmsg(con->sock, &outmessage, NULL, 0, 0);
569−
570− if (ret != 0)
571− log_print("send EOF to node failed: %d", ret);
572−}
573−
574−static void sctp_init_failed_foreach(struct connection *con)
575−{
576−
577− /*
578− * Don't try to recover base con and handle race where the
579− * other node's assoc init creates a assoc and we get that
580− * notification, then we get a notification that our attempt
581− * failed due. This happens when we are still trying the primary
582− * address, but the other node has already tried secondary addrs
583− * and found one that worked.
584− */
585− if (!con->nodeid || con->sctp_assoc)
586− return;
587−
588− log_print("Retrying SCTP association init for node %d\n", con->nodeid);
589−
590− con->try_new_addr = true;
591− con->sctp_assoc = 0;
592− if (test_and_clear_bit(CF_INIT_PENDING, &con->flags)) {
593− if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
594− queue_work(send_workqueue, &con->swork);
595− }
596−}
597−
598−/* INIT failed but we don't know which node...
599− restart INIT on all pending nodes */
600−static void sctp_init_failed(void)
601−{
602− mutex_lock(&connections_lock);
603−
604− foreach_conn(sctp_init_failed_foreach);
605−
606− mutex_unlock(&connections_lock);
607−}
608−
609−static void retry_failed_sctp_send(struct connection *recv_con,
610− struct sctp_send_failed *sn_send_failed,
611− char *buf)
612−{
613− int len = sn_send_failed->ssf_length - sizeof(struct sctp_send_failed);
614− struct dlm_mhandle *mh;
615− struct connection *con;
616− char *retry_buf;
617− int nodeid = sn_send_failed->ssf_info.sinfo_ppid;
618−
619− log_print("Retry sending %d bytes to node id %d", len, nodeid);
620−
621− if (!nodeid) {
622− log_print("Shouldn't resend data via listening connection.");
623− return;
624− }
625−
626− con = nodeid2con(nodeid, 0);
627− if (!con) {
628− log_print("Could not look up con for nodeid %d\n",
629− nodeid);
630− return;
631− }
632−
633− mh = dlm_lowcomms_get_buffer(nodeid, len, GFP_NOFS, &retry_buf);
634− if (!mh) {
635− log_print("Could not allocate buf for retry.");
636− return;
637− }
638− memcpy(retry_buf, buf + sizeof(struct sctp_send_failed), len);
639− dlm_lowcomms_commit_buffer(mh);
640−
641− /*
642− * If we got a assoc changed event before the send failed event then
643− * we only need to retry the send.
644− */
645− if (con->sctp_assoc) {
646− if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
647− queue_work(send_workqueue, &con->swork);
648− } else
649− sctp_init_failed_foreach(con);
650−}
651−
652−/* Something happened to an association */
653−static void process_sctp_notification(struct connection *con,
654− struct msghdr *msg, char *buf)
655−{
656− union sctp_notification *sn = (union sctp_notification *)buf;
657− struct linger linger;
658−
659− switch (sn->sn_header.sn_type) {
660− case SCTP_SEND_FAILED:
661− retry_failed_sctp_send(con, &sn->sn_send_failed, buf);
662− break;
663− case SCTP_ASSOC_CHANGE:
664− switch (sn->sn_assoc_change.sac_state) {
665− case SCTP_COMM_UP:
666− case SCTP_RESTART:
667− {
668− /* Check that the new node is in the lockspace */
669− struct sctp_prim prim;
670− int nodeid;
671− int prim_len, ret;
672− int addr_len;
673− struct connection *new_con;
674−
675− /*
676− * We get this before any data for an association.
677− * We verify that the node is in the cluster and
678− * then peel off a socket for it.
679− */
680− if ((int)sn->sn_assoc_change.sac_assoc_id <= 0) {
681− log_print("COMM_UP for invalid assoc ID %d",
682− (int)sn->sn_assoc_change.sac_assoc_id);
683− sctp_init_failed();
684− return;
685− }
686− memset(&prim, 0, sizeof(struct sctp_prim));
687− prim_len = sizeof(struct sctp_prim);
688− prim.ssp_assoc_id = sn->sn_assoc_change.sac_assoc_id;
689−
690− ret = kernel_getsockopt(con->sock,
691− IPPROTO_SCTP,
692− SCTP_PRIMARY_ADDR,
693− (char*)&prim,
694− &prim_len);
695− if (ret < 0) {
696− log_print("getsockopt/sctp_primary_addr on "
697− "new assoc %d failed : %d",
698− (int)sn->sn_assoc_change.sac_assoc_id,
699− ret);
700−
701− /* Retry INIT later */
702− new_con = assoc2con(sn->sn_assoc_change.sac_assoc_id);
703− if (new_con)
704− clear_bit(CF_CONNECT_PENDING, &con->flags);
705− return;
706− }
707− make_sockaddr(&prim.ssp_addr, 0, &addr_len);
708− if (addr_to_nodeid(&prim.ssp_addr, &nodeid)) {
709− unsigned char *b=(unsigned char *)&prim.ssp_addr;
710− log_print("reject connect from unknown addr");
711− print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE,
712− b, sizeof(struct sockaddr_storage));
713− sctp_send_shutdown(prim.ssp_assoc_id);
714− return;
715− }
716−
717− new_con = nodeid2con(nodeid, GFP_NOFS);
718− if (!new_con)
719− return;
720−
721− /* Peel off a new sock */
722− lock_sock(con->sock->sk);
723− ret = sctp_do_peeloff(con->sock->sk,
724− sn->sn_assoc_change.sac_assoc_id,
725− &new_con->sock);
726− release_sock(con->sock->sk);
727− if (ret < 0) {
728− log_print("Can't peel off a socket for "
729− "connection %d to node %d: err=%d",
730− (int)sn->sn_assoc_change.sac_assoc_id,
731− nodeid, ret);
732− return;
733− }
734− add_sock(new_con->sock, new_con);
735−
736− linger.l_onoff = 1;
737− linger.l_linger = 0;
738− ret = kernel_setsockopt(new_con->sock, SOL_SOCKET, SO_LINGER,
739− (char *)&linger, sizeof(linger));
740− if (ret < 0)
741− log_print("set socket option SO_LINGER failed");
742−
743− log_print("connecting to %d sctp association %d",
744− nodeid, (int)sn->sn_assoc_change.sac_assoc_id);
745−
746− new_con->sctp_assoc = sn->sn_assoc_change.sac_assoc_id;
747− new_con->try_new_addr = false;
748− /* Send any pending writes */
749− clear_bit(CF_CONNECT_PENDING, &new_con->flags);
750− clear_bit(CF_INIT_PENDING, &new_con->flags);
751− if (!test_and_set_bit(CF_WRITE_PENDING, &new_con->flags)) {
752− queue_work(send_workqueue, &new_con->swork);
753− }
754− if (!test_and_set_bit(CF_READ_PENDING, &new_con->flags))
755− queue_work(recv_workqueue, &new_con->rwork);
756− }
757− break;
758−
759− case SCTP_COMM_LOST:
760− case SCTP_SHUTDOWN_COMP:
761− {
762− con = assoc2con(sn->sn_assoc_change.sac_assoc_id);
763− if (con) {
764− con->sctp_assoc = 0;
765− }
766− }
767− break;
768−
769− case SCTP_CANT_STR_ASSOC:
770− {
771− /* Will retry init when we get the send failed notification */
772− log_print("Can't start SCTP association - retrying");
773− }
774− break;
775−
776− default:
777− log_print("unexpected SCTP assoc change id=%d state=%d",
778− (int)sn->sn_assoc_change.sac_assoc_id,
779− sn->sn_assoc_change.sac_state);
780− }
781− default:
782− ; /* fall through */
783− }
784−}
785−
786568 /* Data received from remote end */
787569 static int receive_from_sock(struct connection *con)
788570 {
@@ -793,7 +575,6 @@ static int receive_from_sock(struct connection *con) · 4 unmodified lines
793575 int r;
794576 int call_again_soon = 0;
795577 int nvec;
796− char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
797578
798579 mutex_lock(&con->sock_mutex);
799580
@@ -801,6 +582,10 @@ static int receive_from_sock(struct connection *con) · 1 unmodified line
801582 ret = -EAGAIN;
802583 goto out_close;
803584 }
585+ if (con->nodeid == 0) {
586+ ret = -EINVAL;
587+ goto out_close;
588+ }
804589
805590 if (con->rx_page == NULL) {
806591 /*
@@ -813,11 +598,6 @@ static int receive_from_sock(struct connection *con) · 6 unmodified lines
813598 cbuf_init(&con->cb, PAGE_CACHE_SIZE);
814599 }
815600
816− /* Only SCTP needs these really */
817− memset(&incmsg, 0, sizeof(incmsg));
818− msg.msg_control = incmsg;
819− msg.msg_controllen = sizeof(incmsg);
820−
821601 /*
822602 * iov[0] is the bit of the circular buffer between the current end
823603 * point (cb.base + cb.len) and the end of the buffer.
@@ -843,31 +623,18 @@ static int receive_from_sock(struct connection *con) · 19 unmodified lines
843623 MSG_DONTWAIT | MSG_NOSIGNAL);
844624 if (ret <= 0)
845625 goto out_close;
846−
847− /* Process SCTP notifications */
848− if (msg.msg_flags & MSG_NOTIFICATION) {
849− msg.msg_control = incmsg;
850− msg.msg_controllen = sizeof(incmsg);
851−
852− process_sctp_notification(con, &msg,
853− page_address(con->rx_page) + con->cb.base);
854− mutex_unlock(&con->sock_mutex);
855− return 0;
856− }
857− BUG_ON(con->nodeid == 0);
858−
859− if (ret == len)
626+ else if (ret == len)
860627 call_again_soon = 1;
628+
861629 cbuf_add(&con->cb, ret);
862630 ret = dlm_process_incoming_buffer(con->nodeid,
863631 page_address(con->rx_page),
864632 con->cb.base, con->cb.len,
865633 PAGE_CACHE_SIZE);
866634 if (ret == -EBADMSG) {
867− log_print("lowcomms: addr=%p, base=%u, len=%u, "
868− "iov_len=%u, iov_base[0]=%p, read=%d",
869− page_address(con->rx_page), con->cb.base, con->cb.len,
870− len, iov[0].iov_base, r);
635+ log_print("lowcomms: addr=%p, base=%u, len=%u, read=%d",
636+ page_address(con->rx_page), con->cb.base,
637+ con->cb.len, r);
871638 }
872639 if (ret < 0)
873640 goto out_close;
@@ -892,7 +659,7 @@ out_resched: · 18 unmodified lines
892659 out_close:
893660 mutex_unlock(&con->sock_mutex);
894661 if (ret != -EAGAIN) {
895− close_connection(con, false);
662+ close_connection(con, false, true, false);
896663 /* Reconnect when there is something to send */
897664 }
898665 /* Don't return success if we really got EOF */
@@ -1033,6 +800,120 @@ accept_err: · 134 unmodified lines
1033800 return result;
1034801 }
1035802
803+static int sctp_accept_from_sock(struct connection *con)
804+{
805+ /* Check that the new node is in the lockspace */
806+ struct sctp_prim prim;
807+ int nodeid;
808+ int prim_len, ret;
809+ int addr_len;
810+ struct connection *newcon;
811+ struct connection *addcon;
812+ struct socket *newsock;
813+
814+ mutex_lock(&connections_lock);
815+ if (!dlm_allow_conn) {
816+ mutex_unlock(&connections_lock);
817+ return -1;
818+ }
819+ mutex_unlock(&connections_lock);
820+
821+ mutex_lock_nested(&con->sock_mutex, 0);
822+
823+ ret = kernel_accept(con->sock, &newsock, O_NONBLOCK);
824+ if (ret < 0)
825+ goto accept_err;
826+
827+ memset(&prim, 0, sizeof(struct sctp_prim));
828+ prim_len = sizeof(struct sctp_prim);
829+
830+ ret = kernel_getsockopt(newsock, IPPROTO_SCTP, SCTP_PRIMARY_ADDR,
831+ (char *)&prim, &prim_len);
832+ if (ret < 0) {
833+ log_print("getsockopt/sctp_primary_addr failed: %d", ret);
834+ goto accept_err;
835+ }
836+
837+ make_sockaddr(&prim.ssp_addr, 0, &addr_len);
838+ if (addr_to_nodeid(&prim.ssp_addr, &nodeid)) {
839+ unsigned char *b = (unsigned char *)&prim.ssp_addr;
840+
841+ log_print("reject connect from unknown addr");
842+ print_hex_dump_bytes("ss: ", DUMP_PREFIX_NONE,
843+ b, sizeof(struct sockaddr_storage));
844+ goto accept_err;
845+ }
846+
847+ newcon = nodeid2con(nodeid, GFP_NOFS);
848+ if (!newcon) {
849+ ret = -ENOMEM;
850+ goto accept_err;
851+ }
852+
853+ mutex_lock_nested(&newcon->sock_mutex, 1);
854+
855+ if (newcon->sock) {
856+ struct connection *othercon = newcon->othercon;
857+
858+ if (!othercon) {
859+ othercon = kmem_cache_zalloc(con_cache, GFP_NOFS);
860+ if (!othercon) {
861+ log_print("failed to allocate incoming socket");
862+ mutex_unlock(&newcon->sock_mutex);
863+ ret = -ENOMEM;
864+ goto accept_err;
865+ }
866+ othercon->nodeid = nodeid;
867+ othercon->rx_action = receive_from_sock;
868+ mutex_init(&othercon->sock_mutex);
869+ INIT_WORK(&othercon->swork, process_send_sockets);
870+ INIT_WORK(&othercon->rwork, process_recv_sockets);
871+ set_bit(CF_IS_OTHERCON, &othercon->flags);
872+ }
873+ if (!othercon->sock) {
874+ newcon->othercon = othercon;
875+ othercon->sock = newsock;
876+ newsock->sk->sk_user_data = othercon;
877+ add_sock(newsock, othercon);
878+ addcon = othercon;
879+ } else {
880+ printk("Extra connection from node %d attempted\n", nodeid);
881+ ret = -EAGAIN;
882+ mutex_unlock(&newcon->sock_mutex);
883+ goto accept_err;
884+ }
885+ } else {
886+ newsock->sk->sk_user_data = newcon;
887+ newcon->rx_action = receive_from_sock;
888+ add_sock(newsock, newcon);
889+ addcon = newcon;
890+ }
891+
892+ log_print("connected to %d", nodeid);
893+
894+ mutex_unlock(&newcon->sock_mutex);
895+
896+ /*
897+ * Add it to the active queue in case we got data
898+ * between processing the accept adding the socket
899+ * to the read_sockets list
900+ */
901+ if (!test_and_set_bit(CF_READ_PENDING, &addcon->flags))
902+ queue_work(recv_workqueue, &addcon->rwork);
903+ mutex_unlock(&con->sock_mutex);
904+
905+ return 0;
906+
907+accept_err:
908+ mutex_unlock(&con->sock_mutex);
909+ if (newsock)
910+ sock_release(newsock);
911+ if (ret != -EAGAIN)
912+ log_print("error accepting connection from node: %d", ret);
913+
914+ return ret;
915+}
916+
1036917 static void free_entry(struct writequeue_entry *e)
1037918 {
1038919 __free_page(e->page);
@@ -1057,97 +938,129 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed) · 18 unmodified lines
1057938 }
1058939 }
1059940
941+/*
942+ * sctp_bind_addrs - bind a SCTP socket to all our addresses
943+ */
944+static int sctp_bind_addrs(struct connection *con, uint16_t port)
945+{
946+ struct sockaddr_storage localaddr;
947+ int i, addr_len, result = 0;
948+
949+ for (i = 0; i < dlm_local_count; i++) {
950+ memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr));
951+ make_sockaddr(&localaddr, port, &addr_len);
952+
953+ if (!i)
954+ result = kernel_bind(con->sock,
955+ (struct sockaddr *)&localaddr,
956+ addr_len);
957+ else
958+ result = kernel_setsockopt(con->sock, SOL_SCTP,
959+ SCTP_SOCKOPT_BINDX_ADD,
960+ (char *)&localaddr, addr_len);
961+
962+ if (result < 0) {
963+ log_print("Can't bind to %d addr number %d, %d.\n",
964+ port, i + 1, result);
965+ break;
966+ }
967+ }
968+ return result;
969+}
970+
1060971 /* Initiate an SCTP association.
1061972 This is a special case of send_to_sock() in that we don't yet have a
1062973 peeled-off socket for this association, so we use the listening socket
1063974 and add the primary IP address of the remote node.
1064975 */
1065−static void sctp_init_assoc(struct connection *con)
976+static void sctp_connect_to_sock(struct connection *con)
1066977 {
1067− struct sockaddr_storage rem_addr;
1068− char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
1069− struct msghdr outmessage;
1070− struct cmsghdr *cmsg;
1071− struct sctp_sndrcvinfo *sinfo;
1072− struct connection *base_con;
1073− struct writequeue_entry *e;
1074− int len, offset;
1075− int ret;
1076− int addrlen;
1077− struct kvec iov[1];
978+ struct sockaddr_storage daddr;
979+ int one = 1;
980+ int result;
981+ int addr_len;
982+ struct socket *sock;
983+
984+ if (con->nodeid == 0) {
985+ log_print("attempt to connect sock 0 foiled");
986+ return;
987+ }
1078988
1079989 mutex_lock(&con->sock_mutex);
1080− if (test_and_set_bit(CF_INIT_PENDING, &con->flags))
1081− goto unlock;
1082990
1083− if (nodeid_to_addr(con->nodeid, NULL, (struct sockaddr *)&rem_addr,
1084− con->try_new_addr)) {
991+ /* Some odd races can cause double-connects, ignore them */
992+ if (con->retries++ > MAX_CONNECT_RETRIES)
993+ goto out;
994+
995+ if (con->sock) {
996+ log_print("node %d already connected.", con->nodeid);
997+ goto out;
998+ }
999+
1000+ memset(&daddr, 0, sizeof(daddr));
1001+ result = nodeid_to_addr(con->nodeid, &daddr, NULL, true);
1002+ if (result < 0) {
10851003 log_print("no address for nodeid %d", con->nodeid);
1086− goto unlock;
1004+ goto out;
10871005 }
1088− base_con = nodeid2con(0, 0);
1089− BUG_ON(base_con == NULL);
10901006
1091− make_sockaddr(&rem_addr, dlm_config.ci_tcp_port, &addrlen);
1007+ /* Create a socket to communicate with */
1008+ result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family,
1009+ SOCK_STREAM, IPPROTO_SCTP, &sock);
1010+ if (result < 0)
1011+ goto socket_err;
10921012
1093− outmessage.msg_name = &rem_addr;
1094− outmessage.msg_namelen = addrlen;
1095− outmessage.msg_control = outcmsg;
1096− outmessage.msg_controllen = sizeof(outcmsg);
1097− outmessage.msg_flags = MSG_EOR;
1013+ sock->sk->sk_user_data = con;
1014+ con->rx_action = receive_from_sock;
1015+ con->connect_action = sctp_connect_to_sock;
1016+ add_sock(sock, con);
10981017
1099− spin_lock(&con->writequeue_lock);
1018+ /* Bind to all addresses. */
1019+ if (sctp_bind_addrs(con, 0))
1020+ goto bind_err;
11001021
1101− if (list_empty(&con->writequeue)) {
1102− spin_unlock(&con->writequeue_lock);
1103− log_print("writequeue empty for nodeid %d", con->nodeid);
1104− goto unlock;
1105− }
1022+ make_sockaddr(&daddr, dlm_config.ci_tcp_port, &addr_len);
11061023
1107− e = list_first_entry(&con->writequeue, struct writequeue_entry, list);
1108− len = e->len;
1109− offset = e->offset;
1024+ log_print("connecting to %d", con->nodeid);
11101025
1111− /* Send the first block off the write queue */
1112− iov[0].iov_base = page_address(e->page)+offset;
1113− iov[0].iov_len = len;
1114− spin_unlock(&con->writequeue_lock);
1026+ /* Turn off Nagle's algorithm */
1027+ kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY, (char *)&one,
1028+ sizeof(one));
11151029
1116− if (rem_addr.ss_family == AF_INET) {
1117− struct sockaddr_in *sin = (struct sockaddr_in *)&rem_addr;
1118− log_print("Trying to connect to %pI4", &sin->sin_addr.s_addr);
1119− } else {
1120− struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&rem_addr;
1121− log_print("Trying to connect to %pI6", &sin6->sin6_addr);
1122− }
1030+ result = sock->ops->connect(sock, (struct sockaddr *)&daddr, addr_len,
1031+ O_NONBLOCK);
1032+ if (result == -EINPROGRESS)
1033+ result = 0;
1034+ if (result == 0)
1035+ goto out;
11231036
1124− cmsg = CMSG_FIRSTHDR(&outmessage);
1125− cmsg->cmsg_level = IPPROTO_SCTP;
1126− cmsg->cmsg_type = SCTP_SNDRCV;
1127− cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
1128− sinfo = CMSG_DATA(cmsg);
1129− memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
1130− sinfo->sinfo_ppid = cpu_to_le32(con->nodeid);
1131− outmessage.msg_controllen = cmsg->cmsg_len;
1132− sinfo->sinfo_flags |= SCTP_ADDR_OVER;
11331037
1134− ret = kernel_sendmsg(base_con->sock, &outmessage, iov, 1, len);
1135− if (ret < 0) {
1136− log_print("Send first packet to node %d failed: %d",
1137− con->nodeid, ret);
1038+bind_err:
1039+ con->sock = NULL;
1040+ sock_release(sock);
11381041
1139− /* Try again later */
1042+socket_err:
1043+ /*
1044+ * Some errors are fatal and this list might need adjusting. For other
1045+ * errors we try again until the max number of retries is reached.
1046+ */
1047+ if (result != -EHOSTUNREACH &&
1048+ result != -ENETUNREACH &&
1049+ result != -ENETDOWN &&
1050+ result != -EINVAL &&
1051+ result != -EPROTONOSUPPORT) {
1052+ log_print("connect %d try %d error %d", con->nodeid,
1053+ con->retries, result);
1054+ mutex_unlock(&con->sock_mutex);
1055+ msleep(1000);
11401056 clear_bit(CF_CONNECT_PENDING, &con->flags);
1141− clear_bit(CF_INIT_PENDING, &con->flags);
1142− }
1143− else {
1144− spin_lock(&con->writequeue_lock);
1145− writequeue_entry_complete(e, ret);
1146− spin_unlock(&con->writequeue_lock);
1057+ lowcomms_connect_sock(con);
1058+ return;
11471059 }
11481060
1149−unlock:
1061+out:
11501062 mutex_unlock(&con->sock_mutex);
1063+ set_bit(CF_WRITE_PENDING, &con->flags);
11511064 }
11521065
11531066 /* Connect a new socket to its peer */
@@ -1236,11 +1149,13 @@ out_err: · 82 unmodified lines
12361149 con->retries, result);
12371150 mutex_unlock(&con->sock_mutex);
12381151 msleep(1000);
1152+ clear_bit(CF_CONNECT_PENDING, &con->flags);
12391153 lowcomms_connect_sock(con);
12401154 return;
12411155 }
12421156 out:
12431157 mutex_unlock(&con->sock_mutex);
1158+ set_bit(CF_WRITE_PENDING, &con->flags);
12441159 return;
12451160 }
12461161
@@ -1325,37 +1240,11 @@ static void init_local(void) · 78 unmodified lines
13251240 }
13261241 }
13271242
1328−/* Bind to an IP address. SCTP allows multiple address so it can do
1329− multi-homing */
1330−static int add_sctp_bind_addr(struct connection *sctp_con,
1331− struct sockaddr_storage *addr,
1332− int addr_len, int num)
1333−{
1334− int result = 0;
1335−
1336− if (num == 1)
1337− result = kernel_bind(sctp_con->sock,
1338− (struct sockaddr *) addr,
1339− addr_len);
1340− else
1341− result = kernel_setsockopt(sctp_con->sock, SOL_SCTP,
1342− SCTP_SOCKOPT_BINDX_ADD,
1343− (char *)addr, addr_len);
1344−
1345− if (result < 0)
1346− log_print("Can't bind to port %d addr number %d",
1347− dlm_config.ci_tcp_port, num);
1348−
1349− return result;
1350−}
1351−
13521243 /* Initialise SCTP socket and bind to all interfaces */
13531244 static int sctp_listen_for_all(void)
13541245 {
13551246 struct socket *sock = NULL;
1356− struct sockaddr_storage localaddr;
1357− struct sctp_event_subscribe subscribe;
1358− int result = -EINVAL, num = 1, i, addr_len;
1247+ int result = -EINVAL;
13591248 struct connection *con = nodeid2con(0, GFP_NOFS);
13601249 int bufsize = NEEDED_RMEM;
13611250 int one = 1;
@@ -1366,33 +1255,17 @@ static int sctp_listen_for_all(void) · 4 unmodified lines
13661255 log_print("Using SCTP for communications");
13671256
13681257 result = sock_create_kern(&init_net, dlm_local_addr[0]->ss_family,
1369− SOCK_SEQPACKET, IPPROTO_SCTP, &sock);
1258+ SOCK_STREAM, IPPROTO_SCTP, &sock);
13701259 if (result < 0) {
13711260 log_print("Can't create comms socket, check SCTP is loaded");
13721261 goto out;
13731262 }
13741263
1375− /* Listen for events */
1376− memset(&subscribe, 0, sizeof(subscribe));
1377− subscribe.sctp_data_io_event = 1;
1378− subscribe.sctp_association_event = 1;
1379− subscribe.sctp_send_failure_event = 1;
1380− subscribe.sctp_shutdown_event = 1;
1381− subscribe.sctp_partial_delivery_event = 1;
1382−
13831264 result = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE,
13841265 (char *)&bufsize, sizeof(bufsize));
13851266 if (result)
13861267 log_print("Error increasing buffer space on socket %d", result);
13871268
1388− result = kernel_setsockopt(sock, SOL_SCTP, SCTP_EVENTS,
1389− (char *)&subscribe, sizeof(subscribe));
1390− if (result < 0) {
1391− log_print("Failed to set SCTP_EVENTS on socket: result=%d",
1392− result);
1393− goto create_delsock;
1394− }
1395−
13961269 result = kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one,
13971270 sizeof(one));
13981271 if (result < 0)
@@ -1402,19 +1275,12 @@ static int sctp_listen_for_all(void) · 3 unmodified lines
14021275 sock->sk->sk_user_data = con;
14031276 con->sock = sock;
14041277 con->sock->sk->sk_data_ready = lowcomms_data_ready;
1405− con->rx_action = receive_from_sock;
1406− con->connect_action = sctp_init_assoc;
1278+ con->rx_action = sctp_accept_from_sock;
1279+ con->connect_action = sctp_connect_to_sock;
14071280
1408− /* Bind to all interfaces. */
1409− for (i = 0; i < dlm_local_count; i++) {
1410− memcpy(&localaddr, dlm_local_addr[i], sizeof(localaddr));
1411− make_sockaddr(&localaddr, dlm_config.ci_tcp_port, &addr_len);
1412−
1413− result = add_sctp_bind_addr(con, &localaddr, addr_len, num);
1414− if (result)
1415− goto create_delsock;
1416− ++num;
1417− }
1281+ /* Bind to all addresses. */
1282+ if (sctp_bind_addrs(con, dlm_config.ci_tcp_port))
1283+ goto create_delsock;
14181284
14191285 result = sock->ops->listen(sock, 5);
14201286 if (result < 0) {
@@ -1612,14 +1478,13 @@ out: · 191 unmodified lines
16121478
16131479 send_error:
16141480 mutex_unlock(&con->sock_mutex);
1615− close_connection(con, false);
1481+ close_connection(con, false, false, true);
16161482 lowcomms_connect_sock(con);
16171483 return;
16181484
16191485 out_connect:
16201486 mutex_unlock(&con->sock_mutex);
1621− if (!test_bit(CF_INIT_PENDING, &con->flags))
1622− lowcomms_connect_sock(con);
1487+ lowcomms_connect_sock(con);
16231488 }
16241489
16251490 static void clean_one_writequeue(struct connection *con)
@@ -1644,15 +1509,9 @@ int dlm_lowcomms_close(int nodeid) · 18 unmodified lines
16441509 log_print("closing connection to node %d", nodeid);
16451510 con = nodeid2con(nodeid, 0);
16461511 if (con) {
1647− clear_bit(CF_CONNECT_PENDING, &con->flags);
1648− clear_bit(CF_WRITE_PENDING, &con->flags);
16491512 set_bit(CF_CLOSE, &con->flags);
1650− if (cancel_work_sync(&con->swork))
1651− log_print("canceled swork for node %d", nodeid);
1652− if (cancel_work_sync(&con->rwork))
1653− log_print("canceled rwork for node %d", nodeid);
1513+ close_connection(con, true, true, true);
16541514 clean_one_writequeue(con);
1655− close_connection(con, true);
16561515 }
16571516
16581517 spin_lock(&dlm_node_addrs_spin);
@@ -1685,10 +1544,8 @@ static void process_send_sockets(struct work_struct *work) · 26 unmodified lines
16851544 {
16861545 struct connection *con = container_of(work, struct connection, swork);
16871546
1688− if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags)) {
1547+ if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags))
16891548 con->connect_action(con);
1690− set_bit(CF_WRITE_PENDING, &con->flags);
1691− }
16921549 if (test_and_clear_bit(CF_WRITE_PENDING, &con->flags))
16931550 send_to_sock(con);
16941551 }
@@ -1735,7 +1592,7 @@ static void stop_conn(struct connection *con) · 40 unmodified lines
17351592
17361593 static void free_conn(struct connection *con)
17371594 {
1738− close_connection(con, true);
1595+ close_connection(con, true, true, true);
17391596 if (con->othercon)
17401597 kmem_cache_free(con_cache, con->othercon);
17411598 hlist_del(&con->list);
@@ -1806,7 +1663,7 @@ fail_unlisten: · 64 unmodified lines
18061663 dlm_allow_conn = 0;
18071664 con = nodeid2con(0,0);
18081665 if (con) {
1809− close_connection(con, false);
1666+ close_connection(con, false, true, true);
18101667 kmem_cache_free(con_cache, con);
18111668 }
18121669 fail_destroy:
fs/dlm/user.c+4−3
@@ -782,6 +782,7 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count, · 781 unmodified lines
782782 DECLARE_WAITQUEUE(wait, current);
783783 struct dlm_callback cb;
784784 int rv, resid, copy_lvb = 0;
785+ int old_mode, new_mode;
785786
786787 if (count == sizeof(struct dlm_device_version)) {
787788 rv = copy_version_to_user(buf, count);
@@ -838,6 +839,9 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count, · 50 unmodified lines
838839
839840 lkb = list_entry(proc->asts.next, struct dlm_lkb, lkb_cb_list);
840841
842+ /* rem_lkb_callback sets a new lkb_last_cast */
843+ old_mode = lkb->lkb_last_cast.mode;
844+
841845 rv = dlm_rem_lkb_callback(lkb->lkb_resource->res_ls, lkb, &cb, &resid);
842846 if (rv < 0) {
843847 /* this shouldn't happen; lkb should have been removed from
@@ -861,9 +865,6 @@ static ssize_t device_read(struct file *file, char __user *buf, size_t count, · 17 unmodified lines
861865 }
862866
863867 if (cb.flags & DLM_CB_CAST) {
864− int old_mode, new_mode;
865−
866− old_mode = lkb->lkb_last_cast.mode;
867868 new_mode = cb.mode;
868869
869870 if (!cb.sb_status && lkb->lkb_lksb->sb_lvbptr &&
include/uapi/linux/dlm_device.h+1−1
@@ -26,7 +26,7 @@ · 25 unmodified lines
2626 /* Version of the device interface */
2727 #define DLM_DEVICE_VERSION_MAJOR 6
2828 #define DLM_DEVICE_VERSION_MINOR 0
29−#define DLM_DEVICE_VERSION_PATCH 1
29+#define DLM_DEVICE_VERSION_PATCH 2
3030
3131 /* struct passed to the lock write */
3232 struct dlm_lock_params {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t