Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Sep 2021 15:36:58 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: d71e1a883c92 - main - fifo: support flock
Message-ID:  <202109251536.18PFawjc066062@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

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

commit d71e1a883c92b8b166eea59734850acd54048d72
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2021-09-25 12:24:39 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2021-09-25 14:58:31 +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
---
 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 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);
 



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