~ubuntu-branches/ubuntu/saucy/linux-ti-omap4/saucy-proposed

« back to all changes in this revision

Viewing changes to net/ceph/messenger.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati, Stefan Bader, Upstream Kernel Changes
  • Date: 2012-08-15 17:17:43 UTC
  • Revision ID: package-import@ubuntu.com-20120815171743-h5wnuf51xe7pvdid
Tags: 3.5.0-207.13
[ Paolo Pisati ]

* Start new release

[ Stefan Bader ]

* (config) Enable getabis to use local package copies

[ Upstream Kernel Changes ]

* fixup: gargabe collect iva_seq[0|1] init
* [Config] enable all SND_OMAP_SOC_*s
* fixup: cm2xxx_3xxx.o is needed for omap2_cm_read|write_reg
* fixup: add some snd_soc_dai* helper functions
* fixup: s/snd_soc_dpcm_params/snd_soc_dpcm/g
* fixup: typo, no_host_mode and useless SDP4430 init
* fixup: enable again aess hwmod

Show diffs side-by-side

added added

removed removed

Lines of Context:
563
563
                m->hdr.seq = cpu_to_le64(++con->out_seq);
564
564
                m->needs_out_seq = false;
565
565
        }
 
566
#ifdef CONFIG_BLOCK
 
567
        else
 
568
                m->bio_iter = NULL;
 
569
#endif
566
570
 
