Subject: Dumping to wedges
To: None <tech-kern@NetBSD.org>
From: Martin Husemann <martin@duskware.de>
List: tech-kern
Date: 08/14/2006 22:12:19
--EeQfGwPcQSOJBaQU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Besides wedges not autoconfiguring the dump device (which is pretty easy to
solve and testable w/o writing a dump all over your disk ;-}), I noticed
that the wedges dump routine is not implemented.

As I'm very unfamiliar with block devices, is the attached patch the right
thing to do?

Martin

--EeQfGwPcQSOJBaQU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

Index: dk.c
===================================================================
RCS file: /cvsroot/src/sys/dev/dkwedge/dk.c,v
retrieving revision 1.16
diff -u -p -r1.16 dk.c
--- dk.c	21 Jul 2006 16:48:48 -0000	1.16
+++ dk.c	14 Aug 2006 20:10:06 -0000
@@ -1253,7 +1253,40 @@ dksize(dev_t dev)
 static int
 dkdump(dev_t dev, daddr_t blkno, caddr_t va, size_t size)
 {
+	struct dkwedge_softc *sc = dkwedge_lookup(dev);
+	const struct bdevsw *bdev;
+	int rv = 0;
 
-	/* XXX */
-	return (ENXIO);
+	if (sc == NULL)
+		return (-1);
+	
+	if (sc->sc_state != DKW_STATE_RUNNING)
+		return (ENXIO);
+
+	(void) lockmgr(&sc->sc_dk.dk_openlock, LK_EXCLUSIVE, NULL);
+	(void) lockmgr(&sc->sc_parent->dk_rawlock, LK_EXCLUSIVE, NULL);
+
+	/* Our content type is static, no need to open the device. */
+
+	if (strcmp(sc->sc_ptype, DKW_PTYPE_SWAP) != 0) {
+		rv = ENXIO;
+		goto out;
+	}
+	if (blkno + size > sc->sc_size) {
+		rv = EINVAL;
+		goto out;
+	}
+
+	bdev = bdevsw_lookup(sc->sc_pdev);
+	if (bdev == NULL)
+		rv = ENXIO;
+	else
+		rv = (*bdev->d_dump)(sc->sc_pdev, blkno+sc->sc_offset,
+		    va, size);
+
+out:
+	(void) lockmgr(&sc->sc_parent->dk_rawlock, LK_RELEASE, NULL);
+	(void) lockmgr(&sc->sc_dk.dk_openlock, LK_RELEASE, NULL);
+
+	return rv;
 }

--EeQfGwPcQSOJBaQU--