Skip to contentSkip to conversation

block_dev.c: fsync() on close() considered harmful

PATCH In review Miquel van Smoorenburg 2 participants 2 messages Nov 22, 2001 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block_dev.c: fsync() on close() considered harmful

I'm running an INN usenet news server that uses raw partitions for storage. I.e. it opens /dev/sda7 etc. and mmap()s [which finally works in 2.4, hurray]

Even though the server is keeping those devices open, when a utility program (sm) opens that file/device and closes() it the close() causes a fsync() on the device, something that is not wanted.

I applied the following patch which fixes it for me, it prevents the sync-after-close if it was close() calling blkdev_put() and we're not the last one to call blkdev_put().

That means fsync() will still be done on unmounts or when the last user of the device closes it, but not otherwise.

Is this correct or am I overlooking something?

fs/block_dev.c renamed from fs/block_dev.c.orig +0 -0
@@ -603,7 +603,7 @@
 
	down(&bdev->bd_sem);
	lock_kernel();
-	if (kind == BDEV_FILE)
+	if (kind == BDEV_FILE && bdev->bd_openers == 1)
		__block_fsync(bd_inode);
	else if (kind == BDEV_FS)
		fsync_no_super(rdev);

Mike.

Signature · 2 lines
"Only two things are infinite, the universe and human stupidity,
 and I'm not sure about the former" -- Albert Einstein.
#1 lore raw
Quoted 3 lines · Miquel van Smoorenburg

I'm running an INN usenet news server that uses raw partitions for storage. I.e. it opens /dev/sda7 etc. and mmap()s [which finally works in 2.4, hurray]

:)

Quoted 4 lines

Even though the server is keeping those devices open, when a utility program (sm) opens that file/device and closes() it the close() causes a fsync() on the device, something that is not wanted.

Quoted 8 lines

I applied the following patch which fixes it for me, it prevents the sync-after-close if it was close() calling blkdev_put() and we're not the last one to call blkdev_put().

That means fsync() will still be done on unmounts or when the last user of the device closes it, but not otherwise.

Is this correct or am I overlooking something?

it's correct, thanks.

Quoted 14 lines
fs/block_dev.c renamed from fs/block_dev.c.orig +1 -1
@@ -603,7 +603,7 @@
 
 	down(&bdev->bd_sem);
 	lock_kernel();
-	if (kind == BDEV_FILE)
+	if (kind == BDEV_FILE && bdev->bd_openers == 1)
 		__block_fsync(bd_inode);
 	else if (kind == BDEV_FS)
 		fsync_no_super(rdev);
Quoted 4 lines

Mike.

Signature · 2 lines
"Only two things are infinite, the universe and human stupidity,
 and I'm not sure about the former" -- Albert Einstein.

Andrea