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

From: Alan Stern
Date: Mon Sep 08 2003 - 14:24:37 EST


On Fri, 5 Sep 2003, Andreas Dilger wrote:

> On Sep 05, 2003 13:46 -0400, 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?
>
> If you open the file with O_DIRECT, it should read/write directly on the
> disk, and it will also invalidate any existing cache for the read/written
> area.

I tried doing that, but it caused a segmentation violation. The trouble
was this line near the start of fs/direct_io.c:dio_refill_pages()

down_read(&current->mm->mmap_sem);

Unfortunately, in a kernel thread (which is where my code runs)
current->mm is NULL.

Can anybody offer additional advice? How about a way to invalidate all
the page cache entries that contain a page from the file?

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/