Skip to contentSkip to conversation

Commit 02c24a82187d5a628c68edfe71ae60dc135cd178 breaks s2disk

Regression Rafael J. Wysocki 3 participants 12 messages Aug 1, 2011 – Aug 2, 2011 VFS

lore
Share & tools
lore
#0 lore raw

Hi,

Unfortunately s2disk (which is a user space tool for saving hibernate images) doesn't work any more after your commit 02c24a82187d5a628c68edfe71ae60dc135cd178 (fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers). The symptom is that the s2disk's resume counterpart cannot find the image in the device even though s2disk considers it as successfully saved.

What happens is that s2disk opens a block device (disk partition to be precise) directly and writes to it eventually calling fsync(). My interpretation of the failure is that before commit 02c24a82187d5a628c68ed, when s2disk called fsync() the VFS layer would run filemap_write_and_wait_range() that in turn would cause the data to go to the disk, but after that commit this doesn't happen any more.

If I'm right, then not only s2disk, but any process writing directly to a block device will have a problem with fsync().

Thanks,
Rafael

#1 lore raw
Quoted 8 lines · Rafael J. Wysocki

Hi,

Unfortunately s2disk (which is a user space tool for saving hibernate images) doesn't work any more after your commit 02c24a82187d5a628c68edfe71ae60dc135cd178 (fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers). The symptom is that the s2disk's resume counterpart cannot find the image in the device even though s2disk considers it as successfully saved.

Quoted 8 lines

What happens is that s2disk opens a block device (disk partition to be precise) directly and writes to it eventually calling fsync(). My interpretation of the failure is that before commit 02c24a82187d5a628c68ed, when s2disk called fsync() the VFS layer would run filemap_write_and_wait_range() that in turn would cause the data to go to the disk, but after that commit this doesn't happen any more.

If I'm right, then not only s2disk, but any process writing directly to a block device will have a problem with fsync().

Well, I'm not sure if the patch below is the right fix, but it evidently makes s2disk work for me again.

Thanks,
Rafael

---
 fs/block_dev.c |    4 ++++
 1 file changed, 4 insertions(+)
fs/block_dev.c +4 -0
Index: linux-2.6/fs/block_dev.c
===================================================================
@@ -387,6 +387,10 @@ int blkdev_fsync(struct file *filp, loff
 	struct inode *bd_inode = filp->f_mapping->host;
 	struct block_device *bdev = I_BDEV(bd_inode);
 	int error;
+	
+	error = filemap_write_and_wait_range(filp->f_mapping, start, end);
+	if (error)
+		return error;
 
 	/*
 	 * There is no need to serialise calls to blkdev_issue_flush with
#2 lore raw
Quoted 3 lines · Rafael J. Wysocki

Well, I'm not sure if the patch below is the right fix, but it evidently makes s2disk work for me again.

Looks right to me.

The only issue is whether we should use "db_mapping->i_mapping" or "file->f_mapping". I think they are the same for block devices.

Al?

Also, what about some of the other fsync things that apparently weren't updated to write back page caches. ps3flash_fsync? Others?

Linus

#3 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

Well, I'm not sure if the patch below is the right fix, but it evidently makes s2disk work for me again.

Looks right to me.

The only issue is whether we should use "db_mapping->i_mapping" or "file->f_mapping". I think they are the same for block devices.

Al?

Also, what about some of the other fsync things that apparently weren't updated to write back page caches. ps3flash_fsync? Others?

Linus

maintainer
#4 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Rafael J. Wysocki

Well, I'm not sure if the patch below is the right fix, but it evidently makes s2disk work for me again.

Looks right to me.

The only issue is whether we should use "db_mapping->i_mapping" or "file->f_mapping". I think they are the same for block devices.

Al?

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

Quoted 2 lines

Also, what about some of the other fsync things that apparently weren't updated to write back page caches. ps3flash_fsync? Others?

ps3flash, IIRC, doesn't go through page cache on read and write... If anything, we probably have instances that bother with pagecache for no reason...

maintainer
#5 lore raw
In reply to Linus Torvalds
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · Rafael J. Wysocki

Well, I'm not sure if the patch below is the right fix, but it evidently makes s2disk work for me again.

Looks right to me.

The only issue is whether we should use "db_mapping->i_mapping" or "file->f_mapping". I think they are the same for block devices.

Al?

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

Quoted 2 lines

Also, what about some of the other fsync things that apparently weren't updated to write back page caches. ps3flash_fsync? Others?

ps3flash, IIRC, doesn't go through page cache on read and write... If anything, we probably have instances that bother with pagecache for no reason...

#6 lore raw
Quoted 3 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

My only issue was that from a "mindless conversion" standpoint, most of the other users had been changed to use inode->i_mapping.

I dunno why. I agree that file->f_mapping looks cleaner and is what the code used to do. But maybe there was some reason why the other fsync methods had been changed to use

  filemap_write_and_wait_range(inode->i_mapping, start, end);

instead.

Linus

#7 lore raw
In reply to Al Viro
Quoted 3 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

My only issue was that from a "mindless conversion" standpoint, most of the other users had been changed to use inode->i_mapping.

I dunno why. I agree that file->f_mapping looks cleaner and is what the code used to do. But maybe there was some reason why the other fsync methods had been changed to use

  filemap_write_and_wait_range(inode->i_mapping, start, end);

instead.

Linus

maintainer
#8 lore raw
In reply to Al Viro
Quoted 2 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

BTW, I've put s-o-b: Rafael J. Wysocki <[email protected]> in there. Rafael, do you have any problems with that?

maintainer
#9 lore raw
In reply to Al Viro
Quoted 2 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

BTW, I've put s-o-b: Rafael J. Wysocki <[email protected]> in there. Rafael, do you have any problems with that?

#10 lore raw
Quoted 7 lines · Al Viro
Quoted 2 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

BTW, I've put s-o-b: Rafael J. Wysocki <[email protected]> in there. Rafael, do you have any problems with that?

Not at all.

Thanks a lot,
Rafael

#11 lore raw
In reply to Al Viro
Quoted 7 lines · Al Viro
Quoted 2 lines · Al Viro

Applied (in file->f_mapping variant; it is equal to bdev->bd_mapping, but what's wrong with using ->f_mapping here?)

BTW, I've put s-o-b: Rafael J. Wysocki <[email protected]> in there. Rafael, do you have any problems with that?

Not at all.

Thanks a lot,
Rafael