From patchwork Mon Jan 22 02:04:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 864134 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="o6MAcr6H"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zPvtR5Gnkz9sBW for ; Mon, 22 Jan 2018 13:06:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751164AbeAVCFT (ORCPT ); Sun, 21 Jan 2018 21:05:19 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38925 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbeAVCFS (ORCPT ); Sun, 21 Jan 2018 21:05:18 -0500 Received: by mail-pf0-f195.google.com with SMTP id e11so5919658pff.6; Sun, 21 Jan 2018 18:05:17 -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=YCvousbKGN3cS+F1VHrAdUZCmQfPMyKP6AvbPHzvNjk=; b=o6MAcr6HXSZVr7oOiz6sKhrDxIfMgr3wzXEtGXNQN09LQIJi0HLXyDiafPIN3wVINg Yc9h6Z7saPlvf4MfzTYM2BPvtWTBde/RYsOs7HHLc23BOVeXIxHq0waKzwH8/65hGKf1 hiuDrs0Ulf9DkojVA1OLV53wsGVsunPRJqnIxySv/x6XwrHPfHUz7Q0Xz93peGlMRN86 McvDRbcg2IeycVDh+KXXD4vx6tcs+ju/NaSE6Fb9aY+WwQAtpUxUPAIOcACNuAudUJC0 s1gd5I6O5E6KvXinvFE1Py0cpVr86CKJ+q/e5U6zZal9K6sIXFkegJVFyjqRipmQoZmL UJow== 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=YCvousbKGN3cS+F1VHrAdUZCmQfPMyKP6AvbPHzvNjk=; b=ixL+drXdELLydg3TzGaudTlXp23DfEXFQMZHa1OtfzQJL2c3x+RSiNOzPDSIMMHQWM mS2nnEHJKclnfsT+eR9IKC7fm1XXwRlQlbSMBw0lQiW/N/au5gfXK6wjRtVW+2/ZVX65 uOYCZiMCmhy05KXMTzZhHxPAlcLFXpuhvvXLMU1iXwrQomMO8DqgIOwteeewy1LTOfPZ mhLbUfetCwo/w87/LFakvZp/FQ92XIHkJoBzUyEqK4vntsYSLnLbfINdpPuFDH04sbuc da3jMu+SOyUGScDin95+uTaYnUlYdcLXZiVVuY8MKN5GBQ+yzUo6Sc+bvYnjfrtceZYX GKSw== X-Gm-Message-State: AKwxytcMSqyonU8jW7PGQB1B0XiKzxfvrUcRUhUogCSqyECQ+AZpjtAm ErzNCq/oqLTbn3jhajDe8Hw= X-Google-Smtp-Source: AH8x225gAUfeBq2NjVqKUBAyQZZ1Q/FMntB0x7/hdGok4YgVpuy7xudPS0fWwXvk4nq+LQvgx7/CeA== X-Received: by 10.99.123.91 with SMTP id k27mr5844608pgn.179.1516586717521; Sun, 21 Jan 2018 18:05:17 -0800 (PST) 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 y79sm27168472pfb.177.2018.01.21.18.05.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:16 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 1/4] vfs: Add file timestamp range support Date: Sun, 21 Jan 2018 18:04:23 -0800 Message-Id: <20180122020426.2988-2-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-deepa.kernel@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add fields to the superblock to track the min and max timestamps supported by filesystems. Initially, when a superblock is allocated, initialize it to the max and min values the fields can hold. Individual filesystems override these to match their actual limits. Pseudo filesystems are assumed to always support the min and max allowable values for the fields. Note that the time ranges are saved in type time64_t rather than time_t. This is required because if we save ranges in time_t then we would not be able to save timestamp ranges for files that support timestamps beyond y2038. Signed-off-by: Deepa Dinamani --- fs/super.c | 2 ++ include/linux/fs.h | 3 +++ include/linux/time64.h | 2 ++ 3 files changed, 7 insertions(+) diff --git a/fs/super.c b/fs/super.c index 672538ca9831..9e0c97e54e46 100644 --- a/fs/super.c +++ b/fs/super.c @@ -244,6 +244,8 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_maxbytes = MAX_NON_LFS; s->s_op = &default_op; s->s_time_gran = 1000000000; + s->s_time_min = TIME64_MIN; + s->s_time_max = TIME64_MAX; s->cleancache_poolid = CLEANCACHE_NO_POOL; s->s_shrink.seeks = DEFAULT_SEEKS; diff --git a/include/linux/fs.h b/include/linux/fs.h index f9d01c0951a8..406f3de71c22 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1379,6 +1379,9 @@ struct super_block { /* Granularity of c/m/atime in ns. Cannot be worse than a second */ u32 s_time_gran; + /* Time limits for c/m/atime in seconds. */ + time64_t s_time_min; + time64_t s_time_max; /* * The next field is for VFS *only*. No filesystems have any business diff --git a/include/linux/time64.h b/include/linux/time64.h index 93d39499838e..76ed46db7a7f 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -36,6 +36,8 @@ struct itimerspec64 { /* Located here for timespec[64]_valid_strict */ #define TIME64_MAX ((s64)~((u64)1 << 63)) +#define TIME64_MIN (-TIME64_MAX - 1) + #define KTIME_MAX ((s64)~((u64)1 << 63)) #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) From patchwork Mon Jan 22 02:04:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 864133 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SfKsq+Uf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zPvtG1yTFz9s74 for ; Mon, 22 Jan 2018 13:06:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751228AbeAVCF1 (ORCPT ); Sun, 21 Jan 2018 21:05:27 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:45888 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbeAVCFY (ORCPT ); Sun, 21 Jan 2018 21:05:24 -0500 Received: by mail-pf0-f196.google.com with SMTP id a88so5905028pfe.12; Sun, 21 Jan 2018 18:05:24 -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=V4/3uy3DmJZ3QpxMT4501VEMRbU/nT9ZF+3f9W4T1gg=; b=SfKsq+UfoToP7P3IWuNAzKI5/sE+6mQPlu5JAN1tvs+iXMeaJqWW8Fd64lgStIEvuZ +gEt4QPhZY3J/IyNhSlFKsuZblWHZ0HYjK4beGh4W1iQiFVM+HZgJTV4rc2CrzmS31GI TnjLgeOFnBomymQ9lGdZuTzuIRlRgG7+D338w1s0FoCFn3qlL0lcIQuamldxb1BRhlb3 qQ0C7chmRMVl7MB2T6iu4E7CCRp6xI5sP/ShgfeW4Uxpn0xg5LeCBoE32rNOeWsfMnHB CI0wB9Frh9yF2CaThhubuPbNovTTxHvjZFXoaq9qDpnq2raY8URhqjkA+DSsB57d22Rh Jcxg== 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=V4/3uy3DmJZ3QpxMT4501VEMRbU/nT9ZF+3f9W4T1gg=; b=l900dgVt8ctfD4vfEVmZGYmzF8tXM7TrsXoo8g5M8O+JOYJL6GAtpcmEiWdKQN2Dmu e4rNXuFmkXinb+oaawwAVBHajkPgAJwPxnIerLO6MQ5MqiWcjyhW6atItXRUnquqV/qd oM9Es1tWTY3SSpt7FPm0xb2l+12YDP7rxJgQBJfnVICDJfearwMeXnb7OcQZHYBUg9SW QfUGl3+nJTFW+/wt3/tSTT/MkHXXgy/o9dKEhNYA1dL7sLwq5+/xcMjzOjcJ3FJHrhkq 81zGvrxDEAkX4S8ahD8Z5aBpvc1czFbL5ekytLp7neoVVLLjTXUXFNQ4y8vna9KXPlvo dWXg== X-Gm-Message-State: AKwxytfYhOmf4dliI4vtWVhAxSEcrohdPZ/6fmhpfDzeFjIl6FIRHHmv ItV5efNx5kAxV+4fwzNUPak= X-Google-Smtp-Source: AH8x226PJrLB0FLCoI45B4hwNfD0IstD88mB1oVdkUPTTdqeXbXmcjAfIe69Z+lwwOeCMqEcuLgmtw== X-Received: by 10.98.141.199 with SMTP id p68mr6604022pfk.25.1516586724249; Sun, 21 Jan 2018 18:05:24 -0800 (PST) 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 y79sm27168472pfb.177.2018.01.21.18.05.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:23 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 2/4] ext4: Initialize timestamps limits Date: Sun, 21 Jan 2018 18:04:24 -0800 Message-Id: <20180122020426.2988-3-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-deepa.kernel@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ext4 has different overflow limits for max filesystem timestamps based on the extra bytes available. Signed-off-by: Deepa Dinamani Cc: "Theodore Ts'o" Cc: Andreas Dilger Cc: linux-ext4@vger.kernel.org --- fs/ext4/ext4.h | 4 ++++ fs/ext4/super.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3241475a1733..fe4d7a168664 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1602,6 +1602,10 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei) #define EXT4_GOOD_OLD_INODE_SIZE 128 +#define EXT4_EXTRA_TIMESTAMP_MAX (((s64)1 << 34) - 1 + S32_MIN) +#define EXT4_NON_EXTRA_TIMESTAMP_MAX S32_MAX +#define EXT4_TIMESTAMP_MIN S32_MIN + /* * Feature set definitions */ diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 0843ebfeace1..7c2b227aa319 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3768,8 +3768,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_inode_size); goto failed_mount; } - if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) + if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); + sb->s_time_max = EXT4_EXTRA_TIMESTAMP_MAX; + } else + sb->s_time_max = EXT4_NON_EXTRA_TIMESTAMP_MAX; + + sb->s_time_min = EXT4_TIMESTAMP_MIN; } sbi->s_desc_size = le16_to_cpu(es->s_desc_size); From patchwork Mon Jan 22 02:04:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 864132 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZbSqud0U"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zPvt53T4pz9s9Y for ; Mon, 22 Jan 2018 13:06:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751264AbeAVCFe (ORCPT ); Sun, 21 Jan 2018 21:05:34 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:41776 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbeAVCFa (ORCPT ); Sun, 21 Jan 2018 21:05:30 -0500 Received: by mail-pg0-f66.google.com with SMTP id 136so5915856pgd.8; Sun, 21 Jan 2018 18:05:30 -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=Rs0d39FNuYOTBPYi8ubx47+mA9bgU0C8swbnRvt1DiE=; b=ZbSqud0Unk24CHFz8jo7RanSPHcshVDxYv/xsX6a0m0bi/bffkvWWgnK008EPi4r79 5lACYnMkyA1G17DxPGq4jHrumUDdFnt0ra9Fzry8qjVZZik7lU+47URlmnBtcw4Wg66j /iwonoK6gfMsyUl2HUq/doH3lYPaPCu0+tbPhckPR+6PjRO9lt/hsstqXbtycL2JdhTV 8hT+YAiKOz9QOtGsRnr48L74qHTNd2R+FXqn9iKGAK94NjSr12DoJ2bhY9/sRdKqyo+0 nJ533sS+JwR8HHVoyHwSqmqD8DrvcOH9dbKNgdp2PoK+yPMey+Q++0hYxN2E/uBVlwSc KeUA== 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=Rs0d39FNuYOTBPYi8ubx47+mA9bgU0C8swbnRvt1DiE=; b=OMI75OH6a8k7AwY04hhZugnIm3XT33Ktq/rx3//hY2CAQ1IzlfiDgXyfWp4brNy0bu EDM1o1Fxvk/mKlPIMPcsUNEvfRSVBxMO34m+ZFVT//4BE5l8AvBsLeOw18s8wPr4Jsav QRdD5e8arWh/76oQV8LuC7y9EnC99H/ik7ZxE484AwiboEWpiP98YnMgLap3TzOJWyoj QlGbDVpfiyGFUORWBqtsXIknrfsNhjWJlIiWUsehi145vOCiG57+Kt3nGgyKwyOJ9pUe oTZxw8FVJihmMvxgpsLBPSzMugPtMiEeG/5sejpFgP0MRBvIwO6v+fi97N9iyTds6km3 3FMw== X-Gm-Message-State: AKwxytczvLXnZqQqQ2mqTisWGTwdLv4+UuApSdD//VCL6nPt42SOR8P2 NFj6lNKZRflEt566RNLRc3Y= X-Google-Smtp-Source: AH8x226Z2FZyFRpQctZuzrnkP867tlDpi6L7vZUC3aeh3bpjgtVubvkkDp+uyEUuYAASKd21oCcicA== X-Received: by 10.98.202.84 with SMTP id n81mr6767288pfg.226.1516586730058; Sun, 21 Jan 2018 18:05:30 -0800 (PST) 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 y79sm27168472pfb.177.2018.01.21.18.05.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:29 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 3/4] vfs: Add timestamp_truncate() api Date: Sun, 21 Jan 2018 18:04:25 -0800 Message-Id: <20180122020426.2988-4-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-deepa.kernel@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 ef362364d396..0e2820ade554 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2107,6 +2107,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. @@ -2126,6 +2156,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); From patchwork Mon Jan 22 02:04:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 864131 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aW3DFcAC"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zPvsq5KK2z9s9Y for ; Mon, 22 Jan 2018 13:05:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751256AbeAVCFf (ORCPT ); Sun, 21 Jan 2018 21:05:35 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:38032 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751069AbeAVCFb (ORCPT ); Sun, 21 Jan 2018 21:05:31 -0500 Received: by mail-pf0-f195.google.com with SMTP id k19so5919170pfj.5; Sun, 21 Jan 2018 18:05:31 -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=fDhRECMcNsvujjmxvp2XlvDKoTYS4VHgBf8JF6zt7wU=; b=aW3DFcACT3maGhsmYvOH3TAKCFs97XvPgecgBLVyzecZaFHgR/RadK6Wqi6r5sQt+v w6uyUw397aAUnd67/iSiHmFhchTEmfBId8a44BgTl9Rl9baoHI7tBxpA8GcQsI2c6z1Y YxCB7TNbLhYOCyBMxGeN/K3LUUuI3Z26C0RhmSzpvl9xyn8iuQLh3y1XA+HMgV42fnkG h13lbjGIXzm8DcqeGoaz2bYMj/7f08/bewMneNy3bY4ZVcaRh9GkEIKzuA3EAPHWY1vf hAsVuydpzEstzUrgCUWdvNlIfWg2mlzvKbvGT6+PoJeTpXbYYymMmP4BlGCETI7LjRNK uGeg== 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=fDhRECMcNsvujjmxvp2XlvDKoTYS4VHgBf8JF6zt7wU=; b=q8VzCoIut51S1BTMMs9F7ubi/eZpaDmbOGe7g/wHSQBybQosAnd+/08AoKeOZ9IUZ2 HMeY+QrCVnSmBjufsbEuqKgZtAFB6DsO6aLvgfonHlYc/RQFdaxJVbL57hwAXcI8rdmq VK8cQ1j92rAXdG+GoTLLmJpQd9i647olad2KvENBLINVn2H0i5Q0t06JJ+ift0SjjaTN d+h9RoL8CiSDHYjfJbPmFnHPpQtW7zWu2ygmvXyX3X+T3w8Cut7cyib/xw3TG/2daedn UnJXiCx/IjfWSrDrAIlPIB6yHcWkkaXPkMpku/AmckVeHY/XpmhdeMlCdxIeh9fryh0b Y2vw== X-Gm-Message-State: AKwxytdBewKMEIgQX0V+xT9NQgkOxZWZSkPbb+vLFemuRo30fW3jHcEp md8E+tCWoWLtbRWQoj/PUgM= X-Google-Smtp-Source: AH8x226xxnObq0wgC7T67pgYCBbzFNaYAm9oTvQPldmfvKL+ZbB/dPjSPAvDwvKn8ufyQ5IFmOM18Q== X-Received: by 10.98.103.83 with SMTP id b80mr6747721pfc.223.1516586731175; Sun, 21 Jan 2018 18:05:31 -0800 (PST) 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 y79sm27168472pfb.177.2018.01.21.18.05.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 18:05:30 -0800 (PST) From: Deepa Dinamani To: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de, y2038@lists.linaro.org Subject: [PATCH v6 4/4] utimes: Clamp the timestamps before update Date: Sun, 21 Jan 2018 18:04:26 -0800 Message-Id: <20180122020426.2988-5-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180122020426.2988-1-deepa.kernel@gmail.com> References: <20180122020426.2988-1-deepa.kernel@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org POSIX.1 section for futimens, utimensat and utimes says: The file's relevant timestamp shall be set to the greatest value supported by the file system that is not greater than the specified time. Clamp the timestamps accordingly before assignment. 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/utimes.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/utimes.c b/fs/utimes.c index e4b3d7c2c9f5..82fdcc3284b9 100644 --- a/fs/utimes.c +++ b/fs/utimes.c @@ -50,6 +50,7 @@ static int utimes_common(const struct path *path, struct timespec64 *times) int error; struct iattr newattrs; struct inode *inode = path->dentry->d_inode; + struct super_block *sb = inode->i_sb; struct inode *delegated_inode = NULL; error = mnt_want_write(path->mnt); @@ -65,16 +66,24 @@ static int utimes_common(const struct path *path, struct timespec64 *times) if (times[0].tv_nsec == UTIME_OMIT) newattrs.ia_valid &= ~ATTR_ATIME; else if (times[0].tv_nsec != UTIME_NOW) { - newattrs.ia_atime.tv_sec = times[0].tv_sec; - newattrs.ia_atime.tv_nsec = times[0].tv_nsec; + newattrs.ia_atime.tv_sec = + clamp_t(time64_t, times[0].tv_sec, sb->s_time_min, sb->s_time_max); + if (times[0].tv_sec >= sb->s_time_max) + newattrs.ia_atime.tv_nsec = 0; + else + newattrs.ia_atime.tv_nsec = times[0].tv_nsec; newattrs.ia_valid |= ATTR_ATIME_SET; } if (times[1].tv_nsec == UTIME_OMIT) newattrs.ia_valid &= ~ATTR_MTIME; else if (times[1].tv_nsec != UTIME_NOW) { - newattrs.ia_mtime.tv_sec = times[1].tv_sec; - newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; + newattrs.ia_mtime.tv_sec = + clamp_t(time64_t, times[1].tv_sec, sb->s_time_min, sb->s_time_max); + if (times[1].tv_sec >= sb->s_time_max) + newattrs.ia_mtime.tv_nsec = 0; + else + newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; newattrs.ia_valid |= ATTR_MTIME_SET; } /*