drbd: Use the read and write request trees for request lookups
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com>
Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
diff --git a/drivers/block/drbd/drbd_interval.h b/drivers/block/drbd/drbd_interval.h
index bf8dcf7..a847b4a 100644
--- a/drivers/block/drbd/drbd_interval.h
+++ b/drivers/block/drbd/drbd_interval.h
@@ -22,8 +22,7 @@
}
bool drbd_insert_interval(struct rb_root *, struct drbd_interval *);
-struct drbd_interval *drbd_find_interval(struct rb_root *, sector_t,
- struct drbd_interval *);
+bool drbd_contains_interval(struct rb_root *, sector_t, struct drbd_interval *);
void drbd_remove_interval(struct rb_root *, struct drbd_interval *);
struct drbd_interval *drbd_find_overlap(struct rb_root *, sector_t,
unsigned int);
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index 6b072584..b148398 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1470,27 +1470,15 @@
}
static struct drbd_request *
-find_request(struct drbd_conf *mdev,
- struct hlist_head *(*hash_slot)(struct drbd_conf *, sector_t),
- u64 id, sector_t sector, bool missing_ok, const char *func)
+find_request(struct drbd_conf *mdev, struct rb_root *root, u64 id,
+ sector_t sector, bool missing_ok, const char *func)
{
- struct hlist_head *slot = hash_slot(mdev, sector);
- struct hlist_node *n;
struct drbd_request *req;
- hlist_for_each_entry(req, n, slot, collision) {
- if ((unsigned long)req != (unsigned long)id)
- continue;
- if (req->i.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->i.sector,
- (unsigned long long)sector);
- return NULL;
- }
+ /* Request object according to our peer */
+ req = (struct drbd_request *)(unsigned long)id;
+ if (drbd_contains_interval(root, sector, &req->i))
return req;
- }
if (!missing_ok) {
dev_err(DEV, "%s: failed to find request %lu, sector %llus\n", func,
(unsigned long)id, (unsigned long long)sector);
@@ -1508,7 +1496,7 @@
sector = be64_to_cpu(p->sector);
spin_lock_irq(&mdev->req_lock);
- req = find_request(mdev, ar_hash_slot, p->block_id, sector, false, __func__);
+ req = find_request(mdev, &mdev->read_requests, p->block_id, sector, false, __func__);
spin_unlock_irq(&mdev->req_lock);
if (unlikely(!req))
return false;
@@ -4245,16 +4233,16 @@
return true;
}
-static int validate_req_change_req_state(struct drbd_conf *mdev,
- u64 id, sector_t sector,
- struct hlist_head *(*hash_slot)(struct drbd_conf *, sector_t),
- const char *func, enum drbd_req_event what, bool missing_ok)
+static int
+validate_req_change_req_state(struct drbd_conf *mdev, u64 id, sector_t sector,
+ struct rb_root *root, const char *func,
+ enum drbd_req_event what, bool missing_ok)
{
struct drbd_request *req;
struct bio_and_error m;
spin_lock_irq(&mdev->req_lock);
- req = find_request(mdev, hash_slot, id, sector, missing_ok, func);
+ req = find_request(mdev, root, id, sector, missing_ok, func);
if (unlikely(!req)) {
spin_unlock_irq(&mdev->req_lock);
return false;
@@ -4304,8 +4292,8 @@
}
return validate_req_change_req_state(mdev, p->block_id, sector,
- tl_hash_slot, __func__, what,
- false);
+ &mdev->write_requests, __func__,
+ what, false);
}
static int got_NegAck(struct drbd_conf *mdev, struct p_header80 *h)
@@ -4326,7 +4314,7 @@
}
found = validate_req_change_req_state(mdev, p->block_id, sector,
- tl_hash_slot, __func__,
+ &mdev->write_requests, __func__,
neg_acked, missing_ok);
if (!found) {
/* Protocol A has no P_WRITE_ACKs, but has P_NEG_ACKs.
@@ -4351,8 +4339,8 @@
(unsigned long long)sector, be32_to_cpu(p->blksize));
return validate_req_change_req_state(mdev, p->block_id, sector,
- ar_hash_slot, __func__, neg_acked,
- false);
+ &mdev->read_requests, __func__,
+ neg_acked, false);
}
static int got_NegRSDReply(struct drbd_conf *mdev, struct p_header80 *h)