Module Name: src
Committed By: pooka
Date: Sat May 16 15:03:12 UTC 2015
Modified Files:
src/sys/rump/dev/lib/libvirtio_ld: ld_at_virtio.c
Log Message:
Autogenerate /dev/ldNx nodes based on which units attached instead of
hardcoding some arbitrary value for N.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c
diff -u src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c:1.1 src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c:1.2
--- src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c:1.1 Fri Aug 22 09:57:05 2014
+++ src/sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c Sat May 16 15:03:12 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: ld_at_virtio.c,v 1.1 2014/08/22 09:57:05 pooka Exp $ */
+/* $NetBSD: ld_at_virtio.c,v 1.2 2015/05/16 15:03:12 pooka Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@@ -26,13 +26,14 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_at_virtio.c,v 1.1 2014/08/22 09:57:05 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_at_virtio.c,v 1.2 2015/05/16 15:03:12 pooka Exp $");
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/bus.h>
#include <sys/stat.h>
+#include <sys/disklabel.h>
#include "rump_private.h"
#include "rump_vfs_private.h"
@@ -46,21 +47,38 @@ RUMP_COMPONENT(RUMP_COMPONENT_DEV)
cfattach_ioconf_virtio_ld, cfdata_ioconf_virtio_ld);
}
-RUMP_COMPONENT(RUMP_COMPONENT_VFS)
+/*
+ * Pseudo-devfs. Since creating device nodes is non-free, don't
+ * speculatively create hundreds of them (= milliseconds slower
+ * bootstrap). Instead, after the probe is done, see which units
+ * were found and create nodes only for them.
+ */
+RUMP_COMPONENT(RUMP_COMPONENT_POSTINIT)
{
extern const struct bdevsw ld_bdevsw;
extern const struct cdevsw ld_cdevsw;
devmajor_t bmaj = -1, cmaj = -1;
- int error;
+ int error, i;
if ((error = devsw_attach("ld", &ld_bdevsw, &bmaj,
&ld_cdevsw, &cmaj)) != 0)
panic("cannot attach ld: %d", error);
- if ((error = rump_vfs_makedevnodes(S_IFBLK, "/dev/ld0", 'a',
- bmaj, 0, 7)) != 0)
- panic("cannot create cooked ld dev nodes: %d", error);
- if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/rld0", 'a',
- cmaj, 0, 7)) != 0)
- panic("cannot create raw ld dev nodes: %d", error);
+ for (i = 0; i < 10; i++) {
+ char bbase[] = "/dev/ldX";
+ char rbase[] = "/dev/rldX";
+
+ if (device_lookup(&ld_cd, i) == NULL)
+ break;
+
+ bbase[sizeof(bbase)-2] = '0' + i;
+ rbase[sizeof(rbase)-2] = '0' + i;
+
+ if ((error = rump_vfs_makedevnodes(S_IFBLK, bbase, 'a',
+ bmaj, DISKMINOR(i, 0), 5)) != 0)
+ panic("cannot create cooked ld dev nodes: %d", error);
+ if ((error = rump_vfs_makedevnodes(S_IFCHR, rbase, 'a',
+ cmaj, DISKMINOR(i, 0), 5)) != 0)
+ panic("cannot create raw ld dev nodes: %d", error);
+ }
}