linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Refreshing after OOB file update?
@ 2014-08-28 14:37 Rob Harris
  2014-08-28 23:32 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Rob Harris @ 2014-08-28 14:37 UTC (permalink / raw)
  To: linux-ext4

Greetings. My apologies in advance... I need to ask a weird question and 
can't think of a more appropriate place to ask.

And yes, I know this is a broken/stupid/insane/WTF?/n00b request, but 
bear with me for a second.

I'm writing a FUSE layer for a project that sits on top of a ext4 
filesystem. My daemon will be the ONLY reader and writer; Except! ... 
I've been told that upon request, another (hardware--pcie) component of 
my system needs to be able to write data into a existing file in the 
filesystem DIRECTLY (i.e. using the absolute block ID returned from 
fiemap() ) without my FUSE layer or the ext4 file system knowing that 
the writing is occuring (I get a notification later via another means). 
So, basically, files are changing out from under me. (Assume that they 
know how big the extents are so they won't do anything stupid like 
overrun them or anything.)

Thinking this was insane, I ran a simple test:

- I created a file of all 0's using dd.
- I ran mkfs.ext4 on the file and loop mounted the file system.
- I created a dummy text file comprised of all 'y's (output of the yes 
command).
- I wrote a program to call fiemap() and get the physical location of 
the text file contents in the loop mounted fs file.
- I used dd to write a string into the file (i.e. echo "xxxx" | dd 
of=/tmp/dummy.fs bs=1 seek=138416128 conv=notrunc)
- If I dd if=/tmp/dummy.fs | hexdump -C, then I can see the changes written.
- If I cat the text file, I DON'T see the changes.
- If I touch the text file and cat it, still no joy.
- If I copy the text file to another file, I DON'T see the changes in 
either file.
- If I umount and remount the partition and then cat the file, I CAN see 
the changes.

This tells me (probably naively) that the kernel is caching the old file 
contents.

Is there a way for me to tell the file system that something out-of-band 
change a file contents and to force a re-read from the disk?

Also, this was performed using a loop mount--is the expectation that a 
similar test with live hardware/block device file systems would behave 
similarly?

Thanks again for placating my insanity.
-Rob Harris



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Refreshing after OOB file update?
  2014-08-28 14:37 Refreshing after OOB file update? Rob Harris
@ 2014-08-28 23:32 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2014-08-28 23:32 UTC (permalink / raw)
  To: Rob Harris; +Cc: linux-ext4

On Thu, Aug 28, 2014 at 10:37:04AM -0400, Rob Harris wrote:
> 
> This tells me (probably naively) that the kernel is caching the old file
> contents.

Yes, that's what the page cache is all about.

> Is there a way for me to tell the file system that something out-of-band
> change a file contents and to force a re-read from the disk?

Have your userspace program do an O_DIRECT read.  That will discard
the page cache and do a direct read from the disk.

Cheers,

							- Ted

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-28 23:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-28 14:37 Refreshing after OOB file update? Rob Harris
2014-08-28 23:32 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).