tech-userlevel archive

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

Re: wedge device to name



In article <qltvkd$4ck$1%serpens.de@localhost>,
Michael van Elst <mlelstv%serpens.de@localhost> wrote:
>manu%netbsd.org@localhost (Emmanuel Dreyfus) writes:
>
>>But since almost all commands do the NAME=label to /dev/device translation,
>>you can take NAME=label as a device path.
>
>Only some NetBSD commands do. Most are old-fashioned and want file paths
>to deal with, and that's where the current mount output may come handy.
>
>There's nothing against an option making mount or df print wedge names
>and people can just use aliases in their profile.

I added that to df, but it needs root/operator in order to access the
device node to get wedge info. I also wrote a patch to expose the
wedge info via sysctl:

$ sysctl -a | grep dkw
hw.dkwedge.dk0.wname = wd0a
hw.dkwedge.dk0.parent = wd0
hw.dkwedge.dk0.ptype = ffs
hw.dkwedge.dk0.size = 201326529
hw.dkwedge.dk0.offset = 63
hw.dkwedge.dk1.wname = wd0b
hw.dkwedge.dk1.parent = wd0
hw.dkwedge.dk1.ptype = swap
hw.dkwedge.dk1.size = 8388608
hw.dkwedge.dk1.offset = 201326592

But I am not sure if I should commit it... Here it is... Should I?

christos

Index: df/df.c
===================================================================
RCS file: /cvsroot/src/bin/df/df.c,v
retrieving revision 1.94
diff -u -p -u -r1.94 df.c
--- df/df.c	18 Sep 2019 20:14:44 -0000	1.94
+++ df/df.c	19 Sep 2019 02:49:43 -0000
@@ -54,6 +54,7 @@ __RCSID("$NetBSD: df.c,v 1.94 2019/09/18
 #include <sys/mount.h>
 #include <sys/disk.h>
 #include <sys/ioctl.h>
+#include <sys/sysctl.h>
 
 #include <assert.h>
 #include <err.h>
@@ -310,8 +311,12 @@ getwedgeinfo(const struct statvfs *mntbu
 		}
 		rdn++;
 		int fd = opendisk(rdn, O_RDONLY, buf, sizeof(buf), false);
-		if (fd == -1)
-			err(EXIT_FAILURE, "opendisk on `%s' failed", rdn);
+		if (fd == -1) {
+			size_t oldlen = sizeof(wi[i].dkw_wname);
+			snprintf(buf, sizeof(buf), "hw.dkwedge.%s.wname", rdn);
+			sysctlbyname(buf, wi[i].dkw_wname, &oldlen, NULL, 0);
+			continue;
+		}
 		if (ioctl(fd, DIOCGWEDGEINFO, &wi[i]) == -1) {
 			warn("DIOCGWEDGEINFO for `%s' failed", buf);
 		}
Index: dk.c
===================================================================
RCS file: /cvsroot/src/sys/dev/dkwedge/dk.c,v
retrieving revision 1.97
diff -u -p -u -r1.97 dk.c
--- dk.c	12 May 2018 10:33:06 -0000	1.97
+++ dk.c	19 Sep 2019 02:50:02 -0000
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.97 
 #include <sys/pool.h>
 #include <sys/ioctl.h>
 #include <sys/disklabel.h>
+#include <sys/sysctl.h>
 #include <sys/disk.h>
 #include <sys/fcntl.h>
 #include <sys/buf.h>
@@ -90,6 +91,7 @@ struct dkwedge_softc {
 	kcondvar_t	sc_dkdrn;
 	u_int		sc_iopend;	/* I/Os pending */
 	int		sc_flags;	/* flags (sc_iolock) */
+	struct sysctllog *sc_sysctllog;	/* sysctl info */
 };
 
 #define	DK_F_WAIT_DRAIN		0x0001	/* waiting for I/O to drain */
@@ -107,6 +109,9 @@ static int	dkwedge_del1(struct dkwedge_i
 static int	dk_open_parent(dev_t, int, struct vnode **);
 static int	dk_close_parent(struct vnode *, int);
 
+static void	dkwedge_sysctl_attach(struct dkwedge_softc *);
+static void	dkwedge_sysctl_detach(struct dkwedge_softc *);
+
 static dev_type_open(dkopen);
 static dev_type_close(dkclose);
 static dev_type_read(dkread);
@@ -483,6 +488,8 @@ dkwedge_add(struct dkwedge_info *dkw)
 	    sc->sc_size, sc->sc_offset,
 	    sc->sc_ptype[0] == '\0' ? "<unknown>" : sc->sc_ptype);
 
+	dkwedge_sysctl_attach(sc);
+
 	return (0);
 }
 
@@ -545,6 +552,8 @@ dkwedge_del1(struct dkwedge_info *dkw, i
 	if ((sc = dkwedge_find(dkw, NULL)) == NULL)
 		return (ESRCH);
 
+	dkwedge_sysctl_detach(sc);
+
 	return config_detach(sc->sc_dev, flags);
 }
 
@@ -1684,3 +1693,68 @@ dkwedge_get_parent_name(dev_t dev)
 	return sc->sc_parent->dk_name;
 }
 
+static void
+dkwedge_sysctl_detach(struct dkwedge_softc *sc)
+{
+	sysctl_teardown(&sc->sc_sysctllog);
+}
+
+static void
+dkwedge_sysctl_attach(struct dkwedge_softc *sc)
+{
+	int rc;
+	static const struct sysctlnode *rnode;
+	static struct sysctllog *dlog;
+	const struct sysctlnode *dnode;
+
+	struct sysctllog **clog = &sc->sc_sysctllog;
+
+	if (rnode == NULL) {
+		if ((rc = sysctl_createv(&dlog, 0, NULL, &rnode,
+		    CTLFLAG_PERMANENT, CTLTYPE_NODE, "dkwedge",
+		    SYSCTL_DESCR("wedge root"),
+		    NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
+			goto err;
+	}
+
+	if ((rc = sysctl_createv(clog, 0, &rnode, &dnode,
+	    CTLFLAG_READONLY, CTLTYPE_NODE, device_xname(sc->sc_dev),
+	    SYSCTL_DESCR("wedge info"),
+	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(clog, 0, &dnode, NULL,
+	    CTLFLAG_READONLY, CTLTYPE_STRING, "wname",
+	    SYSCTL_DESCR("wedge name"),
+	    NULL, 0, sc->sc_wname, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(clog, 0, &dnode, NULL,
+	    CTLFLAG_READONLY, CTLTYPE_STRING, "parent",
+	    SYSCTL_DESCR("parent disk name"),
+	    NULL, 0, __UNCONST(sc->sc_parent->dk_name), 0,
+	    CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(clog, 0, &dnode, NULL,
+	    CTLFLAG_READONLY, CTLTYPE_STRING, "ptype",
+	    SYSCTL_DESCR("partition type"),
+	    NULL, 0, sc->sc_ptype, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(clog, 0, &dnode, NULL,
+	    CTLFLAG_READONLY, CTLTYPE_QUAD, "size",
+	    SYSCTL_DESCR("size in blocks"),
+	    NULL, 0, &sc->sc_size, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	if ((rc = sysctl_createv(clog, 0, &dnode, NULL,
+	    CTLFLAG_READONLY, CTLTYPE_QUAD, "offset",
+	    SYSCTL_DESCR("LBA offset in blocks"),
+	    NULL, 0, &sc->sc_offset, 0, CTL_CREATE, CTL_EOL)) != 0)
+		goto err;
+
+	return;
+err:
+	aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
+}





Home | Main Index | Thread Index | Old Index