Author: allanjude
Date: Thu Sep 17 21:51:05 2020
New Revision: 365860
URL: https://svnweb.freebsd.org/changeset/base/365860

Log:
  Update naming of per-dataset counters introduced in r365689
  
  Upstream OpenZFS is changing the structure of the sysctl mibs to avoid
  having a / in the element name. Chase this change here to avoid introducing
  a new sysctl that will change named between 12.2 and 13.0
  
  MFC-with:     365689
  Relnotes:     yes (fix example)
  Sponsored by: Klara Inc.

Modified:
  stable/12/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c

Modified: stable/12/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c
==============================================================================
--- stable/12/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c      Thu Sep 
17 21:24:11 2020        (r365859)
+++ stable/12/sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c      Thu Sep 
17 21:51:05 2020        (r365860)
@@ -55,6 +55,7 @@ kstat_create(char *module, int instance, char *name, c
 {
        struct sysctl_oid *root;
        kstat_t *ksp;
+       char *pool;
 
        KASSERT(instance == 0, ("instance=%d", instance));
        KASSERT(type == KSTAT_TYPE_NAMED, ("type=%hhu", type));
@@ -70,9 +71,18 @@ kstat_create(char *module, int instance, char *name, c
        ksp->ks_update = kstat_default_update;
 
        /*
+        * Some kstats use a module name like "zfs/poolname" to distinguish a
+        * set of kstats belonging to a specific pool.  Split on '/' to add an
+        * extra node for the pool name if needed.
+        */
+       pool = strchr(module, '/');
+       if (pool != NULL)
+               *pool++ = '\0';
+
+       /*
         * Create sysctl tree for those statistics:
         *
-        *      kstat.<module>.<class>.<name>.
+        *      kstat.<module>[.<pool>].<class>.<name>
         */
        sysctl_ctx_init(&ksp->ks_sysctl_ctx);
        root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx,
@@ -84,11 +94,26 @@ kstat_create(char *module, int instance, char *name, c
                free(ksp, M_KSTAT);
                return (NULL);
        }
+       if (pool != NULL) {
+               root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx,
+                   SYSCTL_CHILDREN(root), OID_AUTO, pool, CTLFLAG_RW, 0, "");
+               if (root == NULL) {
+                       printf("%s: Cannot create kstat.%s.%s tree!\n",
+                           __func__, module, pool);
+                       sysctl_ctx_free(&ksp->ks_sysctl_ctx);
+                       free(ksp, M_KSTAT);
+                       return (NULL);
+               }
+       }
        root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
            OID_AUTO, class, CTLFLAG_RW, 0, "");
        if (root == NULL) {
-               printf("%s: Cannot create kstat.%s.%s tree!\n", __func__,
-                   module, class);
+               if (pool != NULL)
+                       printf("%s: Cannot create kstat.%s.%s.%s tree!\n",
+                           __func__, module, pool, class);
+               else
+                       printf("%s: Cannot create kstat.%s.%s tree!\n",
+                           __func__, module, class);
                sysctl_ctx_free(&ksp->ks_sysctl_ctx);
                free(ksp, M_KSTAT);
                return (NULL);
@@ -96,8 +121,13 @@ kstat_create(char *module, int instance, char *name, c
        root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
            OID_AUTO, name, CTLFLAG_RW, 0, "");
        if (root == NULL) {
-               printf("%s: Cannot create kstat.%s.%s.%s tree!\n", __func__,
-                   module, class, name);
+               if (pool != NULL)
+                       printf("%s: Cannot create kstat.%s.%s.%s.%s "
+                           "tree!\n", __func__, module, pool, class,
+                           name);
+               else
+                       printf("%s: Cannot create kstat.%s.%s.%s "
+                           "tree!\n", __func__, module, class, name);
                sysctl_ctx_free(&ksp->ks_sysctl_ctx);
                free(ksp, M_KSTAT);
                return (NULL);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to