Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Mar 2009 18:16:03 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r189638 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb kern sys
Message-ID:  <200903101816.n2AIG3b5069869@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Mar 10 18:16:03 2009
New Revision: 189638
URL: http://svn.freebsd.org/changeset/base/189638

Log:
  MFC: Add sysctl_rename_oid() and use it in device_set_unit().

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/kern/kern_sysctl.c
  stable/7/sys/kern/subr_bus.c
  stable/7/sys/sys/sysctl.h

Modified: stable/7/sys/kern/kern_sysctl.c
==============================================================================
--- stable/7/sys/kern/kern_sysctl.c	Tue Mar 10 17:57:41 2009	(r189637)
+++ stable/7/sys/kern/kern_sysctl.c	Tue Mar 10 18:16:03 2009	(r189638)
@@ -417,6 +417,25 @@ sysctl_add_oid(struct sysctl_ctx_list *c
 }
 
 /*
+ * Rename an existing oid.
+ */
+void
+sysctl_rename_oid(struct sysctl_oid *oidp, const char *name)
+{
+	ssize_t len;
+	char *newname;
+	void *oldname;
+
+	oldname = (void *)(uintptr_t)(const void *)oidp->oid_name;
+	len = strlen(name);
+	newname = malloc(len + 1, M_SYSCTLOID, M_WAITOK);
+	bcopy(name, newname, len + 1);
+	newname[len] = '\0';
+	oidp->oid_name = newname;
+	free(oldname, M_SYSCTLOID);
+}
+
+/*
  * Reparent an existing oid.
  */
 int

Modified: stable/7/sys/kern/subr_bus.c
==============================================================================
--- stable/7/sys/kern/subr_bus.c	Tue Mar 10 17:57:41 2009	(r189637)
+++ stable/7/sys/kern/subr_bus.c	Tue Mar 10 18:16:03 2009	(r189638)
@@ -307,6 +307,16 @@ device_sysctl_init(device_t dev)
 }
 
 static void
+device_sysctl_update(device_t dev)
+{
+	devclass_t dc = dev->devclass;
+
+	if (dev->sysctl_tree == NULL)
+		return;
+	sysctl_rename_oid(dev->sysctl_tree, dev->nameunit + strlen(dc->name));
+}
+
+static void
 device_sysctl_fini(device_t dev)
 {
 	if (dev->sysctl_tree == NULL)
@@ -2396,6 +2406,7 @@ device_attach(device_t dev)
 		dev->state = DS_NOTPRESENT;
 		return (error);
 	}
+	device_sysctl_update(dev);
 	dev->state = DS_ATTACHED;
 	devadded(dev);
 	return (0);

Modified: stable/7/sys/sys/sysctl.h
==============================================================================
--- stable/7/sys/sys/sysctl.h	Tue Mar 10 17:57:41 2009	(r189637)
+++ stable/7/sys/sys/sysctl.h	Tue Mar 10 18:16:03 2009	(r189638)
@@ -661,6 +661,7 @@ struct sysctl_oid *sysctl_add_oid(struct
 		int kind, void *arg1, int arg2,
 		int (*handler) (SYSCTL_HANDLER_ARGS),
 		const char *fmt, const char *descr);
+void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
 int	sysctl_move_oid(struct sysctl_oid *oidp,
 		struct sysctl_oid_list *parent);
 int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903101816.n2AIG3b5069869>