at master 5.3 kB view raw
1From df0a1cf61188b5b7bb98675d746cb63d9300f148 Mon Sep 17 00:00:00 2001 2From: rnhmjoj <rnhmjoj@inventati.org> 3Date: Sat, 1 Jul 2023 18:47:05 +0200 4Subject: [PATCH] Add mode to validate the atomic configuration 5 6--- 7 src/usr/argp/main.c | 6 ++++++ 8 src/usr/argp/wargp/file.c | 26 +++++++++++++++++++++++++- 9 src/usr/argp/wargp/file.h | 1 + 10 src/usr/nl/file.c | 32 ++++++++++++++++++++++---------- 11 src/usr/nl/file.h | 3 ++- 12 5 files changed, 56 insertions(+), 12 deletions(-) 13 14diff --git a/src/usr/argp/main.c b/src/usr/argp/main.c 15index 744a6df0..d04917da 100644 16--- a/src/usr/argp/main.c 17+++ b/src/usr/argp/main.c 18@@ -238,6 +238,12 @@ static struct cmd_option file_ops[] = { 19 .handler = handle_file_update, 20 .handle_autocomplete = autocomplete_file_update, 21 }, 22+ { 23+ .label = "check", 24+ .xt = XT_ANY, 25+ .handler = handle_file_check, 26+ .handle_autocomplete = autocomplete_file_update, 27+ }, 28 { 0 }, 29 }; 30 31diff --git a/src/usr/argp/wargp/file.c b/src/usr/argp/wargp/file.c 32index 0951b544..27ee3e64 100644 33--- a/src/usr/argp/wargp/file.c 34+++ b/src/usr/argp/wargp/file.c 35@@ -26,6 +26,30 @@ static struct wargp_option update_opts[] = { 36 { 0 }, 37 }; 38 39+int handle_file_check(char *iname, int argc, char **argv, void const *arg) 40+{ 41+ struct update_args uargs = { 0 }; 42+ struct joolnl_socket sk = { 0 }; 43+ struct jool_result result; 44+ 45+ result.error = wargp_parse(update_opts, argc, argv, &uargs); 46+ if (result.error) 47+ return result.error; 48+ 49+ if (!uargs.file_name.value) { 50+ struct requirement reqs[] = { 51+ { false, "a file name" }, 52+ { 0 } 53+ }; 54+ return requirement_print(reqs); 55+ } 56+ 57+ result = joolnl_file_parse(&sk, xt_get(), iname, uargs.file_name.value, 58+ uargs.force.value, true); 59+ 60+ return pr_result(&result); 61+} 62+ 63 int handle_file_update(char *iname, int argc, char **argv, void const *arg) 64 { 65 struct update_args uargs = { 0 }; 66@@ -49,7 +73,7 @@ int handle_file_update(char *iname, int argc, char **argv, void const *arg) 67 return pr_result(&result); 68 69 result = joolnl_file_parse(&sk, xt_get(), iname, uargs.file_name.value, 70- uargs.force.value); 71+ uargs.force.value, false); 72 73 joolnl_teardown(&sk); 74 return pr_result(&result); 75diff --git a/src/usr/argp/wargp/file.h b/src/usr/argp/wargp/file.h 76index ce5de508..8ea4a4d2 100644 77--- a/src/usr/argp/wargp/file.h 78+++ b/src/usr/argp/wargp/file.h 79@@ -2,6 +2,7 @@ 80 #define SRC_USR_ARGP_WARGP_FILE_H_ 81 82 int handle_file_update(char *iname, int argc, char **argv, void const *arg); 83+int handle_file_check(char *iname, int argc, char **argv, void const *arg); 84 void autocomplete_file_update(void const *args); 85 86 #endif /* SRC_USR_ARGP_WARGP_FILE_H_ */ 87diff --git a/src/usr/nl/file.c b/src/usr/nl/file.c 88index f9413236..51a668bd 100644 89--- a/src/usr/nl/file.c 90+++ b/src/usr/nl/file.c 91@@ -29,6 +29,7 @@ static struct joolnl_socket sk; 92 static char const *iname; 93 static xlator_flags flags; 94 static __u8 force; 95+static bool check; 96 97 struct json_meta { 98 char const *name; /* This being NULL signals the end of the array. */ 99@@ -163,9 +164,11 @@ static struct jool_result handle_array(cJSON *json, int attrtype, char *name, 100 goto too_small; 101 102 nla_nest_end(msg, root); 103- result = joolnl_request(&sk, msg, NULL, NULL); 104- if (result.error) 105- return result; 106+ if (!check) { 107+ result = joolnl_request(&sk, msg, NULL, NULL); 108+ if (result.error) 109+ return result; 110+ } 111 112 msg = NULL; 113 json = json->prev; 114@@ -179,6 +182,8 @@ static struct jool_result handle_array(cJSON *json, int attrtype, char *name, 115 return result_success(); 116 117 nla_nest_end(msg, root); 118+ if (check) 119+ return result_success(); 120 return joolnl_request(&sk, msg, NULL, NULL); 121 122 too_small: 123@@ -244,6 +249,8 @@ static struct jool_result handle_global(cJSON *json) 124 125 nla_nest_end(msg, root); 126 free(meta); 127+ if (check) 128+ return result_success(); 129 return joolnl_request(&sk, msg, NULL, NULL); 130 131 revert_meta: 132@@ -654,9 +661,11 @@ static struct jool_result send_ctrl_msg(bool init) 133 else 134 NLA_PUT(msg, JNLAR_ATOMIC_END, 0, NULL); 135 136- result = joolnl_request(&sk, msg, NULL, NULL); 137- if (result.error) 138- return result; 139+ if (!check) { 140+ result = joolnl_request(&sk, msg, NULL, NULL); 141+ if (result.error) 142+ return result; 143+ } 144 145 return result_success(); 146 147@@ -683,9 +692,11 @@ static struct jool_result do_parsing(char const *iname, char *buffer) 148 if (result.error) 149 goto fail; 150 151- result = send_ctrl_msg(true); 152- if (result.error) 153- goto fail; 154+ if (!check) { 155+ result = send_ctrl_msg(true); 156+ if (result.error) 157+ goto fail; 158+ } 159 160 switch (xlator_flags2xt(flags)) { 161 case XT_SIIT: 162@@ -718,12 +729,13 @@ fail: 163 } 164 165 struct jool_result joolnl_file_parse(struct joolnl_socket *_sk, xlator_type xt, 166- char const *iname, char const *file_name, bool _force) 167+ char const *iname, char const *file_name, bool _force, bool _check) 168 { 169 char *buffer; 170 struct jool_result result; 171 172 sk = *_sk; 173+ check = _check; 174 flags = xt; 175 force = _force ? JOOLNLHDR_FLAGS_FORCE : 0; 176 177diff --git a/src/usr/nl/file.h b/src/usr/nl/file.h 178index 51802aaf..8b4a66dd 100644 179--- a/src/usr/nl/file.h 180+++ b/src/usr/nl/file.h 181@@ -9,7 +9,8 @@ struct jool_result joolnl_file_parse( 182 xlator_type xt, 183 char const *iname, 184 char const *file_name, 185- bool force 186+ bool force, 187+ bool check 188 ); 189 190 struct jool_result joolnl_file_get_iname( 191-- 1922.40.1 193