From patchwork Mon Jan 22 02:04:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 10177199 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 D9203601D5 for ; Mon, 22 Jan 2018 02:05:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C947D28399 for ; Mon, 22 Jan 2018 02:05:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE26A283A5; Mon, 22 Jan 2018 02:05:59 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 72DE128399 for ; Mon, 22 Jan 2018 02:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751281AbeAVCFe (ORCPT ); Sun, 21 Jan 2018 21:05:34 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41776 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbeAVCFa (ORCPT ); Sun, 21 Jan 2018 21:05:30 -0500 Received: by mail-pg0-f66.google.com with SMTP id 136so5915856pgd.8; Sun, 21 Jan 2018 18:05:30 -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=Rs0d39FNuYOTBPYi8ubx47+mA9bgU0C8swbnRvt1DiE=; b=ZbSqud0Unk24CHFz8jo7RanSPHcshVDxYv/xsX6a0m0bi/bffkvWWgnK008EPi4r79 5lACYnMkyA1G17DxPGq4jHrumUDdFnt0ra9Fzry8qjVZZik7lU+47URlmnBtcw4Wg66j /iwonoK6gfMsyUl2HUq/doH3lYPaPCu0+tbPhckPR+6PjRO9lt/hsstqXbtycL2JdhTV 8hT+YAiKOz9QOtGsRnr48L74qHTNd2R+FXqn9iKGAK94NjSr12DoJ2bhY9/sRdKqyo+0 nJ533sS+JwR8HHVoyHwSqmqD8DrvcOH9dbKNgdp2PoK+yPMey+Q++0hYxN2E/uBVlwSc KeUA== 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=Rs0d39FNuYOTBPYi8ubx47+mA9bgU0C8swbnRvt1DiE=; b=OMI75OH6a8k7AwY04hhZugnIm3XT33Ktq/rx3//hY2CAQ1IzlfiDgXyfWp4brNy0bu EDM1o1Fxvk/mKlPIMPcsUNEvfRSVBxMO34m+ZFVT//4BE5l8AvBsLeOw18s8wPr4Jsav QRdD5e8arWh/76oQV8LuC7y9EnC99H/ik7ZxE484AwiboEWpiP98YnMgLap3TzOJWyoj QlGbDVpfiyGFUORWBqtsXIknrfsNhjWJlIiWUsehi145vOCiG57+Kt3nGgyKwyOJ9pUe oTZxw8FVJihmMvxgpsLBPSzMugPtMiEeG/5sejpFgP0MRBvIwO6v+fi97N9iyTds6km3 3FMw== X-Gm-Message-State: AKwxytczvLXnZqQqQ2mqTisWGTwdLv4+UuApSdD//VCL6nPt42SOR8P2 NFj6lNKZRflEt566RNLRc3Y= X-Google-Smtp-Source: AH8x226Z2FZyFRpQctZuzrnkP867tlDpi6L7vZUC3aeh3bpjgtVubvkkDp+uyEUuYAASKd21oCcicA== X-Received: by 10.98.202.84 with SMTP id n81mr6767288pfg.226.1516586730058; Sun, 21 Jan 2018 18:05:30 -0800 (PST) Received: from deepa-ubuntu.lan (c-67-170-212-194.hsd1.ca.comcast.net. [67.170.212.194]) by smtp.gmail.com with ESMTPSA id y79sm27168472pfb.177.2018.01.21.18.05.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:29 -0800 (PST) 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, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 3/4] vfs: Add timestamp_truncate() api Date: Sun, 21 Jan 2018 18:04:25 -0800 Message-Id: <20180122020426.2988-4-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-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 ef362364d396..0e2820ade554 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2107,6 +2107,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. @@ -2126,6 +2156,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);