567
571
        dout("prepare_write_message %p seq %lld type %d len %d+%d+%d %d pgs\n",
568
572
             m, con->out_seq, le16_to_cpu(m->hdr.type),
653
657
 * Connection negotiation.
654
658
 */
655
659
 
656
 
static int prepare_connect_authorizer(struct ceph_connection *con)
 
660
static struct ceph_auth_handshake *get_connect_authorizer(struct ceph_connection *con,
 
661
                                                int *auth_proto)
657
662
{
658
 
        void *auth_buf;
659
 
        int auth_len = 0;
660
 
        int auth_protocol = 0;
 
663
        struct ceph_auth_handshake *auth;
 
664
 
 
665
        if (!con->ops->get_authorizer) {
 
666
                con->out_connect.authorizer_protocol = CEPH_AUTH_UNKNOWN;
 
667
                con->out_connect.authorizer_len = 0;
 
668
 
 
669
                return NULL;
 
670
        }
 
671
 
 
672
        /* Can't hold the mutex while getting authorizer */
661
673
 
662
674
        mutex_unlock(&con->mutex);
663
 
        if (con->ops->get_authorizer)
664
 
                con->ops->get_authorizer(con, &auth_buf, &auth_len,
665
 
                                         &auth_protocol, &con->auth_reply_buf,
666
 
                                         &con->auth_reply_buf_len,
667
 
                                         con->auth_retry);
 
675
 
 
676
        auth = con->ops->get_authorizer(con, auth_proto, con->auth_retry);
 
677
 
668
678
        mutex_lock(&con->mutex);
669
679
 
670
 
        if (test_bit(CLOSED, &con->state) ||
671
 
            test_bit(OPENING, &con->state))
672
 
                return -EAGAIN;
673
 
 
674
 
        con->out_connect.authorizer_protocol = cpu_to_le32(auth_protocol);
675
 
        con->out_connect.authorizer_len = cpu_to_le32(auth_len);
676
 
 
677
 
        if (auth_len)
678
 
                ceph_con_out_kvec_add(con, auth_len, auth_buf);
679
 
 
680
 
        return 0;
 
680
        if (IS_ERR(auth))
 
681
                return auth;
 
682
        if (test_bit(CLOSED, &con->state) || test_bit(OPENING, &con->state))
 
683
                return ERR_PTR(-EAGAIN);
 
684
 
 
685
        con->auth_reply_buf = auth->authorizer_reply_buf;
 
686
        con->auth_reply_buf_len = auth->authorizer_reply_buf_len;
 
687
 
 
688
 
 
689
        return auth;
681
690
}
682
691
 
683
692
/*
684
693
 * We connected to a peer and are saying hello.
685
694
 */
686
 
static void prepare_write_banner(struct ceph_messenger *msgr,
687
 
                                 struct ceph_connection *con)
 
695
static void prepare_write_banner(struct ceph_connection *con)
688
696
{
689
 
        ceph_con_out_kvec_reset(con);
690
697
        ceph_con_out_kvec_add(con, strlen(CEPH_BANNER), CEPH_BANNER);
691
 
        ceph_con_out_kvec_add(con, sizeof (msgr->my_enc_addr),
692
 
                                        &msgr->my_enc_addr);
 
698
        ceph_con_out_kvec_add(con, sizeof (con->msgr->my_enc_addr),
 
699
                                        &con->msgr->my_enc_addr);
693
700
 
694
701
        con->out_more = 0;
695
702
        set_bit(WRITE_PENDING, &con->state);
696
703
}
697
704
 
698
 
static int prepare_write_connect(struct ceph_messenger *msgr,
699
 
                                 struct ceph_connection *con,
700
 
                                 int include_banner)
 
705
static int prepare_write_connect(struct ceph_connection *con)
701
706
{
702
 
        unsigned global_seq = get_global_seq(con->msgr, 0);
 
707
        unsigned int global_seq = get_global_seq(con->msgr, 0);
703
708
        int proto;
 
709
        int auth_proto;
 
710
        struct ceph_auth_handshake *auth;
704
711
 
705
712
        switch (con->peer_name.type) {
706
713
        case CEPH_ENTITY_TYPE_MON:
719
726
        dout("prepare_write_connect %p cseq=%d gseq=%d proto=%d\n", con,
720
727
             con->connect_seq, global_seq, proto);
721
728
 
722
 
        con->out_connect.features = cpu_to_le64(msgr->supported_features);
 
729
        con->out_connect.features = cpu_to_le64(con->msgr->supported_features);
723
730
        con->out_connect.host_type = cpu_to_le32(CEPH_ENTITY_TYPE_CLIENT);
724
731
        con->out_connect.connect_seq = cpu_to_le32(con->connect_seq);
725
732
        con->out_connect.global_seq = cpu_to_le32(global_seq);
726
733
        con->out_connect.protocol_version = cpu_to_le32(proto);
727
734
        con->out_connect.flags = 0;
728
735
 
729
 
        if (include_banner)
730
 
                prepare_write_banner(msgr, con);
731
 
        else
732
 
                ceph_con_out_kvec_reset(con);
733
 
        ceph_con_out_kvec_add(con, sizeof (con->out_connect), &con->out_connect);
 
736
        auth_proto = CEPH_AUTH_UNKNOWN;
 
737
        auth = get_connect_authorizer(con, &auth_proto);
 
738
        if (IS_ERR(auth))
 
739
                return PTR_ERR(auth);
 
740
 
 
741
        con->out_connect.authorizer_protocol = cpu_to_le32(auth_proto);
 
742
        con->out_connect.authorizer_len = auth ?
 
743
                cpu_to_le32(auth->authorizer_buf_len) : 0;
 
744
 
 
745
        ceph_con_out_kvec_add(con, sizeof (con->out_connect),
 
746
                                        &con->out_connect);
 
747
        if (auth && auth->authorizer_buf_len)
 
748
                ceph_con_out_kvec_add(con, auth->authorizer_buf_len,
 
749
                                        auth->authorizer_buf);
734
750
 
735
751
        con->out_more = 0;
736
752
        set_bit(WRITE_PENDING, &con->state);
737
753
 
738
 
        return prepare_connect_authorizer(con);
 
754
        return 0;
739
755
}
740
756
 
741
757
/*
816
832
static int write_partial_msg_pages(struct ceph_connection *con)
817
833
{
818
834
        struct ceph_msg *msg = con->out_msg;
819
 
        unsigned data_len = le32_to_cpu(msg->hdr.data_len);
 
835
        unsigned int data_len = le32_to_cpu(msg->hdr.data_len);
820
836
        size_t len;
821
837
        bool do_datacrc = !con->msgr->nocrc;
822
838
        int ret;
992
1008
 
993
1009
 
994
1010
static int read_partial(struct ceph_connection *con,
995
 
                        int *to, int size, void *object)
 
1011
                        int end, int size, void *object)
996
1012
{
997
 
        *to += size;
998
 
        while (con->in_base_pos < *to) {
999
 
                int left = *to - con->in_base_pos;
 
1013
        while (con->in_base_pos < end) {
 
1014
                int left = end - con->in_base_pos;
1000
1015
                int have = size - left;
1001
1016
                int ret = ceph_tcp_recvmsg(con->sock, object + have, left);
1002
1017
                if (ret <= 0)
1012
1027
 */
1013
1028
static int read_partial_banner(struct ceph_connection *con)
1014
1029
{
1015
 
        int ret, to = 0;
 
1030
        int size;
 
1031
        int end;
 
1032
        int ret;
1016
1033
 
1017
1034
        dout("read_partial_banner %p at %d\n", con, con->in_base_pos);
1018
1035
 
1019
1036
        /* peer's banner */
1020
 
        ret = read_partial(con, &to, strlen(CEPH_BANNER), con->in_banner);
1021
 
        if (ret <= 0)
1022
 
                goto out;
1023
 
        ret = read_partial(con, &to, sizeof(con->actual_peer_addr),
1024
 
                           &con->actual_peer_addr);
1025
 
        if (ret <= 0)
1026
 
                goto out;
1027
 
        ret = read_partial(con, &to, sizeof(con->peer_addr_for_me),
1028
 
                           &con->peer_addr_for_me);
1029
 
        if (ret <= 0)
1030
 
                goto out;
 
1037
        size = strlen(CEPH_BANNER);
 
1038
        end = size;
 
1039
        ret = read_partial(con, end, size, con->in_banner);
 
1040
        if (ret <= 0)
 
1041
                goto out;
 
1042
 
 
1043
        size = sizeof (con->actual_peer_addr);
 
1044
        end += size;
 
1045
        ret = read_partial(con, end, size, &con->actual_peer_addr);
 
1046
        if (ret <= 0)
 
1047
                goto out;
 
1048
 
 
1049
        size = sizeof (con->peer_addr_for_me);
 
1050
        end += size;
 
1051
        ret = read_partial(con, end, size, &con->peer_addr_for_me);
 
1052
        if (ret <= 0)
 
1053
                goto out;
 
1054
 
1031
1055
out:
1032
1056
        return ret;
1033
1057
}
1034
1058
 
1035
1059
static int read_partial_connect(struct ceph_connection *con)
1036
1060
{
1037
 
        int ret, to = 0;
 
1061
        int size;
 
1062
        int end;
 
1063
        int ret;
1038
1064
 
1039
1065
        dout("read_partial_connect %p at %d\n", con, con->in_base_pos);
1040
1066
 
1041
 
        ret = read_partial(con, &to, sizeof(con->in_reply), &con->in_reply);
 
1067
        size = sizeof (con->in_reply);
 
1068
        end = size;
 
1069
        ret = read_partial(con, end, size, &con->in_reply);
1042
1070
        if (ret <= 0)
1043
1071
                goto out;
1044
 
        ret = read_partial(con, &to, le32_to_cpu(con->in_reply.authorizer_len),
1045
 
                           con->auth_reply_buf);
 
1072
 
 
1073
        size = le32_to_cpu(con->in_reply.authorizer_len);
 
1074
        end += size;
 
1075
        ret = read_partial(con, end, size, con->auth_reply_buf);
1046
1076
        if (ret <= 0)
1047
1077
                goto out;
1048
1078
 
1377
1407
                        return -1;
1378
1408
                }
1379
1409
                con->auth_retry = 1;
1380
 
                ret = prepare_write_connect(con->msgr, con, 0);
 
1410
                ceph_con_out_kvec_reset(con);
 
1411
                ret = prepare_write_connect(con);
1381
1412
                if (ret < 0)
1382
1413
                        return ret;
1383
1414
                prepare_read_connect(con);
1392
1423
                 * dropped messages.
1393
1424
                 */
1394
1425
                dout("process_connect got RESET peer seq %u\n",
1395
 
                     le32_to_cpu(con->in_connect.connect_seq));
 
1426
                     le32_to_cpu(con->in_reply.connect_seq));
1396
1427
                pr_err("%s%lld %s connection reset\n",
1397
1428
                       ENTITY_NAME(con->peer_name),
1398
1429
                       ceph_pr_addr(&con->peer_addr.in_addr));
1399
1430
                reset_connection(con);
1400
 
                prepare_write_connect(con->msgr, con, 0);
 
1431
                ceph_con_out_kvec_reset(con);
 
1432
                ret = prepare_write_connect(con);
 
1433
                if (ret < 0)
 
1434
                        return ret;
1401
1435
                prepare_read_connect(con);
1402
1436
 
1403
1437
                /* Tell ceph about it. */
1416
1450
                 * If we sent a smaller connect_seq than the peer has, try
1417
1451
                 * again with a larger value.
1418
1452
                 */
1419
 
                dout("process_connect got RETRY my seq = %u, peer_seq = %u\n",
 
1453
                dout("process_connect got RETRY_SESSION my seq %u, peer %u\n",
1420
1454
                     le32_to_cpu(con->out_connect.connect_seq),
1421
 
                     le32_to_cpu(con->in_connect.connect_seq));
1422
 
                con->connect_seq = le32_to_cpu(con->in_connect.connect_seq);
1423
 
                prepare_write_connect(con->msgr, con, 0);
 
1455
                     le32_to_cpu(con->in_reply.connect_seq));
 
1456
                con->connect_seq = le32_to_cpu(con->in_reply.connect_seq);
 
1457
                ceph_con_out_kvec_reset(con);
 
1458
                ret = prepare_write_connect(con);
 
1459
                if (ret < 0)
 
1460
                        return ret;
1424
1461
                prepare_read_connect(con);
1425
1462
                break;
1426
1463
 
1431
1468
                 */
1432
1469
                dout("process_connect got RETRY_GLOBAL my %u peer_gseq %u\n",
1433
1470
                     con->peer_global_seq,
1434
 
                     le32_to_cpu(con->in_connect.global_seq));
 
1471
                     le32_to_cpu(con->in_reply.global_seq));
