From nobody Fri Feb 04 23:31:42 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A5C7E19AEB2F; Fri, 4 Feb 2022 23:31:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JrBdC22DHz4gMt; Fri, 4 Feb 2022 23:31:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644017503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RSnZHWNuZI7f1mSaC5kuoYrsQFS2xvTgESYCt+qxOKs=; b=mgieKyXbmzzX6kwNQnEVDt4u1RSoynHdePTPOkdz5P7LtE+LktliKKnLaBGb7WvVbKayFj kNPuooOcQ3w60jLnQUeUCNQxKRMGgL4NFiC4qE2FvqPm5L76arJRjYiCNpoaBN1Z59vhd2 GgPmVwIR8tOLurPN/5le6b/hx2Ad6hnDIh97AysBUAjvlA9zIo/AcgK6LloJhhj2nWkBeb AX0Os2YmMDYLIhF8j1b4CyaxvzccLChVDJoMsC3VQAY9dKvCSg3xjG3JqplLtfbWRblOiJ QnqJd2VIIzRP1T5rTdFg0jlNrybo16LrY6AnasgT2Bz56f8JMr5arrc/SiD3Lw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0184814E2F; Fri, 4 Feb 2022 23:31:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 214NVgl1082681; Fri, 4 Feb 2022 23:31:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 214NVgjP082680; Fri, 4 Feb 2022 23:31:42 GMT (envelope-from git) Date: Fri, 4 Feb 2022 23:31:42 GMT Message-Id: <202202042331.214NVgjP082680@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 4a6526d84a56 - main - fusefs: optimize NFS readdir for FUSE_NO_OPENDIR_SUPPORT List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4a6526d84a56f398732bff491e63aa42f796a27d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644017503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RSnZHWNuZI7f1mSaC5kuoYrsQFS2xvTgESYCt+qxOKs=; b=XtcJtNZbrFMuxAzPN54SlJ4Nkf5m4pgJ70kUdYy/TgepGmC0TCHxt+yJkKf7+yk3CPZbRy PleGf4Y10cHg+DQtdYWa6caPrAvbwuKev7u78nNLO7cfg7qoFFgIgzTcPs1oqS0WJB4uPw LWHu2QdESBtBOPUHoD1rl/7r71I9VzB7p1wa7xDmuMvp8dV4VfiuebQ6y+ENh+F5QnWr6+ 6636SxHwQGDG51rykZiYRx8ngOQ/jzDFpMHPZp9qkKLnjsHHqijNGK4KbpU8BzXQ3e+rRu xTgsHwfQvtP25rer/vwttNDK8hGtiD9LZg7aLJnX7HvIWE3wlRy857rHvIDshQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644017503; a=rsa-sha256; cv=none; b=wg0iDSlA/nvyOUt71KuogHSS3XVTbKqldWveCSFof7cjCg+a1FF4qqS8g+gO+5qz0PdoXC 2KASp87qVqp4L4FNGbQASYIKNgM9g+I4Z35y2OrgHwNb0SaPgGlvK6H3u8X1k2J/sNDs0p tvrWH6UCXhPfMN8BaUq/iysBGQYNLbROhs4Fbjn1aGAhtiUdFp9ossSVdyQfGRjVKHEuPp IWfh/KHXFvNSp2fQlQIxb0PPoJQdjbvpTqXfK02F95yNFufxWD1VaI00+Aczae+aiRT+es Nvj6BBEVCMEVYX3gosjrHltbvRBKpDMg8BQ/SeBrQpqijwdvl2qDUHqGyUgB/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=4a6526d84a56f398732bff491e63aa42f796a27d commit 4a6526d84a56f398732bff491e63aa42f796a27d Author: Alan Somers AuthorDate: 2022-01-02 22:29:50 +0000 Commit: Alan Somers CommitDate: 2022-02-04 23:30:58 +0000 fusefs: optimize NFS readdir for FUSE_NO_OPENDIR_SUPPORT In its lowest common denominator, FUSE does not require that a directory entry's d_off field is valid outside of the lifetime of the directory's FUSE file handle. But since NFS is stateless, it must reopen the directory on every call to VOP_READDIR. That means reading the directory all the way from the first entry. Not only does this create an O(n^2) condition for large directories, but it can also result in incorrect behavior if either: * The file system _does_ change the d_off field for the last directory entry previously seen by NFS, or * The file system deletes the last directory entry previously seen by NFS. Handily, for file systems that set FUSE_NO_OPENDIR_SUPPORT d_off is guaranteed to be valid for the lifetime of the directory entry, there is no need to read the directory from the start. MFC after: 3 weeks Reviewed by: rmacklem --- sys/fs/fuse/fuse_vnops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index 259925f54d9f..da925b5dcbb5 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -1846,6 +1846,7 @@ fuse_vnop_readdir(struct vop_readdir_args *ap) struct uio *uio = ap->a_uio; struct ucred *cred = ap->a_cred; struct fuse_filehandle *fufh = NULL; + struct fuse_data *mpdata = fuse_get_mpdata(vnode_mount(vp)); struct fuse_iov cookediov; int err = 0; uint64_t *cookies; @@ -1874,13 +1875,14 @@ fuse_vnop_readdir(struct vop_readdir_args *ap) * must implicitly open the directory here */ err = fuse_filehandle_open(vp, FREAD, &fufh, curthread, cred); - if (err == 0) { + if (err == 0 && !(mpdata->dataflags & FSESS_NO_OPEN_SUPPORT)) { /* - * When a directory is opened, it must be read from - * the beginning. Hopefully, the "startoff" still - * exists as an offset cookie for the directory. - * If not, it will read the entire directory without - * returning any entries and just return eof. + * FUSE does not require a directory entry's d_off + * field to be valid outside of the lifetime of the + * directory's FUSE file handle. So we must read the + * directory from the beginning. However, if the file + * system sets FUSE_NO_OPENDIR_SUPPORT, then the d_off + * field will be valid for the lifetime of the dirent. */ uio->uio_offset = 0; }