Index: sys/fs/fuse/fuse_internal.h =================================================================== --- sys/fs/fuse/fuse_internal.h +++ sys/fs/fuse/fuse_internal.h @@ -250,12 +250,12 @@ struct pseudo_dirent { uint32_t d_namlen; }; -int fuse_internal_readdir(struct vnode *vp, struct uio *uio, off_t startoff, +int fuse_internal_readdir(struct vnode *vp, struct uio *uio, struct fuse_filehandle *fufh, struct fuse_iov *cookediov, int *ncookies, uint64_t *cookies); -int fuse_internal_readdir_processdata(struct uio *uio, off_t startoff, - int *fnd_start, size_t reqsize, void *buf, size_t bufsize, - struct fuse_iov *cookediov, int *ncookies, uint64_t **cookiesp); +int fuse_internal_readdir_processdata(struct uio *uio, size_t reqsize, + void *buf, size_t bufsize, struct fuse_iov *cookediov, int *ncookies, + uint64_t **cookiesp); /* remove */ Index: sys/fs/fuse/fuse_internal.c =================================================================== --- sys/fs/fuse/fuse_internal.c +++ sys/fs/fuse/fuse_internal.c @@ -555,7 +555,6 @@ int fuse_internal_readdir(struct vnode *vp, struct uio *uio, - off_t startoff, struct fuse_filehandle *fufh, struct fuse_iov *cookediov, int *ncookies, @@ -564,7 +563,6 @@ int err = 0; struct fuse_dispatcher fdi; struct fuse_read_in *fri = NULL; - int fnd_start; if (uio_resid(uio) == 0) return 0; @@ -574,25 +572,9 @@ * Note that we DO NOT have a UIO_SYSSPACE here (so no need for p2p * I/O). */ - - /* - * fnd_start is set non-zero once the offset in the directory gets - * to the startoff. This is done because directories must be read - * from the beginning (offset == 0) when fuse_vnop_readdir() needs - * to do an open of the directory. - * If it is not set non-zero here, it will be set non-zero in - * fuse_internal_readdir_processdata() when uio_offset == startoff. - */ - fnd_start = 0; - if (uio->uio_offset == startoff) - fnd_start = 1; while (uio_resid(uio) > 0) { fdi.iosize = sizeof(*fri); - if (fri == NULL) - fdisp_make_vp(&fdi, FUSE_READDIR, vp, NULL, NULL); - else - fdisp_refresh_vp(&fdi, FUSE_READDIR, vp, NULL, NULL); - + fdisp_make_vp(&fdi, FUSE_READDIR, vp, NULL, NULL); fri = fdi.indata; fri->fh = fufh->fh_id; fri->offset = uio_offset(uio); @@ -601,9 +583,8 @@ if ((err = fdisp_wait_answ(&fdi))) break; - if ((err = fuse_internal_readdir_processdata(uio, startoff, - &fnd_start, fri->size, fdi.answ, fdi.iosize, cookediov, - ncookies, &cookies))) + if ((err = fuse_internal_readdir_processdata(uio, fri->size, + fdi.answ, fdi.iosize, cookediov, ncookies, &cookies))) break; } @@ -618,8 +599,6 @@ */ int fuse_internal_readdir_processdata(struct uio *uio, - off_t startoff, - int *fnd_start, size_t reqsize, void *buf, size_t bufsize, @@ -673,39 +652,32 @@ err = -1; break; } - /* - * Don't start to copy the directory entries out until - * the requested offset in the directory is found. - */ - if (*fnd_start != 0) { - fiov_adjust(cookediov, oreclen); - bzero(cookediov->base, oreclen); - - de = (struct dirent *)cookediov->base; - de->d_fileno = fudge->ino; - de->d_off = fudge->off; - de->d_reclen = oreclen; - de->d_type = fudge->type; - de->d_namlen = fudge->namelen; - memcpy((char *)cookediov->base + sizeof(struct dirent) - - MAXNAMLEN - 1, - (char *)buf + FUSE_NAME_OFFSET, fudge->namelen); - dirent_terminate(de); - - err = uiomove(cookediov->base, cookediov->len, uio); - if (err) + fiov_adjust(cookediov, oreclen); + bzero(cookediov->base, oreclen); + + de = (struct dirent *)cookediov->base; + de->d_fileno = fudge->ino; + de->d_off = fudge->off; + de->d_reclen = oreclen; + de->d_type = fudge->type; + de->d_namlen = fudge->namelen; + memcpy((char *)cookediov->base + sizeof(struct dirent) - + MAXNAMLEN - 1, + (char *)buf + FUSE_NAME_OFFSET, fudge->namelen); + dirent_terminate(de); + + err = uiomove(cookediov->base, cookediov->len, uio); + if (err) + break; + if (cookies != NULL) { + if (*ncookies == 0) { + err = -1; break; - if (cookies != NULL) { - if (*ncookies == 0) { - err = -1; - break; - } - *cookies = fudge->off; - cookies++; - (*ncookies)--; } - } else if (startoff == fudge->off) - *fnd_start = 1; + *cookies = fudge->off; + cookies++; + (*ncookies)--; + } buf = (char *)buf + freclen; bufsize -= freclen; uio_setoffset(uio, fudge->off); Index: sys/fs/fuse/fuse_vnops.c =================================================================== --- sys/fs/fuse/fuse_vnops.c +++ sys/fs/fuse/fuse_vnops.c @@ -1857,7 +1857,6 @@ struct fuse_iov cookediov; int err = 0; uint64_t *cookies; - off_t startoff; ssize_t tresid; int ncookies; bool closefufh = false; @@ -1874,24 +1873,22 @@ } tresid = uio->uio_resid; - startoff = uio->uio_offset; err = fuse_filehandle_get_dir(vp, &fufh, cred, pid); if (err == EBADF && vnode_mount(vp)->mnt_flag & MNT_EXPORTED) { + /* + * If we get here, FSESS_NO_OPENDIR_SUPPORT should be set, but + * for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260894 + */ + /* + * KASSERT(mpdata->dataflags & FSESS_NO_OPENDIR_SUPPORT, + * ("FUSE file systems that don't set " + * "FUSE_NO_OPENDIR_SUPPORT should not be exported")); + */ /* * nfsd will do VOP_READDIR without first doing VOP_OPEN. We - * must implicitly open the directory here + * must implicitly open the directory here. */ err = fuse_filehandle_open(vp, FREAD, &fufh, curthread, cred); - if (err == 0) { - /* - * 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. - */ - uio->uio_offset = 0; - } closefufh = true; } if (err) @@ -1909,7 +1906,7 @@ #define DIRCOOKEDSIZE FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + MAXNAMLEN + 1) fiov_init(&cookediov, DIRCOOKEDSIZE); - err = fuse_internal_readdir(vp, uio, startoff, fufh, &cookediov, + err = fuse_internal_readdir(vp, uio, fufh, &cookediov, &ncookies, cookies); fiov_teardown(&cookediov); @@ -3006,8 +3003,30 @@ struct vattr va; int err; - if (!(data->dataflags & FSESS_EXPORT_SUPPORT)) + if (!(data->dataflags & FSESS_EXPORT_SUPPORT)) { + /* NFS requires lookups for "." and ".." */ + SDT_PROBE2(fusefs, , vnops, trace, 1, + "VOP_VPTOFH without FUSE_EXPORT_SUPPORT"); return EOPNOTSUPP; + } + if ((mp->mnt_flag & MNT_EXPORTED) && + !(data->dataflags & FSESS_NO_OPENDIR_SUPPORT)) + { + /* + * NFS is stateless, so nfsd must reopen a directory on every + * call to VOP_READDIR, passing in the d_off field from the + * final dirent of the previous invocation. But without + * FUSE_NO_OPENDIR_SUPPORT, the FUSE protocol does not + * guarantee that d_off will be valid after a directory is + * closed and reopened. So prohibit exporting FUSE file + * systems that don't set that flag. + * + * But userspace NFS servers don't have this problem. + */ + SDT_PROBE2(fusefs, , vnops, trace, 1, + "VOP_VPTOFH without FUSE_NO_OPENDIR_SUPPORT"); + return EOPNOTSUPP; + } err = fuse_internal_getattr(vp, &va, curthread->td_ucred, curthread); if (err)