Sun Mar 1 03:19:46 2020 UTC ()
Allow dumping to cgd(4) on a dk(4).

(Technically this also allows dumping to a dk(4) on which there
happens to be a cgd(4) configured, but I'm not sure how to
distinguish that case here.  So don't do that!)


(riastradh)
diff -r1.98 -r1.99 src/sys/dev/dkwedge/dk.c

cvs diff -r1.98 -r1.99 src/sys/dev/dkwedge/dk.c (expand / switch to unified diff)

--- src/sys/dev/dkwedge/dk.c 2020/02/28 06:01:23 1.98
+++ src/sys/dev/dkwedge/dk.c 2020/03/01 03:19:46 1.99
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dk.c,v 1.98 2020/02/28 06:01:23 yamaguchi Exp $ */ 1/* $NetBSD: dk.c,v 1.99 2020/03/01 03:19:46 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2004, 2005, 2006, 2007 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 Jason R. Thorpe. 8 * by Jason R. Thorpe.
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: dk.c,v 1.98 2020/02/28 06:01:23 yamaguchi Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.99 2020/03/01 03:19:46 riastradh Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_dkwedge.h" 36#include "opt_dkwedge.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/proc.h> 41#include <sys/proc.h>
42#include <sys/errno.h> 42#include <sys/errno.h>
43#include <sys/pool.h> 43#include <sys/pool.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/disklabel.h> 45#include <sys/disklabel.h>
46#include <sys/disk.h> 46#include <sys/disk.h>
@@ -1597,27 +1597,28 @@ dkdump(dev_t dev, daddr_t blkno, void *v @@ -1597,27 +1597,28 @@ dkdump(dev_t dev, daddr_t blkno, void *v
1597 int rv = 0; 1597 int rv = 0;
1598 1598
1599 if (sc == NULL) 1599 if (sc == NULL)
1600 return (ENODEV); 1600 return (ENODEV);
1601 if (sc->sc_state != DKW_STATE_RUNNING) 1601 if (sc->sc_state != DKW_STATE_RUNNING)
1602 return (ENXIO); 1602 return (ENXIO);
1603 1603
1604 mutex_enter(&sc->sc_dk.dk_openlock); 1604 mutex_enter(&sc->sc_dk.dk_openlock);
1605 mutex_enter(&sc->sc_parent->dk_rawlock); 1605 mutex_enter(&sc->sc_parent->dk_rawlock);
1606 1606
1607 /* Our content type is static, no need to open the device. */ 1607 /* Our content type is static, no need to open the device. */
1608 1608
1609 if (strcmp(sc->sc_ptype, DKW_PTYPE_SWAP) != 0 && 1609 if (strcmp(sc->sc_ptype, DKW_PTYPE_SWAP) != 0 &&
1610 strcmp(sc->sc_ptype, DKW_PTYPE_RAID) != 0) { 1610 strcmp(sc->sc_ptype, DKW_PTYPE_RAID) != 0 &&
 1611 strcmp(sc->sc_ptype, DKW_PTYPE_CGD) != 0) {
1611 rv = ENXIO; 1612 rv = ENXIO;
1612 goto out; 1613 goto out;
1613 } 1614 }
1614 if (size % DEV_BSIZE != 0) { 1615 if (size % DEV_BSIZE != 0) {
1615 rv = EINVAL; 1616 rv = EINVAL;
1616 goto out; 1617 goto out;
1617 } 1618 }
1618 if (blkno < 0 || blkno + size / DEV_BSIZE > sc->sc_size) { 1619 if (blkno < 0 || blkno + size / DEV_BSIZE > sc->sc_size) {
1619 printf("%s: blkno (%" PRIu64 ") + size / DEV_BSIZE (%zu) > " 1620 printf("%s: blkno (%" PRIu64 ") + size / DEV_BSIZE (%zu) > "
1620 "sc->sc_size (%" PRIu64 ")\n", __func__, blkno, 1621 "sc->sc_size (%" PRIu64 ")\n", __func__, blkno,
1621 size / DEV_BSIZE, sc->sc_size); 1622 size / DEV_BSIZE, sc->sc_size);
1622 rv = EINVAL; 1623 rv = EINVAL;
1623 goto out; 1624 goto out;