From patchwork Thu Nov 24 00:47:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9444589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DE0D2600BA for ; Thu, 24 Nov 2016 00:50:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6A7B27D76 for ; Thu, 24 Nov 2016 00:50:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C950827DCD; Thu, 24 Nov 2016 00:50:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FC9227D76 for ; Thu, 24 Nov 2016 00:50:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936338AbcKXAtf (ORCPT ); Wed, 23 Nov 2016 19:49:35 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36234 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935162AbcKXAsj (ORCPT ); Wed, 23 Nov 2016 19:48:39 -0500 Received: by mail-pf0-f195.google.com with SMTP id c4so1141239pfb.3; Wed, 23 Nov 2016 16:48:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xYykfp4+hV4Y6dAyYsPSEJ5tG+OtEhiC1i+sL8ALhAs=; b=QvGHuq4UWSG+gUH44S5RfSs0Q6JAYJNCjbIpg91YpaJTaWZLLFM+Umuc00IjkOSLke 2a2ZDJuY/i7b2QrTyIdzDQfBDLGiOvpdiMCzuQaDNsDWTDUZjcBwZcmNkK4TB0o2eMv5 3z0efUfvCKCne4lBCj+vgoKuFmB5vJmzDK/Qu9x32adaO5BpDheUIfr7MpmdEsjmx+hm Zu+2109WFjYDO29I5QUZDl/y7cXsRGNmMi/lPpKTNKWkkJeqFGF9d83kI+fZxmTu9qBM +YK/LI0QgU4sdTmdnL8y0D4j0f5gsnWlG6/Jr0ACOk9EANTfE0NSDCamKot7v1ED/ST8 tYxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xYykfp4+hV4Y6dAyYsPSEJ5tG+OtEhiC1i+sL8ALhAs=; b=YKTyVJMDm+4EX9fWBYOQrtjvnVy+nyJI6K6VjXNH4Bs89q/jSNNNTWQNlAJ4whC106 t0dAKt7xDgiuIdd2sHVs+H80D9gg1mnzj14zgNDBo57BKNH/HFBjAU3+Bjv/ZuuynwHD q/LZFM2ixDRK5wo8P+pynjf6Mad1sIkEhxezSH4FJZMra0NeeHpqrjhPm4fyMyP1UXOb eHfOfS/VAMD0/KyoQuTtMZCKAFdPWLCe5gNDNTaEnGfaaVAnERcjYeDfQJtI1Sy8Hq2j lTVu7Tqv1ojwmRwZXP206r/FrjVZSs0MantBOof1HT6oZNSLf/4Epx+JPyTgsmYwY+q8 QvoA== X-Gm-Message-State: AKaTC03CG9Bt6JgXTydgoF38wQH5LB5wx2NxIV8vBJucPSY8Ax3sGSupatYlGH7gI42LSQ== X-Received: by 10.84.218.15 with SMTP id q15mr12460600pli.143.1479948492589; Wed, 23 Nov 2016 16:48:12 -0800 (PST) Received: from localhost.localdomain (c-24-6-102-171.hsd1.ca.comcast.net. [24.6.102.171]) by smtp.gmail.com with ESMTPSA id i11sm37364702pgn.17.2016.11.23.16.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Nov 2016 16:48:12 -0800 (PST) From: Deepa Dinamani To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, tglx@linutronix.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, tytso@mit.edu, viro@zeniv.linux.org.uk, y2038@lists.linaro.org Subject: [RFC 5/6] vfs: Add timestamp_truncate() api Date: Wed, 23 Nov 2016 16:47:49 -0800 Message-Id: <1479948470-2397-6-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479948470-2397-1-git-send-email-deepa.kernel@gmail.com> References: <1479948470-2397-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP timespec_trunc() function is used to truncate a filesystem timestamp to the right granularity. But, the function does not clamp tv_sec part of the timestamps according to the filesystem timestamp limits. Also, timespec_trunc() is exclusively used for filesystem timestamps. Move the api to be part of vfs. The replacement api: timestamp_truncate() also alters the signature of the function to accommodate filesystem timestamp clamping according to flesystem limits. Note that clamp_t macro is used for clamping here as vfs is not yet using struct timespec64 internally. This is only for compilation purposes. The actual patch can only be merged after the vfs is transitioned to use timespec64 for correct operation of clamp macro. At which point, clamp_t() will be replaced by clamp(). Signed-off-by: Deepa Dinamani --- fs/inode.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 7b2b78d..f9285f2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2106,6 +2106,36 @@ void inode_nohighmem(struct inode *inode) EXPORT_SYMBOL(inode_nohighmem); /** + * fs_timespec_trunc - Truncate timespec to a granularity + * @t: Timespec + * @gran: Granularity in ns. + * + * Truncate a timespec to a granularity. Always rounds down. gran must + * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns). + */ +struct timespec timestamp_truncate(struct timespec t, struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + unsigned int gran = sb->s_time_gran; + + t.tv_sec = clamp_t(time64_t, t.tv_sec, sb->s_time_min, sb->s_time_max); + + /* Avoid division in the common cases 1 ns and 1 s. */ + if (gran == 1) { + /* nothing */ + } else if (gran == NSEC_PER_SEC) { + t.tv_nsec = 0; + } else if (gran > 1 && gran < NSEC_PER_SEC) { + t.tv_nsec -= t.tv_nsec % gran; + } else { + WARN(1, "illegal file time granularity: %u", gran); + } + return t; +} +EXPORT_SYMBOL(timestamp_truncate); + + +/** * current_time - Return FS time * @inode: inode. * @@ -2124,6 +2154,6 @@ struct timespec current_time(struct inode *inode) return now; } - return timespec_trunc(now, inode->i_sb->s_time_gran); + return timestamp_truncate(now, inode); } EXPORT_SYMBOL(current_time);