<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Jens Axboe &lt;axboe@suse.de&gt;

ide bits
DESC
disk-barrier-ide-symbol-expoprt
EDESC
DESC
disk-barrier ide warning fix
EDESC

drivers/ide/ide-io.c: In function `ide_complete_barrier':
drivers/ide/ide-io.c:301: warning: long long unsigned int format, different type arg (arg 3)

Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 25-akpm/drivers/ide/ide-disk.c  |   44 +++++++
 25-akpm/drivers/ide/ide-io.c    |  231 ++++++++++++++++++++++++++++++++++++----
 25-akpm/drivers/ide/ide-probe.c |    2 
 25-akpm/include/linux/ide.h     |    6 +
 4 files changed, 260 insertions(+), 23 deletions(-)

diff -puN drivers/ide/ide-disk.c~disk-barrier-ide drivers/ide/ide-disk.c
--- 25/drivers/ide/ide-disk.c~disk-barrier-ide	2004-06-26 13:51:57.801753032 -0700
+++ 25-akpm/drivers/ide/ide-disk.c	2004-06-26 13:51:57.811751512 -0700
@@ -1203,6 +1203,41 @@ static ide_proc_entry_t idedisk_proc[] =
 
 #endif	/* CONFIG_PROC_FS */
 
+static int idedisk_issue_flush(request_queue_t *q, struct gendisk *disk,
+			       sector_t *error_sector)
+{
+	ide_drive_t *drive = q-&gt;queuedata;
+	struct request *rq;
+	int ret;
+
+	if (!drive-&gt;wcache)
+		return 0;
+
+	rq = blk_get_request(q, WRITE, __GFP_WAIT);
+
+	memset(rq-&gt;cmd, 0, sizeof(rq-&gt;cmd));
+
+	if ((drive-&gt;id-&gt;cfs_enable_2 &amp; 0x2400) == 0x2400)
+		rq-&gt;cmd[0] = WIN_FLUSH_CACHE_EXT;
+	else
+		rq-&gt;cmd[0] = WIN_FLUSH_CACHE;
+
+
+	rq-&gt;flags |= REQ_DRIVE_TASK | REQ_SOFTBARRIER;
+	rq-&gt;buffer = rq-&gt;cmd;
+
+	ret = blk_execute_rq(q, disk, rq);
+
+	/*
+	 * if we failed and caller wants error offset, get it
+	 */
+	if (ret &amp;&amp; error_sector)
+		*error_sector = ide_get_error_location(drive, rq-&gt;cmd);
+
+	blk_put_request(rq);
+	return ret;
+}
+
 /*
  * This is tightly woven into the driver-&gt;do_special can not touch.
  * DON'T do it again until a total personality rewrite is committed.
@@ -1241,6 +1276,7 @@ static int set_nowerr(ide_drive_t *drive
 static int write_cache (ide_drive_t *drive, int arg)
 {
 	ide_task_t args;
+	int err;
 
 	if (!ide_id_has_flush_cache(drive-&gt;id))
 		return 1;
@@ -1251,7 +1287,10 @@ static int write_cache (ide_drive_t *dri
 	args.tfRegister[IDE_COMMAND_OFFSET]	= WIN_SETFEATURES;
 	args.command_type			= IDE_DRIVE_TASK_NO_DATA;
 	args.handler				= &amp;task_no_data_intr;
-	(void) ide_raw_taskfile(drive, &amp;args, NULL);
+
+	err = ide_raw_taskfile(drive, &amp;args, NULL);
+	if (err)
+		return err;
 
 	drive-&gt;wcache = arg;
 	return 0;
@@ -1543,6 +1582,9 @@ static void idedisk_setup (ide_drive_t *
 		drive-&gt;wcache = 1;
 
 	write_cache(drive, 1);
+
+	blk_queue_ordered(drive-&gt;queue, 1);
+	blk_queue_issue_flush_fn(drive-&gt;queue, idedisk_issue_flush);
 }
 
 static void ide_cacheflush_p(ide_drive_t *drive)
diff -puN drivers/ide/ide-io.c~disk-barrier-ide drivers/ide/ide-io.c
--- 25/drivers/ide/ide-io.c~disk-barrier-ide	2004-06-26 13:51:57.803752728 -0700
+++ 25-akpm/drivers/ide/ide-io.c	2004-06-26 13:51:57.814751056 -0700
@@ -54,30 +54,62 @@
 #include &lt;asm/io.h&gt;
 #include &lt;asm/bitops.h&gt;
 
-/**
- *	ide_end_request		-	complete an IDE I/O
- *	@drive: IDE device for the I/O
- *	@uptodate: 
- *	@nr_sectors: number of sectors completed
- *
- *	This is our end_request wrapper function. We complete the I/O
- *	update random number input and dequeue the request, which if
- *	it was tagged may be out of order.
+static void ide_fill_flush_cmd(ide_drive_t *drive, struct request *rq)
+{
+	char *buf = rq-&gt;cmd;
+
+	/*
+	 * reuse cdb space for ata command
+	 */
+	memset(buf, 0, sizeof(rq-&gt;cmd));
+
+	rq-&gt;flags |= REQ_DRIVE_TASK | REQ_STARTED;
+	rq-&gt;buffer = buf;
+	rq-&gt;buffer[0] = WIN_FLUSH_CACHE;
+
+	if (drive-&gt;id-&gt;cfs_enable_2 &amp; 0x2400)
+		rq-&gt;buffer[0] = WIN_FLUSH_CACHE_EXT;
+}
+
+/*
+ * preempt pending requests, and store this cache flush for immediate
+ * execution
  */
- 
-int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
+static struct request *ide_queue_flush_cmd(ide_drive_t *drive,
+					   struct request *rq, int post)
 {
-	struct request *rq;
-	unsigned long flags;
-	int ret = 1;
+	struct request *flush_rq = &amp;HWGROUP(drive)-&gt;wrq;
 
-	spin_lock_irqsave(&amp;ide_lock, flags);
-	rq = HWGROUP(drive)-&gt;rq;
+	/*
+	 * write cache disabled, just return barrier write immediately
+	 */
+	if (!drive-&gt;wcache)
+		return rq;
 
-	BUG_ON(!(rq-&gt;flags &amp; REQ_STARTED));
+	ide_init_drive_cmd(flush_rq);
+	ide_fill_flush_cmd(drive, flush_rq);
 
-	if (!nr_sectors)
-		nr_sectors = rq-&gt;hard_cur_sectors;
+	flush_rq-&gt;special = rq;
+	flush_rq-&gt;nr_sectors = rq-&gt;nr_sectors;
+
+	if (!post) {
+		drive-&gt;doing_barrier = 1;
+		flush_rq-&gt;flags |= REQ_BAR_PREFLUSH;
+		blkdev_dequeue_request(rq);
+	} else
+		flush_rq-&gt;flags |= REQ_BAR_POSTFLUSH;
+
+	__elv_add_request(drive-&gt;queue, flush_rq, ELEVATOR_INSERT_FRONT, 0);
+	HWGROUP(drive)-&gt;rq = NULL;
+	return flush_rq;
+}
+
+static int __ide_end_request(ide_drive_t *drive, struct request *rq,
+			     int uptodate, int nr_sectors)
+{
+	int ret = 1;
+
+	BUG_ON(!(rq-&gt;flags &amp; REQ_STARTED));
 
 	/*
 	 * if failfast is set on a request, override number of sectors and
@@ -86,6 +118,9 @@ int ide_end_request (ide_drive_t *drive,
 	if (blk_noretry_request(rq) &amp;&amp; !uptodate)
 		nr_sectors = rq-&gt;hard_nr_sectors;
 
+	if (!blk_fs_request(rq) &amp;&amp; !uptodate &amp;&amp; !rq-&gt;errors)
+		rq-&gt;errors = -EIO;
+
 	/*
 	 * decide whether to reenable DMA -- 3 is a random magic for now,
 	 * if we DMA timeout more than 3 times, just stay in PIO
@@ -97,15 +132,56 @@ int ide_end_request (ide_drive_t *drive,
 
 	if (!end_that_request_first(rq, uptodate, nr_sectors)) {
 		add_disk_randomness(rq-&gt;rq_disk);
+
+		if (blk_rq_tagged(rq))
+			blk_queue_end_tag(drive-&gt;queue, rq);
+
 		blkdev_dequeue_request(rq);
 		HWGROUP(drive)-&gt;rq = NULL;
 		end_that_request_last(rq);
 		ret = 0;
 	}
-	spin_unlock_irqrestore(&amp;ide_lock, flags);
 	return ret;
 }
 
+/**
+ *	ide_end_request		-	complete an IDE I/O
+ *	@drive: IDE device for the I/O
+ *	@uptodate:
+ *	@nr_sectors: number of sectors completed
+ *
+ *	This is our end_request wrapper function. We complete the I/O
+ *	update random number input and dequeue the request, which if
+ *	it was tagged may be out of order.
+ */
+
+int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
+{
+	struct request *rq;
+	unsigned long flags;
+	int ret = 1;
+
+	spin_lock_irqsave(&amp;ide_lock, flags);
+	rq = HWGROUP(drive)-&gt;rq;
+
+	if (!nr_sectors)
+		nr_sectors = rq-&gt;hard_cur_sectors;
+
+	if (!blk_barrier_rq(rq))
+		ret = __ide_end_request(drive, rq, uptodate, nr_sectors);
+	else {
+		struct request *flush_rq = &amp;HWGROUP(drive)-&gt;wrq;
+
+		flush_rq-&gt;nr_sectors -= nr_sectors;
+		if (!flush_rq-&gt;nr_sectors) {
+			ide_queue_flush_cmd(drive, rq, 1);
+			ret = 0;
+		}
+	}
+
+	spin_unlock_irqrestore(&amp;ide_lock, flags);
+	return ret;
+}
 EXPORT_SYMBOL(ide_end_request);
 
 /**
@@ -137,6 +213,96 @@ static void ide_complete_pm_request (ide
 	spin_unlock_irqrestore(&amp;ide_lock, flags);
 }
 
+/*
+ * FIXME: probably move this somewhere else, name is bad too :)
+ */
+u64 ide_get_error_location(ide_drive_t *drive, char *args)
+{
+	u32 high, low;
+	u8 hcyl, lcyl, sect;
+	u64 sector;
+
+	high = 0;
+	hcyl = args[5];
+	lcyl = args[4];
+	sect = args[3];
+
+	if (drive-&gt;id-&gt;cfs_enable_2 &amp; 0x2400) {
+		low = (hcyl &lt;&lt; 16) | (lcyl &lt;&lt; 8) | sect;
+		HWIF(drive)-&gt;OUTB(drive-&gt;ctl|0x80, IDE_CONTROL_REG);
+		high = ide_read_24(drive);
+	} else {
+		u8 cur = HWIF(drive)-&gt;INB(IDE_SELECT_REG);
+		if (cur &amp; 0x40)
+			low = (hcyl &lt;&lt; 16) | (lcyl &lt;&lt; 8) | sect;
+		else {
+			low = hcyl * drive-&gt;head * drive-&gt;sect;
+			low += lcyl * drive-&gt;sect;
+			low += sect - 1;
+		}
+	}
+
+	sector = ((u64) high &lt;&lt; 24) | low;
+	return sector;
+}
+EXPORT_SYMBOL(ide_get_error_location);
+
+static void ide_complete_barrier(ide_drive_t *drive, struct request *rq,
+				 int error)
+{
+	struct request *real_rq = rq-&gt;special;
+	int good_sectors, bad_sectors;
+	sector_t sector;
+
+	if (!error) {
+		if (blk_barrier_postflush(rq)) {
+			/*
+			 * this completes the barrier write
+			 */
+			__ide_end_request(drive, real_rq, 1, real_rq-&gt;hard_nr_sectors);
+			drive-&gt;doing_barrier = 0;
+		} else {
+			/*
+			 * just indicate that we did the pre flush
+			 */
+			real_rq-&gt;flags |= REQ_BAR_PREFLUSH;
+			elv_requeue_request(drive-&gt;queue, real_rq);
+		}
+		/*
+		 * all is fine, return
+		 */
+		return;
+	}
+
+	/*
+	 * bummer, flush failed. if it was the pre-flush, fail the barrier.
+	 * if it was the post-flush, complete the succesful part of the request
+	 * and fail the rest
+	 */
+	good_sectors = 0;
+	if (blk_barrier_postflush(rq)) {
+		sector = ide_get_error_location(drive, rq-&gt;buffer);
+
+		if ((sector &gt;= real_rq-&gt;hard_sector) &amp;&amp;
+		    (sector &lt; real_rq-&gt;hard_sector + real_rq-&gt;hard_nr_sectors))
+			good_sectors = sector - real_rq-&gt;hard_sector;
+	} else
+		sector = real_rq-&gt;hard_sector;
+
+	bad_sectors = real_rq-&gt;hard_nr_sectors - good_sectors;
+	if (good_sectors)
+		__ide_end_request(drive, real_rq, 1, good_sectors);
+	if (bad_sectors)
+		__ide_end_request(drive, real_rq, 0, bad_sectors);
+
+	drive-&gt;doing_barrier = 0;
+
+	printk(KERN_ERR "%s: failed barrier write: "
+			"sector=%Lx(good=%d/bad=%d)\n",
+			drive-&gt;name, (unsigned long long)sector,
+			good_sectors, bad_sectors);
+}
+
 /**
  *	ide_end_drive_cmd	-	end an explicit drive command
  *	@drive: command 
@@ -226,6 +392,10 @@ void ide_end_drive_cmd (ide_drive_t *dri
 
 	spin_lock_irqsave(&amp;ide_lock, flags);
 	blkdev_dequeue_request(rq);
+
+	if (blk_barrier_preflush(rq) || blk_barrier_postflush(rq))
+		ide_complete_barrier(drive, rq, err);
+
 	HWGROUP(drive)-&gt;rq = NULL;
 	end_that_request_last(rq);
 	spin_unlock_irqrestore(&amp;ide_lock, flags);
@@ -712,6 +882,15 @@ static inline ide_drive_t *choose_drive 
 repeat:	
 	best = NULL;
 	drive = hwgroup-&gt;drive;
+
+	/*
+	 * drive is doing pre-flush, ordered write, post-flush sequence. even
+	 * though that is 3 requests, it must be seen as a single transaction.
+	 * we must not preempt this drive until that is complete
+	 */
+	if (drive-&gt;doing_barrier)
+		return drive;
+
 	do {
 		if ((!drive-&gt;sleep || time_after_eq(jiffies, drive-&gt;sleep))
 		    &amp;&amp; !elv_queue_empty(drive-&gt;queue)) {
@@ -868,6 +1047,13 @@ void ide_do_request (ide_hwgroup_t *hwgr
 		}
 
 		/*
+		 * if rq is a barrier write, issue pre cache flush if not
+		 * already done
+		 */
+		if (blk_barrier_rq(rq) &amp;&amp; !blk_barrier_preflush(rq))
+			rq = ide_queue_flush_cmd(drive, rq, 0);
+
+		/*
 		 * Sanity: don't accept a request that isn't a PM request
 		 * if we are currently power managed. This is very important as
 		 * blk_stop_queue() doesn't prevent the elv_next_request()
@@ -917,7 +1103,9 @@ EXPORT_SYMBOL(ide_do_request);
  */
 void do_ide_request(request_queue_t *q)
 {
-	ide_do_request(q-&gt;queuedata, IDE_NO_IRQ);
+	ide_drive_t *drive = q-&gt;queuedata;
+
+	ide_do_request(HWGROUP(drive), IDE_NO_IRQ);
 }
 
 /*
@@ -1286,6 +1474,7 @@ void ide_init_drive_cmd (struct request 
 {
 	memset(rq, 0, sizeof(*rq));
 	rq-&gt;flags = REQ_DRIVE_CMD;
+	rq-&gt;ref_count = 1;
 }
 
 EXPORT_SYMBOL(ide_init_drive_cmd);
diff -puN drivers/ide/ide-probe.c~disk-barrier-ide drivers/ide/ide-probe.c
--- 25/drivers/ide/ide-probe.c~disk-barrier-ide	2004-06-26 13:51:57.805752424 -0700
+++ 25-akpm/drivers/ide/ide-probe.c	2004-06-26 13:51:57.815750904 -0700
@@ -893,7 +893,7 @@ static int ide_init_queue(ide_drive_t *d
 	if (!q)
 		return 1;
 
-	q-&gt;queuedata = HWGROUP(drive);
+	q-&gt;queuedata = drive;
 	blk_queue_segment_boundary(q, 0xffff);
 
 	if (!hwif-&gt;rqsize)
diff -puN include/linux/ide.h~disk-barrier-ide include/linux/ide.h
--- 25/include/linux/ide.h~disk-barrier-ide	2004-06-26 13:51:57.806752272 -0700
+++ 25-akpm/include/linux/ide.h	2004-06-26 13:51:57.816750752 -0700
@@ -780,6 +780,7 @@ typedef struct ide_drive_s {
 	u8	sect;		/* "real" sectors per track */
 	u8	bios_head;	/* BIOS/fdisk/LILO number of heads */
 	u8	bios_sect;	/* BIOS/fdisk/LILO sectors per track */
+	u8	doing_barrier;	/* state, 1=currently doing flush */
 
 	unsigned int	bios_cyl;	/* BIOS/fdisk/LILO number of cyls */
 	unsigned int	cyl;		/* "real" number of cyls */
@@ -1293,6 +1294,11 @@ extern ide_startstop_t ide_do_reset (ide
 extern void ide_init_drive_cmd (struct request *rq);
 
 /*
+ * this function returns error location sector offset in case of a write error
+ */
+extern u64 ide_get_error_location(ide_drive_t *, char *);
+
+/*
  * "action" parameter type for ide_do_drive_cmd() below.
  */
 typedef enum {
_
</pre></body></html>