Klara update for json

Fix checkstyle indicated errors, source format fixes

Signed-off-by: Fred Weigel <fred.weigel@klarasystems.com>
This commit is contained in:
Fred Weigel 2023-06-12 09:31:41 +00:00 committed by Geoff Amey
parent 2284c4d200
commit 6ccb1a75af
4 changed files with 78 additions and 80 deletions

View File

@ -17,7 +17,7 @@
/* #include <inttypes.h> */ /* #include <inttypes.h> */
/* maximum stack nesting */ /* maximum stack nesting */
#define JP_MAX_STACK 32 #define JP_MAX_STACK 32
enum jp_type { enum jp_type {
JP_OBJECT = 1, JP_OBJECT = 1,
@ -30,26 +30,26 @@ struct jp_stack {
}; };
typedef struct jprint { typedef struct jprint {
char *buffer; /* pointer to application's buffer */ char *buffer; /* pointer to application's buffer */
size_t buflen; /* length of buffer */ size_t buflen; /* length of buffer */
char *bufp; /* current write position in buffer */ char *bufp; /* current write position in buffer */
char tmpbuf[32]; /* local buffer for conversions */ char tmpbuf[32]; /* local buffer for conversions */
int error; /* error code */ int error; /* error code */
int ncall; /* API call number on which error occurred */ int ncall; /* API call number on which error occurred */
struct jp_stack /* stack of array/object nodes */ struct jp_stack /* stack of array/object nodes */
stack[JP_MAX_STACK]; stack[JP_MAX_STACK];
int stackp; int stackp;
} jprint_t; } jprint_t;
/* error return codes */ /* error return codes */
#define JPRINT_OK 0 /* no error */ #define JPRINT_OK 0 /* no error */
#define JPRINT_BUF_FULL 1 /* output buffer full */ #define JPRINT_BUF_FULL 1 /* output buffer full */
#define JPRINT_NEST_ERROR 2 /* nesting error */ #define JPRINT_NEST_ERROR 2 /* nesting error */
#define JPRINT_STACK_FULL 3 /* array/object nesting */ #define JPRINT_STACK_FULL 3 /* array/object nesting */
#define JPRINT_STACK_EMPTY 4 /* stack underflow error */ #define JPRINT_STACK_EMPTY 4 /* stack underflow error */
#define JPRINT_OPEN 5 /* not all objects closed */ #define JPRINT_OPEN 5 /* not all objects closed */
#define JPRINT_FMT 6 /* format error */ #define JPRINT_FMT 6 /* format error */
#define JPRINT_NO_DOUBLE 7 /* %g support not included */ #define JPRINT_NO_DOUBLE 7 /* %g support not included */
const char *jp_errorstring(int err); const char *jp_errorstring(int err);
int jp_error(jprint_t *jp); int jp_error(jprint_t *jp);
@ -57,4 +57,3 @@ void jp_open(jprint_t *jp, char *buffer, size_t buflen);
int jp_close(jprint_t *jp); int jp_close(jprint_t *jp);
int jp_errorpos(jprint_t *jp); int jp_errorpos(jprint_t *jp);
int jp_printf(jprint_t *jp, const char *fmt, ...); int jp_printf(jprint_t *jp, const char *fmt, ...);

View File

@ -4,4 +4,3 @@
void json_stats_destroy(spa_t *spa); void json_stats_destroy(spa_t *spa);
void json_stats_init(spa_t *spa); void json_stats_init(spa_t *spa);

View File

@ -10,19 +10,19 @@
/* #include "jprint.h" */ /* #include "jprint.h" */
/* Do not support %g format. Just %d and %l for integers (if set) */ /* Do not support %g format. Just %d and %l for integers (if set) */
#define NO_DOUBLE 1 #define NO_DOUBLE 1
/* Use %g instead of %e for double format */ /* Use %g instead of %e for double format */
#define USE_G 1 #define USE_G 1
/* Formats for int64_t and uint64_t */ /* Formats for int64_t and uint64_t */
#ifndef PRId64 #ifndef PRId64
#define PRId64 "lld" /* %D, int64_t */ #define PRId64 "lld" /* %D, int64_t */
#define PRIu64 "llu" /* %U, uint64_t*/ #define PRIu64 "llu" /* %U, uint64_t */
#endif #endif
/* literal key length maximum */ /* literal key length maximum */
#define KEYLEN 255 #define KEYLEN 5
/* return error position (call number of jp_printf) */ /* return error position (call number of jp_printf) */
int int
@ -36,17 +36,17 @@ const char *
jp_errorstring(int err) jp_errorstring(int err)
{ {
switch (err) { switch (err) {
case JPRINT_OK: return "jprint ok"; case JPRINT_OK: return "jprint ok";
case JPRINT_BUF_FULL: return "jprint buffer full"; case JPRINT_BUF_FULL: return "jprint buffer full";
case JPRINT_NEST_ERROR: return "jprint nest error"; case JPRINT_NEST_ERROR: return "jprint nest error";
case JPRINT_STACK_FULL: return "jprint stack full"; case JPRINT_STACK_FULL: return "jprint stack full";
case JPRINT_STACK_EMPTY: return "jprint stack empty"; case JPRINT_STACK_EMPTY: return "jprint stack empty";
case JPRINT_OPEN: return "jprint open"; case JPRINT_OPEN: return "jprint open";
case JPRINT_FMT: return "jprint format"; case JPRINT_FMT: return "jprint format";
case JPRINT_NO_DOUBLE: return "jprint no double support"; case JPRINT_NO_DOUBLE: return "jprint no double support";
default: return "jprint unknown error"; default: return "jprint unknown error";
} }
return "jprint unknown error"; return ("jprint unknown error");
} }
/* return error from jprint_t */ /* return error from jprint_t */
@ -74,7 +74,7 @@ int
jp_close(jprint_t *jp) jp_close(jprint_t *jp)
{ {
if (jp->error != JPRINT_OK) if (jp->error != JPRINT_OK)
return (jp->error); return (jp->error);
if (jp->stackp != -1) if (jp->stackp != -1)
jp->error = JPRINT_OPEN; jp->error = JPRINT_OPEN;
return (jp->error); return (jp->error);
@ -118,51 +118,51 @@ jp_putsq(jprint_t *jp, char *s)
} }
jp_putc(jp, '\"'); jp_putc(jp, '\"');
while (*s && (jp->error == JPRINT_OK)) { while (*s && (jp->error == JPRINT_OK)) {
c = (int)*s++; c = (int)*s++;
/* formfeed, newline, return, tab, backspace */ /* formfeed, newline, return, tab, backspace */
if (c == 12) if (c == 12)
jp_puts(jp, (char *)"\\f"); jp_puts(jp, (char *)"\\f");
else if (c == 10) else if (c == 10)
jp_puts(jp, (char *)"\\n"); jp_puts(jp, (char *)"\\n");
else if (c == 13) else if (c == 13)
jp_puts(jp, (char *)"\\r"); jp_puts(jp, (char *)"\\r");
else if (c == 9) else if (c == 9)
jp_puts(jp, (char *)"\\t"); jp_puts(jp, (char *)"\\t");
else if (c == 8) else if (c == 8)
jp_puts(jp, (char *)"\\b"); jp_puts(jp, (char *)"\\b");
/* /*
* all characters from 0x00 to 0x1f, and 0x7f are * all characters from 0x00 to 0x1f, and 0x7f are
* escaped as: \u00xx * escaped as: \u00xx
*/ */
else if (((0 <= c) && (c <= 0x1f)) || (c == 0x7f)) { else if (((0 <= c) && (c <= 0x1f)) || (c == 0x7f)) {
jp_puts(jp, (char *)"\\u00"); jp_puts(jp, (char *)"\\u00");
jp_putc(jp, hex[(c >> 4) & 0x0f]); jp_putc(jp, hex[(c >> 4) & 0x0f]);
jp_putc(jp, hex[c & 0x0f]); jp_putc(jp, hex[c & 0x0f]);
/* * " \ / */ /* * " \ / */
} else if (c == '"') } else if (c == '"')
jp_puts(jp, (char *)"\\\""); jp_puts(jp, (char *)"\\\"");
else if (c == '\\') else if (c == '\\')
jp_puts(jp, (char *)"\\\\"); jp_puts(jp, (char *)"\\\\");
else if (c == '/') else if (c == '/')
jp_puts(jp, (char *)"\\/"); jp_puts(jp, (char *)"\\/");
/* /*
* all other printable characters ' ' to '~', and * all other printable characters ' ' to '~', and
* any utf-8 sequences (high bit set): * any utf-8 sequences (high bit set):
* 1xxxxxxx 10xxxxxx ... * 1xxxxxxx 10xxxxxx ...
* is a utf-8 sequence (10xxxxxx may occur 1 to 3 times). * is a utf-8 sequence (10xxxxxx may occur 1 to 3 times).
* Note that this is simply distinguished here as high * Note that this is simply distinguished here as high
* bit set. * bit set.
*/ */
else else
jp_putc(jp, (char)c); jp_putc(jp, (char)c);
} }
jp_putc(jp, '\"'); jp_putc(jp, '\"');
} }
/* put out key if object open. error if nothing open */ /* put out key if object open. error if nothing open */
static int static int
jp_key(jprint_t *jp, char *key) jp_key(jprint_t *jp, char *key)
{ {
if (jp->error != JPRINT_OK) if (jp->error != JPRINT_OK)
goto err; goto err;
@ -323,7 +323,7 @@ jp_printf(jprint_t *jp, const char *fmt, ...)
*/ */
i = snprintf( i = snprintf(
jp->tmpbuf, sizeof (jp->tmpbuf), jp->tmpbuf, sizeof (jp->tmpbuf),
"%g", x); "%g", x);
#else #else
/* /*
* double has 15 places: * double has 15 places:
@ -331,7 +331,7 @@ jp_printf(jprint_t *jp, const char *fmt, ...)
*/ */
i = snprintf( i = snprintf(
jp->tmpbuf, sizeof (jp->tmpbuf), jp->tmpbuf, sizeof (jp->tmpbuf),
"%21.14e", x); "%21.14e", x);
#endif #endif
if ((i >= sizeof (jp->tmpbuf)) || if ((i >= sizeof (jp->tmpbuf)) ||
(i < 0)) (i < 0))
@ -349,8 +349,9 @@ jp_printf(jprint_t *jp, const char *fmt, ...)
} }
if (jp_key(jp, key) == JPRINT_OK) { if (jp_key(jp, key) == JPRINT_OK) {
b = (boolean_t)va_arg(ap, int); b = (boolean_t)va_arg(ap, int);
s = b ? (char *)"true" : s = b ?
(char *)"false"; (char *)"true" :
(char *)"false";
jp_puts(jp, s); jp_puts(jp, s);
} }
key[k = 0] = '\0'; key[k = 0] = '\0';
@ -440,7 +441,6 @@ jp_printf(jprint_t *jp, const char *fmt, ...)
va_end(ap); va_end(ap);
if (jp->error != JPRINT_OK) if (jp->error != JPRINT_OK)
return (-1); return (-1);
return (int)(jp->bufp - start); return (int)(jp->bufp - start);
} }

