Skip to contentSkip to conversation

extend e2fsprogs functionality to add EXT2_FLAG_DIRECT option

PATCH In review Michal Novotny 6 participants 31 messages Jan 8, 2010 – Jan 14, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extend e2fsprogs functionality to add EXT2_FLAG_DIRECT option

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations. In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

The main reason why this was done is that pygrub (used by xen virtualization user-space package, it's a python version of grub for paravirtualized guests) sometimes uses outdated version of grub.conf file. Modifications to xen package were *not* enough because e2fsprogs doesn't open the files directly. That's why I added EXT2_FLAG_DIRECT support to make read/write operations work directly when passed. It's been tested with pygrub like mentioned above for read operation and it's working fine.

Author: Michal Novotny <[email protected]>
Date:   Wed Dec 23 11:25:40 2009 +0200

extend e{2|4}fsprogs functionality to add EXT2_FLAG_DIRECT option

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations.
In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

lib/ext2fs/ext2fs.h renamed from lib/ext2fs/ext2fs.h.opendirect +1 -0
diff -up e2fsprogs-1.41.9/lib/ext2fs/ext2fs.h.opendirect e2fsprogs-1.41.9/lib/ext2fs/ext2fs.h
@@ -172,6 +172,7 @@ typedef struct ext2_file *ext2_file_t;
 #define EXT2_FLAG_EXCLUSIVE		0x4000
 #define EXT2_FLAG_SOFTSUPP_FEATURES	0x8000
 #define EXT2_FLAG_NOFREE_ON_ERROR	0x10000
+#define EXT2_FLAG_DIRECT		0x20000
 
 /*
  * Special flag in the ext2 inode i_flag field that means that this is
lib/ext2fs/ext2_io.h renamed from lib/ext2fs/ext2_io.h.opendirect +2 -0
diff -up e2fsprogs-1.41.9/lib/ext2fs/ext2_io.h.opendirect e2fsprogs-1.41.9/lib/ext2fs/ext2_io.h
@@ -29,6 +29,7 @@ typedef struct struct_io_channel *io_cha
 typedef struct struct_io_stats *io_stats;
 
 #define CHANNEL_FLAGS_WRITETHROUGH	0x01
+#define CHANNEL_FLAGS_DIRECT		0x02
 
 struct struct_io_channel {
 	errcode_t	magic;
@@ -88,6 +89,7 @@ struct struct_io_manager {
 
 #define IO_FLAG_RW		0x0001
 #define IO_FLAG_EXCLUSIVE	0x0002
+#define IO_FLAG_DIRECT		0x0004
 
 /*
  * Convenience functions....
lib/ext2fs/openfs.c renamed from lib/ext2fs/openfs.c.opendirect +3 -0
diff -up e2fsprogs-1.41.9/lib/ext2fs/openfs.c.opendirect e2fsprogs-1.41.9/lib/ext2fs/openfs.c
@@ -121,6 +121,8 @@ errcode_t ext2fs_open2(const char *name,
 		io_flags |= IO_FLAG_RW;
 	if (flags & EXT2_FLAG_EXCLUSIVE)
 		io_flags |= IO_FLAG_EXCLUSIVE;
+	if (flags & EXT2_FLAG_DIRECT)
+		io_flags |= IO_FLAG_DIRECT;
 	retval = manager->open(fs->device_name, io_flags, &fs->io);
 	if (retval)
 		goto cleanup;
@@ -296,6 +298,7 @@ errcode_t ext2fs_open2(const char *name,
        }
 	fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
 					  EXT2_DESC_PER_BLOCK(fs->super));
+
 	retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
 				&fs->group_desc);
 	if (retval)
lib/ext2fs/unix_io.c renamed from lib/ext2fs/unix_io.c.opendirect +49 -2

95 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Michal Novotny

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations. In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

The main reason why this was done is that pygrub (used by xen virtualization user-space package, it's a python version of grub for paravirtualized guests) sometimes uses outdated version of grub.conf file. Modifications to xen package were *not* enough because e2fsprogs doesn't open the files directly. That's why I added EXT2_FLAG_DIRECT support to make read/write operations work directly when passed. It's been tested with pygrub like mentioned above for read operation and it's working fine.

Can you add to this some kind of data flow overview? Seems like a really odd way to update this file system...

ric

#2 lore raw
Quoted 4 lines · Ric Wheeler
Quoted 3 lines · Michal Novotny

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations. In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

Quoted 8 lines
Quoted 3 lines

The main reason why this was done is that pygrub (used by xen virtualization user-space package, it's a python version of grub for paravirtualized guests) sometimes uses outdated version of grub.conf file. Modifications to xen package were *not* enough because e2fsprogs doesn't open the files directly. That's why I added EXT2_FLAG_DIRECT support to make read/write operations work directly when passed. It's been tested with pygrub like mentioned above for read operation and it's working fine.

Can you add to this some kind of data flow overview? Seems like a really odd way to update this file system...

ric

What do you mean by adding some kind of data flow overview? I am not working on file systems but I needed option open files directly to be added to e2fsprogs to make pygrub working right with not using cached/outdated data so this was the first patch I did for file system so I don't realy know what do you mean by data flow overview ...

Thanks,
Michal

#3 lore raw
Quoted 25 lines · Michal Novotny
Quoted 17 lines · Ric Wheeler
Quoted 16 lines · Michal Novotny

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations.
In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

The main reason why this was done is that pygrub (used by xen virtualization user-space package, it's a python version of grub for paravirtualized guests) sometimes uses outdated version of grub.conf file. Modifications to xen package were *not* enough because e2fsprogs doesn't open the files directly. That's why I added EXT2_FLAG_DIRECT support to make read/write operations work directly when passed. It's been tested with pygrub like mentioned above for read operation and it's working fine.

Quoted 7 lines
Quoted 1 line

Can you add to this some kind of data flow overview? Seems like a really odd way to update this file system...

ric

Quoted 8 lines

What do you mean by adding some kind of data flow overview? I am not working on file systems but I needed option open files directly to be added to e2fsprogs to make pygrub working right with not using cached/outdated data so this was the first patch I did for file system so I don't realy know what do you mean by data flow overview ...

Thanks,
Michal

Hi Michael,

What would be useful is where the data is written (guest/host) and the state of the file system (mounted/unmounted). Which app it is that writes the data that gets cached, who needs to read it and misses that cached data.

From the above, it is really not clear that you should not be able to use existing interfaces to flush any cached data to disk....

ric

#4 lore raw
Quoted 35 lines · Ric Wheeler
Quoted 25 lines · Michal Novotny
Quoted 17 lines · Ric Wheeler
Quoted 16 lines · Michal Novotny

This patch extends functionality of e{2|4}fsprogs to add EXT2_FLAG_DIRECT flag to be passed to ext2fs_open2() function. This internally calls open() function with O_DIRECT and handles the memory alignment for both read and write operations.
In some cases direct access to devices is necessary and that was the main reason for this patch to be done.

The main reason why this was done is that pygrub (used by xen virtualization user-space package, it's a python version of grub for paravirtualized guests) sometimes uses outdated version of grub.conf file. Modifications to xen package were *not* enough because e2fsprogs doesn't open the files directly. That's why I added EXT2_FLAG_DIRECT support to make read/write operations work directly when passed. It's been tested with pygrub like mentioned above for read operation and it's working fine.

Quoted 7 lines
Quoted 1 line

Can you add to this some kind of data flow overview? Seems like a really odd way to update this file system...

ric

Quoted 8 lines

What do you mean by adding some kind of data flow overview? I am not working on file systems but I needed option open files directly to be added to e2fsprogs to make pygrub working right with not using cached/outdated data so this was the first patch I did for file system so I don't realy know what do you mean by data flow overview ...

Thanks,
Michal

Quoted 8 lines

Hi Michael,

What would be useful is where the data is written (guest/host) and the state of the file system (mounted/unmounted). Which app it is that writes the data that gets cached, who needs to read it and misses that cached data.

From the above, it is really not clear that you should not be able to use existing interfaces to flush any cached data to disk....

ric

Hi Ric,
I don't really know if I see your point but the thing here is that there was no way to open a file directly (ie. using O_DIRECT). The direct write support has been added only to make it possible to use both read and write directly. The main reason to create this patch was to add direct read support and flush capability won't help me at all. I am working in Red Hat, Virtualization team on Xen so I am really not that much familiar with file systems but what I needed was an option to read the data directly (using O_DIRECT) in e2fsprogs. One bug was about pygrub (Python version of GRUB of Xen PV guests that is internally using e2fsprogs functionality to access data on ext2/3/4 partition to boot the PV guests) uses outdated/cached data so some modifications were necessary to open everything directly... It was done to Xen by a collegue but there was some open() call with no O_DIRECT set so I investigated this further and it turned out that this call was coming from e2fsprogs library. That was the reason why I needed to add O_DIRECT read support and O_DIRECT write support was added just to make it for both read and write. For write, yes, there may be the option to flush the disk but not for read. To workaround this but dropping caches is a really ugly idea so finally patching e2fsprogs too (along with Xen) turned out to the best idea. Once again, this was done to support O_DIRECT for read function only - it is *not* used for write function and it was added just to make it complete for both read and write functions. Regarding the functionality of read function, this is done in the host machine before the PV guest boots. It reads grub.conf, then it reads initrd and kernel and boots from it... Some incidents of booting outdated grub.conf/initrd and kernel has been reported to us and this patch is to make it don't use caches so outdated data can't be used...

Is the scenario clear or do you need some other information about that?

Thanks,
Michal

#5 lore raw
Quoted 4 lines · Michal Novotny

I don't really know if I see your point but the thing here is that there was no way to open a file directly (ie. using O_DIRECT). The direct write support has been added only to make it possible to use both read and write directly. The main reason to create this patch was to add

Quoted 8 lines

direct read support and flush capability won't help me at all. I am working in Red Hat, Virtualization team on Xen so I am really not that much familiar with file systems but what I needed was an option to read the data directly (using O_DIRECT) in e2fsprogs. One bug was about pygrub (Python version of GRUB of Xen PV guests that is internally using e2fsprogs functionality to access data on ext2/3/4 partition to boot the PV guests) uses outdated/cached data so some modifications were necessary to open everything directly...

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

#6 lore raw
Quoted 15 lines · Christoph Hellwig
Quoted 4 lines · Michal Novotny

I don't really know if I see your point but the thing here is that there was no way to open a file directly (ie. using O_DIRECT). The direct write support has been added only to make it possible to use both read and write directly. The main reason to create this patch was to add

Quoted 9 lines

direct read support and flush capability won't help me at all. I am working in Red Hat, Virtualization team on Xen so I am really not that much familiar with file systems but what I needed was an option to read the data directly (using O_DIRECT) in e2fsprogs. One bug was about pygrub (Python version of GRUB of Xen PV guests that is internally using e2fsprogs functionality to access data on ext2/3/4 partition to boot the PV guests) uses outdated/cached data so some modifications were necessary to open everything directly...

Quoted 5 lines

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

#7 lore raw
Quoted 9 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago
- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs
- once the guest is life it uses the extN kernel driver to access the filesystem

nowhere in this cycle you should have any stale cached data. The kernel always makes sure to write back data on umount/reboot, as does e2fsprogs if actually used to write data (which you said is not the case anyway).

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block device implementation, but these can't cause any problems.

#8 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Quoted 6 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 3 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 3 lines

- once the guest is life it uses the extN kernel driver to access the filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 4 lines

nowhere in this cycle you should have any stale cached data. The kernel always makes sure to write back data on umount/reboot, as does e2fsprogs if actually used to write data (which you said is not the case anyway).

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 4 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block device implementation, but these can't cause any problems.

Michal

#9 lore raw
Quoted 35 lines · Michal Novotny
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Quoted 5 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 2 lines

- once the guest is life it uses the extN kernel driver to access the filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 3 lines

nowhere in this cycle you should have any stale cached data. The kernel always makes sure to write back data on umount/reboot, as does e2fsprogs if actually used to write data (which you said is not the case anyway).

Quoted 7 lines

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 3 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block device implementation, but these can't cause any problems.

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

#10 lore raw
Quoted 42 lines · Ric Wheeler
Quoted 41 lines · Michal Novotny
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Quoted 5 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 2 lines

- once the guest is life it uses the extN kernel driver to access the filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 3 lines

nowhere in this cycle you should have any stale cached data. The kernel always makes sure to write back data on umount/reboot, as does e2fsprogs if actually used to write data (which you said is not the case anyway).

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 3 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block device implementation, but these can't cause any problems.

Quoted 8 lines
Quoted 1 line

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

Michal

#11 lore raw
Quoted 45 lines · Michal Novotny
Quoted 44 lines · Ric Wheeler
Quoted 42 lines · Michal Novotny
Quoted 10 lines · Christoph Hellwig
Quoted 9 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Quoted 5 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 2 lines

- once the guest is life it uses the extN kernel driver to access the filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 3 lines

nowhere in this cycle you should have any stale cached data. The kernel always makes sure to write back data on umount/reboot, as does e2fsprogs if actually used to write data (which you said is not the case anyway).

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 3 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block device implementation, but these can't cause any problems.

Michal

Quoted 8 lines
Quoted 6 lines

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

One more thing to point out, let's have a look at: https://bugzilla.redhat.com/show_bug.cgi?id=466681#c15 .This is about workaround to drop caches to be added to pygrub in the host machine using this command:

echo 1> /proc/sys/vm/drop_caches

So this really looks like the caching issue if it's working fine after dropping the caches. That may be the reason why this could be fine with this patch present in e2fsprogs.

Michal

#12 lore raw
Quoted 75 lines · Michal Novotny
Quoted 60 lines · Michal Novotny
Quoted 59 lines · Ric Wheeler
Quoted 43 lines · Michal Novotny
Quoted 15 lines · Christoph Hellwig
Quoted 6 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for
PV guest and after this is read and selected in pygrub then the guest is

Quoted 8 lines

booted using the kernel and initrd extracted from the image (after which
the file is closed). Once again, nothing uses write support and it was
added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the
only way to make it use non-cached data.

Quoted 5 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 2 lines

- once the guest is life it uses the extN kernel driver to access the filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 6 lines

nowhere in this cycle you should have any stale cached data. The kernel
always makes sure to write back data on umount/reboot, as does e2fsprogs
if actually used to write data (which you said is not the case anyway).

Quoted 8 lines

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 4 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block
device implementation, but these can't cause any problems.

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

Quoted 9 lines
Quoted 5 lines

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

One more thing to point out, let's have a look at:
https://bugzilla.redhat.com/show_bug.cgi?id=466681#c15 .This is about workaround to drop caches to be added to pygrub in the host machine using this command:

Quoted 7 lines

echo 1> /proc/sys/vm/drop_caches

So this really looks like the caching issue if it's working fine after dropping the caches. That may be the reason why this could be fine with this patch present in e2fsprogs.

Michal

That BZ has a pretty long and twisted history, but after a quick read, I still don't see why a cleanly shutdown guest would have issues with caching that using O_DIRECT on read would help.

We will need to dig into a bit more...

ric

#13 lore raw
Quoted 84 lines · Ric Wheeler
Quoted 83 lines · Michal Novotny
Quoted 62 lines · Michal Novotny
Quoted 61 lines · Ric Wheeler
Quoted 45 lines · Michal Novotny
Quoted 15 lines · Christoph Hellwig
Quoted 6 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for
PV guest and after this is read and selected in pygrub then the guest is

Quoted 8 lines

booted using the kernel and initrd extracted from the image (after which
the file is closed). Once again, nothing uses write support and it was
added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the
only way to make it use non-cached data.

Quoted 6 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the
host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 3 lines

- once the guest is life it uses the extN kernel driver to access the
filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 6 lines

nowhere in this cycle you should have any stale cached data. The kernel
always makes sure to write back data on umount/reboot, as does e2fsprogs
if actually used to write data (which you said is not the case anyway).

Quoted 8 lines

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 4 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block
device implementation, but these can't cause any problems.

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

Quoted 9 lines
Quoted 5 lines

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

One more thing to point out, let's have a look at:
https://bugzilla.redhat.com/show_bug.cgi?id=466681#c15 .This is about workaround to drop caches to be added to pygrub in the host machine using this command:

echo 1> /proc/sys/vm/drop_caches

So this really looks like the caching issue if it's working fine after dropping the caches. That may be the reason why this could be fine with this patch present in e2fsprogs.

Quoted 8 lines
Quoted 1 line

Michal

That BZ has a pretty long and twisted history, but after a quick read, I still don't see why a cleanly shutdown guest would have issues with caching that using O_DIRECT on read would help.

We will need to dig into a bit more...

ric

I am not saying we don't need to dig a little bit more, we surely do but unfortunately I am waiting for information from reporter. But I am also thinking that this O_DIRECT functionality support to bypass caches could be useful...

Thanks,
Michal

#14 lore raw
Quoted 89 lines · Michal Novotny
Quoted 88 lines · Ric Wheeler
Quoted 77 lines · Michal Novotny
Quoted 62 lines · Michal Novotny
Quoted 61 lines · Ric Wheeler
Quoted 45 lines · Michal Novotny
Quoted 15 lines · Christoph Hellwig
Quoted 6 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for
PV guest and after this is read and selected in pygrub then the guest is

Quoted 8 lines

booted using the kernel and initrd extracted from the image (after which
the file is closed). Once again, nothing uses write support and it was
added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the
only way to make it use non-cached data.

Quoted 6 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the
host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 2 lines

- before booting a guest your "pygrub" tools needs to read files on it, and it's doing so using e2fsprogs

Correct.

Quoted 3 lines

- once the guest is life it uses the extN kernel driver to access the
filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 6 lines

nowhere in this cycle you should have any stale cached data. The kernel
always makes sure to write back data on umount/reboot, as does e2fsprogs
if actually used to write data (which you said is not the case anyway).

Quoted 8 lines

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 4 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block
device implementation, but these can't cause any problems.

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

Quoted 9 lines
Quoted 5 lines

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

One more thing to point out, let's have a look at:
https://bugzilla.redhat.com/show_bug.cgi?id=466681#c15 .This is about workaround to drop caches to be added to pygrub in the host machine using this command:

Quoted 7 lines

echo 1> /proc/sys/vm/drop_caches

So this really looks like the caching issue if it's working fine after dropping the caches. That may be the reason why this could be fine with this patch present in e2fsprogs.

Michal

That BZ has a pretty long and twisted history, but after a quick read, I still don't see why a cleanly shutdown guest would have issues with caching that using O_DIRECT on read would help.

Quoted 13 lines
Quoted 4 lines

We will need to dig into a bit more...

ric

I am not saying we don't need to dig a little bit more, we surely do but unfortunately I am waiting for information from reporter. But I am also thinking that this O_DIRECT functionality support to bypass caches could be useful...

Thanks,
Michal

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

I can not see where the cache could cause this problem but is it possible that it is in the Host file system rather than than the guest where it is causing a problem; If a guest shuts down it writes to it's file system and all is good only it's file system is a file on another file system. So the cache looking after those writes as managed by the hyper visor or whatever could hold that data un-flushed for whatever reason. But when the guest starts up it should get the cached or most recent version, this should not be stale data unless more than one guest is using this file system and they are overwriting each others files, then a cached version might be newer and different from what is expected and the on disk version might be the old and expected version.
End user needs to provide more information.

Chris.

#15 lore raw
Quoted 99 lines · Chris Lee
Quoted 96 lines · Michal Novotny
Quoted 85 lines · Ric Wheeler
Quoted 84 lines · Michal Novotny
Quoted 63 lines · Michal Novotny
Quoted 62 lines · Ric Wheeler
Quoted 46 lines · Michal Novotny
Quoted 15 lines · Christoph Hellwig
Quoted 6 lines · Michal Novotny

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for
PV guest and after this is read and selected in pygrub then the guest is

Quoted 8 lines

booted using the kernel and initrd extracted from the image (after which
the file is closed). Once again, nothing uses write support and it was
added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the
only way to make it use non-cached data.

Quoted 6 lines

So what caches get in the way? From the above it seems the situation is the following:

- filesystem N is a guest filesystem. It's not usually mounted on the
host, except for initial setup long time ago

Yes, it is really a guest file system. This is not mounted in the host and the reason is to get actual version of grub.conf, initrd and kernel to be booted...

Quoted 3 lines

- before booting a guest your "pygrub" tools needs to read files on
it, and it's doing so using e2fsprogs

Correct.

Quoted 3 lines

- once the guest is life it uses the extN kernel driver to access the
filesystem

That's right. So this is no longer pygrub responsibility...

Quoted 6 lines

nowhere in this cycle you should have any stale cached data. The kernel
always makes sure to write back data on umount/reboot, as does e2fsprogs
if actually used to write data (which you said is not the case anyway).

Quoted 8 lines

In fact I was unable to run into those problems myself but reporter/customer did.

Quoted 4 lines

The only data that may be in the cache are unmodified data from reads on the block device from either e2fsprogs or a suboptimal virtual block
device implementation, but these can't cause any problems.

Michal

If the guest is the only one (when running) that installs a new grub.conf file and kernel and it shuts down properly, you should be good. It if does not shut down cleanly, it could have a stale grub.conf file (or worse, a partially written one), but using O_DIRECT to bypass the file system cache should not help.

Quoted 9 lines
Quoted 5 lines

If we cannot reproduce this failure, sounds like we need to go back and get a better understanding of what the customer saw?

ric

That's right. I am going write an e-mail regarding this information to the reproducer if this bug and tell him that I need more information about what's happening at the customer side.

One more thing to point out, let's have a look at:
https://bugzilla.redhat.com/show_bug.cgi?id=466681#c15 .This is about workaround to drop caches to be added to pygrub in the host machine using this command:

echo 1> /proc/sys/vm/drop_caches

So this really looks like the caching issue if it's working fine after dropping the caches. That may be the reason why this could be fine with this patch present in e2fsprogs.

Quoted 8 lines
Quoted 1 line

Michal

That BZ has a pretty long and twisted history, but after a quick read, I still don't see why a cleanly shutdown guest would have issues with caching that using O_DIRECT on read would help.

We will need to dig into a bit more...

ric

I am not saying we don't need to dig a little bit more, we surely do but unfortunately I am waiting for information from reporter. But I am also thinking that this O_DIRECT functionality support to bypass caches could be useful...

Quoted 8 lines
Quoted 7 lines

Thanks,
Michal

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

I can not see where the cache could cause this problem but is it possible that it is in the Host file system rather than than the guest where it is causing a problem;

This may be right because drop caches in the host is a working workaround. Also, I am having some information about it. Scott wrote that he was able to reproduce it but with my patches applied it is working fine. I am waiting for more information about that and customer test results...

Michal

#16 lore raw
In reply to Michal Novotny

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

#17 lore raw
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 4 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

#18 lore raw
Quoted 2 lines · Michal Novotny

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

Yes, the Xen blkback driver just submits I/O directly without using the right interfaces to force cache coherency. It might be relatively easy to hack a call in to flush all caches when it starts up, but given how it bypasses all abstractions it's almost impossible to give full coherency as if using the normal block device interfaces.

#19 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 3 lines · Michal Novotny

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

Yes, the Xen blkback driver just submits I/O directly without using the right interfaces to force cache coherency. It might be relatively easy to hack a call in to flush all caches when it starts up, but given how it bypasses all abstractions it's almost impossible to give full coherency as if using the normal block device interfaces.

Ok, this way the fix to the drivers should be done. Thanks for your investigation. I just forwarded your reply to other members of my team.

Thanks,
Michal

#20 lore raw
In reply to Michal Novotny
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

ric

#21 lore raw
Quoted 19 lines · Ric Wheeler
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Quoted 8 lines

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

ric

Ok, so you think this is not good to do this patch for e2fsprogs for direct access support? The only things we could do now is to fix the backend drivers or create a workaround to drop caches? I need to discuss this further with guys in my team...

Thanks,
Michal

#22 lore raw
Quoted 32 lines · Michal Novotny
Quoted 31 lines · Ric Wheeler
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

Quoted 6 lines
Quoted 2 lines

ric

Ok, so you think this is not good to do this patch for e2fsprogs for direct access support? The only things we could do now is to fix the backend drivers or create a workaround to drop caches? I need to discuss this further with guys in my team...

I do think that patching it up in e2fsprogs is unnecessarily invasive; it's fixing it at the wrong spot.

Any block dev IO from the host is dangerous; fixing it only in e2fsprogs for this one case doesn't seem like the right course of action.

-Eric

Quoted 6 lines

Thanks,
Michal

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw
Quoted 40 lines · Eric Sandeen
Quoted 32 lines · Michal Novotny
Quoted 31 lines · Ric Wheeler
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

Quoted 6 lines
Quoted 2 lines

ric

Ok, so you think this is not good to do this patch for e2fsprogs for direct access support? The only things we could do now is to fix the backend drivers or create a workaround to drop caches? I need to discuss this further with guys in my team...

Quoted 7 lines

I do think that patching it up in e2fsprogs is unnecessarily invasive; it's fixing it at the wrong spot.

Any block dev IO from the host is dangerous; fixing it only in e2fsprogs for this one case doesn't seem like the right course of action.

-Eric

It actually could produce some nastier issues where it would work a bit, the bad data gets flushed back to the backing store and then your O_DIRECT read would be broken.

Also, for normal users of e2fsprogs, they should never bypass the cache...

ric

#24 lore raw
Quoted 47 lines · Ric Wheeler
Quoted 46 lines · Eric Sandeen
Quoted 32 lines · Michal Novotny
Quoted 31 lines · Ric Wheeler
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

Quoted 6 lines
Quoted 2 lines

ric

Ok, so you think this is not good to do this patch for e2fsprogs for direct access support? The only things we could do now is to fix the backend drivers or create a workaround to drop caches? I need to discuss this further with guys in my team...

I do think that patching it up in e2fsprogs is unnecessarily invasive; it's fixing it at the wrong spot.

Any block dev IO from the host is dangerous; fixing it only in e2fsprogs for this one case doesn't seem like the right course of action.

Quoted 7 lines
Quoted 1 line

-Eric

It actually could produce some nastier issues where it would work a bit, the bad data gets flushed back to the backing store and then your O_DIRECT read would be broken.

Also, for normal users of e2fsprogs, they should never bypass the cache...

ric

Ok, good to know the normal users should never bypass the cache. That way this seems to be some kind of kernel bug...

Thank you all for your input,
Michal

#25 lore raw
Quoted 48 lines · Michal Novotny
Quoted 47 lines · Ric Wheeler
Quoted 46 lines · Eric Sandeen
Quoted 32 lines · Michal Novotny
Quoted 31 lines · Ric Wheeler
Quoted 10 lines · Michal Novotny
Quoted 9 lines · Christoph Hellwig

Ok, I looked at the issue. The problem is that the Xen backend drivers are (as expected) utterly braindead and submit bios directly from the virtualization backed without using proper abstractions and thus bypassing all the cache coherency features in the fileystems (the block device nodes are just another mini-filesystem in that respect). So when you first have buffered access in the host pages may stay in cache and get overwritten directly on disk by a Xen guest, and once the guest is down the host may still use the now stale cached data.

Quoted 5 lines
Quoted 3 lines

I would recommend to migrate your cutomers to KVM which uses the proper abtractions and thus doesn't have this problem. There's a reason after all why all the Xen dom0 mess never got merged to mainline.

So, do you think the problem is in the Xen backend drivers and to make it working right in Xen the driver fix is needed?

If XEN drivers by pass the normal IO and FS stack on the host, then I can understand why the hack to e2fsprogs works but it does not seem like a good fix.

Specifically, the data will continue to be cached (and if dirty, might be written back to the storage eventually).

If we need a work around, you need to drop VM caches for that device before you update the guest's files and possibly again afterwards (and make sure that nothing pulls the data into cache during the operation).

Basically, this sounds like the backend drivers are doing something really, really dangerous....

Quoted 6 lines
Quoted 2 lines

ric

Ok, so you think this is not good to do this patch for e2fsprogs for direct access support? The only things we could do now is to fix the backend drivers or create a workaround to drop caches? I need to discuss this further with guys in my team...

I do think that patching it up in e2fsprogs is unnecessarily invasive; it's fixing it at the wrong spot.

Any block dev IO from the host is dangerous; fixing it only in e2fsprogs for this one case doesn't seem like the right course of action.

Quoted 9 lines
Quoted 7 lines
Quoted 1 line

-Eric

It actually could produce some nastier issues where it would work a bit, the bad data gets flushed back to the backing store and then your O_DIRECT read would be broken.

Also, for normal users of e2fsprogs, they should never bypass the cache...

ric

Ok, good to know the normal users should never bypass the cache. That way this seems to be some kind of kernel bug...

Hi,
finally, after discussing this with several people we decided it's better to solve it in kernel path since Xen is using some weird IO path like mentioned. Since this patch is about using O_DIRECT in e2fsprogs which I've been told that normal e2fsprogs user should never do I'd like to thanks you all for your help and tell you to ignore this patch since we're going to solve it some other way, ie. fix this in the kernel itself.

Thanks for your help!

Michal

#26 lore raw
In reply to Michal Novotny
Quoted 7 lines · Michal Novotny
Quoted 4 lines · Christoph Hellwig

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Michal, I think the thing that is confusing everyone is that if you are not accessing a live filesystem, and you are not doing the writes yourself, then why is it bad to read cached data? How is it that the cached data becomes stale if pygrub isn't modifying it, and there is nothing else mounting the filesystem?

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

#27 lore raw
Quoted 7 lines · Andreas Dilger
Quoted 6 lines · Michal Novotny
Quoted 4 lines · Christoph Hellwig

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

Quoted 5 lines
Quoted 1 line

Not really, pygrub doesn't do any manipulation with file system and also, it's not working on a life file system. It's called before the guest boots up to read information about grub.conf/initrd and kernel for PV guest and after this is read and selected in pygrub then the guest is booted using the kernel and initrd extracted from the image (after which the file is closed). Once again, nothing uses write support and it was added just to make it use O_DIRECT for both read and write operations but only pygrub uses only read support and O_DIRECT passed here is the only way to make it use non-cached data.

Michal, I think the thing that is confusing everyone is that if you are not accessing a live filesystem, and you are not doing the writes yourself, then why is it bad to read cached data? How is it that the cached data becomes stale if pygrub isn't modifying it, and there is nothing else mounting the filesystem?

Hi Andreas,
it really is bad because the host have data about grub.conf, kernel and initrd cached but if you run the guest, update kernel or grub.conf etc., you need to see the changes here to boot the new/updated kernel now. Not the old, cached one. This is why it is bad to read cached data. Pygrub isn't modifying it but the guest can modify the data itself...

Thanks,
Michal

#28 lore raw
In reply to Christoph Hellwig
Quoted 14 lines · Christoph Hellwig
Quoted 4 lines · Michal Novotny

I don't really know if I see your point but the thing here is that there was no way to open a file directly (ie. using O_DIRECT). The direct write support has been added only to make it possible to use both read and write directly. The main reason to create this patch was to add

Quoted 8 lines

direct read support and flush capability won't help me at all. I am working in Red Hat, Virtualization team on Xen so I am really not that much familiar with file systems but what I needed was an option to read the data directly (using O_DIRECT) in e2fsprogs. One bug was about pygrub (Python version of GRUB of Xen PV guests that is internally using e2fsprogs functionality to access data on ext2/3/4 partition to boot the PV guests) uses outdated/cached data so some modifications were necessary to open everything directly...

Quoted 4 lines

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

Christoph -

It's my understanding that nobody is doing concurrent access.

If the host reads the block device via pygrub to boot the guest, the guest while running updates the same device when installing a new kernel (either through the fs, or by writing to the bdev; probably the former...), and then the guest shuts down - is there something which will sync the host's cache (cached from the prior read) with the updates from the guest?

I don't know nearly enough about how the virt IO goes ...

But if access is sequential between host & guest, I'd hope that this would all just work.

If that is all supposed to work, then maybe the description of the data flow (as Ric asked for) is not correct.

-Eric

#29 lore raw
Quoted 17 lines · Eric Sandeen
Quoted 15 lines · Christoph Hellwig
Quoted 13 lines · Michal Novotny

I don't really know if I see your point but the thing here is that there was no way to open a file directly (ie. using O_DIRECT). The direct write support has been added only to make it possible to use both read and write directly. The main reason to create this patch was to add direct read support and flush capability won't help me at all. I am working in Red Hat, Virtualization team on Xen so I am really not that much familiar with file systems but what I needed was an option to read the data directly (using O_DIRECT) in e2fsprogs. One bug was about pygrub (Python version of GRUB of Xen PV guests that is internally using e2fsprogs functionality to access data on ext2/3/4 partition to boot the PV guests) uses outdated/cached data so some modifications were necessary to open everything directly...

Quoted 10 lines
Quoted 5 lines

So to get things staigt: you're using e2fsprogs to manipulate a life filesystem and thing using O_DIRECT saves your ass? I think you need to rething your model of operation fundamentally in that case.

Christoph -

It's my understanding that nobody is doing concurrent access.

Eric,
indeed, no concurrent accesses are happening that time. The guests file system seems to be cached since after dropping caches in host (dom0) it is reported to work correctly.

Quoted 7 lines

If the host reads the block device via pygrub to boot the guest, the guest while running updates the same device when installing a new kernel (either through the fs, or by writing to the bdev; probably the former...), and then the guest shuts down - is there something which will sync the host's cache (cached from the prior read) with the updates from the guest?

It appears that the data are cached in host (dom0) and another access (after guest update/shutdown sequence) makes dom0 still provide old (cached) data and not the current (newest) data.

Michal

#30 lore raw

Just for completeness, this is what we think we have going on:

1) First boot: Running on the host, pygrub reads the device (unmounted) to bootstrap the guest with image A (kernel + grub.conf)

(2) guest image updates the kernel/grub.conf using weird Xen IO path (bypassing the host page cache, creating BIO's directly in the host memory).

Note that at this point in time, the image from (1) is still possibly in the page cache of the host

(3) reboot of guest - host pygrub uses page cache (stale pages) when bootstrapping the guest who occasionally boots into the stale image.

This doesn't happen all of the time - if the pages are dropped before (3) happens, it won't happen.

Uses O_DIRECT has a side effect of invalidating the page cache while reading.

Dropping VM caches just for the devices in question would fix this or (as Christoph mentioned) use kvm which does this more sanely :-)

ric