From 70e9d4ecc9130aeed1260d78cd8b33a5cde6edd7 Mon Sep 17 00:00:00 2001 From: Steve Guminski Date: Tue, 8 Nov 2016 16:38:15 -0500 Subject: [PATCH 1/1] LU-6210 utils: Change positional struct initializers to C99 This patch makes no functional changes. Struct initializers in the utils directory that use C89 or GCC-only syntax are updated to C99 syntax. Whitespace is corrected to match the coding style guidelines. Variables of type struct option have been renamed to long_opts for consistency. The C99 syntax prevents incorrect initialization if values are accidently placed in the wrong position, allows changes in the struct definition, and clears any members that are not given an explicit value. The following struct initializers have been updated: utils/gss/gssd.c: struct sembuf op (2 occurrences) utils/gss/lgss_sk.c: static struct option long_opt[] utils/gss/lsupport.c: static struct convert_struct converter[] static struct user_mapping mapping utils/gss/svcgssd_mech2file.c: static const struct oid2mech o2m[] Test-Parameters: trivial Signed-off-by: Steve Guminski Change-Id: I9bee8bbea817afc369a34252513ad3bdee947851 Reviewed-on: https://review.whamcloud.com/23537 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Nathaniel Clark Reviewed-by: Sebastien Buisson Reviewed-by: Oleg Drokin --- lustre/utils/gss/gssd.c | 17 ++++++++----- lustre/utils/gss/lgss_sk.c | 43 ++++++++++++++++----------------- lustre/utils/gss/lsupport.c | 12 ++++----- lustre/utils/gss/svcgssd_mech2file.c | 47 +++++++++++++++++++++++++++++++----- 4 files changed, 79 insertions(+), 40 deletions(-) diff --git a/lustre/utils/gss/gssd.c b/lustre/utils/gss/gssd.c index 004db2c..2f96b5c 100644 --- a/lustre/utils/gss/gssd.c +++ b/lustre/utils/gss/gssd.c @@ -109,10 +109,13 @@ void lgssd_fini_mutexs(void) void lgssd_mutex_get(int semid) { - struct sembuf op[1] = { {0, -1, SEM_UNDO} }; - int rc; + struct sembuf op = { + .sem_op = -1, + .sem_flag = SEM_UNDO + }; + int rc; - rc = semop(semid, op, 1); + rc = semop(semid, &op, 1); if (rc != 0) { printerr(0, "exit on mutex_get err %d: %s\n", rc, strerror(errno)); @@ -122,10 +125,12 @@ void lgssd_mutex_get(int semid) void lgssd_mutex_put(int semid) { - struct sembuf op[1] = { {0, 1, 0} }; - int rc; + struct sembuf op = { + .sem_op = 1 + }; + int rc; - rc = semop(semid, op, 1); + rc = semop(semid, &op, 1); if (rc != 0) { printerr(0, "ignore mutex_put err %d: %s\n", rc, strerror(errno)); diff --git a/lustre/utils/gss/lgss_sk.c b/lustre/utils/gss/lgss_sk.c index 3c0a467..f7254d2 100644 --- a/lustre/utils/gss/lgss_sk.c +++ b/lustre/utils/gss/lgss_sk.c @@ -341,30 +341,29 @@ int main(int argc, char **argv) bool generate_prime = false; DH *dh; - static struct option long_opt[] = { - {"crypt", 1, 0, 'c'}, - {"data", 1, 0, 'd'}, - {"expire", 1, 0, 'e'}, - {"fsname", 1, 0, 'f'}, - {"mgsnids", 1, 0, 'g'}, - {"help", 0, 0, 'h'}, - {"hmac", 1, 0, 'i'}, - {"integrity", 1, 0, 'i'}, - {"key-bits", 1, 0, 'k'}, - {"shared", 1, 0, 'k'}, - {"load", 1, 0, 'l'}, - {"modify", 1, 0, 'm'}, - {"nodemap", 1, 0, 'n'}, - {"prime-bits", 1, 0, 'p'}, - {"read", 1, 0, 'r'}, - {"type", 1, 0, 't'}, - {"verbose", 0, 0, 'v'}, - {"write", 1, 0, 'w'}, - {0, 0, 0, 0}, - }; + static struct option long_opts[] = { + { .name = "crypt", .has_arg = required_argument, .val = 'c'}, + { .name = "data", .has_arg = required_argument, .val = 'd'}, + { .name = "expire", .has_arg = required_argument, .val = 'e'}, + { .name = "fsname", .has_arg = required_argument, .val = 'f'}, + { .name = "mgsnids", .has_arg = required_argument, .val = 'g'}, + { .name = "help", .has_arg = no_argument, .val = 'h'}, + { .name = "hmac", .has_arg = required_argument, .val = 'i'}, + { .name = "integrity", .has_arg = required_argument, .val = 'i'}, + { .name = "key-bits", .has_arg = required_argument, .val = 'k'}, + { .name = "shared", .has_arg = required_argument, .val = 'k'}, + { .name = "load", .has_arg = required_argument, .val = 'l'}, + { .name = "modify", .has_arg = required_argument, .val = 'm'}, + { .name = "nodemap", .has_arg = required_argument, .val = 'n'}, + { .name = "prime-bits", .has_arg = required_argument, .val = 'p'}, + { .name = "read", .has_arg = required_argument, .val = 'r'}, + { .name = "type", .has_arg = required_argument, .val = 't'}, + { .name = "verbose", .has_arg = no_argument, .val = 'v'}, + { .name = "write", .has_arg = required_argument, .val = 'w'}, + { .name = NULL, } }; while ((opt = getopt_long(argc, argv, - "c:d:e:f:g:hi:l:m:n:p:r:s:k:t:w:v", long_opt, + "c:d:e:f:g:hi:l:m:n:p:r:s:k:t:w:v", long_opts, NULL)) != EOF) { switch (opt) { case 'c': diff --git a/lustre/utils/gss/lsupport.c b/lustre/utils/gss/lsupport.c index 744fc27..f27ba4a 100644 --- a/lustre/utils/gss/lsupport.c +++ b/lustre/utils/gss/lsupport.c @@ -292,11 +292,11 @@ struct convert_struct { }; static struct convert_struct converter[] = { - [0] = { "UNUSED0", NULL}, - [SOCKLND] = { "SOCKLND", ipv4_nid2hostname }, - [O2IBLND] = { "O2IBLND", ipv4_nid2hostname }, - [LOLND] = { "LOLND", lolnd_nid2hostname }, - [PTL4LND] = { "PTL4LND", external_nid2hostname }, + [0] = { .name = "UNUSED0" }, + [SOCKLND] = { .name = "SOCKLND", .nid2name = ipv4_nid2hostname }, + [O2IBLND] = { .name = "O2IBLND", .nid2name = ipv4_nid2hostname }, + [LOLND] = { .name = "LOLND", .nid2name = lolnd_nid2hostname }, + [PTL4LND] = { .name = "PTL4LND", .nid2name = external_nid2hostname } }; #define LND_MAX (sizeof(converter) / sizeof(converter[0])) @@ -344,7 +344,7 @@ struct user_mapping { struct user_map_item *items; }; -static struct user_mapping mapping = {0, NULL}; +static struct user_mapping mapping; /* FIXME to be finished: monitor change of mapping database */ static int mapping_mtime = 0; diff --git a/lustre/utils/gss/svcgssd_mech2file.c b/lustre/utils/gss/svcgssd_mech2file.c index ca98f42..43c0d78 100644 --- a/lustre/utils/gss/svcgssd_mech2file.c +++ b/lustre/utils/gss/svcgssd_mech2file.c @@ -50,12 +50,47 @@ struct oid2mech { }; static const struct oid2mech o2m[] = { - {{9, "\052\206\110\206\367\022\001\002\002"}, "krb5"}, - {{7, "\053\006\001\005\005\001\003"}, "spkm3"}, - {{7, "\053\006\001\005\005\001\009"}, "lipkey"}, - {{12, "\053\006\001\004\001\311\146\215\126\001\000\000"}, "gssnull"}, - {{12, "\053\006\001\004\001\311\146\215\126\001\000\001"}, "sk"}, - {{0,0},""}, + { + .mech = { + .length = 9, + .elements = "\052\206\110\206\367\022\001\002\002", + }, + .mechname = "krb5", + }, + { + .mech = { + .length = 7, + .elements = "\053\006\001\005\005\001\003", + }, + .mechname = "spkm3", + }, + { + .mech = { + .length = 7, + .elements = "\053\006\001\005\005\001\009", + }, + .mechname = "lipkey", + }, + { + .mech = { + .length = 12, + .elements = "\053\006\001\004\001\311\146\215\126\001\000\000", + }, + .mechname = "gssnull", + }, + { + .mech = { + .length = 12, + .elements = "\053\006\001\004\001\311\146\215\126\001\000\001", + }, + .mechname = "sk", + }, + { + .mech = { + .length = 0, + }, + .mechname = "", + } }; /* -- 1.8.3.1