From patchwork Sat Feb 25 01:41:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9591433 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 4DBCD60471 for ; Sat, 25 Feb 2017 01:43:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DB65275A2 for ; Sat, 25 Feb 2017 01:43:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 32CB82867F; Sat, 25 Feb 2017 01:43:19 +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 CCBF5275A2 for ; Sat, 25 Feb 2017 01:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751709AbdBYBmW (ORCPT ); Fri, 24 Feb 2017 20:42:22 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33654 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751586AbdBYBmA (ORCPT ); Fri, 24 Feb 2017 20:42:00 -0500 Received: by mail-pg0-f67.google.com with SMTP id 5so5002182pgj.0; Fri, 24 Feb 2017 17:41:22 -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=Y1xaPbJWQXE1WOxAzEd0g3T/zzksK4uDchWESMmQqnU=; b=HxPSVRcL8O/oZcH3r1KYHHSrPbvMhQGLKxAEz3G3MtsARSkbEEUf59mVKaraLFED2r c75ND8uknU4Vn/SnIGMqrLv/kIZLSrUVcVHmwezT9TSRarlG3D4+grcKHgUIe6u3B3Vq JFgtFcRuRY4z1k7oQAHH3CryX1UXgzuSIR7alwosmtnlS+DvEFdd9M2vXyEsmAqdN8CS orOqPOWWT1P7ItGd2CRKiXd+lJepNnBlQwujRs7V9cJX/mWk0q9PRsb5SiaDU68O5OJk Zb9JDgt8/us5DV72OXvXVLzGdFdYXu1Y8oVHRX20559Zp5oD7DCev/vGoYMsQNWyJ9ac 5iZw== 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=Y1xaPbJWQXE1WOxAzEd0g3T/zzksK4uDchWESMmQqnU=; b=GqU3fEIwu1Dc8D1W7H5spxKDxoK7dilYRFVMtGfG8DFWJu/WwO0QaXCfJRbKV6JW6r Ravpf6G9tNu3tvc4S8jh2XczazWPsGcGr/gVoaMOB+iMD5GW/fLTYCDgFUEV3xBcYvxi zfnkg553rLJqIOah6pJokRBdXIFi+Jn0QxEnVeswgtzcUpyj2QT5fQI5+uNgxGRo4nUW HLVjujVSIvF0e+FVE3vJFnr67Xv4mDm7FZiwUqZf0tro7aTi/T2BWXgwSlf1hfu1BaO+ Rn0tMBl3F3E2tmRCOa5ahUEMAa39ky6b19PwLb1bWi8GKgv0pVSoiDf9tlbycn3FUokM HX7A== X-Gm-Message-State: AMke39l/SRrypo+YDbp0aMLligAdoDMwr1DUE9894hpg6Fe9Hzcm1Yz0+FcBqYgJEtQf4A== X-Received: by 10.84.209.194 with SMTP id y60mr8008601plh.115.1487986881791; Fri, 24 Feb 2017 17:41:21 -0800 (PST) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:d459:bd54:9ed4:a3f5]) by smtp.gmail.com with ESMTPSA id o24sm17175001pfj.78.2017.02.24.17.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Feb 2017 17:41:21 -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 v4 4/5] vfs: Add timestamp_truncate() api Date: Fri, 24 Feb 2017 17:41:02 -0800 Message-Id: <1487986863-6005-5-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487986863-6005-1-git-send-email-deepa.kernel@gmail.com> References: <1487986863-6005-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 7967f9c..39b875b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2116,6 +2116,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. * @@ -2134,6 +2164,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);