Re: [patch 3/7] fs: introduce inode writeback helpers

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Christoph Hellwig
Date: Monday, November 29, 2010 - 8:13 am

On Wed, Nov 24, 2010 at 01:06:13AM +1100, npiggin@kernel.dk wrote:

Generally looks fine, but as Dave already mentioned I'd rather keep
i_state manipulation outside the filesystems.  This could be done with
two wrappers like the following, which should also keep the churn
inside fsync implementations downs:

int fsync_begin(struct inode *inode, int datasync)
{
	int ret = 0;
	unsigned mask = I_DIRTY_DATASYNC;

	if (!datasync)
		mask |= I_DIRTY_SYNC;

	spin_lock(&inode_lock);
	if (!inode_writeback_begin(inode, 1))
		goto out;
	if (!(inode->i_state & mask))
		goto out;

	inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
	ret = 1;
out:
	spin_unlock(&inode_lock);
	return ret;
}

static void fsync_end(struct inode *inode, int fail)
{
	spin_lock(&inode_lock);
	if (fail)
		inode->i_state |= I_DIRTY_SYNC | I_DIRTY_DATASYNC;
	inode_writeback_end(inode);
	spin_unlock(&inode_lock);
}

note that this one marks the inode fully dirty in case of a failure,
which is a bit overkill but keeps the interface simpler.  Given that
failure is fsync is catastrophic anyway (filesystem corruption, etc)
that seems fine to me.

Alternatively we could add a fsync_helper that gets a function
pointer with the ->write_inode signature and contains the above
code before and after it. generic_file_fsync would pass the real
->write_inode while other filesystems could pass specific routines.

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch 0/7] icache dirty / sync fixes, npiggin, (Tue Nov 23, 7:06 am)
[patch 1/7] fs: mark_inode_dirty barrier fix, npiggin, (Tue Nov 23, 7:06 am)
[patch 2/7] fs: simple fsync race fix, npiggin, (Tue Nov 23, 7:06 am)
[patch 5/7] fs: ext2 inode sync fix, npiggin, (Tue Nov 23, 7:06 am)
[patch 6/7] fs: fsync optimisations, npiggin, (Tue Nov 23, 7:06 am)
Re: [patch 2/7] fs: simple fsync race fix, Christoph Hellwig, (Mon Nov 29, 7:58 am)
Re: [patch 4/7] fs: preserve inode dirty bits on failed me ..., Christoph Hellwig, (Mon Nov 29, 7:59 am)
Re: [patch 6/7] fs: fsync optimisations, Christoph Hellwig, (Mon Nov 29, 8:03 am)
Re: [patch 3/7] fs: introduce inode writeback helpers, Christoph Hellwig, (Mon Nov 29, 8:13 am)
Re: [patch 6/7] fs: fsync optimisations, Nick Piggin, (Mon Nov 29, 5:11 pm)
Re: [patch 3/7] fs: introduce inode writeback helpers, Nick Piggin, (Mon Nov 29, 5:22 pm)