xfs: mark inodes dirty before issuing I/O
To make sure they get properly waited on in sync when I/O is in flight and we latter need to update the inode size. Requires a new helper to check if an ioend structure is beyond the current EOF. Signed-off-by: Dave Chinner <david@fromorbit.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Signed-off-by: Alex Elder <aelder@sgi.com>
This commit is contained in:
@@ -185,6 +185,24 @@ xfs_destroy_ioend(
|
|||||||
mempool_free(ioend, xfs_ioend_pool);
|
mempool_free(ioend, xfs_ioend_pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the end of the current ioend is beyond the current EOF,
|
||||||
|
* return the new EOF value, otherwise zero.
|
||||||
|
*/
|
||||||
|
STATIC xfs_fsize_t
|
||||||
|
xfs_ioend_new_eof(
|
||||||
|
xfs_ioend_t *ioend)
|
||||||
|
{
|
||||||
|
xfs_inode_t *ip = XFS_I(ioend->io_inode);
|
||||||
|
xfs_fsize_t isize;
|
||||||
|
xfs_fsize_t bsize;
|
||||||
|
|
||||||
|
bsize = ioend->io_offset + ioend->io_size;
|
||||||
|
isize = MAX(ip->i_size, ip->i_new_size);
|
||||||
|
isize = MIN(isize, bsize);
|
||||||
|
return isize > ip->i_d.di_size ? isize : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update on-disk file size now that data has been written to disk.
|
* Update on-disk file size now that data has been written to disk.
|
||||||
* The current in-memory file size is i_size. If a write is beyond
|
* The current in-memory file size is i_size. If a write is beyond
|
||||||
@@ -192,13 +210,13 @@ xfs_destroy_ioend(
|
|||||||
* updated. If this write does not extend all the way to the valid
|
* updated. If this write does not extend all the way to the valid
|
||||||
* file size then restrict this update to the end of the write.
|
* file size then restrict this update to the end of the write.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
STATIC void
|
STATIC void
|
||||||
xfs_setfilesize(
|
xfs_setfilesize(
|
||||||
xfs_ioend_t *ioend)
|
xfs_ioend_t *ioend)
|
||||||
{
|
{
|
||||||
xfs_inode_t *ip = XFS_I(ioend->io_inode);
|
xfs_inode_t *ip = XFS_I(ioend->io_inode);
|
||||||
xfs_fsize_t isize;
|
xfs_fsize_t isize;
|
||||||
xfs_fsize_t bsize;
|
|
||||||
|
|
||||||
ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
|
ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
|
||||||
ASSERT(ioend->io_type != IOMAP_READ);
|
ASSERT(ioend->io_type != IOMAP_READ);
|
||||||
@@ -206,14 +224,9 @@ xfs_setfilesize(
|
|||||||
if (unlikely(ioend->io_error))
|
if (unlikely(ioend->io_error))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bsize = ioend->io_offset + ioend->io_size;
|
|
||||||
|
|
||||||
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
||||||
|
isize = xfs_ioend_new_eof(ioend);
|
||||||
isize = MAX(ip->i_size, ip->i_new_size);
|
if (isize) {
|
||||||
isize = MIN(isize, bsize);
|
|
||||||
|
|
||||||
if (ip->i_d.di_size < isize) {
|
|
||||||
ip->i_d.di_size = isize;
|
ip->i_d.di_size = isize;
|
||||||
xfs_mark_inode_dirty_sync(ip);
|
xfs_mark_inode_dirty_sync(ip);
|
||||||
}
|
}
|
||||||
@@ -403,10 +416,16 @@ xfs_submit_ioend_bio(
|
|||||||
struct bio *bio)
|
struct bio *bio)
|
||||||
{
|
{
|
||||||
atomic_inc(&ioend->io_remaining);
|
atomic_inc(&ioend->io_remaining);
|
||||||
|
|
||||||
bio->bi_private = ioend;
|
bio->bi_private = ioend;
|
||||||
bio->bi_end_io = xfs_end_bio;
|
bio->bi_end_io = xfs_end_bio;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the I/O is beyond EOF we mark the inode dirty immediately
|
||||||
|
* but don't update the inode size until I/O completion.
|
||||||
|
*/
|
||||||
|
if (xfs_ioend_new_eof(ioend))
|
||||||
|
xfs_mark_inode_dirty_sync(XFS_I(ioend->io_inode));
|
||||||
|
|
||||||
submit_bio(WRITE, bio);
|
submit_bio(WRITE, bio);
|
||||||
ASSERT(!bio_flagged(bio, BIO_EOPNOTSUPP));
|
ASSERT(!bio_flagged(bio, BIO_EOPNOTSUPP));
|
||||||
bio_put(bio);
|
bio_put(bio);
|
||||||
|
Reference in New Issue
Block a user