From 57551cb0529b48411f8f63a002882b7e1cf792f8 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Diego=20E.=20'Flameeyes'=20Petten=C3=B2?= <flameeyes@gmail.com>
Date: Wed, 25 Mar 2009 16:14:26 +0100
Subject: [PATCH 1/2] Fix building with Linux kernel 2.6.28 and later.

With changeset 30c40d2c01f68c7eb1a41ab3552bdaf5dbf300d4 of the Linux
kernel, the functions open_bdev_excl and close_bdev_excl were replaced with
functionally-equivalent open_bdev_exclusive and close_bdev_exclusive.

The new interface uses fmode_t instead of integer flags to carry on the
opening mode for a block device, thus require some minor changes in the
calls.
---
 kernel/block-io.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/kernel/block-io.c b/kernel/block-io.c
index e4a25f7..af10c7e 100644
--- a/kernel/block-io.c
+++ b/kernel/block-io.c
@@ -13,11 +13,18 @@
 #include <linux/blkdev.h>
 #include <linux/parser.h>
 #include <linux/buffer_head.h>
+#include <linux/version.h>
 
 #include "iscsi.h"
 #include "iscsi_dbg.h"
 #include "iotype.h"
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
+# define HAVE_OPEN_BDEV_EXCLUSIVE 1
+#else
+# define HAVE_OPEN_BDEV_EXCLUSIVE 0
+#endif
+
 struct blockio_data {
 	char *path;
 	struct block_device *bdev;
@@ -154,14 +161,22 @@ blockio_open_path(struct iet_volume *volume, const char *path)
 {
 	struct blockio_data *bio_data = volume->private;
 	struct block_device *bdev;
+#if HAVE_OPEN_BDEV_EXCLUSIVE
+	fmode_t mode = FMODE_READ | ( LUReadonly(volume) ? 0 : FMODE_WRITE );
+#else
 	int flags = LUReadonly(volume) ? MS_RDONLY : 0;
+#endif
 	int err = 0;
 
 	bio_data->path = kstrdup(path, GFP_KERNEL);
 	if (!bio_data->path)
 		return -ENOMEM;
 
+#if HAVE_OPEN_BDEV_EXCLUSIVE
+	bdev = open_bdev_exclusive(path, mode, THIS_MODULE);
+#else
 	bdev = open_bdev_excl(path, flags, THIS_MODULE);
+#endif
 	if (IS_ERR(bdev)) {
 		err = PTR_ERR(bdev);
 		eprintk("Can't open device %s, error %d\n", path, err);
@@ -323,9 +338,16 @@ static void
 blockio_detach(struct iet_volume *volume)
 {
 	struct blockio_data *bio_data = volume->private;
+#if HAVE_OPEN_BDEV_EXCLUSIVE
+	fmode_t mode = FMODE_READ | ( LUReadonly(volume) ? 0 : FMODE_WRITE );
+#endif
 
 	if (bio_data->bdev)
+#if HAVE_OPEN_BDEV_EXCLUSIVE
+		close_bdev_exclusive(bio_data->bdev, mode);
+#else
 		close_bdev_excl(bio_data->bdev);
+#endif
 	kfree(bio_data->path);
 
 	kfree(volume->private);
-- 
1.6.2