1435
1472
                get_global_seq(con->msgr,
1436
 
                               le32_to_cpu(con->in_connect.global_seq));
1437
 
                prepare_write_connect(con->msgr, con, 0);
 
1473
                               le32_to_cpu(con->in_reply.global_seq));
 
1474
                ceph_con_out_kvec_reset(con);
 
1475
                ret = prepare_write_connect(con);
 
1476
                if (ret < 0)
 
1477
                        return ret;
1438
1478
                prepare_read_connect(con);
1439
1479
                break;
1440
1480
 
1491
1531
 */
1492
1532
static int read_partial_ack(struct ceph_connection *con)
1493
1533
{
1494
 
        int to = 0;
 
1534
        int size = sizeof (con->in_temp_ack);
 
1535
        int end = size;
1495
1536
 
1496
 
        return read_partial(con, &to, sizeof(con->in_temp_ack),
1497
 
                            &con->in_temp_ack);
 
1537
        return read_partial(con, end, size, &con->in_temp_ack);
1498
1538
}
1499
1539
 
1500
1540
 
1554
1594
 
1555
1595
static int read_partial_message_pages(struct ceph_connection *con,
1556
1596
                                      struct page **pages,
1557
 
                                      unsigned data_len, bool do_datacrc)
 
1597
                                      unsigned int data_len, bool do_datacrc)
