Module Name: src Committed By: martin Date: Sun Apr 10 09:43:37 UTC 2016
Modified Files: src/usr.sbin/vnconfig [netbsd-7]: vnconfig.8 vnconfig.c Log Message: Pull up following revision(s) (requested by christos in ticket #1076): usr.sbin/vnconfig/vnconfig.8: revision 1.41 usr.sbin/vnconfig/vnconfig.c: revision 1.43-1.44 Since now the kernel returns ENXIO again for devices exceeding the number of devices configured in the kernel, use that instead of scanning /dev. Cosmetic tweaks to vncfonfig -l output. This should restore compatibility for old scripts trying to find free vnodes in the new cloning world order. To generate a diff of this commit: cvs rdiff -u -r1.39.6.1 -r1.39.6.2 src/usr.sbin/vnconfig/vnconfig.8 cvs rdiff -u -r1.42 -r1.42.2.1 src/usr.sbin/vnconfig/vnconfig.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/vnconfig/vnconfig.8 diff -u src/usr.sbin/vnconfig/vnconfig.8:1.39.6.1 src/usr.sbin/vnconfig/vnconfig.8:1.39.6.2 --- src/usr.sbin/vnconfig/vnconfig.8:1.39.6.1 Sun Nov 8 02:05:25 2015 +++ src/usr.sbin/vnconfig/vnconfig.8 Sun Apr 10 09:43:37 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: vnconfig.8,v 1.39.6.1 2015/11/08 02:05:25 riz Exp $ +.\" $NetBSD: vnconfig.8,v 1.39.6.2 2016/04/10 09:43:37 martin Exp $ .\" .\" Copyright (c) 1997 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -69,6 +69,7 @@ .Nd configure vnode disks .Sh SYNOPSIS .Nm +.\" Fcf:lm:rt:uvz .Op Fl crvz .Op Fl f Ar disktab .Op Fl t Ar typename @@ -81,7 +82,8 @@ .Ar vnode_disk .Nm .Fl l -.Op Ar vnode_disk +.Op Fl m Ar min +.Op Ar vnode_disk ... .Sh DESCRIPTION The .Nm @@ -124,7 +126,7 @@ If geometry is not specified, the kernel cylinders. .Ar secsize is the number of bytes per sector. -It must be an even multiple of 512. +It must be a power of two, and at least 512. .Ar nsectors is the number of sectors per track. .Ar ntracks @@ -144,9 +146,28 @@ instead of in .Pa /etc/disktab . .It Fl l List the vnd devices and indicate which ones are in use. -If a specific -.Ar vnode_disk -is given, then only that will be described. +If one or more specific +.Ar vnode_disks +are given, then only those will be described. +.It Fl m Ar min +Together with +.Fl l +and if no specific devices are given, +causes at least +.Ar min +devices to be listed. +The default for +.Ar min +is 4, +but all vnd devices up to (and sometimes just beyond) +the highest numbered vnd device configured since +the system last booted will be listed. +If +.Ar min +is set to 0, +then only vnd devices currently in use will be shown. +.It Fl r +Configure the device as read-only. .It Fl t Ar typename If configuring the device, look up .Ar typename @@ -156,8 +177,6 @@ and use the geometry specified in the en This option and the .Ar geomspec argument are mutually exclusive. -.It Fl r -Configure the device as read-only. .It Fl u Unconfigures the device. .It Fl v @@ -172,9 +191,25 @@ See the manpage on how to create such an image. .El .Pp -If no action option is given, +If no action option +.Op Fl clu +is given, .Fl c is assumed. +.Sh EXIT STATUS +.Nm +will exit with status 0 if the operation requested +completed successfully, +or 1 otherwise. +Unsuccessful completion can be caused by unknown or +incorrectly used options; +attempting to configure a vnd that is already configured; +or unconfigure one that is not, or without +.Fl F , +one which is still in use; +or if devices are specified that do not exist or are not +.Xr vnd 4 +devices, giving an improper geometry, etc. .Sh FILES .Bl -tag -width /etc/disktab -compact .It Pa /dev/rvnd?? @@ -190,6 +225,10 @@ Configures the vnode disk .Pa vnd0 . Please note that use of the second form of the command is discouraged because it requires knowledge of the raw partition which varies between architectures. +For the first form, be aware that there must not be a file +.Ar vnd0 +in the current directory, or it will be assumed to be the vnd device to +be configured (which will usually fail.) .Pp .Dl vndconfig vnd0 /tmp/floppy.img 512/18/2/80 .Pp @@ -212,6 +251,22 @@ entry in Unconfigures the .Pa vnd0 device. +.Pp +To obtain status on all vnd devices listed in /dev +(assuming a system where the +.Sq d +partition is the whole device (RAW_PART)), use: +.Pp +.Dl vndconfig -l /dev/vnd*d +.Pp +Using +.Dl vndconfig -m0 -l /dev/vnd*d +will omit those devices that are not in use, whereas +.Dl vnconfig -l +will list all devices known to the kernel (at least 4 +without +.Fl m ) +regardless of what might appear in /dev (or elsewhere.) .Sh SEE ALSO .Xr vndcompress 1 , .Xr opendisk 3 , @@ -229,4 +284,5 @@ It was renamed to in .Nx 7.0 for consistency with other similar commands. -(The original name was also retained for backwards compatability.) +(The original name was also retained as an alternative +for backwards compatibility.) Index: src/usr.sbin/vnconfig/vnconfig.c diff -u src/usr.sbin/vnconfig/vnconfig.c:1.42 src/usr.sbin/vnconfig/vnconfig.c:1.42.2.1 --- src/usr.sbin/vnconfig/vnconfig.c:1.42 Fri May 23 20:50:16 2014 +++ src/usr.sbin/vnconfig/vnconfig.c Sun Apr 10 09:43:37 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vnconfig.c,v 1.42 2014/05/23 20:50:16 dholland Exp $ */ +/* $NetBSD: vnconfig.c,v 1.42.2.1 2016/04/10 09:43:37 martin Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -73,13 +73,11 @@ #include <sys/buf.h> #include <sys/disklabel.h> #include <sys/disk.h> -#include <sys/bitops.h> #include <dev/vndvar.h> #include <disktab.h> #include <err.h> -#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <stddef.h> @@ -89,28 +87,36 @@ #include <unistd.h> #include <util.h> #include <paths.h> +#include <limits.h> #define VND_CONFIG 1 #define VND_UNCONFIG 2 #define VND_GET 3 +/* with -l we always print at least this many entries */ +#define DUMMY_FREE 4 + static int verbose = 0; static int readonly = 0; static int force = 0; static int compressed = 0; +static int minimum = DUMMY_FREE; static char *tabname; -static void show(int, int); +static int show(int, int, const char * const); static int config(char *, char *, char *, int); static int getgeom(struct vndgeom *, char *); __dead static void usage(void); +static void show_unused(int); int main(int argc, char *argv[]) { int ch, rv, action = VND_CONFIG; + char *end; + unsigned long cnt; - while ((ch = getopt(argc, argv, "Fcf:lrt:uvz")) != -1) { + while ((ch = getopt(argc, argv, "Fcf:lm:rt:uvz")) != -1) { switch (ch) { case 'F': force = 1; @@ -125,6 +131,12 @@ main(int argc, char *argv[]) case 'l': action = VND_GET; break; + case 'm': + cnt = strtoul(optarg, &end, 10); + if (cnt >= INT_MAX || end == optarg || *end != '\0') + usage(); + minimum = (int)cnt; + break; case 'r': readonly = 1; break; @@ -161,51 +173,58 @@ main(int argc, char *argv[]) usage(); rv = config(argv[0], NULL, NULL, action); } else { /* VND_GET */ - int n, v; + int n, vdisk; const char *vn; char path[64]; - if (argc != 0 && argc != 1) - usage(); - - vn = argc ? argv[0] : "vnd0"; + if (argc == 0) { + vn = "vnd0"; - v = opendisk(vn, O_RDONLY, path, sizeof(path), 0); - if (v == -1) - err(1, "open: %s", vn); - - if (argc) - show(v, -1); - else { - DIR *dirp; - struct dirent *dp; - __BITMAP_TYPE(, uint32_t, 65536) bm; - - __BITMAP_ZERO(&bm); - - if ((dirp = opendir(_PATH_DEV)) == NULL) - err(1, "opendir: %s", _PATH_DEV); - - while ((dp = readdir(dirp)) != NULL) { - if (strncmp(dp->d_name, "rvnd", 4) != 0) - continue; - n = atoi(dp->d_name + 4); - if (__BITMAP_ISSET(n, &bm)) - continue; - __BITMAP_SET(n, &bm); - show(v, n); + vdisk = opendisk(vn, O_RDONLY, path, sizeof(path), 0); + if (vdisk == -1) { + if (minimum == 0) + return 1; + err(1, "open: %s", vn); } - closedir(dirp); + for (n = 0; show(vdisk, n, 0); n++) + continue; + while (n < minimum) + show_unused(n++); + close(vdisk); + return 0; } - close(v); + rv = 0; + while (--argc >= 0) { + vn = *argv++; + + vdisk = opendisk(vn, O_RDONLY, path, sizeof(path), 0); + if (vdisk == -1) { + warn("open: %s", vn); + rv = 1; + continue; + } + + if (!show(vdisk, -1, vn)) + rv = 1; + close(vdisk); + } } return rv; } static void -show(int v, int n) +show_unused(int n) +{ + if (minimum == 0) + return; + + printf("vnd%d: not in use\n", n); +} + +static int +show(int v, int n, const char * const name) { struct vnd_user vnu; char *dev; @@ -213,12 +232,18 @@ show(int v, int n) int i, nmount; vnu.vnu_unit = n; - if (ioctl(v, VNDIOCGET, &vnu) == -1) - err(1, "VNDIOCGET"); + if (ioctl(v, VNDIOCGET, &vnu) == -1) { + if (errno != ENXIO) { + if (n != -1) + err(1, "VNDIOCGET"); + warn("%s: VNDIOCGET", name); + } + return 0; + } if (vnu.vnu_ino == 0) { - printf("vnd%d: not in use\n", vnu.vnu_unit); - return; + show_unused(vnu.vnu_unit); + return -1; } printf("vnd%d: ", vnu.vnu_unit); @@ -251,6 +276,7 @@ show(int v, int n) (unsigned long long)minor(vnu.vnu_dev)); printf("inode %llu\n", (unsigned long long)vnu.vnu_ino); + return 1; } static int @@ -399,9 +425,9 @@ usage(void) { (void)fprintf(stderr, "%s%s", - "usage: vnconfig [-crvz] [-f disktab] [-t typename] vnode_disk" - " regular-file [geomspec]\n", + "usage: vnconfig [-crvz] [-f dsktab] [-t type] vnode_disk" + " reg-file [geomspec]\n", " vnconfig -u [-Fv] vnode_disk\n" - " vnconfig -l [vnode_disk]\n"); + " vnconfig -l [-m num | vnode_disk...]\n"); exit(1); }