Commit 668eebc6 authored by Andreas Gruenbacher's avatar Andreas Gruenbacher Committed by Philipp Reisner

drbd: Request lookup code cleanup (2)

Unify the ar_id_to_req() and ack_id_to_req() functions: make both fail
if the consistency check fails.  Move the request lookup code now
duplicated in both functions into its own function.
Signed-off-by: default avatarPhilipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: default avatarLars Ellenberg <lars.ellenberg@linbit.com>
parent 51624585
...@@ -1469,24 +1469,39 @@ static int recv_resync_read(struct drbd_conf *mdev, sector_t sector, int data_si ...@@ -1469,24 +1469,39 @@ static int recv_resync_read(struct drbd_conf *mdev, sector_t sector, int data_si
return false; return false;
} }
/* when we receive the answer for a read request, static struct drbd_request *
* verify that we actually know about it */ find_request(struct drbd_conf *mdev,
static struct drbd_request *ar_id_to_req(struct drbd_conf *mdev, u64 id, struct hlist_head *(*hash_slot)(struct drbd_conf *, sector_t),
sector_t sector) u64 id, sector_t sector, const char *func)
{ {
struct hlist_head *slot = ar_hash_slot(mdev, sector); struct hlist_head *slot = hash_slot(mdev, sector);
struct hlist_node *n; struct hlist_node *n;
struct drbd_request *req; struct drbd_request *req;
hlist_for_each_entry(req, n, slot, collision) { hlist_for_each_entry(req, n, slot, collision) {
if ((unsigned long)req == (unsigned long)id) { if ((unsigned long)req != (unsigned long)id)
D_ASSERT(req->sector == sector); continue;
return req; if (req->sector != sector) {
dev_err(DEV, "%s: found request %lu but it has "
"wrong sector (%llus versus %llus)\n",
func, (unsigned long)req,
(unsigned long long)req->sector,
(unsigned long long)sector);
break;
} }
return req;
} }
return NULL; return NULL;
} }
/* when we receive the answer for a read request,
* verify that we actually know about it */
static struct drbd_request *ar_id_to_req(struct drbd_conf *mdev, u64 id,
sector_t sector)
{
return find_request(mdev, ar_hash_slot, id, sector, __func__);
}
static int receive_DataReply(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned int data_size) static int receive_DataReply(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned int data_size)
{ {
struct drbd_request *req; struct drbd_request *req;
...@@ -4243,23 +4258,7 @@ static int got_IsInSync(struct drbd_conf *mdev, struct p_header80 *h) ...@@ -4243,23 +4258,7 @@ static int got_IsInSync(struct drbd_conf *mdev, struct p_header80 *h)
static struct drbd_request *ack_id_to_req(struct drbd_conf *mdev, u64 id, static struct drbd_request *ack_id_to_req(struct drbd_conf *mdev, u64 id,
sector_t sector) sector_t sector)
{ {
struct hlist_head *slot = tl_hash_slot(mdev, sector); return find_request(mdev, tl_hash_slot, id, sector, __func__);
struct hlist_node *n;
struct drbd_request *req;
hlist_for_each_entry(req, n, slot, collision) {
if ((unsigned long)req == (unsigned long)id) {
if (req->sector != sector) {
dev_err(DEV, "ack_id_to_req: found req %p but it has "
"wrong sector (%llus versus %llus)\n", req,
(unsigned long long)req->sector,
(unsigned long long)sector);
break;
}
return req;
}
}
return NULL;
} }
static int validate_req_change_req_state(struct drbd_conf *mdev, static int validate_req_change_req_state(struct drbd_conf *mdev,
......
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