Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jun 2022 19:39:04 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 85575b7e0c7d - stable/13 - getdirentries: return ENOENT for unlinked but still open directory.
Message-ID:  <202206171939.25HJd4WR015528@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=85575b7e0c7d2e722559a44c2e246991eab2f2be

commit 85575b7e0c7d2e722559a44c2e246991eab2f2be
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2022-06-17 19:33:51 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2022-06-17 19:33:51 +0000

    getdirentries: return ENOENT for unlinked but still open directory.
    
    To be more compatible to IEEE Std 1003.1-2008 (“POSIX.1”).
    
    Reviewed by:            mjg, Pau Amma (doc)
    Differential revision:  https://reviews.freebsd.org/D34680
    MFC after:              2 weeks
    
    (cherry picked from commit c6487446d7e99537551d2e51a2f6c6569fcb89fc)
---
 lib/libc/sys/getdirentries.2 | 2 ++
 sys/kern/vfs_subr.c          | 1 +
 sys/kern/vfs_syscalls.c      | 4 ++++
 sys/sys/vnode.h              | 1 +
 4 files changed, 8 insertions(+)

diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2
index 4185fb84f0f9..76fe18bf6edb 100644
--- a/lib/libc/sys/getdirentries.2
+++ b/lib/libc/sys/getdirentries.2
@@ -193,6 +193,8 @@ An
 error occurred while reading from or writing to the file system.
 .It Bq Er EINTEGRITY
 Corrupted data was detected while reading from the file system.
+.It Bq Er ENOENT
+Directory unlinked but still open.
 .El
 .Sh SEE ALSO
 .Xr lseek 2 ,
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 753e0062e808..ca2d86385f4c 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -6021,6 +6021,7 @@ vop_rmdir_post(void *ap, int rc)
 	vn_seqc_write_end(dvp);
 	vn_seqc_write_end(vp);
 	if (!rc) {
+		vp->v_vflag |= VV_UNLINKED;
 		VFS_KNOTE_LOCKED(dvp, NOTE_WRITE | NOTE_LINK);
 		VFS_KNOTE_LOCKED(vp, NOTE_DELETE);
 	}
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 276383fce2a0..b8f2bf4f695c 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -4176,6 +4176,10 @@ unionread:
 		error = EINVAL;
 		goto fail;
 	}
+	if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) {
+		error = ENOENT;
+		goto fail;
+	}
 	aiov.iov_base = buf;
 	aiov.iov_len = count;
 	auio.uio_iov = &aiov;
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 92978eae8846..6d3e7eac8b23 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -272,6 +272,7 @@ struct xvnode {
 #define	VV_FORCEINSMQ	0x1000	/* force the insmntque to succeed */
 #define	VV_READLINK	0x2000	/* fdescfs linux vnode */
 #define	VV_UNREF	0x4000	/* vunref, do not drop lock in inactive() */
+#define	VV_UNLINKED	0x8000	/* unlinked but stil open directory */
 
 #define	VMP_LAZYLIST	0x0001	/* Vnode is on mnt's lazy list */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202206171939.25HJd4WR015528>