mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Hungyu Lin <dennylin0707@gmail.com>,
	Christian Brauner <brauner@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	Deepa Dinamani <deepa.kernel@gmail.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfs: preserve subsecond timestamps at filesystem time limits
Date: Sun, 01 Nov 2026 07:14:38 -0500	[thread overview]
Message-ID: <641bce29adb873a472711d4db3960929c1122587.camel@kernel.org> (raw)
In-Reply-To: <20261101113815.52911-1-dennylin0707@gmail.com>

On Sun, 2026-11-01 at 11:38 +0000, Hungyu Lin wrote:
> timestamp_truncate() clears tv_nsec whenever the clamped seconds equal
> either filesystem time limit. This also drops the fractional part of
> timestamps whose seconds were already within the supported range.
> 
> For example, setting a JFS mtime to 0.123456789 produces 0.000000000,
> although the filesystem can store the requested value. Utilities such
> as touch and cp -p consequently lose valid subsecond timestamps when
> preserving these endpoint values. Timestamps strictly between the
> filesystem limits are unaffected.
> 
> Only clear tv_nsec when clamping actually changes tv_sec. Continue to
> truncate in-range nanoseconds to the filesystem's timestamp granularity,
> including when the seconds equal either endpoint.
> 
> Ben Hutchings suggested comparing clamped and original seconds in the
> 2019 utimes review. That caller was switched to timestamp_truncate(),
> but the helper retained its endpoint equality check.
> 
> Link: https://lore.kernel.org/lkml/12c095e595836a7ff7f2c7b2a32cb5544dd29b55.camel@codethink.co.uk/
> Fixes: 50e17c000c46 ("vfs: Add timestamp_truncate() api")
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---
>  fs/inode.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 1cb6293b237a..7f8e8feec4db 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -2847,9 +2847,10 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode)
>  {
>  	struct super_block *sb = inode->i_sb;
>  	unsigned int gran = sb->s_time_gran;
> +	time64_t seconds = t.tv_sec;
>  
>  	t.tv_sec = clamp(t.tv_sec, sb->s_time_min, sb->s_time_max);
> -	if (unlikely(t.tv_sec == sb->s_time_max || t.tv_sec == sb->s_time_min))
> +	if (unlikely(t.tv_sec != seconds))
>  		t.tv_nsec = 0;
>  
>  	/* Avoid division in the common cases 1 ns and 1 s. */

Seems right. To wit: you only want to zero out tv_nsec in the case
where the clamp happens. If seconds was already at s_time_max/min,
don't zero out the nsec field.

Reviewed-by: Jeff Layton <jlayton@kernel.org>

      reply	other threads:[~2026-11-01 12:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 11:38 Hungyu Lin
2026-11-01 12:14 ` Jeff Layton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=641bce29adb873a472711d4db3960929c1122587.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=deepa.kernel@gmail.com \
    --cc=dennylin0707@gmail.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®