From patchwork Wed Sep 14 14:48:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9331815 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 57D516077A for ; Wed, 14 Sep 2016 14:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4931B2A0EF for ; Wed, 14 Sep 2016 14:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DBBF2A0F4; Wed, 14 Sep 2016 14:49:51 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 29B5D2A0EF for ; Wed, 14 Sep 2016 14:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764292AbcINOtq (ORCPT ); Wed, 14 Sep 2016 10:49:46 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:33506 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762100AbcINOsh (ORCPT ); Wed, 14 Sep 2016 10:48:37 -0400 Received: by mail-pa0-f68.google.com with SMTP id oz2so840719pac.0; Wed, 14 Sep 2016 07:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u1ttHSNIBz3IRAoWv8HVSuAWSpTwYNIAJ3zAkuI1d8I=; b=tGbj7BRPpDF3rDK6lO5HT6gERmUyNmZRSG0lkMs/poHTljbgMWm5/YtA9mZJcWYfrU lYZ/G5GXqOmvDitaEJqUi0mXf8o/pd83y4Ul7+nLTmNdKpGKk3ePSrIOUs+cjmYmUAPf jO4BLsAfJHczcWIXxK4bq9NEkXVgLD+aMioQNmt8eLcMizvtTnt+AqrNundiqFRygOdv skIWxpW23aIt6DrIbRE9PPRFwLjhZo1yl2kDSW0x331S5ILFgiV4iR7z53S6t2ooURVk ohbHQ4QyD6bfkUXKVrKiD9i2zHg4pzp63XGb3EJc7xFZojTZfIEVO9Z566dEcQoluizj MOFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u1ttHSNIBz3IRAoWv8HVSuAWSpTwYNIAJ3zAkuI1d8I=; b=TH1zBvQdpGij4hRoZ0CohMiJasQR7IIhFSV7dDrzNOcWvIJiynU5UALn94N3KGzFwX uffrqZ6rVYnBh75t3j1Ouec/qT0C97Erdpi/mST/ubnpW8ZkvaCf/QaGP5DCgxelCZQm CQHGMGeKrHdy0jOiSDc5J/P7tT6vTCr5dBursqKKd7rukVLlhfZM/S6AKnLPhTo4bdD4 Y8yCDAPZm9/i/9dV2Iyk4nwKTElb/JZQQNtgSWx8+FaqlJykt+CkoN9O6P6VorTjfITh Z4aIzkljxbfq/1scLcN1LBuNVEKdPh9DXQ5QYfx8dUZymD4JYuXWfhw1MEGmZigBvQc2 GAHw== X-Gm-Message-State: AE9vXwP+dgvete5gkPx0JnDUyyUHgwFGtwtQ+PIP5d45ffAP/5EAGZPWNZlHtGGSZtr4uQ== X-Received: by 10.66.72.40 with SMTP id a8mr5247408pav.15.1473864516901; Wed, 14 Sep 2016 07:48:36 -0700 (PDT) Received: from deepa-ubuntu.hsd1.ca.comcast.net ([2601:647:5000:6620:3862:3238:dafb:7d5f]) by smtp.gmail.com with ESMTPSA id k80sm710142pfk.27.2016.09.14.07.48.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Sep 2016 07:48:36 -0700 (PDT) From: Deepa Dinamani To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, tglx@linutronix.de, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, akpm@linux-foundation.org, tytso@mit.edu, viro@zeniv.linux.org.uk, y2038@lists.linaro.org Subject: [PATCH v5 1/5] vfs: Add current_time() api Date: Wed, 14 Sep 2016 07:48:02 -0700 Message-Id: <1473864486-30862-2-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473864486-30862-1-git-send-email-deepa.kernel@gmail.com> References: <1473864486-30862-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 current_fs_time() is used for inode timestamps. Change the signature of the function to take inode pointer instead of superblock as per Linus's suggestion. Also, move the api under vfs as per the discussion on the thread: https://lkml.org/lkml/2016/6/9/36 . As per Arnd's suggestion on the thread, changing the function name. current_fs_time() will be deleted after all the references to it are replaced by current_time(). There was a bug reported by kbuild test bot with the change as some of the calls to current_time() were made before the super_block was initialized. Catch these accidental assignments as timespec_trunc() does for wrong granularities. This allows for the function to work right even in these circumstances. But, adds a warning to make the user aware of the bug. A coccinelle script was used to identify all the current .alloc_inode super_block callbacks that updated inode timestamps. proc filesystem was the only one that was modifying inode times as part of this callback. The series includes a patch to fix that. Note that timespec_trunc() will also be moved to fs/inode.c in a separate patch when this will need to be revamped for bounds checking purposes. Signed-off-by: Deepa Dinamani Reviewed-by: Arnd Bergmann --- fs/inode.c | 23 +++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 24 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index fd604c0..a95e04e 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2075,3 +2075,26 @@ void inode_nohighmem(struct inode *inode) mapping_set_gfp_mask(inode->i_mapping, GFP_USER); } EXPORT_SYMBOL(inode_nohighmem); + +/** + * current_time - Return FS time + * @inode: inode. + * + * Return the current time truncated to the time granularity supported by + * the fs. + * + * Note that inode and inode->sb cannot be NULL. + * Otherwise, the function warns and returns time without truncation. + */ +struct timespec current_time(struct inode *inode) +{ + struct timespec now = current_kernel_time(); + + if (unlikely(!inode->i_sb)) { + WARN(1, "current_time() called with uninitialized super_block in the inode"); + return now; + } + + return timespec_trunc(now, inode->i_sb->s_time_gran); +} +EXPORT_SYMBOL(current_time); diff --git a/include/linux/fs.h b/include/linux/fs.h index fde36d2..ab249e1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1471,6 +1471,7 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) } extern struct timespec current_fs_time(struct super_block *sb); +extern struct timespec current_time(struct inode *inode); /* * Snapshotting support.