public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Block - Honour barrier requests in loop driver
@ 2009-03-17  8:47 Nikanth Karthikesan
  2009-03-17  9:19 ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Nikanth Karthikesan @ 2009-03-17  8:47 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Gerd Hoffmann, Constantine Sapuntzakis, Miklos Szeredi, nikanth,
	linux-kernel

Based on the patch[1] posted by Constantine Sapuntzakis back in May 2006,
and various other similar patches by Jens Axboe, Gerd Hoffmann and Miklos
Szeredi for Suse Kernels, this patch adds barrier support to loop back
devices. I am not sure why this support was not merged earlier.

Jens can you please review this?

Thanks
Nikanth

[1] http://lkml.indiana.edu/hypermail/linux/kernel/0605.0/1172.html

Honour barrier requests in the loop back block device driver.
In case of barrier bios, flush the backing file once before processing the
barrier and once after to guarantee ordering. In case of filesystems that does
not support fsync, barrier bios would be failed with -EOPNOTSUPP.

Signed-off-by: Nikanth Karthikesan <knikanth@suse.de>

---

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index bf03455..e805985 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -202,6 +202,35 @@ lo_do_transfer(struct loop_device *lo, int cmd,
 	return lo->transfer(lo, cmd, rpage, roffs, lpage, loffs, size, rblock);
 }
 
+static int sync_file(struct file *file)
+{
+	struct address_space *mapping;
+	int ret;
+
+	if (!file->f_op || !file->f_op->fsync)
+		return -EOPNOTSUPP;
+
+	mapping = file->f_mapping;
+
+	ret = filemap_fdatawrite(mapping);
+	if (!ret) {
+		int ret2;
+
+		mutex_lock(&mapping->host->i_mutex);
+		ret = file->f_op->fsync(file, file->f_dentry, 1);
+		mutex_unlock(&mapping->host->i_mutex);
+
+		ret2 = filemap_fdatawait(mapping);
+		if (!ret)
+			ret = ret2;
+	}
+
+	if (unlikely(ret))
+		ret = -EIO;
+
+	return ret;
+}
+
 /**
  * do_lo_send_aops - helper for writing data to a loop device
  *
@@ -472,12 +501,23 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
 {
 	loff_t pos;
 	int ret;
+	int barrier = bio_barrier(bio);
+
+	if (barrier) {
+		ret = sync_file(lo->lo_backing_file);
+		if (unlikely(ret))
+			goto out;
+	}
 
 	pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset;
-	if (bio_rw(bio) == WRITE)
+	if (bio_rw(bio) == WRITE) {
 		ret = lo_send(lo, bio, pos);
-	else
+		if (barrier && !ret)
+			ret = sync_file(lo->lo_backing_file);
+	} else
 		ret = lo_receive(lo, bio, lo->lo_blocksize, pos);
+
+out:
 	return ret;
 }
 


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-03-24 11:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-17  8:47 [PATCH] Block - Honour barrier requests in loop driver Nikanth Karthikesan
2009-03-17  9:19 ` Christoph Hellwig
2009-03-17 12:09   ` Nikanth Karthikesan
2009-03-17 19:09     ` Christoph Hellwig
2009-03-18  4:58       ` Nikanth Karthikesan
2009-03-24  5:54         ` Nikanth Karthikesan
2009-03-24 11:24           ` Jens Axboe
2009-03-24 11:26             ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox