From patchwork Tue Oct 1 10:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 13817775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 008F7CE7D13 for ; Tue, 1 Oct 2024 10:59:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830C7280072; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78D1A280068; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59238280072; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1A5D2280068 for ; Tue, 1 Oct 2024 06:59:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D0A7481064 for ; Tue, 1 Oct 2024 10:59:18 +0000 (UTC) X-FDA: 82624736796.04.9030648 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf16.hostedemail.com (Postfix) with ESMTP id 1BD80180007 for ; Tue, 1 Oct 2024 10:59:16 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RKj3yhF+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727780263; a=rsa-sha256; cv=none; b=wfsUvZ2kr74FRL9MxN3s4gwXbdmDevbVTmoWB1NeToTVdloo4nGGusKU7ggbjsbStnwZnh +ljBWbGA0Ro7UZEzFjWRh06aaKrshbMZ3bIrImQiSEzyfPnDMdXv4fHan58KWB7L4Yzwyw osLM8OSvsx4Yu9AOEduUaZ3XSGs/3a4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RKj3yhF+; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of jlayton@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=jlayton@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727780263; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yiUOK3rTw35TZrDDtW4Dy9XZk4oh8mUxmZIeN6Z2Fj8=; b=KS3Gnf2gJtpuVYvPrcVnaF6tzCcakhq/+bGMgOWukCAQ7nBCBrMVXiiFCjSTU+LC/QbM4B MYxtBeC7qKBQOAbwZ2X+1hKtxSOuAswRHtgKEn0ehGoRetbTKXvzaXZr+v9bt6zPFMJEKp 5Hsat27Ig92obRT7Zvci5Mr4OacZWg0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 198E8A434E3; Tue, 1 Oct 2024 10:59:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DCE5C4CED2; Tue, 1 Oct 2024 10:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727780356; bh=aZAy0l7/4k2LGVLomi5Ve4y/LL6QUr6Sx2B+lukvqM0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RKj3yhF+oyStx9Ni6wvM47DBmMhesTGtSCcVZdAfTR4yHvS0WANQ3nvJpFYGtLuhE 8CTbi5m0FG5JDzr6TH+WHBA87ZeoNTTbCpdM276nOUd/nyewrZqFz42lu2WwJU7myQ yocbQsn859y/ddxiV1KGzbca9l+PW9WxNG15zleyD+i2DYRfLODpBXMxVxxWXnEBzO pEPRO9f+Y6NHr2MTh028YXXoS1+bFDYVbocP0/8x5kGDbe55/50Aa2PPptcQmptjno m/1eK26LozQyaAgmrbp4I06xI/IShYV+wcnvmxH5K+Rdr9UIvD26hxRx5n4DoA/jf9 7Khcg74ufAZSg== From: Jeff Layton Date: Tue, 01 Oct 2024 06:58:56 -0400 Subject: [PATCH v8 02/12] fs: add infrastructure for multigrain timestamps MIME-Version: 1.0 Message-Id: <20241001-mgtime-v8-2-903343d91bc3@kernel.org> References: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> In-Reply-To: <20241001-mgtime-v8-0-903343d91bc3@kernel.org> To: John Stultz , Thomas Gleixner , Stephen Boyd , Alexander Viro , Christian Brauner , Jan Kara , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jonathan Corbet , Randy Dunlap , Chandan Babu R , "Darrick J. Wong" , Theodore Ts'o , Andreas Dilger , Chris Mason , Josef Bacik , David Sterba , Hugh Dickins , Andrew Morton , Chuck Lever , Vadim Fedorenko Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=13860; i=jlayton@kernel.org; h=from:subject:message-id; bh=aZAy0l7/4k2LGVLomi5Ve4y/LL6QUr6Sx2B+lukvqM0=; b=kA0DAAgBAA5oQRlWghUByyZiAGb71fmhaxnBnt3uu+eWAn3QZ18UG7uIL1EaKhEmH/OooHjaT okCMwQAAQgAHRYhBEvA17JEcbKhhOr10wAOaEEZVoIVBQJm+9X5AAoJEAAOaEEZVoIVSf8QAM+g MP18mwnri8/J0NBz/aWBjcV49FmVxqQWT1SKFUxkr+SiCkdR95yiZrA6HxJKjmG33TwqtYE1xxy jE5MmASJRwNH6eYdcVLzA0HCE+8E8NOQxC7oftNAnRUGVoXbKGK917J3R7CWKt3m9HH2hKMhpvN eW5V0+jP46fcviUwwmn/Hsbqd1ZkfKRsxNXLF8oj9wzYaKQPqLshJOrJXZdnQ8vfsnrj1DCMTtL aDl8K3fIrKV4iuwX87XGp+MuIk30uG7aP/F8n79JcjuW/iHCQXhzKbXGxR0kQGCWKVRerRgry7o RBoX25Sp5bSmIyssXym+CCp3veoq9SNx1l6Pv4EjdpvXr8jwESXNwE7eTrbQxhpPbXJ7P22ZvrF pSY6FpesmwMvkBYuq9SO1ke0GlgGfhtGUYy12PBhsO4wQWGcLHII9K+4EQeuPxDf6BxrgsXsOYj t38h1Ag63T5oSCVrEUCntMTTwCdf2dXv05RKGNyOMAxdsoydC4H8+/YLoBI6zVwvbT1qXUBzg2F nUrepXFfsDgWtVXvjGIAhVvOz4Zhfq9F9Q+taMn7ECNfVAGnFdBF5e74PZVg137ChVusDy4SXfN IdcZiZpHU36/BrIij7yRtN+XpQhbFUhdhPHRC6nz3idRe6Y2lCsqTPVpqyy+tFA9mBlSl/QNjTL pIj6H X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-Rspamd-Queue-Id: 1BD80180007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: g868dt6eksb9yfr3ebjtpe7hsaac9dgw X-HE-Tag: 1727780356-285665 X-HE-Meta: U2FsdGVkX19Iq9MzHdR7wXBSFbh13mFM3qqR8rRed2kUDsWYzOXqUGk4fH/TiyOKxqEDOMtDeh8bW9G3dJxFf1fNl5WHHzj+k0HPfg9m0LsNPted//e/u6HO48kOr/PszEvXg9VyH0rgRUOfGaOTuzu2Jh4DGZihMt03jLZRFmNwSdB06hs7H//XbxIpxfAbpRVQhHgRGPT6Ap9lPWz763tNDKF7UlYredXLtBl6LJk4hvHW/YzY4Wo7gC8JsuDxeFgZIOj8/6TUXNtXv+xbxU1D50GGyV/tC8FoTMOj+5xKAwgpfvOZFnfwse7aN5egrDUDTDCFeSuiTxv/8vQ1wyOGLsYoxcGWRsdkOapRgLMtZZklklcNdvZPOx7dMMNEmwOeU0FD36sFMZ5j00pJMv62NjDYK1pGvv1bRnM2yyvFJ2zeUodJ4QlrKVTB8CRSsisUtLBtcMEu9ZXRJix6G+PTQ/53KO13K1+6DcKcolRn3b74CwYo677JnBP9E1Kofxf40wRdSCMvIVy9BwAukSK6NJvEK2oOxEas9acGvT9uxbP5O4EQY9k2R2caHi1ZiK3NfaN2wU9ff8xI/HMkQ0RpuMlyFCF5agV9WTWJrL/dF+TjFODd5adNv/fE1JjF878A+l5Cpmb6QrZH2E/xaKGnXIMQc73Jt35KqNOsFVEOZax1or3TNbkLr4wIuR+/LWCYrHvin12iG4PZK5F+MBMG7td1QZSw+Il+AulpWuZDkddonDIOUwsvWfcaaHRuN671hzw7vqfenofFWpGPZJOjbJpaegk3T9RH7za9qGNpzzf7xCDMFfJ6zgsApwQ+Zy8CKT/+c7D4HHK+bjZnQE0nxD5pY/jsHrmjEFkGRu+asGPtZ10koTZ+R6ZpjzLCjEX7pp1GN85FQxLC4273CPFIN42LPKCijdBQCzhbvysphK1vdHefhYX5r6YJSI929dByi6wj9ziBWBhgety E8M2QpSw ZVS9TSlaCLGzTdyqK7pHo20PvJHrX2CZoITjKivWqYvgOfR9FbxAgtgsDZYBgfOa/eRXgLZOiOjfHegB6pQG4mp/32cVUzkxRALgBk89kJQ7j6EW3OaggyLoNnHpkalaSZUnkYLWu3XVdNgEjH7YWY30hVTzoGdJ2xRp513Mn5Mc8uVPSNxIizfakhVNpy6MMQ5WHiGnC9tI2wPtrTPx+3rxF0sMZkYU2r4CudbLTHWcgYM2oqzpAEl69VfoudLB6JEdc9Lbt2XFuwOSDG8JXV29KaZeRGfRZQOjIQoCdOp6aV9wvnoyHuqdqPQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The VFS has always used coarse-grained timestamps when updating the ctime and mtime after a change. This has the benefit of allowing filesystems to optimize away a lot metadata updates, down to around 1 per jiffy, even when a file is under heavy writes. Unfortunately, this has always been an issue when we're exporting via NFSv3, which relies on timestamps to validate caches. A lot of changes can happen in a jiffy, so timestamps aren't sufficient to help the client decide when to invalidate the cache. Even with NFSv4, a lot of exported filesystems don't properly support a change attribute and are subject to the same problems with timestamp granularity. Other applications have similar issues with timestamps (e.g backup applications). If we were to always use fine-grained timestamps, that would improve the situation, but that becomes rather expensive, as the underlying filesystem would have to log a lot more metadata updates. What we need is a way to only use fine-grained timestamps when they are being actively queried. Use the (unused) top bit in inode->i_ctime_nsec as a flag that indicates whether the current timestamps have been queried via stat() or the like. When it's set, we allow the kernel to use a fine-grained timestamp iff it's necessary to make the ctime show a different value. This solves the problem of being able to distinguish the timestamp between updates, but introduces a new problem: it's now possible for a file being changed to get a fine-grained timestamp. A file that is altered just a bit later can then get a coarse-grained one that appears older than the earlier fine-grained time. This violates timestamp ordering guarantees. To remedy this, keep a global monotonic atomic64_t value that acts as a timestamp floor. When we go to stamp a file, we first get the latter of the current floor value and the current coarse-grained time. If the inode ctime hasn't been queried then we just attempt to stamp it with that value. If it has been queried, then first see whether the current coarse time is later than the existing ctime. If it is, then we accept that value. If it isn't, then we get a fine-grained timestamp. Filesystems can opt into this by setting the FS_MGTIME fstype flag. Others should be unaffected (other than being subject to the same floor value as multigrain filesystems). Tested-by: Randy Dunlap # documentation bits Signed-off-by: Jeff Layton Reviewed-by: Jan Kara --- fs/inode.c | 137 +++++++++++++++++++++++++++++++++++++++++++---------- fs/stat.c | 39 ++++++++++++++- include/linux/fs.h | 34 +++++++++---- 3 files changed, 175 insertions(+), 35 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 471ae4a31549..4ec1e71e9a9d 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2209,19 +2209,58 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); +/** + * current_time - Return FS time (possibly fine-grained) + * @inode: inode. + * + * Return the current time truncated to the time granularity supported by + * the fs, as suitable for a ctime/mtime change. If the ctime is flagged + * as having been QUERIED, get a fine-grained timestamp, but don't update + * the floor. + * + * For a multigrain inode, this is effectively an estimate of the timestamp + * that a file would receive. An actual update must go through + * inode_set_ctime_current(). + */ +struct timespec64 current_time(struct inode *inode) +{ + struct timespec64 now; + u32 cns; + + ktime_get_coarse_real_ts64_mg(&now); + + if (!is_mgtime(inode)) + goto out; + + /* If nothing has queried it, then coarse time is fine */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + /* + * If there is no apparent change, then get a fine-grained + * timestamp. + */ + if (now.tv_nsec == (cns & ~I_CTIME_QUERIED)) + ktime_get_real_ts64(&now); + } +out: + return timestamp_truncate(now, inode); +} +EXPORT_SYMBOL(current_time); + static int inode_needs_update_time(struct inode *inode) { + struct timespec64 now, ts; int sync_it = 0; - struct timespec64 now = current_time(inode); - struct timespec64 ts; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; + now = current_time(inode); + ts = inode_get_mtime(inode); if (!timespec64_equal(&ts, &now)) - sync_it = S_MTIME; + sync_it |= S_MTIME; ts = inode_get_ctime(inode); if (!timespec64_equal(&ts, &now)) @@ -2598,6 +2637,15 @@ void inode_nohighmem(struct inode *inode) } EXPORT_SYMBOL(inode_nohighmem); +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts) +{ + set_normalized_timespec64(&ts, ts.tv_sec, ts.tv_nsec); + inode->i_ctime_sec = ts.tv_sec; + inode->i_ctime_nsec = ts.tv_nsec; + return ts; +} +EXPORT_SYMBOL(inode_set_ctime_to_ts); + /** * timestamp_truncate - Truncate timespec to a granularity * @t: Timespec @@ -2630,36 +2678,75 @@ struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode) EXPORT_SYMBOL(timestamp_truncate); /** - * current_time - Return FS time - * @inode: inode. + * inode_set_ctime_current - set the ctime to current_time + * @inode: inode * - * Return the current time truncated to the time granularity supported by - * the fs. + * Set the inode's ctime to the current value for the inode. Returns the + * current value that was assigned. If this is not a multigrain inode, then we + * set it to the later of the coarse time and floor value. * - * Note that inode and inode->sb cannot be NULL. - * Otherwise, the function warns and returns time without truncation. + * If it is multigrain, then we first see if the coarse-grained timestamp is + * distinct from what we have. If so, then we'll just use that. If we have to + * get a fine-grained timestamp, then do so, and try to swap it into the floor. + * We accept the new floor value regardless of the outcome of the cmpxchg. + * After that, we try to swap the new value into i_ctime_nsec. Again, we take + * the resulting ctime, regardless of the outcome of the swap. */ -struct timespec64 current_time(struct inode *inode) +struct timespec64 inode_set_ctime_current(struct inode *inode) { struct timespec64 now; + u32 cns, cur; - ktime_get_coarse_real_ts64(&now); - return timestamp_truncate(now, inode); -} -EXPORT_SYMBOL(current_time); + ktime_get_coarse_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); -/** - * inode_set_ctime_current - set the ctime to current_time - * @inode: inode - * - * Set the inode->i_ctime to the current value for the inode. Returns - * the current value that was assigned to i_ctime. - */ -struct timespec64 inode_set_ctime_current(struct inode *inode) -{ - struct timespec64 now = current_time(inode); + /* Just return that if this is not a multigrain fs */ + if (!is_mgtime(inode)) { + inode_set_ctime_to_ts(inode, now); + goto out; + } - inode_set_ctime_to_ts(inode, now); + /* + * We only need a fine-grained time if someone has queried it, + * and the current coarse grained time isn't later than what's + * already there. + */ + cns = smp_load_acquire(&inode->i_ctime_nsec); + if (cns & I_CTIME_QUERIED) { + struct timespec64 ctime = { .tv_sec = inode->i_ctime_sec, + .tv_nsec = cns & ~I_CTIME_QUERIED }; + + if (timespec64_compare(&now, &ctime) <= 0) { + ktime_get_real_ts64_mg(&now); + now = timestamp_truncate(now, inode); + } + } + + /* No need to cmpxchg if it's exactly the same */ + if (cns == now.tv_nsec && inode->i_ctime_sec == now.tv_sec) + goto out; + cur = cns; +retry: + /* Try to swap the nsec value into place. */ + if (try_cmpxchg(&inode->i_ctime_nsec, &cur, now.tv_nsec)) { + /* If swap occurred, then we're (mostly) done */ + inode->i_ctime_sec = now.tv_sec; + } else { + /* + * Was the change due to someone marking the old ctime QUERIED? + * If so then retry the swap. This can only happen once since + * the only way to clear I_CTIME_QUERIED is to stamp the inode + * with a new ctime. + */ + if (!(cns & I_CTIME_QUERIED) && (cns | I_CTIME_QUERIED) == cur) { + cns = cur; + goto retry; + } + /* Otherwise, keep the existing ctime */ + now.tv_sec = inode->i_ctime_sec; + now.tv_nsec = cur & ~I_CTIME_QUERIED; + } +out: return now; } EXPORT_SYMBOL(inode_set_ctime_current); diff --git a/fs/stat.c b/fs/stat.c index 41e598376d7e..381926fb405f 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -26,6 +26,35 @@ #include "internal.h" #include "mount.h" +/** + * fill_mg_cmtime - Fill in the mtime and ctime and flag ctime as QUERIED + * @stat: where to store the resulting values + * @request_mask: STATX_* values requested + * @inode: inode from which to grab the c/mtime + * + * Given @inode, grab the ctime and mtime out if it and store the result + * in @stat. When fetching the value, flag it as QUERIED (if not already) + * so the next write will record a distinct timestamp. + */ +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode) +{ + atomic_t *pcn = (atomic_t *)&inode->i_ctime_nsec; + + /* If neither time was requested, then don't report them */ + if (!(request_mask & (STATX_CTIME|STATX_MTIME))) { + stat->result_mask &= ~(STATX_CTIME|STATX_MTIME); + return; + } + + stat->mtime = inode_get_mtime(inode); + stat->ctime.tv_sec = inode->i_ctime_sec; + stat->ctime.tv_nsec = (u32)atomic_read(pcn); + if (!(stat->ctime.tv_nsec & I_CTIME_QUERIED)) + stat->ctime.tv_nsec = ((u32)atomic_fetch_or(I_CTIME_QUERIED, pcn)); + stat->ctime.tv_nsec &= ~I_CTIME_QUERIED; +} +EXPORT_SYMBOL(fill_mg_cmtime); + /** * generic_fillattr - Fill in the basic attributes from the inode struct * @idmap: idmap of the mount the inode was found from @@ -58,8 +87,14 @@ void generic_fillattr(struct mnt_idmap *idmap, u32 request_mask, stat->rdev = inode->i_rdev; stat->size = i_size_read(inode); stat->atime = inode_get_atime(inode); - stat->mtime = inode_get_mtime(inode); - stat->ctime = inode_get_ctime(inode); + + if (is_mgtime(inode)) { + fill_mg_cmtime(stat, request_mask, inode); + } else { + stat->ctime = inode_get_ctime(inode); + stat->mtime = inode_get_mtime(inode); + } + stat->blksize = i_blocksize(inode); stat->blocks = inode->i_blocks; diff --git a/include/linux/fs.h b/include/linux/fs.h index e3c603d01337..23908bad166c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1653,6 +1653,17 @@ static inline struct timespec64 inode_set_mtime(struct inode *inode, return inode_set_mtime_to_ts(inode, ts); } +/* + * Multigrain timestamps + * + * Conditionally use fine-grained ctime and mtime timestamps when there + * are users actively observing them via getattr. The primary use-case + * for this is NFS clients that use the ctime to distinguish between + * different states of the file, and that are often fooled by multiple + * operations that occur in the same coarse-grained timer tick. + */ +#define I_CTIME_QUERIED ((u32)BIT(31)) + static inline time64_t inode_get_ctime_sec(const struct inode *inode) { return inode->i_ctime_sec; @@ -1660,7 +1671,7 @@ static inline time64_t inode_get_ctime_sec(const struct inode *inode) static inline long inode_get_ctime_nsec(const struct inode *inode) { - return inode->i_ctime_nsec; + return inode->i_ctime_nsec & ~I_CTIME_QUERIED; } static inline struct timespec64 inode_get_ctime(const struct inode *inode) @@ -1671,13 +1682,7 @@ static inline struct timespec64 inode_get_ctime(const struct inode *inode) return ts; } -static inline struct timespec64 inode_set_ctime_to_ts(struct inode *inode, - struct timespec64 ts) -{ - inode->i_ctime_sec = ts.tv_sec; - inode->i_ctime_nsec = ts.tv_nsec; - return ts; -} +struct timespec64 inode_set_ctime_to_ts(struct inode *inode, struct timespec64 ts); /** * inode_set_ctime - set the ctime in the inode @@ -2542,6 +2547,7 @@ struct file_system_type { #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ +#define FS_MGTIME 64 /* FS uses multigrain timestamps */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; @@ -2565,6 +2571,17 @@ struct file_system_type { #define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME) +/** + * is_mgtime: is this inode using multigrain timestamps + * @inode: inode to test for multigrain timestamps + * + * Return true if the inode uses multigrain timestamps, false otherwise. + */ +static inline bool is_mgtime(const struct inode *inode) +{ + return inode->i_sb->s_type->fs_flags & FS_MGTIME; +} + extern struct dentry *mount_bdev(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, int (*fill_super)(struct super_block *, void *, int)); @@ -3321,6 +3338,7 @@ extern void page_put_link(void *); extern int page_symlink(struct inode *inode, const char *symname, int len); extern const struct inode_operations page_symlink_inode_operations; extern void kfree_link(void *); +void fill_mg_cmtime(struct kstat *stat, u32 request_mask, struct inode *inode); void generic_fillattr(struct mnt_idmap *, u32, struct inode *, struct kstat *); void generic_fill_statx_attr(struct inode *inode, struct kstat *stat); void generic_fill_statx_atomic_writes(struct kstat *stat,