Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys file(9): New fo_posix_fadvise operation.
details: https://anonhg.NetBSD.org/src/rev/fe97d0db0ba0
branches: trunk
changeset: 374415:fe97d0db0ba0
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Apr 22 13:53:02 2023 +0000
description:
file(9): New fo_posix_fadvise operation.
XXX kernel revbump -- changes struct fileops API and ABI
diffstat:
sys/kern/sys_descrip.c | 97 ++++---------------------------------------------
sys/kern/sys_pipe.c | 13 +++++-
sys/kern/sys_socket.c | 13 +++++-
sys/kern/vfs_vnops.c | 86 +++++++++++++++++++++++++++++++++++++++++++-
sys/sys/file.h | 4 +-
5 files changed, 117 insertions(+), 96 deletions(-)
diffs (truncated from 355 to 300 lines):
diff -r 69434b3fe130 -r fe97d0db0ba0 sys/kern/sys_descrip.c
--- a/sys/kern/sys_descrip.c Sat Apr 22 13:52:54 2023 +0000
+++ b/sys/kern/sys_descrip.c Sat Apr 22 13:53:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_descrip.c,v 1.42 2023/04/22 13:52:54 riastradh Exp $ */
+/* $NetBSD: sys_descrip.c,v 1.43 2023/04/22 13:53:02 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.42 2023/04/22 13:52:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.43 2023/04/22 13:53:02 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -650,98 +650,17 @@ sys_flock(struct lwp *l, const struct sy
int
do_posix_fadvise(int fd, off_t offset, off_t len, int advice)
{
- const off_t OFF_MAX = __type_max(off_t);
file_t *fp;
- vnode_t *vp;
- off_t endoffset;
int error;
- CTASSERT(POSIX_FADV_NORMAL == UVM_ADV_NORMAL);
- CTASSERT(POSIX_FADV_RANDOM == UVM_ADV_RANDOM);
- CTASSERT(POSIX_FADV_SEQUENTIAL == UVM_ADV_SEQUENTIAL);
-
- if (offset < 0) {
- return EINVAL;
- }
- if (len == 0) {
- endoffset = OFF_MAX;
- } else if (len > 0 && (OFF_MAX - offset) >= len) {
- endoffset = offset + len;
- } else {
- return EINVAL;
- }
- if ((fp = fd_getfile(fd)) == NULL) {
+ if ((fp = fd_getfile(fd)) == NULL)
return EBADF;
- }
- if (fp->f_type != DTYPE_VNODE) {
- if (fp->f_type == DTYPE_PIPE || fp->f_type == DTYPE_SOCKET) {
- error = ESPIPE;
- } else {
- error = EOPNOTSUPP;
- }
- fd_putfile(fd);
- return error;
- }
-
- switch (advice) {
- case POSIX_FADV_WILLNEED:
- case POSIX_FADV_DONTNEED:
- vp = fp->f_vnode;
- if (vp->v_type != VREG && vp->v_type != VBLK) {
- fd_putfile(fd);
- return 0;
- }
- break;
+ if (fp->f_ops->fo_posix_fadvise == NULL) {
+ error = EOPNOTSUPP;
+ } else {
+ error = (*fp->f_ops->fo_posix_fadvise)(fp, offset, len,
+ advice);
}
-
- switch (advice) {
- case POSIX_FADV_NORMAL:
- case POSIX_FADV_RANDOM:
- case POSIX_FADV_SEQUENTIAL:
- /*
- * We ignore offset and size. Must lock the file to
- * do this, as f_advice is sub-word sized.
- */
- mutex_enter(&fp->f_lock);
- fp->f_advice = (u_char)advice;
- mutex_exit(&fp->f_lock);
- error = 0;
- break;
-
- case POSIX_FADV_WILLNEED:
- vp = fp->f_vnode;
- error = uvm_readahead(&vp->v_uobj, offset, endoffset - offset);
- break;
-
- case POSIX_FADV_DONTNEED:
- vp = fp->f_vnode;
- /*
- * Align the region to page boundaries as VOP_PUTPAGES expects
- * by shrinking it. We shrink instead of expand because we
- * do not want to deactivate cache outside of the requested
- * region. It means that if the specified region is smaller
- * than PAGE_SIZE, we do nothing.
- */
- if (offset <= trunc_page(OFF_MAX) &&
- round_page(offset) < trunc_page(endoffset)) {
- rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
- error = VOP_PUTPAGES(vp,
- round_page(offset), trunc_page(endoffset),
- PGO_DEACTIVATE | PGO_CLEANIT);
- } else {
- error = 0;
- }
- break;
-
- case POSIX_FADV_NOREUSE:
- /* Not implemented yet. */
- error = 0;
- break;
- default:
- error = EINVAL;
- break;
- }
-
fd_putfile(fd);
return error;
}
diff -r 69434b3fe130 -r fe97d0db0ba0 sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c Sat Apr 22 13:52:54 2023 +0000
+++ b/sys/kern/sys_pipe.c Sat Apr 22 13:53:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_pipe.c,v 1.159 2023/04/22 13:52:54 riastradh Exp $ */
+/* $NetBSD: sys_pipe.c,v 1.160 2023/04/22 13:53:02 riastradh Exp $ */
/*-
* Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.159 2023/04/22 13:52:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.160 2023/04/22 13:53:02 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -101,6 +101,7 @@ static int pipe_stat(file_t *, struct st
static int pipe_ioctl(file_t *, u_long, void *);
static void pipe_restart(file_t *);
static int pipe_fpathconf(file_t *, int, register_t *);
+static int pipe_posix_fadvise(file_t *, off_t, off_t, int);
static const struct fileops pipeops = {
.fo_name = "pipe",
@@ -114,6 +115,7 @@ static const struct fileops pipeops = {
.fo_kqfilter = pipe_kqfilter,
.fo_restart = pipe_restart,
.fo_fpathconf = pipe_fpathconf,
+ .fo_posix_fadvise = pipe_posix_fadvise,
};
/*
@@ -928,6 +930,13 @@ pipe_fpathconf(struct file *fp, int name
}
}
+static int
+pipe_posix_fadvise(struct file *fp, off_t offset, off_t len, int advice)
+{
+
+ return ESPIPE;
+}
+
static void
pipe_free_kmem(struct pipe *pipe)
{
diff -r 69434b3fe130 -r fe97d0db0ba0 sys/kern/sys_socket.c
--- a/sys/kern/sys_socket.c Sat Apr 22 13:52:54 2023 +0000
+++ b/sys/kern/sys_socket.c Sat Apr 22 13:53:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_socket.c,v 1.80 2023/04/22 13:52:54 riastradh Exp $ */
+/* $NetBSD: sys_socket.c,v 1.81 2023/04/22 13:53:02 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.80 2023/04/22 13:52:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_socket.c,v 1.81 2023/04/22 13:53:02 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -81,6 +81,7 @@
#include <net/route.h>
static int soo_fpathconf(struct file *, int, register_t *);
+static int soo_posix_fadvise(struct file *, off_t, off_t, int);
const struct fileops socketops = {
.fo_name = "socket",
@@ -94,6 +95,7 @@ const struct fileops socketops = {
.fo_kqfilter = soo_kqfilter,
.fo_restart = soo_restart,
.fo_fpathconf = soo_fpathconf,
+ .fo_posix_fadvise = soo_posix_fadvise,
};
int (*ifioctl)(struct socket *, u_long, void *, struct lwp *) = (void *)eopnotsupp;
@@ -279,3 +281,10 @@ soo_fpathconf(struct file *fp, int name,
return EINVAL;
}
}
+
+static int
+soo_posix_fadvise(struct file *fp, off_t offset, off_t len, int advice)
+{
+
+ return ESPIPE;
+}
diff -r 69434b3fe130 -r fe97d0db0ba0 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c Sat Apr 22 13:52:54 2023 +0000
+++ b/sys/kern/vfs_vnops.c Sat Apr 22 13:53:02 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_vnops.c,v 1.240 2023/04/22 13:52:54 riastradh Exp $ */
+/* $NetBSD: vfs_vnops.c,v 1.241 2023/04/22 13:53:02 riastradh Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.240 2023/04/22 13:52:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.241 2023/04/22 13:53:02 riastradh Exp $");
#include "veriexec.h"
@@ -124,6 +124,7 @@ static int vn_mmap(struct file *, off_t
static int vn_seek(struct file *, off_t, int, off_t *, int);
static int vn_advlock(struct file *, void *, int, struct flock *, int);
static int vn_fpathconf(struct file *, int, register_t *);
+static int vn_posix_fadvise(struct file *, off_t, off_t, int);
const struct fileops vnops = {
.fo_name = "vn",
@@ -140,6 +141,7 @@ const struct fileops vnops = {
.fo_seek = vn_seek,
.fo_advlock = vn_advlock,
.fo_fpathconf = vn_fpathconf,
+ .fo_posix_fadvise = vn_posix_fadvise,
};
/*
@@ -1249,6 +1251,86 @@ vn_fpathconf(struct file *fp, int name,
return error;
}
+static int
+vn_posix_fadvise(struct file *fp, off_t offset, off_t len, int advice)
+{
+ const off_t OFF_MAX = __type_max(off_t);
+ struct vnode *vp = fp->f_vnode;
+ off_t endoffset;
+ int error;
+
+ if (offset < 0) {
+ return EINVAL;
+ }
+ if (len == 0) {
+ endoffset = OFF_MAX;
+ } else if (len > 0 && (OFF_MAX - offset) >= len) {
+ endoffset = offset + len;
+ } else {
+ return EINVAL;
+ }
+
+ CTASSERT(POSIX_FADV_NORMAL == UVM_ADV_NORMAL);
+ CTASSERT(POSIX_FADV_RANDOM == UVM_ADV_RANDOM);
+ CTASSERT(POSIX_FADV_SEQUENTIAL == UVM_ADV_SEQUENTIAL);
+
+ switch (advice) {
+ case POSIX_FADV_WILLNEED:
+ case POSIX_FADV_DONTNEED:
+ if (vp->v_type != VREG && vp->v_type != VBLK)
+ return 0;
+ break;
+ }
+
+ switch (advice) {
+ case POSIX_FADV_NORMAL:
+ case POSIX_FADV_RANDOM:
+ case POSIX_FADV_SEQUENTIAL:
+ /*
+ * We ignore offset and size. Must lock the file to
+ * do this, as f_advice is sub-word sized.
+ */
+ mutex_enter(&fp->f_lock);
+ fp->f_advice = (u_char)advice;
+ mutex_exit(&fp->f_lock);
+ error = 0;
+ break;
+
+ case POSIX_FADV_WILLNEED:
Home |
Main Index |
Thread Index |
Old Index