aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/drbd/drbd_receiver.c
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@linbit.com>2010-12-11 15:53:12 -0500
committerPhilipp Reisner <philipp.reisner@linbit.com>2011-03-10 05:36:34 -0500
commit2c46407d241f4b0e5b87959aae8f50f41fdd2a3a (patch)
treeea596a353a89095993f666e6b9ecf9d15392bd11 /drivers/block/drbd/drbd_receiver.c
parentf70af118e3f3638698ac08959a41b9f9fe7237c8 (diff)
drbd: receive_bitmap_plain: Get rid of ugly and useless enum
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.c73
1 files changed, 47 insertions, 26 deletions
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index f217d351d77c..be7fc67eeeca 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3311,23 +3311,32 @@ static int receive_sync_uuid(struct drbd_conf *mdev, enum drbd_packets cmd, unsi
3311 return true; 3311 return true;
3312} 3312}
3313 3313
3314enum receive_bitmap_ret { OK, DONE, FAILED }; 3314/**
3315 3315 * receive_bitmap_plain
3316static enum receive_bitmap_ret 3316 *
3317 * Return 0 when done, 1 when another iteration is needed, and a negative error
3318 * code upon failure.
3319 */
3320static int
3317receive_bitmap_plain(struct drbd_conf *mdev, unsigned int data_size, 3321receive_bitmap_plain(struct drbd_conf *mdev, unsigned int data_size,
3318 unsigned long *buffer, struct bm_xfer_ctx *c) 3322 unsigned long *buffer, struct bm_xfer_ctx *c)
3319{ 3323{
3320 unsigned num_words = min_t(size_t, BM_PACKET_WORDS, c->bm_words - c->word_offset); 3324 unsigned num_words = min_t(size_t, BM_PACKET_WORDS, c->bm_words - c->word_offset);
3321 unsigned want = num_words * sizeof(long); 3325 unsigned want = num_words * sizeof(long);
3326 int err;
3322 3327
3323 if (want != data_size) { 3328 if (want != data_size) {
3324 dev_err(DEV, "%s:want (%u) != data_size (%u)\n", __func__, want, data_size); 3329 dev_err(DEV, "%s:want (%u) != data_size (%u)\n", __func__, want, data_size);
3325 return FAILED; 3330 return -EIO;
3326 } 3331 }
3327 if (want == 0) 3332 if (want == 0)
3328 return DONE; 3333 return 0;
3329 if (drbd_recv(mdev, buffer, want) != want) 3334 err = drbd_recv(mdev, buffer, want);
3330 return FAILED; 3335 if (err != want) {
3336 if (err >= 0)
3337 err = -EIO;
3338 return err;
3339 }
3331 3340
3332 drbd_bm_merge_lel(mdev, c->word_offset, num_words, buffer); 3341 drbd_bm_merge_lel(mdev, c->word_offset, num_words, buffer);
3333 3342
@@ -3336,10 +3345,16 @@ receive_bitmap_plain(struct drbd_conf *mdev, unsigned int data_size,
3336 if (c->bit_offset > c->bm_bits) 3345 if (c->bit_offset > c->bm_bits)
3337 c->bit_offset = c->bm_bits; 3346 c->bit_offset = c->bm_bits;
3338 3347
3339 return OK; 3348 return 1;
3340} 3349}
3341 3350
3342static enum receive_bitmap_ret 3351/**
3352 * recv_bm_rle_bits
3353 *
3354 * Return 0 when done, 1 when another iteration is needed, and a negative error
3355 * code upon failure.
3356 */
3357static int
3343recv_bm_rle_bits(struct drbd_conf *mdev, 3358recv_bm_rle_bits(struct drbd_conf *mdev,
3344 struct p_compressed_bm *p, 3359 struct p_compressed_bm *p,
3345 struct bm_xfer_ctx *c) 3360 struct bm_xfer_ctx *c)
@@ -3359,18 +3374,18 @@ recv_bm_rle_bits(struct drbd_conf *mdev,
3359 3374
3360 bits = bitstream_get_bits(&bs, &look_ahead, 64); 3375 bits = bitstream_get_bits(&bs, &look_ahead, 64);
3361 if (bits < 0) 3376 if (bits < 0)
3362 return FAILED; 3377 return -EIO;
3363 3378
3364 for (have = bits; have > 0; s += rl, toggle = !toggle) { 3379 for (have = bits; have > 0; s += rl, toggle = !toggle) {
3365 bits = vli_decode_bits(&rl, look_ahead); 3380 bits = vli_decode_bits(&rl, look_ahead);
3366 if (bits <= 0) 3381 if (bits <= 0)
3367 return FAILED; 3382 return -EIO;
3368 3383
3369 if (toggle) { 3384 if (toggle) {
3370 e = s + rl -1; 3385 e = s + rl -1;
3371 if (e >= c->bm_bits) { 3386 if (e >= c->bm_bits) {
3372 dev_err(DEV, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e); 3387 dev_err(DEV, "bitmap overflow (e:%lu) while decoding bm RLE packet\n", e);
3373 return FAILED; 3388 return -EIO;
3374 } 3389 }
3375 _drbd_bm_set_bits(mdev, s, e); 3390 _drbd_bm_set_bits(mdev, s, e);
3376 } 3391 }
@@ -3380,14 +3395,14 @@ recv_bm_rle_bits(struct drbd_conf *mdev,
3380 have, bits, look_ahead, 3395 have, bits, look_ahead,
3381 (unsigned int)(bs.cur.b - p->code), 3396 (unsigned int)(bs.cur.b - p->code),
3382 (unsigned int)bs.buf_len); 3397 (unsigned int)bs.buf_len);
3383 return FAILED; 3398 return -EIO;
3384 } 3399 }
3385 look_ahead >>= bits; 3400 look_ahead >>= bits;
3386 have -= bits; 3401 have -= bits;
3387 3402
3388 bits = bitstream_get_bits(&bs, &tmp, 64 - have); 3403 bits = bitstream_get_bits(&bs, &tmp, 64 - have);
3389 if (bits < 0) 3404 if (bits < 0)
3390 return FAILED; 3405 return -EIO;
3391 look_ahead |= tmp << have; 3406 look_ahead |= tmp << have;
3392 have += bits; 3407 have += bits;
3393 } 3408 }
@@ -3395,10 +3410,16 @@ recv_bm_rle_bits(struct drbd_conf *mdev,
3395 c->bit_offset = s; 3410 c->bit_offset = s;
3396 bm_xfer_ctx_bit_to_word_offset(c); 3411 bm_xfer_ctx_bit_to_word_offset(c);
3397 3412
3398 return (s == c->bm_bits) ? DONE : OK; 3413 return (s != c->bm_bits);
3399} 3414}
3400 3415
3401static enum receive_bitmap_ret 3416/**
3417 * decode_bitmap_c
3418 *
3419 * Return 0 when done, 1 when another iteration is needed, and a negative error
3420 * code upon failure.
3421 */
3422static int
3402decode_bitmap_c(struct drbd_conf *mdev, 3423decode_bitmap_c(struct drbd_conf *mdev,
3403 struct p_compressed_bm *p, 3424 struct p_compressed_bm *p,
3404 struct bm_xfer_ctx *c) 3425 struct bm_xfer_ctx *c)
@@ -3412,7 +3433,7 @@ decode_bitmap_c(struct drbd_conf *mdev,
3412 3433
3413 dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding); 3434 dev_err(DEV, "receive_bitmap_c: unknown encoding %u\n", p->encoding);
3414 drbd_force_state(mdev, NS(conn, C_PROTOCOL_ERROR)); 3435 drbd_force_state(mdev, NS(conn, C_PROTOCOL_ERROR));
3415 return FAILED; 3436 return -EIO;
3416} 3437}
3417 3438
3418void INFO_bm_xfer_stats(struct drbd_conf *mdev, 3439void INFO_bm_xfer_stats(struct drbd_conf *mdev,
@@ -3461,7 +3482,7 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3461{ 3482{
3462 struct bm_xfer_ctx c; 3483 struct bm_xfer_ctx c;
3463 void *buffer; 3484 void *buffer;
3464 enum receive_bitmap_ret ret; 3485 int err;
3465 int ok = false; 3486 int ok = false;
3466 struct p_header80 *h = &mdev->data.rbuf.header.h80; 3487 struct p_header80 *h = &mdev->data.rbuf.header.h80;
3467 3488
@@ -3480,9 +3501,9 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3480 .bm_words = drbd_bm_words(mdev), 3501 .bm_words = drbd_bm_words(mdev),
3481 }; 3502 };
3482 3503
3483 do { 3504 for(;;) {
3484 if (cmd == P_BITMAP) { 3505 if (cmd == P_BITMAP) {
3485 ret = receive_bitmap_plain(mdev, data_size, buffer, &c); 3506 err = receive_bitmap_plain(mdev, data_size, buffer, &c);
3486 } else if (cmd == P_COMPRESSED_BITMAP) { 3507 } else if (cmd == P_COMPRESSED_BITMAP) {
3487 /* MAYBE: sanity check that we speak proto >= 90, 3508 /* MAYBE: sanity check that we speak proto >= 90,
3488 * and the feature is enabled! */ 3509 * and the feature is enabled! */
@@ -3501,7 +3522,7 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3501 dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", data_size); 3522 dev_err(DEV, "ReportCBitmap packet too small (l:%u)\n", data_size);
3502 goto out; 3523 goto out;
3503 } 3524 }
3504 ret = decode_bitmap_c(mdev, p, &c); 3525 err = decode_bitmap_c(mdev, p, &c);
3505 } else { 3526 } else {
3506 dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", cmd); 3527 dev_warn(DEV, "receive_bitmap: cmd neither ReportBitMap nor ReportCBitMap (is 0x%x)", cmd);
3507 goto out; 3528 goto out;
@@ -3510,14 +3531,14 @@ static int receive_bitmap(struct drbd_conf *mdev, enum drbd_packets cmd, unsigne
3510 c.packets[cmd == P_BITMAP]++; 3531 c.packets[cmd == P_BITMAP]++;
3511 c.bytes[cmd == P_BITMAP] += sizeof(struct p_header80) + data_size; 3532 c.bytes[cmd == P_BITMAP] += sizeof(struct p_header80) + data_size;
3512 3533
3513 if (ret != OK) 3534 if (err <= 0) {
3535 if (err < 0)
3536 goto out;
3514 break; 3537 break;
3515 3538 }
3516 if (!drbd_recv_header(mdev, &cmd, &data_size)) 3539 if (!drbd_recv_header(mdev, &cmd, &data_size))
3517 goto out; 3540 goto out;
3518 } while (ret == OK); 3541 }
3519 if (ret == FAILED)
3520 goto out;
3521 3542
3522 INFO_bm_xfer_stats(mdev, "receive", &c); 3543 INFO_bm_xfer_stats(mdev, "receive", &c);
3523 3544