Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/vnconfig Cosmetic tweaks to vncfonfig -l output, fr...



details:   https://anonhg.NetBSD.org/src/rev/baccb5f86180
branches:  trunk
changeset: 344653:baccb5f86180
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Apr 10 09:04:09 2016 +0000

description:
Cosmetic tweaks to vncfonfig -l output, from Robert Elz (with minor tweaks
[and all bugs] by me). This should restore compatibility for old scripts
trying to find free vnodes in the new cloning world order.

diffstat:

 usr.sbin/vnconfig/vnconfig.8 |  76 ++++++++++++++++++++++++++++++++----
 usr.sbin/vnconfig/vnconfig.c |  90 ++++++++++++++++++++++++++++++++-----------
 2 files changed, 132 insertions(+), 34 deletions(-)

diffs (truncated from 314 to 300 lines):

diff -r b4d640a8ad4a -r baccb5f86180 usr.sbin/vnconfig/vnconfig.8
--- a/usr.sbin/vnconfig/vnconfig.8      Sun Apr 10 08:15:52 2016 +0000
+++ b/usr.sbin/vnconfig/vnconfig.8      Sun Apr 10 09:04:09 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: vnconfig.8,v 1.40 2015/11/05 22:35:24 pgoyette Exp $
+.\"    $NetBSD: vnconfig.8,v 1.41 2016/04/10 09:04:09 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 @@
 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 @@
 .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 @@
 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 @@
 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 @@
 .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 @@
 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 @@
 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.)
diff -r b4d640a8ad4a -r baccb5f86180 usr.sbin/vnconfig/vnconfig.c
--- a/usr.sbin/vnconfig/vnconfig.c      Sun Apr 10 08:15:52 2016 +0000
+++ b/usr.sbin/vnconfig/vnconfig.c      Sun Apr 10 09:04:09 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnconfig.c,v 1.43 2015/11/09 17:39:20 christos Exp $   */
+/*     $NetBSD: vnconfig.c,v 1.44 2016/04/10 09:04:09 martin Exp $     */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -87,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 int     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;
@@ -123,6 +131,12 @@
                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;
@@ -159,33 +173,58 @@
                        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();
+               if (argc == 0) {
+                       vn = "vnd0";
 
-               vn = argc ? argv[0] : "vnd0";
-
-               v = opendisk(vn, O_RDONLY, path, sizeof(path), 0);
-               if (v == -1)
-                       err(1, "open: %s", vn);
+                       vdisk = opendisk(vn, O_RDONLY, path, sizeof(path), 0);
+                       if (vdisk == -1) {
+                               if (minimum == 0)
+                                       return 1;
+                               err(1, "open: %s", vn);
+                       }
 
-               if (argc)
-                       show(v, -1);
-               else {
-                       for (n = 0; show(v, n); n++)
+                       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_unused(int n)
+{
+       if (minimum == 0) 
+               return;
+
+       printf("vnd%d: not in use\n", n);
+}
+
 static int
-show(int v, int n)
+show(int v, int n, const char * const name)
 {
        struct vnd_user vnu;
        char *dev;
@@ -194,14 +233,17 @@
 
        vnu.vnu_unit = n;
        if (ioctl(v, VNDIOCGET, &vnu) == -1) {
-               if (errno != ENXIO)
-                       err(1, "VNDIOCGET");
+               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 1;
+               show_unused(vnu.vnu_unit);
+               return -1;
        }
 



Home | Main Index | Thread Index | Old Index