Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/vnconfig Now that we grow vnd's dynamically we cann...
details: https://anonhg.NetBSD.org/src/rev/0441738638b3
branches: trunk
changeset: 787287:0441738638b3
user: christos <christos%NetBSD.org@localhost>
date: Sun Jun 09 13:25:40 2013 +0000
description:
Now that we grow vnd's dynamically we cannot depend on the kernel returning
ENXIO when we exceed the number of configured vnds, so in the -l case, print
info for all vnds we can find device nodes for in /dev.
diffstat:
usr.sbin/vnconfig/vnconfig.c | 126 ++++++++++++++++++++++++------------------
1 files changed, 73 insertions(+), 53 deletions(-)
diffs (185 lines):
diff -r c87506eca996 -r 0441738638b3 usr.sbin/vnconfig/vnconfig.c
--- a/usr.sbin/vnconfig/vnconfig.c Sun Jun 09 12:52:33 2013 +0000
+++ b/usr.sbin/vnconfig/vnconfig.c Sun Jun 09 13:25:40 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vnconfig.c,v 1.40 2011/08/30 20:54:18 joerg Exp $ */
+/* $NetBSD: vnconfig.c,v 1.41 2013/06/09 13:25:40 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -73,11 +73,13 @@
#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>
@@ -86,6 +88,7 @@
#include <string.h>
#include <unistd.h>
#include <util.h>
+#include <paths.h>
#define VND_CONFIG 1
#define VND_UNCONFIG 2
@@ -97,6 +100,7 @@
static int compressed = 0;
static char *tabname;
+static void show(int, int);
static int config(char *, char *, char *, int);
static int getgeom(struct vndgeom *, char *);
__dead static void usage(void);
@@ -157,10 +161,9 @@
usage();
rv = config(argv[0], NULL, NULL, action);
} else { /* VND_GET */
+ int n, v;
const char *vn;
char path[64];
- struct vnd_user vnu;
- int v, n;
if (argc != 0 && argc != 1)
usage();
@@ -171,66 +174,83 @@
if (v == -1)
err(1, "open: %s", vn);
- for (n = 0; ; n++) {
- vnu.vnu_unit = argc ? -1 : n;
- rv = ioctl(v, VNDIOCGET, &vnu);
- if (rv == -1) {
- if (errno == ENXIO)
- break;
- err(1, "VNDIOCGET");
+ 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);
}
- if (vnu.vnu_ino == 0)
- printf("vnd%d: not in use\n",
- vnu.vnu_unit);
- else {
- char *dev;
- struct statvfs *mnt = NULL;
- int i, nmount;
+ closedir(dirp);
+ }
+ close(v);
+ rv = 0;
+ }
+ return rv;
+}
- nmount = 0; /* XXXGCC -Wuninitialized */
+static void
+show(int v, int n)
+{
+ struct vnd_user vnu;
+ char *dev;
+ struct statvfs *mnt;
+ int i, nmount;
- printf("vnd%d: ", vnu.vnu_unit);
+ vnu.vnu_unit = n;
+ if (ioctl(v, VNDIOCGET, &vnu) == -1)
+ err(1, "VNDIOCGET");
- dev = devname(vnu.vnu_dev, S_IFBLK);
- if (dev != NULL)
- nmount = getmntinfo(&mnt, MNT_NOWAIT);
- else
- mnt = NULL;
- if (mnt != NULL) {
- for (i = 0; i < nmount; i++) {
- if (strncmp(
- mnt[i].f_mntfromname,
- "/dev/", 5) == 0 &&
- strcmp(
- mnt[i].f_mntfromname + 5,
- dev) == 0)
- break;
- }
- if (i < nmount)
- printf("%s (%s) ",
- mnt[i].f_mntonname,
- mnt[i].f_mntfromname);
- else
- printf("%s ", dev);
- }
- else if (dev != NULL)
- printf("%s ", dev);
- else
- printf("dev %llu,%llu ",
- (unsigned long long)major(vnu.vnu_dev),
- (unsigned long long)minor(vnu.vnu_dev));
+ if (vnu.vnu_ino == 0) {
+ printf("vnd%d: not in use\n", vnu.vnu_unit);
+ return;
+ }
+
+ printf("vnd%d: ", vnu.vnu_unit);
- printf("inode %llu\n",
- (unsigned long long)vnu.vnu_ino);
- }
+ dev = devname(vnu.vnu_dev, S_IFBLK);
+ if (dev != NULL)
+ nmount = getmntinfo(&mnt, MNT_NOWAIT);
+ else {
+ mnt = NULL;
+ nmount = 0;
+ }
- if (argc)
+ if (mnt != NULL) {
+ for (i = 0; i < nmount; i++) {
+ if (strncmp(mnt[i].f_mntfromname, "/dev/", 5) == 0 &&
+ strcmp(mnt[i].f_mntfromname + 5, dev) == 0)
break;
}
- close(v);
+ if (i < nmount)
+ printf("%s (%s) ", mnt[i].f_mntonname,
+ mnt[i].f_mntfromname);
+ else
+ printf("%s ", dev);
}
- exit(rv);
+ else if (dev != NULL)
+ printf("%s ", dev);
+ else
+ printf("dev %llu,%llu ",
+ (unsigned long long)major(vnu.vnu_dev),
+ (unsigned long long)minor(vnu.vnu_dev));
+
+ printf("inode %llu\n", (unsigned long long)vnu.vnu_ino);
}
static int
Home |
Main Index |
Thread Index |
Old Index