From patchwork Wed Jul 11 09:14:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 141701 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp48333ljj; Wed, 11 Jul 2018 02:15:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe37NZ2AgbDeFaaAArNu8mUzNXCzGSCavagT/ztVZeNdh/DKHCzb0Ek33CwV8kCGV0UC3b5 X-Received: by 2002:a62:1a4a:: with SMTP id a71-v6mr1960027pfa.190.1531300506116; Wed, 11 Jul 2018 02:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300506; cv=none; d=google.com; s=arc-20160816; b=Jq1teQw36B5MVhMalKh/+E5C3rmzvyQnGoBr2dT89FixzKnbjHsIAIePnC+U2PKED7 +oiGqc/HpM32dAvub77aDBi5pwUO9peaHCO80pePcTHl3/dPbFH4eHgwWNpMpHeOBbO2 Mwrp1NZxWC4RLJICBztiSgktY0Xk34UwbEZj44WdgBtjg2wHP2D/57OTJ6qLNPM98Sla PBqrw3+5OGFh3fwLeWuycXQoDVaSpX/LNP0VeZg+XoVfW4XFPD+1u3w/S156sUVSwQMQ skZ2M1DJGyMk6gCppQaQIRrIgj3KQ9CR29myYN5DKVca7+iXOBeAe5D4ydS3xt+CELe1 citA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=B0WqIEVpdP5ydgroypsAAy13c3PwJGPpYw+kn2u1rzA=; b=wzCqlCNjg1VJFqjg5nwD2vBdSP7TNOpW4q2Y3tTR52sGIdZrFeq9D7V2R7DIZqXjxV Rtc57v53hGH92BOg32VgJd7BiGT8sQGbnUq495pQJPnTyMCYXcwCb3jl4yZzwOQ1gCxO CVjHu0LS4LQ9gfBI0YW7bgvTQSF14baOo734ROiRhI6jxjKpR5JyO1IzcAtGU9HzBQzy k2CF+OXLaCgGyxqHhqaxfCDGEtS5k5gPIqZry6ApxrCtOb3LSrQcJ4W5jKU0x/FacGIo vswl8WDc0fyCfYCxxRlC+oEBeuoIrTcqLEE4PBbddrBxs8k4t5k74j8Pz526mqL61Qoc rGaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si18885598pld.485.2018.07.11.02.15.05; Wed, 11 Jul 2018 02:15:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732553AbeGKJSS (ORCPT + 22 others); Wed, 11 Jul 2018 05:18:18 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:49143 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbeGKJSO (ORCPT ); Wed, 11 Jul 2018 05:18:14 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M0Qv7-1fvOTt2wnN-00ubJL; Wed, 11 Jul 2018 11:14:48 +0200 From: Arnd Bergmann To: adilger.kernel@dilger.ca Cc: arnd@arndb.de, jack@suse.cz, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, sirmy15@gmail.com, stable@vger.kernel.org, tgnottingham@gmail.com, tytso@mit.edu, y2038@lists.linaro.org Subject: [PATCH v2 1/6] ext4: sysfs: print ext4_super_block fields as little-endian Date: Wed, 11 Jul 2018 11:14:09 +0200 Message-Id: <20180711091414.1494843-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:k96ja8uKs2cKCxeGGBOC7DdqQntq9kxxFt1GvibNWAjl6FnyhOc oGHbX9U/lTfzNyLSYeEqIh8QMmHpWFCDN0fMQod7i990D13JxOiVNwE09hYFzGLsF9Sej8a amVEi7x1dqyLMdUtaRmea0LhEkI/q88GpUwpIlIvICnvTd6Skkf1BJwhz70QyjJZ1YdmYdv z65cQ82y5Ltecb5vKHzhA== X-UI-Out-Filterresults: notjunk:1; V01:K0:XB78hOjXeho=:VUFx62ifQMg9bF/Ofbfhut OS3T9wkUGtA3dTe65iJ3NRV9He4Z6QJb+u4uYT/tGBtshquIjKGXQbaZQjUKVz2wUXdFNR8L/ 0sNOA5nE8UNybHFG+U7svmR3SaPYNoyNYoS4X4QbJTN1YB9E2DpQpafEWaZlBnvjRjMF4V607 UsQuozQcnT3qTHJWAK74bf+2TBZYjudvwKs+091+36bebY+dG3mflqUue1dVrtm/hK5RWYAQJ 4Vry5oNXC0Ir+DekBxHvzWZFX1ozOxABKUKw6T6p6vWO3nHj4yKgtTpRgJjxPR2o1iQFKE4+S rjUnkp7kDDrH7ypPZOEhoohy6Rrydg21t5YMGaea64u3Ic6cOKCWnBY49Iu0DHENoIUU371Gz nm5b/y+E0r3WP47H/FlKG31YkwZFzzCHDR8wsWXHd6973rWgJ7eOaNtae8pKZlRmcv3BbFB/M 4DSlChT/z3R/qjdqdLhveO6F8UuBZRsBxqMuDuz0aeE5hlvJaMmFPIgVRtjA1To+Y3Z972fw5 UNgkHJM4h98ksf4sfT1j34ugITRrmifc0bsMeIhAyAhKfYoJgHKJaLEjuln+L6zP5RsW1zqJe cEGbwoPveN4YX6I8J3SQXurVZj3WnkvOYeAZ0BpwAnNPzChLOF+7wKR68OpeRAUTRlwqN3/Pt sYGFJCmfwvWkhzuCayQOur+XqnuCk4LBrlHz5jQm4zNkX7kzlyG/Yl+MAAJc/yVeSn04= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While working on extended rand for last_error/first_error timestamps, I noticed that the endianess is wrong, we access the little-endian fields in struct ext4_super_block as native-endian when we print them. This adds a special case in ext4_attr_show() and ext4_attr_store() to byteswap the superblock fields if needed. In older kernels, this code was part of super.c, it got moved to sysfs.c in linux-4.4. Cc: stable@vger.kernel.org Fixes: 52c198c6820f ("ext4: add sysfs entry showing whether the fs contains errors") Reviewed-by: Andreas Dilger Signed-off-by: Arnd Bergmann --- fs/ext4/sysfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) -- 2.9.0 diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index f34da0bb8f17..b970a200f20c 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -274,8 +274,12 @@ static ssize_t ext4_attr_show(struct kobject *kobj, case attr_pointer_ui: if (!ptr) return 0; - return snprintf(buf, PAGE_SIZE, "%u\n", - *((unsigned int *) ptr)); + if (a->attr_ptr == ptr_ext4_super_block_offset) + return snprintf(buf, PAGE_SIZE, "%u\n", + le32_to_cpup(ptr)); + else + return snprintf(buf, PAGE_SIZE, "%u\n", + *((unsigned int *) ptr)); case attr_pointer_atomic: if (!ptr) return 0; @@ -308,7 +312,10 @@ static ssize_t ext4_attr_store(struct kobject *kobj, ret = kstrtoul(skip_spaces(buf), 0, &t); if (ret) return ret; - *((unsigned int *) ptr) = t; + if (a->attr_ptr == ptr_ext4_super_block_offset) + *((__le32 *) ptr) = cpu_to_le32(t); + else + *((unsigned int *) ptr) = t; return len; case attr_inode_readahead: return inode_readahead_blks_store(sbi, buf, len); From patchwork Wed Jul 11 09:14:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 141702 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp48418ljj; Wed, 11 Jul 2018 02:15:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdvGmi9BzApWFoGECU4BWt2iNJuVRTuQZPHLXZ+IAwKGgpKSVuL3hUIy1bsc3w2uJdhhK9i X-Received: by 2002:a63:82c7:: with SMTP id w190-v6mr25799995pgd.253.1531300510781; Wed, 11 Jul 2018 02:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300510; cv=none; d=google.com; s=arc-20160816; b=fG9qt/e8X3RC0Kgb38yvlbUjVJARbWXeAyE5STL1z9RYsQRH+EYVpzqornova7ik0f Sf3RPReyi2NXYkLcNupNqk05oBgXz/TDjJ5a9TveGNDC8ZAm10lpGmDVjq1BpD0Xe7ez D/x9ETuCKQWwnoRihNnhWeCxrZSdwmfRRcUJ9pXEhvXdeW+dZbW/3Hs36jp/WFONd8XO H+KOl9LuQKbnePIc13n9Pe0MRX/FZjZ3xVRlncy6CNHHxtHlqORKXifT/CkWSYfpzEZM fGelngSO08OVO/+CXHCJNuKdrHx+sn9szDp5JijAp9EN4Rk76YjQ4hPa1ssVBE5l1ik7 px3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=/P1TWjOKjBYyDOT1AifRhlgIFO6iBwhQfQMQxHuk6ks=; b=ATsNYDiB/gCOBQjLAbGjCBoT4wnGTLehhBGdT9BFJM9ShN+E73ASlW+hIulgXw8DYA 4SofPSGPxv6OdViei4IIwK/sIPBwlv7a6c8/YQjwugXJPtoXkRw7EuksMPwOBz43QD+n Izmo8914asq16rc0rTjpbVuHbjD0klGAwyL/C7c/sCq5zQ7XhPU4JFeAFzoHeSxZgsqd 8SZA24XofSb2UVEKZbVPXl3e7kGwOytQPY6LVFGglwlV24SnfPe0U/8sPOB9P10TXxOH Tn5EyfsyJheX3hfSWe2eocmwm+ildaFiPR/T3MKs/TcMUCWC6jeM1D2qV69a0e13LMi4 9VUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n68-v6si18012962pga.662.2018.07.11.02.15.10; Wed, 11 Jul 2018 02:15:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732540AbeGKJSR (ORCPT + 22 others); Wed, 11 Jul 2018 05:18:17 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:59793 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbeGKJSP (ORCPT ); Wed, 11 Jul 2018 05:18:15 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M8iRY-1fn6qE0aZY-00C9q6; Wed, 11 Jul 2018 11:14:50 +0200 From: Arnd Bergmann To: adilger.kernel@dilger.ca Cc: arnd@arndb.de, jack@suse.cz, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, sirmy15@gmail.com, stable@vger.kernel.org, tgnottingham@gmail.com, tytso@mit.edu, y2038@lists.linaro.org Subject: [PATCH v2 4/6] ext4: use timespec64 for all inode times Date: Wed, 11 Jul 2018 11:14:12 +0200 Message-Id: <20180711091414.1494843-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180711091414.1494843-1-arnd@arndb.de> References: <20180711091414.1494843-1-arnd@arndb.de> X-Provags-ID: V03:K1:btygqJY5XDy41W3h5gSj0JmWcqxhEd25Q38kiD0YBSTilUYitYq /EnuPJjMSqpEx98oUYKuOzgt2pvmFCDHM6wVD0XyV7bjaAlP4vGVqMwqwfrMp9gTkHDxzGN 0COqNN+PY3FTCbmlpDvCwWdvlusZ2Fxrj5vlvGPb0TkFdkJhQqVzOKhFdoeUdzvxnCwcuLv HjYPGXFwWPJ14psvLL7zQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:+nsWJ4ZGs08=:GzMwSZOYFjGKKTG3q/atyy e5I0mCzh/UYJua4yYZRIoMiPZFSDJlyOCMn+vfkW1UTqVkG7tye+XazCE+Y1dDzqC/CqHAYoD ebbYYmCSSqts+1Scyndu57IFKk5cF9GjBS7yiTtK7yWzE3dYjBevZ8yTfNXdhhrIqTTatDqxg YXI2oDAXFyNcWmpz8KMYHJ4KA4fBrCC//AS+EKGcRK4rU5AaAzdGipwh6EuovXU7onh02Bmhc JulK7zvFXRhtO9CK52vDKLOiqBq3dY/BbvZojIy7/kJADevFNJkIBlMFktEdjSzB/WQMOT94p PUi9jI7Pa5Q2JiN4+kydnCOa1yJM1aQn3fQJmWmbuxLXmIAUL0hhCPf2e3cuyaE3Yk/26NpZb XXoqmuVCvs+wPzWCrzUuZrZQhasRYvZ/OLd1xV24YQZdeW+2kQYN8FBvfjxq3f6eqBRfti9ZO bzmK1dwUKNKPl6hCh2Ps8BbcFI4WGmzQ7SpS1ctyJ89lv+pNCaUpw2XdpG6/GRZGqPasE05GD KwnBrsmXPGuIC4QmhCdsJdA35Tbc1Dz1P8IljqVwvoemOOcCA0p28Mi3ffBadADDGbSDy0V3L uU5Of2UuIlSEQ6R9EZ5iMqVLuG6Y0ETlZBeiXWXHTCCYlCmplNJ2FLemRt12C7k4K597jIDTB 93UebVOvzlNwxRmdVXkArkbxJTxFa3rWrKpO84OR0Qe9akoHs7A613wgc++8RqGOf99M= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the last missing piece for the inode times on 32-bit systems: now that VFS interfaces use timespec64, we just need to stop truncating the tv_sec values for y2038 compatibililty. Reviewed-by: Andreas Dilger Signed-off-by: Arnd Bergmann --- fs/ext4/ext4.h | 22 +++++++++------------- fs/ext4/ialloc.c | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) -- 2.9.0 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index d79d1a54a27e..f71ccafe8f9f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -789,17 +789,16 @@ struct move_extent { * affected filesystem before 2242. */ -static inline __le32 ext4_encode_extra_time(struct timespec *time) +static inline __le32 ext4_encode_extra_time(struct timespec64 *time) { - u32 extra = sizeof(time->tv_sec) > 4 ? - ((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK : 0; + u32 extra =((time->tv_sec - (s32)time->tv_sec) >> 32) & EXT4_EPOCH_MASK; return cpu_to_le32(extra | (time->tv_nsec << EXT4_EPOCH_BITS)); } -static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) +static inline void ext4_decode_extra_time(struct timespec64 *time, + __le32 extra) { - if (unlikely(sizeof(time->tv_sec) > 4 && - (extra & cpu_to_le32(EXT4_EPOCH_MASK)))) { + if (unlikely(extra & cpu_to_le32(EXT4_EPOCH_MASK))) { #if 1 /* Handle legacy encoding of pre-1970 dates with epoch @@ -821,9 +820,8 @@ static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra) do { \ (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \ if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) {\ - struct timespec ts = timespec64_to_timespec((inode)->xtime); \ (raw_inode)->xtime ## _extra = \ - ext4_encode_extra_time(&ts); \ + ext4_encode_extra_time(&(inode)->xtime); \ } \ } while (0) @@ -840,10 +838,8 @@ do { \ do { \ (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \ if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) { \ - struct timespec ts = timespec64_to_timespec((inode)->xtime); \ - ext4_decode_extra_time(&ts, \ + ext4_decode_extra_time(&(inode)->xtime, \ raw_inode->xtime ## _extra); \ - (inode)->xtime = timespec_to_timespec64(ts); \ } \ else \ (inode)->xtime.tv_nsec = 0; \ @@ -993,9 +989,9 @@ struct ext4_inode_info { /* * File creation time. Its function is same as that of - * struct timespec i_{a,c,m}time in the generic inode. + * struct timespec64 i_{a,c,m}time in the generic inode. */ - struct timespec i_crtime; + struct timespec64 i_crtime; /* mballoc */ struct list_head i_prealloc_list; diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index fb83750c1a14..18c37c43751c 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1083,7 +1083,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, /* This is the optimal IO size (for stat), not the fs block size */ inode->i_blocks = 0; inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode); - ei->i_crtime = timespec64_to_timespec(inode->i_mtime); + ei->i_crtime = inode->i_mtime; memset(ei->i_data, 0, sizeof(ei->i_data)); ei->i_dir_start_lookup = 0; From patchwork Wed Jul 11 09:14:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 141700 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp48283ljj; Wed, 11 Jul 2018 02:15:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+G5Jm/tYOo5SMOyF3rn/IoDb8P8MIZs0o2IxZyKFSeTTWhyeZf6aCc1e9QsGKhgcEs99W X-Received: by 2002:a63:920c:: with SMTP id o12-v6mr25874220pgd.233.1531300501521; Wed, 11 Jul 2018 02:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300501; cv=none; d=google.com; s=arc-20160816; b=AKaykAPF6WQHG6SlFTC9uUlTK5PSRTgc/JfLnPkAZSFKmmqkFUFCt5nHCTeBTs/N6R uD/jFW8W7L9tfrBHth7xNK27W9Fgt1uhS//Q4VOIX3AJsfYcCLHKOhqx7SRm1VP4/FpK MGUkfXEEPNcJbteCzvEqMRMBztM+Z3g/ceBPmpjr5rEfbZQVN7VlP//JS80Voh7i/8Vz iTFXvMQKZgxtMCVeLsG0i3bkGK+hHIPV2dQVvkW61s+gdaCgsabYhCa5XkAnQ0Gv68yS XTSEgb7zBUnuygbadbikGDnhJ9mpap1fEKRIDgj+YybPCh274GAnXFy6Fg8hy0KFyANE CVNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QaPj4Eh+FpcxMp6t6KzoBhl/hLuWPJgjYhXiJ7RO7cc=; b=bnJUyPl5bvjse5MwyUQoDxfsvzSWVoCNvZnjdPRfyJaq3NIjXaa/cG8JvBSX1Cnn4Y GgXGLA9n1XTMBJSQFEVMwrfHVdunWH1JXD2CcYoPvpENeivaXzq1HX47Y7vjV2wYzuwZ ylvQCBA4l0+815b/ukaGjHzjRM/t20bmJHALZaoJ6dxI3HGaIdoCI9akVBNgEAYxr2qY meFFze0nOpIJU39w104FtNGrbXQvoowtIf4kL97SX9v1nGPUzuryvOXEIzvi3MH81YmZ 3xyhzvfQdkczFLUhL3/xecHohW18D1N1zWXlBxCj7utlsmZ4pzUG0Dpgb48+cZMldm3S LbgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si3056094pgg.75.2018.07.11.02.15.01; Wed, 11 Jul 2018 02:15:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732566AbeGKJSS (ORCPT + 22 others); Wed, 11 Jul 2018 05:18:18 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:36257 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732496AbeGKJSQ (ORCPT ); Wed, 11 Jul 2018 05:18:16 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MI6MY-1fep6K2TB0-003s6C; Wed, 11 Jul 2018 11:14:50 +0200 From: Arnd Bergmann To: adilger.kernel@dilger.ca Cc: arnd@arndb.de, jack@suse.cz, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, sirmy15@gmail.com, stable@vger.kernel.org, tgnottingham@gmail.com, tytso@mit.edu, y2038@lists.linaro.org Subject: [PATCH v2 5/6] jbd2: replace current_kernel_time64 with ktime equivalent Date: Wed, 11 Jul 2018 11:14:13 +0200 Message-Id: <20180711091414.1494843-5-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180711091414.1494843-1-arnd@arndb.de> References: <20180711091414.1494843-1-arnd@arndb.de> X-Provags-ID: V03:K1:cVp0WYR2ZFIdEgbp9PF+Qdqd0SUXDYog7yfsgNUFUmd9mj8u2Cs aGL4HqKtEcPQgTMkfDdVWDNaD4AN2C9Ymm4GdkWPO+05GTFnwidcyCfW3cL3vP8JMO9A4wC cZgpBTsvRsolEphYT0vewKYZMOCzAXOp+ymz019x+Eb5h8cNXy48NcABJtAgyOA2efmRYu4 qmuQZU4q5Y/nqvJFhGaag== X-UI-Out-Filterresults: notjunk:1; V01:K0:d3MQqQdD6FA=:YokxPCv4m6sBog4Pxap2mi IcNPusw86p7AQW0af+5kMQeBMMbLFNvCWWbOjhoxWOQYcO0vl0I/UKc36+NeBvF7bQX75evS/ iUfPkB9HzlKooY8Ln6mENqcLcIhmgPcaxbL2Muuj80Y/ap5EMrcbOZ1weRnPkIXp4MtbGmT98 vBTlxgQlTfIZMbYM86s0YE92TTmrGANq/Ot7y3k0b8QmfGRzidu5wd2CcyL3WUU5sulqR0aaV tF5lyz4H30vRD5Ldf4+HAbZLPSlUAMchrda3kXsTgnhFND0W1KkhGcn0sMThZrDzRlyKQHLSo QO4tOqLq/SI1ENwwNbclLboGiJawK8ERW9uv7q3zo55d+ZFbR0S40aXspMV2nib3sryTxJivG NtLp97AyOLBgVbCSXe0kPuEMaRwGnQgs042wCAbCGls7JegV+M67hlPWEM5+Iz5BlW0NOAZBz WlOPH48mwCYBvaqfxOB0+XZKhfALtzAedh6RLzGY4AnBvav7bmi+Wt2SOMaqwg2gzf/EwoxZA GGbl63vopkyxCjXpFE+ttCp8yrx9Ee91lgWP0URGHRrPgWm1DrdG5lF66a28vU2K6p8ejz/p5 WufSe6JlWsMb6tQb/JTdOk+NCEt04fCfRWHHFl4WnoYLAcku+GWo3/AWdGZp+t/THS4hxiKTt CQpQmvrzrAkw8U0wh3iJPZaMQUDtBw0hUcjLS4eOle+5r5zduu/ZQKIrf0Wj/jmTzTAc= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org jbd2 is one of the few callers of current_kernel_time64(), which is a wrapper around ktime_get_coarse_real_ts64(). This calls the latter directly for consistency with the rest of the kernel that is moving to the ktime_get_ family of time accessors. Reviewed-by: Andreas Dilger Reviewed-by: Jan Kara Signed-off-by: Arnd Bergmann --- fs/jbd2/commit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.9.0 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 8de0e7723316..150cc030b4d7 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -121,7 +121,7 @@ static int journal_submit_commit_record(journal_t *journal, struct commit_header *tmp; struct buffer_head *bh; int ret; - struct timespec64 now = current_kernel_time64(); + struct timespec64 now; *cbh = NULL; @@ -134,6 +134,7 @@ static int journal_submit_commit_record(journal_t *journal, return 1; tmp = (struct commit_header *)bh->b_data; + ktime_get_coarse_real_ts64(&now); tmp->h_commit_sec = cpu_to_be64(now.tv_sec); tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec); From patchwork Wed Jul 11 09:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 141703 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp48576ljj; Wed, 11 Jul 2018 02:15:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeDessoU0fper709U70Hx8yONmyK+W/JQgYkewvT0TdpRNn4FCj52lIBreX/fAqjX3972me X-Received: by 2002:a62:4704:: with SMTP id u4-v6mr29186025pfa.76.1531300522810; Wed, 11 Jul 2018 02:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300522; cv=none; d=google.com; s=arc-20160816; b=JN9K6E4SzJ5fI71ndZ51bmSr4hQqj64kqw4cS1xOq84OXBywXn/+XrI5aMKmOYcele cr7+jR12Q/6rmrDET88cHldL+vsUfpe1aLf2hRJgvFW4iBEYJKwR1n8Ye3Fe0FF2onld Sx48+9ePcRh2xVzKMeV2PF2FtN0/J92gp+A4kfzQXlm3ubY2LzfL6Iwaiabfco6iCIUv M/186Sus9lznlfnftrJQ8qZ7E3M77zydwM1quYNRPYek9ge9p7vZ+giSaVm5ZTwYRY8A SY8gD8j85yXGETYA/bmy//GOgpRMvzS9fB7UIc2INkGyUzu8jrHJV7nAYfcaXw5tIOgP IIiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=ES5ttTo/eVBcwcPzGAWv3k7NxjYucZsMWiW0O4FCBNI=; b=iRzdmLV4uWQQQEBxH8N48Jap4X0CmWnDoH7GgRckYU3jYnK5tnt+L6wcnV53QfjM7w PFeH6opESHPCwV3tPSuT+rtRFa1dYlD7N4bNkGFEQf9zs3ggEJQk7O/Bt58BmMGWJGbt I/tO2QSt/x8jXlQ4YVWORBN5p1usycuXMeee7jxPYuqEkbK+QODyjqmOKn9Yc4W85NrA 5KCFj4ICTxUtsLc9WXlDvomYJ3E/SdcYhXbOHOxpdmwF9OzMtse8b7FLNRcIshItyVVB WQxtENpgcNfaiG6YWQmoZnTAiBd6W6I9kbBNziFAMLHm9V0lydEYjKcs4JcSMmj25UXh JlqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23-v6si20659232plj.494.2018.07.11.02.15.22; Wed, 11 Jul 2018 02:15:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732579AbeGKJSk (ORCPT + 22 others); Wed, 11 Jul 2018 05:18:40 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:46595 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732495AbeGKJSQ (ORCPT ); Wed, 11 Jul 2018 05:18:16 -0400 Received: from wuerfel.lan ([46.223.138.35]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LbItu-1gNoR70C1y-00kwA0; Wed, 11 Jul 2018 11:14:51 +0200 From: Arnd Bergmann To: adilger.kernel@dilger.ca Cc: arnd@arndb.de, jack@suse.cz, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, sirmy15@gmail.com, stable@vger.kernel.org, tgnottingham@gmail.com, tytso@mit.edu, y2038@lists.linaro.org Subject: [PATCH v2 6/6] ext4: super: extend timestamps to 40 bits Date: Wed, 11 Jul 2018 11:14:14 +0200 Message-Id: <20180711091414.1494843-6-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20180711091414.1494843-1-arnd@arndb.de> References: <20180711091414.1494843-1-arnd@arndb.de> X-Provags-ID: V03:K1:20Wchcr3kLso94smYgixxLckDSeH2idv+oOepEOCqYyI9iQpkjn BebCENWmuw08kHSrBOPapDRRdQm7QaV4umeaJuTFUHpQgawkRENkPQx32hocvtHokSrjuwG 8Zd+yF5ElZkjR2TXQcK+2kmPAVigtIwz+afz/l+vIBDd/D3QCP+m8HnwMENbHWG+U6upfxU Zq8Rmuqc80A7hBai6VYbg== X-UI-Out-Filterresults: notjunk:1; V01:K0:uI8gAj6IHnI=:POsO6RWEndsVb7ad646Y/l Zk+E57bZ0mM0Ef4O4qGAqbn/8D2abArfwO5CZuhdiHBhpQD2vGcXljHrNnGiqhpX9qkWCSVyM iG78YN5oh2vP6KBjeAOnoJaD/cxuAjWGvrDhwxlXgUKrbowbPMaWa+FXG8oE/GZERBxbT5sdE H5xxuaz0ptMcC318hZhIraVNIjaijHL5tIkynx404F16SLRFoXB9bh/5UHnMSpagktE4HMJxc nuJdVjUujCCvhJbdQz0sPzRLuNN5fKKvMVh8TqDHzdLO5ipU9Rql1cn7tNYos73y06jQmrTSL ZWLlE4W14TAK9vi/9uLIQWCA6aiGiiPpky+EyZeyTqiLgo9vGxkqZBYe6cqeEL0j0dwjdniG2 AWhJ813YR/3KUzH+SPuU3Qj/1OWSzP6RMEHnLXf6HD6b4+BOs+4TxjmcEsqVIEfyE8q/0qlRf Z/cXQSKZyeXIP3xwPeD1IydUaDgDKhc/0WzXVplsY5BrqdDrZcmAcr0j9nHXNHsEmjDCvj8PY YH5MUYC/aZ4Bti731DsQiTJNNEWoeTfnVKWGuBEWl9gMIUiLACLMHM08Lew1Z0dUOFFivMkZj xtSHbqXK0y4JSdJDJRmI0SoKfwiMCHmPP8otxVjQT9iLTcwkqp86olTvSYyKevTjsAoPyIOnI fMPntocDStNdyaPqdTZPpPicmAXbnNLU9l863iLAicqGGSuGNgDYHmCvi6Ia58YSTy9o= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The inode timestamps use 34 bits in ext4, but the various timestamps in the superblock are limited to 32 bits. If every user accesses these as 'unsigned', then this is good until year 2106, but it seems better to extend this a bit further in the process of removing the deprecated get_seconds() function. This adds another byte for each timestamp in the superblock, making them long enough to store timestamps beyond what is in the inodes, which seems good enough here (in ocfs2, they are already 64-bit wide, which is appropriate for a new layout). I did not modify e2fsprogs, which obviously needs the same change to actually interpret future timestamps correctly. Signed-off-by: Arnd Bergmann --- v2: drop 'RFC' from subject minor changes as suggested by Andreas Dilger --- fs/ext4/ext4.h | 9 ++++++++- fs/ext4/super.c | 39 ++++++++++++++++++++++++++++++--------- fs/ext4/sysfs.c | 19 +++++++++++++++++-- 3 files changed, 55 insertions(+), 12 deletions(-) -- 2.9.0 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index f71ccafe8f9f..3ee9f198c698 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1295,7 +1295,14 @@ struct ext4_super_block { __le32 s_lpf_ino; /* Location of the lost+found inode */ __le32 s_prj_quota_inum; /* inode for tracking project quota */ __le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */ - __le32 s_reserved[98]; /* Padding to the end of the block */ + __u8 s_wtime_hi; + __u8 s_mtime_hi; + __u8 s_mkfs_time_hi; + __u8 s_lastcheck_hi; + __u8 s_first_error_time_hi; + __u8 s_last_error_time_hi; + __u8 s_pad[2]; + __le32 s_reserved[96]; /* Padding to the end of the block */ __le32 s_checksum; /* crc32c(superblock) */ }; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 86e3d13787e6..aaf29e3981db 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -313,6 +313,24 @@ void ext4_itable_unused_set(struct super_block *sb, bg->bg_itable_unused_hi = cpu_to_le16(count >> 16); } +static void __ext4_update_tstamp(__le32 *lo, __u8 *hi) +{ + time64_t now = ktime_get_real_seconds(); + + now = clamp_val(now, 0, (1ull << 40) - 1); + + *lo = cpu_to_le32(lower_32_bits(now)); + *hi = upper_32_bits(now); +} + +static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi) +{ + return ((time64_t)(*hi) << 32) + le32_to_cpu(*lo); +} +#define ext4_update_tstamp(es, tstamp) \ + __ext4_update_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi) +#define ext4_get_tstamp(es, tstamp) \ + __ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi) static void __save_error_info(struct super_block *sb, const char *func, unsigned int line) @@ -323,11 +341,12 @@ static void __save_error_info(struct super_block *sb, const char *func, if (bdev_read_only(sb->s_bdev)) return; es->s_state |= cpu_to_le16(EXT4_ERROR_FS); - es->s_last_error_time = cpu_to_le32(get_seconds()); + ext4_update_tstamp(es, s_last_error_time); strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func)); es->s_last_error_line = cpu_to_le32(line); if (!es->s_first_error_time) { es->s_first_error_time = es->s_last_error_time; + es->s_first_error_time_hi = es->s_last_error_time_hi; strncpy(es->s_first_error_func, func, sizeof(es->s_first_error_func)); es->s_first_error_line = cpu_to_le32(line); @@ -2175,8 +2194,8 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, "warning: maximal mount count reached, " "running e2fsck is recommended"); else if (le32_to_cpu(es->s_checkinterval) && - (le32_to_cpu(es->s_lastcheck) + - le32_to_cpu(es->s_checkinterval) <= get_seconds())) + (ext4_get_tstamp(es, s_lastcheck) + + le32_to_cpu(es->s_checkinterval) <= ktime_get_real_seconds())) ext4_msg(sb, KERN_WARNING, "warning: checktime reached, " "running e2fsck is recommended"); @@ -2185,7 +2204,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); le16_add_cpu(&es->s_mnt_count, 1); - es->s_mtime = cpu_to_le32(get_seconds()); + ext4_update_tstamp(es, s_mtime); ext4_update_dynamic_rev(sb); if (sbi->s_journal) ext4_set_feature_journal_needs_recovery(sb); @@ -2876,8 +2895,9 @@ static void print_daily_error_info(struct timer_list *t) ext4_msg(sb, KERN_NOTICE, "error count since last fsck: %u", le32_to_cpu(es->s_error_count)); if (es->s_first_error_time) { - printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %u: %.*s:%d", - sb->s_id, le32_to_cpu(es->s_first_error_time), + printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %llu: %.*s:%d", + sb->s_id, + ext4_get_tstamp(es, s_first_error_time), (int) sizeof(es->s_first_error_func), es->s_first_error_func, le32_to_cpu(es->s_first_error_line)); @@ -2890,8 +2910,9 @@ static void print_daily_error_info(struct timer_list *t) printk(KERN_CONT "\n"); } if (es->s_last_error_time) { - printk(KERN_NOTICE "EXT4-fs (%s): last error at time %u: %.*s:%d", - sb->s_id, le32_to_cpu(es->s_last_error_time), + printk(KERN_NOTICE "EXT4-fs (%s): last error at time %llu: %.*s:%d", + sb->s_id, + ext4_get_tstamp(es, s_last_error_time), (int) sizeof(es->s_last_error_func), es->s_last_error_func, le32_to_cpu(es->s_last_error_line)); @@ -4822,7 +4843,7 @@ static int ext4_commit_super(struct super_block *sb, int sync) * to complain and force a full file system check. */ if (!(sb->s_flags & SB_RDONLY)) - es->s_wtime = cpu_to_le32(get_seconds()); + ext4_update_tstamp(es, s_wtime); if (sb->s_bdev->bd_part) es->s_kbytes_written = cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index b970a200f20c..e60cc5e89023 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -25,6 +25,8 @@ typedef enum { attr_reserved_clusters, attr_inode_readahead, attr_trigger_test_error, + attr_first_error_time, + attr_last_error_time, attr_feature, attr_pointer_ui, attr_pointer_atomic, @@ -182,8 +184,8 @@ EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst); EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval); EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst); EXT4_RO_ATTR_ES_UI(errors_count, s_error_count); -EXT4_RO_ATTR_ES_UI(first_error_time, s_first_error_time); -EXT4_RO_ATTR_ES_UI(last_error_time, s_last_error_time); +EXT4_ATTR(first_error_time, 0444, first_error_time); +EXT4_ATTR(last_error_time, 0444, last_error_time); static unsigned int old_bump_val = 128; EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); @@ -249,6 +251,15 @@ static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi) return NULL; } +static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) +{ + return snprintf(buf, PAGE_SIZE, "%lld", + ((time64_t)hi << 32) + le32_to_cpu(lo)); +} + +#define print_tstamp(buf, es, tstamp) \ + __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi) + static ssize_t ext4_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { @@ -287,6 +298,10 @@ static ssize_t ext4_attr_show(struct kobject *kobj, atomic_read((atomic_t *) ptr)); case attr_feature: return snprintf(buf, PAGE_SIZE, "supported\n"); + case attr_first_error_time: + return print_tstamp(buf, sbi->s_es, s_first_error_time); + case attr_last_error_time: + return print_tstamp(buf, sbi->s_es, s_last_error_time); } return 0;