From patchwork Sat May 12 04:59:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 10395785 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 B8A9F60236 for ; Sat, 12 May 2018 05:02:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA77428B58 for ; Sat, 12 May 2018 05:02:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F4C728D69; Sat, 12 May 2018 05:02:48 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 3120828B58 for ; Sat, 12 May 2018 05:02:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751096AbeELFBO (ORCPT ); Sat, 12 May 2018 01:01:14 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:44388 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751017AbeELFBL (ORCPT ); Sat, 12 May 2018 01:01:11 -0400 Received: by mail-pl0-f67.google.com with SMTP id e6-v6so4360322plt.11; Fri, 11 May 2018 22:01:11 -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=Ahb0obAPdQV4aGbcBp7euiaeL7pr2oiJwD5F/WBY7jo=; b=mZC4XRMv8Wj1FxApLGBJDqkmyY36eZWiMUrGXRg2yj+7RCp7AD6d+BK8420aPAgX5R EvuWuVPWxpkdxPvaITt9N3aS8gtSIkbu0tHd0mQPaDchvbcdRnDmTO/EYRe23zF6g5+3 idIrHXwkMdsZY+R0GK7AI5ZIN6kvBreFIIvteWrnrA9IWasKmduvDpivpEVsYjsw3zRZ vkyDlbdzYUC0cKN5G+1HYrgbRga+MYx00YO9fbpMf1HuOa59ik3OBmQHP50w+lZy0mLh BFOvkviOYbGzYtbLyf29omfn+D8/G1DnL39WDAdw3xUEqlLG5GAmCTnUCwWwjYpDB2mF ikkA== 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=Ahb0obAPdQV4aGbcBp7euiaeL7pr2oiJwD5F/WBY7jo=; b=bX4BAb1Ti3aVhXVKmR6FwJYC2NB62gEh41vE3SBCLMqifJPNaq3WmHZbGMC4vdfKRS d3g2StRPd/YzAJpNjmvSImkRaGbgj6p6CCoSYJyhCRQO/pAtw/4gpKdXQ6WPag/aOTvn /H2TNvDQ/M7BPo3Iuf8juU0MuH642xXQNMxBqpvPwws/aG3cTbFmi1AJKvz/1ogDSCNx aZs7tVIYtnjfCgZ7td0YyDkSUhYpL3s54eWrLC5vFdF3pJri7xhen3WxGLF16c9oCtoc hYpHJm+Jqk6XARLf/dd6Mygn4DzIO3MWwx0f4vwdTrgu5rvlhd9fglKXeYCSSafNyElp d69Q== X-Gm-Message-State: ALKqPwdBeZ5omGvk0t66eG8D7EcGYoeGeyGPVWN3PaJk5fZ1ClS8tTNc rymI+pvt6e91Bf5b27BmWyI= X-Google-Smtp-Source: AB8JxZqIJNWGRHfBhBD/joZ/lit+HxFMQGEHzsjUl4Bd1Ux3e0780zsbvNiMTmO66GeD8ITu5EUNVQ== X-Received: by 2002:a17:902:4464:: with SMTP id k91-v6mr979069pld.219.1526101271448; Fri, 11 May 2018 22:01:11 -0700 (PDT) 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 206-v6sm7794717pfy.51.2018.05.11.22.01.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 22:01:10 -0700 (PDT) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tglx@linutronix.de Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, y2038@lists.linaro.org Subject: [PATCH 1/6] fs: add timespec64_truncate() Date: Fri, 11 May 2018 21:59:16 -0700 Message-Id: <20180512045921.18311-2-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180512045921.18311-1-deepa.kernel@gmail.com> References: <20180512045921.18311-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 As vfs moves to using struct timespec64 to represent times, update the argument to timespec_truncate() to use struct timespec64. Also change the name of the function. The rest of the implementation logic is the same. Move this to fs/inode.c instead of kernel/time/time.c as all the users of this api are filesystems. Signed-off-by: Deepa Dinamani Cc: --- fs/inode.c | 24 ++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 25 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 13ceb98c3bd3..93af998ee290 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2110,6 +2110,30 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +/** + * timespec64_trunc - Truncate timespec64 to a granularity + * @t: Timespec64 + * @gran: Granularity in ns. + * + * Truncate a timespec64 to a granularity. Always rounds down. gran must + * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns). + */ +struct timespec64 timespec64_trunc(struct timespec64 t, unsigned gran) +{ + /* 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(timespec64_trunc); + /** * current_time - Return FS time * @inode: inode. diff --git a/include/linux/fs.h b/include/linux/fs.h index 0eedf745667b..381c77a37404 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1477,6 +1477,7 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid = make_kgid(inode->i_sb->s_user_ns, gid); } +extern struct timespec64 timespec64_trunc(struct timespec64 t, unsigned gran); extern struct timespec current_time(struct inode *inode); /*