View File

@ -1598,7 +1598,9 @@ zfs_ioc_pool_configs(zfs_cmd_t *zc)
int error; int error;
if (fmgw_debug != 0) if (fmgw_debug != 0)
zfs_dbgmsg("fmgw -- calling spa_all_configs, which takes spa_namespace_lock"); zfs_dbgmsg(
"fmgw -- calling spa_all_configs,"
"which takes spa_namespace_lock");
if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL) if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
return (SET_ERROR(EEXIST)); return (SET_ERROR(EEXIST));
@ -7475,8 +7477,6 @@ zfsdev_ioctl_common(uint_t vecnum, zfs_cmd_t *zc, int flag)
if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL) if (vec->zvec_func == NULL && vec->zvec_legacy_func == NULL)
return (SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL)); return (SET_ERROR(ZFS_ERR_IOC_CMD_UNAVAIL));
// if (fmgw_debug != 0)
// zfs_dbgmsg("enter ioctl, %d %x %s", vecnum, vecnum, fmgw_zioctl(vecnum + ZFS_IOC_FIRST));
zc->zc_iflags = flag & FKIOCTL; zc->zc_iflags = flag & FKIOCTL;
max_nvlist_src_size = zfs_max_nvlist_src_size_os(); max_nvlist_src_size = zfs_max_nvlist_src_size_os();
if (zc->zc_nvlist_src_size > max_nvlist_src_size) { if (zc->zc_nvlist_src_size > max_nvlist_src_size) {