aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_receiver.c
diff options
context:
space:
mode:
authorPhilipp Reisner <philipp.reisner@linbit.com>2011-01-26 06:15:29 -0500
committerPhilipp Reisner <philipp.reisner@linbit.com>2011-09-28 04:26:18 -0400
commit257d0af689df9aaf6ebecfc8d66b15415006c257 (patch)
tree3f8f365bbc25134d84b666e653ded434401ba12e /drivers/block/drbd/drbd_receiver.c
parentfd340c12c98b57ec0751ebb317057eee41be0c3d (diff)
drbd: Implemented receiving of new style packets on meta socket
Now drbd communication with protocol 100 actually works. Replaced the remaining p_header80 with p_header where we no longer know which header it is. In the places where p_header80 is still in use, it is on purpose, because we know that it is an old style header there. 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.c133
1 files changed, 68 insertions, 65 deletions
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 8f5a241fe20a..c0435c4f5d84 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -926,18 +926,9 @@ out_release_sockets:
926 return -1; 926 return -1;
927} 927}
928 928
929static int drbd_recv_header(struct drbd_conf *mdev, enum drbd_packets *cmd, unsigned int *packet_size) 929static bool decode_header(struct drbd_conf *mdev, struct p_header *h, enum drbd_packets *cmd,
930 unsigned int *packet_size)
930{ 931{
931 struct p_header *h = &mdev->tconn->data.rbuf.header;
932 int r;
933
934 r = drbd_recv(mdev, h, sizeof(*h));
935 if (unlikely(r != sizeof(*h))) {
936 if (!signal_pending(current))
937 dev_warn(DEV, "short read expecting header on sock: r=%d\n", r);
938 return false;
939 }
940
941 if (h->h80.magic == cpu_to_be32(DRBD_MAGIC)) { 932 if (h->h80.magic == cpu_to_be32(DRBD_MAGIC)) {
942 *cmd = be16_to_cpu(h->h80.command); 933 *cmd = be16_to_cpu(h->h80.command);
943 *packet_size = be16_to_cpu(h->h80.length); 934 *packet_size = be16_to_cpu(h->h80.length);
@@ -951,9 +942,25 @@ static int drbd_recv_header(struct drbd_conf *mdev, enum drbd_packets *cmd, unsi
951 be16_to_cpu(h->h80.length)); 942 be16_to_cpu(h->h80.length));
952 return false; 943 return false;
953 } 944 }
945 return true;
946}
947
948static int drbd_recv_header(struct drbd_conf *mdev, enum drbd_packets *cmd, unsigned int *packet_size)
949{
950 struct p_header *h = &mdev->tconn->data.rbuf.header;
951 int r;
952
953 r = drbd_recv(mdev, h, sizeof(*h));
954 if (unlikely(r != sizeof(*h))) {
955 if (!signal_pending(current))
956 dev_warn(DEV, "short read expecting header on sock: r=%d\n", r);
957 return false;
958 }
959
960 r = decode_header(mdev, h, cmd, packet_size);
954 mdev->tconn->last_received = jiffies; 961 mdev->tconn->last_received = jiffies;
955 962
956 return true; 963 return r;
957} 964}
958 965
959static void drbd_flush(struct drbd_conf *mdev) 966static void drbd_flush(struct drbd_conf *mdev)
@@ -2807,14 +2814,14 @@ static int receive_SyncParam(struct drbd_conf *mdev, enum drbd_packets cmd, unsi
2807 } 2814 }
2808 2815
2809 if (apv <= 88) { 2816 if (apv <= 88) {
2810 header_size = sizeof(struct p_rs_param) - sizeof(struct p_header80); 2817 header_size = sizeof(struct p_rs_param) - sizeof(struct p_header);
2811 data_size = packet_size - header_size; 2818 data_size = packet_size - header_size;
2812 } else if (apv <= 94) { 2819 } else if (apv <= 94) {
2813 header_size = sizeof(struct p_rs_param_89) - sizeof(struct p_header80); 2820 header_size = sizeof(struct p_rs_param_89) - sizeof(struct p_header);
2814 data_size = packet_size - header_size; 2821 data_size = packet_size - header_size;
2815 D_ASSERT(data_size == 0); 2822 D_ASSERT(data_size == 0);
2816 } else { 2823 } else {
2817 header_size = sizeof(struct p_rs_param_95) - sizeof(struct p_header80); 2824 header_size = sizeof(struct p_rs_param_95) - sizeof(struct p_header);
2818 data_size = packet_size - header_size; 2825 data_size = packet_size - header_size;
2819 D_ASSERT(data_size == 0); 2826 D_ASSERT(data_size == 0);
2820 } 2827 }
@@ -3524,7 +3531,7 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3524 void *buffer; 3531 void *buffer;
3525 int err; 3532 int err;
3526 int ok = false; 3533 int ok = false;
3527 struct p_header80 *h = &mdev->tconn->data.rbuf.header.h80; 3534 struct p_header *h = &mdev->tconn->data.rbuf.header;
3528 3535
3529 drbd_bm_lock(mdev, "receive bitmap", BM_LOCKED_SET_ALLOWED); 3536 drbd_bm_lock(mdev, "receive bitmap", BM_LOCKED_SET_ALLOWED);
3530 /* you are supposed to send additional out-of-sync information 3537 /* you are supposed to send additional out-of-sync information
@@ -3571,7 +3578,7 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3571 } 3578 }
3572 3579
3573 c.packets[cmd == P_BITMAP]++; 3580 c.packets[cmd == P_BITMAP]++;
3574 c.bytes[cmd == P_BITMAP] += sizeof(struct p_header80) + data_size; 3581 c.bytes[cmd == P_BITMAP] += sizeof(struct p_header) + data_size;
3575 3582
3576 if (err <= 0) { 3583 if (err <= 0) {
3577 if (err < 0) 3584 if (err < 0)
@@ -3670,13 +3677,13 @@ static struct data_cmd drbd_cmd_handler[] = {
3670 [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply }, 3677 [P_DATA_REPLY] = { 1, sizeof(struct p_data), receive_DataReply },
3671 [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } , 3678 [P_RS_DATA_REPLY] = { 1, sizeof(struct p_data), receive_RSDataReply } ,
3672 [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } , 3679 [P_BARRIER] = { 0, sizeof(struct p_barrier), receive_Barrier } ,
3673 [P_BITMAP] = { 1, sizeof(struct p_header80), receive_bitmap } , 3680 [P_BITMAP] = { 1, sizeof(struct p_header), receive_bitmap } ,
3674 [P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header80), receive_bitmap } , 3681 [P_COMPRESSED_BITMAP] = { 1, sizeof(struct p_header), receive_bitmap } ,
3675 [P_UNPLUG_REMOTE] = { 0, sizeof(struct p_header80), receive_UnplugRemote }, 3682 [P_UNPLUG_REMOTE] = { 0, sizeof(struct p_header), receive_UnplugRemote },
3676 [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, 3683 [P_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest },
3677 [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest }, 3684 [P_RS_DATA_REQUEST] = { 0, sizeof(struct p_block_req), receive_DataRequest },
3678 [P_SYNC_PARAM] = { 1, sizeof(struct p_header80), receive_SyncParam }, 3685 [P_SYNC_PARAM] = { 1, sizeof(struct p_header), receive_SyncParam },
3679 [P_SYNC_PARAM89] = { 1, sizeof(struct p_header80), receive_SyncParam }, 3686 [P_SYNC_PARAM89] = { 1, sizeof(struct p_header), receive_SyncParam },
3680 [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol }, 3687 [P_PROTOCOL] = { 1, sizeof(struct p_protocol), receive_protocol },
3681 [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids }, 3688 [P_UUIDS] = { 0, sizeof(struct p_uuids), receive_uuids },
3682 [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes }, 3689 [P_SIZES] = { 0, sizeof(struct p_sizes), receive_sizes },
@@ -4184,9 +4191,9 @@ int drbdd_init(struct drbd_thread *thi)
4184 4191
4185/* ********* acknowledge sender ******** */ 4192/* ********* acknowledge sender ******** */
4186 4193
4187static int got_RqSReply(struct drbd_conf *mdev, struct p_header80 *h) 4194static int got_RqSReply(struct drbd_conf *mdev, enum drbd_packets cmd)
4188{ 4195{
4189 struct p_req_state_reply *p = (struct p_req_state_reply *)h; 4196 struct p_req_state_reply *p = &mdev->tconn->meta.rbuf.req_state_reply;
4190 4197
4191 int retcode = be32_to_cpu(p->retcode); 4198 int retcode = be32_to_cpu(p->retcode);
4192 4199
@@ -4202,13 +4209,13 @@ static int got_RqSReply(struct drbd_conf *mdev, struct p_header80 *h)
4202 return true; 4209 return true;
4203} 4210}
4204 4211
4205static int got_Ping(struct drbd_conf *mdev, struct p_header80 *h) 4212static int got_Ping(struct drbd_conf *mdev, enum drbd_packets cmd)
4206{ 4213{
4207 return drbd_send_ping_ack(mdev); 4214 return drbd_send_ping_ack(mdev);
4208 4215
4209} 4216}
4210 4217
4211static int got_PingAck(struct drbd_conf *mdev, struct p_header80 *h) 4218static int got_PingAck(struct drbd_conf *mdev, enum drbd_packets cmd)
4212{ 4219{
4213 /* restore idle timeout */ 4220 /* restore idle timeout */
4214 mdev->tconn->meta.socket->sk->sk_rcvtimeo = mdev->tconn->net_conf->ping_int*HZ; 4221 mdev->tconn->meta.socket->sk->sk_rcvtimeo = mdev->tconn->net_conf->ping_int*HZ;
@@ -4218,9 +4225,9 @@ static int got_PingAck(struct drbd_conf *mdev, struct p_header80 *h)
4218 return true; 4225 return true;
4219} 4226}
4220 4227
4221static int got_IsInSync(struct drbd_conf *mdev, struct p_header80 *h) 4228static int got_IsInSync(struct drbd_conf *mdev, enum drbd_packets cmd)
4222{ 4229{
4223 struct p_block_ack *p = (struct p_block_ack *)h; 4230 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4224 sector_t sector = be64_to_cpu(p->sector); 4231 sector_t sector = be64_to_cpu(p->sector);
4225 int blksize = be32_to_cpu(p->blksize); 4232 int blksize = be32_to_cpu(p->blksize);
4226 4233
@@ -4263,9 +4270,9 @@ validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector,
4263 return true; 4270 return true;
4264} 4271}
4265 4272
4266static int got_BlockAck(struct drbd_conf *mdev, struct p_header80 *h) 4273static int got_BlockAck(struct drbd_conf *mdev, enum drbd_packets cmd)
4267{ 4274{
4268 struct p_block_ack *p = (struct p_block_ack *)h; 4275 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4269 sector_t sector = be64_to_cpu(p->sector); 4276 sector_t sector = be64_to_cpu(p->sector);
4270 int blksize = be32_to_cpu(p->blksize); 4277 int blksize = be32_to_cpu(p->blksize);
4271 enum drbd_req_event what; 4278 enum drbd_req_event what;
@@ -4277,7 +4284,7 @@ static int got_BlockAck(struct drbd_conf *mdev, struct p_header80 *h)
4277 dec_rs_pending(mdev); 4284 dec_rs_pending(mdev);
4278 return true; 4285 return true;
4279 } 4286 }
4280 switch (be16_to_cpu(h->command)) { 4287 switch (cmd) {
4281 case P_RS_WRITE_ACK: 4288 case P_RS_WRITE_ACK:
4282 D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C); 4289 D_ASSERT(mdev->tconn->net_conf->wire_protocol == DRBD_PROT_C);
4283 what = WRITE_ACKED_BY_PEER_AND_SIS; 4290 what = WRITE_ACKED_BY_PEER_AND_SIS;
@@ -4304,9 +4311,9 @@ static int got_BlockAck(struct drbd_conf *mdev, struct p_header80 *h)
4304 what, false); 4311 what, false);
4305} 4312}
4306 4313
4307static int got_NegAck(struct drbd_conf *mdev, struct p_header80 *h) 4314static int got_NegAck(struct drbd_conf *mdev, enum drbd_packets cmd)
4308{ 4315{
4309 struct p_block_ack *p = (struct p_block_ack *)h; 4316 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4310 sector_t sector = be64_to_cpu(p->sector); 4317 sector_t sector = be64_to_cpu(p->sector);
4311 int size = be32_to_cpu(p->blksize); 4318 int size = be32_to_cpu(p->blksize);
4312 bool missing_ok = mdev->tconn->net_conf->wire_protocol == DRBD_PROT_A || 4319 bool missing_ok = mdev->tconn->net_conf->wire_protocol == DRBD_PROT_A ||
@@ -4337,9 +4344,9 @@ static int got_NegAck(struct drbd_conf *mdev, struct p_header80 *h)
4337 return true; 4344 return true;
4338} 4345}
4339 4346
4340static int got_NegDReply(struct drbd_conf *mdev, struct p_header80 *h) 4347static int got_NegDReply(struct drbd_conf *mdev, enum drbd_packets cmd)
4341{ 4348{
4342 struct p_block_ack *p = (struct p_block_ack *)h; 4349 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4343 sector_t sector = be64_to_cpu(p->sector); 4350 sector_t sector = be64_to_cpu(p->sector);
4344 4351
4345 update_peer_seq(mdev, be32_to_cpu(p->seq_num)); 4352 update_peer_seq(mdev, be32_to_cpu(p->seq_num));
@@ -4351,11 +4358,11 @@ static int got_NegDReply(struct drbd_conf *mdev, struct p_header80 *h)
4351 NEG_ACKED, false); 4358 NEG_ACKED, false);
4352} 4359}
4353 4360
4354static int got_NegRSDReply(struct drbd_conf *mdev, struct p_header80 *h) 4361static int got_NegRSDReply(struct drbd_conf *mdev, enum drbd_packets cmd)
4355{ 4362{
4356 sector_t sector; 4363 sector_t sector;
4357 int size; 4364 int size;
4358 struct p_block_ack *p = (struct p_block_ack *)h; 4365 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4359 4366
4360 sector = be64_to_cpu(p->sector); 4367 sector = be64_to_cpu(p->sector);
4361 size = be32_to_cpu(p->blksize); 4368 size = be32_to_cpu(p->blksize);
@@ -4366,7 +4373,7 @@ static int got_NegRSDReply(struct drbd_conf *mdev, struct p_header80 *h)
4366 4373
4367 if (get_ldev_if_state(mdev, D_FAILED)) { 4374 if (get_ldev_if_state(mdev, D_FAILED)) {
4368 drbd_rs_complete_io(mdev, sector); 4375 drbd_rs_complete_io(mdev, sector);
4369 switch (be16_to_cpu(h->command)) { 4376 switch (cmd) {
4370 case P_NEG_RS_DREPLY: 4377 case P_NEG_RS_DREPLY:
4371 drbd_rs_failed_io(mdev, sector, size); 4378 drbd_rs_failed_io(mdev, sector, size);
4372 case P_RS_CANCEL: 4379 case P_RS_CANCEL:
@@ -4382,9 +4389,9 @@ static int got_NegRSDReply(struct drbd_conf *mdev, struct p_header80 *h)
4382 return true; 4389 return true;
4383} 4390}
4384 4391
4385static int got_BarrierAck(struct drbd_conf *mdev, struct p_header80 *h) 4392static int got_BarrierAck(struct drbd_conf *mdev, enum drbd_packets cmd)
4386{ 4393{
4387 struct p_barrier_ack *p = (struct p_barrier_ack *)h; 4394 struct p_barrier_ack *p = &mdev->tconn->meta.rbuf.barrier_ack;
4388 4395
4389 tl_release(mdev, p->barrier, be32_to_cpu(p->set_size)); 4396 tl_release(mdev, p->barrier, be32_to_cpu(p->set_size));
4390 4397
@@ -4398,9 +4405,9 @@ static int got_BarrierAck(struct drbd_conf *mdev, struct p_header80 *h)
4398 return true; 4405 return true;
4399} 4406}
4400 4407
4401static int got_OVResult(struct drbd_conf *mdev, struct p_header80 *h) 4408static int got_OVResult(struct drbd_conf *mdev, enum drbd_packets cmd)
4402{ 4409{
4403 struct p_block_ack *p = (struct p_block_ack *)h; 4410 struct p_block_ack *p = &mdev->tconn->meta.rbuf.block_ack;
4404 struct drbd_work *w; 4411 struct drbd_work *w;
4405 sector_t sector; 4412 sector_t sector;
4406 int size; 4413 int size;
@@ -4442,14 +4449,14 @@ static int got_OVResult(struct drbd_conf *mdev, struct p_header80 *h)
4442 return true; 4449 return true;
4443} 4450}
4444 4451
4445static int got_skip(struct drbd_conf *mdev, struct p_header80 *h) 4452static int got_skip(struct drbd_conf *mdev, enum drbd_packets cmd)
4446{ 4453{
4447 return true; 4454 return true;
4448} 4455}
4449 4456
4450struct asender_cmd { 4457struct asender_cmd {
4451 size_t pkt_size; 4458 size_t pkt_size;
4452 int (*process)(struct drbd_conf *mdev, struct p_header80 *h); 4459 int (*process)(struct drbd_conf *mdev, enum drbd_packets cmd);
4453}; 4460};
4454 4461
4455static struct asender_cmd *get_asender_cmd(int cmd) 4462static struct asender_cmd *get_asender_cmd(int cmd)
@@ -4458,8 +4465,8 @@ static struct asender_cmd *get_asender_cmd(int cmd)
4458 /* anything missing from this table is in 4465 /* anything missing from this table is in
4459 * the drbd_cmd_handler (drbd_default_handler) table, 4466 * the drbd_cmd_handler (drbd_default_handler) table,
4460 * see the beginning of drbdd() */ 4467 * see the beginning of drbdd() */
4461 [P_PING] = { sizeof(struct p_header80), got_Ping }, 4468 [P_PING] = { sizeof(struct p_header), got_Ping },
4462 [P_PING_ACK] = { sizeof(struct p_header80), got_PingAck }, 4469 [P_PING_ACK] = { sizeof(struct p_header), got_PingAck },
4463 [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4470 [P_RECV_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
4464 [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4471 [P_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
4465 [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck }, 4472 [P_RS_WRITE_ACK] = { sizeof(struct p_block_ack), got_BlockAck },
@@ -4483,15 +4490,16 @@ static struct asender_cmd *get_asender_cmd(int cmd)
4483int drbd_asender(struct drbd_thread *thi) 4490int drbd_asender(struct drbd_thread *thi)
4484{ 4491{
4485 struct drbd_conf *mdev = thi->mdev; 4492 struct drbd_conf *mdev = thi->mdev;
4486 struct p_header80 *h = &mdev->tconn->meta.rbuf.header.h80; 4493 struct p_header *h = &mdev->tconn->meta.rbuf.header;
4487 struct asender_cmd *cmd = NULL; 4494 struct asender_cmd *cmd = NULL;
4488 4495
4489 int rv, len; 4496 int rv;
4490 void *buf = h; 4497 void *buf = h;
4491 int received = 0; 4498 int received = 0;
4492 int expect = sizeof(struct p_header80); 4499 int expect = sizeof(struct p_header);
4493 int empty;
4494 int ping_timeout_active = 0; 4500 int ping_timeout_active = 0;
4501 int empty, pkt_size;
4502 enum drbd_packets cmd_nr;
4495 4503
4496 sprintf(current->comm, "drbd%d_asender", mdev_to_minor(mdev)); 4504 sprintf(current->comm, "drbd%d_asender", mdev_to_minor(mdev));
4497 4505
@@ -4581,30 +4589,25 @@ int drbd_asender(struct drbd_thread *thi)
4581 } 4589 }
4582 4590
4583 if (received == expect && cmd == NULL) { 4591 if (received == expect && cmd == NULL) {
4584 if (unlikely(h->magic != cpu_to_be32(DRBD_MAGIC))) { 4592 if (!decode_header(mdev, h, &cmd_nr, &pkt_size))
4585 dev_err(DEV, "magic?? on meta m: 0x%08x c: %d l: %d\n",
4586 be32_to_cpu(h->magic),
4587 be16_to_cpu(h->command),
4588 be16_to_cpu(h->length));
4589 goto reconnect; 4593 goto reconnect;
4590 } 4594 cmd = get_asender_cmd(cmd_nr);
4591 cmd = get_asender_cmd(be16_to_cpu(h->command));
4592 len = be16_to_cpu(h->length);
4593 if (unlikely(cmd == NULL)) { 4595 if (unlikely(cmd == NULL)) {
4594 dev_err(DEV, "unknown command?? on meta m: 0x%08x c: %d l: %d\n", 4596 dev_err(DEV, "unknown command %d on meta (l: %d)\n",
4595 be32_to_cpu(h->magic), 4597 cmd_nr, pkt_size);
4596 be16_to_cpu(h->command),
4597 be16_to_cpu(h->length));
4598 goto disconnect; 4598 goto disconnect;
4599 } 4599 }
4600 expect = cmd->pkt_size; 4600 expect = cmd->pkt_size;
4601 if (!expect(len == expect - sizeof(struct p_header80))) 4601 if (pkt_size != expect - sizeof(struct p_header)) {
4602 dev_err(DEV, "Wrong packet size on meta (c: %d, l: %d)\n",
4603 cmd_nr, pkt_size);
4602 goto reconnect; 4604 goto reconnect;
4605 }
4603 } 4606 }
4604 if (received == expect) { 4607 if (received == expect) {
4605 mdev->tconn->last_received = jiffies; 4608 mdev->tconn->last_received = jiffies;
4606 D_ASSERT(cmd != NULL); 4609 D_ASSERT(cmd != NULL);
4607 if (!cmd->process(mdev, h)) 4610 if (!cmd->process(mdev, cmd_nr))
4608 goto reconnect; 4611 goto reconnect;
4609 4612
4610 /* the idle_timeout (ping-int) 4613 /* the idle_timeout (ping-int)
@@ -4614,7 +4617,7 @@ int drbd_asender(struct drbd_thread *thi)
4614 4617
4615 buf = h; 4618 buf = h;
4616 received = 0; 4619 received = 0;
4617 expect = sizeof(struct p_header80); 4620 expect = sizeof(struct p_header);
4618 cmd = NULL; 4621 cmd = NULL;
4619 } 4622 }
4620 } 4623 }