Re: sysctl fix

2013-06-09 Thread Ted Unangst
On Thu, Jun 06, 2013 at 23:58, Sylvestre Gallon wrote:
 Here is a second one to add fuse sysctls.

 +#define FUSEFS_NB_OPENDEVS   1   /* # of fuse devices opened */

Applied, except I changed this to FUSEFS_OPENDEVS, which seemed a
little simpler. Thanks.



sysctl fix

2013-06-06 Thread Sylvestre Gallon
Hi tech@

I was currently trying to get the fuse sysctls working when I found a bug
in sbin/sysctl.c

If you look at sys/kern/vfs_init.c MOUNT_FUSEFS use the biggest typenum : 18.
So when the function vfsinit in sbin/sysctl.c gets VFS_MAXTYPENUM it gets 
18, but this value will never be reached in the for statement...

I jump on the occasion to remove all compilation warnings for sysctl.

Cheers,

Index: sysctl.c
===
RCS file: /cvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.189
diff -u -p -u -p -r1.189 sysctl.c
--- sysctl.c16 Apr 2013 22:06:48 -  1.189
+++ sysctl.c6 Jun 2013 12:07:38 -
@@ -268,7 +268,8 @@ void
 listall(char *prefix, struct list *lp)
 {
char *cp, name[BUFSIZ];
-   int lvl2, len;
+   size_t len;
+   int lvl2;
 
if (lp-list == NULL)
return;
@@ -861,7 +862,7 @@ parse(char *string, int flags)
}
if (special  RNDSTATS) {
struct rndstats *rndstats = (struct rndstats *)buf;
-   int i;
+   size_t i;
 
if (!nflag)
(void)printf(%s%s, string, equ);
@@ -1025,7 +1026,7 @@ parse_ports(char *portspec, int *port, i
 
 void
 parse_baddynamic(int mib[], size_t len, char *string, void **newvalp,
-size_t *newsizep, int flags, int nflag)
+size_t *newsizep, int flags, int nf)
 {
static u_int32_t newbaddynamic[DP_MAPSIZE];
int port, high_port, baddynamic_loaded = 0, full_list_set = 0;
@@ -1043,7 +1044,7 @@ parse_baddynamic(int mib[], size_t len, 
size, 0, 0) == -1) {
if (flags == 0)
return;
-   if (!nflag)
+   if (!nf)
printf(%s: , string);
puts(kernel does contain bad dynamic 
port tables);
@@ -1138,8 +1139,8 @@ vfsinit(void)
}
mib[2] = VFS_CONF;
buflen = sizeof vfc;
-   for (loc = lastused, cnt = 1; cnt  maxtypenum; cnt++) {
-   mib[3] = cnt - 1;
+   for (loc = lastused, cnt = 0; cnt  maxtypenum; cnt++) {
+   mib[3] = cnt;
if (sysctl(mib, 4, vfc, buflen, (void *)0, (size_t)0)  0) {
if (errno == EOPNOTSUPP)
continue;
@@ -1280,13 +1281,13 @@ sysctl_bios(char *string, char **bufpp, 
mib[2] = indx;
if (indx == BIOS_DISKINFO) {
if (*bufpp == NULL) {
-   char name[BUFSIZ];
+   char str[BUFSIZ];
 
/* scan all the bios devices */
for (indx = 0; indx  256; indx++) {
-   snprintf(name, sizeof(name), %s.%u,
+   snprintf(str, sizeof(str), %s.%u,
string, indx);
-   parse(name, 1);
+   parse(str, 1);
}
return (-1);
}
@@ -1782,10 +1783,10 @@ sysctl_forkstat(char *string, char **buf
 int
 sysctl_malloc(char *string, char **bufpp, int mib[], int flags, int *typep)
 {
-   int indx, stor, i;
+   int indx, stor;
char *name, bufp[SYSCTL_BUFSIZ], *buf, *ptr;
struct list lp;
-   size_t size;
+   size_t size, i;
 
if (*bufpp == NULL) {
listall(string, kernmalloclist);
@@ -2282,7 +2283,7 @@ sysctl_tc(char *string, char **bufpp, in
 int
 sysctl_sensors(char *string, char **bufpp, int mib[], int flags, int *typep)
 {
-   char *devname, *typename;
+   char *name, *typename;
int dev, numt, i;
enum sensor_type type;
struct sensordev snsrdev;
@@ -2312,7 +2313,7 @@ sysctl_sensors(char *string, char **bufp
 * provided below hw.sensors tree.
 * The first branch of hw.sensors tree is the device name.
 */
-   if ((devname = strsep(bufpp, .)) == NULL) {
+   if ((name = strsep(bufpp, .)) == NULL) {
warnx(%s: incomplete specification, string);
return (-1);
}
@@ -2325,11 +2326,11 @@ sysctl_sensors(char *string, char **bufp
if (errno == ENOENT)
break;
}
-   if (strcmp(devname, snsrdev.xname) == 0)
+   if (strcmp(name, snsrdev.xname) == 0)
break;
}
-   if (strcmp(devname, snsrdev.xname) != 0) {
-   warnx(%s: sensor device not found: %s, string, devname);
+   if (strcmp(name, snsrdev.xname) != 0) {
+   warnx(%s: sensor device not found: %s, string, name);
return (-1);
}
if (*bufpp == 

Re: sysctl fix

2013-06-06 Thread Alexey E. Suslikov
Sylvestre Gallon ccna.syl at gmail.com writes:

  at  at  -2586,6 +2587,7  at  at  struct emulname {
  } *emul_names;
  int  emul_num, nemuls;
  int  emul_init(void);
 +int  emulcmp(const void *, const void *);

this seems unrelated to rest of changes you've made. no?



Re: sysctl fix

2013-06-06 Thread Sylvestre Gallon
On Thu, Jun 6, 2013 at 4:39 PM, Alexey E. Suslikov
alexey.susli...@gmail.com wrote:
 int  emulcmp(const void *, const void *);

using WARNINGS=yes make it remove the following warning :

sysctl.c:2697: warning: no previous prototype for 'emulcmp'

Cheers,


--
Sylvestre Gallon



Re: sysctl fix

2013-06-06 Thread Ted Unangst
On Thu, Jun 06, 2013 at 15:39, Sylvestre Gallon wrote:
 Hi tech@
 
 I was currently trying to get the fuse sysctls working when I found a bug
 in sbin/sysctl.c
 
 If you look at sys/kern/vfs_init.c MOUNT_FUSEFS use the biggest typenum : 18.
 So when the function vfsinit in sbin/sysctl.c gets VFS_MAXTYPENUM it gets
 18, but this value will never be reached in the for statement...
 
 I jump on the occasion to remove all compilation warnings for sysctl.

Unfortunately, this makes it hard to see the real change. Can you do
just the fix as a diff please? I'm happy to fix the warnings too, but
separately.



Re: sysctl fix

2013-06-06 Thread Ted Unangst
On Thu, Jun 06, 2013 at 11:42, patrick keshishian wrote:

 Just curious, how do the variable name changes help any
 warrnings?
 
 nflag - nf

-Wshadow. nflag is a global, which becomes hidden by giving a local
parameter the same name. The code is kind of silly anyway, since the
only call to that function passes the global in, so the local version
will never have a different value. Could just delete the parameter
entirely.



Re: sysctl fix

2013-06-06 Thread Sylvestre Gallon
Hi,

Sorry for the last mistakes. Here is a new diff that allow the
maxtypenum to be reached.

Cheers,

Index: sysctl.c
===
RCS file: /cvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.189
diff -u -p -r1.189 sysctl.c
--- sysctl.c16 Apr 2013 22:06:48 -  1.189
+++ sysctl.c6 Jun 2013 21:19:32 -
@@ -1138,8 +1138,8 @@ vfsinit(void)
}
mib[2] = VFS_CONF;
buflen = sizeof vfc;
-   for (loc = lastused, cnt = 1; cnt  maxtypenum; cnt++) {
-   mib[3] = cnt - 1;
+   for (loc = lastused, cnt = 0; cnt  maxtypenum; cnt++) {
+   mib[3] = cnt;
if (sysctl(mib, 4, vfc, buflen, (void *)0, (size_t)0)  0) {
if (errno == EOPNOTSUPP)
continue;



Re: sysctl fix

2013-06-06 Thread Sylvestre Gallon
Here is a second one to add fuse sysctls.

Cheers,

Index: sys/miscfs/fuse/fusefs.h
===
RCS file: /cvs/src/sys/miscfs/fuse/fusefs.h,v
retrieving revision 1.1
diff -u -p -r1.1 fusefs.h
--- sys/miscfs/fuse/fusefs.h3 Jun 2013 15:50:56 -   1.1
+++ sys/miscfs/fuse/fusefs.h6 Jun 2013 21:41:36 -
@@ -18,6 +18,23 @@
 #ifndef __FUSEFS_H__
 #define __FUSEFS_H__
 
+/* sysctl defines */
+#define FUSEFS_NB_OPENDEVS 1   /* # of fuse devices opened */
+#define FUSEFS_INFBUFS 2   /* # of in fbufs */
+#define FUSEFS_WAITFBUFS   3   /* # of fbufs waiting for a response */
+#define FUSEFS_POOL_NBPAGES4   /* # total fusefs size */
+#define FUSEFS_MAXID   5   /* number of valid fusefs ids */
+
+#define FUSEFS_NAMES { \
+   { 0, 0}, \
+   { fusefs_open_devices, CTLTYPE_INT }, \
+   { fusefs_fbufs_in, CTLTYPE_INT }, \
+   { fusefs_fbufs_wait, CTLTYPE_INT }, \
+   { fusefs_pool_pages, CTLTYPE_INT }, \
+}
+
+#ifdef  _KERNEL
+
 struct fuse_msg;
 
 struct fusefs_mnt {
@@ -42,21 +59,6 @@ struct fusefs_mnt {
 extern struct vops fusefs_vops;
 extern struct pool fusefs_fbuf_pool;
 
-/* sysctl defines */
-#define FUSEFS_NB_OPENDEVS 1   /* # of fuse devices opened */
-#define FUSEFS_INFBUFS 2   /* # of in fbufs */
-#define FUSEFS_WAITFBUFS   3   /* # of fbufs waiting for a response */
-#define FUSEFS_POOL_NBPAGES4   /* # total fusefs size */
-#define FUSEFS_MAXID   5   /* number of valid fusefs ids */
-
-#define FUSEFS_NAMES { \
-   { 0, 0}, \
-   { fusefs_open_devices, CTLTYPE_INT }, \
-   { fusefs_fbufs_in, CTLTYPE_INT }, \
-   { fusefs_fbufs_wait, CTLTYPE_INT }, \
-   { fusefs_pool_pages, CTLTYPE_INT }, \
-}
-
 /* fuse helpers */
 #define TSLEEP_TIMEOUT 5
 void update_vattr(struct mount *mp, struct vattr *v);
@@ -82,4 +84,5 @@ void fuse_device_set_fmp(struct fusefs_m
 /* #define FUSE_DEBUG_VNOP
 #define FUSE_DEBUG */
 
+#endif /* _KERNEL */
 #endif /* __FUSEFS_H__ */
Index: sbin/sysctl/sysctl.c
===
RCS file: /cvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.189
diff -u -p -r1.189 sysctl.c
--- sbin/sysctl/sysctl.c16 Apr 2013 22:06:48 -  1.189
+++ sbin/sysctl/sysctl.c6 Jun 2013 21:41:37 -
@@ -88,6 +88,8 @@
 #include ufs/ufs/inode.h
 #include ufs/ffs/ffs_extern.h
 
+#include miscfs/fuse/fusefs.h
+
 #include nfs/nfsproto.h
 #include nfs/nfs.h
 
@@ -1103,6 +1105,7 @@ debuginit(void)
 struct ctlname vfsgennames[] = CTL_VFSGENCTL_NAMES;
 struct ctlname ffsname[] = FFS_NAMES;
 struct ctlname nfsname[] = FS_NFS_NAMES;
+struct ctlname fusefsname[] = FUSEFS_NAMES;
 struct list *vfsvars;
 int *vfs_typenums;
 
@@ -1156,6 +1159,10 @@ vfsinit(void)
if (!strcmp(vfc.vfc_name, MOUNT_NFS)) {
vfsvars[cnt].list = nfsname;
vfsvars[cnt].size = NFS_MAXID;
+   }
+   if (!strcmp(vfc.vfc_name, MOUNT_FUSEFS)) {
+   vfsvars[cnt].list = fusefsname;
+   vfsvars[cnt].size = FUSEFS_MAXID;
}
vfs_typenums[cnt] = vfc.vfc_typenum;
strlcat(names[loc], vfc.vfc_name, sizeof names - loc);
Index: sbin/sysctl/sysctl.8
===
RCS file: /cvs/src/sbin/sysctl/sysctl.8,v
retrieving revision 1.169
diff -u -p -r1.169 sysctl.8
--- sbin/sysctl/sysctl.82 Jun 2013 21:37:03 -   1.169
+++ sbin/sysctl/sysctl.86 Jun 2013 21:41:37 -
@@ -399,6 +399,10 @@ and a few require a kernel compiled with
 .It vfs.ffs.dirhash_maxmem Ta integer Ta yes
 .It vfs.ffs.dirhash_mem Ta integer Ta no
 .It vfs.nfs.iothreads Ta integer Ta yes
+.It vfs.fuse.fusefs_open_devices Ta integer Ta no
+.It vfs.fuse.fusefs_fbufs_in Ta integer Ta no
+.It vfs.fuse.fusefs_fbufs_wait Ta integer Ta no
+.It vfs.fuse.fusefs_pool_pages Ta integer Ta no
 .El
 .Pp
 The
@@ -449,6 +453,8 @@ definitions for second level ddb identif
 definitions for second level vfs identifiers
 .It Aq Pa nfs/nfs.h
 definitions for third level NFS identifiers
+.It Aq Pa miscfs/fuse/fusefs.h
+definitions for third level fusefs identifiers
 .It Aq Pa ufs/ffs/ffs_extern.h
 definitions for third level FFS identifiers
 .It Aq Pa machine/cpu.h



Re: sysctl fix

2013-06-06 Thread Sylvestre Gallon
And here the third one that removes all warns for :

WARNINGS=yes make

Cheers,

Index: sysctl.c
===
RCS file: /cvs/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.189
diff -u -p -u -p -r1.189 sysctl.c
--- sysctl.c16 Apr 2013 22:06:48 -  1.189
+++ sysctl.c6 Jun 2013 12:07:38 -
@@ -268,7 +268,8 @@ void
 listall(char *prefix, struct list *lp)
 {
char *cp, name[BUFSIZ];
-   int lvl2, len;
+   size_t len;
+   int lvl2;
 
if (lp-list == NULL)
return;
@@ -861,7 +862,7 @@ parse(char *string, int flags)
}
if (special  RNDSTATS) {
struct rndstats *rndstats = (struct rndstats *)buf;
-   int i;
+   size_t i;
 
if (!nflag)
(void)printf(%s%s, string, equ);
@@ -1025,7 +1026,7 @@ parse_ports(char *portspec, int *port, i
 
 void
 parse_baddynamic(int mib[], size_t len, char *string, void **newvalp,
-size_t *newsizep, int flags, int nflag)
+size_t *newsizep, int flags, int nf)
 {
static u_int32_t newbaddynamic[DP_MAPSIZE];
int port, high_port, baddynamic_loaded = 0, full_list_set = 0;
@@ -1043,7 +1044,7 @@ parse_baddynamic(int mib[], size_t len, 
size, 0, 0) == -1) {
if (flags == 0)
return;
-   if (!nflag)
+   if (!nf)
printf(%s: , string);
puts(kernel does contain bad dynamic 
port tables);
@@ -1280,13 +1281,13 @@ sysctl_bios(char *string, char **bufpp, 
mib[2] = indx;
if (indx == BIOS_DISKINFO) {
if (*bufpp == NULL) {
-   char name[BUFSIZ];
+   char str[BUFSIZ];
 
/* scan all the bios devices */
for (indx = 0; indx  256; indx++) {
-   snprintf(name, sizeof(name), %s.%u,
+   snprintf(str, sizeof(str), %s.%u,
string, indx);
-   parse(name, 1);
+   parse(str, 1);
}
return (-1);
}
@@ -1782,10 +1783,10 @@ sysctl_forkstat(char *string, char **buf
 int
 sysctl_malloc(char *string, char **bufpp, int mib[], int flags, int *typep)
 {
-   int indx, stor, i;
+   int indx, stor;
char *name, bufp[SYSCTL_BUFSIZ], *buf, *ptr;
struct list lp;
-   size_t size;
+   size_t size, i;
 
if (*bufpp == NULL) {
listall(string, kernmalloclist);
@@ -2282,7 +2283,7 @@ sysctl_tc(char *string, char **bufpp, in
 int
 sysctl_sensors(char *string, char **bufpp, int mib[], int flags, int *typep)
 {
-   char *devname, *typename;
+   char *name, *typename;
int dev, numt, i;
enum sensor_type type;
struct sensordev snsrdev;
@@ -2312,7 +2313,7 @@ sysctl_sensors(char *string, char **bufp
 * provided below hw.sensors tree.
 * The first branch of hw.sensors tree is the device name.
 */
-   if ((devname = strsep(bufpp, .)) == NULL) {
+   if ((name = strsep(bufpp, .)) == NULL) {
warnx(%s: incomplete specification, string);
return (-1);
}
@@ -2325,11 +2326,11 @@ sysctl_sensors(char *string, char **bufp
if (errno == ENOENT)
break;
}
-   if (strcmp(devname, snsrdev.xname) == 0)
+   if (strcmp(name, snsrdev.xname) == 0)
break;
}
-   if (strcmp(devname, snsrdev.xname) != 0) {
-   warnx(%s: sensor device not found: %s, string, devname);
+   if (strcmp(name, snsrdev.xname) != 0) {
+   warnx(%s: sensor device not found: %s, string, name);
return (-1);
}
if (*bufpp == NULL) {
@@ -2586,6 +2587,7 @@ struct emulname {
 } *emul_names;
 intemul_num, nemuls;
 intemul_init(void);
+intemulcmp(const void *, const void *);
 
 int
 sysctl_emul(char *string, char *newval, int flags)



Re: sysctl fix

2013-06-06 Thread Ted Unangst
On Thu, Jun 06, 2013 at 23:53, Sylvestre Gallon wrote:
 Hi,
 
 Sorry for the last mistakes. Here is a new diff that allow the
 maxtypenum to be reached.
 
 Cheers,
 
 Index: sysctl.c
 ===
 RCS file: /cvs/src/sbin/sysctl/sysctl.c,v
 retrieving revision 1.189
 diff -u -p -r1.189 sysctl.c
 --- sysctl.c  16 Apr 2013 22:06:48 -  1.189
 +++ sysctl.c  6 Jun 2013 21:19:32 -
 @@ -1138,8 +1138,8 @@ vfsinit(void)
 }
 mib[2] = VFS_CONF;
 buflen = sizeof vfc;
 - for (loc = lastused, cnt = 1; cnt  maxtypenum; cnt++) {
 - mib[3] = cnt - 1;
 + for (loc = lastused, cnt = 0; cnt  maxtypenum; cnt++) {
 + mib[3] = cnt;

I think we want to keep starting at 1. 0 isn't a valid vfc_typenum.
(doesn't really matter, but better correct than not.)

I can fix this before commit, you don't need to send a new diff.