Commit d71e1a88 authored by Mateusz Guzik's avatar Mateusz Guzik
Browse files

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
parent f766826f
......@@ -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));
}
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment