From patchwork Wed Jun 1 21:01:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12867261 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 A81F7C43334 for ; Wed, 1 Jun 2022 21:07:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C7896B0073; Wed, 1 Jun 2022 17:07:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3762B6B0074; Wed, 1 Jun 2022 17:07:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23D756B0075; Wed, 1 Jun 2022 17:07:17 -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 17C206B0073 for ; Wed, 1 Jun 2022 17:07:17 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 95890120D74 for ; Wed, 1 Jun 2022 21:07:16 +0000 (UTC) X-FDA: 79530902472.03.F21F067 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf04.hostedemail.com (Postfix) with ESMTP id 295C240065 for ; Wed, 1 Jun 2022 21:06:56 +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 251HgMO8011588 for ; Wed, 1 Jun 2022 14:07:15 -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=/c1tXQ+b6bxtOlEa/BmLZu1viU9avcsa0t6EYp9adkM=; b=ahLuLGnBdh3I8IY+HUwXj7x1wIS/tEzXcJcIi+XHlYbF1CeV04fGbd8QYEKjaZPdf1MG U8H/KOmqVjASX+7i0DTKsqV+9QGJM78ryP/0PEoM1DNiaeYwFzXiMitPPBj70/2Ie9Xf HvcugF6DUtMBfnXXFQW9Kho5cnTjN5ZSVR8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3ge3wk4ub5-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 01 Jun 2022 14:07:15 -0700 Received: from twshared14818.18.frc3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Wed, 1 Jun 2022 14:07:12 -0700 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id EE9ACFEB23A9; Wed, 1 Jun 2022 14:01:42 -0700 (PDT) From: Stefan Roesch To: , , , , CC: , , , , , Christoph Hellwig Subject: [PATCH v7 10/15] fs: Add async write file modification handling. Date: Wed, 1 Jun 2022 14:01:36 -0700 Message-ID: <20220601210141.3773402-11-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220601210141.3773402-1-shr@fb.com> References: <20220601210141.3773402-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: JJmpZBjd5zFdYWEA--rTTbOk7tNgdLXC X-Proofpoint-ORIG-GUID: JJmpZBjd5zFdYWEA--rTTbOk7tNgdLXC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-01_08,2022-06-01_01,2022-02-23_01 X-Stat-Signature: penc3s6fqux743uzooz6wq7k4z37ujrs Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=fb.com header.s=facebook header.b=ahLuLGnB; dmarc=pass (policy=reject) header.from=fb.com; spf=none (imf04.hostedemail.com: domain of "prvs=71517ce8a8=shr@fb.com" has no SPF policy when checking 67.231.153.30) smtp.mailfrom="prvs=71517ce8a8=shr@fb.com" X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 295C240065 X-HE-Tag: 1654117616-13125 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 adds a file_modified_async() function to return -EAGAIN if the request either requires to remove privileges or needs to update the file modification time. This is required for async buffered writes, so the request gets handled in the io worker of io-uring. Signed-off-by: Stefan Roesch Reviewed-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/inode.c | 43 +++++++++++++++++++++++++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index c44573a32c6a..4503bed063e7 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2116,17 +2116,21 @@ int file_update_time(struct file *file) EXPORT_SYMBOL(file_update_time); /** - * file_modified - handle mandated vfs changes when modifying a file + * file_modified_flags - handle mandated vfs changes when modifying a file * @file: file that was modified + * @flags: kiocb flags * * When file has been modified ensure that special * file privileges are removed and time settings are updated. * + * If IOCB_NOWAIT is set, special file privileges will not be removed and + * time settings will not be updated. It will return -EAGAIN. + * * Context: Caller must hold the file's inode lock. * * Return: 0 on success, negative errno on failure. */ -int file_modified(struct file *file) +static int file_modified_flags(struct file *file, int flags) { int ret; struct inode *inode = file_inode(file); @@ -2146,11 +2150,46 @@ int file_modified(struct file *file) ret = inode_needs_update_time(inode, &now); if (ret <= 0) return ret; + if (flags & IOCB_NOWAIT) + return -EAGAIN; return __file_update_time(file, &now, ret); } + +/** + * file_modified - handle mandated vfs changes when modifying a file + * @file: file that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int file_modified(struct file *file) +{ + return file_modified_flags(file, 0); +} EXPORT_SYMBOL(file_modified); +/** + * kiocb_modified - handle mandated vfs changes when modifying a file + * @iocb: iocb that was modified + * + * When file has been modified ensure that special + * file privileges are removed and time settings are updated. + * + * Context: Caller must hold the file's inode lock. + * + * Return: 0 on success, negative errno on failure. + */ +int kiocb_modified(struct kiocb *iocb) +{ + return file_modified_flags(iocb->ki_filp, iocb->ki_flags); +} +EXPORT_SYMBOL_GPL(kiocb_modified); + int inode_needs_sync(struct inode *inode) { if (IS_SYNC(inode)) diff --git a/include/linux/fs.h b/include/linux/fs.h index bdf1ce48a458..553e57ec3efa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2392,6 +2392,7 @@ static inline void file_accessed(struct file *file) } extern int file_modified(struct file *file); +int kiocb_modified(struct kiocb *iocb); int sync_inode_metadata(struct inode *inode, int wait);