Skip to content

Commit

Permalink
fix for cstyle. (openzfs#13)
Browse files Browse the repository at this point in the history
This is a large commit, but it should have no functional changes, just cstyle corrections.

* fix for cstyle.

Had to guess some things. Move ident in made some places nicer.

* Correct typos in cstyle

Thanks for the mindless work

Co-authored-by: Kajerik Lundman <kajerik@lundman.net>
  • Loading branch information
2 people authored and andrewc12 committed Aug 27, 2022
1 parent 62635da commit 7252469
Show file tree
Hide file tree
Showing 296 changed files with 34,255 additions and 32,340 deletions.
105 changes: 63 additions & 42 deletions cmd/os/windows/kstat/kstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
//#include <sys/kstat.h>
//#include <langinfo.h>
#include <libgen.h>
#include <limits.h>
#include <locale.h>
Expand Down Expand Up @@ -118,7 +116,7 @@ main(int argc, char **argv)
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
#endif
//(void) textdomain(TEXT_DOMAIN);
// (void) textdomain(TEXT_DOMAIN);

/*
* Create the selector list and a dummy default selector to match
Expand Down Expand Up @@ -222,7 +220,8 @@ main(int argc, char **argv)
argv += optind;

if (g_wflg) {
/* kstat_write mode: consume commandline arguments:
/*
* kstat_write mode: consume commandline arguments:
* kstat -w module:instance:name:statistic_name=value
*/
n = write_mode(argc, argv);
Expand Down Expand Up @@ -383,15 +382,15 @@ main(int argc, char **argv)
static void
usage(void)
{
(void)fprintf(stderr, gettext(
"Usage:\n"
"kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
" [ -m module ] [ -i instance ] [ -n name ] [ -s statistic ]\n"
" [ interval [ count ] ]\n"
"kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
" [ module[:instance[:name[:statistic]]] ... ]\n"
" [ interval [ count ] ]\n"
"kstat -w module:instance:name:statistic=value [ ... ] \n"));
(void) fprintf(stderr, gettext(
"Usage:\n"
"kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
" [ -m module ] [ -i instance ] [ -n name ] [ -s statistic ]\n"
" [ interval [ count ] ]\n"
"kstat [ -Cjlpq ] [ -T d|u ] [ -c class ]\n"
" [ module[:instance[:name[:statistic]]] ... ]\n"
" [ interval [ count ] ]\n"
"kstat -w module:instance:name:statistic=value [ ... ] \n"));
}

/*
Expand Down Expand Up @@ -427,7 +426,7 @@ ks_safe_strdup(char *str)

while ((ret = _strdup(str)) == NULL) {
if (errno == EAGAIN) {
(void)usleep(200);
(void) usleep(200);
} else {
perror("strdup");
exit(3);
Expand Down Expand Up @@ -1045,7 +1044,8 @@ ks_instances_print(void)
* e.g. "kstat -w zfs:0:tunable:zfs_arc_mac=1234567890
*
*/
int write_mode(int argc, char **argv)
int
write_mode(int argc, char **argv)
{
char *arg;
int instance, rc = 0;
Expand All @@ -1055,52 +1055,64 @@ int write_mode(int argc, char **argv)

if (argc == 0) {
usage();
(void)fprintf(stderr, "-w takes at least one argument\n");
(void)fprintf(stderr, "\te.g. kstat -w zfs:0:tunable:zfs_arc_max=1200000\n");
return -1;
(void) fprintf(stderr, "-w takes at least one argument\n");
(void) fprintf(stderr,
"\te.g. kstat -w zfs:0:tunable:zfs_arc_max=1200000\n");
return (-1);
}

while ((kc = kstat_open()) == NULL) {
if (errno == EAGAIN) {
(void)usleep(200);
(void) usleep(200);
} else {
perror("kstat_open");
exit(3);
}
}

while (argc--) {
char mod[KSTAT_STRLEN + 1], name[KSTAT_STRLEN + 1], stat[KSTAT_STRLEN + 1];
char mod[KSTAT_STRLEN + 1], name[KSTAT_STRLEN + 1],
stat[KSTAT_STRLEN + 1];

arg = *argv;

// TODO: make this more flexible. Spaces, and other types than uint64.
// TODO: make this more flexible. Spaces, and other types than
// uint64.
// Call C11 sscanf_s which takes string-width following ptr.
if ((rc = sscanf_s(arg, "%[^:]:%d:%[^:]:%[^=]=%llu",
mod, KSTAT_STRLEN,
&instance,
name, KSTAT_STRLEN,
stat, KSTAT_STRLEN,
&value)) != 5) {
(void)fprintf(stderr, "Unable to parse '%s'\n input not in 'module:instance:name:statisticname=value' format. %d\n", arg, rc);
if ((rc = sscanf_s(arg,
"%[^:]:%d:%[^:]:%[^=]=%llu",
mod, KSTAT_STRLEN,
&instance,
name, KSTAT_STRLEN,
stat, KSTAT_STRLEN,
&value)) != 5) {
(void) fprintf(stderr, "Unable to parse '%s'\n input "
"not in 'module:instance:name:statisticname=value' "
"format. %d\n", arg, rc);
failure++;
} else {
kstat_t *ks;
ks = kstat_lookup(kc, mod, instance, name);
if (ks == NULL) {
(void)fprintf(stderr, "Unable to lookup '%s:%d:%s': %d\n",
mod, instance, name, errno);
(void) fprintf(stderr,
"Unable to lookup '%s:%d:%s': %d\n",
mod, instance, name, errno);
failure++;
} else {
if (kstat_read(kc, ks, NULL) == -1) {
(void)fprintf(stderr, "Unable to read '%s:%d:%s': %d\n",
mod, instance, name, errno);
(void) fprintf(stderr,
"Unable to read '%s:%d:%s': %d\n",
mod, instance, name, errno);
failure++;
} else {
kstat_named_t *kn = kstat_data_lookup(ks, stat);
kstat_named_t *kn =
kstat_data_lookup(ks, stat);
if (kn == NULL) {
(void)fprintf(stderr, "Unable to find '%s' in '%s:%d:%s': %d\n",
stat, mod, instance, name, errno);
(void) fprintf(stderr,
"Unable to find '%s' in "
"'%s:%d:%s': %d\n",
stat, mod, instance,
name, errno);
failure++;
} else {
before_value = kn->value.ui64;
Expand All @@ -1110,12 +1122,22 @@ int write_mode(int argc, char **argv)
rc = kstat_write(kc, ks, NULL);

if (rc == -1) {
(void)fprintf(stderr, "Unable to write '%s:%d:%s:%s': %d\n",
mod, instance, name, stat, errno);
(void) fprintf(stderr,
"Unable to write "
"'%s:%d:%s:%s': "
"%d\n",
mod, instance,
name,
stat, errno);
failure++;
} else {
(void)fprintf(stderr, "%s:%d:%s:%s: %llu -> %llu\n",
mod, instance, name, stat, before_value, value);
(void) fprintf(stderr,
"%s:%d:%s:%s: %llu "
"-> %llu\n",
mod, instance,
name, stat,
before_value,
value);
} // rc
} // kstat_data_lookup
} // kstat_read
Expand All @@ -1125,11 +1147,10 @@ int write_mode(int argc, char **argv)
}

kstat_close(kc);
return failure;
return (failure);
}



#ifndef WIN32
static void
save_cpu_stat(kstat_t *kp, ks_instance_t *ksi)
Expand Down Expand Up @@ -1607,7 +1628,7 @@ save_fault_list(kstat_t *kp, ks_instance_t *ksi)
}
}
#endif
#endif
#endif

static void
save_named(kstat_t *kp, ks_instance_t *ksi)
Expand Down
10 changes: 2 additions & 8 deletions cmd/os/windows/kstat/kstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,8 @@
/*
* Structures needed by the kstat reader functions.
*/
//#include <sys/var.h>
#include <sys/utsname.h>
//#include <sys/sysinfo.h>
//#include <sys/flock.h>
//#include <sys/dnlc.h>
#include <regex.h>
//#include <nfs/nfs.h>
//#include <nfs/nfs_clnt.h>

#ifdef __sparc
#include <vm/hat_sfmmu.h>
Expand Down Expand Up @@ -107,7 +101,7 @@ typedef union ks_value {
{ \
ks_value_t v; \
v.str.addr.ptr = _strdup(S->N); \
v.str.len = (uint32_t) strlen(S->N); \
v.str.len = (uint32_t)strlen(S->N); \
nvpair_insert(I, #N, &v, KSTAT_DATA_STRING); \
}

Expand Down Expand Up @@ -143,7 +137,7 @@ typedef union ks_value {
{ \
ks_value_t v; \
v.str.addr.ptr = _strdup(V); \
v.str.len = (uint32_t)( (V) ? strlen(V) : 0 ); \
v.str.len = (uint32_t)((V) ? strlen(V) : 0); \
nvpair_insert(I, N, &v, KSTAT_DATA_STRING); \
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/os/windows/zfsinstaller/zfsinstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2018 Julian Heuking <J.Heuking@beckhoff.com>
*/
/*
* Copyright (c) 2018 Julian Heuking <J.Heuking@beckhoff.com>
*/

#pragma once


#include <windows.h>
#include <SetupAPI.h>
#include <stdio.h>
Expand All @@ -33,7 +32,7 @@
DWORD zfs_install(char *);
DWORD zfs_uninstall(char *);
DWORD executeInfSection(const char *, char *);
DWORD startService(char*);
DWORD startService(char *);
void printUsage();
DWORD send_zfs_ioc_unregister_fs();
DWORD installRootDevice(char *inf_path);
Expand Down
14 changes: 9 additions & 5 deletions cmd/zpool/zpool_vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,9 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
*/
if (is_mpath_whole_disk(path)) {
update_vdev_config_dev_strs(nv);
/* update might change path, so fetch it again */
verify(!nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path));
/* update might change path, so fetch again */
verify(!nvlist_lookup_string(nv,
ZPOOL_CONFIG_PATH, &path));
}
if (!is_spare(NULL, path))
(void) zero_label(path);
Expand Down Expand Up @@ -1033,7 +1034,7 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
#ifdef _WIN32
char *backslash = strrchr(devpath, '\\');
if (devnode == NULL || backslash > devnode)
devnode = backslash;
devnode = backslash;
#endif
devnode = &devnode[1];

Expand Down Expand Up @@ -1068,8 +1069,11 @@ make_disks(zpool_handle_t *zhp, nvlist_t *nv)
if (ret)
return (ret);
#ifdef _WIN32
// Append_partition will only work once label_disk has been called
// (To find offset+length). Call it again to get correct path.
/*
* Append_partition will only work once label_disk has
* been called (To find offset+length).
* Call it again to get correct path.
*/
(void) zfs_append_partition(udevpath, MAXPATHLEN);
#endif
}
Expand Down
53 changes: 29 additions & 24 deletions include/os/windows/Trace.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

#if !defined WPPFILE || !defined RUN_WPP // To enable Wpp; Select Yes under Run Wpp Tracing in Project properties
#undef WPPFILE // And define both RUN_WPP and WPPFILE="%(FileName).tmh" in C/C++ preprocessor
#undef RUN_WPP // To disable Wpp; Select No under Run Wpp Tracing; undef RUN_WPP/WPPFILE in C/C++ preprocessor
#if !defined WPPFILE || !defined RUN_WPP
// To enable Wpp; Select Yes under Run Wpp Tracing in Project properties
#undef WPPFILE
// And define both RUN_WPP and WPPFILE="%(FileName).tmh" in C/C++ preprocessor
#undef RUN_WPP
// To disable Wpp; Select No under Run Wpp Tracing;
// undef RUN_WPP/WPPFILE in C/C++ preprocessor
#endif

static const int TRACE_FATAL = 1;
Expand All @@ -13,31 +17,32 @@ static const int TRACE_VERBOSE = 5;
static const int TRACE_NOISY = 8;

#if defined RUN_WPP && defined WPPFILE
#define WPPNAME ZFSinTraceGuid
#define WPPGUID c20c603c,afd4,467d,bf76,c0a4c10553df
#define WPPNAME ZFSinTraceGuid
#define WPPGUID c20c603c, afd4, 467d, bf76, c0a4c10553df

#define WPP_DEFINE_DEFAULT_BITS \
WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) \
WPP_DEFINE_BIT(TRACE_KDPRINT) \
WPP_DEFINE_BIT(DEFAULT_TRACE_LEVEL)
#define WPP_DEFINE_DEFAULT_BITS \
WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) \
WPP_DEFINE_BIT(TRACE_KDPRINT) \
WPP_DEFINE_BIT(DEFAULT_TRACE_LEVEL)

#undef WPP_DEFINE_CONTROL_GUID
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(WPPNAME,(WPPGUID), \
WPP_DEFINE_DEFAULT_BITS )
#undef WPP_DEFINE_CONTROL_GUID
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(WPPNAME, (WPPGUID), \
WPP_DEFINE_DEFAULT_BITS)

#define WPP_FLAGS_LEVEL_LOGGER(Flags, level) \
#define WPP_FLAGS_LEVEL_LOGGER(Flags, level) \
WPP_LEVEL_LOGGER(Flags)

#define WPP_FLAGS_LEVEL_ENABLED(Flags, level) \
(WPP_LEVEL_ENABLED(Flags) && \
#define WPP_FLAGS_LEVEL_ENABLED(Flags, level) \
(WPP_LEVEL_ENABLED(Flags) && \
WPP_CONTROL(WPP_BIT_ ## Flags).Level >= level)

#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \
WPP_LEVEL_LOGGER(flags)
#define WPP_LEVEL_FLAGS_LOGGER(lvl, flags) \
WPP_LEVEL_LOGGER(flags)

#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \
(WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl)
#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \
(WPP_LEVEL_ENABLED(flags) && \
WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl)


// begin_wpp config
Expand All @@ -50,17 +55,17 @@ static const int TRACE_NOISY = 8;
#else

#undef WPP_INIT_TRACING
#define WPP_INIT_TRACING(...) ((void)(0, __VA_ARGS__))
#define WPP_INIT_TRACING(...) ((void)(0, __VA_ARGS__))

#undef WPP_CLEANUP
#define WPP_CLEANUP(...) ((void)(0, __VA_ARGS__))
#define WPP_CLEANUP(...) ((void)(0, __VA_ARGS__))
#endif

#ifndef WPP_CHECK_INIT
#define WPP_CHECK_INIT
#define WPP_CHECK_INIT
#endif


void ZFSWppInit(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath);

void ZFSWppCleanup(PDRIVER_OBJECT pDriverObject);
void ZFSWppCleanup(PDRIVER_OBJECT pDriverObject);
Loading

0 comments on commit 7252469

Please sign in to comment.