aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2021-09-25 12:24:39 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2021-09-25 14:58:31 +0000
commitd71e1a883c92b8b166eea59734850acd54048d72 (patch)
tree0271409504d23813f51496c15716ba813621f381
parentf766826fe3b82462c6397ec849dc2243f4bdfeee (diff)
downloadsrc-d71e1a883c92b8b166eea59734850acd54048d72.tar.gz
src-d71e1a883c92b8b166eea59734850acd54048d72.zip
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
-rw-r--r--sys/fs/fifofs/fifo_vnops.c4
-rw-r--r--sys/kern/kern_descrip.c16
-rw-r--r--sys/kern/vfs_vnops.c2
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 d4229160f11e..aeeeee3e3a1d 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1829,7 +1829,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);