Re: svn commit: r365268 - in head: sbin/sysctl sys/kern

2020-09-02 Thread John Baldwin
On 9/2/20 12:09 PM, Mark Johnston wrote:
> On Wed, Sep 02, 2020 at 11:43:56AM -0700, John Baldwin wrote:
>> On 9/2/20 11:17 AM, Mark Johnston wrote:
>>> Author: markj
>>> Date: Wed Sep  2 18:17:08 2020
>>> New Revision: 365268
>>> URL: https://svnweb.freebsd.org/changeset/base/365268
>>>
>>> Log:
>>>   Add sysctl(8) formatting for hw.pagesizes.
>>>   
>>>   - Change the type of hw.pagesizes to OPAQUE, since it returns an array.
>>>   - Modify the handler to only truncate the returned length if the caller
>>> supplied an output buffer.  This allows use of the trick of passing a
>>> NULL output buffer to fetch the output size, while preserving
>>> compatibility if MAXPAGESIZES is increased.
>>>   - Add a "S,pagesize" formatter to sysctl(8).
>>
>> Doesn't sysctl(8) handle scalar types that are arrays?  That is, couldn't
>> this change just be the change to not truncate 'len' without needing to make
>> it opaque and needing a custom printer, etc.?
> 
> I think you are right.  I didn't know sysctl(8) could do that.

I only know from dealing with it in the past.  kern.cp_time is an array
for example.  In the past year or so I updated sysctl to permit setting
an array of values (for dev.t6nex.0.toe.rx_tls_ports which takes a list
of TCP ports to enable TOE TLS on).

-- 
John Baldwin
___
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"


Re: svn commit: r365268 - in head: sbin/sysctl sys/kern

2020-09-02 Thread Mark Johnston
On Wed, Sep 02, 2020 at 11:43:56AM -0700, John Baldwin wrote:
> On 9/2/20 11:17 AM, Mark Johnston wrote:
> > Author: markj
> > Date: Wed Sep  2 18:17:08 2020
> > New Revision: 365268
> > URL: https://svnweb.freebsd.org/changeset/base/365268
> > 
> > Log:
> >   Add sysctl(8) formatting for hw.pagesizes.
> >   
> >   - Change the type of hw.pagesizes to OPAQUE, since it returns an array.
> >   - Modify the handler to only truncate the returned length if the caller
> > supplied an output buffer.  This allows use of the trick of passing a
> > NULL output buffer to fetch the output size, while preserving
> > compatibility if MAXPAGESIZES is increased.
> >   - Add a "S,pagesize" formatter to sysctl(8).
> 
> Doesn't sysctl(8) handle scalar types that are arrays?  That is, couldn't
> this change just be the change to not truncate 'len' without needing to make
> it opaque and needing a custom printer, etc.?

I think you are right.  I didn't know sysctl(8) could do that.
___
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"


Re: svn commit: r365268 - in head: sbin/sysctl sys/kern

2020-09-02 Thread John Baldwin
On 9/2/20 11:17 AM, Mark Johnston wrote:
> Author: markj
> Date: Wed Sep  2 18:17:08 2020
> New Revision: 365268
> URL: https://svnweb.freebsd.org/changeset/base/365268
> 
> Log:
>   Add sysctl(8) formatting for hw.pagesizes.
>   
>   - Change the type of hw.pagesizes to OPAQUE, since it returns an array.
>   - Modify the handler to only truncate the returned length if the caller
> supplied an output buffer.  This allows use of the trick of passing a
> NULL output buffer to fetch the output size, while preserving
> compatibility if MAXPAGESIZES is increased.
>   - Add a "S,pagesize" formatter to sysctl(8).

Doesn't sysctl(8) handle scalar types that are arrays?  That is, couldn't
this change just be the change to not truncate 'len' without needing to make
it opaque and needing a custom printer, etc.?

-- 
John Baldwin
___
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"


