drbd: Ensure that an epoch contains only requests of one kind

The assert in drbd_req.c:755 forces us to have only requests of
one kind in an epoch. The two kinds we distinguish here are:
local-only or mirrored.

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_main.c b/drivers/block/drbd/drbd_main.c
index 1061b9f..34ee8e4 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -1261,9 +1261,14 @@
 	if (os.conn < C_CONNECTED && ns.conn >= C_CONNECTED)
 		drbd_resume_al(mdev);
 
-	if (os.conn == C_AHEAD && ns.conn != C_AHEAD)
+	/* Start a new epoch in case we start to mirror write requests */
+	if (!drbd_should_do_remote(os) && drbd_should_do_remote(ns))
 		tl_forget(mdev);
 
+	/* Do not add local-only requests to an epoch with mirrored requests */
+	if (drbd_should_do_remote(os) && !drbd_should_do_remote(ns))
+		set_bit(CREATE_BARRIER, &mdev->flags);
+
 	ascw = kmalloc(sizeof(*ascw), GFP_ATOMIC);
 	if (ascw) {
 		ascw->os = os;