summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ellenberg <lars.ellenberg@linbit.com>2012-03-26 15:49:13 +0200
committerPhilipp Reisner <philipp.reisner@linbit.com>2012-11-08 16:58:18 +0100
commitd93f63028f3bc07bbcf6fe25d8d7d8a50f441bd9 (patch)
treea2efbf8e931901f319d98d16143fb44e3e5438eb
parent81f448629aa25051c47b4d5b81702da8cbe922c3 (diff)
drbd: Fix a potential write ordering issue on SyncTarget nodes
Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com>
-rw-r--r--drivers/block/drbd/drbd_receiver.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index caf3c3cd2d2a..8a7f61ba74a8 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1911,6 +1911,33 @@ static void update_peer_seq(struct drbd_conf *mdev, unsigned int peer_seq)
}
}
+static inline int overlaps(sector_t s1, int l1, sector_t s2, int l2)
+{
+ return !((s1 + (l1>>9) <= s2) || (s1 >= s2 + (l2>>9)));
+}
+
+/* maybe change sync_ee into interval trees as well? */
+static bool overlaping_resync_write(struct drbd_conf *mdev, struct drbd_peer_request *peer_req)
+{
+ struct drbd_peer_request *rs_req;
+ bool rv = 0;
+
+ spin_lock_irq(&mdev->tconn->req_lock);
+ list_for_each_entry(rs_req, &mdev->sync_ee, w.list) {
+ if (overlaps(peer_req->i.sector, peer_req->i.size,
+ rs_req->i.sector, rs_req->i.size)) {
+ rv = 1;
+ break;
+ }
+ }
+ spin_unlock_irq(&mdev->tconn->req_lock);
+
+ if (rv)
+ dev_warn(DEV, "WARN: Avoiding concurrent data/resync write to single sector.\n");
+
+ return rv;
+}
+
/* Called from receive_Data.
* Synchronize packets on sock with packets on msock.
*
@@ -2192,6 +2219,9 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
list_add(&peer_req->w.list, &mdev->active_ee);
spin_unlock_irq(&mdev->tconn->req_lock);
+ if (mdev->state.conn == C_SYNC_TARGET)
+ wait_event(mdev->ee_wait, !overlaping_resync_write(mdev, peer_req));
+
if (mdev->tconn->agreed_pro_version < 100) {
rcu_read_lock();
switch (rcu_dereference(mdev->tconn->net_conf)->wire_protocol) {