aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_receiver.c
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2011-03-30 06:54:42 -0400
committerPhilipp Reisner <philipp.reisner@linbit.com>2012-11-08 10:45:09 -0500
commite658983af6e62304be785cd6b0ae756723057395 (patch)
tree6dd2e2c85c704fb353d02feeb25cfc44613405e1 /drivers/block/drbd/drbd_receiver.c
parent50d0b1ad78b99aa776c3ddf9b1d45163fff435b9 (diff)
drbd: Remove headers from on-the-wire data structures (struct p_*)
Prepare the introduction of the protocol 100 headers. The actual protocol header is removed for the packet declarations. I.e. allow us to use the packets with different headers. Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Diffstat (limited to 'drivers/block/drbd/drbd_receiver.c')
-rw-r--r--drivers/block/drbd/drbd_receiver.c172
1 files changed, 87 insertions, 85 deletions
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 74ed3ac263f3..7e0ab2246fb6 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -52,6 +52,7 @@ struct packet_info {
52 enum drbd_packet cmd; 52 enum drbd_packet cmd;
53 unsigned int size; 53 unsigned int size;
54 unsigned int vnr; 54 unsigned int vnr;
55 void *data;
55}; 56};
56 57
57enum finish_epoch { 58enum finish_epoch {
@@ -729,14 +730,14 @@ out:
729 return s_estab; 730 return s_estab;
730} 731}
731 732
732static int decode_header(struct drbd_tconn *, struct p_header *, struct packet_info *); 733static int decode_header(struct drbd_tconn *, void *, struct packet_info *);
733 734
734static int send_first_packet(struct drbd_tconn *tconn, struct drbd_socket *sock, 735static int send_first_packet(struct drbd_tconn *tconn, struct drbd_socket *sock,
735 enum drbd_packet cmd) 736 enum drbd_packet cmd)
736{ 737{
737 if (!conn_prepare_command(tconn, sock)) 738 if (!conn_prepare_command(tconn, sock))
738 return -EIO; 739 return -EIO;
739 return conn_send_command(tconn, sock, cmd, sizeof(struct p_header), NULL, 0); 740 return conn_send_command(tconn, sock, cmd, 0, NULL, 0);
740} 741}
741 742
742static int receive_first_packet(struct drbd_tconn *tconn, struct socket *sock) 743static int receive_first_packet(struct drbd_tconn *tconn, struct socket *sock)
@@ -978,36 +979,43 @@ out_release_sockets:
978 return -1; 979 return -1;
979} 980}
980 981
981static int decode_header(struct drbd_tconn *tconn, struct p_header *h, struct packet_info *pi) 982static int decode_header(struct drbd_tconn *tconn, void *header, struct packet_info *pi)
982{ 983{
983 if (h->h80.magic == cpu_to_be32(DRBD_MAGIC)) { 984 unsigned int header_size = drbd_header_size(tconn);
984 pi->cmd = be16_to_cpu(h->h80.command); 985
985 pi->size = be16_to_cpu(h->h80.length); 986 if (header_size == sizeof(struct p_header95) &&
986 pi->vnr = 0; 987 *(__be16 *)header == cpu_to_be16(DRBD_MAGIC_BIG)) {
987 } else if (h->h95.magic == cpu_to_be16(DRBD_MAGIC_BIG)) { 988 struct p_header95 *h = header;
988 pi->cmd = be16_to_cpu(h->h95.command); 989
989 pi->size = be32_to_cpu(h->h95.length) & 0x00ffffff; 990 pi->cmd = be16_to_cpu(h->command);
991 pi->size = be32_to_cpu(h->length) & 0x00ffffff;
992 pi->vnr = 0;
993 } else if (header_size == sizeof(struct p_header80) &&
994 *(__be32 *)header == cpu_to_be32(DRBD_MAGIC)) {
995 struct p_header80 *h = header;
996 pi->cmd = be16_to_cpu(h->command);
997 pi->size = be16_to_cpu(h->length);
990 pi->vnr = 0; 998 pi->vnr = 0;
991 } else { 999 } else {
992 conn_err(tconn, "magic?? on data m: 0x%08x c: %d l: %d\n", 1000 conn_err(tconn, "Wrong magic value 0x%08x in protocol version %d\n",
993 be32_to_cpu(h->h80.magic), 1001 be32_to_cpu(*(__be32 *)header),
994 be16_to_cpu(h->h80.command), 1002 tconn->agreed_pro_version);
995 be16_to_cpu(h->h80.length));
996 return -EINVAL; 1003 return -EINVAL;
997 } 1004 }
1005 pi->data = header + header_size;
998 return 0; 1006 return 0;
999} 1007}
1000 1008
1001static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi) 1009static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi)
1002{ 1010{
1003 struct p_header *h = tconn->data.rbuf; 1011 void *buffer = tconn->data.rbuf;
1004 int err; 1012 int err;
1005 1013
1006 err = drbd_recv_all_warn(tconn, h, drbd_header_size(tconn)); 1014 err = drbd_recv_all_warn(tconn, buffer, drbd_header_size(tconn));
1007 if (err) 1015 if (err)
1008 return err; 1016 return err;
1009 1017
1010 err = decode_header(tconn, h, pi); 1018 err = decode_header(tconn, buffer, pi);
1011 tconn->last_received = jiffies; 1019 tconn->last_received = jiffies;
1012 1020
1013 return err; 1021 return err;
@@ -1242,7 +1250,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
1242{ 1250{
1243 struct drbd_conf *mdev; 1251 struct drbd_conf *mdev;
1244 int rv; 1252 int rv;
1245 struct p_barrier *p = tconn->data.rbuf; 1253 struct p_barrier *p = pi->data;
1246 struct drbd_epoch *epoch; 1254 struct drbd_epoch *epoch;
1247 1255
1248 mdev = vnr_to_mdev(tconn, pi->vnr); 1256 mdev = vnr_to_mdev(tconn, pi->vnr);
@@ -1560,7 +1568,7 @@ static int receive_DataReply(struct drbd_tconn *tconn, struct packet_info *pi)
1560 struct drbd_request *req; 1568 struct drbd_request *req;
1561 sector_t sector; 1569 sector_t sector;
1562 int err; 1570 int err;
1563 struct p_data *p = tconn->data.rbuf; 1571 struct p_data *p = pi->data;
1564 1572
1565 mdev = vnr_to_mdev(tconn, pi->vnr); 1573 mdev = vnr_to_mdev(tconn, pi->vnr);
1566 if (!mdev) 1574 if (!mdev)
@@ -1592,7 +1600,7 @@ static int receive_RSDataReply(struct drbd_tconn *tconn, struct packet_info *pi)
1592 struct drbd_conf *mdev; 1600 struct drbd_conf *mdev;
1593 sector_t sector; 1601 sector_t sector;
1594 int err; 1602 int err;
1595 struct p_data *p = tconn->data.rbuf; 1603 struct p_data *p = pi->data;
1596 1604
1597 mdev = vnr_to_mdev(tconn, pi->vnr); 1605 mdev = vnr_to_mdev(tconn, pi->vnr);
1598 if (!mdev) 1606 if (!mdev)
@@ -1985,7 +1993,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
1985 struct drbd_conf *mdev; 1993 struct drbd_conf *mdev;
1986 sector_t sector; 1994 sector_t sector;
1987 struct drbd_peer_request *peer_req; 1995 struct drbd_peer_request *peer_req;
1988 struct p_data *p = tconn->data.rbuf; 1996 struct p_data *p = pi->data;
1989 u32 peer_seq = be32_to_cpu(p->seq_num); 1997 u32 peer_seq = be32_to_cpu(p->seq_num);
1990 int rw = WRITE; 1998 int rw = WRITE;
1991 u32 dp_flags; 1999 u32 dp_flags;
@@ -2173,7 +2181,7 @@ static int receive_DataRequest(struct drbd_tconn *tconn, struct packet_info *pi)
2173 struct digest_info *di = NULL; 2181 struct digest_info *di = NULL;
2174 int size, verb; 2182 int size, verb;
2175 unsigned int fault_type; 2183 unsigned int fault_type;
2176 struct p_block_req *p = tconn->data.rbuf; 2184 struct p_block_req *p = pi->data;
2177 2185
2178 mdev = vnr_to_mdev(tconn, pi->vnr); 2186 mdev = vnr_to_mdev(tconn, pi->vnr);
2179 if (!mdev) 2187 if (!mdev)
@@ -2893,7 +2901,7 @@ static int cmp_after_sb(enum drbd_after_sb_p peer, enum drbd_after_sb_p self)
2893 2901
2894static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi) 2902static int receive_protocol(struct drbd_tconn *tconn, struct packet_info *pi)
2895{ 2903{
2896 struct p_protocol *p = tconn->data.rbuf; 2904 struct p_protocol *p = pi->data;
2897 int p_proto, p_after_sb_0p, p_after_sb_1p, p_after_sb_2p; 2905 int p_proto, p_after_sb_0p, p_after_sb_1p, p_after_sb_2p;
2898 int p_want_lose, p_two_primaries, cf; 2906 int p_want_lose, p_two_primaries, cf;
2899 char p_integrity_alg[SHARED_SECRET_MAX] = ""; 2907 char p_integrity_alg[SHARED_SECRET_MAX] = "";
@@ -3033,7 +3041,7 @@ static int config_unknown_volume(struct drbd_tconn *tconn, struct packet_info *p
3033static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi) 3041static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi)
3034{ 3042{
3035 struct drbd_conf *mdev; 3043 struct drbd_conf *mdev;
3036 struct p_rs_param_95 *p = tconn->data.rbuf; 3044 struct p_rs_param_95 *p;
3037 unsigned int header_size, data_size, exp_max_sz; 3045 unsigned int header_size, data_size, exp_max_sz;
3038 struct crypto_hash *verify_tfm = NULL; 3046 struct crypto_hash *verify_tfm = NULL;
3039 struct crypto_hash *csums_tfm = NULL; 3047 struct crypto_hash *csums_tfm = NULL;
@@ -3059,22 +3067,23 @@ static int receive_SyncParam(struct drbd_tconn *tconn, struct packet_info *pi)
3059 } 3067 }
3060 3068
3061 if (apv <= 88) { 3069 if (apv <= 88) {
3062 header_size = sizeof(struct p_rs_param) - sizeof(struct p_header); 3070 header_size = sizeof(struct p_rs_param);
3063 data_size = pi->size - header_size; 3071 data_size = pi->size - header_size;
3064 } else if (apv <= 94) { 3072 } else if (apv <= 94) {
3065 header_size = sizeof(struct p_rs_param_89) - sizeof(struct p_header); 3073 header_size = sizeof(struct p_rs_param_89);
3066 data_size = pi->size - header_size; 3074 data_size = pi->size - header_size;
3067 D_ASSERT(data_size == 0); 3075 D_ASSERT(data_size == 0);
3068 } else { 3076 } else {
3069 header_size = sizeof(struct p_rs_param_95) - sizeof(struct p_header); 3077 header_size = sizeof(struct p_rs_param_95);
3070 data_size = pi->size - header_size; 3078 data_size = pi->size - header_size;
3071 D_ASSERT(data_size == 0); 3079 D_ASSERT(data_size == 0);
3072 } 3080 }
3073 3081
3074 /* initialize verify_alg and csums_alg */ 3082 /* initialize verify_alg and csums_alg */
3083 p = pi->data;
3075 memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX); 3084 memset(p->verify_alg, 0, 2 * SHARED_SECRET_MAX);
3076 3085
3077 err = drbd_recv_all(mdev->tconn, &p->head.payload, header_size); 3086 err = drbd_recv_all(mdev->tconn, p, header_size);
3078 if (err) 3087 if (err)
3079 return err; 3088 return err;
3080 3089
@@ -3209,7 +3218,7 @@ static void warn_if_differ_considerably(struct drbd_conf *mdev,
3209static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi) 3218static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi)
3210{ 3219{
3211 struct drbd_conf *mdev; 3220 struct drbd_conf *mdev;
3212 struct p_sizes *p = tconn->data.rbuf; 3221 struct p_sizes *p = pi->data;
3213 enum determine_dev_size dd = unchanged; 3222 enum determine_dev_size dd = unchanged;
3214 sector_t p_size, p_usize, my_usize; 3223 sector_t p_size, p_usize, my_usize;
3215 int ldsc = 0; /* local disk size changed */ 3224 int ldsc = 0; /* local disk size changed */
@@ -3311,7 +3320,7 @@ static int receive_sizes(struct drbd_tconn *tconn, struct packet_info *pi)
3311static int receive_uuids(struct drbd_tconn *tconn, struct packet_info *pi) 3320static int receive_uuids(struct drbd_tconn *tconn, struct packet_info *pi)
3312{ 3321{
3313 struct drbd_conf *mdev; 3322 struct drbd_conf *mdev;
3314 struct p_uuids *p = tconn->data.rbuf; 3323 struct p_uuids *p = pi->data;
3315 u64 *p_uuid; 3324 u64 *p_uuid;
3316 int i, updated_uuids = 0; 3325 int i, updated_uuids = 0;
3317 3326
@@ -3411,7 +3420,7 @@ static union drbd_state convert_state(union drbd_state ps)
3411static int receive_req_state(struct drbd_tconn *tconn, struct packet_info *pi) 3420static int receive_req_state(struct drbd_tconn *tconn, struct packet_info *pi)
3412{ 3421{
3413 struct drbd_conf *mdev; 3422 struct drbd_conf *mdev;
3414 struct p_req_state *p = tconn->data.rbuf; 3423 struct p_req_state *p = pi->data;
3415 union drbd_state mask, val; 3424 union drbd_state mask, val;
3416 enum drbd_state_rv rv; 3425 enum drbd_state_rv rv;
3417 3426
@@ -3441,7 +3450,7 @@ static int receive_req_state(struct drbd_tconn *tconn, struct packet_info *pi)
3441 3450
3442static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info *pi) 3451static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info *pi)
3443{ 3452{
3444 struct p_req_state *p = tconn->data.rbuf; 3453 struct p_req_state *p = pi->data;
3445 union drbd_state mask, val; 3454 union drbd_state mask, val;
3446 enum drbd_state_rv rv; 3455 enum drbd_state_rv rv;
3447 3456
@@ -3466,7 +3475,7 @@ static int receive_req_conn_state(struct drbd_tconn *tconn, struct packet_info *
3466static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi) 3475static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi)
3467{ 3476{
3468 struct drbd_conf *mdev; 3477 struct drbd_conf *mdev;
3469 struct p_state *p = tconn->data.rbuf; 3478 struct p_state *p = pi->data;
3470 union drbd_state os, ns, peer_state; 3479 union drbd_state os, ns, peer_state;
3471 enum drbd_disk_state real_peer_disk; 3480 enum drbd_disk_state real_peer_disk;
3472 enum chg_state_flags cs_flags; 3481 enum chg_state_flags cs_flags;
@@ -3623,7 +3632,7 @@ static int receive_state(struct drbd_tconn *tconn, struct packet_info *pi)
3623static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi) 3632static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi)
3624{ 3633{
3625 struct drbd_conf *mdev; 3634 struct drbd_conf *mdev;
3626 struct p_rs_uuid *p = tconn->data.rbuf; 3635 struct p_rs_uuid *p = pi->data;
3627 3636
3628 mdev = vnr_to_mdev(tconn, pi->vnr); 3637 mdev = vnr_to_mdev(tconn, pi->vnr);
3629 if (!mdev) 3638 if (!mdev)
@@ -3661,14 +3670,13 @@ static int receive_sync_uuid(struct drbd_tconn *tconn, struct packet_info *pi)
3661 */ 3670 */
3662static int 3671static int
3663receive_bitmap_plain(struct drbd_conf *mdev, unsigned int size, 3672receive_bitmap_plain(struct drbd_conf *mdev, unsigned int size,
3664 struct p_header *h, struct bm_xfer_ctx *c) 3673 unsigned long *p, struct bm_xfer_ctx *c)
3665{ 3674{
3666 unsigned long *buffer = (unsigned long *)h->payload;
3667 unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE - 3675 unsigned int data_size = DRBD_SOCKET_BUFFER_SIZE -
3668 drbd_header_size(mdev->tconn); 3676 drbd_header_size(mdev->tconn);
3669 unsigned int num_words = min_t(size_t, data_size / sizeof(unsigned long), 3677 unsigned int num_words = min_t(size_t, data_size / sizeof(*p),
3670 c->bm_words - c->word_offset); 3678 c->bm_words - c->word_offset);
3671 unsigned int want = num_words * sizeof(unsigned long); 3679 unsigned int want = num_words * sizeof(*p);
3672 int err; 3680 int err;
3673 3681
3674 if (want != size) { 3682 if (want != size) {
@@ -3677,11 +3685,11 @@ receive_bitmap_plain(struct drbd_conf *mdev, unsigned int size,
3677 } 3685 }
3678 if (want == 0) 3686 if (want == 0)
3679 return 0; 3687 return 0;
3680 err = drbd_recv_all(mdev->tconn, buffer, want); 3688 err = drbd_recv_all(mdev->tconn, p, want);
3681 if (err) 3689 if (err)
3682 return err; 3690 return err;
3683 3691
3684 drbd_bm_merge_lel(mdev, c->word_offset, num_words, buffer); 3692 drbd_bm_merge_lel(mdev, c->word_offset, num_words, p);
3685 3693
3686 c->word_offset += num_words; 3694 c->word_offset += num_words;
3687 c->bit_offset = c->word_offset * BITS_PER_LONG; 3695 c->bit_offset = c->word_offset * BITS_PER_LONG;
@@ -3784,7 +3792,7 @@ decode_bitmap_c(struct drbd_conf *mdev,
3784 unsigned int len) 3792 unsigned int len)
3785{ 3793{
3786 if (dcbp_get_code(p) == RLE_VLI_Bits) 3794 if (dcbp_get_code(p) == RLE_VLI_Bits)
3787 return recv_bm_rle_bits(mdev, p, c, len); 3795 return recv_bm_rle_bits(mdev, p, c, len - sizeof(*p));
3788 3796
3789 /* other variants had been implemented for evaluation, 3797 /* other variants had been implemented for evaluation,
3790 * but have been dropped as this one turned out to be "best" 3798 * but have been dropped as this one turned out to be "best"
@@ -3844,7 +3852,6 @@ static int receive_bitmap(struct drbd_tconn *tconn, struct packet_info *pi)
3844 struct drbd_conf *mdev; 3852 struct drbd_conf *mdev;
3845 struct bm_xfer_ctx c; 3853 struct bm_xfer_ctx c;
3846 int err; 3854 int err;
3847 struct p_header *h = tconn->data.rbuf;
3848 3855
3849 mdev = vnr_to_mdev(tconn, pi->vnr); 3856 mdev = vnr_to_mdev(tconn, pi->vnr);
3850 if (!mdev) 3857 if (!mdev)
@@ -3860,28 +3867,26 @@ static int receive_bitmap(struct drbd_tconn *tconn, struct packet_info *pi)
3860 }; 3867 };
3861 3868
3862 for(;;) { 3869 for(;;) {
3863 if (pi->cmd == P_BITMAP) { 3870 if (pi->cmd == P_BITMAP)
3864 err = receive_bitmap_plain(mdev, pi->size, h, &c); 3871 err = receive_bitmap_plain(mdev, pi->size, pi->data, &c);
3865 } else if (pi->cmd == P_COMPRESSED_BITMAP) { 3872 else if (pi->cmd == P_COMPRESSED_BITMAP) {
3866 /* MAYBE: sanity check that we speak proto >= 90, 3873 /* MAYBE: sanity check that we speak proto >= 90,
3867 * and the feature is enabled! */ 3874 * and the feature is enabled! */
3868 struct p_compressed_bm *p; 3875 struct p_compressed_bm *p = pi->data;
3869 3876
3870 if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(tconn)) { 3877 if (pi->size > DRBD_SOCKET_BUFFER_SIZE - drbd_header_size(tconn)) {
3871 dev_err(DEV, "ReportCBitmap packet too large\n"); 3878 dev_err(DEV, "ReportCBitmap packet too large\n");
3872 err = -EIO; 3879 err = -EIO;
3873 goto out; 3880 goto out;
3874 } 3881 }
3875 3882 if (pi->size <= sizeof(*p)) {
3876 p = mdev->tconn->data.rbuf;
3877 err = drbd_recv_all(mdev->tconn, p->head.payload, pi->size);
3878 if (err)
3879 goto out;
3880 if (pi->size <= (sizeof(*p) - sizeof(p->head))) {
3881 dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", pi->size); 3883 dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", pi->size);
3882 err = -EIO; 3884 err = -EIO;
3883 goto out; 3885 goto out;
3884 } 3886 }
3887 err = drbd_recv_all(mdev->tconn, p, pi->size);
3888 if (err)
3889 goto out;
3885 err = decode_bitmap_c(mdev, p, &c, pi->size); 3890 err = decode_bitmap_c(mdev, p, &c, pi->size);
3886 } else { 3891 } else {
3887 dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd); 3892 dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", pi->cmd);
@@ -3948,7 +3953,7 @@ static int receive_UnplugRemote(struct drbd_tconn *tconn, struct packet_info *pi
3948static int receive_out_of_sync(struct drbd_tconn *tconn, struct packet_info *pi) 3953static int receive_out_of_sync(struct drbd_tconn *tconn, struct packet_info *pi)
3949{ 3954{
3950 struct drbd_conf *mdev; 3955 struct drbd_conf *mdev;
3951 struct p_block_desc *p = tconn->data.rbuf; 3956 struct p_block_desc *p = pi->data;
3952 3957
3953 mdev = vnr_to_mdev(tconn, pi->vnr); 3958 mdev = vnr_to_mdev(tconn, pi->vnr);
3954 if (!mdev) 3959 if (!mdev)
@@ -3980,13 +3985,13 @@ static struct data_cmd drbd_cmd_handler[] = {
3980 [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply }, 3985 [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply },
3981 [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } , 3986 [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } ,
3982 [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } , 3987 [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } ,
3983 [P_BITMAP] = { 1, sizeof(struct p_header), receive_bitmap } , 3988 [P_BITMAP] = { 1, 0, receive_bitmap } ,
3984 [P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header), receive_bitmap } , 3989 [P_COMPRESSED_BITMAP] = { 1, 0, receive_bitmap } ,
3985 [P_UNPLUG_REMOTE] = { 0, sizeof(struct p_header), receive_UnplugRemote }, 3990 [P_UNPLUG_REMOTE] = { 0, 0, receive_UnplugRemote },
3986 [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, 3991 [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest },
3987 [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, 3992 [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest },
3988 [P_SYNC_PARAM] = { 1, sizeof(struct p_header), receive_SyncParam }, 3993 [P_SYNC_PARAM] = { 1, 0, receive_SyncParam },
3989 [P_SYNC_PARAM89] = { 1, sizeof(struct p_header), receive_SyncParam }, 3994 [P_SYNC_PARAM89] = { 1, 0, receive_SyncParam },
3990 [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol }, 3995 [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol },
3991 [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids }, 3996 [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids },
3992 [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes }, 3997 [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes },
@@ -4003,7 +4008,6 @@ static struct data_cmd drbd_cmd_handler[] = {
4003 4008
4004static void drbdd(struct drbd_tconn *tconn) 4009static void drbdd(struct drbd_tconn *tconn)
4005{ 4010{
4006 struct p_header *header = tconn->data.rbuf;
4007 struct packet_info pi; 4011 struct packet_info pi;
4008 size_t shs; /* sub header size */ 4012 size_t shs; /* sub header size */
4009 int err; 4013 int err;
@@ -4021,14 +4025,14 @@ static void drbdd(struct drbd_tconn *tconn)
4021 goto err_out; 4025 goto err_out;
4022 } 4026 }
4023 4027
4024 shs = cmd->pkt_size - sizeof(struct p_header); 4028 shs = cmd->pkt_size;
4025 if (pi.size - shs > 0 && !cmd->expect_payload) { 4029 if (pi.size > shs && !cmd->expect_payload) {
4026 conn_err(tconn, "No payload expected %s l:%d\n", cmdname(pi.cmd), pi.size); 4030 conn_err(tconn, "No payload expected %s l:%d\n", cmdname(pi.cmd), pi.size);
4027 goto err_out; 4031 goto err_out;
4028 } 4032 }
4029 4033
4030 if (shs) { 4034 if (shs) {
4031 err = drbd_recv_all_warn(tconn, &header->payload, shs); 4035 err = drbd_recv_all_warn(tconn, pi.data, shs);
4032 if (err) 4036 if (err)
4033 goto err_out; 4037 goto err_out;
4034 pi.size -= shs; 4038 pi.size -= shs;
@@ -4219,8 +4223,8 @@ static int drbd_send_features(struct drbd_tconn *tconn)
4219static int drbd_do_features(struct drbd_tconn *tconn) 4223static int drbd_do_features(struct drbd_tconn *tconn)
4220{ 4224{
4221 /* ASSERT current == tconn->receiver ... */ 4225 /* ASSERT current == tconn->receiver ... */
4222 struct p_connection_features *p = tconn->data.rbuf; 4226 struct p_connection_features *p;
4223 const int expect = sizeof(struct p_connection_features) - sizeof(struct p_header80); 4227 const int expect = sizeof(struct p_connection_features);
4224 struct packet_info pi; 4228 struct packet_info pi;
4225 int err; 4229 int err;
4226 4230
@@ -4244,7 +4248,8 @@ static int drbd_do_features(struct drbd_tconn *tconn)
4244 return -1; 4248 return -1;
4245 } 4249 }
4246 4250
4247 err = drbd_recv_all_warn(tconn, &p->head.payload, expect); 4251 p = pi.data;
4252 err = drbd_recv_all_warn(tconn, p, expect);
4248 if (err) 4253 if (err)
4249 return 0; 4254 return 0;
4250 4255
@@ -4322,8 +4327,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn)
4322 rv = 0; 4327 rv = 0;
4323 goto fail; 4328 goto fail;
4324 } 4329 }
4325 rv = !conn_send_command(tconn, sock, P_AUTH_CHALLENGE, 4330 rv = !conn_send_command(tconn, sock, P_AUTH_CHALLENGE, 0,
4326 sizeof(struct p_header),
4327 my_challenge, CHALLENGE_LEN); 4331 my_challenge, CHALLENGE_LEN);
4328 if (!rv) 4332 if (!rv)
4329 goto fail; 4333 goto fail;
@@ -4382,8 +4386,7 @@ static int drbd_do_auth(struct drbd_tconn *tconn)
4382 rv = 0; 4386 rv = 0;
4383 goto fail; 4387 goto fail;
4384 } 4388 }
4385 rv = !conn_send_command(tconn, sock, P_AUTH_RESPONSE, 4389 rv = !conn_send_command(tconn, sock, P_AUTH_RESPONSE, 0,
4386 sizeof(struct p_header),
4387 response, resp_size); 4390 response, resp_size);
4388 if (!rv) 4391 if (!rv)
4389 goto fail; 4392 goto fail;
@@ -4482,7 +4485,7 @@ int drbdd_init(struct drbd_thread *thi)
4482 4485
4483static int got_conn_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) 4486static int got_conn_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi)
4484{ 4487{
4485 struct p_req_state_reply *p = tconn->meta.rbuf; 4488 struct p_req_state_reply *p = pi->data;
4486 int retcode = be32_to_cpu(p->retcode); 4489 int retcode = be32_to_cpu(p->retcode);
4487 4490
4488 if (retcode >= SS_SUCCESS) { 4491 if (retcode >= SS_SUCCESS) {
@@ -4500,7 +4503,7 @@ static int got_conn_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi)
4500static int got_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi) 4503static int got_RqSReply(struct drbd_tconn *tconn, struct packet_info *pi)
4501{ 4504{
4502 struct drbd_conf *mdev; 4505 struct drbd_conf *mdev;
4503 struct p_req_state_reply *p = tconn->meta.rbuf; 4506 struct p_req_state_reply *p = pi->data;
4504 int retcode = be32_to_cpu(p->retcode); 4507 int retcode = be32_to_cpu(p->retcode);
4505 4508
4506 mdev = vnr_to_mdev(tconn, pi->vnr); 4509 mdev = vnr_to_mdev(tconn, pi->vnr);
@@ -4538,7 +4541,7 @@ static int got_PingAck(struct drbd_tconn *tconn, struct packet_info *pi)
4538static int got_IsInSync(struct drbd_tconn *tconn, struct packet_info *pi) 4541static int got_IsInSync(struct drbd_tconn *tconn, struct packet_info *pi)
4539{ 4542{
4540 struct drbd_conf *mdev; 4543 struct drbd_conf *mdev;
4541 struct p_block_ack *p = tconn->meta.rbuf; 4544 struct p_block_ack *p = pi->data;
4542 sector_t sector = be64_to_cpu(p->sector); 4545 sector_t sector = be64_to_cpu(p->sector);
4543 int blksize = be32_to_cpu(p->blksize); 4546 int blksize = be32_to_cpu(p->blksize);
4544 4547
@@ -4588,7 +4591,7 @@ validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector,
4588static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi) 4591static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi)
4589{ 4592{
4590 struct drbd_conf *mdev; 4593 struct drbd_conf *mdev;
4591 struct p_block_ack *p = tconn->meta.rbuf; 4594 struct p_block_ack *p = pi->data;
4592 sector_t sector = be64_to_cpu(p->sector); 4595 sector_t sector = be64_to_cpu(p->sector);
4593 int blksize = be32_to_cpu(p->blksize); 4596 int blksize = be32_to_cpu(p->blksize);
4594 enum drbd_req_event what; 4597 enum drbd_req_event what;
@@ -4638,7 +4641,7 @@ static int got_BlockAck(struct drbd_tconn *tconn, struct packet_info *pi)
4638static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi) 4641static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi)
4639{ 4642{
4640 struct drbd_conf *mdev; 4643 struct drbd_conf *mdev;
4641 struct p_block_ack *p = tconn->meta.rbuf; 4644 struct p_block_ack *p = pi->data;
4642 sector_t sector = be64_to_cpu(p->sector); 4645 sector_t sector = be64_to_cpu(p->sector);
4643 int size = be32_to_cpu(p->blksize); 4646 int size = be32_to_cpu(p->blksize);
4644 bool missing_ok = tconn->net_conf->wire_protocol == DRBD_PROT_A || 4647 bool missing_ok = tconn->net_conf->wire_protocol == DRBD_PROT_A ||
@@ -4676,7 +4679,7 @@ static int got_NegAck(struct drbd_tconn *tconn, struct packet_info *pi)
4676static int got_NegDReply(struct drbd_tconn *tconn, struct packet_info *pi) 4679static int got_NegDReply(struct drbd_tconn *tconn, struct packet_info *pi)
4677{ 4680{
4678 struct drbd_conf *mdev; 4681 struct drbd_conf *mdev;
4679 struct p_block_ack *p = tconn->meta.rbuf; 4682 struct p_block_ack *p = pi->data;
4680 sector_t sector = be64_to_cpu(p->sector); 4683 sector_t sector = be64_to_cpu(p->sector);
4681 4684
4682 mdev = vnr_to_mdev(tconn, pi->vnr); 4685 mdev = vnr_to_mdev(tconn, pi->vnr);
@@ -4698,7 +4701,7 @@ static int got_NegRSDReply(struct drbd_tconn *tconn, struct packet_info *pi)
4698 struct drbd_conf *mdev; 4701 struct drbd_conf *mdev;
4699 sector_t sector; 4702 sector_t sector;
4700 int size; 4703 int size;
4701 struct p_block_ack *p = tconn->meta.rbuf; 4704 struct p_block_ack *p = pi->data;
4702 4705
4703 mdev = vnr_to_mdev(tconn, pi->vnr); 4706 mdev = vnr_to_mdev(tconn, pi->vnr);
4704 if (!mdev) 4707 if (!mdev)
@@ -4732,7 +4735,7 @@ static int got_NegRSDReply(struct drbd_tconn *tconn, struct packet_info *pi)
4732static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi) 4735static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi)
4733{ 4736{
4734 struct drbd_conf *mdev; 4737 struct drbd_conf *mdev;
4735 struct p_barrier_ack *p = tconn->meta.rbuf; 4738 struct p_barrier_ack *p = pi->data;
4736 4739
4737 mdev = vnr_to_mdev(tconn, pi->vnr); 4740 mdev = vnr_to_mdev(tconn, pi->vnr);
4738 if (!mdev) 4741 if (!mdev)
@@ -4753,7 +4756,7 @@ static int got_BarrierAck(struct drbd_tconn *tconn, struct packet_info *pi)
4753static int got_OVResult(struct drbd_tconn *tconn, struct packet_info *pi) 4756static int got_OVResult(struct drbd_tconn *tconn, struct packet_info *pi)
4754{ 4757{
4755 struct drbd_conf *mdev; 4758 struct drbd_conf *mdev;
4756 struct p_block_ack *p = tconn->meta.rbuf; 4759 struct p_block_ack *p = pi->data;
4757 struct drbd_work *w; 4760 struct drbd_work *w;
4758 sector_t sector; 4761 sector_t sector;
4759 int size; 4762 int size;
@@ -4837,8 +4840,8 @@ struct asender_cmd {
4837}; 4840};
4838 4841
4839static struct asender_cmd asender_tbl[] = { 4842static struct asender_cmd asender_tbl[] = {
4840 [P_PING] = { sizeof(struct p_header), got_Ping }, 4843 [P_PING] = { 0, got_Ping },
4841 [P_PING_ACK] = { sizeof(struct p_header), got_PingAck }, 4844 [P_PING_ACK] = { 0, got_PingAck },
4842 [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4845 [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
4843 [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4846 [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
4844 [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4847 [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
@@ -4859,11 +4862,10 @@ static struct asender_cmd asender_tbl[] = {
4859int drbd_asender(struct drbd_thread *thi) 4862int drbd_asender(struct drbd_thread *thi)
4860{ 4863{
4861 struct drbd_tconn *tconn = thi->tconn; 4864 struct drbd_tconn *tconn = thi->tconn;
4862 struct p_header *h = tconn->meta.rbuf;
4863 struct asender_cmd *cmd = NULL; 4865 struct asender_cmd *cmd = NULL;
4864 struct packet_info pi; 4866 struct packet_info pi;
4865 int rv; 4867 int rv;
4866 void *buf = h; 4868 void *buf = tconn->meta.rbuf;
4867 int received = 0; 4869 int received = 0;
4868 unsigned int header_size = drbd_header_size(tconn); 4870 unsigned int header_size = drbd_header_size(tconn);
4869 int expect = header_size; 4871 int expect = header_size;
@@ -4941,7 +4943,7 @@ int drbd_asender(struct drbd_thread *thi)
4941 } 4943 }
4942 4944
4943 if (received == expect && cmd == NULL) { 4945 if (received == expect && cmd == NULL) {
4944 if (decode_header(tconn, h, &pi)) 4946 if (decode_header(tconn, tconn->meta.rbuf, &pi))
4945 goto reconnect; 4947 goto reconnect;
4946 cmd = &asender_tbl[pi.cmd]; 4948 cmd = &asender_tbl[pi.cmd];
4947 if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) { 4949 if (pi.cmd >= ARRAY_SIZE(asender_tbl) || !cmd->fn) {
@@ -4949,7 +4951,7 @@ int drbd_asender(struct drbd_thread *thi)
4949 pi.cmd, pi.size); 4951 pi.cmd, pi.size);
4950 goto disconnect; 4952 goto disconnect;
4951 } 4953 }
4952 expect = cmd->pkt_size; 4954 expect = header_size + cmd->pkt_size;
4953 if (pi.size != expect - header_size) { 4955 if (pi.size != expect - header_size) {
4954 conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n", 4956 conn_err(tconn, "Wrong packet size on meta (c: %d, l: %d)\n",
4955 pi.cmd, pi.size); 4957 pi.cmd, pi.size);
@@ -4972,7 +4974,7 @@ int drbd_asender(struct drbd_thread *thi)
4972 if (cmd == &asender_tbl[P_PING_ACK]) 4974 if (cmd == &asender_tbl[P_PING_ACK])
4973 ping_timeout_active = 0; 4975 ping_timeout_active = 0;
4974 4976
4975 buf = h; 4977 buf = tconn->meta.rbuf;
4976 received = 0; 4978 received = 0;
4977 expect = header_size; 4979 expect = header_size;
4978 cmd = NULL; 4980 cmd = NULL;