Sat Jun 13 22:15:58 2020 UTC ()
Constify.


(riastradh)
diff -r1.132 -r1.133 src/sys/dev/cgd.c
diff -r1.20 -r1.21 src/sys/dev/cgdvar.h

cvs diff -r1.132 -r1.133 src/sys/dev/cgd.c (expand / switch to unified diff)

--- src/sys/dev/cgd.c 2020/06/13 22:15:06 1.132
+++ src/sys/dev/cgd.c 2020/06/13 22:15:57 1.133
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cgd.c,v 1.132 2020/06/13 22:15:06 riastradh Exp $ */ 1/* $NetBSD: cgd.c,v 1.133 2020/06/13 22:15:57 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell. 8 * by Roland C. Dowdeswell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.132 2020/06/13 22:15:06 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.133 2020/06/13 22:15:57 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/buf.h> 37#include <sys/buf.h>
38#include <sys/bufq.h> 38#include <sys/bufq.h>
39#include <sys/conf.h> 39#include <sys/conf.h>
40#include <sys/cpu.h> 40#include <sys/cpu.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/disk.h> 42#include <sys/disk.h>
43#include <sys/disklabel.h> 43#include <sys/disklabel.h>
44#include <sys/errno.h> 44#include <sys/errno.h>
45#include <sys/fcntl.h> 45#include <sys/fcntl.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
@@ -376,27 +376,27 @@ static int cgd_destroy(device_t); @@ -376,27 +376,27 @@ static int cgd_destroy(device_t);
376static int cgd_diskstart(device_t, struct buf *); 376static int cgd_diskstart(device_t, struct buf *);
377static void cgd_diskstart2(struct cgd_softc *, struct cgd_xfer *); 377static void cgd_diskstart2(struct cgd_softc *, struct cgd_xfer *);
378static void cgdiodone(struct buf *); 378static void cgdiodone(struct buf *);
379static void cgd_iodone2(struct cgd_softc *, struct cgd_xfer *); 379static void cgd_iodone2(struct cgd_softc *, struct cgd_xfer *);
380static void cgd_enqueue(struct cgd_softc *, struct cgd_xfer *); 380static void cgd_enqueue(struct cgd_softc *, struct cgd_xfer *);
381static void cgd_process(struct work *, void *); 381static void cgd_process(struct work *, void *);
382static int cgd_dumpblocks(device_t, void *, daddr_t, int); 382static int cgd_dumpblocks(device_t, void *, daddr_t, int);
383 383
384static int cgd_ioctl_set(struct cgd_softc *, void *, struct lwp *); 384static int cgd_ioctl_set(struct cgd_softc *, void *, struct lwp *);
385static int cgd_ioctl_clr(struct cgd_softc *, struct lwp *); 385static int cgd_ioctl_clr(struct cgd_softc *, struct lwp *);
386static int cgd_ioctl_get(dev_t, void *, struct lwp *); 386static int cgd_ioctl_get(dev_t, void *, struct lwp *);
387static int cgdinit(struct cgd_softc *, const char *, struct vnode *, 387static int cgdinit(struct cgd_softc *, const char *, struct vnode *,
388 struct lwp *); 388 struct lwp *);
389static void cgd_cipher(struct cgd_softc *, void *, void *, 389static void cgd_cipher(struct cgd_softc *, void *, const void *,
390 size_t, daddr_t, size_t, int); 390 size_t, daddr_t, size_t, int);
391 391
392static void cgd_selftest(void); 392static void cgd_selftest(void);
393 393
394static const struct dkdriver cgddkdriver = { 394static const struct dkdriver cgddkdriver = {
395 .d_minphys = minphys, 395 .d_minphys = minphys,
396 .d_open = cgdopen, 396 .d_open = cgdopen,
397 .d_close = cgdclose, 397 .d_close = cgdclose,
398 .d_strategy = cgdstrategy, 398 .d_strategy = cgdstrategy,
399 .d_iosize = NULL, 399 .d_iosize = NULL,
400 .d_diskstart = cgd_diskstart, 400 .d_diskstart = cgd_diskstart,
401 .d_dumpblocks = cgd_dumpblocks, 401 .d_dumpblocks = cgd_dumpblocks,
402 .d_lastclose = NULL 402 .d_lastclose = NULL
@@ -1525,31 +1525,31 @@ cgd_process(struct work *wk, void *arg) @@ -1525,31 +1525,31 @@ cgd_process(struct work *wk, void *arg)
1525 if (cx->cx_dir == CGD_CIPHER_ENCRYPT) { 1525 if (cx->cx_dir == CGD_CIPHER_ENCRYPT) {
1526 cgd_diskstart2(sc, cx); 1526 cgd_diskstart2(sc, cx);
1527 } else { 1527 } else {
1528 cgd_iodone2(sc, cx); 1528 cgd_iodone2(sc, cx);
1529 } 1529 }
1530 1530
1531 mutex_enter(&cw->cw_lock); 1531 mutex_enter(&cw->cw_lock);
1532 if (cw->cw_busy > 0) 1532 if (cw->cw_busy > 0)
1533 cw->cw_busy--; 1533 cw->cw_busy--;
1534 mutex_exit(&cw->cw_lock); 1534 mutex_exit(&cw->cw_lock);
1535} 1535}
1536 1536
1537static void 1537static void
1538cgd_cipher(struct cgd_softc *sc, void *dstv, void *srcv, 1538cgd_cipher(struct cgd_softc *sc, void *dstv, const void *srcv,
1539 size_t len, daddr_t blkno, size_t secsize, int dir) 1539 size_t len, daddr_t blkno, size_t secsize, int dir)
1540{ 1540{
1541 char *dst = dstv; 1541 char *dst = dstv;
1542 char *src = srcv; 1542 const char *src = srcv;
1543 cfunc_cipher *cipher = sc->sc_cfuncs->cf_cipher; 1543 cfunc_cipher *cipher = sc->sc_cfuncs->cf_cipher;
1544 size_t blocksize = sc->sc_cdata.cf_blocksize; 1544 size_t blocksize = sc->sc_cdata.cf_blocksize;
1545 size_t todo; 1545 size_t todo;
1546 char blkno_buf[CGD_MAXBLOCKSIZE]; 1546 char blkno_buf[CGD_MAXBLOCKSIZE];
1547 1547
1548 DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir)); 1548 DPRINTF_FOLLOW(("cgd_cipher() dir=%d\n", dir));
1549 1549
1550 KASSERT(len % blocksize == 0); 1550 KASSERT(len % blocksize == 0);
1551 /* ensure that sizeof(daddr_t) <= blocksize (for encblkno IVing) */ 1551 /* ensure that sizeof(daddr_t) <= blocksize (for encblkno IVing) */
1552 KASSERT(sizeof(daddr_t) <= blocksize); 1552 KASSERT(sizeof(daddr_t) <= blocksize);
1553 KASSERT(blocksize <= CGD_MAXBLOCKSIZE); 1553 KASSERT(blocksize <= CGD_MAXBLOCKSIZE);
1554 1554
1555 for (; len > 0; len -= todo) { 1555 for (; len > 0; len -= todo) {

cvs diff -r1.20 -r1.21 src/sys/dev/cgdvar.h (expand / switch to unified diff)

--- src/sys/dev/cgdvar.h 2020/06/13 18:38:33 1.20
+++ src/sys/dev/cgdvar.h 2020/06/13 22:15:58 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cgdvar.h,v 1.20 2020/06/13 18:38:33 riastradh Exp $ */ 1/* $NetBSD: cgdvar.h,v 1.21 2020/06/13 22:15:58 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Roland C. Dowdeswell. 8 * by Roland C. Dowdeswell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -77,27 +77,27 @@ struct cryptdata { @@ -77,27 +77,27 @@ struct cryptdata {
77 size_t cf_blocksize; /* block size (in bytes) */ 77 size_t cf_blocksize; /* block size (in bytes) */
78 int cf_keylen; /* key length */ 78 int cf_keylen; /* key length */
79 int cf_mode; /* Cipher Mode and IV Gen method 79 int cf_mode; /* Cipher Mode and IV Gen method
80 * (see cgu_mode above for defines) */ 80 * (see cgu_mode above for defines) */
81 void *cf_priv; /* enc alg private data */ 81 void *cf_priv; /* enc alg private data */
82}; 82};
83 83
84struct cgd_xfer { 84struct cgd_xfer {
85 struct work cx_work; 85 struct work cx_work;
86 struct cgd_softc *cx_sc; 86 struct cgd_softc *cx_sc;
87 struct buf *cx_obp; 87 struct buf *cx_obp;
88 struct buf *cx_nbp; 88 struct buf *cx_nbp;
89 void *cx_dstv; 89 void *cx_dstv;
90 void *cx_srcv; 90 const void *cx_srcv;
91 size_t cx_len; 91 size_t cx_len;
92 daddr_t cx_blkno; 92 daddr_t cx_blkno;
93 size_t cx_secsize; 93 size_t cx_secsize;
94 int cx_dir; 94 int cx_dir;
95}; 95};
96 96
97struct cgd_worker { 97struct cgd_worker {
98 struct workqueue *cw_wq; /* work queue */ 98 struct workqueue *cw_wq; /* work queue */
99 struct pool *cw_cpool; /* cgd_xfer contexts */ 99 struct pool *cw_cpool; /* cgd_xfer contexts */
100 u_int cw_busy; /* number of busy contexts */ 100 u_int cw_busy; /* number of busy contexts */
101 u_int cw_last; /* index of last CPU used */ 101 u_int cw_last; /* index of last CPU used */
102 kmutex_t cw_lock; 102 kmutex_t cw_lock;
103}; 103};