From patchwork Fri May 20 18:36:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12857272 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 2BCE0C43219 for ; Fri, 20 May 2022 18:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEB348D0007; Fri, 20 May 2022 14:37:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A775F8D0001; Fri, 20 May 2022 14:37:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C5DE8D0007; Fri, 20 May 2022 14:37:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 780568D0001 for ; Fri, 20 May 2022 14:37:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 5274F81A45 for ; Fri, 20 May 2022 18:37:50 +0000 (UTC) X-FDA: 79486980300.24.B6CD21B Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf16.hostedemail.com (Postfix) with ESMTP id 8100F180013 for ; Fri, 20 May 2022 18:37:37 +0000 (UTC) Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 24KHSSLq022515 for ; Fri, 20 May 2022 11:37:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=4Gs4vhLGOpR5fcqmlVRzzwre6v2yRJXtVCNsF05UpCw=; b=piBNszL9xwhOP650YDcXtZMudcup701DSRWDsZyjXfYZDZRSeD/kD0RLr/nYfZ1Nonq4 +UHo0MRzqFrB7TX1uKCZDhWxUMyZ4Ry1/FrQH9Wj0/TR+Twls829cKZoqIBYCAgB+irI g0uSBPUp9TyPVvZ7sNNcJf67L+XUiBnCPPk= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net (PPS) with ESMTPS id 3g6bja2ayx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 20 May 2022 11:37:49 -0700 Received: from twshared11660.23.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 20 May 2022 11:37:48 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 94D73F5E5B33; Fri, 20 May 2022 11:37:16 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , Subject: [RFC PATCH v4 10/17] fs: Split off file_needs_update_time and __file_update_time Date: Fri, 20 May 2022 11:36:39 -0700 Message-ID: <20220520183646.2002023-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220520183646.2002023-1-shr@fb.com> References: <20220520183646.2002023-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: QxcSgrS-dl3a5a_GTyVX6Re84tOPhNm_ X-Proofpoint-ORIG-GUID: QxcSgrS-dl3a5a_GTyVX6Re84tOPhNm_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_05,2022-05-20_02,2022-02-23_01 Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=piBNszL9; spf=none (imf16.hostedemail.com: domain of "prvs=6139886598=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=6139886598=shr@fb.com"; dmarc=pass (policy=reject) header.from=fb.com X-Rspam-User: X-Stat-Signature: t46r5m6y8em5rkft49nkdkcgxex7fd9w X-Rspamd-Queue-Id: 8100F180013 X-Rspamd-Server: rspam01 X-HE-Tag: 1653071857-609929 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: This splits off the functions file_needs_update_time() and __file_update_time() from the function file_update_time(). This is required to support async buffered writes. No intended functional changes in this patch. Signed-off-by: Stefan Roesch --- fs/inode.c | 75 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 1bb8b7db836f..4bb7f583cc6b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2059,35 +2059,19 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); -/** - * file_update_time - update mtime and ctime time - * @file: file accessed - * - * Update the mtime and ctime members of an inode and mark the inode - * for writeback. Note that this function is meant exclusively for - * usage in the file write path of filesystems, and filesystems may - * choose to explicitly ignore update via this function with the - * S_NOCMTIME inode flag, e.g. for network filesystem where these - * timestamps are handled by the server. This can return an error for - * file systems who need to allocate space in order to update an inode. - */ - -int file_update_time(struct file *file) +static int file_needs_update_time(struct inode *inode, struct file *file, + struct timespec64 *now) { - struct inode *inode = file_inode(file); - struct timespec64 now; int sync_it = 0; - int ret; /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; - now = current_time(inode); - if (!timespec64_equal(&inode->i_mtime, &now)) + if (!timespec64_equal(&inode->i_mtime, now)) sync_it = S_MTIME; - if (!timespec64_equal(&inode->i_ctime, &now)) + if (!timespec64_equal(&inode->i_ctime, now)) sync_it |= S_CTIME; if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) @@ -2096,15 +2080,49 @@ int file_update_time(struct file *file) if (!sync_it) return 0; - /* Finally allowed to write? Takes lock. */ - if (__mnt_want_write_file(file)) - return 0; + return sync_it; +} + +static int __file_update_time(struct inode *inode, struct file *file, + struct timespec64 *now, int sync_mode) +{ + int ret = 0; - ret = inode_update_time(inode, &now, sync_it); - __mnt_drop_write_file(file); + /* try to update time settings */ + if (!__mnt_want_write_file(file)) { + ret = inode_update_time(inode, now, sync_mode); + __mnt_drop_write_file(file); + } return ret; } + + /** + * file_update_time - update mtime and ctime time + * @file: file accessed + * + * Update the mtime and ctime members of an inode and mark the inode for + * writeback. Note that this function is meant exclusively for usage in + * the file write path of filesystems, and filesystems may choose to + * explicitly ignore updates via this function with the _NOCMTIME inode + * flag, e.g. for network filesystem where these imestamps are handled + * by the server. This can return an error for file systems who need to + * allocate space in order to update an inode. + * + * Return: 0 on success, negative errno on failure. + */ +int file_update_time(struct file *file) +{ + int ret; + struct inode *inode = file_inode(file); + struct timespec64 now = current_time(inode); + + ret = file_needs_update_time(inode, file, &now); + if (ret <= 0) + return ret; + + return __file_update_time(inode, file, &now, ret); +} EXPORT_SYMBOL(file_update_time); /** @@ -2123,6 +2141,7 @@ int file_modified(struct file *file) int ret; struct dentry *dentry = file_dentry(file); struct inode *inode = file_inode(file); + struct timespec64 now = current_time(inode); /* * Clear the security bits if the process is not being run by root. @@ -2141,7 +2160,11 @@ int file_modified(struct file *file) if (unlikely(file->f_mode & FMODE_NOCMTIME)) return 0; - return file_update_time(file); + ret = file_needs_update_time(inode, file, &now); + if (ret <= 0) + return ret; + + return __file_update_time(inode, file, &now, ret); } EXPORT_SYMBOL(file_modified);