Module Name:    src
Committed By:   dholland
Date:           Fri Jul 25 07:56:14 UTC 2014

Modified Files:
        src/sys/kern: subr_devsw.c
        src/sys/sys: conf.h

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/kern/subr_devsw.c
cvs rdiff -u -r1.144 -r1.145 src/sys/sys/conf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_devsw.c
diff -u src/sys/kern/subr_devsw.c:1.31 src/sys/kern/subr_devsw.c:1.32
--- src/sys/kern/subr_devsw.c:1.31	Sun May 25 16:31:51 2014
+++ src/sys/kern/subr_devsw.c	Fri Jul 25 07:56:14 2014
@@ -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 @@ bdev_size(dev_t dev)
 }
 
 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 @@ cdev_kqfilter(dev_t dev, struct knote *k
 }
 
 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;

Index: src/sys/sys/conf.h
diff -u src/sys/sys/conf.h:1.144 src/sys/sys/conf.h:1.145
--- src/sys/sys/conf.h:1.144	Sat Oct 27 17:18:40 2012
+++ src/sys/sys/conf.h	Fri Jul 25 07:56:14 2014
@@ -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 @@ struct bdevsw {
 	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 @@ struct cdevsw {
 	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 @@ devmajor_t cdevsw_lookup_major(const str
 #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 @@ devmajor_t cdevsw_lookup_major(const str
 #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 @@ devmajor_t cdevsw_lookup_major(const str
 #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_strategy(bdev_strategy);
 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_tty(cdev_tty);
 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);

Reply via email to