From mboxrd@z Thu Jan 1 00:00:00 1970 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 7F901C43334 for ; Thu, 23 Jun 2022 18:02:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B64878E016F; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B15038E0144; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A036A8E016F; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 91DB88E0144 for ; Thu, 23 Jun 2022 14:02:12 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 65B443569A for ; Thu, 23 Jun 2022 18:02:12 +0000 (UTC) X-FDA: 79610269704.25.950EC45 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf31.hostedemail.com (Postfix) with ESMTP id CD75D200BF for ; Thu, 23 Jun 2022 18:02:11 +0000 (UTC) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25NHuqam025904 for ; Thu, 23 Jun 2022 11:02:11 -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=hg9mOHqe8lbN/Pa620EqWCYSM90BEn33RivumAhrzAE=; b=CmDDAQlqynY28763l7sI+aI7i9V+sA/UOfFzsgeNL63J7hp14qkYTlNRnnTKKoLXAkk+ i4nPRrNllQ0bkzTCih7Tr4h0j8AnkVmoc0tLLWvmQ9Jr18zpk2NTIEYywtoYVVqiFAzB 3qQKfHiP8U2XyJqZdWXf1Zjojy6W89hvnMg= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3gvn9433cw-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 23 Jun 2022 11:02:10 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 23 Jun 2022 11:02:08 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 8C5B410C5DC61; Thu, 23 Jun 2022 10:52:00 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , , Christian Brauner Subject: [RESEND PATCH v9 09/14] fs: Split off inode_needs_update_time and __file_update_time Date: Thu, 23 Jun 2022 10:51:52 -0700 Message-ID: <20220623175157.1715274-10-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220623175157.1715274-1-shr@fb.com> References: <20220623175157.1715274-1-shr@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: d1GWIze-PBt6CU0vsXVFXGcfskMGEPnl X-Proofpoint-GUID: d1GWIze-PBt6CU0vsXVFXGcfskMGEPnl X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-23_07,2022-06-23_01,2022-06-22_01 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656007332; a=rsa-sha256; cv=none; b=niAqwLSEaarRNaN5a19v4LJR8pso0y3rvrBLrG0HlvBd30qlIa4ad3dLNfQwqI+YEjbDKP oVCq4aTo7H2RucaqN0tk1sp/1Hb28zVNTwPhuQNL5srv2WZF/ReeL1Zxuvt9DK4nSgqxFr VsTbVxtwUDklcOMEGE6DSBpPYgc01ZU= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=CmDDAQlq; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656007332; 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=hg9mOHqe8lbN/Pa620EqWCYSM90BEn33RivumAhrzAE=; b=aKJuaC5wH7tAExKzt219WRWCQcztKKPTOtMgfMuCfDgZY7lBAfyEqndjTObQr9/W4ri2dp UxHPdfUptj+dn/UhspCzal2mGAYvFn2Yxm4iPAVQIyLm/3onALf3RYAz40jxUtm0k+QrfF 30AMof48rFPn/4h+/OYi+AeinpPpYEU= X-Stat-Signature: 8yiwyhgrcckf3ozoas7wmy9keqe63xet X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CD75D200BF Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=CmDDAQlq; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf31.hostedemail.com: domain of "prvs=71737354e2=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71737354e2=shr@fb.com" X-HE-Tag: 1656007331-247189 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 inode_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 Reviewed-by: Jan Kara Reviewed-by: Christian Brauner (Microsoft) --- fs/inode.c | 76 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index a2e18379c8a6..ff726d99ecc7 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2049,35 +2049,18 @@ int file_remove_privs(struct file *file) } EXPORT_SYMBOL(file_remove_privs); =20 -/** - * 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 inode_needs_update_time(struct inode *inode, struct timespec6= 4 *now) { - struct inode *inode =3D file_inode(file); - struct timespec64 now; int sync_it =3D 0; - int ret; =20 /* First try to exhaust all avenues to not sync */ if (IS_NOCMTIME(inode)) return 0; =20 - now =3D current_time(inode); - if (!timespec64_equal(&inode->i_mtime, &now)) + if (!timespec64_equal(&inode->i_mtime, now)) sync_it =3D S_MTIME; =20 - if (!timespec64_equal(&inode->i_ctime, &now)) + if (!timespec64_equal(&inode->i_ctime, now)) sync_it |=3D S_CTIME; =20 if (IS_I_VERSION(inode) && inode_iversion_need_inc(inode)) @@ -2086,15 +2069,50 @@ int file_update_time(struct file *file) if (!sync_it) return 0; =20 - /* Finally allowed to write? Takes lock. */ - if (__mnt_want_write_file(file)) - return 0; + return sync_it; +} + +static int __file_update_time(struct file *file, struct timespec64 *now, + int sync_mode) +{ + int ret =3D 0; + struct inode *inode =3D file_inode(file); =20 - ret =3D inode_update_time(inode, &now, sync_it); - __mnt_drop_write_file(file); + /* try to update time settings */ + if (!__mnt_want_write_file(file)) { + ret =3D inode_update_time(inode, now, sync_mode); + __mnt_drop_write_file(file); + } =20 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 =3D file_inode(file); + struct timespec64 now =3D current_time(inode); + + ret =3D inode_needs_update_time(inode, &now); + if (ret <=3D 0) + return ret; + + return __file_update_time(file, &now, ret); +} EXPORT_SYMBOL(file_update_time); =20 /** @@ -2111,6 +2129,8 @@ EXPORT_SYMBOL(file_update_time); int file_modified(struct file *file) { int ret; + struct inode *inode =3D file_inode(file); + struct timespec64 now =3D current_time(inode); =20 /* * Clear the security bits if the process is not being run by root. @@ -2123,7 +2143,11 @@ int file_modified(struct file *file) if (unlikely(file->f_mode & FMODE_NOCMTIME)) return 0; =20 - return file_update_time(file); + ret =3D inode_needs_update_time(inode, &now); + if (ret <=3D 0) + return ret; + + return __file_update_time(file, &now, ret); } EXPORT_SYMBOL(file_modified); =20 --=20 2.30.2