From patchwork Sat Jun 25 21:37:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9198857 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 34D126075F for ; Sat, 25 Jun 2016 21:48:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ADF428527 for ; Sat, 25 Jun 2016 21:48:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FC632852B; Sat, 25 Jun 2016 21:48:02 +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=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 BE3C428527 for ; Sat, 25 Jun 2016 21:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751738AbcFYViY (ORCPT ); Sat, 25 Jun 2016 17:38:24 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:34196 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751231AbcFYViV (ORCPT ); Sat, 25 Jun 2016 17:38:21 -0400 Received: by mail-pa0-f67.google.com with SMTP id us13so11943946pab.1; Sat, 25 Jun 2016 14:38:21 -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=vbKC4UIz/klBwkOVEFnGr6qVxRsJrFD4spnFwX1RPSA=; b=qhq48MGVV2mV2YegCeA0anteQ0SaQoW9qdXsANCSfSo2nyXIUwo+duj5rtkvLFiQbJ UUnVnd46FT1x+yigTor3ZEn05QpL8D8ZwAbOWAjCS/jEw7+IP2y0drXD+1Ifzs3iAbnL LSOosEasLsLZ/ldjNABeERC7pkAhJS4n7wOQOVvzbhYySyT1xXBVNkRQCaGCxXeF8UoZ 8e+hXA2BT5aXtg8Z8rgv5MPXFkXWrm1xniX3hBeOKma+WgBjlHESn1tngGa1SAX1bwLy 3rFxnJsbQBqlmwRqGQgBRHPhcM7T/fgFqQxYjXFX7s5O3fj2lYlGu433w2k8VRpCb9O/ h0jQ== 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=vbKC4UIz/klBwkOVEFnGr6qVxRsJrFD4spnFwX1RPSA=; b=U5jrLH62+l2VTvaHN7YOic5Y45OWXL+m/nkCzT57ndU7YcQk9mYsH45aXmk5zjG2cq x86IW+X3UwSzvwWgF+EKMBL5/nor9fhRw+8fcmUr2gjlSXjXMtyD0xyy4gMoHxilrQ/h YrJ0QN1+wvzAiOZhIkXCLoySJklYKxh1+DaU4pTcifZIFcqQBTON5u55+sO4uK/43m1V Wev1PzKoHSnWEoCSvuWtKwTWboszYSBKtRZzdTEKTo0zVlvoioTh1T5kC6ZttLjEGeB3 49TX6YsSJFeSkh5omQ4HEa/9nYjFLiQciqE05FDRPTEsluAs22mGMiqqp03bugWvOUHF 32GA== X-Gm-Message-State: ALyK8tJnxbztRmu/7HPIx2K8X7760i6eMlM6OCHinigpShJ5MIsZgZPEjJnqkcSwEQrzug== X-Received: by 10.67.3.227 with SMTP id bz3mr19748582pad.67.1466890700607; Sat, 25 Jun 2016 14:38:20 -0700 (PDT) Received: from deepa-ubuntu.hsd1.ca.comcast.net (c-73-252-251-201.hsd1.ca.comcast.net. [73.252.251.201]) by smtp.gmail.com with ESMTPSA id m8sm1861308pfi.27.2016.06.25.14.38.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Jun 2016 14:38:20 -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, tytso@mit.edu, viro@zeniv.linux.org.uk, y2038@lists.linaro.org Subject: [PATCH v3 01/24] vfs: Add current_time() api Date: Sat, 25 Jun 2016 14:37:25 -0700 Message-Id: <1466890668-23400-2-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466890668-23400-1-git-send-email-deepa.kernel@gmail.com> References: <1466890668-23400-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 --- 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 e171f7b..80b6898 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2043,3 +2043,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 c4ab2cf..d0d9b38 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1476,6 +1476,7 @@ struct super_block { }; extern struct timespec current_fs_time(struct super_block *sb); +extern struct timespec current_time(struct inode *inode); static inline struct timespec current_fs_time_sec(struct super_block *sb) {