From patchwork Sat Feb 18 23:30:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9581395 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 D5AB06049F for ; Sat, 18 Feb 2017 23:32:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC121287AF for ; Sat, 18 Feb 2017 23:32:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0DC3287B6; Sat, 18 Feb 2017 23:32:23 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 78204287AF for ; Sat, 18 Feb 2017 23:32:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751374AbdBRXbh (ORCPT ); Sat, 18 Feb 2017 18:31:37 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34946 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750825AbdBRXbJ (ORCPT ); Sat, 18 Feb 2017 18:31:09 -0500 Received: by mail-pg0-f68.google.com with SMTP id 1so969754pgz.2; Sat, 18 Feb 2017 15:30:46 -0800 (PST) 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=XdsbL7kUh0zhES+u+gIrzcs12wm/qDE8rLC5X7moHB4=; b=fMupm8/8HztntahKG7eRI/76mf7nrQyrWgXE6obeav2qvzNoWW3WvLMPHSVxziyf6+ HTQY5NJDHeGE2pnc8IVH4oQqkRsuzjUizocJXsUZD+acI3MBzkx9XRneYxNiSKC/GMkz oO7qTh41dNlc2iQRWvNQrwf0ztHFNbD+0Fh6nCQR8KMHi0tgxL2olEfAsphII//XmLMX gyVZU0FavDoXDpc3yWDMKJdze8BDfQRvu85mnulKWDLHZyiKdxdwag1tGdSoI020GI/j 7csPW97RFDuGA8Q6lSExSgWIKoSlVwa5yMiwzkM20uw5EzcX2y5bRpZy/fmJUYQrscvm 4b8w== 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=XdsbL7kUh0zhES+u+gIrzcs12wm/qDE8rLC5X7moHB4=; b=QHG0Dx6nFq6XvzwzVGWfddb4KXFKOcb30duRm6Znml6YbxSAhaOsckzL1OwYSSA6Sj tqk4yeY/YAIcx8A05IC3SpKfdmgMR3ksep8KQ2r2Y2KRrTW4/Yzh11FJdR+Lm4D2+T2m YL783Xru8iTuwMe5zxanpqIpM3YIIxdAE6SOh9VfeeaARFc7kFq7vzM3slnhn/JUpmSz vtKjOWS+1cR0MP6nHruFklMnkPkC5MrF0XVuUe5+oZb0+Tl85Y/T9FgCyR8fQMq9/5Pa 5XFp1vyI/dUsrW9OOSZ2LmadF9N6/sNaO+ZN0BVKqRKN7Aog5V3yECzT4GRFSfvmuaWC 8T5g== X-Gm-Message-State: AMke39kRQUopeoRN0X9lKMZfPFnF34geTz6z5y+i0di05NMj64QxQ+44EUz9LJGP49yJQQ== X-Received: by 10.84.228.208 with SMTP id y16mr17895269pli.168.1487460645461; Sat, 18 Feb 2017 15:30:45 -0800 (PST) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:e8a1:d9de:f814:c176]) by smtp.gmail.com with ESMTPSA id s24sm27278030pgo.25.2017.02.18.15.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 18 Feb 2017 15:30:45 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v3 4/5] vfs: Add timestamp_truncate() api Date: Sat, 18 Feb 2017 15:30:07 -0800 Message-Id: <1487460608-15697-5-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487460608-15697-1-git-send-email-deepa.kernel@gmail.com> References: <1487460608-15697-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 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 0573a3e..6a1bc12 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2114,6 +2114,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. * @@ -2132,6 +2162,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);