summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/pci/drm/drm_linux.c7
-rw-r--r--sys/isofs/cd9660/cd9660_vnops.c4
-rw-r--r--sys/kern/kern_descrip.c14
-rw-r--r--sys/kern/kern_sysctl.c4
-rw-r--r--sys/kern/vfs_syscalls.c4
-rw-r--r--sys/kern/vfs_vnops.c16
-rw-r--r--sys/miscfs/fuse/fuse_vnops.c4
-rw-r--r--sys/msdosfs/msdosfs_vnops.c4
-rw-r--r--sys/nfs/nfs_kq.c4
-rw-r--r--sys/sys/file.h16
-rw-r--r--sys/tmpfs/tmpfs_vnops.c4
-rw-r--r--sys/ufs/ufs/ufs_vnops.c6
12 files changed, 58 insertions, 29 deletions
diff --git a/sys/dev/pci/drm/drm_linux.c b/sys/dev/pci/drm/drm_linux.c
index 641d21efd0d..4e77d829dbc 100644
--- a/sys/dev/pci/drm/drm_linux.c
+++ b/sys/dev/pci/drm/drm_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: drm_linux.c,v 1.46 2019/07/15 01:05:01 jsg Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.47 2019/08/05 08:35:59 anton Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@@ -1378,7 +1378,10 @@ dmabuf_seek(struct file *fp, off_t *offset, int whence, struct proc *p)
default:
return (EINVAL);
}
- fp->f_offset = *offset = newoff;
+ mtx_enter(&fp->f_mtx);
+ fp->f_offset = newoff;
+ mtx_leave(&fp->f_mtx);
+ *offset = newoff;
return (0);
}
diff --git a/sys/isofs/cd9660/cd9660_vnops.c b/sys/isofs/cd9660/cd9660_vnops.c
index 5a588bb1a4e..c05b3dc5941 100644
--- a/sys/isofs/cd9660/cd9660_vnops.c
+++ b/sys/isofs/cd9660/cd9660_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd9660_vnops.c,v 1.78 2019/07/12 13:56:27 solene Exp $ */
+/* $OpenBSD: cd9660_vnops.c,v 1.79 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: cd9660_vnops.c,v 1.42 1997/10/16 23:56:57 christos Exp $ */
/*-
@@ -1016,7 +1016,7 @@ filt_cd9660read(struct knote *kn, long hint)
return (1);
}
- kn->kn_data = node->i_size - kn->kn_fp->f_offset;
+ kn->kn_data = node->i_size - foffset(kn->kn_fp);
if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
kn->kn_fflags |= NOTE_EOF;
return (1);
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 7370a56b74a..d967d543b38 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_descrip.c,v 1.191 2019/07/15 04:11:03 visa Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.192 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
@@ -532,12 +532,14 @@ restart:
ktrflock(p, &fl);
#endif
if (fl.l_whence == SEEK_CUR) {
+ off_t offset = foffset(fp);
+
if (fl.l_start == 0 && fl.l_len < 0) {
/* lockf(3) compliance hack */
fl.l_len = -fl.l_len;
- fl.l_start = fp->f_offset - fl.l_len;
+ fl.l_start = offset - fl.l_len;
} else
- fl.l_start += fp->f_offset;
+ fl.l_start += offset;
}
switch (fl.l_type) {
@@ -602,12 +604,14 @@ restart:
if (error)
break;
if (fl.l_whence == SEEK_CUR) {
+ off_t offset = foffset(fp);
+
if (fl.l_start == 0 && fl.l_len < 0) {
/* lockf(3) compliance hack */
fl.l_len = -fl.l_len;
- fl.l_start = fp->f_offset - fl.l_len;
+ fl.l_start = offset - fl.l_len;
} else
- fl.l_start += fp->f_offset;
+ fl.l_start += offset;
}
if (fl.l_type != F_RDLCK &&
fl.l_type != F_WRLCK &&
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index f3bef1a20c0..73825840448 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.364 2019/07/16 17:39:02 bluhm Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.365 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -1102,8 +1102,8 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
kf->f_usecount = 0;
if (suser(p) == 0 || p->p_ucred->cr_uid == fp->f_cred->cr_uid) {
- kf->f_offset = fp->f_offset;
mtx_enter(&fp->f_mtx);
+ kf->f_offset = fp->f_offset;
kf->f_rxfer = fp->f_rxfer;
kf->f_rwfer = fp->f_wxfer;
kf->f_seek = fp->f_seek;
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 77f2fa0db30..96967678261 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.329 2019/08/04 08:42:29 bluhm Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.330 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -3034,7 +3034,9 @@ sys_getdents(struct proc *p, void *v, register_t *retval)
auio.uio_resid = buflen;
auio.uio_offset = fp->f_offset;
error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag);
+ mtx_enter(&fp->f_mtx);
fp->f_offset = auio.uio_offset;
+ mtx_leave(&fp->f_mtx);
VOP_UNLOCK(vp);
if (error)
goto bad;
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index c829aa20f07..28f2e469f37 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_vnops.c,v 1.103 2019/07/23 19:07:31 anton Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.104 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
@@ -365,8 +365,11 @@ vn_read(struct file *fp, struct uio *uio, int fflags)
error = VOP_READ(vp, uio, (fp->f_flag & FNONBLOCK) ? IO_NDELAY : 0,
cred);
- if ((fflags & FO_POSITION) == 0)
+ if ((fflags & FO_POSITION) == 0) {
+ mtx_enter(&fp->f_mtx);
fp->f_offset += count - uio->uio_resid;
+ mtx_leave(&fp->f_mtx);
+ }
done:
VOP_UNLOCK(vp);
KERNEL_UNLOCK();
@@ -401,10 +404,12 @@ vn_write(struct file *fp, struct uio *uio, int fflags)
count = uio->uio_resid;
error = VOP_WRITE(vp, uio, ioflag, cred);
if ((fflags & FO_POSITION) == 0) {
+ mtx_enter(&fp->f_mtx);
if (ioflag & IO_APPEND)
fp->f_offset = uio->uio_offset;
else
fp->f_offset += count - uio->uio_resid;
+ mtx_leave(&fp->f_mtx);
}
VOP_UNLOCK(vp);
@@ -504,7 +509,7 @@ vn_ioctl(struct file *fp, u_long com, caddr_t data, struct proc *p)
error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
if (error)
return (error);
- *(int *)data = vattr.va_size - fp->f_offset;
+ *(int *)data = vattr.va_size - foffset(fp);
return (0);
}
if (com == FIONBIO || com == FIOASYNC) /* XXX */
@@ -631,7 +636,10 @@ vn_seek(struct file *fp, off_t *offset, int whence, struct proc *p)
error = EINVAL;
goto out;
}
- fp->f_offset = *offset = newoff;
+ mtx_enter(&fp->f_mtx);
+ fp->f_offset = newoff;
+ mtx_leave(&fp->f_mtx);
+ *offset = newoff;
out:
VOP_UNLOCK(vp);
diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c
index 6de20b1744e..6bf5aad757d 100644
--- a/sys/miscfs/fuse/fuse_vnops.c
+++ b/sys/miscfs/fuse/fuse_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fuse_vnops.c,v 1.54 2019/07/12 13:56:27 solene Exp $ */
+/* $OpenBSD: fuse_vnops.c,v 1.55 2019/08/05 08:35:59 anton Exp $ */
/*
* Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
@@ -168,7 +168,7 @@ filt_fusefsread(struct knote *kn, long hint)
return (1);
}
- kn->kn_data = ip->filesize - kn->kn_fp->f_offset;
+ kn->kn_data = ip->filesize - foffset(kn->kn_fp);
if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
kn->kn_fflags |= NOTE_EOF;
return (1);
diff --git a/sys/msdosfs/msdosfs_vnops.c b/sys/msdosfs/msdosfs_vnops.c
index 9da3f95f632..f5e2cfd3784 100644
--- a/sys/msdosfs/msdosfs_vnops.c
+++ b/sys/msdosfs/msdosfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: msdosfs_vnops.c,v 1.125 2019/07/19 00:24:31 cheloha Exp $ */
+/* $OpenBSD: msdosfs_vnops.c,v 1.126 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.63 1997/10/17 11:24:19 ws Exp $ */
/*-
@@ -2017,7 +2017,7 @@ filt_msdosfsread(struct knote *kn, long hint)
return (1);
}
- kn->kn_data = dep->de_FileSize - kn->kn_fp->f_offset;
+ kn->kn_data = dep->de_FileSize - foffset(kn->kn_fp);
if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
kn->kn_fflags |= NOTE_EOF;
return (1);
diff --git a/sys/nfs/nfs_kq.c b/sys/nfs/nfs_kq.c
index a73847a9a2e..990f66651c0 100644
--- a/sys/nfs/nfs_kq.c
+++ b/sys/nfs/nfs_kq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfs_kq.c,v 1.24 2019/07/12 13:56:27 solene Exp $ */
+/* $OpenBSD: nfs_kq.c,v 1.25 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: nfs_kq.c,v 1.7 2003/10/30 01:43:10 simonb Exp $ */
/*-
@@ -226,7 +226,7 @@ filt_nfsread(struct knote *kn, long hint)
return (1);
}
- kn->kn_data = np->n_size - kn->kn_fp->f_offset;
+ kn->kn_data = np->n_size - foffset(kn->kn_fp);
#ifdef DEBUG
printf("nfsread event. %lld\n", kn->kn_data);
#endif
diff --git a/sys/sys/file.h b/sys/sys/file.h
index be123c063f3..7fb36a52b6a 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.h,v 1.57 2019/07/12 13:56:28 solene Exp $ */
+/* $OpenBSD: file.h,v 1.58 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
/*
@@ -74,6 +74,7 @@ struct fileops {
* F global `fhdlk' mutex
* a atomic operations
* f per file `f_mtx'
+ * v vnode lock
* k kernel lock
*/
struct file {
@@ -89,7 +90,7 @@ struct file {
u_int f_count; /* [a] reference count */
struct ucred *f_cred; /* [I] credentials associated with descriptor */
struct fileops *f_ops; /* [I] file operation pointers */
- off_t f_offset; /* [k] */
+ off_t f_offset; /* [f,v] offset */
void *f_data; /* [I] private data */
int f_iflags; /* [k] internal flags */
uint64_t f_rxfer; /* [f] total number of read transfers */
@@ -116,6 +117,17 @@ struct file {
int fdrop(struct file *, struct proc *);
+static inline off_t
+foffset(struct file *fp)
+{
+ off_t offset;
+
+ mtx_enter(&fp->f_mtx);
+ offset = fp->f_offset;
+ mtx_leave(&fp->f_mtx);
+ return (offset);
+}
+
LIST_HEAD(filelist, file);
extern int maxfiles; /* kernel limit on number of open files */
extern int numfiles; /* actual number of open files */
diff --git a/sys/tmpfs/tmpfs_vnops.c b/sys/tmpfs/tmpfs_vnops.c
index 81ad688fd84..857fcb47771 100644
--- a/sys/tmpfs/tmpfs_vnops.c
+++ b/sys/tmpfs/tmpfs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmpfs_vnops.c,v 1.35 2019/07/12 13:56:28 solene Exp $ */
+/* $OpenBSD: tmpfs_vnops.c,v 1.36 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: tmpfs_vnops.c,v 1.100 2012/11/05 17:27:39 dholland Exp $ */
/*
@@ -2645,7 +2645,7 @@ filt_tmpfsread(struct knote *kn, long hint)
return (1);
}
- kn->kn_data = node->tn_size - kn->kn_fp->f_offset;
+ kn->kn_data = node->tn_size - foffset(kn->kn_fp);
if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
kn->kn_fflags |= NOTE_EOF;
return (1);
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index fe4b92d0278..1956cf99155 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ufs_vnops.c,v 1.145 2019/07/12 13:56:28 solene Exp $ */
+/* $OpenBSD: ufs_vnops.c,v 1.146 2019/08/05 08:35:59 anton Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */
/*
@@ -1952,10 +1952,10 @@ filt_ufsread(struct knote *kn, long hint)
#ifdef EXT2FS
if (IS_EXT2_VNODE(ip->i_vnode))
- kn->kn_data = ext2fs_size(ip) - kn->kn_fp->f_offset;
+ kn->kn_data = ext2fs_size(ip) - foffset(kn->kn_fp);
else
#endif
- kn->kn_data = DIP(ip, size) - kn->kn_fp->f_offset;
+ kn->kn_data = DIP(ip, size) - foffset(kn->kn_fp);
if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) {
kn->kn_fflags |= NOTE_EOF;
return (1);