svn commit: r365268 - in head: sbin/sysctl sys/kern

2020-09-02 Thread Mark Johnston
Author: markj
Date: Wed Sep  2 18:17:08 2020
New Revision: 365268
URL: https://svnweb.freebsd.org/changeset/base/365268

Log:
  Add sysctl(8) formatting for hw.pagesizes.
  
  - Change the type of hw.pagesizes to OPAQUE, since it returns an array.
  - Modify the handler to only truncate the returned length if the caller
supplied an output buffer.  This allows use of the trick of passing a
NULL output buffer to fetch the output size, while preserving
compatibility if MAXPAGESIZES is increased.
  - Add a "S,pagesize" formatter to sysctl(8).
  
  Reviewed by:  alc, kib
  MFC after:2 weeks
  Sponsored by: Juniper Networks, Inc.
  Sponsored by: Klara, Inc.
  Differential Revision:https://reviews.freebsd.org/D26239

Modified:
  head/sbin/sysctl/sysctl.c
  head/sys/kern/kern_mib.c

Modified: head/sbin/sysctl/sysctl.c
==
--- head/sbin/sysctl/sysctl.c   Wed Sep  2 18:16:43 2020(r365267)
+++ head/sbin/sysctl/sysctl.c   Wed Sep  2 18:17:08 2020(r365268)
@@ -697,6 +697,29 @@ S_input_id(size_t l2, void *p)
return (0);
 }
 
+static int
+S_pagesizes(size_t l2, void *p)
+{
+   char buf[256];
+   u_long *ps;
+   size_t l;
+   int i;
+
+   l = snprintf(buf, sizeof(buf), "{ ");
+   ps = p;
+   for (i = 0; i * sizeof(*ps) < l2 && ps[i] != 0 && l < sizeof(buf);
+   i++) {
+   l += snprintf([l], sizeof(buf) - l,
+   "%s%lu", i == 0 ? "" : ", ", ps[i]);
+   }
+   if (l < sizeof(buf))
+   (void)snprintf([l], sizeof(buf) - l, " }");
+
+   printf("%s", buf);
+
+   return (0);
+}
+
 #ifdef __amd64__
 static int
 S_efi_map(size_t l2, void *p)
@@ -1002,6 +1025,8 @@ show_var(int *oid, int nlen)
func = S_vmtotal;
else if (strcmp(fmt, "S,input_id") == 0)
func = S_input_id;
+   else if (strcmp(fmt, "S,pagesizes") == 0)
+   func = S_pagesizes;
 #ifdef __amd64__
else if (strcmp(fmt, "S,efi_map_header") == 0)
func = S_efi_map;

Modified: head/sys/kern/kern_mib.c
==
--- head/sys/kern/kern_mib.cWed Sep  2 18:16:43 2020(r365267)
+++ head/sys/kern/kern_mib.cWed Sep  2 18:17:08 2020(r365268)
@@ -246,22 +246,22 @@ sysctl_hw_pagesizes(SYSCTL_HANDLER_ARGS)
pagesizes32[i] = (uint32_t)pagesizes[i];
 
len = sizeof(pagesizes32);
-   if (len > req->oldlen)
+   if (len > req->oldlen && req->oldptr != NULL)
len = req->oldlen;
error = SYSCTL_OUT(req, pagesizes32, len);
} else
 #endif
{
len = sizeof(pagesizes);
-   if (len > req->oldlen)
+   if (len > req->oldlen && req->oldptr != NULL)
len = req->oldlen;
error = SYSCTL_OUT(req, pagesizes, len);
}
return (error);
 }
 SYSCTL_PROC(_hw, OID_AUTO, pagesizes,
-CTLTYPE_ULONG | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0, 
-sysctl_hw_pagesizes, "LU",
+CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
+sysctl_hw_pagesizes, "S,pagesizes",
 "Supported page sizes");
 
 int adaptive_machine_arch = 1;
___
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"