1558
1598
{
1559
1599
        void *p;
1560
1600
        int ret;
1587
1627
#ifdef CONFIG_BLOCK
1588
1628
static int read_partial_message_bio(struct ceph_connection *con,
1589
1629
                                    struct bio **bio_iter, int *bio_seg,
1590
 
                                    unsigned data_len, bool do_datacrc)
 
1630
                                    unsigned int data_len, bool do_datacrc)
1591
1631
{
1592
1632
        struct bio_vec *bv = bio_iovec_idx(*bio_iter, *bio_seg);
1593
1633
        void *p;
1627
1667
static int read_partial_message(struct ceph_connection *con)
1628
1668
{
1629
1669
        struct ceph_msg *m = con->in_msg;
 
1670
        int size;
 
1671
        int end;
1630
1672
        int ret;
1631
 
        int to, left;
1632
 
        unsigned front_len, middle_len, data_len;
 
1673
        unsigned int front_len, middle_len, data_len;
1633
1674
        bool do_datacrc = !con->msgr->nocrc;
1634
1675
        int skip;
1635
1676
        u64 seq;
1638
1679
        dout("read_partial_message con %p msg %p\n", con, m);
1639
1680
 
1640
1681
        /* header */
1641
 
        while (con->in_base_pos < sizeof(con->in_hdr)) {
1642
 
                left = sizeof(con->in_hdr) - con->in_base_pos;
1643
 
                ret = ceph_tcp_recvmsg(con->sock,
1644
 
                                       (char *)&con->in_hdr + con->in_base_pos,
1645
 
                                       left);
1646
 
                if (ret <= 0)
1647
 
                        return ret;
1648
 
                con->in_base_pos += ret;
1649
 
        }
 
1682
        size = sizeof (con->in_hdr);
 
1683
        end = size;
 
1684
        ret = read_partial(con, end, size, &con->in_hdr);
 
1685
        if (ret <= 0)
 
1686
                return ret;
1650
1687
 
1651
1688
        crc = crc32c(0, &con->in_hdr, offsetof(struct ceph_msg_header, crc));
1652
1689
        if (cpu_to_le32(crc) != con->in_hdr.crc) {
1759
1796
        }
1760
1797
 
1761
1798
        /* footer */
1762
 
        to = sizeof(m->hdr) + sizeof(m->footer);
1763
 
        while (con->in_base_pos < to) {
1764
 
                left = to - con->in_base_pos;
1765
 
                ret = ceph_tcp_recvmsg(con->sock, (char *)&m->footer +
1766
 
                                       (con->in_base_pos - sizeof(m->hdr)),
1767
 
                                       left);
1768
 
                if (ret <= 0)
1769
 
                        return ret;
1770
 
                con->in_base_pos += ret;
1771
 
        }
 
1799
        size = sizeof (m->footer);
 
1800
        end += size;
 
1801
        ret = read_partial(con, end, size, &m->footer);
 
1802
        if (ret <= 0)
 
1803
                return ret;
 
1804
 
1772
1805
        dout("read_partial_message got msg %p %d (%u) + %d (%u) + %d (%u)\n",
1773
1806
             m, front_len, m->footer.front_crc, middle_len,
1774
1807
             m->footer.middle_crc, data_len, m->footer.data_crc);
1835
1868
 */
1836
1869
static int try_write(struct ceph_connection *con)
1837
1870
{
1838
 
        struct ceph_messenger *msgr = con->msgr;
1839
1871
        int ret = 1;
1840
1872
 
1841
1873
        dout("try_write start %p state %lu nref %d\n", con, con->state,
1846
1878
 
1847
1879
        /* open the socket first? */
1848
1880
        if (con->sock == NULL) {
1849
 
                prepare_write_connect(msgr, con, 1);
 
1881
                ceph_con_out_kvec_reset(con);
 
1882
                prepare_write_banner(con);
 
1883
                ret = prepare_write_connect(con);
 
1884
                if (ret < 0)
 
1885
                        goto out;
1850
1886
                prepare_read_banner(con);
1851
1887
                set_bit(CONNECTING, &con->state);
1852
1888
                clear_bit(NEGOTIATING, &con->state);
2345
2381
{
2346
2382
        mutex_lock(&con->mutex);
2347
2383
        if (con->in_msg && con->in_msg == msg) {
2348
 
                unsigned front_len = le32_to_cpu(con->in_hdr.front_len);
2349
 
                unsigned middle_len = le32_to_cpu(con->in_hdr.middle_len);
2350
 
                unsigned data_len = le32_to_cpu(con->in_hdr.data_len);
 
2384
                unsigned int front_len = le32_to_cpu(con->in_hdr.front_len);
 
2385
                unsigned int middle_len = le32_to_cpu(con->in_hdr.middle_len);
 
2386
                unsigned int data_len = le32_to_cpu(con->in_hdr.data_len);
2351
2387
 
2352
2388
                /* skip rest of message */
2353
2389
                dout("con_revoke_pages %p msg %p revoked\n", con, msg);