From: kwolf@suse.de
Subject: blktap: Write Barriers
Patch-mainline: obsolete

--- head-2011-02-17.orig/drivers/xen/blktap/blktap.c	2011-02-28 14:15:27.000000000 +0100
+++ head-2011-02-17/drivers/xen/blktap/blktap.c	2011-02-28 14:21:49.000000000 +0100
@@ -1374,6 +1374,9 @@ static int do_block_io_op(blkif_t *blkif
 			dispatch_rw_block_io(blkif, &req, pending_req);
 			break;
 
+		case BLKIF_OP_WRITE_BARRIER:
+			/* TODO Some counter? */
+			/* Fall through */
 		case BLKIF_OP_WRITE:
 			blkif->st_wr_req++;
 			dispatch_rw_block_io(blkif, &req, pending_req);
@@ -1432,7 +1435,7 @@ static void dispatch_rw_block_io(blkif_t
 
 	/* Check that number of segments is sane. */
 	nseg = req->nr_segments;
-	if ( unlikely(nseg == 0) || 
+	if (unlikely(nseg == 0 && req->operation != BLKIF_OP_WRITE_BARRIER) ||
 	    unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST) ) {
 		WPRINTK("Bad number of segments in request (%d)\n", nseg);
 		goto fail_response;
@@ -1458,8 +1461,13 @@ static void dispatch_rw_block_io(blkif_t
 	pending_req->nr_pages  = nseg;
 
 	flags = GNTMAP_host_map;
-	if (req->operation == BLKIF_OP_WRITE)
+	switch (req->operation) {
+	case BLKIF_OP_WRITE:
+	case BLKIF_OP_WRITE_BARRIER:
 		flags |= GNTMAP_readonly;
+		break;
+	}
+
 	op = 0;
 	mm = info->mm;
 	if (!xen_feature(XENFEAT_auto_translated_physmap))
@@ -1622,6 +1630,7 @@ static void dispatch_rw_block_io(blkif_t
 		blkif->st_rd_sect += nr_sects;
 		break;
 	case BLKIF_OP_WRITE:
+	case BLKIF_OP_WRITE_BARRIER:
 		blkif->st_wr_sect += nr_sects;
 		break;
 	}
--- head-2011-02-17.orig/drivers/xen/blktap/xenbus.c	2010-11-25 10:57:14.000000000 +0100
+++ head-2011-02-17/drivers/xen/blktap/xenbus.c	2010-11-25 10:57:21.000000000 +0100
@@ -418,7 +418,28 @@ static void connect(struct backend_info 
 	int err;
 
 	struct xenbus_device *dev = be->dev;
+	struct xenbus_transaction xbt;
 
+	/* Write feature-barrier to xenstore */
+again:
+	err = xenbus_transaction_start(&xbt);
+	if (err) {
+		xenbus_dev_fatal(dev, err, "starting transaction");
+		return;
+	}
+
+	err = xenbus_printf(xbt, dev->nodename, "feature-barrier",  "1");
+	if (err) {
+		xenbus_dev_fatal(dev, err, "writing feature-barrier");
+		xenbus_transaction_end(xbt, 1);
+		return;
+	}
+
+	err = xenbus_transaction_end(xbt, 0);
+	if (err == -EAGAIN)
+		goto again;
+
+	/* Switch state */
 	err = xenbus_switch_state(dev, XenbusStateConnected);
 	if (err)
 		xenbus_dev_fatal(dev, err, "switching to Connected state",
