Commit d8a8559c authored by Jens Axboe's avatar Jens Axboe

writeback: get rid of generic_sync_sb_inodes() export

This adds two new exported functions:

- writeback_inodes_sb(), which only attempts to writeback dirty inodes on
  this super_block, for WB_SYNC_NONE writeout.
- sync_inodes_sb(), which writes out all dirty inodes on this super_block
  and also waits for the IO to complete.
Acked-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 0d03d59d
...@@ -1950,14 +1950,7 @@ static int pohmelfs_get_sb(struct file_system_type *fs_type, ...@@ -1950,14 +1950,7 @@ static int pohmelfs_get_sb(struct file_system_type *fs_type,
*/ */
static void pohmelfs_kill_super(struct super_block *sb) static void pohmelfs_kill_super(struct super_block *sb)
{ {
struct writeback_control wbc = { sync_inodes_sb(sb);
.sync_mode = WB_SYNC_ALL,
.range_start = 0,
.range_end = LLONG_MAX,
.nr_to_write = LONG_MAX,
};
generic_sync_sb_inodes(sb, &wbc);
kill_anon_super(sb); kill_anon_super(sb);
} }
......
...@@ -458,7 +458,7 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc) ...@@ -458,7 +458,7 @@ writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
* on the writer throttling path, and we get decent balancing between many * on the writer throttling path, and we get decent balancing between many
* throttled threads: we don't want them all piling up on inode_sync_wait. * throttled threads: we don't want them all piling up on inode_sync_wait.
*/ */
void generic_sync_sb_inodes(struct super_block *sb, static void generic_sync_sb_inodes(struct super_block *sb,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
const unsigned long start = jiffies; /* livelock avoidance */ const unsigned long start = jiffies; /* livelock avoidance */
...@@ -593,13 +593,6 @@ void generic_sync_sb_inodes(struct super_block *sb, ...@@ -593,13 +593,6 @@ void generic_sync_sb_inodes(struct super_block *sb,
return; /* Leave any unwritten inodes on s_io */ return; /* Leave any unwritten inodes on s_io */
} }
EXPORT_SYMBOL_GPL(generic_sync_sb_inodes);
static void sync_sb_inodes(struct super_block *sb,
struct writeback_control *wbc)
{
generic_sync_sb_inodes(sb, wbc);
}
/* /*
* Start writeback of dirty pagecache data against all unlocked inodes. * Start writeback of dirty pagecache data against all unlocked inodes.
...@@ -640,7 +633,7 @@ restart: ...@@ -640,7 +633,7 @@ restart:
*/ */
if (down_read_trylock(&sb->s_umount)) { if (down_read_trylock(&sb->s_umount)) {
if (sb->s_root) if (sb->s_root)
sync_sb_inodes(sb, wbc); generic_sync_sb_inodes(sb, wbc);
up_read(&sb->s_umount); up_read(&sb->s_umount);
} }
spin_lock(&sb_lock); spin_lock(&sb_lock);
...@@ -653,35 +646,56 @@ restart: ...@@ -653,35 +646,56 @@ restart:
spin_unlock(&sb_lock); spin_unlock(&sb_lock);
} }
/* /**
* writeback and wait upon the filesystem's dirty inodes. The caller will * writeback_inodes_sb - writeback dirty inodes from given super_block
* do this in two passes - one to write, and one to wait. * @sb: the superblock
*
* A finite limit is set on the number of pages which will be written.
* To prevent infinite livelock of sys_sync().
* *
* We add in the number of potentially dirty inodes, because each inode write * Start writeback on some inodes on this super_block. No guarantees are made
* can dirty pagecache in the underlying blockdev. * on how many (if any) will be written, and this function does not wait
* for IO completion of submitted IO. The number of pages submitted is
* returned.
*/ */
void sync_inodes_sb(struct super_block *sb, int wait) long writeback_inodes_sb(struct super_block *sb)
{ {
struct writeback_control wbc = { struct writeback_control wbc = {
.sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE, .sync_mode = WB_SYNC_NONE,
.range_start = 0, .range_start = 0,
.range_end = LLONG_MAX, .range_end = LLONG_MAX,
}; };
if (!wait) {
unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY); unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS); unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
long nr_to_write;
wbc.nr_to_write = nr_dirty + nr_unstable + nr_to_write = nr_dirty + nr_unstable +
(inodes_stat.nr_inodes - inodes_stat.nr_unused); (inodes_stat.nr_inodes - inodes_stat.nr_unused);
} else
wbc.nr_to_write = LONG_MAX; /* doesn't actually matter */
sync_sb_inodes(sb, &wbc); wbc.nr_to_write = nr_to_write;
generic_sync_sb_inodes(sb, &wbc);
return nr_to_write - wbc.nr_to_write;
}
EXPORT_SYMBOL(writeback_inodes_sb);
/**
* sync_inodes_sb - sync sb inode pages
* @sb: the superblock
*
* This function writes and waits on any dirty inode belonging to this
* super_block. The number of pages synced is returned.
*/
long sync_inodes_sb(struct super_block *sb)
{
struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL,
.range_start = 0,
.range_end = LLONG_MAX,
};
long nr_to_write = LONG_MAX; /* doesn't actually matter */
wbc.nr_to_write = nr_to_write;
generic_sync_sb_inodes(sb, &wbc);
return nr_to_write - wbc.nr_to_write;
} }
EXPORT_SYMBOL(sync_inodes_sb);
/** /**
* write_inode_now - write an inode to disk * write_inode_now - write an inode to disk
......
...@@ -19,20 +19,22 @@ ...@@ -19,20 +19,22 @@
SYNC_FILE_RANGE_WAIT_AFTER) SYNC_FILE_RANGE_WAIT_AFTER)
/* /*
* Do the filesystem syncing work. For simple filesystems sync_inodes_sb(sb, 0) * Do the filesystem syncing work. For simple filesystems
* just dirties buffers with inodes so we have to submit IO for these buffers * writeback_inodes_sb(sb) just dirties buffers with inodes so we have to
* via __sync_blockdev(). This also speeds up the wait == 1 case since in that * submit IO for these buffers via __sync_blockdev(). This also speeds up the
* case write_inode() functions do sync_dirty_buffer() and thus effectively * wait == 1 case since in that case write_inode() functions do
* write one block at a time. * sync_dirty_buffer() and thus effectively write one block at a time.
*/ */
static int __sync_filesystem(struct super_block *sb, int wait) static int __sync_filesystem(struct super_block *sb, int wait)
{ {
/* Avoid doing twice syncing and cache pruning for quota sync */ /* Avoid doing twice syncing and cache pruning for quota sync */
if (!wait) if (!wait) {
writeout_quota_sb(sb, -1); writeout_quota_sb(sb, -1);
else writeback_inodes_sb(sb);
} else {
sync_quota_sb(sb, -1); sync_quota_sb(sb, -1);
sync_inodes_sb(sb, wait); sync_inodes_sb(sb);
}
if (sb->s_op->sync_fs) if (sb->s_op->sync_fs)
sb->s_op->sync_fs(sb, wait); sb->s_op->sync_fs(sb, wait);
return __sync_blockdev(sb->s_bdev, wait); return __sync_blockdev(sb->s_bdev, wait);
......
...@@ -65,26 +65,14 @@ ...@@ -65,26 +65,14 @@
static int shrink_liability(struct ubifs_info *c, int nr_to_write) static int shrink_liability(struct ubifs_info *c, int nr_to_write)
{ {
int nr_written; int nr_written;
struct writeback_control wbc = {
.sync_mode = WB_SYNC_NONE,
.range_end = LLONG_MAX,
.nr_to_write = nr_to_write,
};
generic_sync_sb_inodes(c->vfs_sb, &wbc);
nr_written = nr_to_write - wbc.nr_to_write;
nr_written = writeback_inodes_sb(c->vfs_sb);
if (!nr_written) { if (!nr_written) {
/* /*
* Re-try again but wait on pages/inodes which are being * Re-try again but wait on pages/inodes which are being
* written-back concurrently (e.g., by pdflush). * written-back concurrently (e.g., by pdflush).
*/ */
memset(&wbc, 0, sizeof(struct writeback_control)); nr_written = sync_inodes_sb(c->vfs_sb);
wbc.sync_mode = WB_SYNC_ALL;
wbc.range_end = LLONG_MAX;
wbc.nr_to_write = nr_to_write;
generic_sync_sb_inodes(c->vfs_sb, &wbc);
nr_written = nr_to_write - wbc.nr_to_write;
} }
dbg_budg("%d pages were written back", nr_written); dbg_budg("%d pages were written back", nr_written);
......
...@@ -438,12 +438,6 @@ static int ubifs_sync_fs(struct super_block *sb, int wait) ...@@ -438,12 +438,6 @@ static int ubifs_sync_fs(struct super_block *sb, int wait)
{ {
int i, err; int i, err;
struct ubifs_info *c = sb->s_fs_info; struct ubifs_info *c = sb->s_fs_info;
struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL,
.range_start = 0,
.range_end = LLONG_MAX,
.nr_to_write = LONG_MAX,
};
/* /*
* Zero @wait is just an advisory thing to help the file system shove * Zero @wait is just an advisory thing to help the file system shove
...@@ -462,7 +456,7 @@ static int ubifs_sync_fs(struct super_block *sb, int wait) ...@@ -462,7 +456,7 @@ static int ubifs_sync_fs(struct super_block *sb, int wait)
* the user be able to get more accurate results of 'statfs()' after * the user be able to get more accurate results of 'statfs()' after
* they synchronize the file system. * they synchronize the file system.
*/ */
generic_sync_sb_inodes(sb, &wbc); sync_inodes_sb(sb);
/* /*
* Synchronize write buffers, because 'ubifs_run_commit()' does not * Synchronize write buffers, because 'ubifs_run_commit()' does not
......
...@@ -2071,8 +2071,6 @@ static inline void invalidate_remote_inode(struct inode *inode) ...@@ -2071,8 +2071,6 @@ static inline void invalidate_remote_inode(struct inode *inode)
extern int invalidate_inode_pages2(struct address_space *mapping); extern int invalidate_inode_pages2(struct address_space *mapping);
extern int invalidate_inode_pages2_range(struct address_space *mapping, extern int invalidate_inode_pages2_range(struct address_space *mapping,
pgoff_t start, pgoff_t end); pgoff_t start, pgoff_t end);
extern void generic_sync_sb_inodes(struct super_block *sb,
struct writeback_control *wbc);
extern int write_inode_now(struct inode *, int); extern int write_inode_now(struct inode *, int);
extern int filemap_fdatawrite(struct address_space *); extern int filemap_fdatawrite(struct address_space *);
extern int filemap_flush(struct address_space *); extern int filemap_flush(struct address_space *);
......
...@@ -78,7 +78,8 @@ struct writeback_control { ...@@ -78,7 +78,8 @@ struct writeback_control {
*/ */
void writeback_inodes(struct writeback_control *wbc); void writeback_inodes(struct writeback_control *wbc);
int inode_wait(void *); int inode_wait(void *);
void sync_inodes_sb(struct super_block *, int wait); long writeback_inodes_sb(struct super_block *);
long sync_inodes_sb(struct super_block *);
/* writeback.h requires fs.h; it, too, is not included from here. */ /* writeback.h requires fs.h; it, too, is not included from here. */
static inline void wait_on_inode(struct inode *inode) static inline void wait_on_inode(struct inode *inode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment