From patchwork Thu Jan 7 05:35:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 7973681 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D90319F1CC for ; Thu, 7 Jan 2016 05:41:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D74B22012D for ; Thu, 7 Jan 2016 05:41:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA7EF20172 for ; Thu, 7 Jan 2016 05:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752709AbcAGFkx (ORCPT ); Thu, 7 Jan 2016 00:40:53 -0500 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34004 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750732AbcAGFgn (ORCPT ); Thu, 7 Jan 2016 00:36:43 -0500 Received: by mail-pa0-f65.google.com with SMTP id yy13so19281541pab.1; Wed, 06 Jan 2016 21:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=TExSsnIT0p/NowGfjrZVEpcdl7OZ6+x4liWXPla+sGg=; b=b9zLld7ACJI6zu8wm2N2MjthXZNexsptnk3347zq9vxanqdyiiqxBY2MK6eYOooyBN iEaRiLWfh8PGYSzcEfFDzs3EbEysaoT+jlINGcTMgoJJ9DvImgeXG+1g41TFQbWNi8J9 59MC5RFz/sSWHsdLMVbliJs7qT0CGziDI7dNPsa+WFsAkfIWmA0Q7bJ39OofTP+BVr7r EZ+OUocJIy8/QYoTjRpB2wDpHM3QR8zQNWgx/V6ers8un/YK417zBHj7voXF40E1QFxI Bx6A3fYEDy38bWUkoywRdhqSNgPXvxU8iIDcVUXTbXmIxjY5JA9t6J2dfOE3TixLMDDX 677Q== X-Received: by 10.66.100.198 with SMTP id fa6mr106966287pab.123.1452145002679; Wed, 06 Jan 2016 21:36:42 -0800 (PST) Received: from localhost.localdomain ([106.51.24.71]) by smtp.gmail.com with ESMTPSA id kk5sm131390736pab.16.2016.01.06.21.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jan 2016 21:36:42 -0800 (PST) From: Deepa Dinamani To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, y2038@lists.linaro.org Subject: [RFC 02/15] vfs: Change all structures to support 64 bit time Date: Wed, 6 Jan 2016 21:35:59 -0800 Message-Id: <1452144972-15802-3-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452144972-15802-1-git-send-email-deepa.kernel@gmail.com> References: <1452144972-15802-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-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SBL_CSS, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current representation of inode times in struct inode, struct iattr, and struct kstat use struct timespec. timespec is not y2038 safe. Use scalar data types (seconds and nanoseconds stored separately) to represent timestamps in struct inode in order to maintain same size for times across 32 bit and 64 bit architectures. In addition, lay them out such that they are packed on a naturally aligned boundary on 64 bit arch as 4 bytes are used to store nsec. This makes each tuple(sec, nscec) use 12 bytes instead of 16 bytes. This will help save RAM space as inode structure is cached in memory. The other structures are transient and do not benefit from these changes. Add accessors for inode timestamps. These provide a way to access the time field members. Accessors abstract the timestamp representation so that any logic to convert between the struct inode timestamps and other interfaces can be placed here. The plan is to globally change all references to these types through these accessors only. So when the actual internal representation changes, it will be transparent to the outside world. This can be extended to add code to validate the inode times that are being set. Macros are chosen as accessors rather than functions because we can condense 3 {a,c,m} time functions into a single macro. After we agree on an approach, the implementation could be changed to use static inline functions if it suits more. Add inode_timespec aliases to help convert kstat and iattr times to use 64 bit times. These hide the internal data type. Use uapi exposed data types here to keep minimal timstamp data type conversions in API's interfacing with vfs. After the CONFIG_FS_USES_64BIT_TIME is enabled, all inode_timespec aliases will be removed and timespec64 data types and API's will be used directly. Signed-off-by: Deepa Dinamani --- include/linux/fs.h | 55 +++++++++++++++++++++++++++++++++++++++++++------- include/linux/stat.h | 6 +++--- include/linux/time64.h | 21 +++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 12ba937..b9f3cee 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -245,13 +245,13 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate); */ struct iattr { unsigned int ia_valid; - umode_t ia_mode; - kuid_t ia_uid; - kgid_t ia_gid; - loff_t ia_size; - struct timespec ia_atime; - struct timespec ia_mtime; - struct timespec ia_ctime; + umode_t ia_mode; + kuid_t ia_uid; + kgid_t ia_gid; + loff_t ia_size; + struct inode_timespec ia_atime; + struct inode_timespec ia_mtime; + struct inode_timespec ia_ctime; /* * Not an attribute, but an auxiliary info for filesystems wanting to @@ -616,9 +616,18 @@ struct inode { }; dev_t i_rdev; loff_t i_size; +#ifdef CONFIG_FS_USES_64BIT_TIME + time64_t i_atime_sec; + time64_t i_mtime_sec; + time64_t i_ctime_sec; + s32 i_atime_nsec; + s32 i_mtime_nsec; + s32 i_ctime_nsec; +#else struct timespec i_atime; struct timespec i_mtime; struct timespec i_ctime; +#endif spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ unsigned short i_bytes; unsigned int i_blkbits; @@ -679,6 +688,38 @@ struct inode { void *i_private; /* fs or device private pointer */ }; +#ifdef CONFIG_FS_USES_64BIT_TIME + +#define VFS_INODE_SET_XTIME(xtime, inode, ts64) \ + do { \ + struct inode_timespec __ts = (ts64); \ + (inode)->xtime##_sec = __ts.tv_sec; \ + (inode)->xtime##_nsec = __ts.tv_nsec; \ + } while (0) + +#define VFS_INODE_GET_XTIME(xtime, inode) \ + (struct timespec64){.tv_sec = (inode)->xtime##_sec, \ + .tv_nsec = (inode)->xtime##_nsec} + +#else + +#define VFS_INODE_SET_XTIME(xtime, inode, ts) \ + ((inode)->xtime = (ts)) + +#define VFS_INODE_GET_XTIME(xtime, inode) \ + ((inode)->xtime) + +#endif + +#define VFS_INODE_SWAP_XTIME(xtime, inode1, inode2) \ + do { \ + struct inode_timespec __ts = \ + VFS_INODE_GET_XTIME(xtime, inode1); \ + VFS_INODE_SET_XTIME(xtime, inode1, \ + VFS_INODE_GET_XTIME(xtime, inode2)); \ + VFS_INODE_SET_XTIME(xtime, inode2, __ts); \ + } while (0) + static inline int inode_unhashed(struct inode *inode) { return hlist_unhashed(&inode->i_hash); diff --git a/include/linux/stat.h b/include/linux/stat.h index 075cb0c..559983f 100644 --- a/include/linux/stat.h +++ b/include/linux/stat.h @@ -27,9 +27,9 @@ struct kstat { kgid_t gid; dev_t rdev; loff_t size; - struct timespec atime; - struct timespec mtime; - struct timespec ctime; + struct inode_timespec atime; + struct inode_timespec mtime; + struct inode_timespec ctime; unsigned long blksize; unsigned long long blocks; }; diff --git a/include/linux/time64.h b/include/linux/time64.h index 367d5af..be98201 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -26,6 +26,27 @@ struct itimerspec64 { #endif +#ifdef CONFIG_FS_USES_64BIT_TIME + +/* Place holder defines until CONFIG_FS_USES_64BIT_TIME + * is enabled. + * timespec64 data type and functions will be used at that + * time directly and these defines will be deleted. + */ +#define inode_timespec timespec64 + +#define inode_timespec_compare timespec64_compare +#define inode_timespec_equal timespec64_equal + +#else + +#define inode_timespec timespec + +#define inode_timespec_compare timespec_compare +#define inode_timespec_equal timespec_equal + +#endif + /* Parameters used to convert the timespec values: */ #define MSEC_PER_SEC 1000L #define USEC_PER_MSEC 1000L