Skip to content
Permalink
Browse files
vfs: Take I_SYNC whilst performing fsync() and similar
  • Loading branch information
dhowells committed Feb 10, 2022
1 parent 542990e commit 9c1befbc079fcef04228d2b67e931f9635d58591
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
@@ -2759,3 +2759,37 @@ int sync_inode_metadata(struct inode *inode, int wait)
return writeback_single_inode(inode, &wbc);
}
EXPORT_SYMBOL(sync_inode_metadata);

/**
* filemap_fdatawrite_wbc - start writeback on mapping dirty pages in range
* @mapping: address space structure to write
* @wbc: the writeback_control controlling the writeout
*
* Call writepages on the mapping using the provided wbc to control the
* writeout.
*
* Return: %0 on success, negative error code otherwise.
*/
int filemap_fdatawrite_wbc(struct address_space *mapping,
struct writeback_control *wbc)
{
struct inode *inode = mapping->host;
int ret;

if (!mapping_can_writeback(mapping) ||
!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
return 0;

spin_lock(&inode->i_lock);
if (inode->i_state & I_SYNC) {
__inode_wait_for_writeback(inode);
WARN_ON(inode->i_state & I_SYNC);
}

wbc_attach_unlock_fdatawrite_inode(wbc, inode);
ret = do_writepages(mapping, wbc);
wbc_detach_inode(wbc);
inode_sync_complete(inode);
return ret;
}
EXPORT_SYMBOL(filemap_fdatawrite_wbc);
@@ -267,6 +267,22 @@ static inline void wbc_attach_fdatawrite_inode(struct writeback_control *wbc,
wbc_attach_and_unlock_inode(wbc, inode);
}

/**
* wbc_attach_unlock_fdatawrite_inode - associate wbc and inode for fdatawrite
* @wbc: writeback_control of interest
* @inode: target inode
*
* This function is to be used by __filemap_fdatawrite_range(), which is an
* alternative entry point into writeback code, and first ensures @inode is
* associated with a bdi_writeback and attaches it to @wbc.
*/
static inline void wbc_attach_unlock_fdatawrite_inode(struct writeback_control *wbc,
struct inode *inode)
{
inode_attach_wb(inode, NULL);
wbc_attach_and_unlock_inode(wbc, inode);
}

/**
* wbc_init_bio - writeback specific initializtion of bio
* @wbc: writeback_control for the writeback in progress
@@ -361,32 +361,6 @@ static int filemap_check_and_keep_errors(struct address_space *mapping)
return 0;
}

/**
* filemap_fdatawrite_wbc - start writeback on mapping dirty pages in range
* @mapping: address space structure to write
* @wbc: the writeback_control controlling the writeout
*
* Call writepages on the mapping using the provided wbc to control the
* writeout.
*
* Return: %0 on success, negative error code otherwise.
*/
int filemap_fdatawrite_wbc(struct address_space *mapping,
struct writeback_control *wbc)
{
int ret;

if (!mapping_can_writeback(mapping) ||
!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
return 0;

wbc_attach_fdatawrite_inode(wbc, mapping->host);
ret = do_writepages(mapping, wbc);
wbc_detach_inode(wbc);
return ret;
}
EXPORT_SYMBOL(filemap_fdatawrite_wbc);

/**
* __filemap_fdatawrite_range - start writeback on mapping dirty pages in range
* @mapping: address space structure to write

0 comments on commit 9c1befb

Please sign in to comment.