linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trond.myklebust@fys.uio.no>
To: Jan Kara <jack@suse.cz>
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-fsdevel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <jens.axboe@oracle.com>
Subject: Re: [PATCH] vfs: Fix sys_sync() and fsync_super() reliability
Date: Wed, 22 Apr 2009 13:16:16 -0400	[thread overview]
Message-ID: <1240420576.9197.1.camel@heimdal.trondhjem.org> (raw)
In-Reply-To: <1240415781-17834-2-git-send-email-jack@suse.cz>

On Wed, 2009-04-22 at 17:56 +0200, Jan Kara wrote:
> So far, do_sync() called:
>   sync_inodes(0);
>   sync_supers();
>   sync_filesystems(0);
>   sync_filesystems(1);
>   sync_inodes(1);
> 
> This ordering makes it kind of hard for filesystems as sync_inodes(0) need not
> submit all the IO (for example it skips inodes with I_SYNC set) so e.g. forcing
> transaction to disk in ->sync_fs() is not really enough. Therefore sys_sync has
> not been completely reliable on some filesystems (ext3, ext4, reiserfs, ocfs2
> and others are hit by this) when racing e.g. with background writeback. A
> similar problem hits also other filesystems (e.g. ext2) because of
> write_supers() being called before the sync_inodes(1).
> 
> Change the ordering of calls in do_sync() - this requires a new function
> sync_blkdevs() to preserve the property that block devices are always synced
> after write_super() / sync_fs() call.
> 
> The same issue is fixed in __fsync_super() function used on umount /
> remount read-only.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/super.c         |   25 ++++++++++++++++++++++++-
>  fs/sync.c          |    3 ++-
>  include/linux/fs.h |    2 ++
>  3 files changed, 28 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/super.c b/fs/super.c
> index 786fe7d..4f56333 100644
> --- a/fs/super.c
> +++ b/fs/super.c
> @@ -267,6 +267,7 @@ void __fsync_super(struct super_block *sb)
>  {
>  	sync_inodes_sb(sb, 0);
>  	vfs_dq_sync(sb);
> +	sync_inodes_sb(sb, 1);
>  	lock_super(sb);
>  	if (sb->s_dirt && sb->s_op->write_super)
>  		sb->s_op->write_super(sb);
> @@ -274,7 +275,6 @@ void __fsync_super(struct super_block *sb)
>  	if (sb->s_op->sync_fs)
>  		sb->s_op->sync_fs(sb, 1);
>  	sync_blockdev(sb->s_bdev);
> -	sync_inodes_sb(sb, 1);
>  }
>  
>  /*
> @@ -502,6 +502,29 @@ restart:
>  	mutex_unlock(&mutex);
>  }
>  
> +/*
> + *  Sync all block devices underlying some superblock
> + */
> +void sync_blockdevs(void)
> +{
> +	struct super_block *sb;
> +
> +	spin_lock(&sb_lock);
> +restart:
> +	list_for_each_entry(sb, &super_blocks, s_list) {
> +		sb->s_count++;
> +		spin_unlock(&sb_lock);
> +		down_read(&sb->s_umount);
> +		if (sb->s_root)
> +			sync_blockdev(sb->s_bdev);
> +		up_read(&sb->s_umount);

What's the point of going to all this trouble of upping the sb->s_count,
and grabbing sb->s_umount if there is no sb->s_bdev to sync in the first
place?

> +		spin_lock(&sb_lock);
> +		if (__put_super_and_need_restart(sb))
> +			goto restart;
> +	}
> +	spin_unlock(&sb_lock);
> +}
> +
>  /**
>   *	get_super - get the superblock of a device
>   *	@bdev: device to get the superblock for
> diff --git a/fs/sync.c b/fs/sync.c
> index 7abc65f..fa14e42 100644
> --- a/fs/sync.c
> +++ b/fs/sync.c
> @@ -26,10 +26,11 @@ static void do_sync(unsigned long wait)
>  	wakeup_pdflush(0);
>  	sync_inodes(0);		/* All mappings, inodes and their blockdevs */
>  	vfs_dq_sync(NULL);
> +	sync_inodes(wait);	/* Mappings, inodes and blockdevs, again. */
>  	sync_supers();		/* Write the superblocks */
>  	sync_filesystems(0);	/* Start syncing the filesystems */
>  	sync_filesystems(wait);	/* Waitingly sync the filesystems */
> -	sync_inodes(wait);	/* Mappings, inodes and blockdevs, again. */
> +	sync_blockdevs();
>  	if (!wait)
>  		printk("Emergency Sync complete\n");
>  	if (unlikely(laptop_mode))
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 5bed436..4bad02e 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -1942,6 +1942,7 @@ extern void bdput(struct block_device *);
>  extern struct block_device *open_by_devnum(dev_t, fmode_t);
>  extern void invalidate_bdev(struct block_device *);
>  extern int sync_blockdev(struct block_device *bdev);
> +extern void sync_blockdevs(void);
>  extern struct super_block *freeze_bdev(struct block_device *);
>  extern void emergency_thaw_all(void);
>  extern int thaw_bdev(struct block_device *bdev, struct super_block *sb);
> @@ -1951,6 +1952,7 @@ extern int fsync_no_super(struct block_device *);
>  #else
>  static inline void bd_forget(struct inode *inode) {}
>  static inline int sync_blockdev(struct block_device *bdev) { return 0; }
> +static inline void sync_blockdevs(void) { }
>  static inline void invalidate_bdev(struct block_device *bdev) {}
>  
>  static inline struct super_block *freeze_bdev(struct block_device *sb)
> -- 
> 1.6.0.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2009-04-22 17:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-22 15:56 [PATCH 0/2] Fix sys_sync() bug and slightly cleanup the code Jan Kara
2009-04-22 15:56 ` [PATCH] vfs: Fix sys_sync() and fsync_super() reliability Jan Kara
2009-04-22 17:16   ` Trond Myklebust [this message]
2009-04-22 17:23     ` Jan Kara
2009-04-23 11:10   ` Christoph Hellwig
2009-04-23 13:07     ` Jan Kara
2009-04-23 13:09       ` Christoph Hellwig
2009-04-22 15:56 ` [PATCH] vfs: Merge sync_supers(), sync_filesystems() and sync_blockdevs() Jan Kara
2009-04-22 17:20   ` Trond Myklebust
2009-04-23 11:06   ` Christoph Hellwig
2009-04-23 12:31   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1240420576.9197.1.camel@heimdal.trondhjem.org \
    --to=trond.myklebust@fys.uio.no \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --cc=jens.axboe@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).