summaryrefslogtreecommitdiffstats
path: root/sys/dev/vinum
diff options
context:
space:
mode:
authorgrog <grog@FreeBSD.org>2003-05-01 01:34:38 +0000
committergrog <grog@FreeBSD.org>2003-05-01 01:34:38 +0000
commit94787ab4318d66111ab4331260361b6921054a5c (patch)
tree172c3f00b80f638371a77530beb1920f73523d08 /sys/dev/vinum
parentf5210909e57df68f73c9e73a32ee77e37565a609 (diff)
downloadFreeBSD-src-94787ab4318d66111ab4331260361b6921054a5c.zip
FreeBSD-src-94787ab4318d66111ab4331260361b6921054a5c.tar.gz
For consistency's sake, on command failure, throw 1, not -1.
Rewrite minor number decoding. Now we have only three types of object: subdisks, plexes and volumes. The encoding for plexes and subdisks no longer reflects the object to which they belong. The super devices are high-order volume numbers. This gives vastly more potential volumes (4 million instead of 256).
Diffstat (limited to 'sys/dev/vinum')
-rw-r--r--sys/dev/vinum/vinumutil.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/sys/dev/vinum/vinumutil.c b/sys/dev/vinum/vinumutil.c
index 52c7d27..70f2ccb 100644
--- a/sys/dev/vinum/vinumutil.c
+++ b/sys/dev/vinum/vinumutil.c
@@ -35,7 +35,7 @@
* otherwise) arising in any way out of the use of this software, even if
* advised of the possibility of such damage.
*
- * $Id: vinumutil.c,v 1.14 1999/12/30 07:04:02 grog Exp grog $
+ * $Id: vinumutil.c,v 1.17 2003/04/28 02:54:43 grog Exp $
* $FreeBSD$
*/
@@ -227,27 +227,37 @@ sizespec(char *spec)
throw_rude_remark(EINVAL, "Invalid length specification: %s", spec);
#else
fprintf(stderr, "Invalid length specification: %s", spec);
- longjmp(command_fail, -1);
+ longjmp(command_fail, 1);
#endif
}
#ifdef _KERNEL
throw_rude_remark(EINVAL, "Missing length specification");
#else
fprintf(stderr, "Missing length specification");
- longjmp(command_fail, -1);
+ longjmp(command_fail, 1);
#endif
/* NOTREACHED */
return -1;
}
/*
- * Extract the volume number from a device number.
- * Perform no checking.
+ * Extract the volume number from a device number. Check that it's
+ * the correct type, and that it isn't one of the superdevs.
*/
int
Volno(dev_t dev)
{
- return (minor(dev) & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT;
+ int volno = minor(dev);
+
+ if (OBJTYPE(dev) != VINUM_VOLUME_TYPE)
+ return -1;
+ else
+ volno = ((volno & 0x3fff0000) >> 8) | (volno & 0xff);
+ if ((volno == VINUM_SUPERDEV_VOL)
+ || (volno == VINUM_DAEMON_VOL))
+ return -1;
+ else
+ return volno;
}
/*
@@ -258,24 +268,12 @@ Volno(dev_t dev)
int
Plexno(dev_t dev)
{
- switch (DEVTYPE(dev)) {
- case VINUM_VOLUME_TYPE:
- case VINUM_DRIVE_TYPE:
- case VINUM_SUPERDEV_TYPE: /* ordinary super device */
- case VINUM_RAWSD_TYPE:
- return -1;
+ int plexno = minor(dev);
- case VINUM_PLEX_TYPE:
- case VINUM_SD_TYPE:
- return VOL[Volno(dev)].plex[(minor(dev) >> VINUM_PLEX_SHIFT) & (MASK(VINUM_PLEX_WIDTH))];
-
- case VINUM_RAWPLEX_TYPE:
- return ((minor(dev) & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT) /* low order 8 bits */
- |((minor(dev) >> VINUM_RAWPLEX_SHIFT)
- & (MASK(VINUM_RAWPLEX_WIDTH)
- << (VINUM_VOL_SHIFT + VINUM_VOL_WIDTH))); /* upper 12 bits */
- }
- return 0; /* compiler paranoia */
+ if (OBJTYPE(dev) != VINUM_PLEX_TYPE)
+ return -1;
+ else
+ return ((plexno & 0x3fff0000) >> 8) | (plexno & 0xff);
}
/*
@@ -286,21 +284,20 @@ Plexno(dev_t dev)
int
Sdno(dev_t dev)
{
- switch (DEVTYPE(dev)) {
- case VINUM_VOLUME_TYPE:
- case VINUM_DRIVE_TYPE:
- case VINUM_SUPERDEV_TYPE: /* ordinary super device */
- case VINUM_PLEX_TYPE:
- case VINUM_RAWPLEX_TYPE:
- return -1;
-
- case VINUM_SD_TYPE:
- return PLEX[Plexno(dev)].sdnos[(minor(dev) >> VINUM_SD_SHIFT) & (MASK(VINUM_SD_WIDTH))];
+ int sdno = minor(dev);
- case VINUM_RAWSD_TYPE:
- return ((minor(dev) & MASK(VINUM_VOL_WIDTH)) >> VINUM_VOL_SHIFT) /* low order 8 bits */
- |((minor(dev) >> VINUM_RAWPLEX_SHIFT) & (MASK(VINUM_RAWPLEX_WIDTH)
- << (VINUM_VOL_SHIFT + VINUM_VOL_WIDTH))); /* upper 12 bits */
- }
- return -1; /* compiler paranoia */
+ /*
+ * Care: VINUM_SD_TYPE is 2 or 3, which is why we use < instead of
+ * !=. It's not clear that this makes any sense abstracting it to
+ * this level.
+ */
+ if (OBJTYPE(dev) < VINUM_SD_TYPE)
+ return -1;
+ else
+/*
+ * Note that the number we return includes the low-order bit of the
+ * type field. This gives us twice as many potential subdisks as
+ * plexes or volumes.
+ */
+ return ((sdno & 0x7fff0000) >> 8) | (sdno & 0xff);
}
OpenPOWER on IntegriCloud