Commit a5c31904 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: Introduce and use drbd_recv_all_warn()

The pattern of receiving a fixed number of bytes and warning if a short
packet is received and the receiver has not actively been interruped is
repeated many times; clean that up.
Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 309a8348
...@@ -578,6 +578,16 @@ static int drbd_recv_all(struct drbd_tconn *tconn, void *buf, size_t size) ...@@ -578,6 +578,16 @@ static int drbd_recv_all(struct drbd_tconn *tconn, void *buf, size_t size)
return err; return err;
} }
static int drbd_recv_all_warn(struct drbd_tconn *tconn, void *buf, size_t size)
{
int err;
err = drbd_recv_all(tconn, buf, size);
if (err && !signal_pending(current))
conn_warn(tconn, "short read (expected size %d)\n", (int)size);
return err;
}
/* quoting tcp(7): /* quoting tcp(7):
* On individual connections, the socket buffer size must be set prior to the * On individual connections, the socket buffer size must be set prior to the
* listen(2) or connect(2) calls in order to have it take effect. * listen(2) or connect(2) calls in order to have it take effect.
...@@ -986,14 +996,9 @@ static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi) ...@@ -986,14 +996,9 @@ static int drbd_recv_header(struct drbd_tconn *tconn, struct packet_info *pi)
struct p_header *h = &tconn->data.rbuf.header; struct p_header *h = &tconn->data.rbuf.header;
int err; int err;
err = drbd_recv(tconn, h, sizeof(*h)); err = drbd_recv_all_warn(tconn, h, sizeof(*h));
if (unlikely(err != sizeof(*h))) { if (err)
if (!signal_pending(current))
conn_warn(tconn, "short read expecting header on sock: r=%d\n", err);
if (err >= 0)
err = -EIO;
return err; return err;
}
err = decode_header(tconn, h, pi); err = decode_header(tconn, h, pi);
tconn->last_received = jiffies; tconn->last_received = jiffies;
...@@ -1307,7 +1312,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, ...@@ -1307,7 +1312,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector,
const sector_t capacity = drbd_get_capacity(mdev->this_bdev); const sector_t capacity = drbd_get_capacity(mdev->this_bdev);
struct drbd_peer_request *peer_req; struct drbd_peer_request *peer_req;
struct page *page; struct page *page;
int dgs, ds, rr; int dgs, ds, err;
void *dig_in = mdev->tconn->int_dig_in; void *dig_in = mdev->tconn->int_dig_in;
void *dig_vv = mdev->tconn->int_dig_vv; void *dig_vv = mdev->tconn->int_dig_vv;
unsigned long *data; unsigned long *data;
...@@ -1316,14 +1321,9 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, ...@@ -1316,14 +1321,9 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector,
crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0; crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0;
if (dgs) { if (dgs) {
rr = drbd_recv(mdev->tconn, dig_in, dgs); err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs);
if (rr != dgs) { if (err)
if (!signal_pending(current))
dev_warn(DEV,
"short read receiving data digest: read %d expected %d\n",
rr, dgs);
return NULL; return NULL;
}
} }
data_size -= dgs; data_size -= dgs;
...@@ -1357,20 +1357,17 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, ...@@ -1357,20 +1357,17 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector,
page_chain_for_each(page) { page_chain_for_each(page) {
unsigned len = min_t(int, ds, PAGE_SIZE); unsigned len = min_t(int, ds, PAGE_SIZE);
data = kmap(page); data = kmap(page);
rr = drbd_recv(mdev->tconn, data, len); err = drbd_recv_all_warn(mdev->tconn, data, len);
if (drbd_insert_fault(mdev, DRBD_FAULT_RECEIVE)) { if (drbd_insert_fault(mdev, DRBD_FAULT_RECEIVE)) {
dev_err(DEV, "Fault injection: Corrupting data on receive\n"); dev_err(DEV, "Fault injection: Corrupting data on receive\n");
data[0] = data[0] ^ (unsigned long)-1; data[0] = data[0] ^ (unsigned long)-1;
} }
kunmap(page); kunmap(page);
if (rr != len) { if (err) {
drbd_free_ee(mdev, peer_req); drbd_free_ee(mdev, peer_req);
if (!signal_pending(current))
dev_warn(DEV, "short read receiving data: read %d expected %d\n",
rr, len);
return NULL; return NULL;
} }
ds -= rr; ds -= len;
} }
if (dgs) { if (dgs) {
...@@ -1392,7 +1389,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector, ...@@ -1392,7 +1389,7 @@ read_in_block(struct drbd_conf *mdev, u64 id, sector_t sector,
static int drbd_drain_block(struct drbd_conf *mdev, int data_size) static int drbd_drain_block(struct drbd_conf *mdev, int data_size)
{ {
struct page *page; struct page *page;
int rr, err = 0; int err = 0;
void *data; void *data;
if (!data_size) if (!data_size)
...@@ -1404,16 +1401,10 @@ static int drbd_drain_block(struct drbd_conf *mdev, int data_size) ...@@ -1404,16 +1401,10 @@ static int drbd_drain_block(struct drbd_conf *mdev, int data_size)
while (data_size) { while (data_size) {
unsigned int len = min_t(int, data_size, PAGE_SIZE); unsigned int len = min_t(int, data_size, PAGE_SIZE);
rr = drbd_recv(mdev->tconn, data, len); err = drbd_recv_all_warn(mdev->tconn, data, len);
if (rr != len) { if (err)
if (!signal_pending(current))
dev_warn(DEV,
"short read receiving data: read %d expected %d\n",
rr, len);
err = (rr < 0) ? rr : -EIO;
break; break;
} data_size -= len;
data_size -= rr;
} }
kunmap(page); kunmap(page);
drbd_pp_free(mdev, page, 0); drbd_pp_free(mdev, page, 0);
...@@ -1425,7 +1416,7 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, ...@@ -1425,7 +1416,7 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req,
{ {
struct bio_vec *bvec; struct bio_vec *bvec;
struct bio *bio; struct bio *bio;
int dgs, rr, i, expect; int dgs, err, i, expect;
void *dig_in = mdev->tconn->int_dig_in; void *dig_in = mdev->tconn->int_dig_in;
void *dig_vv = mdev->tconn->int_dig_vv; void *dig_vv = mdev->tconn->int_dig_vv;
...@@ -1433,14 +1424,9 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, ...@@ -1433,14 +1424,9 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req,
crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0; crypto_hash_digestsize(mdev->tconn->integrity_r_tfm) : 0;
if (dgs) { if (dgs) {
rr = drbd_recv(mdev->tconn, dig_in, dgs); err = drbd_recv_all_warn(mdev->tconn, dig_in, dgs);
if (rr != dgs) { if (err)
if (!signal_pending(current)) return err;
dev_warn(DEV,
"short read receiving data reply digest: read %d expected %d\n",
rr, dgs);
return rr < 0 ? rr : -EIO;
}
} }
data_size -= dgs; data_size -= dgs;
...@@ -1453,19 +1439,13 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req, ...@@ -1453,19 +1439,13 @@ static int recv_dless_read(struct drbd_conf *mdev, struct drbd_request *req,
D_ASSERT(sector == bio->bi_sector); D_ASSERT(sector == bio->bi_sector);
bio_for_each_segment(bvec, bio, i) { bio_for_each_segment(bvec, bio, i) {
void *mapped = kmap(bvec->bv_page) + bvec->bv_offset;
expect = min_t(int, data_size, bvec->bv_len); expect = min_t(int, data_size, bvec->bv_len);
rr = drbd_recv(mdev->tconn, err = drbd_recv_all_warn(mdev->tconn, mapped, expect);
kmap(bvec->bv_page)+bvec->bv_offset,
expect);
kunmap(bvec->bv_page); kunmap(bvec->bv_page);
if (rr != expect) { if (err)
if (!signal_pending(current)) return err;
dev_warn(DEV, "short read receiving data reply: " data_size -= expect;
"read %d expected %d\n",
rr, expect);
return rr < 0 ? rr : -EIO;
}
data_size -= rr;
} }
if (dgs) { if (dgs) {
...@@ -3984,12 +3964,9 @@ static void drbdd(struct drbd_tconn *tconn) ...@@ -3984,12 +3964,9 @@ static void drbdd(struct drbd_tconn *tconn)
} }
if (shs) { if (shs) {
err = drbd_recv_all(tconn, &header->payload, shs); err = drbd_recv_all_warn(tconn, &header->payload, shs);
if (err) { if (err)
if (!signal_pending(current))
conn_warn(tconn, "short read while reading sub header: rv=%d\n", err);
goto err_out; goto err_out;
}
} }
if (drbd_cmd_handler[pi.cmd].fa_type == CONN) { if (drbd_cmd_handler[pi.cmd].fa_type == CONN) {
...@@ -4199,7 +4176,7 @@ static int drbd_do_handshake(struct drbd_tconn *tconn) ...@@ -4199,7 +4176,7 @@ static int drbd_do_handshake(struct drbd_tconn *tconn)
struct p_handshake *p = &tconn->data.rbuf.handshake; struct p_handshake *p = &tconn->data.rbuf.handshake;
const int expect = sizeof(struct p_handshake) - sizeof(struct p_header80); const int expect = sizeof(struct p_handshake) - sizeof(struct p_header80);
struct packet_info pi; struct packet_info pi;
int err, rv; int err;
err = drbd_send_handshake(tconn); err = drbd_send_handshake(tconn);
if (err) if (err)
...@@ -4221,13 +4198,9 @@ static int drbd_do_handshake(struct drbd_tconn *tconn) ...@@ -4221,13 +4198,9 @@ static int drbd_do_handshake(struct drbd_tconn *tconn)
return -1; return -1;
} }
rv = drbd_recv(tconn, &p->head.payload, expect); err = drbd_recv_all_warn(tconn, &p->head.payload, expect);
if (err)
if (rv != expect) {
if (!signal_pending(current))
conn_warn(tconn, "short read receiving handshake packet: l=%u\n", rv);
return 0; return 0;
}
p->protocol_min = be32_to_cpu(p->protocol_min); p->protocol_min = be32_to_cpu(p->protocol_min);
p->protocol_max = be32_to_cpu(p->protocol_max); p->protocol_max = be32_to_cpu(p->protocol_max);
...@@ -4325,11 +4298,8 @@ static int drbd_do_auth(struct drbd_tconn *tconn) ...@@ -4325,11 +4298,8 @@ static int drbd_do_auth(struct drbd_tconn *tconn)
goto fail; goto fail;
} }
rv = drbd_recv(tconn, peers_ch, pi.size); err = drbd_recv_all_warn(tconn, peers_ch, pi.size);
if (err) {
if (rv != pi.size) {
if (!signal_pending(current))
conn_warn(tconn, "short read AuthChallenge: l=%u\n", rv);
rv = 0; rv = 0;
goto fail; goto fail;
} }
...@@ -4375,11 +4345,8 @@ static int drbd_do_auth(struct drbd_tconn *tconn) ...@@ -4375,11 +4345,8 @@ static int drbd_do_auth(struct drbd_tconn *tconn)
goto fail; goto fail;
} }
rv = drbd_recv(tconn, response , resp_size); err = drbd_recv_all_warn(tconn, response , resp_size);
if (err) {
if (rv != resp_size) {
if (!signal_pending(current))
conn_warn(tconn, "short read receiving AuthResponse: l=%u\n", rv);
rv = 0; rv = 0;
goto fail; goto fail;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment