From patchwork Sat Apr 8 19:37:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 748661 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3w0mxB5SNqz9s76 for ; Sun, 9 Apr 2017 05:39:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GMLur3Wy"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752525AbdDHTj3 (ORCPT ); Sat, 8 Apr 2017 15:39:29 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33615 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752317AbdDHTjZ (ORCPT ); Sat, 8 Apr 2017 15:39:25 -0400 Received: by mail-pf0-f193.google.com with SMTP id c198so1924132pfc.0; Sat, 08 Apr 2017 12:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UShrNlEB9vaiou1Xzu7v+NeRoA7Ti3Ie++8S/Se43p0=; b=GMLur3WyhtzVzXzvRuBfzahnZYRI37hRilj2Slano4VVAkfr8oOocva2q8aZhpWNbU NQMB4933i1B0gI/AAIYSja2hQYCOL2d5uFvuoV1A47X9sqIWWYmhJlDfQSxzVdkyUBxl GB+Vt3ciToct9YmX9I49mRs4E6POxpEyWYZpudCJ2JW0O3Pjc5qH5JIAkCBWG7wWFQBU GPTSmEaw8iSxlSCCfTlyuKFG7rdV0ZUpEzVLyruZIG4TsXM/WzWPVTxb7A/3XBYtkTBd 21xGIS6NsBPAivl8998mz759sYYUDAQGULtQ/bi0+PBEALeWnoX5r7UzS+xod2G81faB lfEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UShrNlEB9vaiou1Xzu7v+NeRoA7Ti3Ie++8S/Se43p0=; b=PAhHaKvw/J1gX/AmZq+eAjT2L2VfVNPC4rCHu9ULE4LkOvg8xE+vp89C8uti9TkV2h gqCniCBBgN057ZOqvsjBVFeNlFTiPqmPxFzIP8m2OHKJ+5+2TpaXlj9h2iJvlGYDtxFQ CN8cv/pDh8XWPxoFZOJfd9wfIgCUJHpos6RG4/S0TBYSUrGcLX3nxkOspCeLrhGpssOc szxbKV8TrlgwFoja2a/DOu213quyiQl5ZE5G+O0qjSsRYrRlyhIw76cVvci0pFvFBXh9 wVjhNX7r7X3TcUks20RBxcwkSjQ0rQJJD78nzaUPhQht3SIrcDHOqVsC0ajBUUMJwCqq osLw== X-Gm-Message-State: AFeK/H3/rt1zVxQf6U3KRvr3xmKgKjKJoxr3CwgUsnyIflGC90jibY3U4Whk3CoSx4z8kQ== X-Received: by 10.98.156.203 with SMTP id u72mr47336746pfk.127.1491680354859; Sat, 08 Apr 2017 12:39:14 -0700 (PDT) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:b9e0:ac:e01a:86f8]) by smtp.gmail.com with ESMTPSA id t12sm16328627pfg.14.2017.04.08.12.39.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Apr 2017 12:39:14 -0700 (PDT) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, tglx@linutronix.de, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v5 4/5] vfs: Add timestamp_truncate() api Date: Sat, 8 Apr 2017 12:37:46 -0700 Message-Id: <1491680267-11171-5-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491680267-11171-1-git-send-email-deepa.kernel@gmail.com> References: <1491680267-11171-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 the clamp_t macro is used for clamping here as vfs is not yet using struct timespec64 internally. This is required for compilation purposes. Also note that clamp won't do the right thing for timestamps beyond 2038 on 32-bit machines until the vfs uses timespec64. After the vfs is transitioned to use timespec64 for timestamps, clamp_t() can 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 a0c1522..8ad5561 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2103,6 +2103,36 @@ void inode_nohighmem(struct inode *inode) EXPORT_SYMBOL(inode_nohighmem); /** + * timestamp_truncate - Truncate timespec to a granularity + * @t: Timespec + * @inode: inode being updated + * + * Truncate a timespec to the granularity supported by the fs + * containing the inode. 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. * @@ -2121,6 +2151,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);