Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Modify dksubr.c to add a function that sets the disk...
details: https://anonhg.NetBSD.org/src/rev/244cd0e9d383
branches: trunk
changeset: 779386:244cd0e9d383
user: elric <elric%NetBSD.org@localhost>
date: Fri May 25 10:53:46 2012 +0000
description:
Modify dksubr.c to add a function that sets the disk properties in
the drvctl framework. And call this new functionality from cgd(4),
the consumer of dksubr.c. We do this to allow gpt(8) to be able
to label cgd(4) disks. We also add in some DIOCGSECTORSIZE logic
and we ensure that the WEDGE ioctls are not called on either
uninitialised disks or disks which have not been opened for write
access.
diffstat:
sys/dev/cgd.c | 20 ++++++++------
sys/dev/cgdvar.h | 3 +-
sys/dev/dksubr.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
sys/dev/dkvar.h | 8 +++---
4 files changed, 85 insertions(+), 20 deletions(-)
diffs (267 lines):
diff -r 86963b58e0a8 -r 244cd0e9d383 sys/dev/cgd.c
--- a/sys/dev/cgd.c Fri May 25 10:48:48 2012 +0000
+++ b/sys/dev/cgd.c Fri May 25 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.76 2011/11/13 23:03:24 christos Exp $ */
+/* $NetBSD: cgd.c,v 1.77 2012/05/25 10:53:46 elric Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.76 2011/11/13 23:03:24 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.77 2012/05/25 10:53:46 elric Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -185,9 +185,9 @@
{
struct cgd_softc *sc = device_private(self);
- sc->sc_dev = self;
simple_lock_init(&sc->sc_slock);
- dk_sc_init(&sc->sc_dksc, sc, device_xname(sc->sc_dev));
+ dk_sc_init(&sc->sc_dksc, device_xname(self));
+ sc->sc_dksc.sc_dev = self;
disk_init(&sc->sc_dksc.sc_dkdev, sc->sc_dksc.sc_xname, &cgddkdriver);
if (!pmf_device_register(self, NULL, NULL))
@@ -278,8 +278,8 @@
return error;
if ((dksc->sc_flags & DKF_INITED) == 0) {
- if ((error = cgd_destroy(cs->sc_dev)) != 0) {
- aprint_error_dev(cs->sc_dev,
+ if ((error = cgd_destroy(cs->sc_dksc.sc_dev)) != 0) {
+ aprint_error_dev(dksc->sc_dev,
"unable to detach instance\n");
return error;
}
@@ -336,7 +336,7 @@
static void *
cgd_getdata(struct dk_softc *dksc, unsigned long size)
{
- struct cgd_softc *cs =dksc->sc_osc;
+ struct cgd_softc *cs = (struct cgd_softc *)dksc;
void * data = NULL;
simple_lock(&cs->sc_slock);
@@ -355,7 +355,7 @@
static void
cgd_putdata(struct dk_softc *dksc, void *data)
{
- struct cgd_softc *cs =dksc->sc_osc;
+ struct cgd_softc *cs = (struct cgd_softc *)dksc;
if (data == cs->sc_data) {
simple_lock(&cs->sc_slock);
@@ -369,7 +369,7 @@
static int
cgdstart(struct dk_softc *dksc, struct buf *bp)
{
- struct cgd_softc *cs = dksc->sc_osc;
+ struct cgd_softc *cs = (struct cgd_softc *)dksc;
struct buf *nbp;
void * addr;
void * newaddr;
@@ -681,6 +681,8 @@
cs->sc_dksc.sc_flags |= DKF_INITED;
+ dk_set_properties(di, &cs->sc_dksc);
+
/* Attach the disk. */
disk_attach(&cs->sc_dksc.sc_dkdev);
diff -r 86963b58e0a8 -r 244cd0e9d383 sys/dev/cgdvar.h
--- a/sys/dev/cgdvar.h Fri May 25 10:48:48 2012 +0000
+++ b/sys/dev/cgdvar.h Fri May 25 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgdvar.h,v 1.14 2010/01/12 21:08:09 dyoung Exp $ */
+/* $NetBSD: cgdvar.h,v 1.15 2012/05/25 10:53:46 elric Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -69,7 +69,6 @@
};
struct cgd_softc {
- device_t sc_dev;
struct dk_softc sc_dksc; /* generic disk interface */
struct cryptinfo *sc_crypt; /* the alg/key/etc */
struct vnode *sc_tvn; /* target device's vnode */
diff -r 86963b58e0a8 -r 244cd0e9d383 sys/dev/dksubr.c
--- a/sys/dev/dksubr.c Fri May 25 10:48:48 2012 +0000
+++ b/sys/dev/dksubr.c Fri May 25 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dksubr.c,v 1.42 2010/11/19 06:44:39 dholland Exp $ */
+/* $NetBSD: dksubr.c,v 1.43 2012/05/25 10:53:46 elric Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 1999, 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.42 2010/11/19 06:44:39 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.43 2012/05/25 10:53:46 elric Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -48,7 +48,9 @@
#include <dev/dkvar.h>
-int dkdebug = 0;
+int dkdebug = 0xff;
+
+#define DEBUG 1
#ifdef DEBUG
#define DKDB_FOLLOW 0x1
@@ -70,11 +72,10 @@
static void dk_makedisklabel(struct dk_intf *, struct dk_softc *);
void
-dk_sc_init(struct dk_softc *dksc, void *osc, const char *xname)
+dk_sc_init(struct dk_softc *dksc, const char *xname)
{
memset(dksc, 0x0, sizeof(*dksc));
- dksc->sc_osc = osc;
strncpy(dksc->sc_xname, xname, DK_XNAME_SIZE);
dksc->sc_dkdev.dk_name = dksc->sc_xname;
}
@@ -306,18 +307,28 @@
case ODIOCWDINFO:
#endif
case DIOCWLABEL:
+ case DIOCAWEDGE:
+ case DIOCDWEDGE:
if ((flag & FWRITE) == 0)
return EBADF;
}
/* ensure that the pseudo-disk is initialized for these */
switch (cmd) {
+#ifdef DIOCGSECTORSIZE
+ case DIOCGSECTORSIZE:
+ case DIOCGMEDIASIZE:
+#endif
case DIOCGDINFO:
case DIOCSDINFO:
case DIOCWDINFO:
case DIOCGPART:
case DIOCWLABEL:
case DIOCGDEFLABEL:
+ case DIOCAWEDGE:
+ case DIOCDWEDGE:
+ case DIOCLWEDGES:
+ case DIOCCACHESYNC:
#ifdef __HAVE_OLD_DISKLABEL
case ODIOCGDINFO:
case ODIOCSDINFO:
@@ -329,6 +340,17 @@
}
switch (cmd) {
+#ifdef DIOCGSECTORSIZE
+ case DIOCGSECTORSIZE:
+ *(u_int *)data = dksc->sc_geom.pdg_secsize;
+ return 0;
+ case DIOCGMEDIASIZE:
+ *(off_t *)data =
+ (off_t)dksc->sc_geom.pdg_secsize *
+ dksc->sc_geom.pdg_nsectors;
+ return 0;
+#endif
+
case DIOCGDINFO:
*(struct disklabel *)data = *(dksc->sc_dkdev.dk_label);
break;
@@ -606,6 +628,48 @@
lp->d_checksum = dkcksum(lp);
}
+void
+dk_set_properties(struct dk_intf *di, struct dk_softc *dksc)
+{
+ prop_dictionary_t disk_info, odisk_info, geom;
+
+ disk_info = prop_dictionary_create();
+
+ geom = prop_dictionary_create();
+
+ prop_dictionary_set_uint64(geom, "sectors-per-unit",
+ dksc->sc_geom.pdg_nsectors * dksc->sc_geom.pdg_ntracks *
+ dksc->sc_geom.pdg_ncylinders);
+
+ prop_dictionary_set_uint32(geom, "sector-size",
+ dksc->sc_geom.pdg_secsize);
+
+ prop_dictionary_set_uint16(geom, "sectors-per-track",
+ dksc->sc_geom.pdg_nsectors);
+
+ prop_dictionary_set_uint16(geom, "tracks-per-cylinder",
+ dksc->sc_geom.pdg_ntracks);
+
+ prop_dictionary_set_uint64(geom, "cylinders-per-unit",
+ dksc->sc_geom.pdg_ncylinders);
+
+ prop_dictionary_set(disk_info, "geometry", geom);
+ prop_object_release(geom);
+
+ prop_dictionary_set(device_properties(dksc->sc_dev),
+ "disk-info", disk_info);
+
+ /*
+ * Don't release disk_info here; we keep a reference to it.
+ * disk_detach() will release it when we go away.
+ */
+
+ odisk_info = dksc->sc_dkdev.dk_info;
+ dksc->sc_dkdev.dk_info = disk_info;
+ if (odisk_info)
+ prop_object_release(odisk_info);
+}
+
/* This function is taken from ccd.c:1.76 --rcd */
/*
diff -r 86963b58e0a8 -r 244cd0e9d383 sys/dev/dkvar.h
--- a/sys/dev/dkvar.h Fri May 25 10:48:48 2012 +0000
+++ b/sys/dev/dkvar.h Fri May 25 10:53:46 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dkvar.h,v 1.15 2010/11/19 06:44:39 dholland Exp $ */
+/* $NetBSD: dkvar.h,v 1.16 2012/05/25 10:53:46 elric Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -47,8 +47,7 @@
* are common to each of the pseudo-disk drivers.
*/
struct dk_softc {
- void *sc_osc; /* the softc of the underlying
- * driver */
+ device_t sc_dev;
u_int32_t sc_flags; /* flags */
size_t sc_size; /* size of disk */
struct dk_geom sc_geom; /* geometry info */
@@ -96,7 +95,7 @@
* Functions that are exported to the pseudo disk implementations:
*/
-void dk_sc_init(struct dk_softc *, void *, const char *);
+void dk_sc_init(struct dk_softc *, const char *);
int dk_open(struct dk_intf *, struct dk_softc *, dev_t,
int, int, struct lwp *);
@@ -113,5 +112,6 @@
void dk_getdisklabel(struct dk_intf *, struct dk_softc *, dev_t);
void dk_getdefaultlabel(struct dk_intf *, struct dk_softc *,
struct disklabel *);
+void dk_set_properties(struct dk_intf *, struct dk_softc *);
int dk_lookup(struct pathbuf *, struct lwp *, struct vnode **);
Home |
Main Index |
Thread Index |
Old Index