Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add d_discard to struct bdevsw/cdevsw, and the plumbing ...
details: https://anonhg.NetBSD.org/src/rev/164b4e24b77e
branches: trunk
changeset: 330901:164b4e24b77e
user: dholland <dholland%NetBSD.org@localhost>
date: Fri Jul 25 07:56:14 2014 +0000
description:
Add d_discard to struct bdevsw/cdevsw, and the plumbing to access it.
Unfortunately we need d_discard in both since we need to be able to
discard from both the block and character forms of disks. I'm
increasingly thinking it would be better to restructure the ops
dispatching so each type of device (ttys, disks, tapes, etc.) has its
own function table. Then we wouldn't need to change every tty driver
to add a disk op.
diffstat:
sys/kern/subr_devsw.c | 36 ++++++++++++++++++++++++++++++++++--
sys/sys/conf.h | 9 ++++++++-
2 files changed, 42 insertions(+), 3 deletions(-)
diffs (129 lines):
diff -r 685acfa75649 -r 164b4e24b77e sys/kern/subr_devsw.c
--- a/sys/kern/subr_devsw.c Fri Jul 25 07:49:56 2014 +0000
+++ b/sys/kern/subr_devsw.c Fri Jul 25 07:56:14 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_devsw.c,v 1.31 2014/05/25 16:31:51 pooka Exp $ */
+/* $NetBSD: subr_devsw.c,v 1.32 2014/07/25 07:56:14 dholland Exp $ */
/*-
* Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.31 2014/05/25 16:31:51 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.32 2014/07/25 07:56:14 dholland Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@@ -819,6 +819,22 @@
}
int
+bdev_discard(dev_t dev, off_t pos, off_t len)
+{
+ const struct bdevsw *d;
+ int rv, mpflag;
+
+ if ((d = bdevsw_lookup(dev)) == NULL)
+ return ENXIO;
+
+ DEV_LOCK(d);
+ rv = (*d->d_discard)(dev, pos, len);
+ DEV_UNLOCK(d);
+
+ return rv;
+}
+
+int
cdev_open(dev_t dev, int flag, int devtype, lwp_t *l)
{
const struct cdevsw *d;
@@ -984,6 +1000,22 @@
}
int
+cdev_discard(dev_t dev, off_t pos, off_t len)
+{
+ const struct cdevsw *d;
+ int rv, mpflag;
+
+ if ((d = cdevsw_lookup(dev)) == NULL)
+ return ENXIO;
+
+ DEV_LOCK(d);
+ rv = (*d->d_discard)(dev, pos, len);
+ DEV_UNLOCK(d);
+
+ return rv;
+}
+
+int
cdev_type(dev_t dev)
{
const struct cdevsw *d;
diff -r 685acfa75649 -r 164b4e24b77e sys/sys/conf.h
--- a/sys/sys/conf.h Fri Jul 25 07:49:56 2014 +0000
+++ b/sys/sys/conf.h Fri Jul 25 07:56:14 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.h,v 1.144 2012/10/27 17:18:40 chs Exp $ */
+/* $NetBSD: conf.h,v 1.145 2014/07/25 07:56:14 dholland Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -74,6 +74,7 @@
int (*d_ioctl)(dev_t, u_long, void *, int, struct lwp *);
int (*d_dump)(dev_t, daddr_t, void *, size_t);
int (*d_psize)(dev_t);
+ int (*d_discard)(dev_t, off_t, off_t);
int d_flag;
};
@@ -91,6 +92,7 @@
int (*d_poll)(dev_t, int, struct lwp *);
paddr_t (*d_mmap)(dev_t, off_t, int);
int (*d_kqfilter)(dev_t, struct knote *);
+ int (*d_discard)(dev_t, off_t, off_t);
int d_flag;
};
@@ -121,6 +123,7 @@
#define dev_type_dump(n) int n (dev_t, daddr_t, void *, size_t)
#define dev_type_size(n) int n (dev_t)
#define dev_type_kqfilter(n) int n (dev_t, struct knote *)
+#define dev_type_discard(n) int n (dev_t, off_t, off_t)
#define noopen ((dev_type_open((*)))enodev)
#define noclose ((dev_type_close((*)))enodev)
@@ -134,6 +137,7 @@
#define nodump ((dev_type_dump((*)))enodev)
#define nosize NULL
#define nokqfilter seltrue_kqfilter
+#define nodiscard ((dev_type_discard((*)))enodev)
#define nullopen ((dev_type_open((*)))nullop)
#define nullclose ((dev_type_close((*)))nullop)
@@ -145,6 +149,7 @@
#define nullmmap ((dev_type_mmap((*)))nullop)
#define nulldump ((dev_type_dump((*)))nullop)
#define nullkqfilter ((dev_type_kqfilter((*)))eopnotsupp)
+#define nulldiscard ((dev_type_discard((*)))nullop)
/* device access wrappers. */
@@ -154,6 +159,7 @@
dev_type_ioctl(bdev_ioctl);
dev_type_dump(bdev_dump);
dev_type_size(bdev_size);
+dev_type_discard(bdev_discard);
dev_type_open(cdev_open);
dev_type_close(cdev_close);
@@ -165,6 +171,7 @@
dev_type_poll(cdev_poll);
dev_type_mmap(cdev_mmap);
dev_type_kqfilter(cdev_kqfilter);
+dev_type_discard(cdev_discard);
int cdev_type(dev_t);
int bdev_type(dev_t);
Home |
Main Index |
Thread Index |
Old Index