From patchwork Sun Aug 27 13:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367141 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 7FAA3C83F11 for ; Sun, 27 Aug 2023 13:30:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AD30280001; Sun, 27 Aug 2023 09:30:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05D8B8E0001; Sun, 27 Aug 2023 09:30:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6781280001; Sun, 27 Aug 2023 09:30:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D37FD8E0001 for ; Sun, 27 Aug 2023 09:30:35 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A99D51201DC for ; Sun, 27 Aug 2023 13:30:35 +0000 (UTC) X-FDA: 81169969230.05.75DA089 Received: from out-246.mta1.migadu.com (out-246.mta1.migadu.com [95.215.58.246]) by imf05.hostedemail.com (Postfix) with ESMTP id E203410001A for ; Sun, 27 Aug 2023 13:30:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=khOm1xqj; spf=pass (imf05.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.246 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143034; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M7eywqhb1fMAXTeyjh6BJsPONBLehGvo8wJ7nQSmBJs=; b=JtB7ESSytnIW08I4ojxUvIwkIW1J2vfvzlagx576jvtdpHf9KnKHMiXY5T0E4OBxVT6ZDb 7SRKQyoXMSKwQ9eRWbTwVaETPZfFb57tzdHSsFDvDr4g2jz0Ct6zNshtpysQs0qlgFqldF Eovw8k8TtO4fA+bb3BWaY1Tcmn9nH+o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143034; a=rsa-sha256; cv=none; b=GNyoFonm+T4gtdfUDs0psRCyIKSXBebXyy8i9W0mlt/7wcVUauXpCwOo44h8gkYn1tlP7E viZEx4CSURAGmkGCxPkJbzXN8FzKpgFmRmzY7fOZpr4P+ZKVbUxCkHgeMTuLXAQiOma9D9 io2taCHEvkq7PkxBK9b2VpxL4un5qSw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=khOm1xqj; spf=pass (imf05.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.246 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M7eywqhb1fMAXTeyjh6BJsPONBLehGvo8wJ7nQSmBJs=; b=khOm1xqjzQOlsKc47XQ2wnLOjuLxGwc+XfDxixj6hJjWBxivRVL9fw6eYA8IJoeNHelD6C SUgrSKu6uB34cMFyQmJmkAayvfASH0HpKYFjusAGKkd85NiwXc4z0BEmZwpbN0iGNr9iqa ll1Q4czDD51HD91ihhmFa2NNXU3DhMY= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 01/11] fs: split off vfs_getdents function of getdents64 syscall Date: Sun, 27 Aug 2023 21:28:25 +0800 Message-Id: <20230827132835.1373581-2-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: cr3au5qe3nk9h3u7jg583otegqztnw56 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: E203410001A X-Rspam-User: X-HE-Tag: 1693143033-277504 X-HE-Meta: U2FsdGVkX19FusWKxyVlI1LRqkQBAHJ28bI1Xy4B6n26Cm+QAVBlTWZVwCWyWbagy+pz4/PzaMoJgFA+Xa13FlJCKK/zgs2D7zWGXf3+iWwdUYzU7DJMX8FqX4Ee0OZTdhR1/bxzB0s03IDqosjgqBixpnEsUfhSZ+d9CYwpYeFhgxWx/3N9wYBDA9bB1z+oDJ/L3p9UTQj01ypsC4jTYWqBCP7Yt74YAMKfLn53YfgTxpBqBQ/5WgpD7FdfPowWZDzf0f0fdsyzxECKTpxvYFjLAF+X2fkg7k2UKpeC7fGj4AjjRXOBHhPGDzuut/fd9brgO/02QoS9qXxyfoQlZbKeB30vlf0eo7o2zvxX5SNT2ZuBBNshbjpYDG/vAtmuRblGk1Yh1l2Wb+PqqEXmffTC0Ijswll2mqHjTjrq0TN5dCxSkhInfIRwkfPzaq/y98/Dy667f22U04i3oUfY/CF7yl6ww5GrTiiuHsOgTni7uzlmrYam+vZMS3KEmnZTrQt8psBX/f9krDKS3ni408GT+inwg9CRKj6xFLEBm5L22JjBsrPahTHTJB7DK6Z0T5W4im074WiQDyb26+4GVSI7tJp+POttUTPgxZRP9mZYGWTuwydVQqyFGh+WIiqLkj45UYc15z4NSyApyXt/ns3xasSlN0t0YzEpeQcQ6/dQYvdSpllwfEWEcwD3rF9s/U7cNvnfFAOu5UkN39TdQRZor+kopWO/P7MPEnnBBwNANy7NUBug8PT7JVXbfDOutgfNtw5QRakVdmWdBViurM001JleFlGwPOBVqAbS1oi9h0yEPkNQLVtceteazbXahR5bB0I/1n9tdlIT5my7VFLsZw1Ri9clWq2fXcxyhi+ndxU6AIdlDQxpn2IWcReNDQPn+W12ppJcsI7+utLwGL7r3fF9VTXtCOZ6tqB4u6fofciZh/9uTJg+pKQFU7NzRWxtPWswUE4jr3w45Zp LdkR89t4 X1Dr034Fs5sNo3GM5TWcarb/pV+2gcAIkV6UvqV6TNwCFza4DJhwDBCqpgwDYePi+pX1WyTBi4rcloIvGapRlKDsay66/EW04gYmqt2+0C/g4AX6kGM7JxTQZ1fE+RYV5k3CBj3yQYiGB2atMNYU8bFtnI8SRx+oP9KSISSsHK+Y8I+Tl3enjRc4GUMLdtWS/+oUL6s95yejM1AaNk7R9VF66s1rQagchaECiEoG2qH0BoXUF5C3fvUdxAMfHdkpKZX3UaixWBOAP1j2gaIAbWx48P2B77FPijeqouK+0/kZaaor50PNTwMC7yVXsAHBnuDMdUmMV5rte8ENIxO6Pl8jo/kEb3GqPTOEDl0am+uIGCYiTPD6NJ36t5mMcmqhzL8CINUXwxKAEZccY23cc5kBo7Dl+XqrKCdzquLSk8M0EYvh5jjXLNGcrIGD2Wgww1U12R1NtG7zoqM0= 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: From: Dominique Martinet This splits off the vfs_getdents function from the getdents64 system call. This will allow io_uring to call the vfs_getdents function. Co-developed-by: Stefan Roesch Signed-off-by: Stefan Roesch Signed-off-by: Dominique Martinet Signed-off-by: Hao Xu --- fs/internal.h | 8 ++++++++ fs/readdir.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index f7a3dc111026..b1f66e52d61b 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -304,3 +304,11 @@ ssize_t __kernel_write_iter(struct file *file, struct iov_iter *from, loff_t *po struct mnt_idmap *alloc_mnt_idmap(struct user_namespace *mnt_userns); struct mnt_idmap *mnt_idmap_get(struct mnt_idmap *idmap); void mnt_idmap_put(struct mnt_idmap *idmap); + +/* + * fs/readdir.c + */ +struct linux_dirent64; + +int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, + unsigned int count); diff --git a/fs/readdir.c b/fs/readdir.c index b264ce60114d..9592259b7e7f 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -21,6 +21,7 @@ #include #include #include +#include "internal.h" #include @@ -351,10 +352,16 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen, return false; } -SYSCALL_DEFINE3(getdents64, unsigned int, fd, - struct linux_dirent64 __user *, dirent, unsigned int, count) + +/** + * vfs_getdents - getdents without fdget + * @file : pointer to file struct of directory + * @dirent : pointer to user directory structure + * @count : size of buffer + */ +int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, + unsigned int count) { - struct fd f; struct getdents_callback64 buf = { .ctx.actor = filldir64, .count = count, @@ -362,11 +369,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, }; int error; - f = fdget_pos(fd); - if (!f.file) - return -EBADF; - - error = iterate_dir(f.file, &buf.ctx); + error = iterate_dir(file, &buf.ctx); if (error >= 0) error = buf.error; if (buf.prev_reclen) { @@ -379,6 +382,21 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, else error = count - buf.count; } + return error; +} + +SYSCALL_DEFINE3(getdents64, unsigned int, fd, + struct linux_dirent64 __user *, dirent, unsigned int, count) +{ + struct fd f; + int error; + + f = fdget_pos(fd); + if (!f.file) + return -EBADF; + + error = vfs_getdents(f.file, dirent, count); + fdput_pos(f); return error; } From patchwork Sun Aug 27 13:28:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367142 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 B8364C83F12 for ; Sun, 27 Aug 2023 13:30:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3454E280002; Sun, 27 Aug 2023 09:30:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31C5D8E0001; Sun, 27 Aug 2023 09:30:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E588280002; Sun, 27 Aug 2023 09:30:59 -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 0E6418E0001 for ; Sun, 27 Aug 2023 09:30:59 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D68551401CA for ; Sun, 27 Aug 2023 13:30:58 +0000 (UTC) X-FDA: 81169970196.17.FA436E9 Received: from out-248.mta1.migadu.com (out-248.mta1.migadu.com [95.215.58.248]) by imf16.hostedemail.com (Postfix) with ESMTP id 162A8180022 for ; Sun, 27 Aug 2023 13:30:56 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=L3dZ2wnh; spf=pass (imf16.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143057; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hTZJGzowdwZotMVwWddSwVfC1FzrP/Lkz2Y0ayQQQXA=; b=sqGIrRQIBzlafrI7sSjkqPuxHpoByLqMj0brbnoIeAyhKEmOfl2NfIyRjQ2era64Qx9J6V SeYumZMHdrcKjh8tuPGVktWgiQRMY8wytj0YKTpmpVX+wl/e6s2L7lU4DxWbDqXYAXrI9s ap6iNr5Gb9Ho1K5M96f+i7UHtCeJXSI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143057; a=rsa-sha256; cv=none; b=wmqJ53g/s9PeZkO7aQlmcxoR9CB02GwUfFECBHiG99kdZlBsxuP4EAuN/31/4fpk/B0QrF TCa8VCrPzt+68xq2c3CfZrUNo9BhL2DPFORSjoUj8qKNSO9cq9yGRBGhT+SKYqKgMTDmmc 91pC6whLZWptnDazgPn5kZui4rkIN08= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=L3dZ2wnh; spf=pass (imf16.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hTZJGzowdwZotMVwWddSwVfC1FzrP/Lkz2Y0ayQQQXA=; b=L3dZ2wnhLl3MpFT8Fx3GtXFd2RCwphC3uDYko8Q0nKz7ONNiGRoAamaCC5cUw2SONEU+W+ FNti/TRpT0IYzrVdjkthri+O6/3aV24bEu1xrJpC4BygFoLKHcj9ftj4kgaNqPcbLz1Ibc FihN2zv2jXx86v+rCxyuW2cfhV75bQE= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 02/11] xfs: add NOWAIT semantics for readdir Date: Sun, 27 Aug 2023 21:28:26 +0800 Message-Id: <20230827132835.1373581-3-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: eiypefs9rc3qbrjf38remkkx3dojru5z X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 162A8180022 X-Rspam-User: X-HE-Tag: 1693143056-738594 X-HE-Meta: U2FsdGVkX19kBI4Ac1IfsHtHL2eq1OkC8K3wTh3VGLcXFSwdnLwfewVwDIDco2tAHEhQf40KXbj1/IkH1fqUJLo+3XTI775cdia//8+fE/BP6QjHN/effGCBBfGYb0AYPAhcixWp7M1sgTuV8drSys+BZftSIOPQmIVBE9aIB+8AMm8Z4TTb9JYp5csKj26fW2Nk7tdmSv/zRd3VtnfVEh+eaHWmg67NOSElrkttnR7/5ll5ESGmD7OWFF5NFXob9IKbZ0d2Plp5imdCQTr8XD8Hp7w0Miz/dsy4+HRU7TnWb3o69vmJmhSL0croTW+Ja3JFWa61Hbkin5X8GMXeDV7I186uAW4B1DKQzZ6jsYxLmtZUY0YOk+KwLAolamUO5UN0JJrJ8OPW+vPjdgL68At2pGcHy9yOqt+/8VAFeTNFQSrvhldZn4ZELkCCk5nFnHveUoTjuP/7wnX3D86m7EeaFOi800OavT0htQB5AhoXlJFqpnHSaNsnsKpWKnzRpockDzdHqa42/haxo2xr7YgEbbNGwrI5a/Dv/Ee8sfMGl02cheh2zJ5zFREJKncxb7LC857+QlamdJT4PXPdqDXpXz6rz2YrODmuSSMAO1rtDqpg9zURH0k/MrWRnpjGCUkMSD2T1uJ26jtkb1v6XkaKFYI0hM0GktafnvIJUk0XBu6940wARYhGD+F42AVlPQwc6ePs3DWbwFanv1nk+V09MD0Z7tcewTr6dSEE71Ab9Yu10wYIxqRXdrSryFpxp472mLChzON+qIFvWR5qtLgSLsNZ4bF9+8A8ieyi2KfUhpfuC/MT9/c6OOAlmGq4KvQ/tEuNHn0w4iGWxJTUTYb2HRRz/IElxkSsJiqVO6/R65XM5Tfyr3Lio2f9d6ihKcFSmDgPEJfL3hOL5ruU3uATKk8rcV+VsTUZ6QudE7RzY3CVFjqvvoCf6yQ4AuAc9KNLmYqvxLOCaEIsCwo 0gHspBcG 2FDzxHBFzHCjjYoFZeiBXY4GTKItFH1xLPPFjdpF7DbIOY9ENfXJqM2P6Hw112QeoQ/Tub1RHbQDumMw3TZ/jjmR2eAbyx8wI4Hv5yOVX1LiD5/ueMZ2s7agyny6vOVBLV/EijX7FlcESkLrBt6HhAFPsV3Ye9D5hrdUNbpPYolXSqOpJfPaLJlYClUQW0/pBa5l/Os1p8nWD9YLv8AfF4Jb5F6Zcovt1jbWZqQztj/ACfjjGkzYoUoKc1exwTGGrneYHM4KsiE67+CJyJ6Z3MqTFSJ1e/PAEZBbuafe+XBnbNiQp7vpHriwzwA== 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: From: Hao Xu Implement NOWAIT semantics for readdir. Return EAGAIN error to the caller if it would block, like failing to get locks, or going to do IO. Co-developed-by: Dave Chinner Signed-off-by: Dave Chinner Signed-off-by: Hao Xu [fixes deadlock issue, tweak code style] --- fs/xfs/libxfs/xfs_da_btree.c | 16 +++++++++++ fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_dir2_block.c | 7 ++--- fs/xfs/libxfs/xfs_dir2_priv.h | 2 +- fs/xfs/scrub/dir.c | 2 +- fs/xfs/scrub/readdir.c | 2 +- fs/xfs/xfs_dir2_readdir.c | 49 ++++++++++++++++++++++++++-------- fs/xfs/xfs_inode.c | 27 +++++++++++++++++++ fs/xfs/xfs_inode.h | 17 +++++++----- 9 files changed, 99 insertions(+), 24 deletions(-) diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index e576560b46e9..7a1a0af24197 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c @@ -2643,16 +2643,32 @@ xfs_da_read_buf( struct xfs_buf_map map, *mapp = ↦ int nmap = 1; int error; + int buf_flags = 0; *bpp = NULL; error = xfs_dabuf_map(dp, bno, flags, whichfork, &mapp, &nmap); if (error || !nmap) goto out_free; + /* + * NOWAIT semantics mean we don't wait on the buffer lock nor do we + * issue IO for this buffer if it is not already in memory. Caller will + * retry. This will return -EAGAIN if the buffer is in memory and cannot + * be locked, and no buffer and no error if it isn't in memory. We + * translate both of those into a return state of -EAGAIN and *bpp = + * NULL. + */ + if (flags & XFS_DABUF_NOWAIT) + buf_flags |= XBF_TRYLOCK | XBF_INCORE; error = xfs_trans_read_buf_map(mp, tp, mp->m_ddev_targp, mapp, nmap, 0, &bp, ops); if (error) goto out_free; + if (!bp) { + ASSERT(flags & XFS_DABUF_NOWAIT); + error = -EAGAIN; + goto out_free; + } if (whichfork == XFS_ATTR_FORK) xfs_buf_set_ref(bp, XFS_ATTR_BTREE_REF); diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h index ffa3df5b2893..32e7b1cca402 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -205,6 +205,7 @@ int xfs_da3_node_read_mapped(struct xfs_trans *tp, struct xfs_inode *dp, */ #define XFS_DABUF_MAP_HOLE_OK (1u << 0) +#define XFS_DABUF_NOWAIT (1u << 1) int xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno); int xfs_da_grow_inode_int(struct xfs_da_args *args, xfs_fileoff_t *bno, diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 00f960a703b2..59b24a594add 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -135,13 +135,14 @@ int xfs_dir3_block_read( struct xfs_trans *tp, struct xfs_inode *dp, + unsigned int flags, struct xfs_buf **bpp) { struct xfs_mount *mp = dp->i_mount; xfs_failaddr_t fa; int err; - err = xfs_da_read_buf(tp, dp, mp->m_dir_geo->datablk, 0, bpp, + err = xfs_da_read_buf(tp, dp, mp->m_dir_geo->datablk, flags, bpp, XFS_DATA_FORK, &xfs_dir3_block_buf_ops); if (err || !*bpp) return err; @@ -380,7 +381,7 @@ xfs_dir2_block_addname( tp = args->trans; /* Read the (one and only) directory block into bp. */ - error = xfs_dir3_block_read(tp, dp, &bp); + error = xfs_dir3_block_read(tp, dp, 0, &bp); if (error) return error; @@ -695,7 +696,7 @@ xfs_dir2_block_lookup_int( dp = args->dp; tp = args->trans; - error = xfs_dir3_block_read(tp, dp, &bp); + error = xfs_dir3_block_read(tp, dp, 0, &bp); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h index 7404a9ff1a92..7d4cf8a0f15b 100644 --- a/fs/xfs/libxfs/xfs_dir2_priv.h +++ b/fs/xfs/libxfs/xfs_dir2_priv.h @@ -51,7 +51,7 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args, /* xfs_dir2_block.c */ extern int xfs_dir3_block_read(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_buf **bpp); + unsigned int flags, struct xfs_buf **bpp); extern int xfs_dir2_block_addname(struct xfs_da_args *args); extern int xfs_dir2_block_lookup(struct xfs_da_args *args); extern int xfs_dir2_block_removename(struct xfs_da_args *args); diff --git a/fs/xfs/scrub/dir.c b/fs/xfs/scrub/dir.c index 0b491784b759..5cc51f201bd7 100644 --- a/fs/xfs/scrub/dir.c +++ b/fs/xfs/scrub/dir.c @@ -313,7 +313,7 @@ xchk_directory_data_bestfree( /* dir block format */ if (lblk != XFS_B_TO_FSBT(mp, XFS_DIR2_DATA_OFFSET)) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk); - error = xfs_dir3_block_read(sc->tp, sc->ip, &bp); + error = xfs_dir3_block_read(sc->tp, sc->ip, 0, &bp); } else { /* dir data format */ error = xfs_dir3_data_read(sc->tp, sc->ip, lblk, 0, &bp); diff --git a/fs/xfs/scrub/readdir.c b/fs/xfs/scrub/readdir.c index e51c1544be63..f0a727311632 100644 --- a/fs/xfs/scrub/readdir.c +++ b/fs/xfs/scrub/readdir.c @@ -101,7 +101,7 @@ xchk_dir_walk_block( unsigned int off, next_off, end; int error; - error = xfs_dir3_block_read(sc->tp, dp, &bp); + error = xfs_dir3_block_read(sc->tp, dp, 0, &bp); if (error) return error; diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c index 9f3ceb461515..dcdbd26e0402 100644 --- a/fs/xfs/xfs_dir2_readdir.c +++ b/fs/xfs/xfs_dir2_readdir.c @@ -149,6 +149,7 @@ xfs_dir2_block_getdents( struct xfs_da_geometry *geo = args->geo; unsigned int offset, next_offset; unsigned int end; + unsigned int flags = 0; /* * If the block number in the offset is out of range, we're done. @@ -156,7 +157,9 @@ xfs_dir2_block_getdents( if (xfs_dir2_dataptr_to_db(geo, ctx->pos) > geo->datablk) return 0; - error = xfs_dir3_block_read(args->trans, dp, &bp); + if (ctx->flags & DIR_CONTEXT_F_NOWAIT) + flags |= XFS_DABUF_NOWAIT; + error = xfs_dir3_block_read(args->trans, dp, flags, &bp); if (error) return error; @@ -240,6 +243,7 @@ xfs_dir2_block_getdents( STATIC int xfs_dir2_leaf_readbuf( struct xfs_da_args *args, + struct dir_context *ctx, size_t bufsize, xfs_dir2_off_t *cur_off, xfs_dablk_t *ra_blk, @@ -258,10 +262,15 @@ xfs_dir2_leaf_readbuf( struct xfs_iext_cursor icur; int ra_want; int error = 0; - - error = xfs_iread_extents(args->trans, dp, XFS_DATA_FORK); - if (error) - goto out; + unsigned int flags = 0; + + if (ctx->flags & DIR_CONTEXT_F_NOWAIT) { + flags |= XFS_DABUF_NOWAIT; + } else { + error = xfs_iread_extents(args->trans, dp, XFS_DATA_FORK); + if (error) + goto out; + } /* * Look for mapped directory blocks at or above the current offset. @@ -280,7 +289,7 @@ xfs_dir2_leaf_readbuf( new_off = xfs_dir2_da_to_byte(geo, map.br_startoff); if (new_off > *cur_off) *cur_off = new_off; - error = xfs_dir3_data_read(args->trans, dp, map.br_startoff, 0, &bp); + error = xfs_dir3_data_read(args->trans, dp, map.br_startoff, flags, &bp); if (error) goto out; @@ -360,6 +369,7 @@ xfs_dir2_leaf_getdents( int byteoff; /* offset in current block */ unsigned int offset = 0; int error = 0; /* error return value */ + int written = 0; /* * If the offset is at or past the largest allowed value, @@ -391,10 +401,17 @@ xfs_dir2_leaf_getdents( bp = NULL; } - if (*lock_mode == 0) - *lock_mode = xfs_ilock_data_map_shared(dp); - error = xfs_dir2_leaf_readbuf(args, bufsize, &curoff, - &rablk, &bp); + if (*lock_mode == 0) { + *lock_mode = + xfs_ilock_data_map_shared_generic(dp, + ctx->flags & DIR_CONTEXT_F_NOWAIT); + if (!*lock_mode) { + error = -EAGAIN; + break; + } + } + error = xfs_dir2_leaf_readbuf(args, ctx, bufsize, + &curoff, &rablk, &bp); if (error || !bp) break; @@ -479,6 +496,7 @@ xfs_dir2_leaf_getdents( */ offset += length; curoff += length; + written += length; /* bufsize may have just been a guess; don't go negative */ bufsize = bufsize > length ? bufsize - length : 0; } @@ -492,6 +510,8 @@ xfs_dir2_leaf_getdents( ctx->pos = xfs_dir2_byte_to_dataptr(curoff) & 0x7fffffff; if (bp) xfs_trans_brelse(args->trans, bp); + if (error == -EAGAIN && written > 0) + error = 0; return error; } @@ -514,6 +534,7 @@ xfs_readdir( unsigned int lock_mode; bool isblock; int error; + bool nowait; trace_xfs_readdir(dp); @@ -531,7 +552,11 @@ xfs_readdir( if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) return xfs_dir2_sf_getdents(&args, ctx); - lock_mode = xfs_ilock_data_map_shared(dp); + nowait = ctx->flags & DIR_CONTEXT_F_NOWAIT; + lock_mode = xfs_ilock_data_map_shared_generic(dp, nowait); + if (!lock_mode) + return -EAGAIN; + error = xfs_dir2_isblock(&args, &isblock); if (error) goto out_unlock; @@ -546,5 +571,7 @@ xfs_readdir( out_unlock: if (lock_mode) xfs_iunlock(dp, lock_mode); + if (error == -EAGAIN) + ASSERT(nowait); return error; } diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 9e62cc500140..d088f7d0c23a 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -120,6 +120,33 @@ xfs_ilock_data_map_shared( return lock_mode; } +/* + * Similar to xfs_ilock_data_map_shared(), except that it will only try to lock + * the inode in shared mode if the extents are already in memory. If it fails to + * get the lock or has to do IO to read the extent list, fail the operation by + * returning 0 as the lock mode. + */ +uint +xfs_ilock_data_map_shared_nowait( + struct xfs_inode *ip) +{ + if (xfs_need_iread_extents(&ip->i_df)) + return 0; + if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) + return 0; + return XFS_ILOCK_SHARED; +} + +int +xfs_ilock_data_map_shared_generic( + struct xfs_inode *dp, + bool nowait) +{ + if (nowait) + return xfs_ilock_data_map_shared_nowait(dp); + return xfs_ilock_data_map_shared(dp); +} + uint xfs_ilock_attr_map_shared( struct xfs_inode *ip) diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 7547caf2f2ab..ea206a5a27df 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -490,13 +490,16 @@ int xfs_rename(struct mnt_idmap *idmap, struct xfs_name *target_name, struct xfs_inode *target_ip, unsigned int flags); -void xfs_ilock(xfs_inode_t *, uint); -int xfs_ilock_nowait(xfs_inode_t *, uint); -void xfs_iunlock(xfs_inode_t *, uint); -void xfs_ilock_demote(xfs_inode_t *, uint); -bool xfs_isilocked(struct xfs_inode *, uint); -uint xfs_ilock_data_map_shared(struct xfs_inode *); -uint xfs_ilock_attr_map_shared(struct xfs_inode *); +void xfs_ilock(struct xfs_inode *ip, uint lockmode); +int xfs_ilock_nowait(struct xfs_inode *ip, uint lockmode); +void xfs_iunlock(struct xfs_inode *ip, uint lockmode); +void xfs_ilock_demote(struct xfs_inode *ip, uint lockmode); +bool xfs_isilocked(struct xfs_inode *ip, uint lockmode); +uint xfs_ilock_data_map_shared(struct xfs_inode *ip); +uint xfs_ilock_data_map_shared_nowait(struct xfs_inode *ip); +int xfs_ilock_data_map_shared_generic(struct xfs_inode *ip, + bool nowait); +uint xfs_ilock_attr_map_shared(struct xfs_inode *ip); uint xfs_ip2xflags(struct xfs_inode *); int xfs_ifree(struct xfs_trans *, struct xfs_inode *); From patchwork Sun Aug 27 13:28:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367143 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 BD927C83F11 for ; Sun, 27 Aug 2023 13:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5DE2E280003; Sun, 27 Aug 2023 09:32:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B4F38E0001; Sun, 27 Aug 2023 09:32:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A3CD280003; Sun, 27 Aug 2023 09:32:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3C8238E0001 for ; Sun, 27 Aug 2023 09:32:18 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0E7E212020E for ; Sun, 27 Aug 2023 13:32:18 +0000 (UTC) X-FDA: 81169973556.13.FCDD0F4 Received: from out-249.mta1.migadu.com (out-249.mta1.migadu.com [95.215.58.249]) by imf07.hostedemail.com (Postfix) with ESMTP id 4D48A40024 for ; Sun, 27 Aug 2023 13:32:16 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=w2Ynrlkl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143136; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=e5tdpTadoLYdZJB8cQ8K1ymkQcAcLx9XJrtCjJGJaVs=; b=lgv74RiG6d0UNqtDYoWo9qRS2igfQfKNzBs00NwaCYZW5cUrEYLvk/0nw5OBvQCWusgNrE +ViTVcP+zKQbgSdP5pmdGLAzTaN0r+QXlmQwamUTK4BBiSAkm+m0ITD6PTK3dDNMi9r1bk rD5drHNEe2pShSJgOBmdEmDRdJwBodI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=w2Ynrlkl; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143136; a=rsa-sha256; cv=none; b=eqKyOa40C58OBOMyoj9sXdBrLPQMepto3Xywtdev7bE0nJBAMn9B+eTPd5r5r3OurZ0xkk cKBWiJAJevpZd/6JfYvz8sIG8dSSxWfDPYAZpdIFxZbTl5FCFphvByPm+xtUq9i2jPUQLZ csnlPQzSFuwa1Y/SQH4mCNkG9sUmVdY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e5tdpTadoLYdZJB8cQ8K1ymkQcAcLx9XJrtCjJGJaVs=; b=w2Ynrlkl0lrPBgOEZvZgZsAroI/SroVLk9P1ruoBqvhkruN+yY2MpcktHEbfNgoWJ1BBu4 4ubUBExoqQaaP8jDC6A2V4vWqXAbneLZ+BhAJSfP0lzTzlCZEFFPuxh0PF54TbtDSMupEM g0UMdnFp1J3UGmAIMamiGdfpc/ghYvs= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 03/11] vfs: add nowait flag for struct dir_context Date: Sun, 27 Aug 2023 21:28:27 +0800 Message-Id: <20230827132835.1373581-4-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4D48A40024 X-Stat-Signature: u7k9xf893dbf9didnupsacudqykyiwu7 X-HE-Tag: 1693143136-405106 X-HE-Meta: U2FsdGVkX19MU11KVfywUca5JnVycZLFAt9Q0vwEWwAYj2LNR3l45XAEj7my0Ktj1uuu6GACOjb3B15PQYkGU4G+u8sspr0uU5YPUu5GNaPOHCj7EwVOP2cRLHKiaxf/ET9wv2YQuNQv8SWeH7yr1DeIr+2AouxtU9CgWwS22w8nPoIFkuyp9qcX7uoo8kO7B7DibeeWCNcIO79EhmEQoMl4X0ANs5j09qBkMaNkBaXcxwUrHpz5qUNNhLZKd0E7oK90zVYzq06W+ngD5sDIBRuq2VagU6Sufwm0Y58zuWrlE7Eb9WCd4TbgScRQwP7F9PX9+UFQQmx0xBfsZNtVYIhmcSzPKOD0QxoV1fOTUc0jIKVySiAQPsiraFXbxLHnQZe/WMwcrDEu3/CddkxO2/akVeVDeDXKsySl/EbEA7JSIGVY27FFMI05l9fe0K/HBfSAqHGGWh7RBXJBVsReFHch/+8CUhFIQxpRrC7ODgUfOYI5CZJipfK2cVQTpYFirlKYjkr+nqilo6iHlvyhzfSf9FIprP5PW5A/CiwUtTOGz8Dslf6x1MZ2dtB3QKcbF7WOYg+WY9mOe3QimJ0K6Ue5t27870VSWtQhvCrI8otMNcfigh5NUH9HNKzq7nWmozZbd7WF+xeKKJxpsoXZDST348jByjzvEUzD/BOs01dk4r7RshdNxtwRKsiffEkT0A2szXE8OzaoZ2aDzTx0mMR9MdE/PnGOxXfYnsV9jh5OYhSkuSy8iX3qdFVeGNnP2Egm4rYbw6WVHIiIk8Rn+SdjWoGG8t1BxZEyNwFRSh7YQok6yAtaTBnptTNIB6J2OinAaN+F/OjW4Aw8zDuEL0RoywFKdgpJddoWfXACe6KzHRyGdd9mdgsw/V9+5jcTD/QeIYUEmKZsrZVikZkreu9t73n3RS4jV+v42C0AIjU5YAMkPG1Du1bg7ikxdOTBuIRk8Hi1hjk+LhgoaR8 VL2E7CZ/ MWh45dzfpJ3d16qLweKpsdTx/1XPhfT/5MduQR9VExpt4k02zeuHxT2NskMvcmHI9yMEV2uR45eTWjAqLl6hChLYhxJSX7fffeAvdyG0Tog6lOPZiWVqHt+mQKG5I+YJuUWjpRzhEbYaMoVawApJSaTR6F2xX7kWfBYT8UMBDhZCg1+aTAtokkA/bNfmgKMbDHkEjKOrAlPnnV9zEFu1eV/8gPtSPxiEUbua+qvC2SjaZrVUrI2XJ8eaQvLp/IytHhlLkylOfnXrBiK4AuHYwRIQr/XnDc5theU2GTZxerlsD0aWLv03B6uEtK/XjLOhae1TWZ/8iOheBaD+bbpsdOElHWs5R34I1Txresn2V0Fbcj3sgQvdyWAj8jogHEvLUOT4JaV9SFnt+Q5U= 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: From: Hao Xu The flags will allow passing DIR_CONTEXT_F_NOWAIT to iterate() implementations that support it (as signaled through FMODE_NWAIT in file->f_mode) Notes: - considered using IOCB_NOWAIT but if we add more flags later it would be confusing to keep track of which values are valid, use dedicated flags - might want to check ctx.flags & DIR_CONTEXT_F_NOWAIT is only set when file->f_mode & FMODE_NOWAIT in iterate_dir() as e.g. WARN_ONCE? Co-developed-by: Dominique Martinet Signed-off-by: Dominique Martinet Signed-off-by: Hao Xu --- fs/internal.h | 2 +- fs/readdir.c | 6 ++++-- include/linux/fs.h | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index b1f66e52d61b..7508d485c655 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -311,4 +311,4 @@ void mnt_idmap_put(struct mnt_idmap *idmap); struct linux_dirent64; int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, - unsigned int count); + unsigned int count, unsigned long flags); diff --git a/fs/readdir.c b/fs/readdir.c index 9592259b7e7f..b80caf4c9321 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -358,12 +358,14 @@ static bool filldir64(struct dir_context *ctx, const char *name, int namlen, * @file : pointer to file struct of directory * @dirent : pointer to user directory structure * @count : size of buffer + * @flags : additional dir_context flags */ int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent, - unsigned int count) + unsigned int count, unsigned long flags) { struct getdents_callback64 buf = { .ctx.actor = filldir64, + .ctx.flags = flags, .count = count, .current_dir = dirent }; @@ -395,7 +397,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd, if (!f.file) return -EBADF; - error = vfs_getdents(f.file, dirent, count); + error = vfs_getdents(f.file, dirent, count, 0); fdput_pos(f); return error; diff --git a/include/linux/fs.h b/include/linux/fs.h index 6867512907d6..f3e315e8efdd 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1719,8 +1719,16 @@ typedef bool (*filldir_t)(struct dir_context *, const char *, int, loff_t, u64, struct dir_context { filldir_t actor; loff_t pos; + unsigned long flags; }; +/* + * flags for dir_context flags + * DIR_CONTEXT_F_NOWAIT: Request non-blocking iterate + * (requires file->f_mode & FMODE_NOWAIT) + */ +#define DIR_CONTEXT_F_NOWAIT (1 << 0) + /* * These flags let !MMU mmap() govern direct device mapping vs immediate * copying more easily for MAP_PRIVATE, especially for ROM filesystems. From patchwork Sun Aug 27 13:28:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367144 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 DC295C83F01 for ; Sun, 27 Aug 2023 13:32:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C8548E000D; Sun, 27 Aug 2023 09:32:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 678428E0001; Sun, 27 Aug 2023 09:32:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 567E58E000D; Sun, 27 Aug 2023 09:32:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4785A8E0001 for ; Sun, 27 Aug 2023 09:32:48 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 20A59160201 for ; Sun, 27 Aug 2023 13:32:48 +0000 (UTC) X-FDA: 81169974816.03.11385F6 Received: from out-250.mta1.migadu.com (out-250.mta1.migadu.com [95.215.58.250]) by imf23.hostedemail.com (Postfix) with ESMTP id 552F614000D for ; Sun, 27 Aug 2023 13:32:46 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Yw+5XvRr; spf=pass (imf23.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.250 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143166; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W04QOWrrBuMFm18D/+g+MI2uZNnKBIsbwxq2wO1dKKw=; b=v7QOeVbqNvgW2526M0/WNiX27lAkI7To5yr3x2qL2w7kemrN3PDFoLEwok2O+U5wdmDx2N +yMBYtsya9M7vBTGaC11XqhaDJMzKHrfZ3Ao24bmO5/ymN4h8sudR+C6mX+rjBIwUhdjOY tH1tndYwPddwyFT9rWWJ4Y31HAIUU4k= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Yw+5XvRr; spf=pass (imf23.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.250 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143166; a=rsa-sha256; cv=none; b=Az+s1n1LdgUPbKIYE1ehCDEc6n5TNHJ8tokBBnBSBQynxrU8WS26UiJHNJ/VgzsLZnQFXQ ks5FuAb9kQZ3a2jVfYu41r5gUyyeLUwrEaciteFb04iHpg3Snaby+YxVUXRc5yebclYwd1 5Wkt6GSCXfnGN65ACtfcPobmMFvnM4k= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W04QOWrrBuMFm18D/+g+MI2uZNnKBIsbwxq2wO1dKKw=; b=Yw+5XvRr3vDIU02wPbTBy+P7Vb3r5vANDo9ahLXEToHmV4GE1+GjTI2/FiGvzS/72CcLGE wNMghjMXDTPCiQyUzrxQFpeftIBQyMH0jGDsayXuE4xMGusaZd0pBKhpckAeDFF1jY1yin IKCCEyk0xEU76DQXzGM7PUWjnMG6kt0= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 04/11] vfs: add a vfs helper for io_uring file pos lock Date: Sun, 27 Aug 2023 21:28:28 +0800 Message-Id: <20230827132835.1373581-5-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 552F614000D X-Rspam-User: X-Stat-Signature: gcsk3yt4k83mjdqege3w976z8cx76hfm X-Rspamd-Server: rspam01 X-HE-Tag: 1693143166-836759 X-HE-Meta: U2FsdGVkX19VocWVYkwKidtBFBkMbQHKaNn0jCLXYVI60td3Tdfzqe+Klw1RoJ+SOSGo5rdrPNTIG6RtM3YdSxzSRT6co1wF+dVPalQr9U3PaV1KL+8IuX4tzCmG+zBBUe0GcaUik43p8d4dz4R+FaOjejXWz6WTSCopjjJfHcARVL/LbWxvgK4pBA7UE9cAjrfw6htAKRQ1oNf6RBivU46pXLsx70xv5yRglk6ATbnHtBjKdESyv8kPnKt3MsNuIVPpT0qcjsurQ72s2bj/zG3XrDmt0qcXSsRPIvXgMrYoUpHfg1PhHbJ0UEvzuQGl9WOqb92Myh4XtNaEpsxzDz60VM1hLZcN7nZ2T64shESa9tlk9ywZ/sysmolVyjBlg7Sw9CYhSPgIxbvI2zolu42eeeZJlNsHsSPxsHQ35axO6E/gSrNJoSlnIVrjR7Q3x8xu9Ks1LKZ3qLA98XXdvImXcLIl1zOMy83oi73/JfieyavU2W5qEdh+Xgz4vxiYVmOLHGg+db1JVGp19Kezpi6fIM1sbboc9BdAza/PMZl4HrBTv44Ymegwod/XTXuFzi2I30SYgJEhS1nCZbFxb3Iat2cNoyiByLuTH4w+/JqiTBZcf84WjORXIgO6ymQjmfxIeT2lDhR6bRHjNjTCb3kRQsV1ka9uLgg4ozMoaJTUmWZB7eT54qE5Dk63/FAd23yTKDM7aa0PCBKnlV32FoQyOINHELfMNYG5ZLfKK1AWCkfmlMbfHEUKEQniqFmDgSOTISHrnnyG41PAc7QI/u6prsxvcQD2lcDiZHS5awPUUsnLLtikOMGi+6rYmlJ2VdKgLIPVObAaiRlX2g34kJFNit1ftck21vgoVPNQ3Ht76FfjvQuiug3kCsU/GdcejngLN0Y/kmrYNnZ3+UOvJregrwBnm0TPYOZ2GtO2ak5TEy+3fWuBFIsLizm0y4o8aYuwzvfHZU0w/NfN8lL 1Alr+I8c uHm05P4fCKvJRCqbY8Nsomer4DZGUXSqdcCHRJczjJCzFmDmexuZ9n0BqtmhKirAEyF3pUUBA68Z+gBjqLUBgRO3qKwaBeJd8CaPlbtOLT+g7d1AYN1v6rdqZ9dbW5oYXeXB5bWQKmfM1pCnDCmfeY6zAV+tRQIxbz+owcluUHkBA0f3k/ihfLoF6FO1SA/rA0Cw4XjVQylaN+8qrhXIQAgGq1aPFNBcj7Q1LTYW1G+HcImVeOwnyNh94O8mtDdduF2ky2XuV/7BXdgR2GEj91F3jWiTdGFKR5TJcoTG1GbQiFJrovi2jO7Utoe67nBs+9hqUJY05nT9skgA= 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: From: Hao Xu Add a vfs helper file_pos_lock_nowait() for io_uring usage. The function have conditional nowait logic, i.e. if nowait is needed, return -EAGAIN when trylock fails. Signed-off-by: Hao Xu --- fs/file.c | 13 +++++++++++++ include/linux/file.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/fs/file.c b/fs/file.c index 35c62b54c9d6..8e5c38f5db52 100644 --- a/fs/file.c +++ b/fs/file.c @@ -1053,6 +1053,19 @@ void __f_unlock_pos(struct file *f) mutex_unlock(&f->f_pos_lock); } +int file_pos_lock_nowait(struct file *file, bool nowait) +{ + if (!(file->f_mode & FMODE_ATOMIC_POS)) + return 0; + + if (!nowait) + mutex_lock(&file->f_pos_lock); + else if (!mutex_trylock(&file->f_pos_lock)) + return -EAGAIN; + + return 1; +} + /* * We only lock f_pos if we have threads or if the file might be * shared with another process. In both cases we'll have an elevated diff --git a/include/linux/file.h b/include/linux/file.h index 6e9099d29343..bcc6ba0aec50 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -81,6 +81,8 @@ static inline void fdput_pos(struct fd f) fdput(f); } +extern int file_pos_lock_nowait(struct file *file, bool nowait); + DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd) extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); From patchwork Sun Aug 27 13:28:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367211 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 217D9C83F11 for ; Sun, 27 Aug 2023 13:33:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B350A280004; Sun, 27 Aug 2023 09:33:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE5E68E0001; Sun, 27 Aug 2023 09:33:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D47D280004; Sun, 27 Aug 2023 09:33:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8F1BD8E0001 for ; Sun, 27 Aug 2023 09:33:14 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 664D4C0216 for ; Sun, 27 Aug 2023 13:33:14 +0000 (UTC) X-FDA: 81169975908.29.516DE10 Received: from out-249.mta1.migadu.com (out-249.mta1.migadu.com [95.215.58.249]) by imf17.hostedemail.com (Postfix) with ESMTP id B85474001D for ; Sun, 27 Aug 2023 13:33:12 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nFii2RaA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143192; a=rsa-sha256; cv=none; b=l3hxAgJBZQLJYotAphri2dfAt7Kl298z4BcAs1ukaN6F7Drm48ZDvw+Xd29y4OIV04cJ4y 7no9N1AaKwEWSX+u+1ssHkkaBnJS5eoXbbfQUVFqlwxq5D2FaLCEAPJib/YrtEx0fKk9Ob +h2NRNE+XHiK1JPBxh7JR+GMGz13EFw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nFii2RaA; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143192; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/w6lIGuCSX5M2SzS7SE+A2P7DaEhoFOZKnfxuRd6M0g=; b=bcnEcSORWntpT1NkQklGaBceFRVrUxTC1/2arn0aDquQYwbbltyGaiMfRk8tD78vhDLayO dhRErs57SPzJkA8dwW9eWxhW7m++DNrieLAr5Pa38xsDTLu0YCoCWwD7boiuKQIGbercz7 xteFgi5n8wjUmL9sAC4avYN/ZP+UBBo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/w6lIGuCSX5M2SzS7SE+A2P7DaEhoFOZKnfxuRd6M0g=; b=nFii2RaAVtERxLk40QaUcpRmI8KsgMix1y0E+FJbochLiKUgvfCEHVlGKzl74Le3vQdKIX Ic8HKxNSkSYAWoFe69ooiMlQ7zn66y3ibRq5sWqNObX5lM32Ml0OMzA1739KowhZg9B8i9 pdpKOlIaZIJj3teGeY/OKxpoMDEzjMc= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 05/11] vfs: add file_pos_unlock() for io_uring usage Date: Sun, 27 Aug 2023 21:28:29 +0800 Message-Id: <20230827132835.1373581-6-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B85474001D X-Stat-Signature: uw6o4pfbymsu9n7o47jt9cuqy144b9a5 X-HE-Tag: 1693143192-281442 X-HE-Meta: U2FsdGVkX1+Vsrw1OEQmZrWMNUlH8K4gBosJpqlAQEKLKkPjw/RwMac1rbkNkJJE2nMBp0YrGU+Ofoy1St0MXvjGDEwMbGoMdww6Dh6Vau2Z0YLikqZA8GhgUv/kx3PHqlEeTVAH5/gUtlEVYt6g8T5ipXLeSXL7CcKTrtnZj/lWjdm7ORh8LWzNMYeLOk/w62RqmrD87mqhYqzVihznOdfJ2+EGrVi1fBSkhYRHVkcqfAjH99QmK8dcHo0VgAE1WTthoY1e2ZHW90oI2ktpG3OYy2E+TwTKMMOgauqLlHUbnpAEv8pAA8C+2/mNbPAlIvadjje4BzufE/JLzO1XBnEpogtZLjPmMCBsrRyB3MY0g5j95zfMc66clo9oWDpQT5jLTpvcvF9WGt6lZYHSEeOtceWvC8ICQfeU2ZjDVMdLUhjwzQGHJwFnY87jLnrDlWeV6k2n++u29sQDV5iwXJ9H2kpg599obvC1zvtfl+lTk8Lim1lU0XqtS2J3JpYxNnyWR/NMyahAx0xejCCObRrqI1f6KATSp3Y2YsTLh5shp6OpnKVj1yqJyvh2OwtgB4rVJKGn/xVNeYgSLd6O75QGUP4ARxvW3eFXqJ6v5yRtD1JMORgZkxroujDjMeRvCfP/Dvzp8u9D+9L+A0UZxPl9iLEwBk84baR0SLn3SaLoMGVFF2lSn5E0qNO4eNabgXSRMOm6HLXdel/y9u0SCFCUwcIuCM1YavNRJH67YAiTBauYIm4f7Hiz6BmKnU3/Ikx3pBcxHxLVxqhWvbRiEQDPmu+5CPwD0VuvmapKOl8at+sxt2P2LQ+Zeh1J9XZNfrqvKYdwzVnMc0LkxgSsO2yuFJ49AkxTMtTOr1yPcefSJatBTTqltp8veIrBy2nVofi2ZseOqHiMD6+wmREiL+yZyTcsP5sxP8DXHHPdzUgOHSuHoUGgwl8gwWQxTk6rZjtysGe8dBdn80/Gr/p xbp+SfK4 qmrcc82YVZNPSjBXBTNm8FHAb53aXOq1EqNwAzqyeW6UX38AQefoUvnQCWXO20GaRF3SmBvxhs67fjZo9v6QhfKB8mdsObSXL22wZMfnEyJM5Tn4iawISqe2zJwMrtYD1czkwvzmjDFjWYxK7LYlQsMOIWxL7HryztA3oGBChKiSgIESu/efYJBYAtkNYiGtt8MQ7Uhj+44ZDPDVygHlDGfwmOtEtZnsQtLA02AHzHZIzjpGwSxTOhIVi6iu3lQ3Mul/npvMREK0M2QqWbX7scAy4kzXDj+x5H4JmAenZTY7BfyWDlC8eFjG5atggBCbYhozuPHNeG+IL7q8= 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: From: Hao Xu Add a helper to unlock f_pos_lock without any condition. Introduce this since io_uring handles f_pos_lock not with a fd struct, thus FDPUT_POS_UNLOCK isn't used. Signed-off-by: Hao Xu --- include/linux/file.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/file.h b/include/linux/file.h index bcc6ba0aec50..a179f4794341 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -81,6 +81,11 @@ static inline void fdput_pos(struct fd f) fdput(f); } +static inline void file_pos_unlock(struct file *file) +{ + __f_unlock_pos(file); +} + extern int file_pos_lock_nowait(struct file *file, bool nowait); DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd) From patchwork Sun Aug 27 13:28:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367212 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 2910FC83F01 for ; Sun, 27 Aug 2023 13:33:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF8B7280005; Sun, 27 Aug 2023 09:33:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA8F78E0001; Sun, 27 Aug 2023 09:33:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7130280005; Sun, 27 Aug 2023 09:33:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9801D8E0001 for ; Sun, 27 Aug 2023 09:33:46 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 80B891A0230 for ; Sun, 27 Aug 2023 13:33:46 +0000 (UTC) X-FDA: 81169977252.25.0DF3933 Received: from out-248.mta1.migadu.com (out-248.mta1.migadu.com [95.215.58.248]) by imf25.hostedemail.com (Postfix) with ESMTP id C4A43A0016 for ; Sun, 27 Aug 2023 13:33:44 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="eP0/0poz"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143225; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/SxFJtissRd8EFEKfjvtrzUrKe2UZWHAXBAv8XN+2Ws=; b=box3bLdkwLj6CPYe6GX8vjbFbbVNcYGwQZ3XfV2Yko3IK/7zjXNvn09wjSWXn/O53nbOyl 6xYUVxq/E7jSQgqp6I9Xbz5GYYwPlP4Ko9Ax39dY949yM1mbMudRXik1nwK9i68DShLTTU R/Q+M2JH6ZKXmNCPlXmcoA1V3CmSQYU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="eP0/0poz"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143225; a=rsa-sha256; cv=none; b=wbUf6vqAjQM0tzH8YELO3YHNzc83pxM5d5kQuH6JoZGh7C/qvyV4iEVovSzn072mwj+KL9 6TFfvkeNb0p+61tQWDWhVpwQc+dn4ChhDw21+4sRjj1TRD00J8kCLAdcSKNtDLUbMcVMik hLMap4OiY6kmUc03+DPuviv/ZvP/cDM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/SxFJtissRd8EFEKfjvtrzUrKe2UZWHAXBAv8XN+2Ws=; b=eP0/0pozPhJqhF9X0LVypWfPixS8Ogox1mSys0p44e7ItbiSDBlkHW42EuiOoGiIwrzhGw tZ/ULBZZYg3CYueJM7OBSSuL9VrufdTT1Ge7QZSiTjhbDK29Ks9eejLI5UabQHt/7N12hX DZgpFPTC3SJN3d95V92Kgu+jAWVmYA0= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 06/11] vfs: add a nowait parameter for touch_atime() Date: Sun, 27 Aug 2023 21:28:30 +0800 Message-Id: <20230827132835.1373581-7-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: C4A43A0016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3uaobeakd4p1pt5gwn4n8jasfct4zymt X-HE-Tag: 1693143224-347234 X-HE-Meta: U2FsdGVkX19PIMsR5oGfb36ADOXxtnxAlHe6yWlAP0q393tblY2qRLmpGxfq6xI6HwrbKp1CVs1BdPHgfSV4SmUYzFmrM+GKYBJhSIrzWvoDoV8ULuPATupvbAN5a6Ejr7kgJC/EeZi15DQs03yZ4es2RQV+5l/FqYC8AhbA2V0DhOV/iUEiGckRgSD0IkwrY9Pvonu1ca++LBXrv1Fs56GgNTI5K6Dkzxh5GBhRK5weAI+trvEqhbxsy+/MHri35U6Py8EL9kFZvYfEgK3Kn/6IrRiaNahQ8wyMj1pLiL7SQfbqWTFUmd/+WtoYWStALLGO6afVTQpAdbQbfD/Bg/oRQoxzZznW9WlUC11QWxx7nXPuHnYNWjzlbaSvl7aAHfh29sOCEBVO1m7XwqJ2Il0FLCSTjDgdL0KwlCQqqDI9wGLmdTL3/6ytnQVn0/BbCil10FF3COIaA1l6j3zuAdYf19lLBzHunze/bJqzqVM+ECOJqgVeV3LSCv7k2NQZkBSJzY1FKzTQowdsu65EFek679NXwEa5Gzz7dh+mFxxgPWklnieg6ufYqrBK7icWDl0/nOmsmpoewmcQUFWR84FcHsel+gGVq5DyL+PAS0K9mnXMQIOR7pLItf6aw7+lbNrPQsbJM6RvBFIhFi3xm6fNy6l9hG6h8BburnXQ0NSXWwcPl+DgfHMDDCmBZ7x8tSYxhFMeoel6kCnEV7ZYRfJgSdB44XOfgf/p2zG1jyZhjnBLmn0XNYZFAnciS3c/nORqOojp0areyJwZykZDwIjaFZqiEtP3FU1FJfDj8Js03XwllfVFU5Wm37ksT6SrLM55wdKFXhxrpQ4/Jhl6AJmhM7kBh4CvuakQNVJIegcoPPMb+3SOAzX+0QkVXGeeBTsWyaVHp+ivY0x76DteEugXNJA7TNiJG2akY/5Cw1uRy2nQgcD382ItTVyZPaGqkblg8NAoYNVz6bQaLa3 snrdKq3Y O7jgjU3LHw3WOU4JV/3bSQWL4hUrrTC8MQRVjqwnaB7J9bJmig42NWxmy8aOoHb2D5X/aTzSF2X8TwUBHpSh/B5zwptTyiZSRAs3F83otLdvcm82SdyiSL7wLoKUMOuDA/LUdy9ci4sugBD+Bmd5k23tNkopyBIKSMmHs/R4nNoh4tWgtxdkLCrYE9jYibLBjoUPq4COG21g8auOyvwMomxeGhxuhaPgYDRlWT44Ybo7PBB+KR1XkbgMONl1mgY1w7b+IR74DFQzdIiEcIrvebrSCkRKDpZpFeptUSWSO9iGPczXI/pWhNPVmNCPPnGRsgqt8gdTAO6UjkGw= 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: From: Hao Xu Add a nowait boolean parameter for touch_atime() to support nowait semantics. It is true only when io_uring is the initial caller. Signed-off-by: Hao Xu --- fs/cachefiles/namei.c | 2 +- fs/ecryptfs/file.c | 4 ++-- fs/inode.c | 7 ++++--- fs/namei.c | 4 ++-- fs/nfsd/vfs.c | 2 +- fs/overlayfs/file.c | 2 +- fs/overlayfs/inode.c | 2 +- fs/stat.c | 2 +- include/linux/fs.h | 4 ++-- kernel/bpf/inode.c | 4 ++-- net/unix/af_unix.c | 4 ++-- 11 files changed, 19 insertions(+), 18 deletions(-) diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index d9d22d0ec38a..7a21bf0e36b8 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -591,7 +591,7 @@ static bool cachefiles_open_file(struct cachefiles_object *object, * used to keep track of culling, and atimes are only updated by read, * write and readdir but not lookup or open). */ - touch_atime(&file->f_path); + touch_atime(&file->f_path, false); dput(dentry); return true; diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index ce0a3c5ed0ca..3db7006cc440 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c @@ -39,7 +39,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb, rc = generic_file_read_iter(iocb, to); if (rc >= 0) { path = ecryptfs_dentry_to_lower_path(file->f_path.dentry); - touch_atime(path); + touch_atime(path, false); } return rc; } @@ -64,7 +64,7 @@ static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos, rc = filemap_splice_read(in, ppos, pipe, len, flags); if (rc >= 0) { path = ecryptfs_dentry_to_lower_path(in->f_path.dentry); - touch_atime(path); + touch_atime(path, false); } return rc; } diff --git a/fs/inode.c b/fs/inode.c index 8fefb69e1f84..e83b836f2d09 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1961,17 +1961,17 @@ bool atime_needs_update(const struct path *path, struct inode *inode) return true; } -void touch_atime(const struct path *path) +int touch_atime(const struct path *path, bool nowait) { struct vfsmount *mnt = path->mnt; struct inode *inode = d_inode(path->dentry); struct timespec64 now; if (!atime_needs_update(path, inode)) - return; + return 0; if (!sb_start_write_trylock(inode->i_sb)) - return; + return 0; if (__mnt_want_write(mnt) != 0) goto skip_update; @@ -1989,6 +1989,7 @@ void touch_atime(const struct path *path) __mnt_drop_write(mnt); skip_update: sb_end_write(inode->i_sb); + return 0; } EXPORT_SYMBOL(touch_atime); diff --git a/fs/namei.c b/fs/namei.c index e56ff39a79bc..35731d405730 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1776,12 +1776,12 @@ static const char *pick_link(struct nameidata *nd, struct path *link, return ERR_PTR(-ELOOP); if (!(nd->flags & LOOKUP_RCU)) { - touch_atime(&last->link); + touch_atime(&last->link, false); cond_resched(); } else if (atime_needs_update(&last->link, inode)) { if (!try_to_unlazy(nd)) return ERR_PTR(-ECHILD); - touch_atime(&last->link); + touch_atime(&last->link, false); } error = security_inode_follow_link(link->dentry, inode, diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 8a2321d19194..3179e7b5d209 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -1569,7 +1569,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp) if (unlikely(!d_is_symlink(path.dentry))) return nfserr_inval; - touch_atime(&path); + touch_atime(&path, false); link = vfs_get_link(path.dentry, &done); if (IS_ERR(link)) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 21245b00722a..6ff466ef98ea 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -255,7 +255,7 @@ static void ovl_file_accessed(struct file *file) inode->i_ctime = upperinode->i_ctime; } - touch_atime(&file->f_path); + touch_atime(&file->f_path, false); } static rwf_t ovl_iocb_to_rwf(int ifl) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index a63e57447be9..66e03025e748 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -703,7 +703,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags) }; if (upperpath.dentry) { - touch_atime(&upperpath); + touch_atime(&upperpath, false); inode->i_atime = d_inode(upperpath.dentry)->i_atime; } } diff --git a/fs/stat.c b/fs/stat.c index 7c238da22ef0..713773e61110 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -485,7 +485,7 @@ static int do_readlinkat(int dfd, const char __user *pathname, if (d_is_symlink(path.dentry) || inode->i_op->readlink) { error = security_inode_readlink(path.dentry); if (!error) { - touch_atime(&path); + touch_atime(&path, false); error = vfs_readlink(path.dentry, buf, bufsiz); } } diff --git a/include/linux/fs.h b/include/linux/fs.h index f3e315e8efdd..ba54879089ac 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2201,13 +2201,13 @@ enum file_time_flags { }; extern bool atime_needs_update(const struct path *, struct inode *); -extern void touch_atime(const struct path *); +extern int touch_atime(const struct path *path, bool nowait); int inode_update_time(struct inode *inode, struct timespec64 *time, int flags); static inline void file_accessed(struct file *file) { if (!(file->f_flags & O_NOATIME)) - touch_atime(&file->f_path); + touch_atime(&file->f_path, false); } extern int file_modified(struct file *file); diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c index 4174f76133df..bc020b45d5c8 100644 --- a/kernel/bpf/inode.c +++ b/kernel/bpf/inode.c @@ -517,7 +517,7 @@ static void *bpf_obj_do_get(int path_fd, const char __user *pathname, raw = bpf_any_get(inode->i_private, *type); if (!IS_ERR(raw)) - touch_atime(&path); + touch_atime(&path, false); path_put(&path); return raw; @@ -591,7 +591,7 @@ struct bpf_prog *bpf_prog_get_type_path(const char *name, enum bpf_prog_type typ return ERR_PTR(ret); prog = __get_prog_inode(d_backing_inode(path.dentry), type); if (!IS_ERR(prog)) - touch_atime(&path); + touch_atime(&path, false); path_put(&path); return prog; } diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 123b35ddfd71..5868e4e47320 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -1084,7 +1084,7 @@ static struct sock *unix_find_bsd(struct sockaddr_un *sunaddr, int addr_len, err = -EPROTOTYPE; if (sk->sk_type == type) - touch_atime(&path); + touch_atime(&path, false); else goto sock_put; @@ -1114,7 +1114,7 @@ static struct sock *unix_find_abstract(struct net *net, dentry = unix_sk(sk)->path.dentry; if (dentry) - touch_atime(&unix_sk(sk)->path); + touch_atime(&unix_sk(sk)->path, false); return sk; } From patchwork Sun Aug 27 13:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367213 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 203C5C83F12 for ; Sun, 27 Aug 2023 13:34:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3543280006; Sun, 27 Aug 2023 09:34:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE5918E0001; Sun, 27 Aug 2023 09:34:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9875B280006; Sun, 27 Aug 2023 09:34:13 -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 8851A8E0001 for ; Sun, 27 Aug 2023 09:34:13 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5830A8013D for ; Sun, 27 Aug 2023 13:34:13 +0000 (UTC) X-FDA: 81169978386.13.0ED8677 Received: from out-244.mta1.migadu.com (out-244.mta1.migadu.com [95.215.58.244]) by imf13.hostedemail.com (Postfix) with ESMTP id 86ADF2000E for ; Sun, 27 Aug 2023 13:34:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="QVXx/bTw"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.244 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143251; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8SowR/5OB7dg0Ze+leVLqrAkBaJI/dvgnJq74oNV+rw=; b=VAd9Mpdm5l8uvJ4KmQ2/OTcFyXq6q7u3vcxLU8q4dktjFu/OyklBBoVIudxqv9m33Uznqr EFdDDwkexzVvlg92lHba8vhgHWyqlaCUkWTmG2xa+UenCoJLU3w1NSTWClw4+umdxwJfqm 2xjGxOo9/bZJ2Km/NKDhFOq8tqXrNWM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="QVXx/bTw"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf13.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.244 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143251; a=rsa-sha256; cv=none; b=fQJP45k3NMx77AAzsAyXXgw/rYmPA6cUQ4ffVtY4P/S4Gs5j0JExNJWirwQR4ctufgP2XA Ryg+9+/Rf+rTVxUgnufdi4wLqvKFW9g5QosHt2KTRGhCBYXXIKIXBMUg/F9dsWL4m6z553 0fDJDRZHYI7iM1FgHjeZbgbbDoW7bC8= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8SowR/5OB7dg0Ze+leVLqrAkBaJI/dvgnJq74oNV+rw=; b=QVXx/bTwdFCK3FigE3bkCbe2czyripMyGLUg4h+GStpxVumOjkcqldjziNgtEa+JIjEIdw 2WdW9WAenCowl3yazyOwy/6Hrh3GC232u8ThOV7lZj17P/Dz8FfBitp2VsRMXLtCnx4lHo En1h8t6fO7bO07ca/V9kDbVI82xb9qY= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 07/11] vfs: add nowait parameter for file_accessed() Date: Sun, 27 Aug 2023 21:28:31 +0800 Message-Id: <20230827132835.1373581-8-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 86ADF2000E X-Stat-Signature: i4hggsorxce3c7u51a6x7f5xfg8gfffr X-HE-Tag: 1693143251-177356 X-HE-Meta: U2FsdGVkX1/lTao+7twchYQs81Wh4nBX3MYtYcZYvEPFnstRJfk/gu2yaMzkVKxuRH3Wmjhawr1MmDomYkl2aq5pY4rHRVdWVDYHpTkzC2ldQuWLRjsKY9HwBKQD+sivstNDqCNL5V3lE1GEdaZ+/T7kQJ38sVhz5THa4d7x0/X5FJO/RrAUYBatXIZ+ySrqYPFgP12l2LJlPRiCc8n7EkMRNwj1ipgXzchZiJ3jol92Yf5zpRgfy7jYopjYiaFaFxZAn+vO8OVlqclgmzH5zsQASrucc/UTD0LNP1fR2YIdDRQR6jhi1Y7cViAavmOjBcSywSuWOzdc/jEDT2LOLgCce/e9zXqzjdaIpmpSe5cxY3w/VUOXgMWtovlNJ2JwtjSVxEVyvmtmV9zigCPKB2ttT+GjhxbhjyXnbRnShSvFOARSRKqkWjm66RElOcEUjzVR0y0kVgvvkZoE3bpqKib3jGrdWYmZ0y8PS/YoD20disiMLBAJwPyfrFbWYcx5pwY2j2k1XD+xsRgiYgoSaNIOqS33Qu1YResKEts9D6Z0N9Qqbxrll73+cSo+IibI31kz/hPTew+ZmZ+wPBngIbi9qDDoUZz8OoMvwGlZ4TTTP85qVZ+h3i3Ilh/o2hOCOyNgBieRBvntdjQktLbiK1B2UA6AWlLpDFsB6HsgcLaY3qGhPX/leMENNvZCGtP4qjQYA9vJUWjki8Vy53wHytXn1mIXidx2esDHjWUYWO6WY6syPqhOLSMQNgfHcZd5aSk/GjLaPch/Eb8Xs9usqnOiv0Ojl6K8t44v4YDDf1I94zw15w8Lr2fBcF3Ahi9ZRtyzEZmpj1AJpiy2VrO7SnP29585waO+o95A3TcRC6Z4Hca2bbmfAunPSkpf1ULYgWIug+oVnBq/O+nm0HlNiOo30Gvm/9GsqzxTesvzgYZwqhnGDdsyBBJwpllJV8Y4CiX9qdZ9MRaTXkJDaol SbSYCkT1 ZVavZuWBh7whrSvgKzAyUeR9w1/GxhWvEs6VVW0mhjLTcFrFZmo8x3wPDoVv9H6RqdlyQjEz9w1RYcm+FZxucl+mu/Q2zb2yuJoh5KUmf6UK/qXwYlHO1tX5XsRXxTQBhp0m0ufsfOHKJHXB2kPxDEfTDxk4abiazeVF+cJneBxMYGAdar+TDJVdnNckLiAppM4T74mr3NbxA5lo9YEDc/ov27cTT1wrRMZby0+6HEdeGyQlX/a47SaLMlt1LUn7jhTKk1MPwcTr7stHyOZEiiOHiuHQPlqHHZPQdtR+EMivoqp1ESiY3Z6erA1DW52jCHv5zSVKOSiSQrtg= 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: From: Hao Xu Add a boolean parameter for file_accessed() to support nowait semantics. Currently it is true only with io_uring as its initial caller. Signed-off-by: Hao Xu --- arch/s390/hypfs/inode.c | 2 +- block/fops.c | 2 +- fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/coda/dir.c | 4 ++-- fs/ext2/file.c | 4 ++-- fs/ext4/file.c | 6 +++--- fs/f2fs/file.c | 4 ++-- fs/fuse/dax.c | 2 +- fs/fuse/file.c | 4 ++-- fs/gfs2/file.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/nilfs2/file.c | 2 +- fs/orangefs/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/pipe.c | 2 +- fs/ramfs/file-nommu.c | 2 +- fs/readdir.c | 2 +- fs/smb/client/cifsfs.c | 2 +- fs/splice.c | 2 +- fs/ubifs/file.c | 2 +- fs/udf/file.c | 2 +- fs/xfs/xfs_file.c | 6 +++--- fs/zonefs/file.c | 4 ++-- include/linux/fs.h | 5 +++-- mm/filemap.c | 8 ++++---- mm/shmem.c | 6 +++--- 27 files changed, 43 insertions(+), 42 deletions(-) diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c index ee919bfc8186..55f562027c4f 100644 --- a/arch/s390/hypfs/inode.c +++ b/arch/s390/hypfs/inode.c @@ -157,7 +157,7 @@ static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to) if (!count) return -EFAULT; iocb->ki_pos = pos + count; - file_accessed(file); + file_accessed(file, false); return count; } diff --git a/block/fops.c b/block/fops.c index a286bf3325c5..546ecd3c8084 100644 --- a/block/fops.c +++ b/block/fops.c @@ -601,7 +601,7 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = kiocb_write_and_wait(iocb, count); if (ret < 0) goto reexpand; - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); ret = blkdev_direct_IO(iocb, to); if (ret >= 0) { diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index fd03e689a6be..24c0bf3818a6 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2013,7 +2013,7 @@ static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma) if (!mapping->a_ops->read_folio) return -ENOEXEC; - file_accessed(filp); + file_accessed(filp, false); vma->vm_ops = &btrfs_file_vm_ops; return 0; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index dbbb67293e34..50e9ae8c388c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10153,7 +10153,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, struct extent_map *em; bool unlocked = false; - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); btrfs_inode_lock(inode, BTRFS_ILOCK_SHARED); diff --git a/fs/coda/dir.c b/fs/coda/dir.c index 8450b1bd354b..1d94c013ac88 100644 --- a/fs/coda/dir.c +++ b/fs/coda/dir.c @@ -436,12 +436,12 @@ static int coda_readdir(struct file *coda_file, struct dir_context *ctx) if (host_file->f_op->iterate_shared) { inode_lock_shared(host_inode); ret = host_file->f_op->iterate_shared(host_file, ctx); - file_accessed(host_file); + file_accessed(host_file, false); inode_unlock_shared(host_inode); } else { inode_lock(host_inode); ret = host_file->f_op->iterate(host_file, ctx); - file_accessed(host_file); + file_accessed(host_file, false); inode_unlock(host_inode); } } diff --git a/fs/ext2/file.c b/fs/ext2/file.c index 0b4c91c62e1f..dc059cae50a4 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -44,7 +44,7 @@ static ssize_t ext2_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = dax_iomap_rw(iocb, to, &ext2_iomap_ops); inode_unlock_shared(inode); - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); return ret; } @@ -127,7 +127,7 @@ static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) if (!IS_DAX(file_inode(file))) return generic_file_mmap(file, vma); - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &ext2_dax_vm_ops; return 0; } diff --git a/fs/ext4/file.c b/fs/ext4/file.c index c457c8517f0f..2ab790a668a8 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -94,7 +94,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = iomap_dio_rw(iocb, to, &ext4_iomap_ops, NULL, 0, NULL, 0); inode_unlock_shared(inode); - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); return ret; } @@ -122,7 +122,7 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = dax_iomap_rw(iocb, to, &ext4_iomap_ops); inode_unlock_shared(inode); - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); return ret; } #endif @@ -820,7 +820,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) if (!daxdev_mapping_supported(vma, dax_dev)) return -EOPNOTSUPP; - file_accessed(file); + file_accessed(file, false); if (IS_DAX(file_inode(file))) { vma->vm_ops = &ext4_dax_vm_ops; vm_flags_set(vma, VM_HUGEPAGE); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 093039dee992..246e61d78f92 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -524,7 +524,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma) if (!f2fs_is_compress_backend_ready(inode)) return -EOPNOTSUPP; - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &f2fs_file_vm_ops; set_inode_flag(inode, FI_MMAP_FILE); return 0; @@ -4380,7 +4380,7 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) f2fs_up_read(&fi->i_gc_rwsem[READ]); - file_accessed(file); + file_accessed(file, false); out: trace_f2fs_direct_IO_exit(inode, pos, count, READ, ret); return ret; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 8e74f278a3f6..8a43c37195dd 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -858,7 +858,7 @@ static const struct vm_operations_struct fuse_dax_vm_ops = { int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma) { - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &fuse_dax_vm_ops; vm_flags_set(vma, VM_MIXEDMAP | VM_HUGEPAGE); return 0; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index bc4115288eec..3c4cbc5e2de6 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2496,7 +2496,7 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) fuse_link_write_file(file); - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &fuse_file_vm_ops; return 0; } @@ -3193,7 +3193,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, clear_bit(FUSE_I_SIZE_UNSTABLE, &fi_out->state); inode_unlock(inode_out); - file_accessed(file_in); + file_accessed(file_in, false); fuse_flush_time_update(inode_out); diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 1bf3c4453516..3003be5b8266 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c @@ -601,7 +601,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) return error; /* grab lock to update inode */ gfs2_glock_dq_uninit(&i_gh); - file_accessed(file); + file_accessed(file, false); } vma->vm_ops = &gfs2_vm_ops; diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 7b17ccfa039d..729f66346c3c 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -161,7 +161,7 @@ static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) return -EINVAL; inode_lock(inode); - file_accessed(file); + file_accessed(file, false); ret = -ENOMEM; if (!hugetlb_reserve_pages(inode, diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index a9eb3487efb2..a857ebcf099c 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c @@ -119,7 +119,7 @@ static const struct vm_operations_struct nilfs_file_vm_ops = { static int nilfs_file_mmap(struct file *file, struct vm_area_struct *vma) { - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &nilfs_file_vm_ops; return 0; } diff --git a/fs/orangefs/file.c b/fs/orangefs/file.c index d68372241b30..5c7a17995fe1 100644 --- a/fs/orangefs/file.c +++ b/fs/orangefs/file.c @@ -412,7 +412,7 @@ static int orangefs_file_mmap(struct file *file, struct vm_area_struct *vma) /* set the sequential readahead hint */ vm_flags_mod(vma, VM_SEQ_READ, VM_RAND_READ); - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &orangefs_file_vm_ops; return 0; } diff --git a/fs/orangefs/inode.c b/fs/orangefs/inode.c index 9014bbcc8031..77d56703bb09 100644 --- a/fs/orangefs/inode.c +++ b/fs/orangefs/inode.c @@ -597,7 +597,7 @@ static ssize_t orangefs_direct_IO(struct kiocb *iocb, ret = total_count; if (ret > 0) { if (type == ORANGEFS_IO_READ) { - file_accessed(file); + file_accessed(file, false); } else { file_update_time(file); if (*offset > i_size_read(inode)) diff --git a/fs/pipe.c b/fs/pipe.c index 2d88f73f585a..ce1038d3de4b 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -393,7 +393,7 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to) wake_up_interruptible_sync_poll(&pipe->rd_wait, EPOLLIN | EPOLLRDNORM); kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT); if (ret > 0) - file_accessed(filp); + file_accessed(filp, false); return ret; } diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index efb1b4c1a0a4..ad69f828f6ad 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c @@ -267,7 +267,7 @@ static int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma) if (!is_nommu_shared_mapping(vma->vm_flags)) return -ENOSYS; - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &generic_file_vm_ops; return 0; } diff --git a/fs/readdir.c b/fs/readdir.c index b80caf4c9321..2f4c9c663a39 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -68,7 +68,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = file->f_op->iterate(file, ctx); file->f_pos = ctx->pos; fsnotify_access(file); - file_accessed(file); + file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); } if (shared) inode_unlock_shared(inode); diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index a4d8b0ea1c8c..20156c5e83e6 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1307,7 +1307,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, rc = target_tcon->ses->server->ops->copychunk_range(xid, smb_file_src, smb_file_target, off, len, destoff); - file_accessed(src_file); + file_accessed(src_file, false); /* force revalidate of size and timestamps of target file now * that target is updated on the server diff --git a/fs/splice.c b/fs/splice.c index 004eb1c4ce31..e4dcfa1c0fef 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1104,7 +1104,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, done: pipe->tail = pipe->head = 0; - file_accessed(in); + file_accessed(in, false); return bytes; read_failure: diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c index 6738fe43040b..a27c73848571 100644 --- a/fs/ubifs/file.c +++ b/fs/ubifs/file.c @@ -1603,7 +1603,7 @@ static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_ops = &ubifs_file_vm_ops; if (IS_ENABLED(CONFIG_UBIFS_ATIME_SUPPORT)) - file_accessed(file); + file_accessed(file, false); return 0; } diff --git a/fs/udf/file.c b/fs/udf/file.c index 243840dc83ad..46edf6e64632 100644 --- a/fs/udf/file.c +++ b/fs/udf/file.c @@ -191,7 +191,7 @@ static int udf_release_file(struct inode *inode, struct file *filp) static int udf_file_mmap(struct file *file, struct vm_area_struct *vma) { - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &udf_file_vm_ops; return 0; diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 4f502219ae4f..c72efdb9e43e 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -227,7 +227,7 @@ xfs_file_dio_read( if (!iov_iter_count(to)) return 0; /* skip atime */ - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED); if (ret) @@ -257,7 +257,7 @@ xfs_file_dax_read( ret = dax_iomap_rw(iocb, to, &xfs_read_iomap_ops); xfs_iunlock(ip, XFS_IOLOCK_SHARED); - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); return ret; } @@ -1434,7 +1434,7 @@ xfs_file_mmap( if (!daxdev_mapping_supported(vma, target->bt_daxdev)) return -EOPNOTSUPP; - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &xfs_file_vm_ops; if (IS_DAX(inode)) vm_flags_set(vma, VM_HUGEPAGE); diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index 92c9aaae3663..664ebae181bd 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -323,7 +323,7 @@ static int zonefs_file_mmap(struct file *file, struct vm_area_struct *vma) (vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) return -EINVAL; - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &zonefs_file_vm_ops; return 0; @@ -736,7 +736,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) ret = -EINVAL; goto inode_unlock; } - file_accessed(iocb->ki_filp); + file_accessed(iocb->ki_filp, false); ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops, &zonefs_read_dio_ops, 0, NULL, 0); } else { diff --git a/include/linux/fs.h b/include/linux/fs.h index ba54879089ac..ed60b3d70d1e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2204,10 +2204,11 @@ extern bool atime_needs_update(const struct path *, struct inode *); extern int touch_atime(const struct path *path, bool nowait); int inode_update_time(struct inode *inode, struct timespec64 *time, int flags); -static inline void file_accessed(struct file *file) +static inline int file_accessed(struct file *file, bool nowait) { if (!(file->f_flags & O_NOATIME)) - touch_atime(&file->f_path, false); + return touch_atime(&file->f_path, nowait); + return 0; } extern int file_modified(struct file *file); diff --git a/mm/filemap.c b/mm/filemap.c index 9e44a49bbd74..1f2032f4fd10 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2723,7 +2723,7 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter, folio_batch_init(&fbatch); } while (iov_iter_count(iter) && iocb->ki_pos < isize && !error); - file_accessed(filp); + file_accessed(filp, false); return already_read ? already_read : error; } @@ -2809,7 +2809,7 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) retval = kiocb_write_and_wait(iocb, count); if (retval < 0) return retval; - file_accessed(file); + file_accessed(file, false); retval = mapping->a_ops->direct_IO(iocb, iter); if (retval >= 0) { @@ -2978,7 +2978,7 @@ ssize_t filemap_splice_read(struct file *in, loff_t *ppos, out: folio_batch_release(&fbatch); - file_accessed(in); + file_accessed(in, false); return total_spliced ? total_spliced : error; } @@ -3613,7 +3613,7 @@ int generic_file_mmap(struct file *file, struct vm_area_struct *vma) if (!mapping->a_ops->read_folio) return -ENOEXEC; - file_accessed(file); + file_accessed(file, false); vma->vm_ops = &generic_file_vm_ops; return 0; } diff --git a/mm/shmem.c b/mm/shmem.c index 2f2e0e618072..440b23e2d9e1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2317,7 +2317,7 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) /* arm64 - allow memory tagging on RAM-based files */ vm_flags_set(vma, VM_MTE_ALLOWED); - file_accessed(file); + file_accessed(file, false); /* This is anonymous shared memory if it is unlinked at the time of mmap */ if (inode->i_nlink) vma->vm_ops = &shmem_vm_ops; @@ -2727,7 +2727,7 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) } *ppos = ((loff_t) index << PAGE_SHIFT) + offset; - file_accessed(file); + file_accessed(file, false); return retval ? retval : error; } @@ -2859,7 +2859,7 @@ static ssize_t shmem_file_splice_read(struct file *in, loff_t *ppos, if (folio) folio_put(folio); - file_accessed(in); + file_accessed(in, false); return total_spliced ? total_spliced : error; } From patchwork Sun Aug 27 13:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367214 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 655EAC83F1C for ; Sun, 27 Aug 2023 13:34:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0393F280007; Sun, 27 Aug 2023 09:34:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2BF48E0001; Sun, 27 Aug 2023 09:34:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1AB4280007; Sun, 27 Aug 2023 09:34:43 -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 D428C8E0001 for ; Sun, 27 Aug 2023 09:34:43 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id ABE4540157 for ; Sun, 27 Aug 2023 13:34:43 +0000 (UTC) X-FDA: 81169979646.26.1F2E2D8 Received: from out-248.mta1.migadu.com (out-248.mta1.migadu.com [95.215.58.248]) by imf09.hostedemail.com (Postfix) with ESMTP id 07D0614000E for ; Sun, 27 Aug 2023 13:34:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WXr39RUh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143282; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X5RgYva0uI/YfpMcRAQXXXC0hBNumZORbEO2XQnoCOE=; b=SdgEdMqLs5KY0mzGW1oUwKaMDhJtoTLolxo2Bx7DpbUgyv9bOnX7kih2cjgFgTFlVIDsg0 zvKNSVVl7dYvZke3riSNiVgV7hydqQ6RjC+Fx7/NjDFadU4Auy1+8FFyIZdGrZotlxFpJA kZgELk5t4dZhctwFeajDDXLNPyzqSYk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WXr39RUh; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143282; a=rsa-sha256; cv=none; b=cVZ/FswJsgptbRypdn9/KieY0yzZZcw3bYTAPvjFWH3VdCgXfSTsw0NOPJpzNqyy/jg4Yi zbIGq+ygRy+N1RwqPig4NZW8uQP//ZM5Ap8wgkUKt7fwW4gdYHaSKgYfAzkFiNNSbUMIu7 0IsZU4GY+7+3EQe2NbkPvR0rBi6PaNs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X5RgYva0uI/YfpMcRAQXXXC0hBNumZORbEO2XQnoCOE=; b=WXr39RUhGjmbBKUuqHmNng9tnfRreU8ks2ZtLjekYh53jHM4CnAQcsfBzBDABn1mkShot8 ZX46/udLE4Y2+Gp8W4OGBBchscS3B/zTnSSJs8rd29bz5YyB6Ia5W1tSVuXmmsCsWASJVj OhE3i3OIyl7cEamjJGJ1G7EdndXC44c= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 08/11] vfs: move file_accessed() to the beginning of iterate_dir() Date: Sun, 27 Aug 2023 21:28:32 +0800 Message-Id: <20230827132835.1373581-9-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: fxp1n1p1oj71jndf3jhe9qf8cikye7q1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 07D0614000E X-HE-Tag: 1693143281-7662 X-HE-Meta: U2FsdGVkX18LZe1/Uet1nfD4qbwc2jiOBDMriobD1LKmen0EBDbi/MPmLoBtgTqRPLyffzt8y7ccL/0VH7DVWGZi0EmGIe1ooRZhmRWVOE9eekq4PvxHkERg6c0WOlK8XFCgBHEycmYDpoGIuZdcPocqlRBJicD1oDb+B8Rfx+YSnIn0KigdF2YvQVsuO7rGG57u7w9H6gqqNS37N7XksSx9bojtOY8UpG9GSOmThXKUxj7ULLnB1RxuKfxSA3rGAOIp/9HGZSGsT+5PLr0QySL722g0sdLSESJqxIFfDcyQRBoeVGMdRYshLsZG8JCtkfqhXKgFslDFaNESthOGY8d28zt7xFfCr7A2fjG0n0+XeFlCApzR13SOSU0b59w7QBB0ShPV89bu5AvPvrRUJ3Q+n7x+iqaQNpFSaVC0Nd+ze/rqexfTZn00pYW4JgyoZ2RSlOipMT4ifXpNFq6qu0g9LxOt1SsspZBYLUzNLVpbc6ouogGKdVn981ybKApYqLWxNsmGp5xRhSHr4O5nTUtEqGb6Q/2l70LbNgSaaCiDo7CeKGO0jDJRn9d8CZFzR0+wArH1am5j45kuGyGUVWyuDGwWovvrLR5wuTf4IEgWH4HySsjUFclw2BgVQvswAJpzIF69wN/ANzhdd0u3ZfRTdCrRW4ZNbydzRvPar8xosevcezSirE762ze0tpp2YrnqjAYf9C03WrUszAVQjNSE5wnMDRQbvYJ7QWkyeZGi38BynaXXc3M7NYYKTzH+gRphE5LJgC9peVw+ZxARpWZy2Vzp4UNO6UfWgETeUZDsbNi38zo4Wj/C5w1m8iN3DMtHQVr5y22IMSvQ0lO1AGyM1gCF0HAjtJiTUYdDt0rBmW9z0yVYEgGAy96XeEllt+fFW+DEtx5z0vmoPOCXd/JuQ2Hjj/sSaf4+u4cc9i2BWWu+EwhR3T4Y0iYtWbbhs0TnC4aTNs5anJd2VEd 1M6BHaAd zIKr9mignvuq3F8aiPfuf2Gg7p9I8VxH6SxNXcMl2AUUMUdHYFYNN6Xks61GS6BICLs+9MtYNdj8uiX6Va/DJqUo++CDmd3EwDOMKRh5GAoAl1w0wrFQv7bER+9WpdBEdfsHtnLW9bZhX6KYqGWuL5y35TshdnHVuUVpJRF9FcYAa91JfSM3/+/n//HcerG+iAwM66trX7pxiJPfW0E4hR0oQWWPyBuh0nLml8VaK5OEO9pwYJq0O4ql0Sh4nRqQ2fJsoKHqCjaF69Cac4cB0WvTR8dOhwBZynZkJOpdBrfBTnnSyUIdnXOoSZKfBxWj75aZScbbsFGpPSG0= 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: From: Hao Xu Move file_accessed() to the beginning of iterate_dir() so that we don't need to rollback all the work done when file_accessed() returns -EAGAIN at the end of getdents. Signed-off-by: Hao Xu --- fs/readdir.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/readdir.c b/fs/readdir.c index 2f4c9c663a39..6469f076ba6e 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -61,6 +61,10 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = -ENOENT; if (!IS_DEADDIR(inode)) { + res = file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); + if (res == -EAGAIN) + goto out_unlock; + ctx->pos = file->f_pos; if (shared) res = file->f_op->iterate_shared(file, ctx); @@ -68,8 +72,9 @@ int iterate_dir(struct file *file, struct dir_context *ctx) res = file->f_op->iterate(file, ctx); file->f_pos = ctx->pos; fsnotify_access(file); - file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); } + +out_unlock: if (shared) inode_unlock_shared(inode); else From patchwork Sun Aug 27 13:28:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367215 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 17EC2C83F12 for ; Sun, 27 Aug 2023 13:35:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 988CA280008; Sun, 27 Aug 2023 09:35:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 911D88E0001; Sun, 27 Aug 2023 09:35:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DAA7280008; Sun, 27 Aug 2023 09:35:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6AFBD8E0001 for ; Sun, 27 Aug 2023 09:35:11 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 449B112020B for ; Sun, 27 Aug 2023 13:35:11 +0000 (UTC) X-FDA: 81169980822.17.302E99D Received: from out-248.mta1.migadu.com (out-248.mta1.migadu.com [95.215.58.248]) by imf17.hostedemail.com (Postfix) with ESMTP id 9621C4001B for ; Sun, 27 Aug 2023 13:35:09 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=S4P5Lis+; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143309; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=y42FYySYNsis5G3mORomW/nSivl81IaFtk7YSUfz0Jg=; b=rda03bFQ6ivbRxCWd/AZE7X5OUvju85iH/cNPF9oSnY7kLAwYczwxi3qu8K3u12UR+r2m3 oqGDzF1f9mUJVHKFrPQLx3m3NhrZIpc8+T5AxO35JNopLgUOl0EbRM6qliBNLGUGY5CwKw GgTLGnw1ARoZzwSX6fFfclYPlsdtmcs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=S4P5Lis+; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143309; a=rsa-sha256; cv=none; b=JoW/bEp1J1zObTv7SkCeLd5rcpOjTEFA1i5ER7xvFWxEPLBlOtZFJWzQK/W28N2VXijpBz uB50rqxxrheMPHg967X6mz+q+Vqcbz2xYEQBd8qbgLolwOO7WMvv4DBablT8MmtPcYQAmN U2zNOEGMFztvQAB7/u0a1BV5CNENuuM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y42FYySYNsis5G3mORomW/nSivl81IaFtk7YSUfz0Jg=; b=S4P5Lis+5UgxAXsbIFEQ0bJcfwW5bp3gD+5EV25w4Odl6XRzUJpaJGVaokRckJ9Hpyff0y QCMWQ876jzpmtvZlXQ4fdJDhdeygghENaAwk2aokCERTn3SKcsNlbNr+KPD/7nkWidZUEs LZ/LAlKjzWeA2HQHZTdX8ZHXdvIJ060= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 09/11] vfs: error out -EAGAIN if atime needs to be updated Date: Sun, 27 Aug 2023 21:28:33 +0800 Message-Id: <20230827132835.1373581-10-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 9621C4001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: dkkozftb6pceqoic9wtxaba8bfc4chpa X-HE-Tag: 1693143309-183887 X-HE-Meta: U2FsdGVkX1/WDR1KmOv5lzPn8lzpIYpahhc+NEAGQBK4UTT+1RHXG+O/WoBzTYVjSBnj9sN7rzjZiZFCTgF6eGgiB184l6n5WBeAAxEtNuHZAqzr8YoVRZEwouEkeKtv9+2kIaNRGO9ocnXz8CDaRp/Wv8/XDIPQwJLfPkvn/sNcHrQJ6XGehJWwRdZ2Srb50/Zw6jabnz8lsU1Nzs2aHG/uh8JveRfXaJMnWMIfMdUQzdp1Cd71rPUhTzV5nLySkG3Ixb3s9B1GS7Q9wZRNkDOqjL708JiiQP76kCRx0LsC871E1j279TJnMi6BUOlTVewa3oUVjzdTMayQ0Gc9PRlx4hLxe4mSzYbcT9aqM7UoadW8RnbI35HzFdU6gZKNljvHKrTWq7EHl/dKfdrSnwRnhDCcwytJq9LnefPlD6ii3hRGdQoOQh93bDPKg9Ve+fIvdngQKU1vxuDzOnWaGj8zuzx09WnXLjHWVFr1DlBcMPfKHkIhcBEJ1LPJekRhKYYMexeW8K8xisIH1G1GKbWA6wpm5IJE2yQg9AIyF1aF+jwFJiTfUoBHJIW380TEG3HlxQsc6xXpqSTfyMuLR6zEeF6lJQSrY+F4XDV1tHH/CUvuyz3RHvuBDG6WcDss7vy+/aCC6Rmhuoys4stZ65Y6+Bjgdq0A1R5BtsKgqnjPtLG/SevU21Sb5+7mv3Oz7ECj17oWK0KLsaf66UeGo2DNV2hXABiOP1Quqq1O/zfE5IFtCjIBuSXsjjn4g9ZnaP6uO0hxxy3CymRfJgMhV3hWNUf0WgJpmRIWWi2bGLBLqmBfg5+ZngkGxdAh+UEPVlx+TmZmn2mmuMRhYjzqlSmKXk+aM705di7F49S45PIIuvA4QcWg9t2AsgK9pQoX3vg1dTYWvyMO1nqU5o2e2SPUHu0PgjzMRmIIs93Rg1jYyYadhHbpf/4MBAeMfePEVdjWUncCB0pPk52lza2 qivjQG3F gWrLk5s3J33GR7WSRgpsJ509KOBoXcZ/Wr0PvVqhYu03U5VgT6BHY2oqs54uU56DMLx3Fl8FOsOtNh11CDYiuUaUr5rh+qx2WaBMGNwbrxNtaZwFjaV2kZcg0d5vV+K/OSBYd+tSYT5QIvsOWQn8NfNqqgRCQDAyhcVN0bPGS6+FXz5XEaFwFStgoSvCdB3+eAizNf8uhTxoaOFc= 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: From: Hao Xu To enforce nowait semantics, error out -EAGAIN if atime needs to be updated. Signed-off-by: Hao Xu --- fs/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index e83b836f2d09..32d81be65cf9 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1970,6 +1970,9 @@ int touch_atime(const struct path *path, bool nowait) if (!atime_needs_update(path, inode)) return 0; + if (nowait) + return -EAGAIN; + if (!sb_start_write_trylock(inode->i_sb)) return 0; From patchwork Sun Aug 27 13:28:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367216 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 E064FC83F11 for ; Sun, 27 Aug 2023 13:35:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 829D9280009; Sun, 27 Aug 2023 09:35:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B25B8E0001; Sun, 27 Aug 2023 09:35:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 67A80280009; Sun, 27 Aug 2023 09:35:37 -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 552948E0001 for ; Sun, 27 Aug 2023 09:35:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2D828A0223 for ; Sun, 27 Aug 2023 13:35:37 +0000 (UTC) X-FDA: 81169981914.14.4B9EB59 Received: from out-243.mta1.migadu.com (out-243.mta1.migadu.com [95.215.58.243]) by imf28.hostedemail.com (Postfix) with ESMTP id 7C6D8C0017 for ; Sun, 27 Aug 2023 13:35:35 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BRJIOv0s; spf=pass (imf28.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.243 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143335; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CL8wzJoAbQ75iZcN0EHSqoGXIWt+IFMvEgcKIhs6zqE=; b=OEAsLt3DMuKh/okYLaB20XudDotxF/HaZ3UgOC1IrG+xXppy3kVxz1t60w9q/0J4c0QA6s J66qlhXAerl5saiHdOD+xh9jtuxeHpNUDomPSoo2yzahlRnWGd0XIHpwhZhJFomVgx/mAP NKzcQpxVEFrVW+Vk4zZ+VzuRzPN19u0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143335; a=rsa-sha256; cv=none; b=UrwP0ecFsMl5RobbYiGO0bXmEEXe67/bufdkumY9PMG9YzwKBEx8Cer6kjV9PwbpgUO3P8 veSrSMXTHedlQgFgMsR+8jJVIS8oSlrO/Sq3kShBvzS8F3ezRDuYirHAulHWOgKlbW23tF xn/fNxUSHmMIWSRbpdkAOI1H0p7RvGY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BRJIOv0s; spf=pass (imf28.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.243 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CL8wzJoAbQ75iZcN0EHSqoGXIWt+IFMvEgcKIhs6zqE=; b=BRJIOv0sJCNWH9arCNNuOEeHNgvBAsJDXsD/9ROslY/E3EvWdOi7NTa+04JucH099rNnul 4aa7v7DjXCaaQfzVNr38jK1tfhfTVUIcRN9rZkXC1mcdwty8x7yMXlzmlXd+zl6Ur2HPps a6OaK6jfFgLdJwLH2JKSlhPncqJxHqY= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 10/11] vfs: trylock inode->i_rwsem in iterate_dir() to support nowait Date: Sun, 27 Aug 2023 21:28:34 +0800 Message-Id: <20230827132835.1373581-11-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 3nt796pmm6use594jcs5ddan9dcpudrn X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7C6D8C0017 X-Rspam-User: X-HE-Tag: 1693143335-616595 X-HE-Meta: U2FsdGVkX19kCQkO0UoFMiZtC4H3mtM3UNrnn7R6/tlp2HPIN0+TWJK7KwHZhcjxSvJs2gb8FdDUJHXxj23GVsWBvqOSc83Z+h1clRWwI/Xmxvt4m/xZLtYkUAkwZJ6l7RDUHSTO+xxstg1np2fy5OKgHlkRa0tm9ZXnTM2elLVGzLVKadZ7GCeTd8hTQfbBZx6E5jOuiOpEuPSJ6Gjms6OIyhOcL4ow+gC9+qtIzm+9jci5Jl9VsZHEJPWSIhMwqy2vHWVvTCqpyoIQJdCaxt1TzEYcLoqEgxZFX3m/iARm2aHreO/PrEKd9JzKQYKWrKp3SYS761qwWHhIBIecCF9AAp/Puvcp69FBsnZ1sYrrX6yJg+K/8xKu9Lpsd1X9fRU8CytLNodhLmYB+oixTkUDvb4x5yVdNsStEznt11EvsQXMhhaOj5ZRbOLvnOl518MGwOwqFEOXpqpbj5T9wS2HtA5OADFcb7RHwdbK9WBUV36pEWYRBsAlIRrpH9HE/61SCTk+6zjlI+nODL9M0EGm4tyaDI/FSW2qlF0dgwILa3kKr32tFBsZV6C1w1XvINzDLw5WJY3Sut4fkQnaCgJHoE4IqIGFRoxEyhi5BxMr6NkWM3YjCNcIkAUcwyszvhtrWvLuA01ZjNf2U3irqn0rdVYr4Tm+VlOSEY4Z2lsu/tTIQn3GGEulJ8Sa6zIHmiQDhq6CTTmH2zVZqkah/ARvr20qEaCi1lt4Dj90bu51oYmrArYNIMEvSGYGe4feR7F0Q9O8FbDuC/BMzubZeDJwKDgOe1B5mR2ravto7+HRg8nJDHzyvbDsefodocGELdGAaYRJP8Y+1KpJfAdDEkq1cF/de79vfOqgh5tk+icHkBAc60gLvv8Gc6w+YCluiVB4CJHd3oJ6M4RSnlZF+1Alvc3q1FWbTonxTI0rooR2+Nj5IVwVHdncNqYmfgsTTQ04SncovTVg/OjBjXH qOIvPt6g kpdCS1nPnzkn+UmtOukRU6Mhub8Vl3TK7oAq6nmJv1hbmLC8Q4dHY+TtLhpDQ8AOIgyUa1RhFDYM/zjtDJYTgPzOjeGeYzCXVGbc7uCEd/rkp00yk/D4DpnuD3sGaUIz1waM7FWOyxRQY8TwzJKMT1CeUh3O8KyCSXWSlmSPcnFCjAkq4aK0w2ssHQKJZC7ojsFZF7rKquJfx7rzOIZ/zoc/N1qtJavHcJDwKwvlsSK4t3blXOM3CqV8G+z2953XVw7XeJt2CZk72Bn/zWAEHHmqoBjT0LCjkj/AfJuPqhCQfb1KH4B6ZB+60CIvgOwhu7H1vBsXpAIsXQ4okbqjhIGCyIzhTQbPc+ok5BV9pivoa94wHwg8sWUoV5g== 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: From: Hao Xu Trylock inode->i_rwsem in iterate_dir() to support nowait semantics and error out -EAGAIN when there is contention. Signed-off-by: Hao Xu --- fs/readdir.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fs/readdir.c b/fs/readdir.c index 6469f076ba6e..664ecd9665a1 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -43,6 +43,8 @@ int iterate_dir(struct file *file, struct dir_context *ctx) struct inode *inode = file_inode(file); bool shared = false; int res = -ENOTDIR; + bool nowait; + if (file->f_op->iterate_shared) shared = true; else if (!file->f_op->iterate) @@ -52,16 +54,22 @@ int iterate_dir(struct file *file, struct dir_context *ctx) if (res) goto out; - if (shared) - res = down_read_killable(&inode->i_rwsem); - else - res = down_write_killable(&inode->i_rwsem); - if (res) + nowait = ctx->flags & DIR_CONTEXT_F_NOWAIT; + if (nowait) { + res = shared ? down_read_trylock(&inode->i_rwsem) : + down_write_trylock(&inode->i_rwsem); + if (!res) + res = -EAGAIN; + } else { + res = shared ? down_read_killable(&inode->i_rwsem) : + down_write_killable(&inode->i_rwsem); + } + if (res < 0) goto out; res = -ENOENT; if (!IS_DEADDIR(inode)) { - res = file_accessed(file, ctx->flags & DIR_CONTEXT_F_NOWAIT); + res = file_accessed(file, nowait); if (res == -EAGAIN) goto out_unlock; From patchwork Sun Aug 27 13:28:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13367217 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 F0A83C83F01 for ; Sun, 27 Aug 2023 13:36:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C55828000A; Sun, 27 Aug 2023 09:36:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E7D8E0001; Sun, 27 Aug 2023 09:36:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F08528000A; Sun, 27 Aug 2023 09:36:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 59DE08E0001 for ; Sun, 27 Aug 2023 09:36:30 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3A2FDB1B90 for ; Sun, 27 Aug 2023 13:36:30 +0000 (UTC) X-FDA: 81169984140.12.B0AB6C7 Received: from out-253.mta1.migadu.com (out-253.mta1.migadu.com [95.215.58.253]) by imf09.hostedemail.com (Postfix) with ESMTP id 5D9D2140013 for ; Sun, 27 Aug 2023 13:36:28 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u7n0PP5Y; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.253 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693143388; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NAMtHKwgj081g8lIPVs72MliioxtTYHj7D9CTN85ELE=; b=YAhHZGrSIj5/ExSADqgfyeFx9Vw4M8zDtbBmtAd02HzbtdocDqWKibyUzQ7M3FF+Zkq7ya cMZepgl4E9dhl8NyNUkl08mFZFVe1zJEs12XkLo2zxGVAwMmDKZDmDaugj7etaa9kzUCFx bNX65yGUcW/d2LtQNBkVW26FPcls64M= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u7n0PP5Y; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.253 as permitted sender) smtp.mailfrom=hao.xu@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693143388; a=rsa-sha256; cv=none; b=cYYgudTvdupwaoPQdhT9lZwWsXUOo7yJRY6DzsqCcLSZXfCjSG2prr64R0SeBY3PGl5sqT oz7RnnnDn1Ht1g55q4lKLdCu627Y1N5VlMqMimvp50XEDWLAO0crGw1+8AWT2kCRw3KEp8 5poX0U/iCf+oQZPqwEmmAigdZ1EYm4s= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693143386; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NAMtHKwgj081g8lIPVs72MliioxtTYHj7D9CTN85ELE=; b=u7n0PP5Y7t8pZAzx+5IbBJkZfY9azRKTfFVD9LVMOb4Thl+C2D6j0w7wWcMlmzcA25L4C8 zEudurGp2ODbmGylA6BsBPQ9105gr52QFoDr/T1ABSTboWT6yVGzUbuarS4ljsFfYjiAKI tkX7K8GiO8NfI2EeGspOsslEfgzb2IA= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 11/11] io_uring: add support for getdents Date: Sun, 27 Aug 2023 21:28:35 +0800 Message-Id: <20230827132835.1373581-12-hao.xu@linux.dev> In-Reply-To: <20230827132835.1373581-1-hao.xu@linux.dev> References: <20230827132835.1373581-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5D9D2140013 X-Stat-Signature: 8g7eicmy7nucgdrzigb3by1w8yfaec9x X-HE-Tag: 1693143388-749652 X-HE-Meta: U2FsdGVkX19wfzKCXi9B3MhiMtQJE06DpMfffEFacwl0LIC3f+Obk8Y8r5LsyUvIHBWHLKJCIvXbPzTeWUIkmNDTC3dRK+R1A1m+uTp9fSGsXnyamHk0xePBm7a93uwMUf69czGL+GyW1yHr+WgpOU6Du8x1gTaaEPTXDN1jvjJKlwZayMa9vQe90YPpLr9dLjidzN14hDcau3Xo+KngqGVv1gc39c4Jd9qtP/2BkvQ7864QJnjH/DzVYjexHu2fKGVdaO7UolOlwVmTuk3bWUgn7FMpLZmOc7SDuXgjMJqFObFeZe+5BNL8QAChCQ28wS7xc7lwVgN393y3fES+DJwlY/ON2DT7XULbOpWO2NigVEtkZgkLYui1GkFQ/PdaMgKANJcRLTc8JwvaDCbUS+VsRe0aECo0yF8bftoffnuZB94w1fUquf0sVt49DkVvotBltHPV+8kolCYsicPY91Q6Bd/xmxfG0j4rM0gopMQneUSgxUvrqsSGLJTIkeeswWg9epxitBQtSAOsAwbK8ISFPQoIliA5CRth859J7Byb4IIpCg8PbIDsbhgOpa+ZJNbR/JB7a/zh7iJlJ16/LHDU3Eyqy3rh2UtHdCNLr+Fr9wv5TfSO/qUZF3rqBVqHFKe8Kd6BHd3f2iY270BnFKDoDicL2WxBp9pSwP/U6Cbrm02v2GAtA1IsJcRXd3phk4Cr0jk7Wb9wbia+SY8FbyYjTsAbk5jiR2XRjMkkeEgFQMQEjpkHD+eGyDryTPD7y3w7kiXDbYSXhX4kSYEocmaIlmzg97usIKe4LBR5Z9rvO+0+lBFb/zVFIA+F+uNvftPX7v8/HenIhIUGVymuW89QoHSoVTh0zdoHqAiYfKdmrPRVMTpQLrhG0Ml24mPnFiMaktO3qq6kNkBVxs/f8j8zat2PviSDXf0zUTahKUxVYodd32btBNvLfUhYMrpNRrVDhCT7Pz9y6y5DwYR CVRGNgQ7 hMwnBuGt1lPlKirXi+7558d/K2r+vJq7HHoI3sbnXRRoGgdEdtWrzPjkuV06EOzkIyK3MkPmGrXkRIC08e+zpRPpYsB5Xtdc6p2HDolmTegEwN2zWzwIwh9Ni/fZUujFuI0kIOdYD6E3rD7JV31uxEKqbuoGZZusWFREeyJRS4DUAC7EmoSYTk3JgZZTXRoZaz3tNTsZkYKg7hd4t5C151iBVsSHoKX7rbtZZ0sRSIk3jM1dXrfhr33/9kClrk5m3nm1QpTWcTkCHlauVMygz4qXmi3hgFoI1blvuF3a//HO/MS8ix60Yi+lFEP3szkfqxhwLR/XZ+0IJ8V4jyVk5gPWkasDi6YRuih/+mgHenqmDNvHBFB28XtB21Fmc5nmS9O7MNYwQWDp+T0s= 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: From: Hao Xu This add support for getdents64 to io_uring, acting exactly like the syscall: the directory is iterated from it's current's position as stored in the file struct, and the file's position is updated exactly as if getdents64 had been called. For filesystems that support NOWAIT in iterate_shared(), try to use it first; if a user already knows the filesystem they use do not support nowait they can force async through IOSQE_ASYNC in the sqe flags, avoiding the need to bounce back through a useless EAGAIN return. Co-developed-by: Dominique Martinet Signed-off-by: Dominique Martinet Signed-off-by: Hao Xu --- include/uapi/linux/io_uring.h | 1 + io_uring/fs.c | 53 +++++++++++++++++++++++++++++++++++ io_uring/fs.h | 3 ++ io_uring/opdef.c | 8 ++++++ 4 files changed, 65 insertions(+) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 8e61f8b7c2ce..3896397a1998 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -240,6 +240,7 @@ enum io_uring_op { IORING_OP_URING_CMD, IORING_OP_SEND_ZC, IORING_OP_SENDMSG_ZC, + IORING_OP_GETDENTS, /* this goes last, obviously */ IORING_OP_LAST, diff --git a/io_uring/fs.c b/io_uring/fs.c index f6a69a549fd4..04711feac4e6 100644 --- a/io_uring/fs.c +++ b/io_uring/fs.c @@ -47,6 +47,12 @@ struct io_link { int flags; }; +struct io_getdents { + struct file *file; + struct linux_dirent64 __user *dirent; + unsigned int count; +}; + int io_renameat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { struct io_rename *ren = io_kiocb_to_cmd(req, struct io_rename); @@ -291,3 +297,50 @@ void io_link_cleanup(struct io_kiocb *req) putname(sl->oldpath); putname(sl->newpath); } + +int io_getdents_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) +{ + struct io_getdents *gd = io_kiocb_to_cmd(req, struct io_getdents); + + if (READ_ONCE(sqe->off)) + return -EINVAL; + + gd->dirent = u64_to_user_ptr(READ_ONCE(sqe->addr)); + gd->count = READ_ONCE(sqe->len); + + return 0; +} + +int io_getdents(struct io_kiocb *req, unsigned int issue_flags) +{ + struct io_getdents *gd = io_kiocb_to_cmd(req, struct io_getdents); + struct file *file = req->file; + unsigned long getdents_flags = 0; + bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; + bool locked; + int ret; + + if (force_nonblock) { + if (!(file->f_flags & O_NONBLOCK) && + !(file->f_mode & FMODE_NOWAIT)) + return -EAGAIN; + + getdents_flags = DIR_CONTEXT_F_NOWAIT; + } + + ret = file_pos_lock_nowait(file, force_nonblock); + if (ret == -EAGAIN) + return ret; + locked = ret; + + ret = vfs_getdents(file, gd->dirent, gd->count, getdents_flags); + if (locked) + file_pos_unlock(file); + + if (ret == -EAGAIN && force_nonblock) + return -EAGAIN; + + io_req_set_res(req, ret, 0); + return 0; +} + diff --git a/io_uring/fs.h b/io_uring/fs.h index 0bb5efe3d6bb..f83a6f3a678d 100644 --- a/io_uring/fs.h +++ b/io_uring/fs.h @@ -18,3 +18,6 @@ int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags); int io_linkat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_linkat(struct io_kiocb *req, unsigned int issue_flags); void io_link_cleanup(struct io_kiocb *req); + +int io_getdents_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); +int io_getdents(struct io_kiocb *req, unsigned int issue_flags); diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 3b9c6489b8b6..1bae6b2a8d0b 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -428,6 +428,11 @@ const struct io_issue_def io_issue_defs[] = { .prep = io_eopnotsupp_prep, #endif }, + [IORING_OP_GETDENTS] = { + .needs_file = 1, + .prep = io_getdents_prep, + .issue = io_getdents, + }, }; @@ -648,6 +653,9 @@ const struct io_cold_def io_cold_defs[] = { .fail = io_sendrecv_fail, #endif }, + [IORING_OP_GETDENTS] = { + .name = "GETDENTS", + }, }; const char *io_uring_get_opcode(u8 opcode)