Author: erj
Date: Mon May  6 21:31:02 2019
New Revision: 347213
URL: https://svnweb.freebsd.org/changeset/base/347213

Log:
  MFC r345312: iflib: mark isc_driver_version as constant
  
  (Additional comment by erj: This also adds a new sysctl_add_oid macro,
  SYSCTL_ADD_CONST_STRING, for displaying const strings. This commit also
  includes an edit to the sysctl.9 man page for it.)
  
  Sponsored by: Intel Corporation

Modified:
  stable/11/share/man/man9/sysctl.9
  stable/11/sys/net/iflib.c
  stable/11/sys/net/iflib.h
  stable/11/sys/sys/sysctl.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/share/man/man9/sysctl.9
==============================================================================
--- stable/11/share/man/man9/sysctl.9   Mon May  6 21:21:15 2019        
(r347212)
+++ stable/11/share/man/man9/sysctl.9   Mon May  6 21:31:02 2019        
(r347213)
@@ -42,6 +42,7 @@
 .Nm SYSCTL_ADD_S32 ,
 .Nm SYSCTL_ADD_S64 ,
 .Nm SYSCTL_ADD_STRING ,
+.Nm SYSCTL_ADD_CONST_STRING ,
 .Nm SYSCTL_ADD_STRUCT ,
 .Nm SYSCTL_ADD_U8 ,
 .Nm SYSCTL_ADD_U16 ,
@@ -67,6 +68,7 @@
 .Nm SYSCTL_S32 ,
 .Nm SYSCTL_S64 ,
 .Nm SYSCTL_STRING ,
+.Nm SYSCTL_CONST_STRING ,
 .Nm SYSCTL_STRUCT ,
 .Nm SYSCTL_U8 ,
 .Nm SYSCTL_U16 ,
@@ -211,6 +213,16 @@
 .Fa "const char *descr"
 .Fc
 .Ft struct sysctl_oid *
+.Fo SYSCTL_ADD_CONST_STRING
+.Fa "struct sysctl_ctx_list *ctx"
+.Fa "struct sysctl_oid_list *parent"
+.Fa "int number"
+.Fa "const char *name"
+.Fa "int ctlflags"
+.Fa "const char *ptr"
+.Fa "const char *descr"
+.Fc
+.Ft struct sysctl_oid *
 .Fo SYSCTL_ADD_STRUCT
 .Fa "struct sysctl_ctx_list *ctx"
 .Fa "struct sysctl_oid_list *parent"
@@ -335,6 +347,7 @@
 .Fn SYSCTL_S32 parent number name ctlflags ptr val descr
 .Fn SYSCTL_S64 parent number name ctlflags ptr val descr
 .Fn SYSCTL_STRING parent number name ctlflags arg len descr
+.Fn SYSCTL_CONST_STRING parent number name ctlflags arg descr
 .Fn SYSCTL_STRUCT parent number name ctlflags ptr struct_type descr
 .Fn SYSCTL_U8 parent number name ctlflags ptr val descr
 .Fn SYSCTL_U16 parent number name ctlflags ptr val descr
@@ -484,6 +497,11 @@ If the
 .Fa len
 argument in zero, the string length is computed at every access to the OID 
using
 .Xr strlen 3 .
+Use the
+.Fn SYSCTL_CONST_STRING
+macro or the
+.Fn SYSCTL_ADD_CONST_STRING
+function to add a sysctl for a constant string.
 .Sh CREATING OPAQUE SYSCTLS
 The
 .Fn SYSCTL_OPAQUE
@@ -528,6 +546,7 @@ Static sysctls are declared using one of the
 .Fn SYSCTL_S32 ,
 .Fn SYSCTL_S64 ,
 .Fn SYSCTL_STRING ,
+.Fn SYSCTL_CONST_STRING ,
 .Fn SYSCTL_STRUCT ,
 .Fn SYSCTL_U8 ,
 .Fn SYSCTL_U16 ,
@@ -552,6 +571,7 @@ Dynamic nodes are created using one of the
 .Fn SYSCTL_ADD_S32 ,
 .Fn SYSCTL_ADD_S64 ,
 .Fn SYSCTL_ADD_STRING ,
+.Fn SYSCTL_ADD_CONST_STRING ,
 .Fn SYSCTL_ADD_STRUCT ,
 .Fn SYSCTL_ADD_U8 ,
 .Fn SYSCTL_ADD_U16 ,

Modified: stable/11/sys/net/iflib.c
==============================================================================
--- stable/11/sys/net/iflib.c   Mon May  6 21:21:15 2019        (r347212)
+++ stable/11/sys/net/iflib.c   Mon May  6 21:31:02 2019        (r347213)
@@ -5844,8 +5844,8 @@ iflib_add_device_sysctl_pre(if_ctx_t ctx)
                                                      CTLFLAG_RD, NULL, "IFLIB 
fields");
        oid_list = SYSCTL_CHILDREN(node);
 
-       SYSCTL_ADD_STRING(ctx_list, oid_list, OID_AUTO, "driver_version",
-                      CTLFLAG_RD, ctx->ifc_sctx->isc_driver_version, 0,
+       SYSCTL_ADD_CONST_STRING(ctx_list, oid_list, OID_AUTO, "driver_version",
+                      CTLFLAG_RD, ctx->ifc_sctx->isc_driver_version,
                       "driver version");
 
        SYSCTL_ADD_U16(ctx_list, oid_list, OID_AUTO, "override_ntxqs",

Modified: stable/11/sys/net/iflib.h
==============================================================================
--- stable/11/sys/net/iflib.h   Mon May  6 21:21:15 2019        (r347212)
+++ stable/11/sys/net/iflib.h   Mon May  6 21:31:02 2019        (r347213)
@@ -242,7 +242,7 @@ struct if_shared_ctx {
 
        /* fields necessary for probe */
        pci_vendor_info_t *isc_vendor_info;
-       char *isc_driver_version;
+       const char *isc_driver_version;
        /* optional function to transform the read values to match the table*/
        void (*isc_parse_devinfo) (uint16_t *device_id, uint16_t *subvendor_id,
                                   uint16_t *subdevice_id, uint16_t *rev_id);

Modified: stable/11/sys/sys/sysctl.h
==============================================================================
--- stable/11/sys/sys/sysctl.h  Mon May  6 21:21:15 2019        (r347212)
+++ stable/11/sys/sys/sysctl.h  Mon May  6 21:31:02 2019        (r347213)
@@ -333,6 +333,24 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
            __arg, len, sysctl_handle_string, "A", __DESCR(descr));     \
 })
 
+/* Oid for a constant '\0' terminated string. */
+#define        SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr)      
\
+       SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),          \
+           __DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \
+       CTASSERT(!(access & CTLFLAG_WR));                               \
+       CTASSERT(((access) & CTLTYPE) == 0 ||                           \
+           ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
+
+#define        SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, 
descr) \
+({                                                                     \
+       char *__arg = __DECONST(char *, arg);                           \
+       CTASSERT(!(access & CTLFLAG_WR));                               \
+       CTASSERT(((access) & CTLTYPE) == 0 ||                           \
+           ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);      \
+       sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \
+           __arg, 0, sysctl_handle_string, "A", __DESCR(descr));       \
+})
+
 /* Oid for a bool.  If ptr is NULL, val is returned. */
 #define        SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
 #define        SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr) \
_______________________________________________
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