Flesh out sysctl types further (follow-up of r290475)

Use the right intmax_t type instead of intptr_t in a few remaining
places.

Add support for CTLFLAG_TUN for the new fixed with types.  Bruce will be
upset that the new handlers silently truncate tuned quad-sized inputs,
but so do all of the existing handlers.

Add the new types to debug_dump_node, for whatever use that is.

Bump FreeBSD_version again, for good measure.  We are changing
SYSCTL_HANDLER_ARGS and a member of struct sysctl_oid to intmax_t.

Correct the sysctl typed NULL values for the fixed-width types.  (Hat
tip: hps@.)

Suggested by:	hps (partial)
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Conrad Meyer 2015-11-07 18:26:32 +00:00
parent c261189f26
commit e072f955ff
3 changed files with 64 additions and 13 deletions

View File

@ -147,7 +147,7 @@ sysctl_wunlock(void)
}
static int
sysctl_root_handler_locked(struct sysctl_oid *oid, void *arg1, intptr_t arg2,
sysctl_root_handler_locked(struct sysctl_oid *oid, void *arg1, intmax_t arg2,
struct sysctl_req *req, struct rm_priotracker *tracker)
{
int error;
@ -189,6 +189,9 @@ sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
char path[64];
ssize_t rem = sizeof(path);
ssize_t len;
uint8_t val_8;
uint16_t val_16;
uint32_t val_32;
int val_int;
long val_long;
int64_t val_64;
@ -243,6 +246,27 @@ sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
req.newlen = sizeof(val_long);
req.newptr = &val_long;
break;
case CTLTYPE_S8:
if (getenv_int(path + rem, &val_int) == 0)
return;
val_8 = val_int;
req.newlen = sizeof(val_8);
req.newptr = &val_8;
break;
case CTLTYPE_S16:
if (getenv_int(path + rem, &val_int) == 0)
return;
val_16 = val_int;
req.newlen = sizeof(val_16);
req.newptr = &val_16;
break;
case CTLTYPE_S32:
if (getenv_long(path + rem, &val_long) == 0)
return;
val_32 = val_long;
req.newlen = sizeof(val_32);
req.newptr = &val_32;
break;
case CTLTYPE_S64:
if (getenv_quad(path + rem, &val_quad) == 0)
return;
@ -250,6 +274,27 @@ sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
req.newlen = sizeof(val_64);
req.newptr = &val_64;
break;
case CTLTYPE_U8:
if (getenv_uint(path + rem, (unsigned int *)&val_int) == 0)
return;
val_8 = val_int;
req.newlen = sizeof(val_8);
req.newptr = &val_8;
break;
case CTLTYPE_U16:
if (getenv_uint(path + rem, (unsigned int *)&val_int) == 0)
return;
val_16 = val_int;
req.newlen = sizeof(val_16);
req.newptr = &val_16;
break;
case CTLTYPE_U32:
if (getenv_ulong(path + rem, (unsigned long *)&val_long) == 0)
return;
val_32 = val_long;
req.newlen = sizeof(val_32);
req.newptr = &val_32;
break;
case CTLTYPE_U64:
/* XXX there is no getenv_uquad() */
if (getenv_quad(path + rem, &val_quad) == 0)
@ -806,8 +851,14 @@ sysctl_sysctl_debug_dump_node(struct sysctl_oid_list *l, int i)
case CTLTYPE_LONG: printf(" Long\n"); break;
case CTLTYPE_ULONG: printf(" u_long\n"); break;
case CTLTYPE_STRING: printf(" String\n"); break;
case CTLTYPE_U64: printf(" uint64_t\n"); break;
case CTLTYPE_S8: printf(" int8_t\n"); break;
case CTLTYPE_S16: printf(" int16_t\n"); break;
case CTLTYPE_S32: printf(" int32_t\n"); break;
case CTLTYPE_S64: printf(" int64_t\n"); break;
case CTLTYPE_U8: printf(" uint8_t\n"); break;
case CTLTYPE_U16: printf(" uint16_t\n"); break;
case CTLTYPE_U32: printf(" uint32_t\n"); break;
case CTLTYPE_U64: printf(" uint64_t\n"); break;
case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
default: printf("\n");
}

View File

@ -58,7 +58,7 @@
* in the range 5 to 9.
*/
#undef __FreeBSD_version
#define __FreeBSD_version 1100088 /* Master, propagated to newvers */
#define __FreeBSD_version 1100089 /* Master, propagated to newvers */
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,

View File

@ -137,7 +137,7 @@ struct ctlname {
#endif
#define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, \
intptr_t arg2, struct sysctl_req *req
intmax_t arg2, struct sysctl_req *req
/* definitions for sysctl_req 'lock' member */
#define REQ_UNWIRED 1
@ -181,7 +181,7 @@ struct sysctl_oid {
int oid_number;
u_int oid_kind;
void *oid_arg1;
intptr_t oid_arg2;
intmax_t oid_arg2;
const char *oid_name;
int (*oid_handler)(SYSCTL_HANDLER_ARGS);
const char *oid_fmt;
@ -329,7 +329,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for a signed 8-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S8_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
#define SYSCTL_S8(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \
@ -349,7 +349,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for an unsigned 8-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U8_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
#define SYSCTL_U8(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \
@ -369,7 +369,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for a signed 16-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S16_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
#define SYSCTL_S16(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \
@ -389,7 +389,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for an unsigned 16-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U16_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
#define SYSCTL_U16(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \
@ -409,7 +409,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for a signed 32-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S32_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
#define SYSCTL_S32(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \
@ -429,7 +429,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for an unsigned 32-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U32_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
#define SYSCTL_U32(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \
@ -449,7 +449,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for a signed 64-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_S64_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
#define SYSCTL_S64(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \
@ -469,7 +469,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
})
/* Oid for an unsigned 64-bit int. If ptr is NULL, val is returned. */
#define SYSCTL_NULL_U64_PTR ((unsigned *)NULL)
#define SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
#define SYSCTL_U64(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \