public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@suse.de>
To: Arjan van de Ven <arjanv@redhat.com>
Cc: linux-kernel@vger.kernel.org, B.Zolnierkiewicz@elka.pw.edu.pl,
	akpm@osdl.org
Subject: Re: Force IDE cache flush on shutdown
Date: Thu, 6 May 2004 10:05:57 +0200	[thread overview]
Message-ID: <20040506080556.GD2009@suse.de> (raw)
In-Reply-To: <20040506080411.GD12862@devserv.devel.redhat.com>

On Thu, May 06 2004, Arjan van de Ven wrote:
> 
> On Thu, May 06, 2004 at 09:58:10AM +0200, Jens Axboe wrote:> On Thu, May 06 2004, Arjan van de Ven wrote:
> > > Hi,
> > > 
> > > Alan discovered the hard way that the current 2.6 IDE code doesn't do a
> > > cache-flush on shutdown. The patch below forward ports this from 2.4. In
> > > addition it fixes a bug where the ->wcache value only got determined for
> > > removable disks not all disks. (that fix is from Alan, all other bugs are
> > > mine ;)
> > 
> > Yeah that's a dumb bug, I fixed that in the barrier patches as well (but
> > forgot to send it in).
> > 
> > Maybe you could send that in seperately first, it needs to go in
> > regardless.
> 
> 
> ok below are the uncontended bits
> 1) calculate wcache for non-removable disks too
> 2) flush the cache BEFORE unlocking the door on removable media,
>    otherwise you have a small race with the human..
> 
> it makes sense for these to go in separate; I'm working on the shutdown hook
> now (and testing which is the fun part ;)
> 
> diff -urNp linux-1110/drivers/ide/ide-disk.c linux-1120/drivers/ide/ide-disk.c
> --- linux-1110/drivers/ide/ide-disk.c
> +++ linux-1120/drivers/ide/ide-disk.c
> @@ -1729,11 +1733,11 @@ static ide_driver_t idedisk_driver = {
>  
>  static int idedisk_open(struct inode *inode, struct file *filp)
>  {
> +	u8 cf;
>  	ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
>  	drive->usage++;
>  	if (drive->removable && drive->usage == 1) {
>  		ide_task_t args;
> -		u8 cf;
>  		memset(&args, 0, sizeof(ide_task_t));
>  		args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK;
>  		args.command_type = IDE_DRIVE_TASK_NO_DATA;
> @@ -1746,18 +1750,18 @@ static int idedisk_open(struct inode *in
>  		 */
>  		if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
>  			drive->doorlocking = 0;
> -		drive->wcache = 0;
> -		/* Cache enabled ? */
> -		if (drive->id->csfo & 1)
> -		drive->wcache = 1;
> -		/* Cache command set available ? */
> -		if (drive->id->cfs_enable_1 & (1<<5))
> -			drive->wcache = 1;
> -		/* ATA6 cache extended commands */
> -		cf = drive->id->command_set_2 >> 24;
> -		if((cf & 0xC0) == 0x40 && (cf & 0x30) != 0)
> -			drive->wcache = 1;
>  	}
> +	drive->wcache = 0;
> +	/* Cache enabled ? */
> +	if (drive->id->csfo & 1)
> +		drive->wcache = 1;
> +	/* Cache command set available ? */
> +	if (drive->id->cfs_enable_1 & (1<<5))
> +		drive->wcache = 1;
> +	/* ATA6 cache extended commands */
> +	cf = drive->id->command_set_2 >> 24;
> +	if((cf & 0xC0) == 0x40 && (cf & 0x30) != 0)
> +		drive->wcache = 1;
>  	return 0;
>  }
>  
> @@ -1779,6 +1783,7 @@ static int ide_cacheflush_p(ide_drive_t 
>  static int idedisk_release(struct inode *inode, struct file *filp)
>  {
>  	ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
> +	ide_cacheflush_p(drive);
>  	if (drive->removable && drive->usage == 1) {
>  		ide_task_t args;
>  		memset(&args, 0, sizeof(ide_task_t));
> @@ -1788,7 +1793,6 @@ static int idedisk_release(struct inode 
>  		if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
>  			drive->doorlocking = 0;
>  	}
> -	ide_cacheflush_p(drive);
>  	drive->usage--;
>  	return 0;
>  }

Looks good to me.

-- 
Jens Axboe


      reply	other threads:[~2004-05-06  8:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-06  7:04 Force IDE cache flush on shutdown Arjan van de Ven
2004-05-06  7:49 ` Christoph Hellwig
2004-05-06  7:50   ` Arjan van de Ven
2004-05-06  7:55     ` Christoph Hellwig
2004-05-06 10:46       ` Arjan van de Ven
2004-05-06 10:52         ` Christoph Hellwig
2004-05-06 11:33           ` Arjan van de Ven
2004-05-06 11:45             ` Nigel Cunningham
2004-05-06 11:45             ` Arjan van de Ven
2004-05-06 12:36             ` Bartlomiej Zolnierkiewicz
2004-05-07  1:08               ` Benjamin Herrenschmidt
2004-05-06 11:38   ` Bartlomiej Zolnierkiewicz
2004-05-07  1:09     ` Benjamin Herrenschmidt
2004-05-09  2:00   ` Pavel Machek
2004-05-06  7:58 ` Jens Axboe
2004-05-06  8:04   ` Arjan van de Ven
2004-05-06  8:05     ` Jens Axboe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040506080556.GD2009@suse.de \
    --to=axboe@suse.de \
    --cc=B.Zolnierkiewicz@elka.pw.edu.pl \
    --cc=akpm@osdl.org \
    --cc=arjanv@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox