Re: How can I force a read to hit the disk?

From: Alan Stern
Date: Fri Sep 05 2003 - 14:23:32 EST


On Fri, 5 Sep 2003, Richard B. Johnson wrote:

> On Fri, 5 Sep 2003, Alan Stern wrote:
>
> > My kernel module for Linux-2.6 needs to be able to verify that the media
> > on which a file resides actually is readable. How can I do that?
> >
> > It would certainly suffice to use the normal VFS read routines, if there
> > was some way to force the system to actually read from the device rather
> > than just returning data already in the cache. So I guess it would be
> > enough to perform an fdatasync for the file and then invalidate the file's
> > cache entries. How does one invalidate a file's cache entries? Does
> > filemap_flush() perform both these operations for you?
> >
> > TIA,
> >
> > Alan Stern
>
> Force a read() before some write data was flushed to the disk??

No, no! Force a read() _after_ all the dirty buffers are flushed to the
disk.

> Well, if you insist, just do a raw read of the device after
> you find the inode, then offset, that your data is on. You
> can walk the same fs structure(s) as the active file-system
> to get all meta-data information.

I assume you're kidding... :-)

> ...but... The most current data is probably in the kernel
> buffers. I don't think you really want what you are asking
> for.

No, I _do_ want exactly what I asked for. Actually, I would really like a
bit more: to ask the disk drive to read from its media rather than its
cache. But I'll settle for bypassing the O/S's cache.

> If you did a fdatasync(), you get the current data your
> process wrote to go to the disk.

Not if there is a bad sector that causes a read error.

> However, there may be
> other writers. This, too, may not be what you want.

I'm assuming there aren't other writers. It doesn't really matter if
there are. I don't care _what_ data is on the disk; I just want to know
that it is _readable_ without getting hardware errors.

> Also,
> Just because the data was queued to go to a (SCSI) disk,
> doesn't mean it actually got to the platters.

Yes. It's an imperfect world.

Alan Stern

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/