Re: [PATCH 08/10] fs: add support for non-blocking timestamp updates

Jan Kara <[email protected]>
Newsgroups dev.linux.lists.gfs2,org.infradead.lists.linux-mtd,org.kernel.vger.io-uring,org.kernel.vger.linux-btrfs,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.linux-nfs,org.kernel.vger.linux-unionfs,org.kernel.vger.linux-xfs
Message-ID <2hnq54zc4x2fpxkpuprnrutrwfp3yi5ojntu3e3xfcpeh6ztei@2fwwsemx4y5z>
On Wed 17-12-25 07:09:41, Christoph Hellwig wrote:
> Currently file_update_time_flags unconditionally returns -EAGAIN if any
> timestamp needs to be updated and IOCB_NOWAIT is passed.  This makes
> non-blocking direct writes impossible on file systems with granular
> enough timestamps.
> 
> Add a S_NOWAIT to ask for timestamps to not block, and return -EAGAIN in
> all methods for now.
> 
> Signed-off-by: Christoph Hellwig <[email protected]>
> Reviewed-by: Jeff Layton <[email protected]>

...

> @@ -2110,12 +2110,26 @@ int inode_update_timestamps(struct inode *inode, int *flags)
>  		now = inode_set_ctime_current(inode);
>  		if (!timespec64_equal(&now, &ctime))
>  			updated |= S_CTIME;
> -		if (!timespec64_equal(&now, &mtime)) {
> -			inode_set_mtime_to_ts(inode, now);
> +		if (!timespec64_equal(&now, &mtime))
>  			updated |= S_MTIME;
> +
> +		if (IS_I_VERSION(inode)) {
> +			if (*flags & S_NOWAIT) {
> +				/*
> +				 * Error out if we'd need timestamp updates, as
> +				 * the generally requires blocking to dirty the
> +				 * inode in one form or another.
> +				 */
> +				if (updated && inode_iversion_need_inc(inode))
> +					goto bail;

I'm confused here. What the code does is that if S_NOWAIT is set and
i_version needs increment we bail. However the comment as well as the
changelog speaks about timestamps needing update and not about i_version.
And intuitively I agree that if any timestamp is updated, inode needs
dirtying and thus we should bail regardless of whether i_version is updated
as well or not. What am I missing?

								Honza

> +			} else {
> +				if (inode_maybe_inc_iversion(inode, updated))
> +					updated |= S_VERSION;
> +			}
>  		}
> -		if (IS_I_VERSION(inode) && inode_maybe_inc_iversion(inode, updated))
> -			updated |= S_VERSION;
> +
> +		if (updated & S_MTIME)
> +			inode_set_mtime_to_ts(inode, now);
>  	} else {
>  		now = current_time(inode);
>  	}
> @@ -2131,6 +2145,9 @@ int inode_update_timestamps(struct inode *inode, int *flags)
>  
>  	*flags = updated;
>  	return 0;
> +bail:
> +	*flags = 0;
> +	return -EAGAIN;
>  }
>  EXPORT_SYMBOL(inode_update_timestamps);
>  
-- 
Jan Kara <[email protected]>
SUSE Labs, CR
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.