Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fat: switch to fsinfo_inode

Currently FAT file-system maps the VFS "superblock" abstraction to the
FSINFO block. The FSINFO block contains non-essential data about the
amount of free clusters and the next free cluster. FAT file-system can
always find out this information by scanning the FAT table, but having it
in the FSINFO block may speed things up sometimes. So FAT file-system
relies on the VFS superblock write-out services to make sure the FSINFO
block is written out to the media from time to time.

The whole "superblock write-out" VFS infrastructure is served by the
'sync_supers()' kernel thread, which wakes up every 5 (by default) seconds
and writes out all dirty superblock using the '->write_super()' call-back.
But the problem with this thread is that it wastes power by waking up the
system every 5 seconds no matter what. So we want to kill it completely
and thus, we need to make file-systems to stop using the '->write_super'
VFS service, and then remove it together with the kernel thread.

This patch switches the FAT FSINFO block management from
'->write_super()'/'->s_dirt' to 'fsinfo_inode'/'->write_inode'. Now,
instead of setting the 's_dirt' flag, we just mark the special
'fsinfo_inode' inode as dirty and let VFS invoke the '->write_inode'
call-back when needed, where we write-out the FSINFO block.

This patch also makes sure we do not mark the 'fsinfo_inode' inode as
dirty if we are not FAT32 (FAT16 and FAT12 do not have the FSINFO block)
or if we are in R/O mode.

As a bonus, we can also remove the '->sync_fs()' and '->write_super()' FAT
call-back function because they become unneeded.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Artem Bityutskiy and committed by
Linus Torvalds
78491189 330fe3c4

+18 -31
+6 -1
fs/fat/fatent.c
··· 310 310 311 311 static void mark_fsinfo_dirty(struct super_block *sb) 312 312 { 313 - sb->s_dirt = 1; 313 + struct msdos_sb_info *sbi = MSDOS_SB(sb); 314 + 315 + if (sb->s_flags & MS_RDONLY || sbi->fat_bits != 32) 316 + return; 317 + 318 + __mark_inode_dirty(sbi->fsinfo_inode, I_DIRTY_SYNC); 314 319 } 315 320 316 321 static inline int fat_ent_update_ptr(struct super_block *sb,
+12 -30
fs/fat/inode.c
··· 459 459 fat_detach(inode); 460 460 } 461 461 462 - static void fat_write_super(struct super_block *sb) 463 - { 464 - lock_super(sb); 465 - sb->s_dirt = 0; 466 - 467 - if (!(sb->s_flags & MS_RDONLY)) 468 - fat_clusters_flush(sb); 469 - unlock_super(sb); 470 - } 471 - 472 - static int fat_sync_fs(struct super_block *sb, int wait) 473 - { 474 - int err = 0; 475 - 476 - if (sb->s_dirt) { 477 - lock_super(sb); 478 - sb->s_dirt = 0; 479 - err = fat_clusters_flush(sb); 480 - unlock_super(sb); 481 - } 482 - 483 - return err; 484 - } 485 - 486 462 static void fat_put_super(struct super_block *sb) 487 463 { 488 464 struct msdos_sb_info *sbi = MSDOS_SB(sb); 489 - 490 - if (sb->s_dirt) 491 - fat_write_super(sb); 492 465 493 466 iput(sbi->fsinfo_inode); 494 467 iput(sbi->fat_inode); ··· 635 662 636 663 static int fat_write_inode(struct inode *inode, struct writeback_control *wbc) 637 664 { 638 - return __fat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL); 665 + int err; 666 + 667 + if (inode->i_ino == MSDOS_FSINFO_INO) { 668 + struct super_block *sb = inode->i_sb; 669 + 670 + lock_super(sb); 671 + err = fat_clusters_flush(sb); 672 + unlock_super(sb); 673 + } else 674 + err = __fat_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL); 675 + 676 + return err; 639 677 } 640 678 641 679 int fat_sync_inode(struct inode *inode) ··· 663 679 .write_inode = fat_write_inode, 664 680 .evict_inode = fat_evict_inode, 665 681 .put_super = fat_put_super, 666 - .write_super = fat_write_super, 667 - .sync_fs = fat_sync_fs, 668 682 .statfs = fat_statfs, 669 683 .remount_fs = fat_remount, 670 684