Date: Mon, 11 Oct 2021 09:15:51 GMT From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: f312cc6e5627 - stable/13 - fifo: support flock Message-ID: <202110110915.19B9Fpc5009530@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=f312cc6e562736e1942ecb2da50c5b58bbbbd850 commit f312cc6e562736e1942ecb2da50c5b58bbbbd850 Author: Mateusz Guzik <mjg@FreeBSD.org> AuthorDate: 2021-09-25 12:24:39 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2021-10-11 09:12:48 +0000 fifo: support flock This evens it up with Linux. Original patch by: Greg V <greg@unrelenting.technology> Differential Revision: https://reviews.freebsd.org/D24255#565302 (cherry picked from commit d71e1a883c92b8b166eea59734850acd54048d72) --- sys/fs/fifofs/fifo_vnops.c | 4 +++- sys/kern/kern_descrip.c | 16 ++++++++++------ sys/kern/vfs_vnops.c | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sys/fs/fifofs/fifo_vnops.c b/sys/fs/fifofs/fifo_vnops.c index 861f1b40a744..1b941620b080 100644 --- a/sys/fs/fifofs/fifo_vnops.c +++ b/sys/fs/fifofs/fifo_vnops.c @@ -376,5 +376,7 @@ fifo_advlock(ap) } */ *ap; { - return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL); + if ((ap->a_flags & F_FLOCK) == 0) + return (EINVAL); + return (vop_stdadvlock(ap)); } diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index ed7fe83cf02f..58c2d1939dba 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3560,11 +3560,15 @@ sys_flock(struct thread *td, struct flock_args *uap) error = fget(td, uap->fd, &cap_flock_rights, &fp); if (error != 0) return (error); - if (fp->f_type != DTYPE_VNODE || fp->f_ops == &path_fileops) { - fdrop(fp, td); - return (EOPNOTSUPP); + error = EOPNOTSUPP; + if (fp->f_type != DTYPE_VNODE && fp->f_type != DTYPE_FIFO) { + goto done; + } + if (fp->f_ops == &path_fileops) { + goto done; } + error = 0; vp = fp->f_vnode; lf.l_whence = SEEK_SET; lf.l_start = 0; @@ -3573,7 +3577,7 @@ sys_flock(struct thread *td, struct flock_args *uap) lf.l_type = F_UNLCK; atomic_clear_int(&fp->f_flag, FHASLOCK); error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK); - goto done2; + goto done; } if (uap->how & LOCK_EX) lf.l_type = F_WRLCK; @@ -3581,12 +3585,12 @@ sys_flock(struct thread *td, struct flock_args *uap) lf.l_type = F_RDLCK; else { error = EBADF; - goto done2; + goto done; } atomic_set_int(&fp->f_flag, FHASLOCK); error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, (uap->how & LOCK_NB) ? F_FLOCK : F_FLOCK | F_WAIT); -done2: +done: fdrop(fp, td); return (error); } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 8ff78b9d6319..e8d6df5c4193 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1826,7 +1826,7 @@ vn_closefile(struct file *fp, struct thread *td) vp = fp->f_vnode; fp->f_ops = &badfileops; - ref = (fp->f_flag & FHASLOCK) != 0 && fp->f_type == DTYPE_VNODE; + ref = (fp->f_flag & FHASLOCK) != 0; error = vn_close1(vp, fp->f_flag, fp->f_cred, td, ref);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110110915.19B9Fpc5009530>